src/share/jaxws_classes/com/sun/xml/internal/ws/policy/PolicyMapUtil.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/policy/PolicyMapUtil.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,133 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.policy;
    1.30 +
    1.31 +import com.sun.xml.internal.ws.policy.PolicyMap.ScopeType;
    1.32 +import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages;
    1.33 +import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
    1.34 +import com.sun.xml.internal.ws.policy.subject.PolicyMapKeyConverter;
    1.35 +import com.sun.xml.internal.ws.policy.subject.WsdlBindingSubject;
    1.36 +
    1.37 +import java.util.Collection;
    1.38 +import java.util.HashMap;
    1.39 +import java.util.LinkedList;
    1.40 +import javax.xml.namespace.QName;
    1.41 +
    1.42 +/**
    1.43 + * Utility methods that operate on a PolicyMap.
    1.44 + *
    1.45 + * @author Fabian Ritzmann
    1.46 + */
    1.47 +public class PolicyMapUtil {
    1.48 +
    1.49 +    private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyMapUtil.class);
    1.50 +
    1.51 +    private static final PolicyMerger MERGER = PolicyMerger.getMerger();
    1.52 +
    1.53 +    /**
    1.54 +     * Prevent instantiation.
    1.55 +     */
    1.56 +    private PolicyMapUtil() {
    1.57 +    }
    1.58 +
    1.59 +    /**
    1.60 +     * Throw an exception if the policy map contains any policy with at least two
    1.61 +     * policy alternatives.
    1.62 +     *
    1.63 +     * Optional assertions are not considered (unless they have been normalized into
    1.64 +     * two policy alternatives).
    1.65 +     *
    1.66 +     * @param map policy map to be processed
    1.67 +     * @throws PolicyException Thrown if the policy map contains at least one policy
    1.68 +     * with more than one policy alternative
    1.69 +     */
    1.70 +    public static void rejectAlternatives(final PolicyMap map) throws PolicyException {
    1.71 +        for (Policy policy : map) {
    1.72 +            if (policy.getNumberOfAssertionSets() > 1) {
    1.73 +                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0035_RECONFIGURE_ALTERNATIVES(policy.getIdOrName())));
    1.74 +            }
    1.75 +        }
    1.76 +    }
    1.77 +
    1.78 +    /**
    1.79 +     * Inserts all PolicySubjects of type WsdlBindingSubject into the given policy map.
    1.80 +     *
    1.81 +     * @param policyMap The policy map
    1.82 +     * @param policySubjects The policy subjects. The actual subject must have the
    1.83 +     *   type WsdlBindingSubject, otherwise it will not be processed.
    1.84 +     * @param serviceName The name of the current WSDL service
    1.85 +     * @param portName The name of the current WSDL port
    1.86 +     * @throws PolicyException Thrown if the effective policy of a policy subject
    1.87 +     *   could not be computed
    1.88 +     */
    1.89 +    public static void insertPolicies(final PolicyMap policyMap, final Collection<PolicySubject> policySubjects, QName serviceName, QName portName)
    1.90 +            throws PolicyException {
    1.91 +        LOGGER.entering(policyMap, policySubjects, serviceName, portName);
    1.92 +
    1.93 +        final HashMap<WsdlBindingSubject, Collection<Policy>> subjectToPolicies = new HashMap<WsdlBindingSubject, Collection<Policy>>();
    1.94 +        for (PolicySubject subject: policySubjects) {
    1.95 +            final Object actualSubject = subject.getSubject();
    1.96 +            if (actualSubject instanceof WsdlBindingSubject) {
    1.97 +                final WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) actualSubject;
    1.98 +                final Collection<Policy> subjectPolicies = new LinkedList<Policy>();
    1.99 +                subjectPolicies.add(subject.getEffectivePolicy(MERGER));
   1.100 +                final Collection<Policy> existingPolicies = subjectToPolicies.put(wsdlSubject, subjectPolicies);
   1.101 +                if (existingPolicies != null) {
   1.102 +                    subjectPolicies.addAll(existingPolicies);
   1.103 +                }
   1.104 +            }
   1.105 +        }
   1.106 +
   1.107 +        final PolicyMapKeyConverter converter = new PolicyMapKeyConverter(serviceName, portName);
   1.108 +        for (WsdlBindingSubject wsdlSubject : subjectToPolicies.keySet()) {
   1.109 +            final PolicySubject newSubject = new PolicySubject(wsdlSubject, subjectToPolicies.get(wsdlSubject));
   1.110 +            PolicyMapKey mapKey = converter.getPolicyMapKey(wsdlSubject);
   1.111 +
   1.112 +            if (wsdlSubject.isBindingSubject()) {
   1.113 +                policyMap.putSubject(ScopeType.ENDPOINT, mapKey, newSubject);
   1.114 +            }
   1.115 +            else if (wsdlSubject.isBindingOperationSubject()) {
   1.116 +                policyMap.putSubject(ScopeType.OPERATION, mapKey, newSubject);
   1.117 +            }
   1.118 +            else if (wsdlSubject.isBindingMessageSubject()) {
   1.119 +                switch (wsdlSubject.getMessageType()) {
   1.120 +                    case INPUT:
   1.121 +                        policyMap.putSubject(ScopeType.INPUT_MESSAGE, mapKey, newSubject);
   1.122 +                        break;
   1.123 +                    case OUTPUT:
   1.124 +                        policyMap.putSubject(ScopeType.OUTPUT_MESSAGE, mapKey, newSubject);
   1.125 +                        break;
   1.126 +                    case FAULT:
   1.127 +                        policyMap.putSubject(ScopeType.FAULT_MESSAGE, mapKey, newSubject);
   1.128 +                        break;
   1.129 +                }
   1.130 +            }
   1.131 +        }
   1.132 +
   1.133 +        LOGGER.exiting();
   1.134 +    }
   1.135 +
   1.136 +}

mercurial