ohair@286: /* mkos@408: * Copyright (c) 1997, 2013, 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.model.wsdl; ohair@286: ohair@286: import com.sun.istack.internal.NotNull; ohair@286: import com.sun.xml.internal.ws.api.model.ParameterBinding; ohair@286: import com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage; ohair@286: import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel; ohair@286: import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation; ohair@286: import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundOperation; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundPortType; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLMessage; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPart; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPort; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPortType; mkos@408: import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLService; ohair@286: import com.sun.xml.internal.ws.policy.PolicyMap; ohair@286: ohair@286: import javax.jws.WebParam.Mode; ohair@286: import javax.xml.namespace.QName; mkos@408: ohair@286: import java.util.Collections; ohair@286: import java.util.HashMap; ohair@286: import java.util.LinkedHashMap; ohair@286: import java.util.Map; ohair@286: ohair@286: /** ohair@286: * Implementation of {@link WSDLModel} ohair@286: * ohair@286: * @author Vivek Pandey ohair@286: */ mkos@408: public final class WSDLModelImpl extends AbstractExtensibleImpl implements EditableWSDLModel { mkos@408: private final Map messages = new HashMap(); mkos@408: private final Map portTypes = new HashMap(); mkos@408: private final Map bindings = new HashMap(); mkos@408: private final Map services = new LinkedHashMap(); ohair@286: ohair@286: private PolicyMap policyMap; mkos@408: private final Map unmBindings mkos@408: = Collections.unmodifiableMap(bindings); ohair@286: ohair@286: ohair@286: public WSDLModelImpl(@NotNull String systemId) { ohair@286: super(systemId,-1); ohair@286: } ohair@286: ohair@286: /** ohair@286: * To create {@link WSDLModelImpl} from WSDL that doesn't have a system ID. ohair@286: */ ohair@286: public WSDLModelImpl() { ohair@286: super(null,-1); ohair@286: } ohair@286: mkos@408: public void addMessage(EditableWSDLMessage msg){ ohair@286: messages.put(msg.getName(), msg); ohair@286: } ohair@286: mkos@408: public EditableWSDLMessage getMessage(QName name){ ohair@286: return messages.get(name); ohair@286: } ohair@286: mkos@408: public void addPortType(EditableWSDLPortType pt){ ohair@286: portTypes.put(pt.getName(), pt); ohair@286: } ohair@286: mkos@408: public EditableWSDLPortType getPortType(QName name){ ohair@286: return portTypes.get(name); ohair@286: } ohair@286: mkos@408: public void addBinding(EditableWSDLBoundPortType boundPortType){ ohair@286: assert !bindings.containsValue(boundPortType); ohair@286: bindings.put(boundPortType.getName(), boundPortType); ohair@286: } ohair@286: mkos@408: public EditableWSDLBoundPortType getBinding(QName name){ ohair@286: return bindings.get(name); ohair@286: } ohair@286: mkos@408: public void addService(EditableWSDLService svc){ ohair@286: services.put(svc.getName(), svc); ohair@286: } ohair@286: mkos@408: public EditableWSDLService getService(QName name){ ohair@286: return services.get(name); ohair@286: } ohair@286: mkos@408: public Map getMessages() { ohair@286: return messages; ohair@286: } ohair@286: mkos@408: public @NotNull Map getPortTypes() { ohair@286: return portTypes; ohair@286: } ohair@286: mkos@408: public @NotNull Map getBindings() { ohair@286: return unmBindings; ohair@286: } ohair@286: mkos@408: public @NotNull Map getServices(){ ohair@286: return services; ohair@286: } ohair@286: ohair@286: /** ohair@286: * Returns the first service QName from insertion order ohair@286: */ ohair@286: public QName getFirstServiceName(){ ohair@286: if(services.isEmpty()) ohair@286: return null; ohair@286: return services.values().iterator().next().getName(); ohair@286: } ohair@286: ohair@286: /** ohair@286: * ohair@286: * @param serviceName non-null service QName ohair@286: * @param portName non-null port QName ohair@286: * @return ohair@286: * WSDLBoundOperation on success otherwise null. throws NPE if any of the parameters null ohair@286: */ mkos@408: public EditableWSDLBoundPortType getBinding(QName serviceName, QName portName){ mkos@408: EditableWSDLService service = services.get(serviceName); ohair@286: if(service != null){ mkos@408: EditableWSDLPort port = service.get(portName); ohair@286: if(port != null) ohair@286: return port.getBinding(); ohair@286: } ohair@286: return null; ohair@286: } ohair@286: mkos@408: public void finalizeRpcLitBinding(EditableWSDLBoundPortType boundPortType){ ohair@286: assert(boundPortType != null); ohair@286: QName portTypeName = boundPortType.getPortTypeName(); ohair@286: if(portTypeName == null) ohair@286: return; ohair@286: WSDLPortType pt = portTypes.get(portTypeName); ohair@286: if(pt == null) ohair@286: return; mkos@408: for (EditableWSDLBoundOperation bop : boundPortType.getBindingOperations()) { ohair@286: WSDLOperation pto = pt.get(bop.getName().getLocalPart()); ohair@286: WSDLMessage inMsgName = pto.getInput().getMessage(); ohair@286: if(inMsgName == null) ohair@286: continue; mkos@408: EditableWSDLMessage inMsg = messages.get(inMsgName.getName()); ohair@286: int bodyindex = 0; ohair@286: if(inMsg != null){ mkos@408: for(EditableWSDLPart part:inMsg.parts()){ ohair@286: String name = part.getName(); ohair@286: ParameterBinding pb = bop.getInputBinding(name); ohair@286: if(pb.isBody()){ ohair@286: part.setIndex(bodyindex++); ohair@286: part.setBinding(pb); ohair@286: bop.addPart(part, Mode.IN); ohair@286: } ohair@286: } ohair@286: } ohair@286: bodyindex=0; ohair@286: if(pto.isOneWay()) ohair@286: continue; ohair@286: WSDLMessage outMsgName = pto.getOutput().getMessage(); ohair@286: if(outMsgName == null) ohair@286: continue; mkos@408: EditableWSDLMessage outMsg = messages.get(outMsgName.getName()); ohair@286: if(outMsg!= null){ mkos@408: for(EditableWSDLPart part:outMsg.parts()){ ohair@286: String name = part.getName(); ohair@286: ParameterBinding pb = bop.getOutputBinding(name); ohair@286: if(pb.isBody()){ ohair@286: part.setIndex(bodyindex++); ohair@286: part.setBinding(pb); ohair@286: bop.addPart(part, Mode.OUT); ohair@286: } ohair@286: } ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: /** ohair@286: * Gives the PolicyMap associated with the WSDLModel ohair@286: * ohair@286: * @return PolicyMap ohair@286: */ ohair@286: public PolicyMap getPolicyMap() { ohair@286: return policyMap; ohair@286: } ohair@286: ohair@286: /** ohair@286: * Set PolicyMap for the WSDLModel. ohair@286: * @param policyMap ohair@286: */ ohair@286: public void setPolicyMap(PolicyMap policyMap) { ohair@286: this.policyMap = policyMap; ohair@286: } ohair@286: ohair@286: /** ohair@286: * Invoked at the end of the model construction to fix up references, etc. ohair@286: */ ohair@286: public void freeze() { mkos@408: for (EditableWSDLService service : services.values()) { ohair@286: service.freeze(this); ohair@286: } mkos@408: for (EditableWSDLBoundPortType bp : bindings.values()) { ohair@286: bp.freeze(); ohair@286: } ohair@286: // Enforce freeze all the portTypes referenced by this endpoints, see Bug8966673 for detail mkos@408: for (EditableWSDLPortType pt : portTypes.values()) { ohair@286: pt.freeze(); ohair@286: } ohair@286: } ohair@286: }