|
Lines 12-28
Link Here
|
| 12 |
|
12 |
|
| 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; |
|
|
| 16 |
import java.util.Arrays; |
| 17 |
import java.util.Iterator; |
15 |
import java.util.Iterator; |
| 18 |
import java.util.LinkedList; |
16 |
import java.util.LinkedList; |
| 19 |
import java.util.List; |
17 |
import java.util.List; |
| 20 |
import java.util.Map; |
18 |
import java.util.Map; |
| 21 |
import java.util.Vector; |
|
|
| 22 |
|
19 |
|
| 23 |
import javax.wsdl.Definition; |
20 |
import javax.wsdl.Definition; |
| 24 |
import javax.wsdl.Fault; |
21 |
import javax.wsdl.Fault; |
| 25 |
import javax.wsdl.Import; |
|
|
| 26 |
import javax.wsdl.Input; |
22 |
import javax.wsdl.Input; |
| 27 |
import javax.wsdl.Message; |
23 |
import javax.wsdl.Message; |
| 28 |
import javax.wsdl.Operation; |
24 |
import javax.wsdl.Operation; |
|
Lines 31-54
Link Here
|
| 31 |
import javax.wsdl.PortType; |
27 |
import javax.wsdl.PortType; |
| 32 |
import javax.xml.namespace.QName; |
28 |
import javax.xml.namespace.QName; |
| 33 |
|
29 |
|
|
|
30 |
import org.apache.muse.core.Environment; |
| 31 |
import org.apache.muse.util.xml.XmlUtils; |
| 34 |
import org.eclipse.core.runtime.IProgressMonitor; |
32 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 35 |
import org.eclipse.core.runtime.NullProgressMonitor; |
33 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 36 |
import org.eclipse.emf.common.util.EList; |
|
|
| 37 |
import org.eclipse.emf.common.util.URI; |
34 |
import org.eclipse.emf.common.util.URI; |
| 38 |
import org.eclipse.emf.ecore.resource.Resource; |
35 |
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.EclipseEnvironment; |
| 39 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
|
|
| 40 |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| 41 |
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.wsdl.XSDSchemaMerger; |
| 42 |
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition; |
36 |
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition; |
| 43 |
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages; |
37 |
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages; |
| 44 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils; |
38 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils; |
| 45 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants; |
39 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants; |
| 46 |
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils; |
40 |
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils; |
| 47 |
import org.eclipse.xsd.XSDElementDeclaration; |
41 |
import org.eclipse.xsd.XSDElementDeclaration; |
| 48 |
import org.eclipse.xsd.XSDImport; |
|
|
| 49 |
import org.eclipse.xsd.XSDInclude; |
| 50 |
import org.eclipse.xsd.XSDSchema; |
42 |
import org.eclipse.xsd.XSDSchema; |
| 51 |
import org.eclipse.xsd.util.XSDResourceFactoryImpl; |
43 |
import org.w3c.dom.Document; |
|
|
44 |
import org.w3c.dom.Element; |
| 52 |
|
45 |
|
| 53 |
/** |
46 |
/** |
| 54 |
* Command class to import operations into the capability. |
47 |
* Command class to import operations into the capability. |
|
Lines 64-70
Link Here
|
| 64 |
private URI _importedWsdlURI; |
57 |
private URI _importedWsdlURI; |
| 65 |
private List _newOperations; |
58 |
private List _newOperations; |
| 66 |
private IProgressMonitor _monitor; |
59 |
private IProgressMonitor _monitor; |
| 67 |
private XSDSchema[] _importedWsdlSchemas = new XSDSchema[0]; |
|
|
| 68 |
private QName WSA_ACTION_QNAME = new QName(WsdmConstants.WSA_URI, |
60 |
private QName WSA_ACTION_QNAME = new QName(WsdmConstants.WSA_URI, |
| 69 |
WsdmConstants.WSA_ACTION_NAME); |
61 |
WsdmConstants.WSA_ACTION_NAME); |
| 70 |
|
62 |
|
|
Lines 81-87
Link Here
|
| 81 |
_importedOperations = importedOperations; |
73 |
_importedOperations = importedOperations; |
| 82 |
_newOperations = new LinkedList(); |
74 |
_newOperations = new LinkedList(); |
| 83 |
_monitor = monitor; |
75 |
_monitor = monitor; |
| 84 |
_importedWsdlSchemas = loadSchemas(); |
|
|
| 85 |
//XSDSchema[] capabilityWsdlSchemas = _capabilityDefinition.getXSDSchemas(); |
76 |
//XSDSchema[] capabilityWsdlSchemas = _capabilityDefinition.getXSDSchemas(); |
| 86 |
// TODO |
77 |
// TODO |
| 87 |
/* |
78 |
/* |
|
Lines 112-117
Link Here
|
| 112 |
_importedOperations.length); |
103 |
_importedOperations.length); |
| 113 |
_definition.addNamespace(WsdmConstants.WSA_PREFIX, |
104 |
_definition.addNamespace(WsdmConstants.WSA_PREFIX, |
| 114 |
WsdmConstants.WSA_URI); |
105 |
WsdmConstants.WSA_URI); |
|
|
106 |
createMergeWsdlForImportedWsdl(); |
| 115 |
for (int i = 0; i < _importedOperations.length; i++) |
107 |
for (int i = 0; i < _importedOperations.length; i++) |
| 116 |
{ |
108 |
{ |
| 117 |
String taskName = Messages.bind(Messages.IMPORTING_OPERATION, |
109 |
String taskName = Messages.bind(Messages.IMPORTING_OPERATION, |
|
Lines 224-231
Link Here
|
| 224 |
part.setName(importedPart.getName()); |
216 |
part.setName(importedPart.getName()); |
| 225 |
if(importedPart.getElementName()!=null) |
217 |
if(importedPart.getElementName()!=null) |
| 226 |
{ |
218 |
{ |
| 227 |
XSDSchema importedPartSchema = getImportedWSDLSchema(importedPart.getElementName().getNamespaceURI()); |
|
|
| 228 |
importSchemaForElement(importedPartSchema); |
| 229 |
String xsdNS = importedPart.getElementName().getNamespaceURI(); |
219 |
String xsdNS = importedPart.getElementName().getNamespaceURI(); |
| 230 |
String elementName = importedPart.getElementName().getLocalPart(); |
220 |
String elementName = importedPart.getElementName().getLocalPart(); |
| 231 |
XSDSchema elementSchema = _capabilityDefinition.getSchema(xsdNS); |
221 |
XSDSchema elementSchema = _capabilityDefinition.getSchema(xsdNS); |
|
Lines 242-371
Link Here
|
| 242 |
return message; |
232 |
return message; |
| 243 |
} |
233 |
} |
| 244 |
|
234 |
|
| 245 |
private XSDSchema getImportedWSDLSchema(String namespace) |
|
|
| 246 |
{ |
| 247 |
for(int i=0;i<_importedWsdlSchemas.length;i++) |
| 248 |
if(_importedWsdlSchemas[i].getTargetNamespace().equals(namespace)) |
| 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(); |
| 257 |
} |
| 258 |
return null; |
| 259 |
} |
| 260 |
|
| 261 |
private void importSchemaForElement(XSDSchema elementSchema) |
| 262 |
{ |
| 263 |
XSDSchemaMerger merger = new XSDSchemaMerger(elementSchema); |
| 264 |
XSDSchema[] mergedSchemas = merger.merge(); |
| 265 |
for(int i=0;i<mergedSchemas.length;i++) |
| 266 |
{ |
| 267 |
if(!isSchemaExistsInWsdl(mergedSchemas[i])) |
| 268 |
{ |
| 269 |
XSDSchema copySchema = createCopy(mergedSchemas[i]); |
| 270 |
XSDSchema schema = _capabilityDefinition.createOrFindSchema(copySchema.getTargetNamespace()); |
| 271 |
schema.setElement(copySchema.getElement()); |
| 272 |
schema.updateElement(true); |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
private boolean isSchemaExistsInWsdl(XSDSchema schema) |
| 278 |
{ |
| 279 |
XSDSchema wsdlSchema = _capabilityDefinition.getSchema(schema |
| 280 |
.getTargetNamespace()); |
| 281 |
if (wsdlSchema != null) |
| 282 |
return true; |
| 283 |
return false; |
| 284 |
} |
| 285 |
|
| 286 |
private XSDSchema createCopy(XSDSchema schema) |
| 287 |
{ |
| 288 |
XSDSchema copySchema = (XSDSchema) schema.cloneConcreteComponent(true, |
| 289 |
false); |
| 290 |
List contents = copySchema.getContents(); |
| 291 |
List includes = new LinkedList(); |
| 292 |
List imports = new LinkedList(); |
| 293 |
for (int i = 0; i < contents.size(); i++) |
| 294 |
{ |
| 295 |
if (contents.get(i) instanceof XSDInclude) |
| 296 |
includes.add(contents.get(i)); |
| 297 |
else if (contents.get(i) instanceof XSDImport) |
| 298 |
{ |
| 299 |
XSDImport theImport = (XSDImport) contents.get(i); |
| 300 |
theImport.setSchemaLocation(null); |
| 301 |
imports.add(theImport); |
| 302 |
} |
| 303 |
} |
| 304 |
contents.removeAll(includes); |
| 305 |
contents.removeAll(imports); |
| 306 |
contents.addAll(0, imports); |
| 307 |
copySchema.updateElement(true); |
| 308 |
return copySchema; |
| 309 |
} |
| 310 |
|
| 311 |
public Operation[] getNewOperations() |
235 |
public Operation[] getNewOperations() |
| 312 |
{ |
236 |
{ |
| 313 |
return (Operation[]) _newOperations |
237 |
return (Operation[]) _newOperations |
| 314 |
.toArray(new Operation[_newOperations.size()]); |
238 |
.toArray(new Operation[_newOperations.size()]); |
| 315 |
} |
239 |
} |
| 316 |
|
240 |
|
| 317 |
private XSDSchema[] loadSchemas() |
241 |
private void createMergeWsdlForImportedWsdl() |
| 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 |
|
| 348 |
private XSDSchema[] loadSchemas(URI uri) |
| 349 |
{ |
242 |
{ |
| 350 |
// Get a ResourceSet describing the XSD in the WSDL |
243 |
Environment env = new EclipseEnvironment(); |
| 351 |
XSDSchema schema = null; |
244 |
String wsdlPath = _importedWsdlURI.toString(); |
| 352 |
ResourceSet resourceSet = new ResourceSetImpl(); |
245 |
Document mergedWsdl = org.apache.muse.ws.wsdl.WsdlUtils.createWSDL(env, wsdlPath, true); |
| 353 |
Resource resourceWsdl = null; |
246 |
Element root = XmlUtils.getFirstElement(mergedWsdl); |
| 354 |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() |
247 |
org.apache.muse.ws.wsdl.WsdlUtils.removeWsdlReferences(root); |
| 355 |
.put("*", new XSDResourceFactoryImpl()); |
248 |
org.apache.muse.ws.wsdl.WsdlUtils.removeSchemaReferences(root); |
| 356 |
resourceWsdl = resourceSet.getResource(uri, true); |
249 |
Element types = XmlUtils.getElement(root, org.apache.muse.ws.wsdl.WsdlUtils.TYPES_QNAME); |
| 357 |
EList list = resourceWsdl.getContents(); |
250 |
Element[] schemas = XmlUtils.getElements(types, org.apache.muse.util.xml.XsdUtils.SCHEMA_QNAME); |
| 358 |
|
251 |
Map namespacesMap = _importDefinition.getNamespaces(); |
| 359 |
List schemas = new ArrayList(); |
252 |
for(int i=0;i<schemas.length;i++) |
| 360 |
for (int i = 0; i < list.size(); i++) |
253 |
{ |
| 361 |
{ |
254 |
_capabilityDefinition.addSchema(schemas[i], namespacesMap); |
| 362 |
Object o = list.get(i); |
255 |
} |
| 363 |
if (o instanceof XSDSchema) |
|
|
| 364 |
{ |
| 365 |
schema = (XSDSchema) o; |
| 366 |
schemas.add(schema); |
| 367 |
} |
| 368 |
} |
| 369 |
return (XSDSchema[]) schemas.toArray(new XSDSchema[0]); |
| 370 |
} |
256 |
} |
| 371 |
} |
257 |
} |