Search in sources :

Example 1 with PolicyMapKeyConverter

use of com.sun.xml.ws.policy.subject.PolicyMapKeyConverter in project metro-jax-ws by eclipse-ee4j.

the class PolicyMapUtil method insertPolicies.

/**
 * Inserts all PolicySubjects of type WsdlBindingSubject into the given policy map.
 *
 * @param policyMap The policy map
 * @param policySubjects The policy subjects. The actual subject must have the
 *   type WsdlBindingSubject, otherwise it will not be processed.
 * @param serviceName The name of the current WSDL service
 * @param portName The name of the current WSDL port
 * @throws PolicyException Thrown if the effective policy of a policy subject
 *   could not be computed
 */
public static void insertPolicies(final PolicyMap policyMap, final Collection<PolicySubject> policySubjects, QName serviceName, QName portName) throws PolicyException {
    LOGGER.entering(policyMap, policySubjects, serviceName, portName);
    final HashMap<WsdlBindingSubject, Collection<Policy>> subjectToPolicies = new HashMap<>();
    for (PolicySubject subject : policySubjects) {
        final Object actualSubject = subject.getSubject();
        if (actualSubject instanceof WsdlBindingSubject) {
            final WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) actualSubject;
            final Collection<Policy> subjectPolicies = new LinkedList<>();
            subjectPolicies.add(subject.getEffectivePolicy(MERGER));
            final Collection<Policy> existingPolicies = subjectToPolicies.put(wsdlSubject, subjectPolicies);
            if (existingPolicies != null) {
                subjectPolicies.addAll(existingPolicies);
            }
        }
    }
    final PolicyMapKeyConverter converter = new PolicyMapKeyConverter(serviceName, portName);
    for (Entry<WsdlBindingSubject, Collection<Policy>> entry : subjectToPolicies.entrySet()) {
        WsdlBindingSubject wsdlSubject = entry.getKey();
        Collection<Policy> policySet = entry.getValue();
        final PolicySubject newSubject = new PolicySubject(wsdlSubject, policySet);
        PolicyMapKey mapKey = converter.getPolicyMapKey(wsdlSubject);
        if (wsdlSubject.isBindingSubject()) {
            policyMap.putSubject(ScopeType.ENDPOINT, mapKey, newSubject);
        } else if (wsdlSubject.isBindingOperationSubject()) {
            policyMap.putSubject(ScopeType.OPERATION, mapKey, newSubject);
        } else if (wsdlSubject.isBindingMessageSubject()) {
            switch(wsdlSubject.getMessageType()) {
                case INPUT:
                    policyMap.putSubject(ScopeType.INPUT_MESSAGE, mapKey, newSubject);
                    break;
                case OUTPUT:
                    policyMap.putSubject(ScopeType.OUTPUT_MESSAGE, mapKey, newSubject);
                    break;
                case FAULT:
                    policyMap.putSubject(ScopeType.FAULT_MESSAGE, mapKey, newSubject);
                    break;
                default:
                    break;
            }
        }
    }
    LOGGER.exiting();
}
Also used : HashMap(java.util.HashMap) PolicyMapKeyConverter(com.sun.xml.ws.policy.subject.PolicyMapKeyConverter) Collection(java.util.Collection) WsdlBindingSubject(com.sun.xml.ws.policy.subject.WsdlBindingSubject) LinkedList(java.util.LinkedList)

Aggregations

PolicyMapKeyConverter (com.sun.xml.ws.policy.subject.PolicyMapKeyConverter)1 WsdlBindingSubject (com.sun.xml.ws.policy.subject.WsdlBindingSubject)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1