src/share/jaxws_classes/com/sun/xml/internal/ws/addressing/policy/AddressingPolicyValidator.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.addressing.policy;
    28 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
    29 import com.sun.xml.internal.ws.policy.PolicyAssertion;
    30 import com.sun.xml.internal.ws.policy.NestedPolicy;
    31 import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
    32 import com.sun.xml.internal.ws.policy.spi.PolicyAssertionValidator;
    33 import com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants;
    35 import java.util.ArrayList;
    36 import javax.xml.namespace.QName;
    39 /**
    40  * This class validates the Addressing assertions.
    41  * If the assertion is wsam:Addressing, it makes sure that only valid assertions are nested.
    42  *
    43  * @author japod
    44  * @author Rama Pulavarthi
    45  */
    46 public class AddressingPolicyValidator implements PolicyAssertionValidator {
    48     private static final ArrayList<QName> supportedAssertions = new ArrayList<QName>();
    50     static {
    51         supportedAssertions.add(new QName(AddressingVersion.MEMBER.policyNsUri, "UsingAddressing"));
    52         supportedAssertions.add(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION);
    53         supportedAssertions.add(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION);
    54         supportedAssertions.add(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION);
    55     }
    57     /**
    58      * Creates a new instance of AddressingPolicyValidator
    59      */
    60     public AddressingPolicyValidator() {
    61     }
    63     public Fitness validateClientSide(PolicyAssertion assertion) {
    64         return supportedAssertions.contains(assertion.getName()) ? Fitness.SUPPORTED : Fitness.UNKNOWN;
    65     }
    67     public Fitness validateServerSide(PolicyAssertion assertion) {
    68         if (!supportedAssertions.contains(assertion.getName()))
    69             return Fitness.UNKNOWN;
    71         //Make sure wsam:Addressing contains only one of the allowed nested assertions.
    72         if (assertion.getName().equals(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
    73             NestedPolicy nestedPolicy = assertion.getNestedPolicy();
    74             if (nestedPolicy != null) {
    75                 boolean requiresAnonymousResponses = false;
    76                 boolean requiresNonAnonymousResponses = false;
    77                 for (PolicyAssertion nestedAsser : nestedPolicy.getAssertionSet()) {
    78                     if (nestedAsser.getName().equals(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION)) {
    79                         requiresAnonymousResponses = true;
    80                     } else if (nestedAsser.getName().equals(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION)) {
    81                         requiresNonAnonymousResponses = true;
    82                     } else {
    83                         LOGGER.warning("Found unsupported assertion:\n" + nestedAsser + "\nnested into assertion:\n" + assertion);
    84                         return Fitness.UNSUPPORTED;
    85                     }
    86                 }
    88                 if (requiresAnonymousResponses && requiresNonAnonymousResponses) {
    89                     LOGGER.warning("Only one among AnonymousResponses and NonAnonymousResponses can be nested in an Addressing assertion");
    90                     return Fitness.INVALID;
    91                 }
    92             }
    93         }
    95         return Fitness.SUPPORTED;
    96     }
    98     public String[] declareSupportedDomains() {
    99         return new String[]{AddressingVersion.MEMBER.policyNsUri, AddressingVersion.W3C.policyNsUri, W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME};
   100     }
   102     private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AddressingPolicyValidator.class);
   103 }

mercurial