|
Lines 13-25
Link Here
|
| 13 |
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal; |
13 |
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal; |
| 14 |
|
14 |
|
| 15 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
|
|
16 |
import java.util.Arrays; |
| 16 |
import java.util.Iterator; |
17 |
import java.util.Iterator; |
| 17 |
import java.util.LinkedList; |
18 |
import java.util.LinkedList; |
| 18 |
import java.util.List; |
19 |
import java.util.List; |
| 19 |
import java.util.Map; |
20 |
import java.util.Map; |
|
|
21 |
import java.util.Vector; |
| 20 |
|
22 |
|
| 21 |
import javax.wsdl.Definition; |
23 |
import javax.wsdl.Definition; |
| 22 |
import javax.wsdl.Fault; |
24 |
import javax.wsdl.Fault; |
|
|
25 |
import javax.wsdl.Import; |
| 23 |
import javax.wsdl.Input; |
26 |
import javax.wsdl.Input; |
| 24 |
import javax.wsdl.Message; |
27 |
import javax.wsdl.Message; |
| 25 |
import javax.wsdl.Operation; |
28 |
import javax.wsdl.Operation; |
|
Lines 39-44
Link Here
|
| 39 |
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition; |
42 |
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition; |
| 40 |
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages; |
43 |
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages; |
| 41 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils; |
44 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils; |
|
|
45 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants; |
| 42 |
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils; |
46 |
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils; |
| 43 |
import org.eclipse.xsd.XSDElementDeclaration; |
47 |
import org.eclipse.xsd.XSDElementDeclaration; |
| 44 |
import org.eclipse.xsd.XSDImport; |
48 |
import org.eclipse.xsd.XSDImport; |
|
Lines 54-81
Link Here
|
| 54 |
public class ImportOperationCommand |
58 |
public class ImportOperationCommand |
| 55 |
{ |
59 |
{ |
| 56 |
private CapabilityDefinition _capabilityDefinition; |
60 |
private CapabilityDefinition _capabilityDefinition; |
|
|
61 |
private Definition _importDefinition; |
| 57 |
private Definition _definition; |
62 |
private Definition _definition; |
| 58 |
private Operation[] _importedOperations; |
63 |
private Operation[] _importedOperations; |
| 59 |
private URI _importedWsdlURI; |
64 |
private URI _importedWsdlURI; |
| 60 |
private List _newOperations; |
65 |
private List _newOperations; |
| 61 |
private IProgressMonitor _monitor; |
66 |
private IProgressMonitor _monitor; |
| 62 |
private XSDSchema[] _importedWsdlSchemas = new XSDSchema[0]; |
67 |
private XSDSchema[] _importedWsdlSchemas = new XSDSchema[0]; |
|
|
68 |
private QName WSA_ACTION_QNAME = new QName(WsdmConstants.WSA_URI, |
| 69 |
WsdmConstants.WSA_ACTION_NAME); |
| 63 |
|
70 |
|
| 64 |
/** |
71 |
/** |
| 65 |
* Creates a new object of this class. |
72 |
* Creates a new object of this class. |
| 66 |
*/ |
73 |
*/ |
| 67 |
public ImportOperationCommand(CapabilityDefinition capabilityDefinition, |
74 |
public ImportOperationCommand(CapabilityDefinition capabilityDefinition,Definition importDefinition, |
| 68 |
Operation[] importedOperations, URI importedWsdlURI, IProgressMonitor monitor) |
75 |
Operation[] importedOperations, URI importedWsdlURI, IProgressMonitor monitor) |
| 69 |
{ |
76 |
{ |
| 70 |
_capabilityDefinition = capabilityDefinition; |
77 |
_capabilityDefinition = capabilityDefinition; |
| 71 |
_definition = _capabilityDefinition.getDefinition(); |
78 |
_definition = _capabilityDefinition.getDefinition(); |
|
|
79 |
_importDefinition = importDefinition; |
| 72 |
_importedWsdlURI = importedWsdlURI; |
80 |
_importedWsdlURI = importedWsdlURI; |
| 73 |
_importedOperations = importedOperations; |
81 |
_importedOperations = importedOperations; |
| 74 |
_newOperations = new LinkedList(); |
82 |
_newOperations = new LinkedList(); |
| 75 |
_monitor = monitor; |
83 |
_monitor = monitor; |
| 76 |
_importedWsdlSchemas = loadSchemas(_importedWsdlURI); |
84 |
_importedWsdlSchemas = loadSchemas(); |
| 77 |
XSDSchema[] capabilityWsdlSchemas = _capabilityDefinition |
85 |
//XSDSchema[] capabilityWsdlSchemas = _capabilityDefinition.getXSDSchemas(); |
| 78 |
.getXSDSchemas(); |
|
|
| 79 |
// TODO |
86 |
// TODO |
| 80 |
/* |
87 |
/* |
| 81 |
* if(capabilityWsdlSchemas == null) // No wsdl types defined { Types |
88 |
* if(capabilityWsdlSchemas == null) // No wsdl types defined { Types |
|
Lines 90-99
Link Here
|
| 90 |
/** |
97 |
/** |
| 91 |
* Creates a new object of this class. |
98 |
* Creates a new object of this class. |
| 92 |
*/ |
99 |
*/ |
| 93 |
public ImportOperationCommand(CapabilityDefinition capabilityDefinition, |
100 |
public ImportOperationCommand(CapabilityDefinition capabilityDefinition,Definition importDefinition, |
| 94 |
Operation[] importedOperations, URI importedWsdlURI) |
101 |
Operation[] importedOperations, URI importedWsdlURI) |
| 95 |
{ |
102 |
{ |
| 96 |
this(capabilityDefinition, importedOperations, importedWsdlURI, null); |
103 |
this(capabilityDefinition, importDefinition, importedOperations, importedWsdlURI, null); |
| 97 |
} |
104 |
} |
| 98 |
|
105 |
|
| 99 |
/** |
106 |
/** |
|
Lines 103-108
Link Here
|
| 103 |
{ |
110 |
{ |
| 104 |
_monitor.beginTask(Messages.IMPORTING_OPERATIONS, |
111 |
_monitor.beginTask(Messages.IMPORTING_OPERATIONS, |
| 105 |
_importedOperations.length); |
112 |
_importedOperations.length); |
|
|
113 |
_definition.addNamespace(WsdmConstants.WSA_PREFIX, |
| 114 |
WsdmConstants.WSA_URI); |
| 106 |
for (int i = 0; i < _importedOperations.length; i++) |
115 |
for (int i = 0; i < _importedOperations.length; i++) |
| 107 |
{ |
116 |
{ |
| 108 |
String taskName = Messages.bind(Messages.IMPORTING_OPERATION, |
117 |
String taskName = Messages.bind(Messages.IMPORTING_OPERATION, |
|
Lines 142-157
Link Here
|
| 142 |
newInput.setMessage(newMessage); |
151 |
newInput.setMessage(newMessage); |
| 143 |
_capabilityDefinition.addMessage(newMessage); |
152 |
_capabilityDefinition.addMessage(newMessage); |
| 144 |
|
153 |
|
| 145 |
// TODO |
154 |
String action = getAction(newInput.getMessage()); |
| 146 |
/* |
155 |
newInput.setExtensionAttribute(WSA_ACTION_QNAME, action); |
| 147 |
* String opName = importedOperation.getName(); opName = |
156 |
} |
| 148 |
* opName.substring(0, 1).toUpperCase() + opName.substring(1); String |
157 |
|
| 149 |
* tns = _capabilityDefinition.getTargetNamespace(); |
158 |
private String getAction(Message message) |
| 150 |
* if(!tns.endsWith("/")) tns = tns+"/"; String action = |
159 |
{ |
| 151 |
* tns+opName+"Request"; |
160 |
String uri = message.getQName().getNamespaceURI(); |
| 152 |
* newInput.getElement().setAttributeNS(WsdmConstants.WSA_URI, |
161 |
String name = message.getQName().getLocalPart(); |
| 153 |
* WsdmConstants.WSA_ACTION_NAME, action); |
162 |
name = name.substring(0, 1).toUpperCase() + name.substring(1); |
| 154 |
*/ |
163 |
return uri + "/" + name; |
| 155 |
} |
164 |
} |
| 156 |
|
165 |
|
| 157 |
private void createNewOperationOutput(Operation newOperation, |
166 |
private void createNewOperationOutput(Operation newOperation, |
|
Lines 168-184
Link Here
|
| 168 |
Message newMessage = createNewMessage(importedMessage); |
177 |
Message newMessage = createNewMessage(importedMessage); |
| 169 |
newOutput.setMessage(newMessage); |
178 |
newOutput.setMessage(newMessage); |
| 170 |
_capabilityDefinition.addMessage(newMessage); |
179 |
_capabilityDefinition.addMessage(newMessage); |
| 171 |
|
180 |
|
| 172 |
// TODO |
181 |
String action = getAction(newOutput.getMessage()); |
| 173 |
/* |
182 |
newOutput.setExtensionAttribute(WSA_ACTION_QNAME, action); |
| 174 |
* String opName = importedOperation.getName(); opName = |
|
|
| 175 |
* opName.substring(0, 1).toUpperCase() + opName.substring(1); String |
| 176 |
* tns = _capabilityDefinition.getTargetNamespace(); |
| 177 |
* if(!tns.endsWith("/")) tns = tns+"/"; String action = |
| 178 |
* tns+opName+"Response"; |
| 179 |
* newOutput.getElement().setAttributeNS(WsdmConstants.WSA_URI, |
| 180 |
* WsdmConstants.WSA_ACTION_NAME, action); |
| 181 |
*/ |
| 182 |
} |
183 |
} |
| 183 |
|
184 |
|
| 184 |
private void createNewOperationFaults(Operation newOperation, |
185 |
private void createNewOperationFaults(Operation newOperation, |
|
Lines 220-243
Link Here
|
| 220 |
Part part = definition.createPart(); |
221 |
Part part = definition.createPart(); |
| 221 |
message.addPart(part); |
222 |
message.addPart(part); |
| 222 |
Part importedPart = (Part)importedMessage.getParts().values().iterator().next(); |
223 |
Part importedPart = (Part)importedMessage.getParts().values().iterator().next(); |
| 223 |
XSDSchema importedPartSchema = getImportedWSDLSchema(importedPart.getElementName().getNamespaceURI()); |
|
|
| 224 |
importSchemaForElement(importedPartSchema); |
| 225 |
String xsdNS = importedPart.getElementName().getNamespaceURI(); |
| 226 |
String elementName = importedPart.getElementName().getLocalPart(); |
| 227 |
XSDSchema elementSchema = _capabilityDefinition.getSchema(xsdNS); |
| 228 |
XSDElementDeclaration element = XsdUtils.getXSDElementDeclarationOfName(elementSchema, elementName); |
| 229 |
_capabilityDefinition.createOrFindPrefix(element.getTargetNamespace(), null); |
| 230 |
part.setName(importedPart.getName()); |
224 |
part.setName(importedPart.getName()); |
| 231 |
part.setElementName(new QName(xsdNS, elementName)); |
225 |
if(importedPart.getElementName()!=null) |
|
|
226 |
{ |
| 227 |
XSDSchema importedPartSchema = getImportedWSDLSchema(importedPart.getElementName().getNamespaceURI()); |
| 228 |
importSchemaForElement(importedPartSchema); |
| 229 |
String xsdNS = importedPart.getElementName().getNamespaceURI(); |
| 230 |
String elementName = importedPart.getElementName().getLocalPart(); |
| 231 |
XSDSchema elementSchema = _capabilityDefinition.getSchema(xsdNS); |
| 232 |
XSDElementDeclaration element = XsdUtils.getXSDElementDeclarationOfName(elementSchema, elementName); |
| 233 |
_capabilityDefinition.createOrFindPrefix(element.getTargetNamespace(), null); |
| 234 |
part.setElementName(new QName(xsdNS, elementName)); |
| 235 |
} |
| 236 |
else if(importedPart.getTypeName()!=null) |
| 237 |
{ |
| 238 |
String xsdNS = importedPart.getTypeName().getNamespaceURI(); |
| 239 |
String localName = importedPart.getTypeName().getLocalPart(); |
| 240 |
part.setTypeName(new QName(xsdNS, localName)); |
| 241 |
} |
| 232 |
return message; |
242 |
return message; |
| 233 |
} |
243 |
} |
| 234 |
|
244 |
|
| 235 |
private XSDSchema getImportedWSDLSchema(String namespace) |
245 |
private XSDSchema getImportedWSDLSchema(String namespace) |
| 236 |
{ |
246 |
{ |
| 237 |
for(int i=0;i<_importedWsdlSchemas.length;i++) |
247 |
for(int i=0;i<_importedWsdlSchemas.length;i++) |
| 238 |
{ |
|
|
| 239 |
if(_importedWsdlSchemas[i].getTargetNamespace().equals(namespace)) |
248 |
if(_importedWsdlSchemas[i].getTargetNamespace().equals(namespace)) |
| 240 |
return _importedWsdlSchemas[i]; |
249 |
return _importedWsdlSchemas[i]; |
|
|
250 |
|
| 251 |
for(int i=0;i<_importedWsdlSchemas.length;i++) |
| 252 |
{ |
| 253 |
XSDImport theImports[] = XsdUtils.getAllXSDImports(_importedWsdlSchemas[i]); |
| 254 |
for(int j=0;j<theImports.length;j++) |
| 255 |
if(theImports[j].getNamespace().equals(namespace)) |
| 256 |
return theImports[j].getResolvedSchema(); |
| 241 |
} |
257 |
} |
| 242 |
return null; |
258 |
return null; |
| 243 |
} |
259 |
} |
|
Lines 272-287
Link Here
|
| 272 |
XSDSchema copySchema = (XSDSchema) schema.cloneConcreteComponent(true, |
288 |
XSDSchema copySchema = (XSDSchema) schema.cloneConcreteComponent(true, |
| 273 |
false); |
289 |
false); |
| 274 |
List contents = copySchema.getContents(); |
290 |
List contents = copySchema.getContents(); |
|
|
291 |
List includes = new LinkedList(); |
| 292 |
List imports = new LinkedList(); |
| 275 |
for (int i = 0; i < contents.size(); i++) |
293 |
for (int i = 0; i < contents.size(); i++) |
| 276 |
{ |
294 |
{ |
| 277 |
if (contents.get(i) instanceof XSDInclude) |
295 |
if (contents.get(i) instanceof XSDInclude) |
| 278 |
contents.remove(i); |
296 |
includes.add(contents.get(i)); |
| 279 |
else if (contents.get(i) instanceof XSDImport) |
297 |
else if (contents.get(i) instanceof XSDImport) |
| 280 |
{ |
298 |
{ |
| 281 |
XSDImport theImport = (XSDImport) contents.get(i); |
299 |
XSDImport theImport = (XSDImport) contents.get(i); |
| 282 |
theImport.setSchemaLocation(null); |
300 |
theImport.setSchemaLocation(null); |
|
|
301 |
imports.add(theImport); |
| 283 |
} |
302 |
} |
| 284 |
} |
303 |
} |
|
|
304 |
contents.removeAll(includes); |
| 305 |
contents.removeAll(imports); |
| 306 |
contents.addAll(0, imports); |
| 285 |
copySchema.updateElement(true); |
307 |
copySchema.updateElement(true); |
| 286 |
return copySchema; |
308 |
return copySchema; |
| 287 |
} |
309 |
} |
|
Lines 292-297
Link Here
|
| 292 |
.toArray(new Operation[_newOperations.size()]); |
314 |
.toArray(new Operation[_newOperations.size()]); |
| 293 |
} |
315 |
} |
| 294 |
|
316 |
|
|
|
317 |
private XSDSchema[] loadSchemas() |
| 318 |
{ |
| 319 |
List schemasList = new LinkedList(); |
| 320 |
XSDSchema[] schemas = loadSchemas(_importedWsdlURI); |
| 321 |
schemasList.addAll(Arrays.asList(schemas)); |
| 322 |
|
| 323 |
Map importsMap = _importDefinition.getImports(); |
| 324 |
if(importsMap == null || importsMap.size() == 0) |
| 325 |
return (XSDSchema[]) schemasList.toArray(new XSDSchema[0]); |
| 326 |
|
| 327 |
Iterator it = importsMap.values().iterator(); |
| 328 |
while(it.hasNext()) |
| 329 |
{ |
| 330 |
Object object = it.next(); |
| 331 |
if(object instanceof Vector) |
| 332 |
{ |
| 333 |
Vector vector = (Vector) object; |
| 334 |
for(int i=0;i<vector.size();i++) |
| 335 |
{ |
| 336 |
Import wsdlImport = (Import) vector.get(i); |
| 337 |
String locationURI = wsdlImport.getLocationURI(); |
| 338 |
URI wsdlURI = URI.createURI(_importedWsdlURI.trimSegments(1).toString()+"/"+locationURI); |
| 339 |
XSDSchema[] importedSchemas = loadSchemas(wsdlURI); |
| 340 |
schemasList.addAll(Arrays.asList(importedSchemas)); |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
return (XSDSchema[]) schemasList.toArray(new XSDSchema[0]); |
| 346 |
} |
| 347 |
|
| 295 |
private XSDSchema[] loadSchemas(URI uri) |
348 |
private XSDSchema[] loadSchemas(URI uri) |
| 296 |
{ |
349 |
{ |
| 297 |
// Get a ResourceSet describing the XSD in the WSDL |
350 |
// Get a ResourceSet describing the XSD in the WSDL |