Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 165544 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/tptp/wsdm/model/WSDLDefinition.java (+42 lines)
Lines 31-38 Link Here
31
import org.eclipse.emf.ecore.resource.Resource;
31
import org.eclipse.emf.ecore.resource.Resource;
32
import org.eclipse.emf.ecore.resource.ResourceSet;
32
import org.eclipse.emf.ecore.resource.ResourceSet;
33
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
33
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
34
import org.eclipse.xsd.XSDFactory;
34
import org.eclipse.xsd.XSDSchema;
35
import org.eclipse.xsd.XSDSchema;
36
import org.eclipse.xsd.impl.XSDSchemaImpl;
35
import org.eclipse.xsd.util.XSDResourceFactoryImpl;
37
import org.eclipse.xsd.util.XSDResourceFactoryImpl;
38
import org.w3c.dom.Element;
36
39
37
/**
40
/**
38
 * Its a wrapper class for WSDL4j Definition object. 
41
 * Its a wrapper class for WSDL4j Definition object. 
Lines 362-365 Link Here
362
		}
365
		}
363
		return (XSDSchema[]) schemas.toArray(new XSDSchema[0]);
366
		return (XSDSchema[]) schemas.toArray(new XSDSchema[0]);
364
	}
367
	}
368
	
369
	public void addSchema(Element schemaElement, Map namespacesMap)
370
	{
371
		XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
372
		schema.setElement(schemaElement);
373
		if(namespacesMap!=null)
374
		{
375
			Iterator keyIt = namespacesMap.keySet().iterator();
376
			while(keyIt.hasNext())
377
			{
378
				String prefix = (String) keyIt.next();
379
				String namespace = (String) namespacesMap.get(prefix);
380
				if(!namespace.equals("http://www.w3.org/2001/XMLSchema"))
381
					if(!isPrefixDeclared(schema, prefix))
382
						schema.getQNamePrefixToNamespaceMap().put(prefix, namespace);
383
			}
384
		}
385
		schema.updateElement(true);
386
		namespacesMap = schema.getQNamePrefixToNamespaceMap();
387
		if(namespacesMap!=null)
388
		{
389
			Iterator keyIt = namespacesMap.keySet().iterator();
390
			while(keyIt.hasNext())
391
			{
392
				String prefix = (String) keyIt.next();
393
				String namespace = (String) namespacesMap.get(prefix);
394
				if(prefix!=null)
395
					if(!namespace.equals("http://www.w3.org/2001/XMLSchema"))
396
						schema.getElement().setAttribute("xmlns:"+prefix, namespace);
397
			}
398
		}		
399
		_definedSchemaList.add(schema);
400
	}
401
	
402
	private boolean isPrefixDeclared(XSDSchema schema, String prefix)
403
	{
404
		Map namespacesMap = schema.getQNamePrefixToNamespaceMap();
405
		return namespacesMap.get(prefix)!=null;
406
	} 
365
}
407
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/wsdl/XSDSchemaMerger.java (-108 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.imports.wsdl;
14
15
import java.util.LinkedList;
16
import java.util.List;
17
18
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
19
import org.eclipse.xsd.XSDImport;
20
import org.eclipse.xsd.XSDInclude;
21
import org.eclipse.xsd.XSDSchema;
22
23
/**
24
 * This merges the given XSD Schema and returns the array of new schemas.<br>
25
 * Array contains the original XSD schema and all the Imported schemas.<br>
26
 * All the included schmeas merged into original schema. 
27
 *
28
 */
29
30
public class XSDSchemaMerger
31
{
32
33
	private XSDSchema _schema;
34
	private List _allResultedSchema;
35
	private List _allAddedSchemaURIs;
36
37
	public XSDSchemaMerger(XSDSchema schema)
38
	{
39
		_schema = schema;
40
		_allResultedSchema = new LinkedList();
41
		_allAddedSchemaURIs = new LinkedList();
42
		addSchema(_schema);
43
	}
44
45
	public XSDSchema[] merge()
46
	{
47
		XSDImport[] imports = XsdUtils.getAllXSDImports(_schema);
48
		for (int i = 0; i < imports.length; i++)
49
		{
50
			if (imports[i].getResolvedSchema() == null)
51
				continue;
52
			addSchema(imports[i].getResolvedSchema());
53
			XSDSchemaMerger merger = new XSDSchemaMerger(imports[i]
54
					.getResolvedSchema());
55
			XSDSchema[] schemas = merger.merge();
56
			for (int j = 0; j < schemas.length; j++)
57
				addSchema(schemas[j]);
58
		}
59
60
		XSDInclude[] includes = XsdUtils.getAllXSDIncludes(_schema);
61
		for (int i = 0; i < includes.length; i++)
62
		{
63
			if (includes[i].getResolvedSchema() == null)
64
				continue;
65
			addSchema(includes[i].getResolvedSchema());
66
			XSDSchemaMerger merger = new XSDSchemaMerger(includes[i]
67
					.getResolvedSchema());
68
			XSDSchema[] schemas = merger.merge();
69
			for (int j = 0; j < schemas.length; j++)
70
				addSchema(schemas[j]);
71
		}
72
73
		return (XSDSchema[]) _allResultedSchema
74
				.toArray(new XSDSchema[_allResultedSchema.size()]);
75
	}
76
77
	private void addSchema(XSDSchema givenSchema)
78
	{
79
		if(isAlreadyAdded(givenSchema))
80
			return;
81
		XSDSchema clonedSchema = (XSDSchema) givenSchema.cloneConcreteComponent(true, true);
82
		clonedSchema.setSchemaLocation(givenSchema.getSchemaLocation());
83
		XSDSchema schema = getSchema(clonedSchema.getTargetNamespace());
84
		if (schema != null)
85
			schema.getContents().addAll(clonedSchema.getContents());
86
		else
87
			_allResultedSchema.add(clonedSchema);
88
		String schemaLocation = clonedSchema.getSchemaLocation();
89
		_allAddedSchemaURIs.add(schemaLocation);
90
	}
91
	
92
	private boolean isAlreadyAdded(XSDSchema givenSchema)
93
	{
94
		String schemaLocation = givenSchema.getSchemaLocation();
95
		return _allAddedSchemaURIs.contains(schemaLocation);
96
	}
97
98
	private XSDSchema getSchema(String targetNamespace)
99
	{
100
		for (int i = 0; i < _allResultedSchema.size(); i++)
101
		{
102
			XSDSchema schema = (XSDSchema) _allResultedSchema.get(i);
103
			if (schema.getTargetNamespace().equals(targetNamespace))
104
				return schema;
105
		}
106
		return null;
107
	}
108
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/operation/internal/ImportOperationCommand.java (-134 / +20 lines)
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
}

Return to bug 165544