25 |
25 |
26 package com.sun.xml.internal.ws.model.wsdl; |
26 package com.sun.xml.internal.ws.model.wsdl; |
27 |
27 |
28 import com.sun.istack.internal.NotNull; |
28 import com.sun.istack.internal.NotNull; |
29 import com.sun.xml.internal.ws.api.model.ParameterBinding; |
29 import com.sun.xml.internal.ws.api.model.ParameterBinding; |
30 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType; |
|
31 import com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage; |
30 import com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage; |
32 import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel; |
31 import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel; |
33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation; |
32 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation; |
34 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
|
35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType; |
33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType; |
36 import com.sun.xml.internal.ws.api.model.wsdl.WSDLService; |
34 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundOperation; |
|
35 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLBoundPortType; |
|
36 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLMessage; |
|
37 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel; |
|
38 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPart; |
|
39 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPort; |
|
40 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPortType; |
|
41 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLService; |
37 import com.sun.xml.internal.ws.policy.PolicyMap; |
42 import com.sun.xml.internal.ws.policy.PolicyMap; |
38 |
43 |
39 import javax.jws.WebParam.Mode; |
44 import javax.jws.WebParam.Mode; |
40 import javax.xml.namespace.QName; |
45 import javax.xml.namespace.QName; |
41 import java.net.URL; |
46 |
42 import java.util.Collections; |
47 import java.util.Collections; |
43 import java.util.HashMap; |
48 import java.util.HashMap; |
44 import java.util.Iterator; |
|
45 import java.util.LinkedHashMap; |
49 import java.util.LinkedHashMap; |
46 import java.util.Map; |
50 import java.util.Map; |
47 |
51 |
48 /** |
52 /** |
49 * Implementation of {@link WSDLModel} |
53 * Implementation of {@link WSDLModel} |
50 * |
54 * |
51 * @author Vivek Pandey |
55 * @author Vivek Pandey |
52 */ |
56 */ |
53 public final class WSDLModelImpl extends AbstractExtensibleImpl implements WSDLModel { |
57 public final class WSDLModelImpl extends AbstractExtensibleImpl implements EditableWSDLModel { |
54 private final Map<QName, WSDLMessageImpl> messages = new HashMap<QName, WSDLMessageImpl>(); |
58 private final Map<QName, EditableWSDLMessage> messages = new HashMap<QName, EditableWSDLMessage>(); |
55 private final Map<QName, WSDLPortTypeImpl> portTypes = new HashMap<QName, WSDLPortTypeImpl>(); |
59 private final Map<QName, EditableWSDLPortType> portTypes = new HashMap<QName, EditableWSDLPortType>(); |
56 private final Map<QName, WSDLBoundPortTypeImpl> bindings = new HashMap<QName, WSDLBoundPortTypeImpl>(); |
60 private final Map<QName, EditableWSDLBoundPortType> bindings = new HashMap<QName, EditableWSDLBoundPortType>(); |
57 private final Map<QName, WSDLServiceImpl> services = new LinkedHashMap<QName, WSDLServiceImpl>(); |
61 private final Map<QName, EditableWSDLService> services = new LinkedHashMap<QName, EditableWSDLService>(); |
58 |
62 |
59 private PolicyMap policyMap; |
63 private PolicyMap policyMap; |
60 private final Map<QName,WSDLBoundPortType> unmBindings |
64 private final Map<QName, EditableWSDLBoundPortType> unmBindings |
61 = Collections.<QName,WSDLBoundPortType>unmodifiableMap(bindings); |
65 = Collections.<QName, EditableWSDLBoundPortType>unmodifiableMap(bindings); |
62 |
66 |
63 |
67 |
64 public WSDLModelImpl(@NotNull String systemId) { |
68 public WSDLModelImpl(@NotNull String systemId) { |
65 super(systemId,-1); |
69 super(systemId,-1); |
66 } |
70 } |
70 */ |
74 */ |
71 public WSDLModelImpl() { |
75 public WSDLModelImpl() { |
72 super(null,-1); |
76 super(null,-1); |
73 } |
77 } |
74 |
78 |
75 public void addMessage(WSDLMessageImpl msg){ |
79 public void addMessage(EditableWSDLMessage msg){ |
76 messages.put(msg.getName(), msg); |
80 messages.put(msg.getName(), msg); |
77 } |
81 } |
78 |
82 |
79 public WSDLMessageImpl getMessage(QName name){ |
83 public EditableWSDLMessage getMessage(QName name){ |
80 return messages.get(name); |
84 return messages.get(name); |
81 } |
85 } |
82 |
86 |
83 public void addPortType(WSDLPortTypeImpl pt){ |
87 public void addPortType(EditableWSDLPortType pt){ |
84 portTypes.put(pt.getName(), pt); |
88 portTypes.put(pt.getName(), pt); |
85 } |
89 } |
86 |
90 |
87 public WSDLPortTypeImpl getPortType(QName name){ |
91 public EditableWSDLPortType getPortType(QName name){ |
88 return portTypes.get(name); |
92 return portTypes.get(name); |
89 } |
93 } |
90 |
94 |
91 public void addBinding(WSDLBoundPortTypeImpl boundPortType){ |
95 public void addBinding(EditableWSDLBoundPortType boundPortType){ |
92 assert !bindings.containsValue(boundPortType); |
96 assert !bindings.containsValue(boundPortType); |
93 bindings.put(boundPortType.getName(), boundPortType); |
97 bindings.put(boundPortType.getName(), boundPortType); |
94 } |
98 } |
95 |
99 |
96 public WSDLBoundPortTypeImpl getBinding(QName name){ |
100 public EditableWSDLBoundPortType getBinding(QName name){ |
97 return bindings.get(name); |
101 return bindings.get(name); |
98 } |
102 } |
99 |
103 |
100 public void addService(WSDLServiceImpl svc){ |
104 public void addService(EditableWSDLService svc){ |
101 services.put(svc.getName(), svc); |
105 services.put(svc.getName(), svc); |
102 } |
106 } |
103 |
107 |
104 public WSDLServiceImpl getService(QName name){ |
108 public EditableWSDLService getService(QName name){ |
105 return services.get(name); |
109 return services.get(name); |
106 } |
110 } |
107 |
111 |
108 public Map<QName, WSDLMessageImpl> getMessages() { |
112 public Map<QName, EditableWSDLMessage> getMessages() { |
109 return messages; |
113 return messages; |
110 } |
114 } |
111 |
115 |
112 public @NotNull Map<QName, WSDLPortTypeImpl> getPortTypes() { |
116 public @NotNull Map<QName, EditableWSDLPortType> getPortTypes() { |
113 return portTypes; |
117 return portTypes; |
114 } |
118 } |
115 |
119 |
116 public @NotNull Map<QName, WSDLBoundPortType> getBindings() { |
120 public @NotNull Map<QName, ? extends EditableWSDLBoundPortType> getBindings() { |
117 return unmBindings; |
121 return unmBindings; |
118 } |
122 } |
119 |
123 |
120 public @NotNull Map<QName, WSDLServiceImpl> getServices(){ |
124 public @NotNull Map<QName, EditableWSDLService> getServices(){ |
121 return services; |
125 return services; |
122 } |
126 } |
123 |
127 |
124 /** |
128 /** |
125 * Returns the first service QName from insertion order |
129 * Returns the first service QName from insertion order |
126 */ |
130 */ |
127 public QName getFirstServiceName(){ |
131 public QName getFirstServiceName(){ |
128 if(services.isEmpty()) |
132 if(services.isEmpty()) |
129 return null; |
133 return null; |
130 return services.values().iterator().next().getName(); |
134 return services.values().iterator().next().getName(); |
131 } |
|
132 |
|
133 /** |
|
134 * Returns first port QName from first service as per the insertion order |
|
135 */ |
|
136 public QName getFirstPortName(){ |
|
137 WSDLPort fp = getFirstPort(); |
|
138 if(fp==null) |
|
139 return null; |
|
140 else |
|
141 return fp.getName(); |
|
142 } |
|
143 |
|
144 private WSDLPort getFirstPort(){ |
|
145 if(services.isEmpty()) |
|
146 return null; |
|
147 WSDLService service = services.values().iterator().next(); |
|
148 Iterator<? extends WSDLPort> iter = service.getPorts().iterator(); |
|
149 WSDLPort port = iter.hasNext()?iter.next():null; |
|
150 return port; |
|
151 } |
|
152 |
|
153 /** |
|
154 * gets the first port in the wsdl which matches the serviceName and portType |
|
155 */ |
|
156 public WSDLPortImpl getMatchingPort(QName serviceName, QName portType){ |
|
157 return getService(serviceName).getMatchingPort(portType); |
|
158 } |
135 } |
159 |
136 |
160 /** |
137 /** |
161 * |
138 * |
162 * @param serviceName non-null service QName |
139 * @param serviceName non-null service QName |
163 * @param portName non-null port QName |
140 * @param portName non-null port QName |
164 * @return |
141 * @return |
165 * WSDLBoundOperation on success otherwise null. throws NPE if any of the parameters null |
142 * WSDLBoundOperation on success otherwise null. throws NPE if any of the parameters null |
166 */ |
143 */ |
167 public WSDLBoundPortTypeImpl getBinding(QName serviceName, QName portName){ |
144 public EditableWSDLBoundPortType getBinding(QName serviceName, QName portName){ |
168 WSDLServiceImpl service = services.get(serviceName); |
145 EditableWSDLService service = services.get(serviceName); |
169 if(service != null){ |
146 if(service != null){ |
170 WSDLPortImpl port = service.get(portName); |
147 EditableWSDLPort port = service.get(portName); |
171 if(port != null) |
148 if(port != null) |
172 return port.getBinding(); |
149 return port.getBinding(); |
173 } |
150 } |
174 return null; |
151 return null; |
175 } |
152 } |
176 |
153 |
177 void finalizeRpcLitBinding(WSDLBoundPortTypeImpl boundPortType){ |
154 public void finalizeRpcLitBinding(EditableWSDLBoundPortType boundPortType){ |
178 assert(boundPortType != null); |
155 assert(boundPortType != null); |
179 QName portTypeName = boundPortType.getPortTypeName(); |
156 QName portTypeName = boundPortType.getPortTypeName(); |
180 if(portTypeName == null) |
157 if(portTypeName == null) |
181 return; |
158 return; |
182 WSDLPortType pt = portTypes.get(portTypeName); |
159 WSDLPortType pt = portTypes.get(portTypeName); |
183 if(pt == null) |
160 if(pt == null) |
184 return; |
161 return; |
185 for (WSDLBoundOperationImpl bop : boundPortType.getBindingOperations()) { |
162 for (EditableWSDLBoundOperation bop : boundPortType.getBindingOperations()) { |
186 WSDLOperation pto = pt.get(bop.getName().getLocalPart()); |
163 WSDLOperation pto = pt.get(bop.getName().getLocalPart()); |
187 WSDLMessage inMsgName = pto.getInput().getMessage(); |
164 WSDLMessage inMsgName = pto.getInput().getMessage(); |
188 if(inMsgName == null) |
165 if(inMsgName == null) |
189 continue; |
166 continue; |
190 WSDLMessageImpl inMsg = messages.get(inMsgName.getName()); |
167 EditableWSDLMessage inMsg = messages.get(inMsgName.getName()); |
191 int bodyindex = 0; |
168 int bodyindex = 0; |
192 if(inMsg != null){ |
169 if(inMsg != null){ |
193 for(WSDLPartImpl part:inMsg.parts()){ |
170 for(EditableWSDLPart part:inMsg.parts()){ |
194 String name = part.getName(); |
171 String name = part.getName(); |
195 ParameterBinding pb = bop.getInputBinding(name); |
172 ParameterBinding pb = bop.getInputBinding(name); |
196 if(pb.isBody()){ |
173 if(pb.isBody()){ |
197 part.setIndex(bodyindex++); |
174 part.setIndex(bodyindex++); |
198 part.setBinding(pb); |
175 part.setBinding(pb); |