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.PolicyMap.ScopeType; 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 com.sun.xml.internal.ws.policy.subject.PolicyMapKeyConverter; aoqi@0: import com.sun.xml.internal.ws.policy.subject.WsdlBindingSubject; aoqi@0: aoqi@0: import java.util.Collection; aoqi@0: import java.util.HashMap; aoqi@0: import java.util.LinkedList; aoqi@0: import javax.xml.namespace.QName; aoqi@0: aoqi@0: /** aoqi@0: * Utility methods that operate on a PolicyMap. aoqi@0: * aoqi@0: * @author Fabian Ritzmann aoqi@0: */ aoqi@0: public class PolicyMapUtil { aoqi@0: aoqi@0: private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyMapUtil.class); aoqi@0: aoqi@0: private static final PolicyMerger MERGER = PolicyMerger.getMerger(); aoqi@0: aoqi@0: /** aoqi@0: * Prevent instantiation. aoqi@0: */ aoqi@0: private PolicyMapUtil() { aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Throw an exception if the policy map contains any policy with at least two aoqi@0: * policy alternatives. aoqi@0: * aoqi@0: * Optional assertions are not considered (unless they have been normalized into aoqi@0: * two policy alternatives). aoqi@0: * aoqi@0: * @param map policy map to be processed aoqi@0: * @throws PolicyException Thrown if the policy map contains at least one policy aoqi@0: * with more than one policy alternative aoqi@0: */ aoqi@0: public static void rejectAlternatives(final PolicyMap map) throws PolicyException { aoqi@0: for (Policy policy : map) { aoqi@0: if (policy.getNumberOfAssertionSets() > 1) { aoqi@0: throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0035_RECONFIGURE_ALTERNATIVES(policy.getIdOrName()))); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Inserts all PolicySubjects of type WsdlBindingSubject into the given policy map. aoqi@0: * aoqi@0: * @param policyMap The policy map aoqi@0: * @param policySubjects The policy subjects. The actual subject must have the aoqi@0: * type WsdlBindingSubject, otherwise it will not be processed. aoqi@0: * @param serviceName The name of the current WSDL service aoqi@0: * @param portName The name of the current WSDL port aoqi@0: * @throws PolicyException Thrown if the effective policy of a policy subject aoqi@0: * could not be computed aoqi@0: */ aoqi@0: public static void insertPolicies(final PolicyMap policyMap, final Collection policySubjects, QName serviceName, QName portName) aoqi@0: throws PolicyException { aoqi@0: LOGGER.entering(policyMap, policySubjects, serviceName, portName); aoqi@0: aoqi@0: final HashMap> subjectToPolicies = new HashMap>(); aoqi@0: for (PolicySubject subject: policySubjects) { aoqi@0: final Object actualSubject = subject.getSubject(); aoqi@0: if (actualSubject instanceof WsdlBindingSubject) { aoqi@0: final WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) actualSubject; aoqi@0: final Collection subjectPolicies = new LinkedList(); aoqi@0: subjectPolicies.add(subject.getEffectivePolicy(MERGER)); aoqi@0: final Collection existingPolicies = subjectToPolicies.put(wsdlSubject, subjectPolicies); aoqi@0: if (existingPolicies != null) { aoqi@0: subjectPolicies.addAll(existingPolicies); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: final PolicyMapKeyConverter converter = new PolicyMapKeyConverter(serviceName, portName); aoqi@0: for (WsdlBindingSubject wsdlSubject : subjectToPolicies.keySet()) { aoqi@0: final PolicySubject newSubject = new PolicySubject(wsdlSubject, subjectToPolicies.get(wsdlSubject)); aoqi@0: PolicyMapKey mapKey = converter.getPolicyMapKey(wsdlSubject); aoqi@0: aoqi@0: if (wsdlSubject.isBindingSubject()) { aoqi@0: policyMap.putSubject(ScopeType.ENDPOINT, mapKey, newSubject); aoqi@0: } aoqi@0: else if (wsdlSubject.isBindingOperationSubject()) { aoqi@0: policyMap.putSubject(ScopeType.OPERATION, mapKey, newSubject); aoqi@0: } aoqi@0: else if (wsdlSubject.isBindingMessageSubject()) { aoqi@0: switch (wsdlSubject.getMessageType()) { aoqi@0: case INPUT: aoqi@0: policyMap.putSubject(ScopeType.INPUT_MESSAGE, mapKey, newSubject); aoqi@0: break; aoqi@0: case OUTPUT: aoqi@0: policyMap.putSubject(ScopeType.OUTPUT_MESSAGE, mapKey, newSubject); aoqi@0: break; aoqi@0: case FAULT: aoqi@0: policyMap.putSubject(ScopeType.FAULT_MESSAGE, mapKey, newSubject); aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: LOGGER.exiting(); aoqi@0: } aoqi@0: aoqi@0: }