001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.xml.ws.policy.spi;
037:
038: import com.sun.xml.ws.policy.PolicyAssertion;
039: import java.util.Collection;
040: import java.util.HashSet;
041: import java.util.Set;
042: import javax.xml.namespace.QName;
043:
044: /**
045: * This abstract policy assertion validator validates assertions by their qualified
046: * name. Server and client side validation methods return {@link Fitness} based on
047: * following schema:
048: *
049: * <ul>
050: * <li>{@link Fitness#SUPPORTED} - if the assertion qualified name is in the list of
051: * supported assertion names on the server/client side</li>
052: * <li>{@link Fitness#UNSUPPORTED} - if the assertion qualified name is not in the list of
053: * supported assertion names on the server/client side, however it is in the list of
054: * assertion names supported on the other side</li>
055: * <li>{@link Fitness#UNKNOWN} - if the assertion qualified name is not present in the any of
056: * the lists of supported assertion names</li>
057: * </ul>
058: *
059: * For some domains such validation may be sufficient enough. Other domains may
060: * use functionality of this base class as a first step validation before any attempts
061: * to validate content of the assertion. To do this one needs to override and reuse
062: * the default behavior of {@link #validateClientSide(PolicyAssertion)} and
063: * {@link #validateServerSide(PolicyAssertion)} methods.
064: *
065: * @author Marek Potociar (marek.potociar at sun.com)
066: */
067: public abstract class AbstractQNameValidator implements
068: PolicyAssertionValidator {
069: private final Set<String> supportedDomains = new HashSet<String>();
070: private final Collection<QName> serverAssertions;
071: private final Collection<QName> clientAssertions;
072:
073: /**
074: * Constructor that takes two collections specifying qualified names of assertions
075: * supported on either server or client side. The set of all assertion namespaces
076: * defines list of all domains supported by the assertion validator
077: * (see {@link PolicyAssertionValidator#declareSupportedDomains}).
078: */
079: protected AbstractQNameValidator(
080: Collection<QName> serverSideAssertions,
081: Collection<QName> clientSideAssertions) {
082: if (serverSideAssertions != null) {
083: this .serverAssertions = new HashSet<QName>(
084: serverSideAssertions);
085: for (QName assertion : this .serverAssertions) {
086: supportedDomains.add(assertion.getNamespaceURI());
087: }
088: } else {
089: this .serverAssertions = new HashSet<QName>(0);
090: }
091:
092: if (clientSideAssertions != null) {
093: this .clientAssertions = new HashSet<QName>(
094: clientSideAssertions);
095: for (QName assertion : this .clientAssertions) {
096: supportedDomains.add(assertion.getNamespaceURI());
097: }
098: } else {
099: this .clientAssertions = new HashSet<QName>(0);
100: }
101: }
102:
103: public String[] declareSupportedDomains() {
104: return supportedDomains.toArray(new String[supportedDomains
105: .size()]);
106: }
107:
108: public Fitness validateClientSide(PolicyAssertion assertion) {
109: return validateAssertion(assertion, clientAssertions,
110: serverAssertions);
111: }
112:
113: public Fitness validateServerSide(PolicyAssertion assertion) {
114: return validateAssertion(assertion, serverAssertions,
115: clientAssertions);
116: }
117:
118: private Fitness validateAssertion(PolicyAssertion assertion,
119: Collection<QName> this SideAssertions,
120: Collection<QName> otherSideAssertions) {
121: QName assertionName = assertion.getName();
122: if (thisSideAssertions.contains(assertionName)) {
123: return Fitness.SUPPORTED;
124: } else if (otherSideAssertions.contains(assertionName)) {
125: return Fitness.UNSUPPORTED;
126: } else {
127: return Fitness.UNKNOWN;
128: }
129: }
130: }
|