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

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

ohair@286 1 /*
mkos@408 2 * Copyright (c) 1997, 2013, 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.WSDLMessage;
ohair@286 31 import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel;
ohair@286 32 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
ohair@286 33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType;
mkos@408 34 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundOperation;
mkos@408 35 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundPortType;
mkos@408 36 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLMessage;
mkos@408 37 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel;
mkos@408 38 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPart;
mkos@408 39 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPort;
mkos@408 40 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPortType;
mkos@408 41 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLService;
ohair@286 42 import com.sun.xml.internal.ws.policy.PolicyMap;
ohair@286 43
ohair@286 44 import javax.jws.WebParam.Mode;
ohair@286 45 import javax.xml.namespace.QName;
mkos@408 46
ohair@286 47 import java.util.Collections;
ohair@286 48 import java.util.HashMap;
ohair@286 49 import java.util.LinkedHashMap;
ohair@286 50 import java.util.Map;
ohair@286 51
ohair@286 52 /**
ohair@286 53 * Implementation of {@link WSDLModel}
ohair@286 54 *
ohair@286 55 * @author Vivek Pandey
ohair@286 56 */
mkos@408 57 public final class WSDLModelImpl extends AbstractExtensibleImpl implements EditableWSDLModel {
mkos@408 58 private final Map<QName, EditableWSDLMessage> messages = new HashMap<QName, EditableWSDLMessage>();
mkos@408 59 private final Map<QName, EditableWSDLPortType> portTypes = new HashMap<QName, EditableWSDLPortType>();
mkos@408 60 private final Map<QName, EditableWSDLBoundPortType> bindings = new HashMap<QName, EditableWSDLBoundPortType>();
mkos@408 61 private final Map<QName, EditableWSDLService> services = new LinkedHashMap<QName, EditableWSDLService>();
ohair@286 62
ohair@286 63 private PolicyMap policyMap;
mkos@408 64 private final Map<QName, EditableWSDLBoundPortType> unmBindings
mkos@408 65 = Collections.<QName, EditableWSDLBoundPortType>unmodifiableMap(bindings);
ohair@286 66
ohair@286 67
ohair@286 68 public WSDLModelImpl(@NotNull String systemId) {
ohair@286 69 super(systemId,-1);
ohair@286 70 }
ohair@286 71
ohair@286 72 /**
ohair@286 73 * To create {@link WSDLModelImpl} from WSDL that doesn't have a system ID.
ohair@286 74 */
ohair@286 75 public WSDLModelImpl() {
ohair@286 76 super(null,-1);
ohair@286 77 }
ohair@286 78
mkos@408 79 public void addMessage(EditableWSDLMessage msg){
ohair@286 80 messages.put(msg.getName(), msg);
ohair@286 81 }
ohair@286 82
mkos@408 83 public EditableWSDLMessage getMessage(QName name){
ohair@286 84 return messages.get(name);
ohair@286 85 }
ohair@286 86
mkos@408 87 public void addPortType(EditableWSDLPortType pt){
ohair@286 88 portTypes.put(pt.getName(), pt);
ohair@286 89 }
ohair@286 90
mkos@408 91 public EditableWSDLPortType getPortType(QName name){
ohair@286 92 return portTypes.get(name);
ohair@286 93 }
ohair@286 94
mkos@408 95 public void addBinding(EditableWSDLBoundPortType boundPortType){
ohair@286 96 assert !bindings.containsValue(boundPortType);
ohair@286 97 bindings.put(boundPortType.getName(), boundPortType);
ohair@286 98 }
ohair@286 99
mkos@408 100 public EditableWSDLBoundPortType getBinding(QName name){
ohair@286 101 return bindings.get(name);
ohair@286 102 }
ohair@286 103
mkos@408 104 public void addService(EditableWSDLService svc){
ohair@286 105 services.put(svc.getName(), svc);
ohair@286 106 }
ohair@286 107
mkos@408 108 public EditableWSDLService getService(QName name){
ohair@286 109 return services.get(name);
ohair@286 110 }
ohair@286 111
mkos@408 112 public Map<QName, EditableWSDLMessage> getMessages() {
ohair@286 113 return messages;
ohair@286 114 }
ohair@286 115
mkos@408 116 public @NotNull Map<QName, EditableWSDLPortType> getPortTypes() {
ohair@286 117 return portTypes;
ohair@286 118 }
ohair@286 119
mkos@408 120 public @NotNull Map<QName, ? extends EditableWSDLBoundPortType> getBindings() {
ohair@286 121 return unmBindings;
ohair@286 122 }
ohair@286 123
mkos@408 124 public @NotNull Map<QName, EditableWSDLService> getServices(){
ohair@286 125 return services;
ohair@286 126 }
ohair@286 127
ohair@286 128 /**
ohair@286 129 * Returns the first service QName from insertion order
ohair@286 130 */
ohair@286 131 public QName getFirstServiceName(){
ohair@286 132 if(services.isEmpty())
ohair@286 133 return null;
ohair@286 134 return services.values().iterator().next().getName();
ohair@286 135 }
ohair@286 136
ohair@286 137 /**
ohair@286 138 *
ohair@286 139 * @param serviceName non-null service QName
ohair@286 140 * @param portName non-null port QName
ohair@286 141 * @return
ohair@286 142 * WSDLBoundOperation on success otherwise null. throws NPE if any of the parameters null
ohair@286 143 */
mkos@408 144 public EditableWSDLBoundPortType getBinding(QName serviceName, QName portName){
mkos@408 145 EditableWSDLService service = services.get(serviceName);
ohair@286 146 if(service != null){
mkos@408 147 EditableWSDLPort port = service.get(portName);
ohair@286 148 if(port != null)
ohair@286 149 return port.getBinding();
ohair@286 150 }
ohair@286 151 return null;
ohair@286 152 }
ohair@286 153
mkos@408 154 public void finalizeRpcLitBinding(EditableWSDLBoundPortType boundPortType){
ohair@286 155 assert(boundPortType != null);
ohair@286 156 QName portTypeName = boundPortType.getPortTypeName();
ohair@286 157 if(portTypeName == null)
ohair@286 158 return;
ohair@286 159 WSDLPortType pt = portTypes.get(portTypeName);
ohair@286 160 if(pt == null)
ohair@286 161 return;
mkos@408 162 for (EditableWSDLBoundOperation bop : boundPortType.getBindingOperations()) {
ohair@286 163 WSDLOperation pto = pt.get(bop.getName().getLocalPart());
ohair@286 164 WSDLMessage inMsgName = pto.getInput().getMessage();
ohair@286 165 if(inMsgName == null)
ohair@286 166 continue;
mkos@408 167 EditableWSDLMessage inMsg = messages.get(inMsgName.getName());
ohair@286 168 int bodyindex = 0;
ohair@286 169 if(inMsg != null){
mkos@408 170 for(EditableWSDLPart part:inMsg.parts()){
ohair@286 171 String name = part.getName();
ohair@286 172 ParameterBinding pb = bop.getInputBinding(name);
ohair@286 173 if(pb.isBody()){
ohair@286 174 part.setIndex(bodyindex++);
ohair@286 175 part.setBinding(pb);
ohair@286 176 bop.addPart(part, Mode.IN);
ohair@286 177 }
ohair@286 178 }
ohair@286 179 }
ohair@286 180 bodyindex=0;
ohair@286 181 if(pto.isOneWay())
ohair@286 182 continue;
ohair@286 183 WSDLMessage outMsgName = pto.getOutput().getMessage();
ohair@286 184 if(outMsgName == null)
ohair@286 185 continue;
mkos@408 186 EditableWSDLMessage outMsg = messages.get(outMsgName.getName());
ohair@286 187 if(outMsg!= null){
mkos@408 188 for(EditableWSDLPart part:outMsg.parts()){
ohair@286 189 String name = part.getName();
ohair@286 190 ParameterBinding pb = bop.getOutputBinding(name);
ohair@286 191 if(pb.isBody()){
ohair@286 192 part.setIndex(bodyindex++);
ohair@286 193 part.setBinding(pb);
ohair@286 194 bop.addPart(part, Mode.OUT);
ohair@286 195 }
ohair@286 196 }
ohair@286 197 }
ohair@286 198 }
ohair@286 199 }
ohair@286 200
ohair@286 201 /**
ohair@286 202 * Gives the PolicyMap associated with the WSDLModel
ohair@286 203 *
ohair@286 204 * @return PolicyMap
ohair@286 205 */
ohair@286 206 public PolicyMap getPolicyMap() {
ohair@286 207 return policyMap;
ohair@286 208 }
ohair@286 209
ohair@286 210 /**
ohair@286 211 * Set PolicyMap for the WSDLModel.
ohair@286 212 * @param policyMap
ohair@286 213 */
ohair@286 214 public void setPolicyMap(PolicyMap policyMap) {
ohair@286 215 this.policyMap = policyMap;
ohair@286 216 }
ohair@286 217
ohair@286 218 /**
ohair@286 219 * Invoked at the end of the model construction to fix up references, etc.
ohair@286 220 */
ohair@286 221 public void freeze() {
mkos@408 222 for (EditableWSDLService service : services.values()) {
ohair@286 223 service.freeze(this);
ohair@286 224 }
mkos@408 225 for (EditableWSDLBoundPortType bp : bindings.values()) {
ohair@286 226 bp.freeze();
ohair@286 227 }
ohair@286 228 // Enforce freeze all the portTypes referenced by this endpoints, see Bug8966673 for detail
mkos@408 229 for (EditableWSDLPortType pt : portTypes.values()) {
ohair@286 230 pt.freeze();
ohair@286 231 }
ohair@286 232 }
ohair@286 233 }

mercurial