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;
037:
038: import com.sun.xml.ws.policy.privateutil.PolicyLogger;
039: import com.sun.xml.ws.policy.privateutil.PolicyUtils;
040: import com.sun.xml.ws.policy.spi.PolicyAssertionValidator;
041:
042: import static com.sun.xml.ws.policy.privateutil.LocalizationMessages.WSP_0076_NO_SERVICE_PROVIDERS_FOUND;
043:
044: /**
045: * Singleton class that provides method for assertion validation.
046: *
047: * @author Marek Potociar (marek.potociar at sun.com)
048: */
049: public final class AssertionValidationProcessor {
050: private static final PolicyLogger LOGGER = PolicyLogger
051: .getLogger(AssertionValidationProcessor.class);
052:
053: private static AssertionValidationProcessor processor = new AssertionValidationProcessor();
054: private static final PolicyAssertionValidator[] validators;
055: static {
056: validators = PolicyUtils.ServiceProvider
057: .load(PolicyAssertionValidator.class);
058: }
059:
060: /**
061: * This private constructor prevents direct instantiation of this class.
062: */
063: private AssertionValidationProcessor() {
064: // no instantiation outside the class.
065: }
066:
067: /**
068: * Factory method that returns singleton instance of the class.
069: *
070: * @return singleton instance of the class.
071: */
072: public static AssertionValidationProcessor getInstance()
073: throws PolicyException {
074: if (validators.length == 0) {
075: throw LOGGER
076: .logSevereException(new PolicyException(
077: WSP_0076_NO_SERVICE_PROVIDERS_FOUND(PolicyAssertionValidator.class
078: .getName())));
079: }
080: return processor;
081: }
082:
083: /**
084: * Validates fitness of the {@code assertion} on the client side.
085: *
086: * return client side {@code assertion} fitness
087: */
088: public PolicyAssertionValidator.Fitness validateClientSide(
089: final PolicyAssertion assertion) throws PolicyException {
090: PolicyAssertionValidator.Fitness assertionFitness = PolicyAssertionValidator.Fitness.UNKNOWN;
091: for (PolicyAssertionValidator validator : validators) {
092: assertionFitness = assertionFitness.combine(validator
093: .validateClientSide(assertion));
094: if (assertionFitness == PolicyAssertionValidator.Fitness.SUPPORTED) {
095: break;
096: }
097: }
098:
099: return assertionFitness;
100: }
101:
102: /**
103: * Validates fitness of the {@code assertion} on the server side.
104: *
105: * return server side {@code assertion} fitness
106: */
107: public PolicyAssertionValidator.Fitness validateServerSide(
108: final PolicyAssertion assertion) throws PolicyException {
109: PolicyAssertionValidator.Fitness assertionFitness = PolicyAssertionValidator.Fitness.UNKNOWN;
110: for (PolicyAssertionValidator validator : validators) {
111: assertionFitness = assertionFitness.combine(validator
112: .validateServerSide(assertion));
113: if (assertionFitness == PolicyAssertionValidator.Fitness.SUPPORTED) {
114: break;
115: }
116: }
117:
118: return assertionFitness;
119: }
120: }
|