aoqi@0: /*
aoqi@0: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0: *
aoqi@0: * This code is free software; you can redistribute it and/or modify it
aoqi@0: * under the terms of the GNU General Public License version 2 only, as
aoqi@0: * published by the Free Software Foundation. Oracle designates this
aoqi@0: * particular file as subject to the "Classpath" exception as provided
aoqi@0: * by Oracle in the LICENSE file that accompanied this code.
aoqi@0: *
aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0: * accompanied this code).
aoqi@0: *
aoqi@0: * You should have received a copy of the GNU General Public License version
aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0: *
aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0: * or visit www.oracle.com if you need additional information or have any
aoqi@0: * questions.
aoqi@0: */
aoqi@0:
aoqi@0: package com.sun.xml.internal.ws.policy.spi;
aoqi@0:
aoqi@0: import com.sun.xml.internal.ws.policy.PolicyAssertion;
aoqi@0: import java.util.Collection;
aoqi@0: import java.util.HashSet;
aoqi@0: import java.util.Set;
aoqi@0: import javax.xml.namespace.QName;
aoqi@0:
aoqi@0: /**
aoqi@0: * This abstract policy assertion validator validates assertions by their qualified
aoqi@0: * name. Server and client side validation methods return {@link Fitness} based on
aoqi@0: * following schema:
aoqi@0: *
aoqi@0: *
aoqi@0: * - {@link Fitness#SUPPORTED} - if the assertion qualified name is in the list of
aoqi@0: * supported assertion names on the server/client side
aoqi@0: * - {@link Fitness#UNSUPPORTED} - if the assertion qualified name is not in the list of
aoqi@0: * supported assertion names on the server/client side, however it is in the list of
aoqi@0: * assertion names supported on the other side
aoqi@0: * - {@link Fitness#UNKNOWN} - if the assertion qualified name is not present in the any of
aoqi@0: * the lists of supported assertion names
aoqi@0: *
aoqi@0: *
aoqi@0: * For some domains such validation may be sufficient enough. Other domains may
aoqi@0: * use functionality of this base class as a first step validation before any attempts
aoqi@0: * to validate content of the assertion. To do this one needs to override and reuse
aoqi@0: * the default behavior of {@link #validateClientSide(PolicyAssertion)} and
aoqi@0: * {@link #validateServerSide(PolicyAssertion)} methods.
aoqi@0: *
aoqi@0: * @author Marek Potociar (marek.potociar at sun.com)
aoqi@0: */
aoqi@0: public abstract class AbstractQNameValidator implements PolicyAssertionValidator {
aoqi@0: private final Set supportedDomains = new HashSet();
aoqi@0: private final Collection serverAssertions;
aoqi@0: private final Collection clientAssertions;
aoqi@0:
aoqi@0: /**
aoqi@0: * Constructor that takes two collections specifying qualified names of assertions
aoqi@0: * supported on either server or client side. The set of all assertion namespaces
aoqi@0: * defines list of all domains supported by the assertion validator
aoqi@0: * (see {@link PolicyAssertionValidator#declareSupportedDomains}).
aoqi@0: *
aoqi@0: * @param serverSideAssertions The server-side assertions.
aoqi@0: * @param clientSideAssertions The client-side assertions.
aoqi@0: */
aoqi@0: protected AbstractQNameValidator(Collection serverSideAssertions, Collection clientSideAssertions) {
aoqi@0: if (serverSideAssertions != null) {
aoqi@0: this.serverAssertions = new HashSet(serverSideAssertions);
aoqi@0: for (QName assertion : this.serverAssertions) {
aoqi@0: supportedDomains.add(assertion.getNamespaceURI());
aoqi@0: }
aoqi@0: } else {
aoqi@0: this.serverAssertions = new HashSet(0);
aoqi@0: }
aoqi@0:
aoqi@0: if (clientSideAssertions != null) {
aoqi@0: this.clientAssertions = new HashSet(clientSideAssertions);
aoqi@0: for (QName assertion : this.clientAssertions) {
aoqi@0: supportedDomains.add(assertion.getNamespaceURI());
aoqi@0: }
aoqi@0: } else {
aoqi@0: this.clientAssertions = new HashSet(0);
aoqi@0: }
aoqi@0: }
aoqi@0:
aoqi@0: public String[] declareSupportedDomains() {
aoqi@0: return supportedDomains.toArray(new String[supportedDomains.size()]);
aoqi@0: }
aoqi@0:
aoqi@0: public Fitness validateClientSide(PolicyAssertion assertion) {
aoqi@0: return validateAssertion(assertion, clientAssertions, serverAssertions);
aoqi@0: }
aoqi@0:
aoqi@0: public Fitness validateServerSide(PolicyAssertion assertion) {
aoqi@0: return validateAssertion(assertion, serverAssertions, clientAssertions);
aoqi@0: }
aoqi@0:
aoqi@0: private Fitness validateAssertion(PolicyAssertion assertion, Collection thisSideAssertions, Collection otherSideAssertions) {
aoqi@0: QName assertionName = assertion.getName();
aoqi@0: if (thisSideAssertions.contains(assertionName)) {
aoqi@0: return Fitness.SUPPORTED;
aoqi@0: } else if (otherSideAssertions.contains(assertionName)) {
aoqi@0: return Fitness.UNSUPPORTED;
aoqi@0: } else {
aoqi@0: return Fitness.UNKNOWN;
aoqi@0: }
aoqi@0: }
aoqi@0: }