FileDocCategorySizeDatePackage
PolicyMap.javaAPI DocExample31756Fri Jun 29 08:45:08 BST 2007com.sun.xml.ws.policy

PolicyMap

public final class PolicyMap extends Object implements Iterable
A PolicyMap holds all policies for a scope. This map is modeled around WSDL 1.1 policy scopes according to WS-PolicyAttachment. The map holds an information about every scope for service, endpoint, operation, and input/output/fault message. It also provide accessibility methods for computing and obtaining effective policy on each scope. TODO: rename createWsdlMessageScopeKey to createWsdlInputOutputMessageScopeKey

Fields Summary
private static final com.sun.xml.ws.policy.privateutil.PolicyLogger
LOGGER
private static final PolicyMerger
merger
private final ScopeMap
serviceMap
private final ScopeMap
endpointMap
private final PolicyMapKeyHandler
operationAndInputOutputMessageKeyHandler
private final ScopeMap
operationMap
private final ScopeMap
inputMessageMap
private final ScopeMap
outputMessageMap
private final ScopeMap
faultMessageMap
Constructors Summary
private PolicyMap()
This constructor is private to prevent direct instantiation from outside of the class

    
                      
      
        // nothing to initialize
    
Methods Summary
private voidaddSubjects(java.util.Collection subjects, com.sun.xml.ws.policy.PolicyMap$ScopeMap scopeMap)
Add all subjects in the given map to the collection

param
subjects A collection that should hold subjects. The new subjects are added to the collection. Must not be {@code null}.
param
scopeMap A scope map that holds policy scopes. The subjects are retrieved from the scope objects.

        for (PolicyScope scope : scopeMap.getStoredScopes()) {
            final Collection<PolicySubject> scopedSubjects = scope.getPolicySubjects();
            subjects.addAll(scopedSubjects);
        }
    
private static PolicyMapKeycreateOperationOrInputOutputMessageKey(javax.xml.namespace.QName service, javax.xml.namespace.QName port, javax.xml.namespace.QName operation)

        if (service == null || port == null || operation == null) {
            throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0029_SERVICE_PORT_OPERATION_PARAM_MUST_NOT_BE_NULL(service, port, operation)));
        }
        
        return new PolicyMapKey(service, port, operation);
    
public static com.sun.xml.ws.policy.PolicyMapcreatePolicyMap(java.util.Collection mutators)
Creates new policy map instance and connects provided collection of policy map mutators to the created policy map.

param
mutators collection of mutators that should be connected to the newly created map.
return
new policy map instance (mutable via provided collection of mutators).

        final PolicyMap result = new PolicyMap();
        
        if (mutators != null && !mutators.isEmpty()) {
            for (PolicyMapMutator mutator : mutators) {
                mutator.connect(result);
            }
        }
        
        return result;
    
public static PolicyMapKeycreateWsdlEndpointScopeKey(javax.xml.namespace.QName service, javax.xml.namespace.QName port)
Creates an endpoint policy scope locator object, that serves as a access key into a {@code PolicyMap} where actual endpoint policy scope for given endpoint can be retrieved.

param
service qualified name of the service. Must not be {@code null}.
param
port qualified name of the endpoint. Must not be {@code null}.
throws
IllegalArgumentException in case service, port or operation parameter is {@code null}.

        if (service == null || port == null) {
            throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0033_SERVICE_AND_PORT_PARAM_MUST_NOT_BE_NULL(service, port)));
        }
        return new PolicyMapKey(service, port, null);
    
public static PolicyMapKeycreateWsdlFaultMessageScopeKey(javax.xml.namespace.QName service, javax.xml.namespace.QName port, javax.xml.namespace.QName operation, javax.xml.namespace.QName faultMessage)
Creates an fault message policy scope locator object identified by a bound operation, that serves as a access key into {@code PolicyMap} where actual fault message policy scope for given input message of a bound operation can be retrieved.

The method returns a key that is compliant with WSDL 1.1 Basic Profile Specification, according to which there should be no two operations with the same name in a single port type definition.

param
service qualified name of the service. Must not be {@code null}.
param
port qualified name of the endpoint. Must not be {@code null}.
param
operation qualified name of the operation. Must not be {@code null}.
param
faultMessage qualified name of the fault message. Must not be {@code null}.
throws
IllegalArgumentException in case service, port or operation parameter is {@code null}.

        if (service == null || port == null || operation == null || faultMessage == null) {
            throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0030_SERVICE_PORT_OPERATION_FAULT_MSG_PARAM_MUST_NOT_BE_NULL(service, port, operation, faultMessage)));
        }
        
        return new PolicyMapKey(service, port, operation, faultMessage);
    
public static PolicyMapKeycreateWsdlMessageScopeKey(javax.xml.namespace.QName service, javax.xml.namespace.QName port, javax.xml.namespace.QName operation)
Creates an input/output message policy scope locator object identified by a bound operation, that serves as a access key into {@code PolicyMap} where actual input/output message policy scope for given input message of a bound operation can be retrieved.

The method returns a key that is compliant with WSDL 1.1 Basic Profile Specification, according to which there should be no two operations with the same name in a single port type definition.

param
service qualified name of the service. Must not be {@code null}.
param
port qualified name of the endpoint. Must not be {@code null}.
param
operation qualified name of the operation. Must not be {@code null}.
throws
IllegalArgumentException in case service, port or operation parameter is {@code null}.

        return createOperationOrInputOutputMessageKey(service, port, operation);
    
public static PolicyMapKeycreateWsdlOperationScopeKey(javax.xml.namespace.QName service, javax.xml.namespace.QName port, javax.xml.namespace.QName operation)
Creates an operation policy scope locator object, that serves as a access key into a {@code PolicyMap} where actual operation policy scope for given bound operation can be retrieved.

param
service qualified name of the service. Must not be {@code null}.
param
port qualified name of the endpoint. Must not be {@code null}.
param
operation qualified name of the operation. Must not be {@code null}.
throws
IllegalArgumentException in case service, port or operation parameter is {@code null}.

        return createOperationOrInputOutputMessageKey(service, port, operation);
    
public static PolicyMapKeycreateWsdlServiceScopeKey(javax.xml.namespace.QName service)
Creates a service policy scope locator object, that serves as a access key into a {@code PolicyMap} where actual service policy scope for given service can be retrieved.

param
service qualified name of the service. Must not be {@code null}.
throws
IllegalArgumentException in case service, port or operation parameter is {@code null}.

        if (service == null) {
            throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0031_SERVICE_PARAM_MUST_NOT_BE_NULL()));
        }
        return new PolicyMapKey(service, null, null);
    
public java.util.CollectiongetAllEndpointScopeKeys()
Returns all endpoint scope keys stored in this policy map

return
collection of endpoint scope policy map keys stored in the map.

        return endpointMap.getAllKeys();
    
public java.util.CollectiongetAllFaultMessageScopeKeys()
Returns all fault message scope keys stored in this policy map

return
collection of input message scope policy map keys stored in the map.

        return faultMessageMap.getAllKeys();
    
public java.util.CollectiongetAllInputMessageScopeKeys()
Returns all input message scope keys stored in this policy map

return
collection of input message scope policy map keys stored in the map.

        return inputMessageMap.getAllKeys();
    
public java.util.CollectiongetAllOperationScopeKeys()
Returns all operation scope keys stored in this policy map

return
collection of operation scope policy map keys stored in the map.

        return operationMap.getAllKeys();
    
public java.util.CollectiongetAllOutputMessageScopeKeys()
Returns all output message scope keys stored in this policy map

return
collection of output message scope policy map keys stored in the map.

        return outputMessageMap.getAllKeys();
    
public java.util.CollectiongetAllServiceScopeKeys()
Returns all service scope keys stored in this policy map

return
collection of service scope policy map keys stored in the map.

        return serviceMap.getAllKeys();
    
public PolicygetEndpointEffectivePolicy(PolicyMapKey key, java.util.Collection namespaces)

        return endpointMap.getEffectivePolicy(key, namespaces);
    
public PolicygetEndpointEffectivePolicy(PolicyMapKey key)

        return endpointMap.getEffectivePolicy(key);
    
public PolicygetFaultMessageEffectivePolicy(PolicyMapKey key, java.util.Collection namespaces)

        return faultMessageMap.getEffectivePolicy(key, namespaces);
    
public PolicygetFaultMessageEffectivePolicy(PolicyMapKey key)

        return faultMessageMap.getEffectivePolicy(key);
    
public PolicygetInputMessageEffectivePolicy(PolicyMapKey key, java.util.Collection namespaces)

        return inputMessageMap.getEffectivePolicy(key, namespaces);
    
public PolicygetInputMessageEffectivePolicy(PolicyMapKey key)

        return inputMessageMap.getEffectivePolicy(key);
    
public PolicygetOperationEffectivePolicy(PolicyMapKey key, java.util.Collection namespaces)

        return operationMap.getEffectivePolicy(key, namespaces);
    
public PolicygetOperationEffectivePolicy(PolicyMapKey key)

        return operationMap.getEffectivePolicy(key);
    
public PolicygetOutputMessageEffectivePolicy(PolicyMapKey key, java.util.Collection namespaces)

        return outputMessageMap.getEffectivePolicy(key, namespaces);
    
public PolicygetOutputMessageEffectivePolicy(PolicyMapKey key)

        return outputMessageMap.getEffectivePolicy(key);
    
public java.util.CollectiongetPolicySubjects()
Returns all policy subjects contained by this map.

return
All policy subjects contained by this map

        final List<PolicySubject> subjects = new LinkedList<PolicySubject>();
        addSubjects(subjects, serviceMap);
        addSubjects(subjects, endpointMap);
        addSubjects(subjects, operationMap);
        addSubjects(subjects, inputMessageMap);
        addSubjects(subjects, outputMessageMap);
        addSubjects(subjects, faultMessageMap);
        return subjects;
    
public PolicygetServiceEffectivePolicy(PolicyMapKey key)

        return serviceMap.getEffectivePolicy(key);
    
public PolicygetServiceEffectivePolicy(PolicyMapKey key, java.util.Collection namespaces)

        return serviceMap.getEffectivePolicy(key, namespaces);
    
public booleanisEmpty()
Returns true if this map contains no key - policy pairs A null object key or policy constitutes a non-empty map.

return
true if this map contains no key - policy pairs

        return serviceMap.isEmpty() && endpointMap.isEmpty() &&
                operationMap.isEmpty() && inputMessageMap.isEmpty() &&
                outputMessageMap.isEmpty() && faultMessageMap.isEmpty();
    
public booleanisFaultMessageSubject(PolicySubject subject)

        for (PolicyScope scope : faultMessageMap.getStoredScopes()) {
            if (scope.getPolicySubjects().contains(subject)) {
                return true;
            }
        }
        return false;
    
public booleanisInputMessageSubject(PolicySubject subject)

        for (PolicyScope scope : inputMessageMap.getStoredScopes()) {
            if (scope.getPolicySubjects().contains(subject)) {
                return true;
            }
        }
        return false;
    
public booleanisOutputMessageSubject(PolicySubject subject)

        for (PolicyScope scope : outputMessageMap.getStoredScopes()) {
            if (scope.getPolicySubjects().contains(subject)) {
                return true;
            }
        }
        return false;
    
public java.util.Iteratoriterator()

        return new Iterator<Policy> () {
            private final Iterator<Iterator<Policy>> mainIterator;
            private Iterator<Policy> currentScopeIterator;
            
            { // instance initialization
                final Collection<Iterator<Policy>> scopeIterators = new ArrayList<Iterator<Policy>>(6);
                scopeIterators.add(serviceMap.iterator());
                scopeIterators.add(endpointMap.iterator());
                scopeIterators.add(operationMap.iterator());
                scopeIterators.add(inputMessageMap.iterator());
                scopeIterators.add(outputMessageMap.iterator());
                scopeIterators.add(faultMessageMap.iterator());
                
                mainIterator = scopeIterators.iterator();
                currentScopeIterator = mainIterator.next();
            }
            
            public boolean hasNext() {
                while (!currentScopeIterator.hasNext()) {
                    if (mainIterator.hasNext()) {
                        currentScopeIterator = mainIterator.next();
                    } else {
                        return false;
                    }
                }
                
                return true;
            }
            
            public Policy next() {
                if (hasNext()) {
                    return currentScopeIterator.next();
                }
                throw LOGGER.logSevereException(new NoSuchElementException(LocalizationMessages.WSP_0054_NO_MORE_ELEMS_IN_POLICY_MAP()));
            }
            
            public void remove() {
                throw LOGGER.logSevereException(new UnsupportedOperationException(LocalizationMessages.WSP_0034_REMOVE_OPERATION_NOT_SUPPORTED()));
            }
        };
    
voidputSubject(com.sun.xml.ws.policy.PolicyMap$ScopeType scopeType, PolicyMapKey key, PolicySubject subject)
Places new subject into policy map under the scope identified by it's type and policy map key.

param
scopeType the type of the scope the subject belongs to
param
key a policy map key to be used to store the subject
param
subject actual policy subject to be stored in the policy map
throw
IllegalArgumentException in case the scope type is not recognized.

        switch (scopeType) {
            case SERVICE:
                serviceMap.putSubject(key, subject);
                break;
            case ENDPOINT:
                endpointMap.putSubject(key, subject);
                break;
            case OPERATION:
                operationMap.putSubject(key, subject);
                break;
            case INPUT_MESSAGE:
                inputMessageMap.putSubject(key, subject);
                break;
            case OUTPUT_MESSAGE:
                outputMessageMap.putSubject(key, subject);
                break;
            case FAULT_MESSAGE:
                faultMessageMap.putSubject(key, subject);
                break;
            default:
                throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType)));
        }
    
voidsetNewEffectivePolicyForScope(com.sun.xml.ws.policy.PolicyMap$ScopeType scopeType, PolicyMapKey key, Policy newEffectivePolicy)
Replaces current effective policy on given scope (identified by a {@code key} parameter) with the new efective policy provided as a second input parameter. If no policy was defined for the presented key, the new policy is simply stored with the key.

param
scopeType the type of the scope the subject belongs to. Must not be {@code null}.
param
key identifier of the scope the effective policy should be replaced with the new one. Must not be {@code null}.
param
newEffectivePolicy the new policy to replace the old effective policy of the scope. Must not be {@code null}.
throw
IllegalArgumentException in case any of the input parameters is {@code null} or in case the scope type is not recognized.

        if (scopeType == null || key == null || newEffectivePolicy == null) {
            throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0062_INPUT_PARAMS_MUST_NOT_BE_NULL()));
        }
        
        switch (scopeType) {
            case SERVICE :
                serviceMap.setNewEffectivePolicy(key, newEffectivePolicy);
                break;
            case ENDPOINT :
                endpointMap.setNewEffectivePolicy(key, newEffectivePolicy);
                break;
            case OPERATION :
                operationMap.setNewEffectivePolicy(key, newEffectivePolicy);
                break;
            case INPUT_MESSAGE :
                inputMessageMap.setNewEffectivePolicy(key, newEffectivePolicy);
                break;
            case OUTPUT_MESSAGE :
                outputMessageMap.setNewEffectivePolicy(key, newEffectivePolicy);
                break;
            case FAULT_MESSAGE :
                faultMessageMap.setNewEffectivePolicy(key, newEffectivePolicy);
                break;
            default:
                throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType)));
        }
    
public java.lang.StringtoString()

        // TODO
        final StringBuffer result = new StringBuffer();
        if(null!=this.serviceMap) {
            result.append("\nServiceMap=").append(this.serviceMap);
        }
        if(null!=this.endpointMap) {
            result.append("\nEndpointMap=").append(this.endpointMap);
        }
        if(null!=this.operationMap) {
            result.append("\nOperationMap=").append(this.operationMap);
        }
        if(null!=this.inputMessageMap) {
            result.append("\nInputMessageMap=").append(this.inputMessageMap);
        }
        if(null!=this.outputMessageMap) {
            result.append("\nOutputMessageMap=").append(this.outputMessageMap);
        }
        if(null!=this.faultMessageMap) {
            result.append("\nFaultMessageMap=").append(this.faultMessageMap);
        }
        return result.toString();