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; aoqi@0: aoqi@0: import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages; aoqi@0: import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Collection; aoqi@0: import java.util.HashMap; aoqi@0: import java.util.Iterator; aoqi@0: import java.util.LinkedList; aoqi@0: import java.util.List; aoqi@0: import java.util.Map; aoqi@0: import java.util.NoSuchElementException; aoqi@0: import java.util.Set; aoqi@0: import javax.xml.namespace.QName; aoqi@0: aoqi@0: /** aoqi@0: * A PolicyMap holds all policies for a scope. aoqi@0: * aoqi@0: * This map is modeled around WSDL 1.1 policy scopes according to WS-PolicyAttachment. The map holds an information about aoqi@0: * every scope for service, endpoint, operation, and input/output/fault message. It also provide accessibility methods for aoqi@0: * computing and obtaining effective policy on each scope. aoqi@0: * aoqi@0: * TODO: rename createWsdlMessageScopeKey to createWsdlInputOutputMessageScopeKey aoqi@0: * aoqi@0: * @author Fabian Ritzmann aoqi@0: */ aoqi@0: public final class PolicyMap implements Iterable { aoqi@0: private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyMap.class); aoqi@0: aoqi@0: private static final PolicyMapKeyHandler serviceKeyHandler = new PolicyMapKeyHandler() { aoqi@0: public boolean areEqual(final PolicyMapKey key1, final PolicyMapKey key2) { aoqi@0: return key1.getService().equals(key2.getService()); aoqi@0: } aoqi@0: aoqi@0: public int generateHashCode(final PolicyMapKey key) { aoqi@0: int result = 17; aoqi@0: aoqi@0: result = 37 * result + key.getService().hashCode(); aoqi@0: aoqi@0: return result; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: private static final PolicyMapKeyHandler endpointKeyHandler = new PolicyMapKeyHandler() { aoqi@0: public boolean areEqual(final PolicyMapKey key1, final PolicyMapKey key2) { aoqi@0: boolean retVal = true; aoqi@0: aoqi@0: retVal = retVal && key1.getService().equals(key2.getService()); aoqi@0: retVal = retVal && ((key1.getPort() == null) ? key2.getPort() == null : key1.getPort().equals(key2.getPort())); aoqi@0: aoqi@0: return retVal; aoqi@0: } aoqi@0: aoqi@0: public int generateHashCode(final PolicyMapKey key) { aoqi@0: int result = 17; aoqi@0: aoqi@0: result = 37 * result + key.getService().hashCode(); aoqi@0: result = 37 * result + ((key.getPort() == null) ? 0 : key.getPort().hashCode()); aoqi@0: aoqi@0: return result; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: private static final PolicyMapKeyHandler operationAndInputOutputMessageKeyHandler = new PolicyMapKeyHandler() { aoqi@0: // we use the same algorithm to handle operation and input/output message keys aoqi@0: aoqi@0: public boolean areEqual(final PolicyMapKey key1, final PolicyMapKey key2) { aoqi@0: boolean retVal = true; aoqi@0: aoqi@0: retVal = retVal && key1.getService().equals(key2.getService()); aoqi@0: retVal = retVal && ((key1.getPort() == null) ? key2.getPort() == null : key1.getPort().equals(key2.getPort())); aoqi@0: retVal = retVal && ((key1.getOperation() == null) ? key2.getOperation() == null : key1.getOperation().equals(key2.getOperation())); aoqi@0: aoqi@0: return retVal; aoqi@0: } aoqi@0: aoqi@0: public int generateHashCode(final PolicyMapKey key) { aoqi@0: int result = 17; aoqi@0: aoqi@0: result = 37 * result + key.getService().hashCode(); aoqi@0: result = 37 * result + ((key.getPort() == null) ? 0 : key.getPort().hashCode()); aoqi@0: result = 37 * result + ((key.getOperation() == null) ? 0 : key.getOperation().hashCode()); aoqi@0: aoqi@0: return result; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: private static final PolicyMapKeyHandler faultMessageHandler = new PolicyMapKeyHandler() { aoqi@0: public boolean areEqual(final PolicyMapKey key1, final PolicyMapKey key2) { aoqi@0: boolean retVal = true; aoqi@0: aoqi@0: retVal = retVal && key1.getService().equals(key2.getService()); aoqi@0: retVal = retVal && ((key1.getPort() == null) ? key2.getPort() == null : key1.getPort().equals(key2.getPort())); aoqi@0: retVal = retVal && ((key1.getOperation() == null) ? key2.getOperation() == null : key1.getOperation().equals(key2.getOperation())); aoqi@0: retVal = retVal && ((key1.getFaultMessage() == null) ? key2.getFaultMessage() == null : key1.getFaultMessage().equals(key2.getFaultMessage())); aoqi@0: aoqi@0: return retVal; aoqi@0: } aoqi@0: aoqi@0: public int generateHashCode(final PolicyMapKey key) { aoqi@0: int result = 17; aoqi@0: aoqi@0: result = 37 * result + key.getService().hashCode(); aoqi@0: result = 37 * result + ((key.getPort() == null) ? 0 : key.getPort().hashCode()); aoqi@0: result = 37 * result + ((key.getOperation() == null) ? 0 : key.getOperation().hashCode()); aoqi@0: result = 37 * result + ((key.getFaultMessage() == null) ? 0 : key.getFaultMessage().hashCode()); aoqi@0: aoqi@0: return result; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: static enum ScopeType { aoqi@0: SERVICE, aoqi@0: ENDPOINT, aoqi@0: OPERATION, aoqi@0: INPUT_MESSAGE, aoqi@0: OUTPUT_MESSAGE, aoqi@0: FAULT_MESSAGE aoqi@0: } aoqi@0: aoqi@0: private static final class ScopeMap implements Iterable { aoqi@0: private final Map internalMap = new HashMap(); aoqi@0: private final PolicyMapKeyHandler scopeKeyHandler; aoqi@0: private final PolicyMerger merger; aoqi@0: aoqi@0: ScopeMap(final PolicyMerger merger, final PolicyMapKeyHandler scopeKeyHandler) { aoqi@0: this.merger = merger; aoqi@0: this.scopeKeyHandler = scopeKeyHandler; aoqi@0: } aoqi@0: aoqi@0: Policy getEffectivePolicy(final PolicyMapKey key) throws PolicyException { aoqi@0: final PolicyScope scope = internalMap.get(createLocalCopy(key)); aoqi@0: return (scope == null) ? null : scope.getEffectivePolicy(merger); aoqi@0: } aoqi@0: aoqi@0: void putSubject(final PolicyMapKey key, final PolicySubject subject) { aoqi@0: final PolicyMapKey localKey = createLocalCopy(key); aoqi@0: final PolicyScope scope = internalMap.get(localKey); aoqi@0: if (scope == null) { aoqi@0: final List list = new LinkedList(); aoqi@0: list.add(subject); aoqi@0: internalMap.put(localKey, new PolicyScope(list)); aoqi@0: } else { aoqi@0: scope.attach(subject); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void setNewEffectivePolicy(final PolicyMapKey key, final Policy newEffectivePolicy) { aoqi@0: // we add this policy map as a subject, because there is nothing reasonable we could add there, since aoqi@0: // this is an artificial policy subject aoqi@0: final PolicySubject subject = new PolicySubject(key, newEffectivePolicy); aoqi@0: aoqi@0: final PolicyMapKey localKey = createLocalCopy(key); aoqi@0: final PolicyScope scope = internalMap.get(localKey); aoqi@0: if (scope == null) { aoqi@0: final List list = new LinkedList(); aoqi@0: list.add(subject); aoqi@0: internalMap.put(localKey, new PolicyScope(list)); aoqi@0: } else { aoqi@0: scope.dettachAllSubjects(); aoqi@0: scope.attach(subject); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: Collection getStoredScopes() { aoqi@0: return internalMap.values(); aoqi@0: } aoqi@0: aoqi@0: Set getAllKeys() { aoqi@0: return internalMap.keySet(); aoqi@0: } aoqi@0: aoqi@0: private PolicyMapKey createLocalCopy(final PolicyMapKey key) { aoqi@0: if (key == null) { aoqi@0: throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0045_POLICY_MAP_KEY_MUST_NOT_BE_NULL())); aoqi@0: } aoqi@0: aoqi@0: final PolicyMapKey localKeyCopy = new PolicyMapKey(key); aoqi@0: localKeyCopy.setHandler(scopeKeyHandler); aoqi@0: aoqi@0: return localKeyCopy; aoqi@0: } aoqi@0: aoqi@0: public Iterator iterator() { aoqi@0: return new Iterator () { aoqi@0: private final Iterator keysIterator = internalMap.keySet().iterator(); aoqi@0: aoqi@0: public boolean hasNext() { aoqi@0: return keysIterator.hasNext(); aoqi@0: } aoqi@0: aoqi@0: public Policy next() { aoqi@0: final PolicyMapKey key = keysIterator.next(); aoqi@0: try { aoqi@0: return getEffectivePolicy(key); aoqi@0: } catch (PolicyException e) { aoqi@0: throw LOGGER.logSevereException(new IllegalStateException(LocalizationMessages.WSP_0069_EXCEPTION_WHILE_RETRIEVING_EFFECTIVE_POLICY_FOR_KEY(key), e)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void remove() { aoqi@0: throw LOGGER.logSevereException(new UnsupportedOperationException(LocalizationMessages.WSP_0034_REMOVE_OPERATION_NOT_SUPPORTED())); aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: public boolean isEmpty() { aoqi@0: return internalMap.isEmpty(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String toString() { aoqi@0: return internalMap.toString(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static final PolicyMerger merger = PolicyMerger.getMerger(); aoqi@0: aoqi@0: private final ScopeMap serviceMap = new ScopeMap(merger, serviceKeyHandler); aoqi@0: private final ScopeMap endpointMap = new ScopeMap(merger, endpointKeyHandler); aoqi@0: private final ScopeMap operationMap = new ScopeMap(merger, operationAndInputOutputMessageKeyHandler); aoqi@0: private final ScopeMap inputMessageMap = new ScopeMap(merger, operationAndInputOutputMessageKeyHandler); aoqi@0: private final ScopeMap outputMessageMap = new ScopeMap(merger, operationAndInputOutputMessageKeyHandler); aoqi@0: private final ScopeMap faultMessageMap = new ScopeMap(merger, faultMessageHandler); aoqi@0: aoqi@0: /** aoqi@0: * This constructor is private to prevent direct instantiation from outside of the class aoqi@0: */ aoqi@0: private PolicyMap() { aoqi@0: // nothing to initialize aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Creates new policy map instance and connects provided collection of policy map mutators to the created policy map. aoqi@0: * aoqi@0: * @param mutators collection of mutators that should be connected to the newly created map. aoqi@0: * @return new policy map instance (mutable via provided collection of mutators). aoqi@0: */ aoqi@0: public static PolicyMap createPolicyMap(final Collection mutators) { aoqi@0: final PolicyMap result = new PolicyMap(); aoqi@0: aoqi@0: if (mutators != null && !mutators.isEmpty()) { aoqi@0: for (PolicyMapMutator mutator : mutators) { aoqi@0: mutator.connect(result); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: public Policy getServiceEffectivePolicy(final PolicyMapKey key) throws PolicyException { aoqi@0: return serviceMap.getEffectivePolicy(key); aoqi@0: } aoqi@0: aoqi@0: public Policy getEndpointEffectivePolicy(final PolicyMapKey key) throws PolicyException { aoqi@0: return endpointMap.getEffectivePolicy(key); aoqi@0: } aoqi@0: aoqi@0: public Policy getOperationEffectivePolicy(final PolicyMapKey key) throws PolicyException { aoqi@0: return operationMap.getEffectivePolicy(key); aoqi@0: } aoqi@0: aoqi@0: public Policy getInputMessageEffectivePolicy(final PolicyMapKey key) throws PolicyException { aoqi@0: return inputMessageMap.getEffectivePolicy(key); aoqi@0: } aoqi@0: aoqi@0: public Policy getOutputMessageEffectivePolicy(final PolicyMapKey key) throws PolicyException { aoqi@0: return outputMessageMap.getEffectivePolicy(key); aoqi@0: } aoqi@0: aoqi@0: public Policy getFaultMessageEffectivePolicy(final PolicyMapKey key) throws PolicyException { aoqi@0: return faultMessageMap.getEffectivePolicy(key); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns all service scope keys stored in this policy map aoqi@0: * aoqi@0: * @return collection of service scope policy map keys stored in the map. aoqi@0: */ aoqi@0: public Collection getAllServiceScopeKeys() { aoqi@0: return serviceMap.getAllKeys(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns all endpoint scope keys stored in this policy map aoqi@0: * aoqi@0: * @return collection of endpoint scope policy map keys stored in the map. aoqi@0: */ aoqi@0: public Collection getAllEndpointScopeKeys() { aoqi@0: return endpointMap.getAllKeys(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns all operation scope keys stored in this policy map aoqi@0: * aoqi@0: * @return collection of operation scope policy map keys stored in the map. aoqi@0: */ aoqi@0: public Collection getAllOperationScopeKeys() { aoqi@0: return operationMap.getAllKeys(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns all input message scope keys stored in this policy map aoqi@0: * aoqi@0: * @return collection of input message scope policy map keys stored in the map. aoqi@0: */ aoqi@0: public Collection getAllInputMessageScopeKeys() { aoqi@0: return inputMessageMap.getAllKeys(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns all output message scope keys stored in this policy map aoqi@0: * aoqi@0: * @return collection of output message scope policy map keys stored in the map. aoqi@0: */ aoqi@0: public Collection getAllOutputMessageScopeKeys() { aoqi@0: return outputMessageMap.getAllKeys(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns all fault message scope keys stored in this policy map aoqi@0: * aoqi@0: * @return collection of input message scope policy map keys stored in the map. aoqi@0: */ aoqi@0: public Collection getAllFaultMessageScopeKeys() { aoqi@0: return faultMessageMap.getAllKeys(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Places new subject into policy map under the scope identified by it's type and policy map key. aoqi@0: * aoqi@0: * @param scopeType the type of the scope the subject belongs to aoqi@0: * @param key a policy map key to be used to store the subject aoqi@0: * @param subject actual policy subject to be stored in the policy map aoqi@0: * aoqi@0: * @throw IllegalArgumentException in case the scope type is not recognized. aoqi@0: */ aoqi@0: void putSubject(final ScopeType scopeType, final PolicyMapKey key, final PolicySubject subject) { aoqi@0: switch (scopeType) { aoqi@0: case SERVICE: aoqi@0: serviceMap.putSubject(key, subject); aoqi@0: break; aoqi@0: case ENDPOINT: aoqi@0: endpointMap.putSubject(key, subject); aoqi@0: break; aoqi@0: case OPERATION: aoqi@0: operationMap.putSubject(key, subject); aoqi@0: break; aoqi@0: case INPUT_MESSAGE: aoqi@0: inputMessageMap.putSubject(key, subject); aoqi@0: break; aoqi@0: case OUTPUT_MESSAGE: aoqi@0: outputMessageMap.putSubject(key, subject); aoqi@0: break; aoqi@0: case FAULT_MESSAGE: aoqi@0: faultMessageMap.putSubject(key, subject); aoqi@0: break; aoqi@0: default: aoqi@0: throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType))); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Replaces current effective policy on given scope (identified by a {@code key} parameter) with the new efective aoqi@0: * policy provided as a second input parameter. If no policy was defined for the presented key, the new policy is simply aoqi@0: * stored with the key. aoqi@0: * aoqi@0: * @param scopeType the type of the scope the subject belongs to. Must not be {@code null}. aoqi@0: * @param key identifier of the scope the effective policy should be replaced with the new one. Must not be {@code null}. aoqi@0: * @param newEffectivePolicy the new policy to replace the old effective policy of the scope. Must not be {@code null}. aoqi@0: * aoqi@0: * @throw IllegalArgumentException in case any of the input parameters is {@code null} aoqi@0: * or in case the scope type is not recognized. aoqi@0: */ aoqi@0: void setNewEffectivePolicyForScope(final ScopeType scopeType, final PolicyMapKey key, final Policy newEffectivePolicy) throws IllegalArgumentException { aoqi@0: if (scopeType == null || key == null || newEffectivePolicy == null) { aoqi@0: throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0062_INPUT_PARAMS_MUST_NOT_BE_NULL())); aoqi@0: } aoqi@0: aoqi@0: switch (scopeType) { aoqi@0: case SERVICE : aoqi@0: serviceMap.setNewEffectivePolicy(key, newEffectivePolicy); aoqi@0: break; aoqi@0: case ENDPOINT : aoqi@0: endpointMap.setNewEffectivePolicy(key, newEffectivePolicy); aoqi@0: break; aoqi@0: case OPERATION : aoqi@0: operationMap.setNewEffectivePolicy(key, newEffectivePolicy); aoqi@0: break; aoqi@0: case INPUT_MESSAGE : aoqi@0: inputMessageMap.setNewEffectivePolicy(key, newEffectivePolicy); aoqi@0: break; aoqi@0: case OUTPUT_MESSAGE : aoqi@0: outputMessageMap.setNewEffectivePolicy(key, newEffectivePolicy); aoqi@0: break; aoqi@0: case FAULT_MESSAGE : aoqi@0: faultMessageMap.setNewEffectivePolicy(key, newEffectivePolicy); aoqi@0: break; aoqi@0: default: aoqi@0: throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType))); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns all policy subjects contained by this map. aoqi@0: * aoqi@0: * @return All policy subjects contained by this map aoqi@0: */ aoqi@0: public Collection getPolicySubjects() { aoqi@0: final List subjects = new LinkedList(); aoqi@0: addSubjects(subjects, serviceMap); aoqi@0: addSubjects(subjects, endpointMap); aoqi@0: addSubjects(subjects, operationMap); aoqi@0: addSubjects(subjects, inputMessageMap); aoqi@0: addSubjects(subjects, outputMessageMap); aoqi@0: addSubjects(subjects, faultMessageMap); aoqi@0: return subjects; aoqi@0: } aoqi@0: aoqi@0: /* aoqi@0: * TODO: reconsider this QUICK HACK aoqi@0: */ aoqi@0: public boolean isInputMessageSubject(final PolicySubject subject) { aoqi@0: for (PolicyScope scope : inputMessageMap.getStoredScopes()) { aoqi@0: if (scope.getPolicySubjects().contains(subject)) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: /* aoqi@0: * TODO: reconsider this QUICK HACK aoqi@0: */ aoqi@0: public boolean isOutputMessageSubject(final PolicySubject subject) { aoqi@0: for (PolicyScope scope : outputMessageMap.getStoredScopes()) { aoqi@0: if (scope.getPolicySubjects().contains(subject)) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /* aoqi@0: * TODO: reconsider this QUICK HACK aoqi@0: */ aoqi@0: public boolean isFaultMessageSubject(final PolicySubject subject) { aoqi@0: for (PolicyScope scope : faultMessageMap.getStoredScopes()) { aoqi@0: if (scope.getPolicySubjects().contains(subject)) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Returns true if this map contains no key - policy pairs aoqi@0: * aoqi@0: * A null object key or policy constitutes a non-empty map. aoqi@0: * aoqi@0: * @return true if this map contains no key - policy pairs aoqi@0: */ aoqi@0: public boolean isEmpty() { aoqi@0: return serviceMap.isEmpty() && endpointMap.isEmpty() && aoqi@0: operationMap.isEmpty() && inputMessageMap.isEmpty() && aoqi@0: outputMessageMap.isEmpty() && faultMessageMap.isEmpty(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Add all subjects in the given map to the collection aoqi@0: * aoqi@0: * @param subjects A collection that should hold subjects. The new subjects are added to the collection. Must not be {@code null}. aoqi@0: * @param scopeMap A scope map that holds policy scopes. The subjects are retrieved from the scope objects. aoqi@0: */ aoqi@0: private void addSubjects(final Collection subjects, final ScopeMap scopeMap) { aoqi@0: for (PolicyScope scope : scopeMap.getStoredScopes()) { aoqi@0: final Collection scopedSubjects = scope.getPolicySubjects(); aoqi@0: subjects.addAll(scopedSubjects); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Creates a service policy scope locator object, that serves as a access key into aoqi@0: * a {@code PolicyMap} where actual service policy scope for given service can be retrieved. aoqi@0: * aoqi@0: * @param service qualified name of the service. Must not be {@code null}. aoqi@0: * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}. aoqi@0: */ aoqi@0: public static PolicyMapKey createWsdlServiceScopeKey(final QName service) throws IllegalArgumentException { aoqi@0: if (service == null) { aoqi@0: throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0031_SERVICE_PARAM_MUST_NOT_BE_NULL())); aoqi@0: } aoqi@0: return new PolicyMapKey(service, null, null, serviceKeyHandler); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Creates an endpoint policy scope locator object, that serves as a access key into aoqi@0: * a {@code PolicyMap} where actual endpoint policy scope for given endpoint can be retrieved. aoqi@0: * aoqi@0: * @param service qualified name of the service. Must not be {@code null}. aoqi@0: * @param port qualified name of the endpoint. Must not be {@code null}. aoqi@0: * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}. aoqi@0: */ aoqi@0: public static PolicyMapKey createWsdlEndpointScopeKey(final QName service, final QName port) throws IllegalArgumentException { aoqi@0: if (service == null || port == null) { aoqi@0: throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0033_SERVICE_AND_PORT_PARAM_MUST_NOT_BE_NULL(service, port))); aoqi@0: } aoqi@0: return new PolicyMapKey(service, port, null, endpointKeyHandler); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Creates an operation policy scope locator object, that serves as a access key into aoqi@0: * a {@code PolicyMap} where actual operation policy scope for given bound operation can be retrieved. aoqi@0: * aoqi@0: * @param service qualified name of the service. Must not be {@code null}. aoqi@0: * @param port qualified name of the endpoint. Must not be {@code null}. aoqi@0: * @param operation qualified name of the operation. Must not be {@code null}. aoqi@0: * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}. aoqi@0: */ aoqi@0: public static PolicyMapKey createWsdlOperationScopeKey(final QName service, final QName port, final QName operation) throws IllegalArgumentException { aoqi@0: return createOperationOrInputOutputMessageKey(service, port, operation); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Creates an input/output message policy scope locator object identified by a bound operation, that serves as a aoqi@0: * access key into {@code PolicyMap} where actual input/output message policy scope for given input message of a bound operation aoqi@0: * can be retrieved. aoqi@0: *

aoqi@0: * The method returns a key that is compliant with WSDL 1.1 Basic Profile Specification, according to which there aoqi@0: * should be no two operations with the same name in a single port type definition. aoqi@0: * aoqi@0: * @param service qualified name of the service. Must not be {@code null}. aoqi@0: * @param port qualified name of the endpoint. Must not be {@code null}. aoqi@0: * @param operation qualified name of the operation. Must not be {@code null}. aoqi@0: * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}. aoqi@0: * aoqi@0: */ aoqi@0: public static PolicyMapKey createWsdlMessageScopeKey(final QName service, final QName port, final QName operation) throws IllegalArgumentException { aoqi@0: return createOperationOrInputOutputMessageKey(service, port, operation); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Creates a fault message policy scope locator object identified by a bound operation, that serves as a aoqi@0: * access key into {@code PolicyMap} where the actual fault message policy scope for one of the faults of a bound operation aoqi@0: * can be retrieved. aoqi@0: *

aoqi@0: * The method returns a key that is compliant with the WSDL 1.1 Basic Profile Specification, according to which there aoqi@0: * should be no two operations with the same name in a single port type definition. aoqi@0: * aoqi@0: * @param service qualified name of the service. Must not be {@code null}. aoqi@0: * @param port qualified name of the endpoint. Must not be {@code null}. aoqi@0: * @param operation qualified name of the operation. Must not be {@code null}. aoqi@0: * @param fault qualified name of the fault. Do not confuse this with the name of the actual message. This parameter aoqi@0: * takes the wsdl:binding/wsdl:operation/wsdl:fault name and not the wsdl:message name. Must not be {@code null}. aoqi@0: * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}. aoqi@0: * aoqi@0: */ aoqi@0: public static PolicyMapKey createWsdlFaultMessageScopeKey(final QName service, final QName port, final QName operation, final QName fault) throws IllegalArgumentException { aoqi@0: if (service == null || port == null || operation == null || fault == null) { aoqi@0: throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0030_SERVICE_PORT_OPERATION_FAULT_MSG_PARAM_MUST_NOT_BE_NULL(service, port, operation, fault))); aoqi@0: } aoqi@0: aoqi@0: return new PolicyMapKey(service, port, operation, fault, faultMessageHandler); aoqi@0: } aoqi@0: aoqi@0: private static PolicyMapKey createOperationOrInputOutputMessageKey(final QName service, final QName port, final QName operation) { aoqi@0: if (service == null || port == null || operation == null) { aoqi@0: throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0029_SERVICE_PORT_OPERATION_PARAM_MUST_NOT_BE_NULL(service, port, operation))); aoqi@0: } aoqi@0: aoqi@0: return new PolicyMapKey(service, port, operation, operationAndInputOutputMessageKeyHandler); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String toString(){ aoqi@0: // TODO aoqi@0: final StringBuffer result = new StringBuffer(); aoqi@0: if(null!=this.serviceMap) { aoqi@0: result.append("\nServiceMap=").append(this.serviceMap); aoqi@0: } aoqi@0: if(null!=this.endpointMap) { aoqi@0: result.append("\nEndpointMap=").append(this.endpointMap); aoqi@0: } aoqi@0: if(null!=this.operationMap) { aoqi@0: result.append("\nOperationMap=").append(this.operationMap); aoqi@0: } aoqi@0: if(null!=this.inputMessageMap) { aoqi@0: result.append("\nInputMessageMap=").append(this.inputMessageMap); aoqi@0: } aoqi@0: if(null!=this.outputMessageMap) { aoqi@0: result.append("\nOutputMessageMap=").append(this.outputMessageMap); aoqi@0: } aoqi@0: if(null!=this.faultMessageMap) { aoqi@0: result.append("\nFaultMessageMap=").append(this.faultMessageMap); aoqi@0: } aoqi@0: return result.toString(); aoqi@0: } aoqi@0: aoqi@0: public Iterator iterator() { aoqi@0: return new Iterator () { aoqi@0: private final Iterator> mainIterator; aoqi@0: private Iterator currentScopeIterator; aoqi@0: aoqi@0: { // instance initialization aoqi@0: final Collection> scopeIterators = new ArrayList>(6); aoqi@0: scopeIterators.add(serviceMap.iterator()); aoqi@0: scopeIterators.add(endpointMap.iterator()); aoqi@0: scopeIterators.add(operationMap.iterator()); aoqi@0: scopeIterators.add(inputMessageMap.iterator()); aoqi@0: scopeIterators.add(outputMessageMap.iterator()); aoqi@0: scopeIterators.add(faultMessageMap.iterator()); aoqi@0: aoqi@0: mainIterator = scopeIterators.iterator(); aoqi@0: currentScopeIterator = mainIterator.next(); aoqi@0: } aoqi@0: aoqi@0: public boolean hasNext() { aoqi@0: while (!currentScopeIterator.hasNext()) { aoqi@0: if (mainIterator.hasNext()) { aoqi@0: currentScopeIterator = mainIterator.next(); aoqi@0: } else { aoqi@0: return false; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: public Policy next() { aoqi@0: if (hasNext()) { aoqi@0: return currentScopeIterator.next(); aoqi@0: } aoqi@0: throw LOGGER.logSevereException(new NoSuchElementException(LocalizationMessages.WSP_0054_NO_MORE_ELEMS_IN_POLICY_MAP())); aoqi@0: } aoqi@0: aoqi@0: public void remove() { aoqi@0: throw LOGGER.logSevereException(new UnsupportedOperationException(LocalizationMessages.WSP_0034_REMOVE_OPERATION_NOT_SUPPORTED())); aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: }