Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.model.wsdl; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.istack.internal.NotNull; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.api.model.ParameterBinding; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundOperation; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundPortType; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLMessage; |
aoqi@0 | 37 | import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel; |
aoqi@0 | 38 | import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPart; |
aoqi@0 | 39 | import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPort; |
aoqi@0 | 40 | import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPortType; |
aoqi@0 | 41 | import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLService; |
aoqi@0 | 42 | import com.sun.xml.internal.ws.policy.PolicyMap; |
aoqi@0 | 43 | |
aoqi@0 | 44 | import javax.jws.WebParam.Mode; |
aoqi@0 | 45 | import javax.xml.namespace.QName; |
aoqi@0 | 46 | |
aoqi@0 | 47 | import java.util.Collections; |
aoqi@0 | 48 | import java.util.HashMap; |
aoqi@0 | 49 | import java.util.LinkedHashMap; |
aoqi@0 | 50 | import java.util.Map; |
aoqi@0 | 51 | |
aoqi@0 | 52 | /** |
aoqi@0 | 53 | * Implementation of {@link WSDLModel} |
aoqi@0 | 54 | * |
aoqi@0 | 55 | * @author Vivek Pandey |
aoqi@0 | 56 | */ |
aoqi@0 | 57 | public final class WSDLModelImpl extends AbstractExtensibleImpl implements EditableWSDLModel { |
aoqi@0 | 58 | private final Map<QName, EditableWSDLMessage> messages = new HashMap<QName, EditableWSDLMessage>(); |
aoqi@0 | 59 | private final Map<QName, EditableWSDLPortType> portTypes = new HashMap<QName, EditableWSDLPortType>(); |
aoqi@0 | 60 | private final Map<QName, EditableWSDLBoundPortType> bindings = new HashMap<QName, EditableWSDLBoundPortType>(); |
aoqi@0 | 61 | private final Map<QName, EditableWSDLService> services = new LinkedHashMap<QName, EditableWSDLService>(); |
aoqi@0 | 62 | |
aoqi@0 | 63 | private PolicyMap policyMap; |
aoqi@0 | 64 | private final Map<QName, EditableWSDLBoundPortType> unmBindings |
aoqi@0 | 65 | = Collections.<QName, EditableWSDLBoundPortType>unmodifiableMap(bindings); |
aoqi@0 | 66 | |
aoqi@0 | 67 | |
aoqi@0 | 68 | public WSDLModelImpl(@NotNull String systemId) { |
aoqi@0 | 69 | super(systemId,-1); |
aoqi@0 | 70 | } |
aoqi@0 | 71 | |
aoqi@0 | 72 | /** |
aoqi@0 | 73 | * To create {@link WSDLModelImpl} from WSDL that doesn't have a system ID. |
aoqi@0 | 74 | */ |
aoqi@0 | 75 | public WSDLModelImpl() { |
aoqi@0 | 76 | super(null,-1); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | public void addMessage(EditableWSDLMessage msg){ |
aoqi@0 | 80 | messages.put(msg.getName(), msg); |
aoqi@0 | 81 | } |
aoqi@0 | 82 | |
aoqi@0 | 83 | public EditableWSDLMessage getMessage(QName name){ |
aoqi@0 | 84 | return messages.get(name); |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | public void addPortType(EditableWSDLPortType pt){ |
aoqi@0 | 88 | portTypes.put(pt.getName(), pt); |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | public EditableWSDLPortType getPortType(QName name){ |
aoqi@0 | 92 | return portTypes.get(name); |
aoqi@0 | 93 | } |
aoqi@0 | 94 | |
aoqi@0 | 95 | public void addBinding(EditableWSDLBoundPortType boundPortType){ |
aoqi@0 | 96 | assert !bindings.containsValue(boundPortType); |
aoqi@0 | 97 | bindings.put(boundPortType.getName(), boundPortType); |
aoqi@0 | 98 | } |
aoqi@0 | 99 | |
aoqi@0 | 100 | public EditableWSDLBoundPortType getBinding(QName name){ |
aoqi@0 | 101 | return bindings.get(name); |
aoqi@0 | 102 | } |
aoqi@0 | 103 | |
aoqi@0 | 104 | public void addService(EditableWSDLService svc){ |
aoqi@0 | 105 | services.put(svc.getName(), svc); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | public EditableWSDLService getService(QName name){ |
aoqi@0 | 109 | return services.get(name); |
aoqi@0 | 110 | } |
aoqi@0 | 111 | |
aoqi@0 | 112 | public Map<QName, EditableWSDLMessage> getMessages() { |
aoqi@0 | 113 | return messages; |
aoqi@0 | 114 | } |
aoqi@0 | 115 | |
aoqi@0 | 116 | public @NotNull Map<QName, EditableWSDLPortType> getPortTypes() { |
aoqi@0 | 117 | return portTypes; |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | public @NotNull Map<QName, ? extends EditableWSDLBoundPortType> getBindings() { |
aoqi@0 | 121 | return unmBindings; |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | public @NotNull Map<QName, EditableWSDLService> getServices(){ |
aoqi@0 | 125 | return services; |
aoqi@0 | 126 | } |
aoqi@0 | 127 | |
aoqi@0 | 128 | /** |
aoqi@0 | 129 | * Returns the first service QName from insertion order |
aoqi@0 | 130 | */ |
aoqi@0 | 131 | public QName getFirstServiceName(){ |
aoqi@0 | 132 | if(services.isEmpty()) |
aoqi@0 | 133 | return null; |
aoqi@0 | 134 | return services.values().iterator().next().getName(); |
aoqi@0 | 135 | } |
aoqi@0 | 136 | |
aoqi@0 | 137 | /** |
aoqi@0 | 138 | * |
aoqi@0 | 139 | * @param serviceName non-null service QName |
aoqi@0 | 140 | * @param portName non-null port QName |
aoqi@0 | 141 | * @return |
aoqi@0 | 142 | * WSDLBoundOperation on success otherwise null. throws NPE if any of the parameters null |
aoqi@0 | 143 | */ |
aoqi@0 | 144 | public EditableWSDLBoundPortType getBinding(QName serviceName, QName portName){ |
aoqi@0 | 145 | EditableWSDLService service = services.get(serviceName); |
aoqi@0 | 146 | if(service != null){ |
aoqi@0 | 147 | EditableWSDLPort port = service.get(portName); |
aoqi@0 | 148 | if(port != null) |
aoqi@0 | 149 | return port.getBinding(); |
aoqi@0 | 150 | } |
aoqi@0 | 151 | return null; |
aoqi@0 | 152 | } |
aoqi@0 | 153 | |
aoqi@0 | 154 | public void finalizeRpcLitBinding(EditableWSDLBoundPortType boundPortType){ |
aoqi@0 | 155 | assert(boundPortType != null); |
aoqi@0 | 156 | QName portTypeName = boundPortType.getPortTypeName(); |
aoqi@0 | 157 | if(portTypeName == null) |
aoqi@0 | 158 | return; |
aoqi@0 | 159 | WSDLPortType pt = portTypes.get(portTypeName); |
aoqi@0 | 160 | if(pt == null) |
aoqi@0 | 161 | return; |
aoqi@0 | 162 | for (EditableWSDLBoundOperation bop : boundPortType.getBindingOperations()) { |
aoqi@0 | 163 | WSDLOperation pto = pt.get(bop.getName().getLocalPart()); |
aoqi@0 | 164 | WSDLMessage inMsgName = pto.getInput().getMessage(); |
aoqi@0 | 165 | if(inMsgName == null) |
aoqi@0 | 166 | continue; |
aoqi@0 | 167 | EditableWSDLMessage inMsg = messages.get(inMsgName.getName()); |
aoqi@0 | 168 | int bodyindex = 0; |
aoqi@0 | 169 | if(inMsg != null){ |
aoqi@0 | 170 | for(EditableWSDLPart part:inMsg.parts()){ |
aoqi@0 | 171 | String name = part.getName(); |
aoqi@0 | 172 | ParameterBinding pb = bop.getInputBinding(name); |
aoqi@0 | 173 | if(pb.isBody()){ |
aoqi@0 | 174 | part.setIndex(bodyindex++); |
aoqi@0 | 175 | part.setBinding(pb); |
aoqi@0 | 176 | bop.addPart(part, Mode.IN); |
aoqi@0 | 177 | } |
aoqi@0 | 178 | } |
aoqi@0 | 179 | } |
aoqi@0 | 180 | bodyindex=0; |
aoqi@0 | 181 | if(pto.isOneWay()) |
aoqi@0 | 182 | continue; |
aoqi@0 | 183 | WSDLMessage outMsgName = pto.getOutput().getMessage(); |
aoqi@0 | 184 | if(outMsgName == null) |
aoqi@0 | 185 | continue; |
aoqi@0 | 186 | EditableWSDLMessage outMsg = messages.get(outMsgName.getName()); |
aoqi@0 | 187 | if(outMsg!= null){ |
aoqi@0 | 188 | for(EditableWSDLPart part:outMsg.parts()){ |
aoqi@0 | 189 | String name = part.getName(); |
aoqi@0 | 190 | ParameterBinding pb = bop.getOutputBinding(name); |
aoqi@0 | 191 | if(pb.isBody()){ |
aoqi@0 | 192 | part.setIndex(bodyindex++); |
aoqi@0 | 193 | part.setBinding(pb); |
aoqi@0 | 194 | bop.addPart(part, Mode.OUT); |
aoqi@0 | 195 | } |
aoqi@0 | 196 | } |
aoqi@0 | 197 | } |
aoqi@0 | 198 | } |
aoqi@0 | 199 | } |
aoqi@0 | 200 | |
aoqi@0 | 201 | /** |
aoqi@0 | 202 | * Gives the PolicyMap associated with the WSDLModel |
aoqi@0 | 203 | * |
aoqi@0 | 204 | * @return PolicyMap |
aoqi@0 | 205 | */ |
aoqi@0 | 206 | public PolicyMap getPolicyMap() { |
aoqi@0 | 207 | return policyMap; |
aoqi@0 | 208 | } |
aoqi@0 | 209 | |
aoqi@0 | 210 | /** |
aoqi@0 | 211 | * Set PolicyMap for the WSDLModel. |
aoqi@0 | 212 | * @param policyMap |
aoqi@0 | 213 | */ |
aoqi@0 | 214 | public void setPolicyMap(PolicyMap policyMap) { |
aoqi@0 | 215 | this.policyMap = policyMap; |
aoqi@0 | 216 | } |
aoqi@0 | 217 | |
aoqi@0 | 218 | /** |
aoqi@0 | 219 | * Invoked at the end of the model construction to fix up references, etc. |
aoqi@0 | 220 | */ |
aoqi@0 | 221 | public void freeze() { |
aoqi@0 | 222 | for (EditableWSDLService service : services.values()) { |
aoqi@0 | 223 | service.freeze(this); |
aoqi@0 | 224 | } |
aoqi@0 | 225 | for (EditableWSDLBoundPortType bp : bindings.values()) { |
aoqi@0 | 226 | bp.freeze(); |
aoqi@0 | 227 | } |
aoqi@0 | 228 | // Enforce freeze all the portTypes referenced by this endpoints, see Bug8966673 for detail |
aoqi@0 | 229 | for (EditableWSDLPortType pt : portTypes.values()) { |
aoqi@0 | 230 | pt.freeze(); |
aoqi@0 | 231 | } |
aoqi@0 | 232 | } |
aoqi@0 | 233 | } |