src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/WSDLModelImpl.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 408
b0610cd08440
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

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

mercurial