ohair@286: /* ohair@286: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.xml.internal.ws.api.policy; ohair@286: ohair@286: import com.sun.xml.internal.ws.policy.PolicyMap; ohair@286: import com.sun.xml.internal.ws.policy.PolicyMapMutator; ohair@286: import com.sun.xml.internal.ws.api.server.Container; ohair@286: import com.sun.istack.internal.Nullable; ohair@286: import java.util.Arrays; ohair@286: import java.util.Collection; ohair@286: import javax.xml.ws.WebServiceException; ohair@286: ohair@286: /** ohair@286: * PolicyResolver will be used to resolve the PolicyMap created by configuration understood by JAX-WS. ohair@286: * ohair@286: * Extensions of this can return effective PolicyMap after merge policies from other configurations. ohair@286: * @author Rama Pulavarthi ohair@286: */ ohair@286: public interface PolicyResolver { ohair@286: /** ohair@286: * Creates a PolicyResolver ohair@286: * ohair@286: * @param context ohair@286: * ServerContext that captures information useful for resolving Policy on server-side ohair@286: * ohair@286: * @return ohair@286: * A PolicyMap with single policy alternative that gets created after consulting various configuration models. ohair@286: * ohair@286: * @throws WebServiceException ohair@286: * If resolution failed ohair@286: */ ohair@286: PolicyMap resolve(ServerContext context) throws WebServiceException; ohair@286: ohair@286: /** ohair@286: * Creates a PolicyResolver ohair@286: * ohair@286: * @param context ohair@286: * ServerContext that captures information useful for resolving Policy on client-side ohair@286: * ohair@286: * @return ohair@286: * A PolicyMap with single policy alternative that gets created after consulting various configuration models. ohair@286: * ohair@286: * @throws WebServiceException ohair@286: * If resolution failed ohair@286: */ ohair@286: PolicyMap resolve(ClientContext context) throws WebServiceException; ohair@286: ohair@286: public class ServerContext { ohair@286: private final PolicyMap policyMap; ohair@286: private final Class endpointClass; ohair@286: private final Container container; ohair@286: private final boolean hasWsdl; ohair@286: private final Collection mutators; ohair@286: ohair@286: /** ohair@286: * The abstraction of PolicyMap is not finalized, and will change in few months. It is highly discouraged to use ohair@286: * PolicyMap until it is finalized. ohair@286: * ohair@286: * In presence of WSDL, JAX-WS by default creates PolicyMap from Policy Attachemnts in WSDL. ohair@286: * In absense of WSDL, JAX-WS creates PolicyMap from WebServiceFeatures configured on the endpoint implementation ohair@286: * ohair@286: * @param policyMap ohair@286: * PolicyMap created from PolicyAttachments in WSDL or Feature annotations on endpoint implementation class. ohair@286: * @param container ohair@286: * @param endpointClass ohair@286: * @param mutators ohair@286: * List of PolicyMapMutators that are run eventually when a PolicyMap is created ohair@286: */ ohair@286: public ServerContext(@Nullable PolicyMap policyMap, Container container, ohair@286: Class endpointClass, final PolicyMapMutator... mutators) { ohair@286: this.policyMap = policyMap; ohair@286: this.endpointClass = endpointClass; ohair@286: this.container = container; ohair@286: this.hasWsdl = true; ohair@286: this.mutators = Arrays.asList(mutators); ohair@286: } ohair@286: ohair@286: /** ohair@286: * The abstraction of PolicyMap is not finalized, and will change in few months. It is highly discouraged to use ohair@286: * PolicyMap until it is finalized. ohair@286: * ohair@286: * In presence of WSDL, JAX-WS by default creates PolicyMap from Policy Attachemnts in WSDL. ohair@286: * In absense of WSDL, JAX-WS creates PolicyMap from WebServiceFeatures configured on the endpoint implementation ohair@286: * ohair@286: * @param policyMap ohair@286: * PolicyMap created from PolicyAttachments in WSDL or Feature annotations on endpoint implementation class. ohair@286: * @param container ohair@286: * @param endpointClass ohair@286: * @param hasWsdl Set to true, if this service is bundled with WSDL, false otherwise ohair@286: * @param mutators ohair@286: * List of PolicyMapMutators that are run eventually when a PolicyMap is created ohair@286: */ ohair@286: public ServerContext(@Nullable PolicyMap policyMap, Container container, ohair@286: Class endpointClass, boolean hasWsdl, final PolicyMapMutator... mutators) { ohair@286: this.policyMap = policyMap; ohair@286: this.endpointClass = endpointClass; ohair@286: this.container = container; ohair@286: this.hasWsdl = hasWsdl; ohair@286: this.mutators = Arrays.asList(mutators); ohair@286: } ohair@286: ohair@286: public @Nullable PolicyMap getPolicyMap() { ohair@286: return policyMap; ohair@286: } ohair@286: ohair@286: public @Nullable Class getEndpointClass() { ohair@286: return endpointClass; ohair@286: } ohair@286: ohair@286: public Container getContainer() { ohair@286: return container; ohair@286: } ohair@286: ohair@286: /** ohair@286: * Return true, if this service is bundled with WSDL, false otherwise ohair@286: * @return ohair@286: */ ohair@286: public boolean hasWsdl() { ohair@286: return hasWsdl; ohair@286: } ohair@286: ohair@286: public Collection getMutators() { ohair@286: return mutators; ohair@286: } ohair@286: } ohair@286: ohair@286: public class ClientContext { ohair@286: private PolicyMap policyMap; ohair@286: private Container container; ohair@286: ohair@286: /** ohair@286: * The abstraction of PolicyMap is not finalized, and will change in few months. It is highly discouraged to use ohair@286: * PolicyMap until it is finalized. ohair@286: * ohair@286: * In presence of WSDL, JAX-WS by default creates PolicyMap from Policy Attachemnts in WSDL. ohair@286: * ohair@286: * @param policyMap PolicyMap created from PolicyAttachemnts in WSDL ohair@286: * @param container ohair@286: */ ohair@286: public ClientContext(@Nullable PolicyMap policyMap, Container container) { ohair@286: this.policyMap = policyMap; ohair@286: this.container = container; ohair@286: } ohair@286: ohair@286: public @Nullable PolicyMap getPolicyMap() { ohair@286: return policyMap; ohair@286: } ohair@286: ohair@286: public Container getContainer() { ohair@286: return container; ohair@286: } ohair@286: } ohair@286: }