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/tooling/nls/messages/capability/internal/messages.properties (-1 / +1 lines)
Lines 90-96 Link Here
90
RMD_SOURCE = RMDSource
90
RMD_SOURCE = RMDSource
91
91
92
FAILED_TO_SAVE_MCAP_FILE_ERROR_ = IWAT0542E Failed to save MCAP file
92
FAILED_TO_SAVE_MCAP_FILE_ERROR_ = IWAT0542E Failed to save MCAP file
93
IMPROPER_WSDL_FILE_ERROR_ = IWAT0547E Capability WSDL file is not a proper WSLD file
93
IMPROPER_WSDL_FILE_ERROR_ = IWAT0547E Capability WSDL file is not a proper WSDL file
94
RMD_FILE_DOESNT_EXISTS_ERROR_ = IWAT0548E RMD file doesn't exists
94
RMD_FILE_DOESNT_EXISTS_ERROR_ = IWAT0548E RMD file doesn't exists
95
FAILED_TO_LOAD_RMD_ERROR_ = IWAT0549E Failed to load the RMD file
95
FAILED_TO_LOAD_RMD_ERROR_ = IWAT0549E Failed to load the RMD file
96
INVALID_IEDITOR_ERROR_ = IWAT0550E Invalid Input: Must be IFileEditorInput
96
INVALID_IEDITOR_ERROR_ = IWAT0550E Invalid Input: Must be IFileEditorInput
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/NewProjectWizard.java (-6 / +4 lines)
Lines 34-40 Link Here
34
import org.eclipse.jface.viewers.IStructuredSelection;
34
import org.eclipse.jface.viewers.IStructuredSelection;
35
import org.eclipse.jface.wizard.Wizard;
35
import org.eclipse.jface.wizard.Wizard;
36
import org.eclipse.swt.graphics.Image;
36
import org.eclipse.swt.graphics.Image;
37
import org.eclipse.tptp.wsdm.tooling.editor.mrt.internal.ManageableResourceTypeEditorPlugin;
37
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
38
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
38
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
40
import org.eclipse.ui.INewWizard;
40
import org.eclipse.ui.INewWizard;
Lines 51-58 Link Here
51
51
52
	private static ILog LOG = null;
52
	private static ILog LOG = null;
53
53
54
	private static String PLUGIN_ID = ManageableResourceTypeEditorPlugin.PLUGIN_ID;
55
56
	private GenerationOptionsPage _generationOptionsPage;
54
	private GenerationOptionsPage _generationOptionsPage;
57
55
58
	private String _projectName;
56
	private String _projectName;
Lines 263-274 Link Here
263
	private void handle(String message, Exception e)
261
	private void handle(String message, Exception e)
264
	{
262
	{
265
		_generationOptionsPage.setErrorMessage(message);
263
		_generationOptionsPage.setErrorMessage(message);
266
		Status status = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK,
264
		Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
267
				message, e);
265
				IStatus.OK, message, e);
268
266
269
		if (LOG == null)
267
		if (LOG == null)
270
		{
268
		{
271
			LOG = ManageableResourceTypeEditorPlugin.getDefault().getLog();
269
			LOG = Activator.getPlugin().getLog();
272
		}
270
		}
273
		LOG.log(status);
271
		LOG.log(status);
274
	}
272
	}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/internal/GenerationOptionsPage.java (-2 / +1 lines)
Lines 74-80 Link Here
74
import org.eclipse.swt.widgets.Table;
74
import org.eclipse.swt.widgets.Table;
75
import org.eclipse.swt.widgets.Text;
75
import org.eclipse.swt.widgets.Text;
76
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
76
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
77
import org.eclipse.tptp.wsdm.tooling.editor.mrt.internal.ManageableResourceTypeEditorPlugin;
78
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
77
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
79
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
78
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
80
import org.eclipse.tptp.wsdm.tooling.util.internal.Validation;
79
import org.eclipse.tptp.wsdm.tooling.util.internal.Validation;
Lines 248-254 Link Here
248
247
249
		IExtensionRegistry er = Platform.getExtensionRegistry();
248
		IExtensionRegistry er = Platform.getExtensionRegistry();
250
		IExtensionPoint ep = er.getExtensionPoint(Activator.PLUGIN_ID,
249
		IExtensionPoint ep = er.getExtensionPoint(Activator.PLUGIN_ID,
251
				ManageableResourceTypeEditorPlugin.EXT_PT);
250
				Activator.CODEGEN_EXT_PT);
252
		IExtension[] extensions = ep.getExtensions();
251
		IExtension[] extensions = ep.getExtensions();
253
252
254
		for (int i = 0; i < extensions.length; i++)
253
		for (int i = 0; i < extensions.length; i++)
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/AbstractCapabilityEditor.java (-43 / +75 lines)
Lines 18-26 Link Here
18
import javax.wsdl.Operation;
18
import javax.wsdl.Operation;
19
19
20
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IStorage;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.emf.common.util.URI;
24
import org.eclipse.emf.common.util.URI;
25
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.jface.dialogs.MessageDialog;
26
import org.eclipse.tptp.wsdm.model.MetadataDescriptor;
26
import org.eclipse.tptp.wsdm.model.MetadataDescriptor;
Lines 47-52 Link Here
47
import org.eclipse.ui.IEditorPart;
47
import org.eclipse.ui.IEditorPart;
48
import org.eclipse.ui.IEditorSite;
48
import org.eclipse.ui.IEditorSite;
49
import org.eclipse.ui.IFileEditorInput;
49
import org.eclipse.ui.IFileEditorInput;
50
import org.eclipse.ui.IStorageEditorInput;
50
import org.eclipse.ui.PartInitException;
51
import org.eclipse.ui.PartInitException;
51
import org.eclipse.ui.part.MultiPageEditorPart;
52
import org.eclipse.ui.part.MultiPageEditorPart;
52
import org.eclipse.xsd.XSDElementDeclaration;
53
import org.eclipse.xsd.XSDElementDeclaration;
Lines 118-143 Link Here
118
	{
119
	{
119
		buildModel();
120
		buildModel();
120
		_overviewPage = createOverviewPage();
121
		_overviewPage = createOverviewPage();
122
		_pages.add(_overviewPage);
121
123
122
		_propertyPage = createPropertyPage();
124
		_propertyPage = createPropertyPage();
125
		_pages.add(_propertyPage);
123
126
124
		_operationPage = createOperationPage();
127
		_operationPage = createOperationPage();
128
		_pages.add(_operationPage);
125
129
126
		_topicPage = createTopicPage();
130
		_topicPage = createTopicPage();
131
		_pages.add(_topicPage);
127
132
128
		if (loadWSDLSourcePage())
133
		if (loadWSDLSourcePage())
129
		{
134
		{
130
			_wsdlSourcePage = createWSDLSourcePage();
135
			_wsdlSourcePage = createWSDLSourcePage();
136
			_pages.add(_wsdlSourcePage);
131
			_create_wsdl_source = true;
137
			_create_wsdl_source = true;
132
		}
138
		}
133
		if (loadXSDSourcePage())
139
		if (loadXSDSourcePage())
134
		{
140
		{
135
			_xsdSourcePage = createXSDSourcePage();
141
			_xsdSourcePage = createXSDSourcePage();
142
			_pages.add(_xsdSourcePage);
136
			_create_xsd_source = true;
143
			_create_xsd_source = true;
137
		}
144
		}
138
		if (loadRMDSourcePage())
145
		if (loadRMDSourcePage())
139
		{
146
		{
140
			_rmdSourcePage = createRMDSourcePage();
147
			_rmdSourcePage = createRMDSourcePage();
148
			_pages.add(_rmdSourcePage);
141
			_create_rmd_source = true;
149
			_create_rmd_source = true;
142
		}
150
		}
143
		firePropertyChange(IEditorPart.PROP_DIRTY);
151
		firePropertyChange(IEditorPart.PROP_DIRTY);
Lines 290-320 Link Here
290
				return;
298
				return;
291
			}
299
			}
292
		}
300
		}
293
		// TODO
301
		else if (getEditorInput() instanceof IStorageEditorInput)
294
		// else if(getEditorInput() instanceof IStorageEditorInput)
302
		{
295
		// {
303
			IStorageEditorInput input = (IStorageEditorInput) getEditorInput();
296
		// IStorageEditorInput input = (IStorageEditorInput)getEditorInput();
304
			IStorage storage = null;
297
		// IStorage storage = null;
305
			try
298
		// try
306
			{
299
		// {
307
				storage = input.getStorage();
300
		// storage = input.getStorage();
308
				_read_only = storage.isReadOnly();
301
		// _read_only = storage.isReadOnly();
309
			}
302
		// }
310
			catch (CoreException e1)
303
		// catch (CoreException e1)
311
			{
304
		// {
312
				e1.printStackTrace();
305
		// e1.printStackTrace();
313
			}
306
		// }
314
			URI capFileURI = URI.createURI(storage.getFullPath().toString());
307
		// URI capFileURI = URI.createURI(storage.getFullPath().toString());
315
			try
308
		// try
316
			{
309
		// {
317
				capabilityDefinition = WsdlUtils
310
		// wsdlDefinition = WsdlUtils.getWSDLDefinition(capFileURI);
318
						.getCapabilityDefinition(capFileURI);
311
		// }
319
				if (capFileURI.toString().startsWith("platform:/resource"))
312
		// catch (Exception e)
320
				{
313
		// {
321
					IFile macpFile = EclipseUtils.getIFile(capFileURI
314
		// org.eclipse.wsdl.capability.util.WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_,e);
322
							.toString());
315
		// return;
323
					_capabilityDomain.setCapabilityIFile(macpFile);
316
		// }
324
				}
317
		// }
325
			}
326
			catch (Exception e)
327
			{
328
				WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_, e);
329
				return;
330
			}
331
		}
318
		else
332
		else
319
			return;
333
			return;
320
334
Lines 361-378 Link Here
361
		if (metadataDescriptorLocation != null
375
		if (metadataDescriptorLocation != null
362
				&& metadataDescriptorName != null)
376
				&& metadataDescriptorName != null)
363
		{
377
		{
364
			URI capabilityFileLocationURI = capabilityDefinition
378
			URI rmdFileLocationURI = null;
365
					.getWSDLFileProtocalURI();
379
			if (capabilityDefinition.getWSDLFileProtocalURI() != null)
366
			URI rmdFileLocationURI = URI.createURI(capabilityFileLocationURI
380
			{
367
					.trimSegments(1).toString()
381
				URI capabilityFileLocationURI = capabilityDefinition
368
					+ "/" + metadataDescriptorLocation);
382
						.getWSDLFileProtocalURI();
383
				rmdFileLocationURI = URI.createURI(capabilityFileLocationURI
384
						.trimSegments(1).toString()
385
						+ "/" + metadataDescriptorLocation);
386
			}
387
			else if (capabilityDefinition.getWSDLResourceProtocolURI() != null)
388
			{
389
				URI capabilityFileLocationURI = capabilityDefinition
390
						.getWSDLResourceProtocolURI();
391
				rmdFileLocationURI = URI.createURI(capabilityFileLocationURI
392
						.trimSegments(1).toString()
393
						+ "/" + metadataDescriptorLocation);
394
			}
369
			rmdRoot = MetaDataUtils.getDocumentRoot(rmdFileLocationURI);
395
			rmdRoot = MetaDataUtils.getDocumentRoot(rmdFileLocationURI);
370
			if (rmdRoot != null)
396
			if (rmdRoot != null)
371
			{
397
			{
372
				IFile capabilityFile = _capabilityDomain.getCapabilityIFile();
373
				IFile rmdFile = capabilityFile.getParent().getFile(
374
						new Path(metadataDescriptorLocation));
375
				_capabilityDomain.setCapabilityRmdIFile(rmdFile);
376
				MetadataDescriptor rmdDescriptor = new MetadataDescriptor(
398
				MetadataDescriptor rmdDescriptor = new MetadataDescriptor(
377
						capability, rmdRoot, metadataDescriptorName);
399
						capability, rmdRoot, metadataDescriptorName);
378
			}
400
			}
Lines 669-683 Link Here
669
		}
691
		}
670
692
671
		// Remove rmd file of capability
693
		// Remove rmd file of capability
672
		IFile rmdFile = _capabilityDomain.getCapabilityRmdIFile();
694
		if (_capabilityDomain.getCapability().getMetadata() != null)
673
		if (rmdFile != null && rmdFile.exists())
674
		{
695
		{
675
			String title = Messages.CONFIRM_DELETE;
696
			MetadataDescriptor rmdDescriptor = _capabilityDomain
676
			String message = Messages.bind(Messages.FILE_DELETE_QUESTION,
697
					.getCapability().getMetadata();
677
					rmdFile.getName());
698
			DocumentRoot rmdRoot = rmdDescriptor.getDocumentRoot();
678
			if (MessageDialog
699
			if (rmdRoot != null)
679
					.openQuestion(getSite().getShell(), title, message))
700
			{
680
				rmdFile.delete(true, null);
701
				String rmdRootURIPath = rmdRoot.eResource().getURI().toString();
702
				IFile rmdFile = EclipseUtils.getIFile(rmdRootURIPath);
703
				if (rmdFile != null && rmdFile.exists())
704
				{
705
					String title = Messages.CONFIRM_DELETE;
706
					String message = Messages.bind(
707
							Messages.FILE_DELETE_QUESTION, rmdFile.getName());
708
					if (MessageDialog.openQuestion(getSite().getShell(), title,
709
							message))
710
						rmdFile.delete(true, null);
711
				}
712
			}
681
		}
713
		}
682
	}
714
	}
683
715
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/CapabilityDomain.java (-18 lines)
Lines 45-52 Link Here
45
45
46
	private IFile _capabilityFile;
46
	private IFile _capabilityFile;
47
47
48
	private IFile _rmdFile;
49
50
	private Bundle _artifactsPlugin;
48
	private Bundle _artifactsPlugin;
51
49
52
	/**
50
	/**
Lines 77-90 Link Here
77
	}
75
	}
78
76
79
	/**
77
	/**
80
	 * Returns the capability rmd file.
81
	 */
82
	public IFile getCapabilityRmdIFile()
83
	{
84
		return _rmdFile;
85
	}
86
87
	/**
88
	 * Returns the property schema of capability.
78
	 * Returns the property schema of capability.
89
	 */
79
	 */
90
	public XSDSchema getPropertySchema()
80
	public XSDSchema getPropertySchema()
Lines 141-154 Link Here
141
	}
131
	}
142
132
143
	/**
133
	/**
144
	 * Sets the capability rmd file.
145
	 */
146
	public void setCapabilityRmdIFile(IFile rmdFile)
147
	{
148
		_rmdFile = rmdFile;
149
	}
150
151
	/**
152
	 * Sets the property schema for capability.
134
	 * Sets the property schema for capability.
153
	 */
135
	 */
154
	public void setPropertySchema(XSDSchema propertySchema)
136
	public void setPropertySchema(XSDSchema propertySchema)
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/CapabilityEditor.java (-9 / +1 lines)
Lines 76-82 Link Here
76
		_operationPageIndex = addPage(operationPage.getForm());
76
		_operationPageIndex = addPage(operationPage.getForm());
77
		setPageText(_operationPageIndex, Messages.OPERATIONS);
77
		setPageText(_operationPageIndex, Messages.OPERATIONS);
78
		addPropertyListener(operationPage);
78
		addPropertyListener(operationPage);
79
		_pages.add(operationPage);
80
		return operationPage;
79
		return operationPage;
81
	}
80
	}
82
81
Lines 91-97 Link Here
91
		_overviewPageIndex = addPage(overviewPage.getForm());
90
		_overviewPageIndex = addPage(overviewPage.getForm());
92
		setPageText(_overviewPageIndex, Messages.OVERVIEW);
91
		setPageText(_overviewPageIndex, Messages.OVERVIEW);
93
		addPropertyListener(overviewPage);
92
		addPropertyListener(overviewPage);
94
		_pages.add(overviewPage);
95
		return overviewPage;
93
		return overviewPage;
96
	}
94
	}
97
95
Lines 106-112 Link Here
106
		_propertyPageIndex = addPage(propertyPage.getForm());
104
		_propertyPageIndex = addPage(propertyPage.getForm());
107
		setPageText(_propertyPageIndex, Messages.PROPERTIES);
105
		setPageText(_propertyPageIndex, Messages.PROPERTIES);
108
		addPropertyListener(propertyPage);
106
		addPropertyListener(propertyPage);
109
		_pages.add(propertyPage);
110
		return propertyPage;
107
		return propertyPage;
111
	}
108
	}
112
109
Lines 120-126 Link Here
120
		_topicPageIndex = addPage(topicPage.getForm());
117
		_topicPageIndex = addPage(topicPage.getForm());
121
		setPageText(_topicPageIndex, Messages.TOPICS);
118
		setPageText(_topicPageIndex, Messages.TOPICS);
122
		addPropertyListener(topicPage);
119
		addPropertyListener(topicPage);
123
		_pages.add(topicPage);
124
		return topicPage;
120
		return topicPage;
125
	}
121
	}
126
122
Lines 133-139 Link Here
133
		rmdSourcePage.create();
129
		rmdSourcePage.create();
134
		_rmdSourcePageIndex = addPage(rmdSourcePage.getControl());
130
		_rmdSourcePageIndex = addPage(rmdSourcePage.getControl());
135
		setPageText(_rmdSourcePageIndex, Messages.RMD_SOURCE);
131
		setPageText(_rmdSourcePageIndex, Messages.RMD_SOURCE);
136
		_pages.add(rmdSourcePage);
137
		return rmdSourcePage;
132
		return rmdSourcePage;
138
	}
133
	}
139
134
Lines 146-152 Link Here
146
		sourcePage.create();
141
		sourcePage.create();
147
		_wsdlSourcePageIndex = addPage(sourcePage.getControl());
142
		_wsdlSourcePageIndex = addPage(sourcePage.getControl());
148
		setPageText(_wsdlSourcePageIndex, Messages.WSDL_SOURCE);
143
		setPageText(_wsdlSourcePageIndex, Messages.WSDL_SOURCE);
149
		_pages.add(sourcePage);
150
		return sourcePage;
144
		return sourcePage;
151
	}
145
	}
152
146
Lines 159-165 Link Here
159
		sourcePage.create();
153
		sourcePage.create();
160
		_xsdSourcePageIndex = addPage(sourcePage.getControl());
154
		_xsdSourcePageIndex = addPage(sourcePage.getControl());
161
		setPageText(_xsdSourcePageIndex, Messages.XSD_SOURCE);
155
		setPageText(_xsdSourcePageIndex, Messages.XSD_SOURCE);
162
		_pages.add(sourcePage);
163
		return sourcePage;
156
		return sourcePage;
164
	}
157
	}
165
158
Lines 214-221 Link Here
214
			List topicSpaces = _capabilityDomain.getCapability()
207
			List topicSpaces = _capabilityDomain.getCapability()
215
					.getTopicSpaces();
208
					.getTopicSpaces();
216
			propertyMetaDataDescriptor.saveTopicSpaces(topicSpaces);
209
			propertyMetaDataDescriptor.saveTopicSpaces(topicSpaces);
217
			IFile rmdFile = _capabilityDomain.getCapabilityRmdIFile();
210
			MetaDataUtils.save(propertyMetaDataDescriptor, monitor);
218
			MetaDataUtils.save(propertyMetaDataDescriptor, rmdFile, monitor);
219
		}
211
		}
220
	}
212
	}
221
213
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/WsdlUtils.java (-10 / +51 lines)
Lines 39-44 Link Here
39
import org.eclipse.core.runtime.CoreException;
39
import org.eclipse.core.runtime.CoreException;
40
import org.eclipse.core.runtime.IProgressMonitor;
40
import org.eclipse.core.runtime.IProgressMonitor;
41
import org.eclipse.emf.common.util.URI;
41
import org.eclipse.emf.common.util.URI;
42
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseEnvironment;
42
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
43
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
43
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
44
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
44
import org.eclipse.xsd.XSDComplexTypeDefinition;
45
import org.eclipse.xsd.XSDComplexTypeDefinition;
Lines 51-57 Link Here
51
import org.w3c.dom.Document;
52
import org.w3c.dom.Document;
52
import org.w3c.dom.Element;
53
import org.w3c.dom.Element;
53
import org.w3c.dom.NodeList;
54
import org.w3c.dom.NodeList;
54
import org.xml.sax.InputSource;
55
import org.xml.sax.SAXException;
55
import org.xml.sax.SAXException;
56
56
57
import com.ibm.wsdl.extensions.schema.SchemaConstants;
57
import com.ibm.wsdl.extensions.schema.SchemaConstants;
Lines 83-100 Link Here
83
	public static CapabilityDefinition getCapabilityDefinition(IFile wsdlFile)
83
	public static CapabilityDefinition getCapabilityDefinition(IFile wsdlFile)
84
			throws Exception
84
			throws Exception
85
	{
85
	{
86
		String wsdlFileLocation = wsdlFile.getRawLocation().toString();
86
		String iFileLocation = wsdlFile.getFullPath().toString();
87
		InputStream is = wsdlFile.getContents();
87
		String path = "platform:/resource" + iFileLocation;
88
		InputSource source = new InputSource(is);
88
		URI wsdlFileURI = URI.createURI(path);
89
		return getCapabilityDefinition(wsdlFileURI);
90
	}
91
92
	/**
93
	 * Returns the EMF based object Definition of the given WSDL file.
94
	 * 
95
	 * @param wsdlFile
96
	 *            Any WSDL file available in eclipse workbench
97
	 * 
98
	 * @return EMF based Definition object
99
	 * @throws Exception
100
	 */
101
	public static CapabilityDefinition getCapabilityDefinition(URI wsdlFileURI)
102
			throws Exception
103
	{
104
		EclipseEnvironment eclipseEnv = new EclipseEnvironment();
105
		String path = wsdlFileURI.toString();
106
		Document document = org.apache.muse.ws.wsdl.WsdlUtils.createWSDL(
107
				eclipseEnv, path, true);
108
		Element cleanDocument = org.apache.muse.ws.wsdl.WsdlUtils
109
				.removeSchemaReferences(document.getDocumentElement());
110
		cleanDocument = org.apache.muse.ws.wsdl.WsdlUtils
111
				.removeWsdlReferences(cleanDocument);
89
		WSDLFactory factory = WSDLFactory.newInstance();
112
		WSDLFactory factory = WSDLFactory.newInstance();
90
		WSDLReader reader = factory.newWSDLReader();
113
		WSDLReader reader = factory.newWSDLReader();
91
		Definition definition = reader.readWSDL(wsdlFileLocation, source);
114
		Definition definition = reader.readWSDL(null, cleanDocument);
92
		CapabilityDefinition capabilityDefinition = new CapabilityDefinition(
115
		CapabilityDefinition capabilityDefinition = new CapabilityDefinition(
93
				definition);
116
				definition);
94
		String iFileLocation = wsdlFile.getFullPath().toString();
117
		capabilityDefinition.setWSDLResourceProtocolURI(wsdlFileURI);
95
		URI resourceProtocolURI = URI.createURI("platform:/resource"
96
				+ iFileLocation);
97
		capabilityDefinition.setWSDLResourceProtocolURI(resourceProtocolURI);
98
		return capabilityDefinition;
118
		return capabilityDefinition;
99
	}
119
	}
100
120
Lines 298-304 Link Here
298
					.getXSDModelGroup(complexTypeDefinition);
318
					.getXSDModelGroup(complexTypeDefinition);
299
			return XsdUtils.getElementDeclarations(modelGroup);
319
			return XsdUtils.getElementDeclarations(modelGroup);
300
		}
320
		}
301
		return new XSDElementDeclaration[] { element };
321
		return new XSDElementDeclaration[]
322
		{ element };
302
	}
323
	}
303
324
304
	/**
325
	/**
Lines 562-565 Link Here
562
		return element;
583
		return element;
563
	}
584
	}
564
585
586
	public static Message getWSDLMessage(Definition definition,
587
			String messageName)
588
	{
589
		Map messagesMap = definition.getMessages();
590
		if (messagesMap == null || messagesMap.size() == 0)
591
			return null;
592
		Iterator it = messagesMap.values().iterator();
593
		while (it.hasNext())
594
		{
595
			Object object = it.next();
596
			if (object instanceof Message)
597
			{
598
				Message message = (Message) object;
599
				if (message.getQName().getLocalPart().equals(messageName))
600
					return message;
601
			}
602
		}
603
		return null;
604
	}
605
565
}
606
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/IFile2Capability.java (-48 / +17 lines)
Lines 12-97 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.util.internal;
13
package org.eclipse.tptp.wsdm.tooling.util.internal;
14
14
15
import java.io.InputStream;
16
import java.util.LinkedList;
17
import java.util.List;
18
19
import javax.wsdl.Definition;
15
import javax.wsdl.Definition;
20
import javax.wsdl.factory.WSDLFactory;
16
import javax.wsdl.factory.WSDLFactory;
21
import javax.wsdl.xml.WSDLReader;
17
import javax.wsdl.xml.WSDLReader;
22
18
23
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFile;
24
import org.eclipse.emf.common.util.URI;
20
import org.eclipse.emf.common.util.URI;
21
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.internal.EclipseEnvironment;
25
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
26
import org.xml.sax.InputSource;
23
import org.w3c.dom.Document;
24
import org.w3c.dom.Element;
27
25
28
public class IFile2Capability
26
public class IFile2Capability extends Definition2Capability
29
{
27
{
30
	protected IFile _mcapFile;
28
	protected IFile _mcapFile;
31
	protected Capability _capability;
32
	protected List _errorDiagonistics = new LinkedList();
33
	protected List _warningDiagonistics = new LinkedList();
34
29
35
	public IFile2Capability(IFile mcapFile)
30
	public IFile2Capability(IFile mcapFile)
36
	{
31
	{
32
		super(parse(mcapFile));
37
		_mcapFile = mcapFile;
33
		_mcapFile = mcapFile;
38
	}
34
	}
39
35
40
	public Capability getCapability()
36
	public Capability getCapability()
41
	{
37
	{
42
		Definition definition = parse();
43
		Definition2Capability def2Cap = new Definition2Capability(definition);
44
		URI capabilityURI = URI.createPlatformResourceURI(_mcapFile
38
		URI capabilityURI = URI.createPlatformResourceURI(_mcapFile
45
				.getFullPath().toString());
39
				.getFullPath().toString());
46
		_capability = def2Cap.getCapability(capabilityURI);
40
		return getCapability(capabilityURI);
47
		_errorDiagonistics.addAll(def2Cap.getErrorDiagonistics());
48
		_warningDiagonistics.addAll(def2Cap.getWarningDiagonistics());
49
		return _capability;
50
	}
41
	}
51
42
52
	private Definition parse()
43
	private static Definition parse(IFile mcapFile)
53
	{
44
	{
54
		try
45
		try
55
		{
46
		{
56
			String wsdlFileLocation = _mcapFile.getRawLocation().toString();
47
			EclipseEnvironment eclipseEnv = new EclipseEnvironment();
57
			InputStream is = _mcapFile.getContents();
48
			String iFileLocation = mcapFile.getFullPath().toString();
58
			InputSource source = new InputSource(is);
49
			String path = "platform:/resource" + iFileLocation;
50
			Document document = org.apache.muse.ws.wsdl.WsdlUtils.createWSDL(
51
					eclipseEnv, path, true);
52
			Element cleanDocument = org.apache.muse.ws.wsdl.WsdlUtils
53
					.removeSchemaReferences(document.getDocumentElement());
54
			cleanDocument = org.apache.muse.ws.wsdl.WsdlUtils
55
					.removeWsdlReferences(cleanDocument);
59
			WSDLFactory factory = WSDLFactory.newInstance();
56
			WSDLFactory factory = WSDLFactory.newInstance();
60
			WSDLReader reader = factory.newWSDLReader();
57
			WSDLReader reader = factory.newWSDLReader();
61
			Definition definition = reader.readWSDL(wsdlFileLocation, source);
58
			Definition definition = reader.readWSDL(null, cleanDocument);
62
			return definition;
59
			return definition;
63
		}
60
		}
64
		catch (Exception e)
61
		catch (Exception e)
65
		{
62
		{
66
			prepareErrorDiagnostics(e.getMessage());
67
		}
63
		}
68
69
		return null;
64
		return null;
70
	}
65
	}
71
72
	/**
73
	 * Returns the error diagnostics list.
74
	 */
75
	public List getErrorDiagonistics()
76
	{
77
		return _errorDiagonistics;
78
	}
79
80
	/**
81
	 * Returns the warning diagnostics list.
82
	 */
83
	public List getWarningDiagonistics()
84
	{
85
		return _warningDiagonistics;
86
	}
87
88
	protected void prepareErrorDiagnostics(String message)
89
	{
90
		_errorDiagonistics.add(message);
91
	}
92
93
	protected void prepareWarningDiagnostics(String message)
94
	{
95
		_warningDiagonistics.add(message);
96
	}
97
}
66
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/MrtUtils.java (-12 / +13 lines)
Lines 34-39 Link Here
34
import org.eclipse.emf.ecore.resource.Resource;
34
import org.eclipse.emf.ecore.resource.Resource;
35
import org.eclipse.emf.ecore.resource.ResourceSet;
35
import org.eclipse.emf.ecore.resource.ResourceSet;
36
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
36
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
37
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
37
import org.eclipse.tptp.wsdm.tooling.editor.internal.CategoryCollection;
38
import org.eclipse.tptp.wsdm.tooling.editor.internal.CategoryCollection;
38
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
39
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
39
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
40
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
Lines 160-168 Link Here
160
	public static Collection getWSRPCapabilityUris(boolean includeOptional)
161
	public static Collection getWSRPCapabilityUris(boolean includeOptional)
161
	{
162
	{
162
		List retVal = new LinkedList();
163
		List retVal = new LinkedList();
163
		String ns = "org.eclipse.tptp.wsdm.model";
164
		IExtensionPoint iep = Platform.getExtensionRegistry()
164
		IExtensionPoint iep = Platform.getExtensionRegistry()
165
				.getExtensionPoint(ns, "mrCapability");
165
				.getExtensionPoint(Activator.MODEL_PLUGIN_ID,
166
						Activator.MR_CAPABILITY_EXT_PT);
166
		if (iep != null)
167
		if (iep != null)
167
		{
168
		{
168
			IExtension[] extensions = iep.getExtensions();
169
			IExtension[] extensions = iep.getExtensions();
Lines 189-197 Link Here
189
	public static Collection getMandatoryCapabilityUris(boolean includeOptional)
190
	public static Collection getMandatoryCapabilityUris(boolean includeOptional)
190
	{
191
	{
191
		List retVal = new LinkedList();
192
		List retVal = new LinkedList();
192
		String ns = "org.eclipse.tptp.wsdm.model";
193
		IExtensionPoint iep = Platform.getExtensionRegistry()
193
		IExtensionPoint iep = Platform.getExtensionRegistry()
194
				.getExtensionPoint(ns, "mrCapability");
194
				.getExtensionPoint(Activator.MODEL_PLUGIN_ID,
195
						Activator.MR_CAPABILITY_EXT_PT);
195
		if (iep != null)
196
		if (iep != null)
196
		{
197
		{
197
			IExtension[] extensions = iep.getExtensions();
198
			IExtension[] extensions = iep.getExtensions();
Lines 222-230 Link Here
222
	 */
223
	 */
223
	public static boolean isCapabilityEditable(String name)
224
	public static boolean isCapabilityEditable(String name)
224
	{
225
	{
225
		String ns = "org.eclipse.tptp.wsdm.model";
226
		IExtensionPoint iep = Platform.getExtensionRegistry()
226
		IExtensionPoint iep = Platform.getExtensionRegistry()
227
				.getExtensionPoint(ns, "mrCapability");
227
				.getExtensionPoint(Activator.MODEL_PLUGIN_ID,
228
						Activator.MR_CAPABILITY_EXT_PT);
228
		if (iep != null)
229
		if (iep != null)
229
		{
230
		{
230
			IExtension[] extensions = iep.getExtensions();
231
			IExtension[] extensions = iep.getExtensions();
Lines 254-262 Link Here
254
	 */
255
	 */
255
	public static boolean isSystemCapability(String name)
256
	public static boolean isSystemCapability(String name)
256
	{
257
	{
257
		String ns = "org.eclipse.tptp.wsdm.model";
258
		IExtensionPoint iep = Platform.getExtensionRegistry()
258
		IExtensionPoint iep = Platform.getExtensionRegistry()
259
				.getExtensionPoint(ns, "mrCapability");
259
				.getExtensionPoint(Activator.MODEL_PLUGIN_ID,
260
						Activator.MR_CAPABILITY_EXT_PT);
260
		if (iep != null)
261
		if (iep != null)
261
		{
262
		{
262
			IExtension[] extensions = iep.getExtensions();
263
			IExtension[] extensions = iep.getExtensions();
Lines 284-292 Link Here
284
	public static List getMrCapabilityWsdls()
285
	public static List getMrCapabilityWsdls()
285
	{
286
	{
286
		List retVal = new LinkedList();
287
		List retVal = new LinkedList();
287
		String ns = "org.eclipse.tptp.wsdm.model";
288
		IExtensionPoint iep = Platform.getExtensionRegistry()
288
		IExtensionPoint iep = Platform.getExtensionRegistry()
289
				.getExtensionPoint(ns, "mrCapability");
289
				.getExtensionPoint(Activator.MODEL_PLUGIN_ID,
290
						Activator.MR_CAPABILITY_EXT_PT);
290
		if (iep != null)
291
		if (iep != null)
291
		{
292
		{
292
			IExtension[] extensions = iep.getExtensions();
293
			IExtension[] extensions = iep.getExtensions();
Lines 312-320 Link Here
312
	public static List getMandatoryWsdls(boolean includeOptional)
313
	public static List getMandatoryWsdls(boolean includeOptional)
313
	{
314
	{
314
		List retVal = new LinkedList();
315
		List retVal = new LinkedList();
315
		String ns = "org.eclipse.tptp.wsdm.model";
316
		IExtensionPoint iep = Platform.getExtensionRegistry()
316
		IExtensionPoint iep = Platform.getExtensionRegistry()
317
				.getExtensionPoint(ns, "mrCapability");
317
				.getExtensionPoint(Activator.MODEL_PLUGIN_ID,
318
						Activator.MR_CAPABILITY_EXT_PT);
318
		if (iep != null)
319
		if (iep != null)
319
		{
320
		{
320
			IExtension[] extensions = iep.getExtensions();
321
			IExtension[] extensions = iep.getExtensions();
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/operation/internal/ChangeOperationReturnTypeCommand.java (-3 / +11 lines)
Lines 26-31 Link Here
26
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.property.internal.DataType;
26
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.property.internal.DataType;
27
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.property.internal.DataTypesCollection;
27
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.property.internal.DataTypesCollection;
28
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
28
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
29
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.INewNameGenerator;
30
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.NewWSDLMessageNameGenerator;
31
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.NewXSDElementNameGenerator;
29
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
32
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
30
import org.eclipse.xsd.XSDElementDeclaration;
33
import org.eclipse.xsd.XSDElementDeclaration;
31
import org.eclipse.xsd.XSDFactory;
34
import org.eclipse.xsd.XSDFactory;
Lines 87-93 Link Here
87
			{
90
			{
88
				message = definition.createMessage();
91
				message = definition.createMessage();
89
				String ns = definition.getTargetNamespace();
92
				String ns = definition.getTargetNamespace();
90
				message.setQName(new QName(ns, responseName));
93
				INewNameGenerator generator = new NewWSDLMessageNameGenerator(
94
						definition, responseName);
95
				String messageName = generator.getNewName();
96
				message.setQName(new QName(ns, messageName));
91
				definition.addMessage(message);
97
				definition.addMessage(message);
92
				output.setMessage(message);
98
				output.setMessage(message);
93
			}
99
			}
Lines 109-118 Link Here
109
				}
115
				}
110
			}
116
			}
111
			_element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
117
			_element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
112
			_element.setName(responseName);
113
114
			XSDSchema schema = capabilityDefinition
118
			XSDSchema schema = capabilityDefinition
115
					.createOrFindSchema(definition.getTargetNamespace());
119
					.createOrFindSchema(definition.getTargetNamespace());
120
			INewNameGenerator generator = new NewXSDElementNameGenerator(
121
					schema, responseName);
122
			String elementName = generator.getNewName();
123
			_element.setName(elementName);
116
			schema.getContents().add(_element);
124
			schema.getContents().add(_element);
117
			part_0.setElementName(new QName(_element.getTargetNamespace(),
125
			part_0.setElementName(new QName(_element.getTargetNamespace(),
118
					_element.getName()));
126
					_element.getName()));
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/operation/internal/ListSection.java (-2 / +57 lines)
Lines 15-22 Link Here
15
import java.util.Collection;
15
import java.util.Collection;
16
import java.util.List;
16
import java.util.List;
17
17
18
import javax.wsdl.Definition;
18
import javax.wsdl.Operation;
19
import javax.wsdl.Operation;
19
20
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.resource.ImageRegistry;
23
import org.eclipse.jface.resource.ImageRegistry;
21
import org.eclipse.jface.viewers.IStructuredContentProvider;
24
import org.eclipse.jface.viewers.IStructuredContentProvider;
22
import org.eclipse.jface.viewers.LabelProvider;
25
import org.eclipse.jface.viewers.LabelProvider;
Lines 24-29 Link Here
24
import org.eclipse.jface.viewers.StructuredSelection;
27
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.jface.viewers.Viewer;
28
import org.eclipse.jface.viewers.Viewer;
26
import org.eclipse.jface.window.Window;
29
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.wizard.WizardDialog;
27
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.events.ControlAdapter;
32
import org.eclipse.swt.events.ControlAdapter;
29
import org.eclipse.swt.events.ControlEvent;
33
import org.eclipse.swt.events.ControlEvent;
Lines 38-47 Link Here
38
import org.eclipse.swt.widgets.Listener;
42
import org.eclipse.swt.widgets.Listener;
39
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.swt.widgets.Shell;
40
import org.eclipse.swt.widgets.Table;
44
import org.eclipse.swt.widgets.Table;
45
import org.eclipse.tptp.wsdm.tooling.dialog.provisional.WSDLBrowseDialog;
41
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.AddOperationCommand;
46
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.AddOperationCommand;
42
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.ChangeInputParamTypeCommand;
47
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.ChangeInputParamTypeCommand;
43
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.ChangeOperationReturnTypeCommand;
48
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.ChangeOperationReturnTypeCommand;
44
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.RemoveOperationCommand;
49
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.RemoveOperationCommand;
50
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.wsdl.OperationImportWizard;
45
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.AbstractCapabilityEditor;
51
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.AbstractCapabilityEditor;
46
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
52
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
47
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.property.internal.DataType;
53
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.property.internal.DataType;
Lines 51-56 Link Here
51
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
57
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
52
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages;
58
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages;
53
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
59
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
60
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
54
import org.eclipse.tptp.wsdm.tooling.viewers.internal.IViewerClient;
61
import org.eclipse.tptp.wsdm.tooling.viewers.internal.IViewerClient;
55
import org.eclipse.tptp.wsdm.tooling.viewers.internal.StructuredTableViewer;
62
import org.eclipse.tptp.wsdm.tooling.viewers.internal.StructuredTableViewer;
56
import org.eclipse.ui.forms.widgets.FormToolkit;
63
import org.eclipse.ui.forms.widgets.FormToolkit;
Lines 71-76 Link Here
71
78
72
	private Button _addOperationButton;
79
	private Button _addOperationButton;
73
80
81
	private Button _importOperationButton;
82
74
	private Button _removeOperationButton;
83
	private Button _removeOperationButton;
75
84
76
	private Label _errorLabel;
85
	private Label _errorLabel;
Lines 143-152 Link Here
143
					}
152
					}
144
				});
153
				});
145
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
154
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
146
		gd.widthHint = 50;
155
		gd.widthHint = 100;
147
		_addOperationButton.setLayoutData(gd);
156
		_addOperationButton.setLayoutData(gd);
148
		_addOperationButton.setEnabled(!_editor.isReadOnly());
157
		_addOperationButton.setEnabled(!_editor.isReadOnly());
149
158
159
		_importOperationButton = createPushButton(
160
				_buttonClient,
161
				toolkit,
162
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.IMPORT_OPERATIONS,
163
				new Listener()
164
				{
165
					public void handleEvent(Event event)
166
					{
167
						importOperation();
168
					}
169
				});
170
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
171
		gd.widthHint = 100;
172
		_importOperationButton.setLayoutData(gd);
173
		_importOperationButton.setEnabled(!_editor.isReadOnly());
174
150
		_removeOperationButton = createPushButton(
175
		_removeOperationButton = createPushButton(
151
				_buttonClient,
176
				_buttonClient,
152
				toolkit,
177
				toolkit,
Lines 159-165 Link Here
159
					}
184
					}
160
				});
185
				});
161
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
186
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
162
		gd.widthHint = 50;
187
		gd.widthHint = 100;
163
		_removeOperationButton.setLayoutData(gd);
188
		_removeOperationButton.setLayoutData(gd);
164
		_removeOperationButton.setEnabled(false);
189
		_removeOperationButton.setEnabled(false);
165
190
Lines 206-211 Link Here
206
		}
231
		}
207
	}
232
	}
208
233
234
	private void importOperation()
235
	{
236
		WSDLBrowseDialog dialog = new WSDLBrowseDialog(getForm().getShell());
237
		if (dialog.open() == Window.OK)
238
		{
239
			IFile wsdlFile = (IFile) dialog.getFirstResult();
240
			Definition wsdlDefinition = null;
241
			try
242
			{
243
				wsdlDefinition = WsdlUtils.getCapabilityDefinition(wsdlFile)
244
						.getDefinition();
245
			}
246
			catch (Exception e)
247
			{
248
				MessageDialog
249
						.openError(
250
								getForm().getShell(),
251
								"Error",
252
								org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.IMPROPER_WSDL_FILE);
253
				return;
254
			}
255
			OperationImportWizard importOperationWizard = new OperationImportWizard(
256
					_editor.getCapabilityDomain(), wsdlDefinition);
257
			WizardDialog wizardDialog = new WizardDialog(getForm().getShell(),
258
					importOperationWizard);
259
			wizardDialog.open();
260
			_page.setDirty();
261
		}
262
	}
263
209
	private void removeOperation()
264
	private void removeOperation()
210
	{
265
	{
211
		CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
266
		CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/operation/internal/NewOperationDialog.java (-9 / +28 lines)
Lines 60-65 Link Here
60
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.property.internal.DataTypesContentProvider;
60
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.property.internal.DataTypesContentProvider;
61
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
61
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
62
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.NewNameGenerator;
62
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.NewNameGenerator;
63
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.INewNameGenerator;
64
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.NewWSDLMessageNameGenerator;
65
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.NewXSDElementNameGenerator;
63
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
66
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
64
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages;
67
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages;
65
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
68
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
Lines 119-127 Link Here
119
	private CapabilityDomain _capabilityDomain;
122
	private CapabilityDomain _capabilityDomain;
120
123
121
	// TODO Check it out
124
	// TODO Check it out
122
	// private static final String BASE_FAULT_FILE =
125
	private static final String BASE_FAULT_FILE = "platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/WS-BaseFaults-1_2.xsd";
123
	// "platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/WS-BaseFaults-1_2.xsd";
126
	// private final String BASE_FAULT_FILE =
124
	private final String BASE_FAULT_FILE = "artifacts/managementCapabilities/WS-BaseFaults-1_2.xsd";
127
	// "artifacts/managementCapabilities/WS-BaseFaults-1_2.xsd";
125
128
126
	private DataType _returnType;
129
	private DataType _returnType;
127
130
Lines 253-260 Link Here
253
		gd.horizontalSpan = ((GridLayout) rhsComposite.getLayout()).numColumns;
256
		gd.horizontalSpan = ((GridLayout) rhsComposite.getLayout()).numColumns;
254
		_paramViewer.getControl().setLayoutData(gd);
257
		_paramViewer.getControl().setLayoutData(gd);
255
258
256
		String[] header = new String[] { Messages.PARAM_NAME,
259
		String[] header = new String[]
257
				Messages.PARAM_TYPE };
260
		{ Messages.PARAM_NAME, Messages.PARAM_TYPE };
258
		for (int i = 0; i < header.length; i++)
261
		for (int i = 0; i < header.length; i++)
259
		{
262
		{
260
			TableColumn col = new TableColumn(_paramViewer.getTable(),
263
			TableColumn col = new TableColumn(_paramViewer.getTable(),
Lines 511-517 Link Here
511
				.getTargetNamespace());
514
				.getTargetNamespace());
512
		_capabilityDefinition.createOrFindPrefix(WsdmConstants.WSBF_NS, "wsbf");
515
		_capabilityDefinition.createOrFindPrefix(WsdmConstants.WSBF_NS, "wsbf");
513
		XsdUtils.createImportStatement(_typesSchema, WsdmConstants.WSBF_NS,
516
		XsdUtils.createImportStatement(_typesSchema, WsdmConstants.WSBF_NS,
514
				getBaseFaultFileURI());
517
				BASE_FAULT_FILE);
515
518
516
		_operation.setName(_methodName.getText());
519
		_operation.setName(_methodName.getText());
517
520
Lines 600-605 Link Here
600
	{
603
	{
601
		String tns = _capabilityDomain.getCapability().getNamespace();
604
		String tns = _capabilityDomain.getCapability().getNamespace();
602
		Message message = _capabilityDefinition.getDefinition().createMessage();
605
		Message message = _capabilityDefinition.getDefinition().createMessage();
606
		Definition _definition = _capabilityDefinition.getDefinition();
607
		INewNameGenerator nameGenerator = new NewWSDLMessageNameGenerator(
608
				_definition, name);
609
		name = nameGenerator.getNewName();
603
		message.setQName(new QName(tns, name));
610
		message.setQName(new QName(tns, name));
604
		message.setUndefined(false);
611
		message.setUndefined(false);
605
612
Lines 618-624 Link Here
618
	{
625
	{
619
		XSDElementDeclaration inputParamHolderElement = XSDFactory.eINSTANCE
626
		XSDElementDeclaration inputParamHolderElement = XSDFactory.eINSTANCE
620
				.createXSDElementDeclaration();
627
				.createXSDElementDeclaration();
621
		inputParamHolderElement.setName(_methodName.getText());
628
		String name = _methodName.getText();
629
		INewNameGenerator generator = new NewXSDElementNameGenerator(
630
				_typesSchema, name);
631
		name = generator.getNewName();
632
		inputParamHolderElement.setName(name);
622
		_typesSchema.getContents().add(inputParamHolderElement);
633
		_typesSchema.getContents().add(inputParamHolderElement);
623
		if (_paramList.size() == 0)
634
		if (_paramList.size() == 0)
624
		{
635
		{
Lines 655-661 Link Here
655
	{
666
	{
656
		XSDElementDeclaration outputTypeElement = XSDFactory.eINSTANCE
667
		XSDElementDeclaration outputTypeElement = XSDFactory.eINSTANCE
657
				.createXSDElementDeclaration();
668
				.createXSDElementDeclaration();
658
		outputTypeElement.setName(_methodName.getText() + "Response");
669
		String name = _methodName.getText() + "Response";
670
		INewNameGenerator generator = new NewXSDElementNameGenerator(
671
				_typesSchema, name);
672
		name = generator.getNewName();
673
		outputTypeElement.setName(name);
659
		_typesSchema.getContents().add(outputTypeElement);
674
		_typesSchema.getContents().add(outputTypeElement);
660
		_returnType = (DataType) getSelectedViewerObject();
675
		_returnType = (DataType) getSelectedViewerObject();
661
		return outputTypeElement;
676
		return outputTypeElement;
Lines 665-671 Link Here
665
	{
680
	{
666
		XSDElementDeclaration faultElement = XSDFactory.eINSTANCE
681
		XSDElementDeclaration faultElement = XSDFactory.eINSTANCE
667
				.createXSDElementDeclaration();
682
				.createXSDElementDeclaration();
668
		faultElement.setName(_methodName.getText() + "Fault");
683
		String name = _methodName.getText() + "Fault";
684
		INewNameGenerator generator = new NewXSDElementNameGenerator(
685
				_typesSchema, name);
686
		name = generator.getNewName();
687
		faultElement.setName(name);
669
		_typesSchema.getContents().add(faultElement);
688
		_typesSchema.getContents().add(faultElement);
670
689
671
		XSDComplexTypeDefinition complexTypeDefinition = XSDFactory.eINSTANCE
690
		XSDComplexTypeDefinition complexTypeDefinition = XSDFactory.eINSTANCE
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/util/internal/MetaDataUtils.java (-2 / +14 lines)
Lines 48-53 Link Here
48
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl;
48
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl;
49
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.util.MetadataDescriptorResourceImpl;
49
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.util.MetadataDescriptorResourceImpl;
50
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
50
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
51
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
51
import org.eclipse.tptp.wsdm.tooling.util.internal.MyMetadataDescriptorResourceFactoryImpl;
52
import org.eclipse.tptp.wsdm.tooling.util.internal.MyMetadataDescriptorResourceFactoryImpl;
52
import org.eclipse.tptp.wsdm.tooling.util.internal.RmdUtils;
53
import org.eclipse.tptp.wsdm.tooling.util.internal.RmdUtils;
53
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
54
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
Lines 420-429 Link Here
420
	}
421
	}
421
422
422
	public static void save(MetadataDescriptor metadataDescriptor,
423
	public static void save(MetadataDescriptor metadataDescriptor,
423
			IFile rmdFile, IProgressMonitor monitor)
424
			IProgressMonitor monitor)
424
	{
425
	{
425
		DocumentRoot _root = metadataDescriptor.getDocumentRoot();
426
		DocumentRoot _root = metadataDescriptor.getDocumentRoot();
426
		RmdUtils.serializeAndFormat(_root, rmdFile, monitor);
427
		String rmdRootURIPath = _root.eResource().getURI().toString();
428
		IFile rmdFile = null;
429
		try
430
		{
431
			rmdFile = EclipseUtils.getIFile(rmdRootURIPath);
432
		}
433
		catch (CoreException e)
434
		{
435
			WsdmToolingLog.logError(e.getMessage(), e);
436
		}
437
		if (rmdFile != null)
438
			RmdUtils.serializeAndFormat(_root, rmdFile, monitor);
427
	}
439
	}
428
440
429
	public static MetadataDescriptor createMetaDataDescriptor(
441
	public static MetadataDescriptor createMetaDataDescriptor(
(-)src/org/eclipse/tptp/wsdm/tooling/editor/mrt/internal/ManageableResourceTypeEditorPlugin.java (-71 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.mrt.internal;
14
15
import org.eclipse.ui.plugin.AbstractUIPlugin;
16
import org.osgi.framework.BundleContext;
17
18
/**
19
 * The activator class controls the plug-in life cycle
20
 */
21
public class ManageableResourceTypeEditorPlugin extends AbstractUIPlugin
22
{
23
24
	// The plug-in ID
25
	public static final String PLUGIN_ID = "org.eclipse.tptp.wsdm.tooling.editor.mrt";
26
27
	public static final String EXT_PT = "codeGeneration";
28
29
	// The shared instance
30
	private static ManageableResourceTypeEditorPlugin PLUGIN;
31
32
	/**
33
	 * The constructor
34
	 */
35
	public ManageableResourceTypeEditorPlugin()
36
	{
37
		PLUGIN = this;
38
	}
39
40
	/*
41
	 * (non-Javadoc)
42
	 * 
43
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
44
	 */
45
	public void start(BundleContext context) throws Exception
46
	{
47
		super.start(context);
48
		PLUGIN = this;
49
	}
50
51
	/*
52
	 * (non-Javadoc)
53
	 * 
54
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
55
	 */
56
	public void stop(BundleContext context) throws Exception
57
	{
58
		PLUGIN = null;
59
		super.stop(context);
60
	}
61
62
	/**
63
	 * Returns the shared instance
64
	 * 
65
	 * @return the shared instance
66
	 */
67
	public static ManageableResourceTypeEditorPlugin getDefault()
68
	{
69
		return PLUGIN;
70
	}
71
}
(-)src/org/eclipse/tptp/wsdm/tooling/wizard/capability/internal/NewCapabilityWizard.java (-15 / +70 lines)
Lines 19-24 Link Here
19
import java.util.HashMap;
19
import java.util.HashMap;
20
import java.util.Map;
20
import java.util.Map;
21
21
22
import javax.wsdl.Operation;
22
import javax.wsdl.PortType;
23
import javax.wsdl.PortType;
23
import javax.wsdl.Types;
24
import javax.wsdl.Types;
24
import javax.xml.namespace.QName;
25
import javax.xml.namespace.QName;
Lines 38-46 Link Here
38
import org.eclipse.jface.viewers.ISelection;
39
import org.eclipse.jface.viewers.ISelection;
39
import org.eclipse.jface.viewers.IStructuredSelection;
40
import org.eclipse.jface.viewers.IStructuredSelection;
40
import org.eclipse.jface.wizard.Wizard;
41
import org.eclipse.jface.wizard.Wizard;
42
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.ImportOperationCommand;
43
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ImportPropertyCommand;
44
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.wsdl.OperationImportWizardPage;
45
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.xsd.PropertyImportWizardPage;
41
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
46
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
42
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
47
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
43
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
48
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
49
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.INewNameGenerator;
50
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.namegenerator.NewIFileNameGenerator;
51
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
44
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
52
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
45
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
53
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
46
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
54
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
Lines 71-77 Link Here
71
79
72
	private NewCapabilityWizardPage _newCapPage;
80
	private NewCapabilityWizardPage _newCapPage;
73
81
74
	// private CapabilityFileWizardPage _capFilesPage;
82
	private CapabilityModelImporterPage _importerPage;
83
84
	private PropertyImportWizardPage _importPropertyPage;
85
86
	private OperationImportWizardPage _importOperationPage;
75
87
76
	private ISelection _selection;
88
	private ISelection _selection;
77
89
Lines 105-112 Link Here
105
		_newCapPage = new NewCapabilityWizardPage(_selection, this);
117
		_newCapPage = new NewCapabilityWizardPage(_selection, this);
106
		addPage(_newCapPage);
118
		addPage(_newCapPage);
107
119
108
		// _capFilesPage = new CapabilityFileWizardPage(_selection, this);
120
		_importerPage = new CapabilityModelImporterPage(_selection, this);
109
		// addPage(_capFilesPage);
121
		addPage(_importerPage);
122
123
		_importPropertyPage = new PropertyImportWizardPage();
124
		addPage(_importPropertyPage);
125
126
		_importOperationPage = new OperationImportWizardPage();
127
		addPage(_importOperationPage);
110
	}
128
	}
111
129
112
	/**
130
	/**
Lines 123-136 Link Here
123
			capPrefix = "tns";
141
			capPrefix = "tns";
124
		String capNS = _newCapPage.getNamespace();
142
		String capNS = _newCapPage.getNamespace();
125
		String targetCapFileName = _newCapPage.getTargetFileName();
143
		String targetCapFileName = _newCapPage.getTargetFileName();
126
		// String xsdFilePath = _capFilesPage.getXSDFilePath();
144
127
		// String xsdFileName = _capFilesPage.getXSDFileName();
145
		IResource resource = ResourcesPlugin.getWorkspace().getRoot()
128
		// String rmdFilePath = _capFilesPage.getRMDFilePath();
146
				.findMember(new Path(containerName));
129
		// String rmdFileName = _capFilesPage.getRMDFileName();
147
		INewNameGenerator generator = new NewIFileNameGenerator(resource,
130
		String xsdFilePath = containerName + "/" + capabilityName + ".xsd";
148
				capabilityName + ".xsd");
131
		String xsdFileName = capabilityName + ".xsd";
149
		String xsdFileName = generator.getNewName();
132
		String rmdFilePath = containerName + "/" + capabilityName + ".rmd";
150
		generator = new NewIFileNameGenerator(resource, capabilityName + ".rmd");
133
		String rmdFileName = capabilityName + ".rmd";
151
		String rmdFileName = generator.getNewName();
152
		String xsdFilePath = containerName + "/" + xsdFileName;
153
		String rmdFilePath = containerName + "/" + rmdFileName;
134
154
135
		String capNamespace = capNS;
155
		String capNamespace = capNS;
136
		String xsdNS = capNS;
156
		String xsdNS = capNS;
Lines 146-151 Link Here
146
			capFilePath = containerName + targetCapFileName;
166
			capFilePath = containerName + targetCapFileName;
147
		}
167
		}
148
168
169
		Property[] importedProperties = new Property[0];
170
		Operation[] importedOperations = new Operation[0];
171
172
		if (_importerPage.isFromXSDButtonSelected())
173
			importedProperties = _importPropertyPage.getImportedProperties();
174
		else if (_importerPage.isFromWSDLButtonSelected())
175
			importedOperations = _importOperationPage.getImportedOperations();
176
149
		_options.put(CapabilityWizardKeys.CONTAINER_NAME_KEY, containerName);
177
		_options.put(CapabilityWizardKeys.CONTAINER_NAME_KEY, containerName);
150
		_options.put(CapabilityWizardKeys.CAP_NS_KEY, capNamespace);
178
		_options.put(CapabilityWizardKeys.CAP_NS_KEY, capNamespace);
151
		_options.put(CapabilityWizardKeys.CAP_PREFIX_KEY, capPrefix);
179
		_options.put(CapabilityWizardKeys.CAP_PREFIX_KEY, capPrefix);
Lines 161-166 Link Here
161
		_options.put(CapabilityWizardKeys.RMD_FILE_NAME_KEY, rmdFileName);
189
		_options.put(CapabilityWizardKeys.RMD_FILE_NAME_KEY, rmdFileName);
162
		_options.put(CapabilityWizardKeys.RMD_NS_KEY, rmdNS);
190
		_options.put(CapabilityWizardKeys.RMD_NS_KEY, rmdNS);
163
191
192
		_options.put(CapabilityWizardKeys.IMPORT_PROPERTY_KEY,
193
				importedProperties);
194
		_options.put(CapabilityWizardKeys.IMPORT_OPERATION_KEY,
195
				importedOperations);
196
164
		IRunnableWithProgress shouldOverwriteOperation = new IRunnableWithProgress()
197
		IRunnableWithProgress shouldOverwriteOperation = new IRunnableWithProgress()
165
		{
198
		{
166
			public void run(IProgressMonitor monitor)
199
			public void run(IProgressMonitor monitor)
Lines 473-478 Link Here
473
		resourcePropertyElement.setName(capName + "Properties");
506
		resourcePropertyElement.setName(capName + "Properties");
474
		resourcePropertyElement.setTypeDefinition(null);
507
		resourcePropertyElement.setTypeDefinition(null);
475
		schema.getContents().add(resourcePropertyElement);
508
		schema.getContents().add(resourcePropertyElement);
509
510
		Property[] importedProperties = (Property[]) _options
511
				.get(CapabilityWizardKeys.IMPORT_PROPERTY_KEY);
512
		ImportPropertyCommand command = new ImportPropertyCommand(
513
				resourcePropertyElement, importedProperties);
514
		command.execute();
476
	}
515
	}
477
516
478
	private void createAnnotation(XSDSchema schema)
517
	private void createAnnotation(XSDSchema schema)
Lines 503-508 Link Here
503
		portType.setQName(new QName(capNS, capName + "PortType"));
542
		portType.setQName(new QName(capNS, capName + "PortType"));
504
		portType.setUndefined(false);
543
		portType.setUndefined(false);
505
		_wsdlCapDefinition.getDefinition().addPortType(portType);
544
		_wsdlCapDefinition.getDefinition().addPortType(portType);
545
546
		Operation[] importOperations = (Operation[]) _options
547
				.get(CapabilityWizardKeys.IMPORT_OPERATION_KEY);
548
549
		ImportOperationCommand command = new ImportOperationCommand(
550
				_wsdlCapDefinition, importOperations);
551
		command.execute();
506
	}
552
	}
507
553
508
	private void wsdlEdit()
554
	private void wsdlEdit()
Lines 533-542 Link Here
533
		return _newCapPage;
579
		return _newCapPage;
534
	}
580
	}
535
581
536
	/*
582
	public OperationImportWizardPage getOperationImportWizardPage()
537
	 * protected CapabilityFileWizardPage getCapabilityFileWizardPage() { return
583
	{
538
	 * _capFilesPage; }
584
		return _importOperationPage;
539
	 */
585
	}
586
587
	public PropertyImportWizardPage getPropertyImportWizardPage()
588
	{
589
		return _importPropertyPage;
590
	}
540
}
591
}
541
592
542
class CapabilityWizardKeys
593
class CapabilityWizardKeys
Lines 569-572 Link Here
569
	static final String IMPORT_XSD_KEY = "IMPORT_XSD";
620
	static final String IMPORT_XSD_KEY = "IMPORT_XSD";
570
621
571
	static final String IMPORT_WSDL_KEY = "IMPORT_WSDL";
622
	static final String IMPORT_WSDL_KEY = "IMPORT_WSDL";
623
624
	static final String IMPORT_PROPERTY_KEY = "IMPORT_PROPERTY";
625
626
	static final String IMPORT_OPERATION_KEY = "IMPORT_OPERATION";
572
}
627
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/internal/Activator.java (-2 / +21 lines)
Lines 25-33 Link Here
25
public final class Activator extends EMFPlugin
25
public final class Activator extends EMFPlugin
26
{
26
{
27
27
28
	// The plug-in ID
28
	// The model plug-in ID
29
	public static final String MODEL_PLUGIN_ID = "org.eclipse.tptp.wsdm.model";
30
31
	// The editor plug-in ID
29
	public static final String PLUGIN_ID = "org.eclipse.tptp.wsdm.editor";
32
	public static final String PLUGIN_ID = "org.eclipse.tptp.wsdm.editor";
30
33
34
	// Management capability extension point
35
	public static final String MR_CAPABILITY_EXT_PT = "mrCapability";
36
37
	// Capability validator extension point
38
	public static final String CAPABILITY_VALIDATOR_EXT_PT = "capabilityValidator";
39
40
	// MRT validator extension point
41
	public static final String MRT_VALIDATOR_EXT_PT = "mrtValidator";
42
43
	// DD validator extension point
44
	public static final String DD_VALIDATOR_EXT_PT = "ddeValidator";
45
46
	// Codegen extension point
47
	public static final String CODEGEN_EXT_PT = "codeGeneration";
48
31
	/**
49
	/**
32
	 * Keep track of the singleton. <!-- begin-user-doc --> <!-- end-user-doc
50
	 * Keep track of the singleton. <!-- begin-user-doc --> <!-- end-user-doc
33
	 * -->
51
	 * -->
Lines 51-57 Link Here
51
	 */
69
	 */
52
	public Activator()
70
	public Activator()
53
	{
71
	{
54
		super(new ResourceLocator[] {});
72
		super(new ResourceLocator[]
73
		{});
55
	}
74
	}
56
75
57
	/**
76
	/**
(-)src/org/eclipse/tptp/wsdm/tooling/validation/util/internal/ValidationUtils.java (-19 / +10 lines)
Lines 18-23 Link Here
18
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IExtension;
19
import org.eclipse.core.runtime.IExtension;
20
import org.eclipse.core.runtime.IExtensionPoint;
20
import org.eclipse.core.runtime.IExtensionPoint;
21
import org.eclipse.core.runtime.IExtensionRegistry;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
23
import org.eclipse.tptp.wsdm.tooling.editor.internal.Activator;
23
import org.eclipse.tptp.wsdm.tooling.nls.messages.validation.internal.Messages;
24
import org.eclipse.tptp.wsdm.tooling.nls.messages.validation.internal.Messages;
Lines 37-65 Link Here
37
public class ValidationUtils
38
public class ValidationUtils
38
{
39
{
39
40
40
	public static final String CAPABILITY_VALIDATOR_EXT_POINTID = "capabilityValidator";
41
42
	public static final String MRT_VALIDATOR_EXT_POINTID = "mrtValidator";
43
44
	public static final String DDE_VALIDATOR_EXT_POINTID = "ddeValidator";
45
46
	/**
47
	 * Returns IExtensionPoint of given name.
48
	 */
49
	public static IExtensionPoint getExtensionPoint(String point)
50
	{
51
		String pluginID = Activator.getPlugin().getBundle().getSymbolicName();
52
		return Platform.getExtensionRegistry().getExtensionPoint(pluginID,
53
				point);
54
	}
55
56
	/**
41
	/**
57
	 * Returns all the capability validators by reading the plugin registry.
42
	 * Returns all the capability validators by reading the plugin registry.
58
	 */
43
	 */
59
	public static ICapabilityValidator[] getAllCapabilityValidators()
44
	public static ICapabilityValidator[] getAllCapabilityValidators()
60
	{
45
	{
61
		List validators = new ArrayList();
46
		List validators = new ArrayList();
62
		IExtensionPoint iep = getExtensionPoint(CAPABILITY_VALIDATOR_EXT_POINTID);
47
		IExtensionRegistry er = Platform.getExtensionRegistry();
48
		IExtensionPoint iep = er.getExtensionPoint(Activator.PLUGIN_ID,
49
				Activator.CAPABILITY_VALIDATOR_EXT_PT);
63
		if (iep == null)
50
		if (iep == null)
64
		{
51
		{
65
			WsdmToolingLog.logWarning(Messages.COULDNT_FIND_CAP_VALIDATOR_EXT);
52
			WsdmToolingLog.logWarning(Messages.COULDNT_FIND_CAP_VALIDATOR_EXT);
Lines 97-103 Link Here
97
	public static IMrtValidator[] getAllMrtValidators()
84
	public static IMrtValidator[] getAllMrtValidators()
98
	{
85
	{
99
		List validators = new ArrayList();
86
		List validators = new ArrayList();
100
		IExtensionPoint iep = getExtensionPoint(MRT_VALIDATOR_EXT_POINTID);
87
		IExtensionRegistry er = Platform.getExtensionRegistry();
88
		IExtensionPoint iep = er.getExtensionPoint(Activator.PLUGIN_ID,
89
				Activator.MRT_VALIDATOR_EXT_PT);
101
		if (iep == null)
90
		if (iep == null)
102
		{
91
		{
103
			WsdmToolingLog.logWarning(Messages.COULDNT_FIND_MRT_VALIDATOR_EXT);
92
			WsdmToolingLog.logWarning(Messages.COULDNT_FIND_MRT_VALIDATOR_EXT);
Lines 135-141 Link Here
135
	public static IDdeValidator[] getAllDdeValidators()
124
	public static IDdeValidator[] getAllDdeValidators()
136
	{
125
	{
137
		List validators = new ArrayList();
126
		List validators = new ArrayList();
138
		IExtensionPoint iep = getExtensionPoint(DDE_VALIDATOR_EXT_POINTID);
127
		IExtensionRegistry er = Platform.getExtensionRegistry();
128
		IExtensionPoint iep = er.getExtensionPoint(Activator.PLUGIN_ID,
129
				Activator.DD_VALIDATOR_EXT_PT);
139
		if (iep == null)
130
		if (iep == null)
140
		{
131
		{
141
			WsdmToolingLog.logWarning(Messages.COULDNT_FIND_DDE_VALIDATOR_EXT);
132
			WsdmToolingLog.logWarning(Messages.COULDNT_FIND_DDE_VALIDATOR_EXT);
(-)src/org/eclipse/tptp/wsdm/tooling/validation/capability/internal/CapabilityValidator.java (-30 lines)
Lines 51-84 Link Here
51
		}
51
		}
52
		return report;
52
		return report;
53
	}
53
	}
54
55
	/**
56
	 * Perform RMD validation
57
	 */
58
	/*
59
	 * public IValidationReport validateRMD(Definition definition, DocumentRoot
60
	 * root) { CapabilityRMDValidator rmdValidator = new
61
	 * CapabilityRMDValidator(); IValidationReport rmdReport =
62
	 * rmdValidator.validate(definition, root); return rmdReport; }
63
	 */
64
65
	/**
66
	 * Perform WSDL validation
67
	 */
68
	/*
69
	 * public IValidationReport validateWSDL(Definition definition) {
70
	 * CapabilityWSDLValidator wsdlValidator = new CapabilityWSDLValidator();
71
	 * IValidationReport wsdlReport = wsdlValidator.validate(definition); return
72
	 * wsdlReport; }
73
	 */
74
75
	/**
76
	 * Perform XSD validation
77
	 */
78
	/*
79
	 * public IValidationReport validateXSD(Definition definition, XSDSchema
80
	 * propertySchema) { CapabilityXSDValidator xsdValidator = new
81
	 * CapabilityXSDValidator(); IValidationReport xsdReport =
82
	 * xsdValidator.validate(definition, propertySchema); return xsdReport; }
83
	 */
84
}
54
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/property/internal/ListSection.java (-3 / +44 lines)
Lines 14-22 Link Here
14
14
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.core.resources.IFile;
17
import org.eclipse.jface.viewers.SelectionChangedEvent;
18
import org.eclipse.jface.viewers.SelectionChangedEvent;
18
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.jface.window.Window;
20
import org.eclipse.jface.window.Window;
21
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.ControlAdapter;
23
import org.eclipse.swt.events.ControlAdapter;
22
import org.eclipse.swt.events.ControlEvent;
24
import org.eclipse.swt.events.ControlEvent;
Lines 29-40 Link Here
29
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.swt.widgets.Label;
30
import org.eclipse.swt.widgets.Listener;
32
import org.eclipse.swt.widgets.Listener;
31
import org.eclipse.swt.widgets.Tree;
33
import org.eclipse.swt.widgets.Tree;
34
import org.eclipse.tptp.wsdm.tooling.dialog.provisional.XSDBrowseDialog;
32
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.AddPropertyCommand;
35
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.AddPropertyCommand;
33
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ChangeModifiabilityCommand;
36
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ChangeModifiabilityCommand;
34
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ChangeMutabilityCommand;
37
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ChangeMutabilityCommand;
35
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ChangePropertyCardinalityCommand;
38
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ChangePropertyCardinalityCommand;
36
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ChangePropertyTypeCommand;
39
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ChangePropertyTypeCommand;
37
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.RemovePropertyCommand;
40
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.RemovePropertyCommand;
41
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.xsd.PropertyImportWizard;
38
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.AbstractCapabilityEditor;
42
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.AbstractCapabilityEditor;
39
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
43
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
40
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractPageSection;
44
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractPageSection;
Lines 42-52 Link Here
42
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
46
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
43
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
47
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
44
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.property.internal.Messages;
48
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.property.internal.Messages;
49
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
45
import org.eclipse.tptp.wsdm.tooling.viewers.internal.IViewerClient;
50
import org.eclipse.tptp.wsdm.tooling.viewers.internal.IViewerClient;
46
import org.eclipse.tptp.wsdm.tooling.viewers.internal.StructuredTreeViewer;
51
import org.eclipse.tptp.wsdm.tooling.viewers.internal.StructuredTreeViewer;
47
import org.eclipse.ui.forms.widgets.FormToolkit;
52
import org.eclipse.ui.forms.widgets.FormToolkit;
48
import org.eclipse.ui.forms.widgets.ScrolledForm;
53
import org.eclipse.ui.forms.widgets.ScrolledForm;
49
import org.eclipse.xsd.XSDElementDeclaration;
54
import org.eclipse.xsd.XSDElementDeclaration;
55
import org.eclipse.xsd.XSDSchema;
50
56
51
/**
57
/**
52
 * 
58
 * 
Lines 65-70 Link Here
65
71
66
	private Button _addPropertyButton;
72
	private Button _addPropertyButton;
67
73
74
	private Button _importPropertyButton;
75
68
	private Button _editMetadataButton;
76
	private Button _editMetadataButton;
69
77
70
	private Button _removePropertyButton;
78
	private Button _removePropertyButton;
Lines 138-147 Link Here
138
					}
146
					}
139
				});
147
				});
140
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
148
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
141
		gd.widthHint = 80;
149
		gd.widthHint = 100;
142
		_addPropertyButton.setLayoutData(gd);
150
		_addPropertyButton.setLayoutData(gd);
143
		_addPropertyButton.setEnabled(!_editor.isReadOnly());
151
		_addPropertyButton.setEnabled(!_editor.isReadOnly());
144
152
153
		_importPropertyButton = createPushButton(
154
				_buttonClient,
155
				toolkit,
156
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.IMPORT_PROPERTIES,
157
				new Listener()
158
				{
159
					public void handleEvent(Event event)
160
					{
161
						importProperty();
162
					}
163
				});
164
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
165
		gd.widthHint = 100;
166
		_importPropertyButton.setLayoutData(gd);
167
		_importPropertyButton.setEnabled(!_editor.isReadOnly());
168
145
		_editMetadataButton = createPushButton(_buttonClient, toolkit,
169
		_editMetadataButton = createPushButton(_buttonClient, toolkit,
146
				Messages.EDIT_METADATA_LABEL, new Listener()
170
				Messages.EDIT_METADATA_LABEL, new Listener()
147
				{
171
				{
Lines 151-157 Link Here
151
					}
175
					}
152
				});
176
				});
153
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
177
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
154
		gd.widthHint = 80;
178
		gd.widthHint = 100;
155
		_editMetadataButton.setLayoutData(gd);
179
		_editMetadataButton.setLayoutData(gd);
156
		_editMetadataButton.setEnabled(false);
180
		_editMetadataButton.setEnabled(false);
157
181
Lines 167-173 Link Here
167
					}
191
					}
168
				});
192
				});
169
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
193
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
170
		gd.widthHint = 80;
194
		gd.widthHint = 100;
171
		_removePropertyButton.setLayoutData(gd);
195
		_removePropertyButton.setLayoutData(gd);
172
		_removePropertyButton.setEnabled(false);
196
		_removePropertyButton.setEnabled(false);
173
197
Lines 217-222 Link Here
217
		}
241
		}
218
	}
242
	}
219
243
244
	private void importProperty()
245
	{
246
		XSDBrowseDialog dialog = new XSDBrowseDialog(getForm().getShell());
247
		if (dialog.open() == Window.OK)
248
		{
249
			IFile xsdFile = (IFile) dialog.getFirstResult();
250
			// TODO Check for valid schema file
251
			XSDSchema importedSchema = XsdUtils.getSchema(xsdFile);
252
			PropertyImportWizard importPropertyWizard = new PropertyImportWizard(
253
					_editor.getCapabilityDomain(), importedSchema);
254
			WizardDialog wizardDialog = new WizardDialog(getForm().getShell(),
255
					importPropertyWizard);
256
			wizardDialog.open();
257
			_page.setDirty();
258
		}
259
	}
260
220
	private void editMetadata()
261
	private void editMetadata()
221
	{
262
	{
222
		CapabilityDomain capabilityDomain = (CapabilityDomain) _editor
263
		CapabilityDomain capabilityDomain = (CapabilityDomain) _editor
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/xsd/ImportValidationStatus.java (+37 lines)
Added 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.xsd;
14
15
public class ImportValidationStatus
16
{
17
18
	private String _errorMessage;
19
	private Object[] _causeOfError;
20
21
	public ImportValidationStatus(String errorMessage, Object[] causeOfError)
22
	{
23
		_errorMessage = errorMessage;
24
		_causeOfError = causeOfError;
25
	}
26
27
	public String getErrorMessage()
28
	{
29
		return _errorMessage;
30
	}
31
32
	public Object[] getCauseOfError()
33
	{
34
		return _causeOfError;
35
	}
36
37
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/CapabilityStorageEditorInput.java (+69 lines)
Added 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.internal;
14
15
import org.eclipse.core.resources.IStorage;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.PlatformObject;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.ui.IPersistableElement;
20
import org.eclipse.ui.IStorageEditorInput;
21
22
/**
23
 * This class has been designed to use for opening any existing capability from
24
 * within MRT file.<br>
25
 * This class implements the IStorageEditorInput interface which is used to open
26
 * a file as a stream of bytes.<br>
27
 */
28
29
public class CapabilityStorageEditorInput extends PlatformObject implements
30
		IStorageEditorInput
31
{
32
33
	private ICapabilityStorage _storage;
34
35
	public CapabilityStorageEditorInput(ICapabilityStorage storage)
36
	{
37
		_storage = storage;
38
	}
39
40
	public IStorage getStorage() throws CoreException
41
	{
42
		return _storage;
43
	}
44
45
	public boolean exists()
46
	{
47
		return _storage.exists();
48
	}
49
50
	public ImageDescriptor getImageDescriptor()
51
	{
52
		return null;
53
	}
54
55
	public String getName()
56
	{
57
		return _storage.getName();
58
	}
59
60
	public IPersistableElement getPersistable()
61
	{
62
		return null;
63
	}
64
65
	public String getToolTipText()
66
	{
67
		return getName();
68
	}
69
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/xsd/PropertySchemaContentProvider.java (+80 lines)
Added 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.xsd;
14
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
19
import org.eclipse.jface.viewers.ITreeContentProvider;
20
import org.eclipse.jface.viewers.Viewer;
21
22
public class PropertySchemaContentProvider implements ITreeContentProvider
23
{
24
	private final Map _parentMap;
25
26
	public PropertySchemaContentProvider()
27
	{
28
		_parentMap = new HashMap();
29
	}
30
31
	public Object[] getChildren(Object parentElement)
32
	{
33
		if (parentElement instanceof List)
34
		{
35
			List l = (List) parentElement;
36
			return l.toArray();
37
		}
38
		else if (parentElement instanceof PropertyNamespace)
39
		{
40
			PropertyNamespace propNamespace = (PropertyNamespace) parentElement;
41
			Object[] elements = rememberChildren(parentElement, propNamespace
42
					.getProperties());
43
			return elements;
44
		}
45
		return new Object[0];
46
	}
47
48
	public Object getParent(Object element)
49
	{
50
		Object retVal = _parentMap.get(element);
51
		return retVal;
52
	}
53
54
	public boolean hasChildren(Object element)
55
	{
56
		return (getChildren(element).length > 0);
57
	}
58
59
	public Object[] getElements(Object inputElement)
60
	{
61
		return getChildren(inputElement);
62
	}
63
64
	public void dispose()
65
	{
66
	}
67
68
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
69
	{
70
	}
71
72
	private Object[] rememberChildren(Object parent, Object[] childrens)
73
	{
74
		for (int i = 0; i < childrens.length; i++)
75
		{
76
			_parentMap.put(childrens[i], parent);
77
		}
78
		return childrens;
79
	}
80
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/wsdl/XSDSchemaMerger.java (+91 lines)
Added 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
public class XSDSchemaMerger
24
{
25
26
	private XSDSchema _schema;
27
	private List _allResultedSchema;
28
29
	public XSDSchemaMerger(XSDSchema schema)
30
	{
31
		_schema = schema;
32
		_allResultedSchema = new LinkedList();
33
		addSchema(_schema);
34
	}
35
36
	public XSDSchema[] merge()
37
	{
38
		XSDImport[] imports = XsdUtils.getAllXSDImports(_schema);
39
		for (int i = 0; i < imports.length; i++)
40
		{
41
			if (imports[i].getResolvedSchema() == null)
42
				continue;
43
			addSchema(imports[i].getResolvedSchema());
44
			XSDSchemaMerger merger = new XSDSchemaMerger(imports[i]
45
					.getResolvedSchema());
46
			XSDSchema[] schemas = merger.merge();
47
			for (int j = 0; j < schemas.length; j++)
48
				addSchema(schemas[j]);
49
		}
50
51
		XSDInclude[] includes = XsdUtils.getAllXSDIncludes(_schema);
52
		for (int i = 0; i < includes.length; i++)
53
		{
54
			if (includes[i].getResolvedSchema() == null)
55
				continue;
56
			addSchema(includes[i].getResolvedSchema());
57
			XSDSchemaMerger merger = new XSDSchemaMerger(includes[i]
58
					.getResolvedSchema());
59
			XSDSchema[] schemas = merger.merge();
60
			for (int j = 0; j < schemas.length; j++)
61
				addSchema(schemas[j]);
62
		}
63
64
		return (XSDSchema[]) _allResultedSchema
65
				.toArray(new XSDSchema[_allResultedSchema.size()]);
66
	}
67
68
	private void addSchema(XSDSchema givenSchema)
69
	{
70
		XSDSchema schema = getSchema(givenSchema.getTargetNamespace());
71
		if (schema != null)
72
		{
73
			List givenSchemaContents = givenSchema.getContents();
74
			for (int i = 0; i < givenSchemaContents.size(); i++)
75
				schema.getContents().add(givenSchemaContents.get(i));
76
		}
77
		else
78
			_allResultedSchema.add(givenSchema);
79
	}
80
81
	private XSDSchema getSchema(String targetNamespace)
82
	{
83
		for (int i = 0; i < _allResultedSchema.size(); i++)
84
		{
85
			XSDSchema schema = (XSDSchema) _allResultedSchema.get(i);
86
			if (schema.getTargetNamespace().equals(targetNamespace))
87
				return schema;
88
		}
89
		return null;
90
	}
91
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/operation/internal/ImportOperationCommand.java (+260 lines)
Added 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.command.operation.internal;
14
15
import java.util.Iterator;
16
import java.util.LinkedList;
17
import java.util.List;
18
import java.util.Map;
19
20
import javax.wsdl.Definition;
21
import javax.wsdl.Fault;
22
import javax.wsdl.Input;
23
import javax.wsdl.Message;
24
import javax.wsdl.Operation;
25
import javax.wsdl.Output;
26
import javax.wsdl.PortType;
27
28
import org.eclipse.core.runtime.IProgressMonitor;
29
import org.eclipse.core.runtime.NullProgressMonitor;
30
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
31
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
32
import org.eclipse.xsd.XSDElementDeclaration;
33
import org.eclipse.xsd.XSDImport;
34
import org.eclipse.xsd.XSDInclude;
35
import org.eclipse.xsd.XSDSchema;
36
37
public class ImportOperationCommand
38
{
39
	private CapabilityDefinition _capabilityDefinition;
40
	private Definition _definition;
41
	private Operation[] _importedOperations;
42
	private List _newOperations;
43
	private IProgressMonitor _monitor;
44
45
	public ImportOperationCommand(CapabilityDefinition capabilityDefinition,
46
			Operation[] importedOperations, IProgressMonitor monitor)
47
	{
48
		_capabilityDefinition = capabilityDefinition;
49
		_definition = _capabilityDefinition.getDefinition();
50
		_importedOperations = importedOperations;
51
		_newOperations = new LinkedList();
52
		_monitor = monitor;
53
		XSDSchema[] capabilityWsdlSchemas = _capabilityDefinition
54
				.getXSDSchemas();
55
		// TODO
56
		/*
57
		 * if(capabilityWsdlSchemas == null) // No wsdl types defined { Types
58
		 * types = WSDLFactory.eINSTANCE.createTypes();
59
		 * types.setEnclosingDefinition(_capabilityDefinition);
60
		 * _capabilityDefinition.setETypes(types); }
61
		 */
62
		if (monitor == null)
63
			_monitor = new NullProgressMonitor();
64
	}
65
66
	public ImportOperationCommand(CapabilityDefinition capabilityDefinition,
67
			Operation[] importedOperations)
68
	{
69
		this(capabilityDefinition, importedOperations, null);
70
	}
71
72
	public void execute()
73
	{
74
		_monitor.beginTask(Messages.IMPORTING_OPERATIONS,
75
				_importedOperations.length);
76
		for (int i = 0; i < _importedOperations.length; i++)
77
		{
78
			String taskName = Messages.bind(Messages.IMPORTING_OPERATION,
79
					_importedOperations[i].getName());
80
			_monitor.setTaskName(taskName);
81
			Operation newOperation = createNewOperation(_importedOperations[i]);
82
			_newOperations.add(newOperation);
83
			_monitor.worked(i + 1);
84
		}
85
	}
86
87
	private Operation createNewOperation(Operation importedOperation)
88
	{
89
		Operation newOperation = _definition.createOperation();
90
		newOperation.setUndefined(false);
91
		PortType port = _capabilityDefinition.getPortType();
92
		port.addOperation(newOperation);
93
		newOperation.setName(importedOperation.getName());
94
95
		createNewOperationInput(newOperation, importedOperation);
96
		createNewOperationOutput(newOperation, importedOperation);
97
		createNewOperationFaults(newOperation, importedOperation);
98
99
		return newOperation;
100
	}
101
102
	private void createNewOperationInput(Operation newOperation,
103
			Operation importedOperation)
104
	{
105
		Input newInput = _definition.createInput();
106
		newOperation.setUndefined(false);
107
		newOperation.setInput(newInput);
108
		newInput.setName(importedOperation.getInput().getName());
109
110
		Message importedMessage = importedOperation.getInput().getMessage();
111
		Message newMessage = createNewMessage(importedMessage);
112
		newInput.setMessage(newMessage);
113
		_capabilityDefinition.addMessage(newMessage);
114
115
		// TODO
116
		/*
117
		 * String opName = importedOperation.getName(); opName =
118
		 * opName.substring(0, 1).toUpperCase() + opName.substring(1); String
119
		 * tns = _capabilityDefinition.getTargetNamespace();
120
		 * if(!tns.endsWith("/")) tns = tns+"/"; String action =
121
		 * tns+opName+"Request";
122
		 * newInput.getElement().setAttributeNS(WsdmConstants.WSA_URI,
123
		 * WsdmConstants.WSA_ACTION_NAME, action);
124
		 */
125
	}
126
127
	private void createNewOperationOutput(Operation newOperation,
128
			Operation importedOperation)
129
	{
130
		if (importedOperation.getOutput() == null)
131
			return;
132
133
		Output newOutput = _definition.createOutput();
134
		newOperation.setOutput(newOutput);
135
		newOutput.setName(importedOperation.getOutput().getName());
136
137
		Message importedMessage = importedOperation.getOutput().getMessage();
138
		Message newMessage = createNewMessage(importedMessage);
139
		newOutput.setMessage(newMessage);
140
		_capabilityDefinition.addMessage(newMessage);
141
142
		// TODO
143
		/*
144
		 * String opName = importedOperation.getName(); opName =
145
		 * opName.substring(0, 1).toUpperCase() + opName.substring(1); String
146
		 * tns = _capabilityDefinition.getTargetNamespace();
147
		 * if(!tns.endsWith("/")) tns = tns+"/"; String action =
148
		 * tns+opName+"Response";
149
		 * newOutput.getElement().setAttributeNS(WsdmConstants.WSA_URI,
150
		 * WsdmConstants.WSA_ACTION_NAME, action);
151
		 */
152
	}
153
154
	private void createNewOperationFaults(Operation newOperation,
155
			Operation importedOperation)
156
	{
157
		Map importedFaultsMap = importedOperation.getFaults();
158
		if (importedFaultsMap == null || importedFaultsMap.size() == 0)
159
			return;
160
		Iterator it = importedFaultsMap.values().iterator();
161
		while (it.hasNext())
162
		{
163
			Object object = it.next();
164
			if (object instanceof Fault)
165
			{
166
				Fault importFault = (Fault) object;
167
				Fault newFault = _definition.createFault();
168
				newOperation.addFault(newFault);
169
				newFault.setName(importFault.getName());
170
171
				Message importedMessage = importFault.getMessage();
172
				Message newMessage = createNewMessage(importedMessage);
173
				newFault.setMessage(newMessage);
174
				_capabilityDefinition.addMessage(newMessage);
175
			}
176
		}
177
	}
178
179
	private Message createNewMessage(Message importedMessage)
180
	{
181
		// TODO
182
		/*
183
		 * Message existingMessage =
184
		 * WsdlUtils.getWSDLMessage(_capabilityDefinition,
185
		 * importedMessage.getQName().getLocalPart()); if(existingMessage!=null)
186
		 * return existingMessage; Message message =
187
		 * WSDLFactory.eINSTANCE.createMessage();
188
		 * message.setEnclosingDefinition(_capabilityDefinition); String
189
		 * messageLocalName = importedMessage.getQName().getLocalPart();
190
		 * message.setQName(new
191
		 * QName(_capabilityDefinition.getTargetNamespace(),messageLocalName));
192
		 * Part part = WSDLFactory.eINSTANCE.createPart();
193
		 * part.setEnclosingDefinition(_capabilityDefinition);
194
		 * message.addPart(part); Part importedPart = (Part)
195
		 * importedMessage.getEParts().get(0);
196
		 * importSchemaForElement(importedPart.getElementDeclaration()); String
197
		 * xsdNS = importedPart.getElementDeclaration().getTargetNamespace();
198
		 * String elementName = importedPart.getElementDeclaration().getName();
199
		 * XSDSchema elementSchema = WsdlUtils.getSchema(_capabilityDefinition,
200
		 * xsdNS); XSDElementDeclaration element =
201
		 * XsdUtils.getXSDElementDeclarationOfName(elementSchema, elementName);
202
		 * WsdlUtils.createOrFindPrefix(_capabilityDefinition,
203
		 * element.getTargetNamespace(), null);
204
		 * part.setName(importedPart.getName());
205
		 * part.setElementDeclaration(element); part.setElementName(new
206
		 * QName(xsdNS, elementName)); return message;
207
		 */
208
		return _definition.createMessage();
209
	}
210
211
	private void importSchemaForElement(XSDElementDeclaration element)
212
	{
213
		// TODO
214
		/*
215
		 * XSDSchema elementSchema = element.getSchema(); XSDSchemaMerger merger =
216
		 * new XSDSchemaMerger(elementSchema); XSDSchema[] mergedSchemas =
217
		 * merger.merge(); for(int i=0;i<mergedSchemas.length;i++) {
218
		 * if(!isSchemaExistsInWsdl(mergedSchemas[i])) {
219
		 * XSDSchemaExtensibilityElement schemaElement = WSDLFactory.eINSTANCE
220
		 * .createXSDSchemaExtensibilityElement();
221
		 * schemaElement.setEnclosingDefinition(_capabilityDefinition);
222
		 * XSDSchema copySchema = createCopy(mergedSchemas[i]);
223
		 * schemaElement.setSchema(copySchema);
224
		 * _capabilityDefinition.getTypes().addExtensibilityElement(schemaElement); } }
225
		 */
226
	}
227
228
	private boolean isSchemaExistsInWsdl(XSDSchema schema)
229
	{
230
		XSDSchema wsdlSchema = _capabilityDefinition.getSchema(schema
231
				.getTargetNamespace());
232
		if (wsdlSchema != null)
233
			return true;
234
		return false;
235
	}
236
237
	private XSDSchema createCopy(XSDSchema schema)
238
	{
239
		XSDSchema copySchema = (XSDSchema) schema.cloneConcreteComponent(true,
240
				false);
241
		List contents = copySchema.getContents();
242
		for (int i = 0; i < contents.size(); i++)
243
		{
244
			if (contents.get(i) instanceof XSDInclude)
245
				contents.remove(i);
246
			else if (contents.get(i) instanceof XSDImport)
247
			{
248
				XSDImport theImport = (XSDImport) contents.get(i);
249
				theImport.setSchemaLocation(null);
250
			}
251
		}
252
		return copySchema;
253
	}
254
255
	public Operation[] getNewOperations()
256
	{
257
		return (Operation[]) _newOperations
258
				.toArray(new Operation[_newOperations.size()]);
259
	}
260
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/xsd/PropertyImportWizardPage.java (+250 lines)
Added 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.xsd;
14
15
import java.util.Arrays;
16
import java.util.LinkedList;
17
import java.util.List;
18
19
import org.eclipse.jface.dialogs.Dialog;
20
import org.eclipse.jface.viewers.CheckStateChangedEvent;
21
import org.eclipse.jface.viewers.CheckboxTreeViewer;
22
import org.eclipse.jface.viewers.ICheckStateListener;
23
import org.eclipse.jface.viewers.StructuredSelection;
24
import org.eclipse.jface.wizard.IWizardPage;
25
import org.eclipse.jface.wizard.WizardPage;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
32
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
33
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
34
import org.eclipse.xsd.XSDElementDeclaration;
35
import org.eclipse.xsd.XSDSchema;
36
37
public class PropertyImportWizardPage extends WizardPage
38
{
39
	private XSDSchema _importSchema;
40
	private PropertyNamespace[] _existingPropertyNs = new PropertyNamespace[0];
41
	private CheckboxTreeViewer _viewer;
42
	private PropertySchemaContentProvider _contentProvider;
43
	private Property[] _importedProperties;
44
45
	public PropertyImportWizardPage()
46
	{
47
		super("ImportPropertyWizardPage");
48
		setTitle(Messages.PROPERTY_IMPORT_WIZARD_PAGE_TITLE);
49
		setDescription(Messages.PROPERTY_IMPORT_WIZARD_PAGE_DESCRIPTION);
50
	}
51
52
	public PropertyImportWizardPage(XSDSchema importSchema,
53
			PropertyNamespace[] existingPropertyNs)
54
	{
55
		super("ImportPropertyWizardPage");
56
		setTitle(Messages.PROPERTY_IMPORT_WIZARD_PAGE_TITLE);
57
		setDescription(Messages.PROPERTY_IMPORT_WIZARD_PAGE_DESCRIPTION);
58
		_importSchema = importSchema;
59
		if (existingPropertyNs != null)
60
			_existingPropertyNs = existingPropertyNs;
61
	}
62
63
	public PropertyImportWizardPage(XSDSchema importSchema)
64
	{
65
		this(importSchema, null);
66
	}
67
68
	public void createControl(Composite parent)
69
	{
70
		initializeDialogUnits(parent);
71
		Composite container = new Composite(parent, SWT.NULL);
72
		container.setFont(parent.getFont());
73
		GridLayout layout = new GridLayout();
74
		container.setLayout(layout);
75
		layout.verticalSpacing = 9;
76
77
		Label availablePropertiesLabel = new Label(container, SWT.WRAP);
78
		availablePropertiesLabel.setText(Messages.AVAILABLE_PROPERTIES_LABEL);
79
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
80
		gd.minimumHeight = 15;
81
		availablePropertiesLabel.setLayoutData(gd);
82
83
		_viewer = new CheckboxTreeViewer(container, SWT.MULTI | SWT.BORDER);
84
		_contentProvider = new PropertySchemaContentProvider();
85
		_viewer.setContentProvider(_contentProvider);
86
		_viewer.setLabelProvider(new PropertySchemaLabelProvider(getShell()));
87
		_viewer.getControl().setLayoutData(
88
				new GridData(SWT.FILL, SWT.FILL, true, true));
89
		_viewer.addCheckStateListener(new ICheckStateListener()
90
		{
91
			public void checkStateChanged(CheckStateChangedEvent event)
92
			{
93
				handleCheckStateChanged(event);
94
			}
95
		});
96
		gd = new GridData(SWT.FILL, SWT.FILL, true, true);
97
		gd.heightHint = 200;
98
		gd.widthHint = 300;
99
		_viewer.getControl().setLayoutData(gd);
100
101
		initialize();
102
		// getShell().setSize(500, 100);
103
		setControl(container);
104
		Dialog.applyDialogFont(parent);
105
	}
106
107
	private void initialize()
108
	{
109
		_importedProperties = new Property[0];
110
		if (_importSchema != null)
111
		{
112
			// Get the Consolidated list of schemas
113
			// (Provided through constructor + Schemas collect from given
114
			// capability file)
115
			List allPropNamespaces = new LinkedList();
116
			PropertyNamespace importPropNamespace = createPropertyNamespaceFromImportedSchema();
117
			allPropNamespaces.addAll(Arrays.asList(_existingPropertyNs));
118
			allPropNamespaces.add(importPropNamespace);
119
			_viewer.setInput(allPropNamespaces);
120
		}
121
		// _viewer.expandToLevel(2);
122
		// Checked the Schemas provided by constructor
123
		doIntialCheckedElements();
124
		_viewer.setGrayedElements(_existingPropertyNs);
125
		updateStatus(null);
126
	}
127
128
	protected void doIntialCheckedElements()
129
	{
130
		for (int i = 0; i < _existingPropertyNs.length; i++)
131
			_viewer.setSubtreeChecked(_existingPropertyNs[i], true);
132
	}
133
134
	public void setImportSchema(XSDSchema importSchema)
135
	{
136
		_importSchema = importSchema;
137
		initialize();
138
	}
139
140
	private void handleCheckStateChanged(CheckStateChangedEvent event)
141
	{
142
		// We don't allow user to check uncheck any Properties provided in
143
		// constructor
144
		PropertyNamespace checkedElementNS = getNamespaceOfChekedElement(event
145
				.getElement());
146
		for (int i = 0; i < _existingPropertyNs.length; i++)
147
		{
148
			if (_existingPropertyNs[i].equals(checkedElementNS))
149
			{
150
				_viewer.setChecked(event.getElement(), !event.getChecked());
151
				return;
152
			}
153
		}
154
155
		_viewer.setSubtreeChecked(event.getElement(), event.getChecked());
156
		Property[] checkedProperties = getCheckedProperties();
157
		PropertyImportValidator validator = new PropertyImportValidator(
158
				checkedProperties);
159
		ImportValidationStatus status = validator.validate();
160
		updateStatus(null);
161
		if (status != null)
162
		{
163
			Object[] causeOfError = status.getCauseOfError();
164
			for (int i = 0; i < causeOfError.length; i++)
165
				_viewer.reveal(causeOfError[i]);
166
			_viewer.setSelection(new StructuredSelection(causeOfError));
167
			updateStatus(status.getErrorMessage());
168
		}
169
		_importedProperties = getSelectedProperties();
170
	}
171
172
	private void updateStatus(String message)
173
	{
174
		setErrorMessage(message);
175
		setPageComplete(message == null);
176
	}
177
178
	private PropertyNamespace getNamespaceOfChekedElement(Object checkedElement)
179
	{
180
		if (checkedElement instanceof PropertyNamespace)
181
			return (PropertyNamespace) checkedElement;
182
		Object parent = _contentProvider.getParent(checkedElement);
183
		while (!(parent instanceof PropertyNamespace))
184
			parent = _contentProvider.getParent(parent);
185
		return (PropertyNamespace) parent;
186
	}
187
188
	/**
189
	 * Returns all the checked xsd properties from viewer.
190
	 */
191
	private Property[] getCheckedProperties()
192
	{
193
		Object[] checkedElements = _viewer.getCheckedElements();
194
		List selectedOperationList = new LinkedList();
195
		for (int i = 0; i < checkedElements.length; i++)
196
		{
197
			if (checkedElements[i] instanceof Property)
198
				selectedOperationList.add(checkedElements[i]);
199
		}
200
		return (Property[]) selectedOperationList
201
				.toArray(new Property[selectedOperationList.size()]);
202
	}
203
204
	private Property[] getSelectedProperties()
205
	{
206
		Property[] checkedProperties = getCheckedProperties();
207
		List selectedProperties = new LinkedList();
208
		for (int i = 0; i < checkedProperties.length; i++)
209
		{
210
			PropertyNamespace checkedElementNS = getNamespaceOfChekedElement(checkedProperties[i]);
211
			boolean isImportProperty = true;
212
			for (int j = 0; j < _existingPropertyNs.length; j++)
213
			{
214
				if (_existingPropertyNs[j].equals(checkedElementNS))
215
				{
216
					isImportProperty = false;
217
					break;
218
				}
219
			}
220
			if (isImportProperty)
221
				selectedProperties.add(checkedProperties[i]);
222
		}
223
		return (Property[]) selectedProperties
224
				.toArray(new Property[selectedProperties.size()]);
225
	}
226
227
	public Property[] getImportedProperties()
228
	{
229
		return _importedProperties;
230
	}
231
232
	public IWizardPage getNextPage()
233
	{
234
		return null;
235
	}
236
237
	private PropertyNamespace createPropertyNamespaceFromImportedSchema()
238
	{
239
		PropertyNamespace propNamespace = new PropertyNamespace(_importSchema
240
				.getTargetNamespace());
241
		List importElements = _importSchema.getElementDeclarations();
242
		for (int i = 0; i < importElements.size(); i++)
243
		{
244
			Property property = CapabilitiesFactory.INSTANCE.createProperty();
245
			property.setElement((XSDElementDeclaration) importElements.get(i));
246
			propNamespace.addProperty(property);
247
		}
248
		return propNamespace;
249
	}
250
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/ui/internal/namegenerator/INewNameGenerator.java (+20 lines)
Added 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.ui.internal.namegenerator;
14
15
public interface INewNameGenerator
16
{
17
18
	public String getNewName();
19
20
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/wsdl/OperationImportValidator.java (+210 lines)
Added 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.HashMap;
16
import java.util.Iterator;
17
import java.util.Map;
18
19
import javax.wsdl.Fault;
20
import javax.wsdl.Message;
21
import javax.wsdl.Operation;
22
import javax.wsdl.Part;
23
import javax.xml.namespace.QName;
24
25
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.xsd.ImportValidationStatus;
26
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
27
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
28
29
public class OperationImportValidator
30
{
31
32
	private Operation[] _operations;
33
	private Map _map = new HashMap();
34
	public static final String XMLSCHEMA_2001_URI = "http://www.w3.org/2001/XMLSchema";
35
36
	public OperationImportValidator(Operation[] operations)
37
	{
38
		_operations = operations;
39
	}
40
41
	public ImportValidationStatus validate()
42
	{
43
		Map operationNames = new HashMap();
44
		if (_operations == null)
45
			return null;
46
		for (int i = 0; i < _operations.length; i++)
47
		{
48
			String operationName = _operations[i].getName();
49
50
			// Validate operation name against AbstractCapability methods
51
			if (CapUtils.isOperationNameConflicted(operationName))
52
			{
53
				String errorMessage = org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages
54
						.bind(
55
								org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages.CONFLICTED_OPERATION_WARN_,
56
								operationName);
57
				return new ImportValidationStatus(errorMessage, new Object[]
58
				{ _operations[i] });
59
			}
60
61
			// Validate duplicate operation name
62
			if (!operationNames.containsKey(operationName))
63
				operationNames.put(operationName, _operations[i]);
64
			else
65
			{
66
				String errorMessage = Messages.bind(
67
						Messages.DUPLICATE_OPERATION, operationName);
68
				Operation causeOfError_1 = (Operation) operationNames
69
						.get(operationName);
70
				Operation causeOfError_2 = _operations[i];
71
				return new ImportValidationStatus(errorMessage, new Object[]
72
				{ causeOfError_1, causeOfError_2 });
73
			}
74
75
			// Since we are going to merge all the messages in one wsdl file
76
			// There should not be two messages having same name but different
77
			// namespaces.
78
79
			// Validate Input Message
80
			if (_operations[i].getInput() != null)
81
			{
82
				Message inputMessage = _operations[i].getInput().getMessage();
83
				if (!isDocLiteralMessage(inputMessage))
84
				{
85
					String errorMessage = Messages.NOT_DOC_LITERAL_MESSAGE;
86
					return new ImportValidationStatus(errorMessage,
87
							new Object[]
88
							{ inputMessage });
89
				}
90
				Message conflictedMessage = validateConflictedMessage(inputMessage);
91
				if (conflictedMessage != null)
92
				{
93
					String newLine = System.getProperty("line.separator");
94
					String errorMessage = Messages.CONFLICTED_MESSAGE + newLine
95
							+ conflictedMessage.getQName().toString() + newLine
96
							+ inputMessage.getQName().toString();
97
					return new ImportValidationStatus(errorMessage,
98
							new Object[]
99
							{ conflictedMessage, inputMessage });
100
				}
101
			}
102
			else
103
			{
104
				String errorMessage = Messages.INPUT_MESSAGE_NOT_DEFINED;
105
				return new ImportValidationStatus(errorMessage, new Object[]
106
				{ _operations[i] });
107
			}
108
109
			// Validate Output Message
110
			if (_operations[i].getOutput() != null)
111
			{
112
				Message outputMessage = _operations[i].getOutput().getMessage();
113
				if (!isDocLiteralMessage(outputMessage))
114
				{
115
					String errorMessage = Messages.NOT_DOC_LITERAL_MESSAGE;
116
					return new ImportValidationStatus(errorMessage,
117
							new Object[]
118
							{ outputMessage });
119
				}
120
				Message conflictedMessage = validateConflictedMessage(outputMessage);
121
				if (conflictedMessage != null)
122
				{
123
					String newLine = System.getProperty("line.separator");
124
					String errorMessage = Messages.CONFLICTED_MESSAGE + newLine
125
							+ conflictedMessage.getQName().toString() + newLine
126
							+ outputMessage.getQName().toString();
127
					return new ImportValidationStatus(errorMessage,
128
							new Object[]
129
							{ conflictedMessage, outputMessage });
130
				}
131
			}
132
			else
133
			{
134
				String errorMessage = Messages.OUTPUT_MESSAGE_NOT_DEFINED;
135
				return new ImportValidationStatus(errorMessage, new Object[]
136
				{ _operations[i] });
137
			}
138
139
			// Validate Fault Messages
140
			Iterator faultsIt = _operations[i].getFaults().values().iterator();
141
			while (faultsIt.hasNext())
142
			{
143
				Object object = faultsIt.next();
144
				if (object instanceof Fault)
145
				{
146
					Fault fault = (Fault) object;
147
					Message faultMessage = fault.getMessage();
148
					if (!isDocLiteralMessage(faultMessage))
149
					{
150
						String errorMessage = Messages.NOT_DOC_LITERAL_MESSAGE;
151
						return new ImportValidationStatus(errorMessage,
152
								new Object[]
153
								{ faultMessage });
154
					}
155
					Message conflictedMessage = validateConflictedMessage(faultMessage);
156
					if (conflictedMessage != null)
157
					{
158
						String newLine = System.getProperty("line.separator");
159
						String errorMessage = Messages.CONFLICTED_MESSAGE
160
								+ newLine
161
								+ conflictedMessage.getQName().toString()
162
								+ newLine + faultMessage.getQName().toString();
163
						return new ImportValidationStatus(errorMessage,
164
								new Object[]
165
								{ conflictedMessage, faultMessage });
166
					}
167
				}
168
			}
169
		}
170
		return null;
171
	}
172
173
	private Message validateConflictedMessage(Message wsdlMessage)
174
	{
175
		String messageNS = wsdlMessage.getQName().getNamespaceURI();
176
		String messageName = wsdlMessage.getQName().getLocalPart();
177
		if (_map.get(messageName) == null)
178
		{
179
			_map.put(messageName, wsdlMessage);
180
			return null;
181
		}
182
		Message messageFromMap = (Message) _map.get(messageName);
183
		String nsFromMap = messageFromMap.getQName().getNamespaceURI();
184
		if (!nsFromMap.equals(messageNS))
185
			return messageFromMap;
186
		return null;
187
	}
188
189
	private boolean isDocLiteralMessage(Message wsdlMessage)
190
	{
191
		Map partsMap = wsdlMessage.getParts();
192
		if (partsMap == null || partsMap.size() != 1)
193
			return false;
194
		Part part_0 = (Part) partsMap.values().iterator().next();
195
		QName elementQName = part_0.getElementName();
196
		if (elementQName == null)
197
		{
198
			QName typeDef = part_0.getTypeName();
199
			if (typeDef == null)
200
				return false;
201
			boolean voidType = typeDef.getNamespaceURI().equals(
202
					XMLSCHEMA_2001_URI)
203
					&& typeDef.getLocalPart().equals("anyType");
204
			if (!voidType)
205
				return false;
206
		}
207
		return true;
208
	}
209
210
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/wsdl/OperationImportWizardPage.java (+263 lines)
Added 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
import java.util.Map;
18
19
import javax.wsdl.Definition;
20
import javax.wsdl.Message;
21
import javax.wsdl.Operation;
22
import javax.wsdl.PortType;
23
24
import org.eclipse.jface.dialogs.Dialog;
25
import org.eclipse.jface.viewers.CheckStateChangedEvent;
26
import org.eclipse.jface.viewers.CheckboxTreeViewer;
27
import org.eclipse.jface.viewers.ICheckStateListener;
28
import org.eclipse.jface.viewers.StructuredSelection;
29
import org.eclipse.jface.wizard.IWizardPage;
30
import org.eclipse.jface.wizard.WizardPage;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.layout.GridData;
33
import org.eclipse.swt.layout.GridLayout;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Label;
36
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.xsd.ImportValidationStatus;
37
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
38
39
public class OperationImportWizardPage extends WizardPage
40
{
41
	private CheckboxTreeViewer _viewer;
42
	private WsdlPortTypeContentProvider _contentProvider;
43
	private Definition _wsdlDefinition;
44
	private PortType[] _existingPortTypes = new PortType[0];
45
	private Operation[] _importedOperations;
46
47
	public OperationImportWizardPage()
48
	{
49
		super("ImportOperationWizardPage");
50
		setTitle(Messages.OPERATION_IMPORT_WIZARD_PAGE_TITLE);
51
		setDescription(Messages.OPERATION_IMPORT_WIZARD_PAGE_DESCRIPTION);
52
	}
53
54
	public OperationImportWizardPage(Definition wsdlDefinition,
55
			PortType[] existingPortTypes)
56
	{
57
		super("ImportOperationWizardPage");
58
		setTitle(Messages.OPERATION_IMPORT_WIZARD_PAGE_TITLE);
59
		setDescription(Messages.OPERATION_IMPORT_WIZARD_PAGE_DESCRIPTION);
60
		_wsdlDefinition = wsdlDefinition;
61
		if (existingPortTypes != null)
62
			_existingPortTypes = existingPortTypes;
63
	}
64
65
	public OperationImportWizardPage(Definition wsdlDefinition)
66
	{
67
		this(wsdlDefinition, null);
68
	}
69
70
	public void createControl(Composite parent)
71
	{
72
		initializeDialogUnits(parent);
73
		Composite container = new Composite(parent, SWT.NULL);
74
		container.setFont(parent.getFont());
75
		GridLayout layout = new GridLayout();
76
		container.setLayout(layout);
77
		layout.verticalSpacing = 9;
78
79
		Label descriptionLabel = new Label(container, SWT.WRAP);
80
		descriptionLabel
81
				.setText(Messages.OPERATION_IMPORT_WIZARD_PAGE_INFO_LABEL);
82
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
83
		gd.minimumHeight = 30;
84
		descriptionLabel.setLayoutData(gd);
85
86
		Label availableOperationsLabel = new Label(container, SWT.WRAP);
87
		availableOperationsLabel.setText(Messages.AVAILABLE_OPERATIONS_LABEL);
88
		gd = new GridData(SWT.FILL, SWT.FILL, true, false);
89
		gd.minimumHeight = 15;
90
		availableOperationsLabel.setLayoutData(gd);
91
92
		_viewer = new CheckboxTreeViewer(container, SWT.MULTI | SWT.BORDER);
93
		_contentProvider = new WsdlPortTypeContentProvider();
94
		_viewer.setContentProvider(_contentProvider);
95
		_viewer.setLabelProvider(new WsdlPortTypeLabelProvider(getShell()));
96
		_viewer.getControl().setLayoutData(
97
				new GridData(SWT.FILL, SWT.FILL, true, true));
98
		_viewer.addCheckStateListener(new ICheckStateListener()
99
		{
100
			public void checkStateChanged(CheckStateChangedEvent event)
101
			{
102
				handleCheckStateChanged(event);
103
			}
104
		});
105
		gd = new GridData(SWT.FILL, SWT.FILL, true, true);
106
		gd.heightHint = 200;
107
		gd.widthHint = 300;
108
		_viewer.getControl().setLayoutData(gd);
109
110
		initialize();
111
		// getShell().setSize(500, 100);
112
		setControl(container);
113
		Dialog.applyDialogFont(parent);
114
	}
115
116
	private void initialize()
117
	{
118
		_importedOperations = new Operation[0];
119
		if (_wsdlDefinition != null)
120
		{
121
			// Get the Consolidated list of port types
122
			// (Provided through constructor + Port types collect from given
123
			// wsdl file)
124
			Map portTypeMap = _wsdlDefinition.getPortTypes();
125
			PortType[] portTypes = (PortType[]) portTypeMap.values().toArray(
126
					new PortType[portTypeMap.size()]);
127
			List ports = getConsolidatedPortList(portTypes);
128
			_viewer.setInput(ports);
129
		}
130
		// _viewer.expandToLevel(2);
131
		// Checked the Port types provided by constructor
132
		doIntialCheckedElements();
133
		_viewer.setGrayedElements(_existingPortTypes);
134
		updateStatus(null);
135
	}
136
137
	public void setWSDLDefinition(Definition definition)
138
	{
139
		_wsdlDefinition = definition;
140
		initialize();
141
	}
142
143
	private List getConsolidatedPortList(PortType[] ports)
144
	{
145
		List portTypes = new LinkedList();
146
		for (int i = 0; i < _existingPortTypes.length; i++)
147
			portTypes.add(_existingPortTypes[i]);
148
		if (ports == null)
149
			return portTypes;
150
		for (int i = 0; i < ports.length; i++)
151
			portTypes.add(ports[i]);
152
		return portTypes;
153
	}
154
155
	protected void doIntialCheckedElements()
156
	{
157
		for (int i = 0; i < _existingPortTypes.length; i++)
158
			_viewer.setSubtreeChecked(_existingPortTypes[i], true);
159
	}
160
161
	private void handleCheckStateChanged(CheckStateChangedEvent event)
162
	{
163
		// We don't allow user to check uncheck WSDL Messages
164
		if (event.getElement() instanceof Message)
165
		{
166
			_viewer.setChecked(event.getElement(), !event.getChecked());
167
			return;
168
		}
169
170
		// We don't allow user to check uncheck any Port Type provided in
171
		// constructor
172
		PortType port = getPortTypeOfChekedElement(event.getElement());
173
		for (int i = 0; i < _existingPortTypes.length; i++)
174
		{
175
			if (_existingPortTypes[i].equals(port))
176
			{
177
				_viewer.setChecked(event.getElement(), !event.getChecked());
178
				return;
179
			}
180
		}
181
182
		_viewer.setSubtreeChecked(event.getElement(), event.getChecked());
183
		Operation[] checkedOperations = getCheckedOperations();
184
		OperationImportValidator validator = new OperationImportValidator(
185
				checkedOperations);
186
		ImportValidationStatus status = validator.validate();
187
		updateStatus(null);
188
		if (status != null)
189
		{
190
			Object[] causeOfError = status.getCauseOfError();
191
			for (int i = 0; i < causeOfError.length; i++)
192
				_viewer.reveal(causeOfError[i]);
193
			_viewer.setSelection(new StructuredSelection(causeOfError));
194
			updateStatus(status.getErrorMessage());
195
		}
196
		_importedOperations = getSelectedOperation();
197
	}
198
199
	private void updateStatus(String message)
200
	{
201
		setErrorMessage(message);
202
		setPageComplete(message == null);
203
	}
204
205
	private PortType getPortTypeOfChekedElement(Object checkedElement)
206
	{
207
		if (checkedElement instanceof PortType)
208
			return (PortType) checkedElement;
209
		Object parent = _contentProvider.getParent(checkedElement);
210
		while (!(parent instanceof PortType))
211
			parent = _contentProvider.getParent(parent);
212
		return (PortType) parent;
213
	}
214
215
	/**
216
	 * Returns all the checked wsdl operations from viewer.
217
	 */
218
	private Operation[] getCheckedOperations()
219
	{
220
		Object[] checkedElements = _viewer.getCheckedElements();
221
		List selectedOperationList = new LinkedList();
222
		for (int i = 0; i < checkedElements.length; i++)
223
		{
224
			if (checkedElements[i] instanceof Operation)
225
				selectedOperationList.add(checkedElements[i]);
226
		}
227
		return (Operation[]) selectedOperationList
228
				.toArray(new Operation[selectedOperationList.size()]);
229
	}
230
231
	public Operation[] getImportedOperations()
232
	{
233
		return _importedOperations;
234
	}
235
236
	private Operation[] getSelectedOperation()
237
	{
238
		Operation[] checkedOperations = getCheckedOperations();
239
		List selectedOperations = new LinkedList();
240
		for (int i = 0; i < checkedOperations.length; i++)
241
		{
242
			PortType port = getPortTypeOfChekedElement(checkedOperations[i]);
243
			boolean isImportOperation = true;
244
			for (int j = 0; j < _existingPortTypes.length; j++)
245
			{
246
				if (_existingPortTypes[j].equals(port))
247
				{
248
					isImportOperation = false;
249
					break;
250
				}
251
			}
252
			if (isImportOperation)
253
				selectedOperations.add(checkedOperations[i]);
254
		}
255
		return (Operation[]) selectedOperations
256
				.toArray(new Operation[selectedOperations.size()]);
257
	}
258
259
	public IWizardPage getNextPage()
260
	{
261
		return null;
262
	}
263
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/wsdl/WsdlPortTypeLabelProvider.java (+82 lines)
Added 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 javax.wsdl.Message;
16
import javax.wsdl.Operation;
17
import javax.wsdl.PortType;
18
19
import org.eclipse.jface.resource.ImageRegistry;
20
import org.eclipse.jface.viewers.ILabelProvider;
21
import org.eclipse.jface.viewers.LabelProvider;
22
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
25
26
public class WsdlPortTypeLabelProvider extends LabelProvider implements
27
		ILabelProvider
28
{
29
30
	private ImageRegistry imageRegistry;
31
	private final static String PORT_KEY = "Port";
32
	private final static String OPERATION_KEY = "Operation";
33
	private final static String MESSAGE_KEY = "Message";
34
35
	public WsdlPortTypeLabelProvider(Shell shell)
36
	{
37
		imageRegistry = new ImageRegistry(shell.getDisplay());
38
39
		Image portImage = EclipseUtils.loadImage(shell.getDisplay(),
40
				"icons/obj16/capability_obj.gif");
41
		imageRegistry.put(PORT_KEY, portImage);
42
43
		Image operationImage = EclipseUtils.loadImage(shell.getDisplay(),
44
				"icons/obj16/userOperation_obj.gif");
45
		imageRegistry.put(OPERATION_KEY, operationImage);
46
47
		Image messageImage = EclipseUtils.loadImage(shell.getDisplay(),
48
				"icons/obj16/sample.gif");
49
		imageRegistry.put(MESSAGE_KEY, messageImage);
50
	}
51
52
	public Image getImage(Object element)
53
	{
54
		if (element instanceof PortType)
55
			return imageRegistry.get(PORT_KEY);
56
		else if (element instanceof Operation)
57
			return imageRegistry.get(OPERATION_KEY);
58
		else if (element instanceof Message)
59
			return imageRegistry.get(MESSAGE_KEY);
60
		return null;
61
	}
62
63
	public String getText(Object element)
64
	{
65
		if (element instanceof PortType)
66
		{
67
			PortType port = (PortType) element;
68
			return port.getQName().toString();
69
		}
70
		else if (element instanceof Operation)
71
		{
72
			Operation operation = (Operation) element;
73
			return operation.getName();
74
		}
75
		else if (element instanceof Message)
76
		{
77
			Message message = (Message) element;
78
			return message.getQName().toString();
79
		}
80
		return element.toString();
81
	}
82
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/xsd/PropertyImportValidator.java (+62 lines)
Added 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.xsd;
14
15
import java.util.HashMap;
16
import java.util.Map;
17
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
19
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
21
22
public class PropertyImportValidator
23
{
24
	private Property[] _properties;
25
26
	public PropertyImportValidator(Property[] properties)
27
	{
28
		_properties = properties;
29
	}
30
31
	public ImportValidationStatus validate()
32
	{
33
		Map propertyNames = new HashMap();
34
		if (_properties == null)
35
			return null;
36
		for (int i = 0; i < _properties.length; i++)
37
		{
38
			String propertyName = _properties[i].getElement().getName();
39
40
			// Validate valid java identifier
41
			String errorMessage = CapUtils.validateJavaIdentifier(propertyName);
42
			if (errorMessage != null)
43
				return new ImportValidationStatus(errorMessage, new Object[]
44
				{ _properties[i] });
45
46
			// Validate duplicate property name
47
			if (!propertyNames.containsKey(propertyName))
48
				propertyNames.put(propertyName, _properties[i]);
49
			else
50
			{
51
				errorMessage = Messages.bind(Messages.DUPLICATE_PROPERTY,
52
						propertyName);
53
				Property causeOfError_1 = (Property) propertyNames
54
						.get(propertyName);
55
				Property causeOfError_2 = _properties[i];
56
				return new ImportValidationStatus(errorMessage, new Object[]
57
				{ causeOfError_1, causeOfError_2 });
58
			}
59
		}
60
		return null;
61
	}
62
}
(-)src/org/eclipse/tptp/wsdm/tooling/wizard/capability/internal/CapabilityModelImporterPage.java (+454 lines)
Added 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.wizard.capability.internal;
14
15
import javax.wsdl.Definition;
16
import javax.wsdl.Operation;
17
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IWorkspaceRoot;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.Path;
22
import org.eclipse.jface.dialogs.Dialog;
23
import org.eclipse.jface.dialogs.MessageDialog;
24
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.jface.window.Window;
26
import org.eclipse.jface.wizard.IWizardPage;
27
import org.eclipse.jface.wizard.WizardPage;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.events.ModifyEvent;
30
import org.eclipse.swt.events.ModifyListener;
31
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Button;
36
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Text;
38
import org.eclipse.tptp.wsdm.tooling.dialog.provisional.WSDLBrowseDialog;
39
import org.eclipse.tptp.wsdm.tooling.dialog.provisional.XSDBrowseDialog;
40
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.wsdl.OperationImportWizardPage;
41
import org.eclipse.tptp.wsdm.tooling.editor.capability.imports.xsd.PropertyImportWizardPage;
42
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
43
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
44
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
45
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
46
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
47
import org.eclipse.xsd.XSDSchema;
48
49
/**
50
 * Wizard page to import capability from XSD and WSDL files.
51
 */
52
53
public class CapabilityModelImporterPage extends WizardPage
54
{
55
	private ISelection _selection;
56
57
	private NewCapabilityWizard _wizard;
58
59
	private Button _emptyCapability;
60
61
	private Button _fromXSD;
62
63
	private Text _xsdFilePathText;
64
65
	private Button _browseXSD;
66
67
	private Button _fromWSDL;
68
69
	private Text _wsdlFilePathText;
70
71
	private Button _browseWSDL;
72
73
	private Object[] _checkedItems;
74
75
	private Operation[] _importedOperations = new Operation[0];
76
77
	private boolean _canFlipToNextPage = false;
78
79
	/**
80
	 * Creates new object of this class.
81
	 */
82
	protected CapabilityModelImporterPage(ISelection selection,
83
			NewCapabilityWizard wizard)
84
	{
85
		super("wizardPage");
86
		_selection = selection;
87
		_wizard = wizard;
88
		setTitle(Messages.SELECT_CAPABILITY_IMPORTER);
89
	}
90
91
	/**
92
	 * Creates wizard controls.
93
	 */
94
	public void createControl(Composite parent)
95
	{
96
		initializeDialogUnits(parent);
97
		Composite container = new Composite(parent, SWT.NULL);
98
		container.setFont(parent.getFont());
99
		container.setLayout(new GridLayout());
100
		container.setLayoutData(new GridData());
101
102
		_emptyCapability = new Button(container, SWT.RADIO);
103
		_emptyCapability.setText(Messages.CREATE_EMPTY_CAPABILITY);
104
		_emptyCapability.addSelectionListener(new SelectionAdapter()
105
		{
106
			public void widgetSelected(SelectionEvent e)
107
			{
108
				handleEmptyCapabilityButtonSelection();
109
			}
110
		});
111
112
		createFromXSDControl(container);
113
		createFromWSDLControl(container);
114
115
		intialize();
116
117
		setControl(container);
118
		Dialog.applyDialogFont(parent);
119
	}
120
121
	private void handleEmptyCapabilityButtonSelection()
122
	{
123
		_fromXSD.setSelection(false);
124
		_browseXSD.setEnabled(false);
125
		_xsdFilePathText.setEnabled(false);
126
		_fromWSDL.setSelection(false);
127
		_browseWSDL.setEnabled(false);
128
		_wsdlFilePathText.setEnabled(false);
129
		setMessage(Messages.CREATE_EMPTY_CAPABILITY);
130
		_wizard.getOperationImportWizardPage().setPageComplete(true);
131
		_wizard.getPropertyImportWizardPage().setPageComplete(true);
132
		dialogChanged();
133
	}
134
135
	private void createFromXSDControl(Composite parent)
136
	{
137
		Composite fromXSDComposite = new Composite(parent, SWT.NULL);
138
		GridLayout layout = new GridLayout(2, false);
139
		layout.marginWidth = 0;
140
		fromXSDComposite.setLayout(layout);
141
		GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
142
		fromXSDComposite.setLayoutData(gd);
143
144
		_fromXSD = new Button(fromXSDComposite, SWT.RADIO);
145
		_fromXSD
146
				.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.DEFINE_CAPABILITY_FROM_XSD);
147
		_fromXSD.addSelectionListener(new SelectionAdapter()
148
		{
149
			public void widgetSelected(SelectionEvent e)
150
			{
151
				handleFromXSDButtonSelection();
152
			}
153
		});
154
		gd = new GridData();
155
		gd.horizontalSpan = 2;
156
		_fromXSD.setLayoutData(gd);
157
158
		_xsdFilePathText = new Text(fromXSDComposite, SWT.BORDER);
159
		gd = new GridData(SWT.FILL, SWT.NONE, true, false);
160
		gd.horizontalIndent = 15;
161
		_xsdFilePathText.setLayoutData(gd);
162
		_xsdFilePathText.addModifyListener(new ModifyListener()
163
		{
164
			public void modifyText(ModifyEvent e)
165
			{
166
				dialogChanged();
167
			}
168
		});
169
170
		_browseXSD = createBrowseWorkspaceButton(fromXSDComposite);
171
		_browseXSD.addSelectionListener(new SelectionAdapter()
172
		{
173
			public void widgetSelected(SelectionEvent e)
174
			{
175
				handleXSDBrowse();
176
			}
177
		});
178
		_browseXSD.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
179
	}
180
181
	private void handleFromXSDButtonSelection()
182
	{
183
		_emptyCapability.setSelection(false);
184
		_browseXSD.setEnabled(true);
185
		_xsdFilePathText.setEnabled(true);
186
		_fromWSDL.setSelection(false);
187
		_browseWSDL.setEnabled(false);
188
		_wsdlFilePathText.setEnabled(false);
189
		setMessage(Messages.IMPORT_PROPERTIES_FROM_XSD);
190
		dialogChanged();
191
	}
192
193
	private void createFromWSDLControl(Composite parent)
194
	{
195
		Composite fromWSDLComposite = new Composite(parent, SWT.NULL);
196
		GridLayout layout = new GridLayout(2, false);
197
		layout.marginWidth = 0;
198
		fromWSDLComposite.setLayout(layout);
199
		GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
200
		fromWSDLComposite.setLayoutData(gd);
201
202
		_fromWSDL = new Button(fromWSDLComposite, SWT.RADIO);
203
		_fromWSDL
204
				.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.DEFINE_CAPABILITY_FROM_WSDL);
205
		_fromWSDL.addSelectionListener(new SelectionAdapter()
206
		{
207
			public void widgetSelected(SelectionEvent e)
208
			{
209
				handleFromWSDLButtonSelection();
210
			}
211
		});
212
		gd = new GridData();
213
		gd.horizontalSpan = 2;
214
		_fromWSDL.setLayoutData(gd);
215
216
		_wsdlFilePathText = new Text(fromWSDLComposite, SWT.BORDER);
217
		gd = new GridData(SWT.FILL, SWT.NONE, true, false);
218
		gd.horizontalIndent = 15;
219
		_wsdlFilePathText.setLayoutData(gd);
220
		_wsdlFilePathText.addModifyListener(new ModifyListener()
221
		{
222
			public void modifyText(ModifyEvent e)
223
			{
224
				dialogChanged();
225
			}
226
		});
227
228
		_browseWSDL = createBrowseWorkspaceButton(fromWSDLComposite);
229
		_browseWSDL.addSelectionListener(new SelectionAdapter()
230
		{
231
			public void widgetSelected(SelectionEvent e)
232
			{
233
				handleWSDLBrowse();
234
			}
235
		});
236
		_browseWSDL.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
237
	}
238
239
	private void handleFromWSDLButtonSelection()
240
	{
241
		_emptyCapability.setSelection(false);
242
		_fromXSD.setSelection(false);
243
		_browseXSD.setEnabled(false);
244
		_xsdFilePathText.setEnabled(false);
245
		_browseWSDL.setEnabled(true);
246
		_wsdlFilePathText.setEnabled(true);
247
		setMessage(Messages.IMPORT_OPERATIONS_FROM_WSDL);
248
		dialogChanged();
249
	}
250
251
	private void intialize()
252
	{
253
		_emptyCapability.setSelection(true);
254
		_browseXSD.setEnabled(false);
255
		_xsdFilePathText.setEnabled(false);
256
		_browseWSDL.setEnabled(false);
257
		_wsdlFilePathText.setEnabled(false);
258
		setMessage(Messages.CREATE_EMPTY_CAPABILITY);
259
	}
260
261
	private Button createBrowseWorkspaceButton(Composite container)
262
	{
263
		Button browseButton = new Button(container, SWT.PUSH);
264
		browseButton.setText(Messages.BROWSE_WORKSPACE);
265
		GridData gd = new GridData(GridData.END);
266
		gd.grabExcessHorizontalSpace = true;
267
		browseButton.setLayoutData(gd);
268
		return browseButton;
269
	}
270
271
	private void handleXSDBrowse()
272
	{
273
		XSDBrowseDialog dialog = new XSDBrowseDialog(getShell());
274
		if (dialog.open() == Window.OK)
275
		{
276
			IFile browsedFile = (IFile) dialog.getFirstResult();
277
			XSDSchema xsdSchema = XsdUtils.getSchema(browsedFile);
278
			_xsdFilePathText.setText(browsedFile.getFullPath().toString());
279
			// TODO Check for valid file
280
		}
281
	}
282
283
	private void handleWSDLBrowse()
284
	{
285
		WSDLBrowseDialog dialog = new WSDLBrowseDialog(getShell());
286
		if (dialog.open() == Window.OK)
287
		{
288
			IFile browsedFile = (IFile) dialog.getFirstResult();
289
			try
290
			{
291
				WsdlUtils.getCapabilityDefinition(browsedFile);
292
			}
293
			catch (Exception e)
294
			{
295
				MessageDialog
296
						.openError(
297
								getShell(),
298
								"Error",
299
								org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.IMPROPER_WSDL_FILE);
300
				return;
301
			}
302
			_wsdlFilePathText.setText(browsedFile.getFullPath().toString());
303
		}
304
	}
305
306
	/**
307
	 * Returns the imported XSD schemas specified.
308
	 */
309
	/*
310
	 * protected XSDSchema[] getSchemaToImport() {
311
	 * if(_emptyCapability.getSelection() || _fromWSDL.getSelection()) return
312
	 * new XSDSchema[0]; return new XSDSchema[0]; }
313
	 */
314
315
	/**
316
	 * Returns the imported Operations specified.
317
	 */
318
	/*
319
	 * protected Operation[] getOperationsToImport() {
320
	 * if(_emptyCapability.getSelection() || _fromXSD.getSelection()) return new
321
	 * Operation[0]; return _importedOperations; }
322
	 */
323
324
	private void dialogChanged()
325
	{
326
		if (_fromXSD.getSelection())
327
		{
328
			String xsdFilePath = getXSDFilePath();
329
			if (!isValidWorkspaceFile(xsdFilePath))
330
			{
331
				updateStatus(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.SPECIFY_EXISTING_XSD);
332
				return;
333
			}
334
335
		}
336
		if (_fromWSDL.getSelection())
337
		{
338
			String wsdlFilePath = getWSDLFilePath();
339
			if (!isValidWorkspaceFile(wsdlFilePath))
340
			{
341
				updateStatus(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages.SPECIFY_EXISTING_WSDL);
342
				return;
343
			}
344
		}
345
		updateStatus(null);
346
	}
347
348
	private void updateStatus(String message)
349
	{
350
		_canFlipToNextPage = true;
351
		if (message != null)
352
			_canFlipToNextPage = false;
353
		if (_emptyCapability.getSelection())
354
			_canFlipToNextPage = false;
355
		setErrorMessage(message);
356
		setPageComplete(message == null && _emptyCapability.getSelection());
357
	}
358
359
	private String getXSDFilePath()
360
	{
361
		return _xsdFilePathText.getText();
362
	}
363
364
	private String getWSDLFilePath()
365
	{
366
		return _wsdlFilePathText.getText();
367
	}
368
369
	private boolean isValidWorkspaceFile(String filePath)
370
	{
371
		try
372
		{
373
			IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
374
			IFile file = root.getFile(new Path(filePath));
375
			if (file == null || (!file.exists()))
376
				return false;
377
		}
378
		catch (Exception e)
379
		{
380
			return false;
381
		}
382
		return true;
383
	}
384
385
	public IWizardPage getNextPage()
386
	{
387
		if (_emptyCapability.getSelection())
388
		{
389
			return null;
390
		}
391
		if (_fromWSDL.getSelection())
392
		{
393
			try
394
			{
395
				_wizard.getPropertyImportWizardPage().setPageComplete(true);
396
				String wsdlFilePath = getWSDLFilePath();
397
				IFile wsdlFile = EclipseUtils.getIFile(wsdlFilePath);
398
				CapabilityDefinition capabilityDefinition = WsdlUtils
399
						.getCapabilityDefinition(wsdlFile);
400
				Definition wsdlDefinition = capabilityDefinition
401
						.getDefinition();
402
				OperationImportWizardPage page = _wizard
403
						.getOperationImportWizardPage();
404
				page.setWSDLDefinition(wsdlDefinition);
405
				setPageComplete(true);
406
				return page;
407
			}
408
			catch (Exception e)
409
			{
410
				e.printStackTrace();
411
			}
412
		}
413
		if (_fromXSD.getSelection())
414
		{
415
			try
416
			{
417
				_wizard.getOperationImportWizardPage().setPageComplete(true);
418
				String xsdFilePath = getXSDFilePath();
419
				IFile xsdFile = EclipseUtils.getIFile(xsdFilePath);
420
				XSDSchema importSchema = XsdUtils.getSchema(xsdFile);
421
				PropertyImportWizardPage page = _wizard
422
						.getPropertyImportWizardPage();
423
				page.setImportSchema(importSchema);
424
				setPageComplete(true);
425
				return page;
426
			}
427
			catch (Exception e)
428
			{
429
				e.printStackTrace();
430
			}
431
		}
432
		return super.getNextPage();
433
	}
434
435
	public boolean canFlipToNextPage()
436
	{
437
		return _canFlipToNextPage;
438
	}
439
440
	public boolean isEmptyCapabilityButtonSelected()
441
	{
442
		return _emptyCapability.getSelection();
443
	}
444
445
	public boolean isFromXSDButtonSelected()
446
	{
447
		return _fromXSD.getSelection();
448
	}
449
450
	public boolean isFromWSDLButtonSelected()
451
	{
452
		return _fromWSDL.getSelection();
453
	}
454
}
(-)src/org/eclipse/tptp/wsdm/tooling/nls/messages/capability/imports/internal/messages.properties (+37 lines)
Added 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
IMPORT_OPERATIONS = Import operations
13
IMPORTING_OPERATIONS = Importing operations
14
IMPORTING_OPERATION = Importing operation : {0}
15
OPERATION_IMPORT_WIZARD_PAGE_TITLE = Select operations to import
16
OPERATION_IMPORT_WIZARD_PAGE_DESCRIPTION = Select operations to import from WSDL file to defined this capability
17
OPERATION_IMPORT_WIZARD_PAGE_INFO_LABEL = Selected operations will be merged for the definition of this capability. Selected operation must not have same name to avoid conflict.
18
AVAILABLE_OPERATIONS_LABEL = Available WSDL file operations:
19
DUPLICATE_OPERATION = Duplicate operation : {0}
20
NOT_DOC_LITERAL_MESSAGE = Message is not of doc literal type
21
CONFLICTED_MESSAGE = Conflicted message :
22
INPUT_MESSAGE_NOT_DEFINED = Input message must be defined
23
OUTPUT_MESSAGE_NOT_DEFINED = Output message must be defined
24
IMPROPER_WSDL_FILE = Improper wsdl file
25
DEFINE_CAPABILITY_FROM_WSDL = Define capability from existing WSDL file:
26
SPECIFY_EXISTING_WSDL = Please specify existing WSDL file
27
28
IMPORT_PROPERTIES = Import properties
29
IMPORTING_PROPERTIES = Importing properties
30
IMPORTING_PROPERTY = Importing property : {0}
31
DUPLICATE_PROPERTY = Duplicate property : {0}
32
PROPERTY_IMPORT_WIZARD_PAGE_TITLE = Select properties to import
33
PROPERTY_IMPORT_WIZARD_PAGE_DESCRIPTION = Select properties to import from XSD file to defined this capability
34
AVAILABLE_PROPERTIES_LABEL = Available XSD file properties:
35
DEFINE_CAPABILITY_FROM_XSD = Define capability from existing XSD schema file:
36
SPECIFY_EXISTING_XSD = Please specify existing XSD schema file
37
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/property/internal/ImportPropertyCommand.java (+158 lines)
Added 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.command.property.internal;
14
15
import java.util.LinkedList;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.NullProgressMonitor;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
22
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
23
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
24
import org.eclipse.xsd.XSDComplexTypeDefinition;
25
import org.eclipse.xsd.XSDCompositor;
26
import org.eclipse.xsd.XSDElementDeclaration;
27
import org.eclipse.xsd.XSDFactory;
28
import org.eclipse.xsd.XSDModelGroup;
29
import org.eclipse.xsd.XSDParticle;
30
import org.eclipse.xsd.XSDSchema;
31
32
public class ImportPropertyCommand
33
{
34
	private XSDElementDeclaration _resourcePropertyElement;
35
	private Property[] _importedProperties;
36
	private List _newProperties = new LinkedList();
37
	private List _newSchemas = new LinkedList();
38
	private IProgressMonitor _monitor;
39
40
	public ImportPropertyCommand(XSDElementDeclaration resourcePropertyElement,
41
			Property[] importedProperties, IProgressMonitor monitor)
42
	{
43
		_resourcePropertyElement = resourcePropertyElement;
44
		_importedProperties = importedProperties;
45
		_monitor = monitor;
46
		if (monitor == null)
47
			_monitor = new NullProgressMonitor();
48
	}
49
50
	public ImportPropertyCommand(XSDElementDeclaration resourcePropertyElement,
51
			Property[] importedProperties)
52
	{
53
		this(resourcePropertyElement, importedProperties, null);
54
	}
55
56
	public void execute()
57
	{
58
		_monitor.beginTask(Messages.IMPORTING_PROPERTIES,
59
				_importedProperties.length);
60
		for (int i = 0; i < _importedProperties.length; i++)
61
		{
62
			String taskName = Messages.bind(Messages.IMPORTING_PROPERTY,
63
					_importedProperties[i].getElement().getName());
64
			_monitor.setTaskName(taskName);
65
			Property newProperty = createNewProperty(_importedProperties[i]);
66
			_newProperties.add(newProperty);
67
			if (!_newSchemas.contains(newProperty.getElement().getSchema()))
68
				_newSchemas.add(newProperty.getElement().getSchema());
69
			_monitor.worked(i + 1);
70
		}
71
	}
72
73
	private Property createNewProperty(Property importedProperty)
74
	{
75
		// Get the location for Imported XSD Schema in local drive format
76
		XSDSchema importSchema = importedProperty.getElement().getSchema();
77
		// String schemaLocation =
78
		// XsdUtils.getLocalSystemSchemaLocation(importSchema);
79
80
		// Get the location for capability file
81
		// String capFileLocation = null;
82
		// try {
83
		// capFileLocation =
84
		// WsdlUtils.getLocalSystemWSDLLocation(_capabilityDefinition);
85
		// } catch (CoreException e) {
86
		// e.printStackTrace();
87
		// }
88
89
		// Create xsd:import element
90
		// String importSchemaLocation = EclipseUtils.getRelativePath(
91
		// capFileLocation, schemaLocation, '/');
92
		// XsdUtils.createImportStatement(_resourcePropertyElement.getSchema(),
93
		// importSchema.getTargetNamespace(), importSchemaLocation);
94
95
		XsdUtils.createImportStatement(_resourcePropertyElement.getSchema(),
96
				importSchema.getTargetNamespace(), importSchema.eResource()
97
						.getURI().toString());
98
99
		// Prepare resource property element
100
		XSDModelGroup modelGroup = getXSDModelGroup();
101
102
		// Add element to resource properties
103
		XSDElementDeclaration propertyRef = XSDFactory.eINSTANCE
104
				.createXSDElementDeclaration();
105
		propertyRef
106
				.setResolvedElementDeclaration(importedProperty.getElement());
107
		XSDParticle simpleElementParticle = XSDFactory.eINSTANCE
108
				.createXSDParticle();
109
		simpleElementParticle.setContent(propertyRef);
110
		modelGroup.getContents().add(simpleElementParticle);
111
112
		// Create Capability property representation
113
		Property newProperty = CapabilitiesFactory.INSTANCE.createProperty();
114
		newProperty.setElement(importedProperty.getElement());
115
		return newProperty;
116
	}
117
118
	private XSDModelGroup getXSDModelGroup()
119
	{
120
		XSDModelGroup modelGroup = null;
121
		if (_resourcePropertyElement.getAnonymousTypeDefinition() == null)
122
		{
123
			// Create New XSD Model Group
124
			modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
125
			modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
126
127
			XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
128
			xsdParticle.setContent(modelGroup);
129
130
			XSDComplexTypeDefinition complexTypeDefiniton = XSDFactory.eINSTANCE
131
					.createXSDComplexTypeDefinition();
132
			complexTypeDefiniton.setContent(xsdParticle);
133
			_resourcePropertyElement
134
					.setAnonymousTypeDefinition(complexTypeDefiniton);
135
		}
136
		else
137
		{
138
			// Get the XSD Model Group
139
			XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) _resourcePropertyElement
140
					.getAnonymousTypeDefinition();
141
			modelGroup = XsdUtils.getXSDModelGroup(typeDef);
142
		}
143
		return modelGroup;
144
	}
145
146
	public Property[] getNewProperties()
147
	{
148
		return (Property[]) _newProperties.toArray(new Property[_newProperties
149
				.size()]);
150
	}
151
152
	public XSDSchema[] getNewSchemas()
153
	{
154
		return (XSDSchema[]) _newSchemas.toArray(new XSDSchema[_newSchemas
155
				.size()]);
156
	}
157
158
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/wsdl/WsdlPortTypeContentProvider.java (+113 lines)
Added 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.HashMap;
16
import java.util.Iterator;
17
import java.util.LinkedList;
18
import java.util.List;
19
import java.util.Map;
20
21
import javax.wsdl.Fault;
22
import javax.wsdl.Operation;
23
import javax.wsdl.PortType;
24
25
import org.eclipse.jface.viewers.ITreeContentProvider;
26
import org.eclipse.jface.viewers.Viewer;
27
28
public class WsdlPortTypeContentProvider implements ITreeContentProvider
29
{
30
31
	private final Map _parentMap;
32
33
	public WsdlPortTypeContentProvider()
34
	{
35
		_parentMap = new HashMap();
36
	}
37
38
	public Object[] getChildren(Object parentElement)
39
	{
40
		if (parentElement instanceof List)
41
		{
42
			List l = (List) parentElement;
43
			return l.toArray();
44
		}
45
		else if (parentElement instanceof PortType)
46
		{
47
			PortType port = (PortType) parentElement;
48
			Object[] operations = rememberChildren(parentElement, port
49
					.getOperations());
50
			return operations;
51
		}
52
		else if (parentElement instanceof Operation)
53
		{
54
			Operation operation = (Operation) parentElement;
55
			List messagesList = new LinkedList();
56
			if (operation.getInput() != null)
57
				messagesList.add(operation.getInput().getMessage());
58
			if (operation.getOutput() != null)
59
				messagesList.add(operation.getOutput().getMessage());
60
			Map faultsMap = operation.getFaults();
61
			Iterator it = faultsMap.values().iterator();
62
			while (it.hasNext())
63
			{
64
				Object object = it.next();
65
				if (object instanceof Fault)
66
				{
67
					Fault fault = (Fault) object;
68
					messagesList.add(fault.getMessage());
69
				}
70
			}
71
			Object[] messages = rememberChildren(parentElement, messagesList);
72
			return messages;
73
		}
74
		return new Object[0];
75
	}
76
77
	public Object getParent(Object element)
78
	{
79
		Object retVal = _parentMap.get(element);
80
		return retVal;
81
	}
82
83
	public boolean hasChildren(Object element)
84
	{
85
		return (getChildren(element).length > 0);
86
	}
87
88
	public Object[] getElements(Object inputElement)
89
	{
90
		return getChildren(inputElement);
91
	}
92
93
	public void dispose()
94
	{
95
	}
96
97
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
98
	{
99
	}
100
101
	private Object[] rememberChildren(Object parent, List childrens)
102
	{
103
		Object[] retVal = new Object[childrens.size()];
104
		for (int i = 0; i < retVal.length; i++)
105
		{
106
			Object child = childrens.get(i);
107
			_parentMap.put(child, parent);
108
			retVal[i] = child;
109
		}
110
		return retVal;
111
	}
112
113
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/xsd/PropertyNamespace.java (+47 lines)
Added 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.xsd;
14
15
import java.util.LinkedList;
16
import java.util.List;
17
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
19
20
public class PropertyNamespace
21
{
22
	private String _namespace;
23
	private List _properties;
24
25
	public PropertyNamespace(String namespace)
26
	{
27
		_namespace = namespace;
28
		_properties = new LinkedList();
29
	}
30
31
	public void addProperty(Property property)
32
	{
33
		if (property != null)
34
			_properties.add(property);
35
	}
36
37
	public Property[] getProperties()
38
	{
39
		return (Property[]) _properties
40
				.toArray(new Property[_properties.size()]);
41
	}
42
43
	public String getNamespace()
44
	{
45
		return _namespace;
46
	}
47
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/xsd/PropertyImportWizard.java (+134 lines)
Added 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.xsd;
14
15
import java.lang.reflect.InvocationTargetException;
16
import java.util.Arrays;
17
import java.util.HashMap;
18
import java.util.Iterator;
19
import java.util.LinkedList;
20
import java.util.List;
21
import java.util.Map;
22
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.jface.operation.IRunnableWithProgress;
25
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.jface.wizard.Wizard;
27
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal.ImportPropertyCommand;
28
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
29
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
30
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
31
import org.eclipse.ui.INewWizard;
32
import org.eclipse.ui.IWorkbench;
33
import org.eclipse.xsd.XSDElementDeclaration;
34
import org.eclipse.xsd.XSDSchema;
35
36
public class PropertyImportWizard extends Wizard implements INewWizard
37
{
38
39
	private CapabilityDomain _capabilityDomain;
40
	private XSDSchema _importSchema;
41
	private PropertyNamespace[] _existingPropertyNs = new PropertyNamespace[0];
42
	private PropertyImportWizardPage _importPage;
43
44
	public PropertyImportWizard(CapabilityDomain capabilityDomain,
45
			XSDSchema importSchema)
46
	{
47
		super();
48
		setWindowTitle(Messages.IMPORT_PROPERTIES);
49
		setNeedsProgressMonitor(true);
50
		_capabilityDomain = capabilityDomain;
51
		_importSchema = importSchema;
52
		_existingPropertyNs = createPropertiesNamespacesFromCapability();
53
	}
54
55
	public void addPages()
56
	{
57
		_importPage = new PropertyImportWizardPage(_importSchema,
58
				_existingPropertyNs);
59
		addPage(_importPage);
60
	}
61
62
	public boolean performFinish()
63
	{
64
		IRunnableWithProgress runnable = new IRunnableWithProgress()
65
		{
66
			public void run(IProgressMonitor monitor)
67
					throws InvocationTargetException, InterruptedException
68
			{
69
				performFinish(monitor);
70
			}
71
		};
72
		try
73
		{
74
			getContainer().run(true, false, runnable);
75
			return true;
76
		}
77
		catch (Exception e)
78
		{
79
			e.printStackTrace();
80
		}
81
		return false;
82
	}
83
84
	private void performFinish(IProgressMonitor monitor)
85
	{
86
		Property[] importedProperties = _importPage.getImportedProperties();
87
		ImportPropertyCommand command = new ImportPropertyCommand(
88
				_capabilityDomain.getResourcePropertyElement(),
89
				importedProperties, monitor);
90
		command.execute();
91
		Property[] newProperties = command.getNewProperties();
92
		_capabilityDomain.getCapability().getProperties().addAll(
93
				Arrays.asList(newProperties));
94
		XSDSchema[] newSchemas = command.getNewSchemas();
95
		for (int i = 0; i < newSchemas.length; i++)
96
			_capabilityDomain.addPropertySchema(newSchemas[i]);
97
	}
98
99
	public void init(IWorkbench workbench, IStructuredSelection selection)
100
	{
101
	}
102
103
	private PropertyNamespace[] createPropertiesNamespacesFromCapability()
104
	{
105
		Map propNamespacesMap = new HashMap();
106
		List properties = _capabilityDomain.getCapability().getProperties();
107
		for (int i = 0; i < properties.size(); i++)
108
		{
109
			Property property = (Property) properties.get(i);
110
			XSDElementDeclaration propertyElement = property.getElement();
111
			PropertyNamespace propertyNamespace = (PropertyNamespace) propNamespacesMap
112
					.get(propertyElement.getTargetNamespace());
113
			if (propertyNamespace == null)
114
			{
115
				propertyNamespace = new PropertyNamespace(propertyElement
116
						.getTargetNamespace());
117
				propNamespacesMap.put(propertyElement.getTargetNamespace(),
118
						propertyNamespace);
119
			}
120
			propertyNamespace.addProperty(property);
121
		}
122
123
		List propNamespacesList = new LinkedList();
124
		Iterator keyIt = propNamespacesMap.keySet().iterator();
125
		while (keyIt.hasNext())
126
		{
127
			Object key = keyIt.next();
128
			propNamespacesList.add(propNamespacesMap.get(key));
129
		}
130
131
		return (PropertyNamespace[]) propNamespacesList
132
				.toArray(new PropertyNamespace[propNamespacesList.size()]);
133
	}
134
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/wsdl/OperationImportWizard.java (+101 lines)
Added 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.lang.reflect.InvocationTargetException;
16
import java.util.Arrays;
17
import java.util.Map;
18
19
import javax.wsdl.Definition;
20
import javax.wsdl.Operation;
21
import javax.wsdl.PortType;
22
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.jface.operation.IRunnableWithProgress;
25
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.jface.wizard.Wizard;
27
import org.eclipse.tptp.wsdm.tooling.editor.capability.command.operation.internal.ImportOperationCommand;
28
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
29
import org.eclipse.tptp.wsdm.tooling.editor.internal.CapabilityDefinition;
30
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.Messages;
31
import org.eclipse.ui.INewWizard;
32
import org.eclipse.ui.IWorkbench;
33
34
public class OperationImportWizard extends Wizard implements INewWizard
35
{
36
37
	private CapabilityDomain _capabilityDomain;
38
	private Definition _wsdlDefinition;
39
	private PortType[] _existingPortTypes = new PortType[0];
40
	private OperationImportWizardPage _importPage;
41
42
	public OperationImportWizard(CapabilityDomain capabilityDomain,
43
			Definition definition)
44
	{
45
		super();
46
		setWindowTitle(Messages.IMPORT_OPERATIONS);
47
		setNeedsProgressMonitor(true);
48
		_capabilityDomain = capabilityDomain;
49
		_wsdlDefinition = definition;
50
		Map portsMap = capabilityDomain.getCapability().getWsdlDefinition()
51
				.getDefinition().getPortTypes();
52
		_existingPortTypes = (PortType[]) portsMap.values().toArray(
53
				new PortType[portsMap.size()]);
54
	}
55
56
	public void addPages()
57
	{
58
		_importPage = new OperationImportWizardPage(_wsdlDefinition,
59
				_existingPortTypes);
60
		addPage(_importPage);
61
	}
62
63
	public boolean performFinish()
64
	{
65
		IRunnableWithProgress runnable = new IRunnableWithProgress()
66
		{
67
			public void run(IProgressMonitor monitor)
68
					throws InvocationTargetException, InterruptedException
69
			{
70
				performFinish(monitor);
71
			}
72
		};
73
		try
74
		{
75
			getContainer().run(true, false, runnable);
76
			return true;
77
		}
78
		catch (Exception e)
79
		{
80
			e.printStackTrace();
81
		}
82
		return false;
83
	}
84
85
	private void performFinish(IProgressMonitor monitor)
86
	{
87
		Operation[] importOperations = _importPage.getImportedOperations();
88
		CapabilityDefinition capabilityDefinition = (CapabilityDefinition) _capabilityDomain
89
				.getCapability().getWsdlDefinition();
90
		ImportOperationCommand command = new ImportOperationCommand(
91
				capabilityDefinition, importOperations, monitor);
92
		command.execute();
93
		Operation[] newOperations = command.getNewOperations();
94
		_capabilityDomain.getCapability().getOperations().addAll(
95
				Arrays.asList(newOperations));
96
	}
97
98
	public void init(IWorkbench workbench, IStructuredSelection selection)
99
	{
100
	}
101
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/ui/internal/namegenerator/NewIFileNameGenerator.java (+93 lines)
Added 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.ui.internal.namegenerator;
14
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFolder;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.CoreException;
20
21
public class NewIFileNameGenerator implements INewNameGenerator
22
{
23
	private IResource _resource;
24
	private String _namePattern;
25
26
	public NewIFileNameGenerator(IResource resource, String namePattern)
27
	{
28
		_resource = resource;
29
		if (namePattern == null || namePattern.trim().equals(""))
30
			namePattern = "NewFile.tmp";
31
		if (namePattern.indexOf('.') == -1)
32
		{
33
			namePattern = "NewFile.tmp";
34
		}
35
		_namePattern = namePattern;
36
	}
37
38
	public String getNewName()
39
	{
40
		IResource[] members = null;
41
		if (_resource instanceof IProject)
42
		{
43
			IProject project = (IProject) _resource;
44
			try
45
			{
46
				members = project.members();
47
			}
48
			catch (CoreException e)
49
			{
50
				return _namePattern;
51
			}
52
		}
53
		else if (_resource instanceof IFolder)
54
		{
55
			IFolder folder = (IFolder) _resource;
56
			try
57
			{
58
				members = folder.members();
59
			}
60
			catch (CoreException e)
61
			{
62
				return _namePattern;
63
			}
64
		}
65
66
		int count = 0;
67
		while (isFileExists(members, _namePattern))
68
		{
69
			String fileNameWithoutExtn = _namePattern.substring(0, _namePattern
70
					.lastIndexOf('.'));
71
			String fileExtn = _namePattern.substring(_namePattern
72
					.lastIndexOf('.') + 1);
73
			_namePattern = fileNameWithoutExtn + count + "." + fileExtn;
74
			count++;
75
		}
76
		return _namePattern;
77
	}
78
79
	private boolean isFileExists(IResource[] resources, String fileName)
80
	{
81
		for (int i = 0; i < resources.length; i++)
82
		{
83
			if (resources[i] instanceof IFile)
84
			{
85
				IFile file = (IFile) resources[i];
86
				if (file.getName().equals(fileName))
87
					return true;
88
			}
89
		}
90
		return false;
91
	}
92
93
}
(-)src/org/eclipse/tptp/wsdm/tooling/nls/messages/capability/imports/internal/Messages.java (+52 lines)
Added 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.nls.messages.capability.imports.internal;
14
15
import org.eclipse.osgi.util.NLS;
16
17
public class Messages extends NLS
18
{
19
	private static final String BUNDLE_NAME = "org.eclipse.tptp.wsdm.tooling.nls.messages.capability.imports.internal.messages"; //$NON-NLS-1$
20
21
	public static String IMPORT_OPERATIONS;
22
	public static String IMPORTING_OPERATIONS;
23
	public static String IMPORTING_OPERATION;
24
	public static String OPERATION_IMPORT_WIZARD_PAGE_TITLE;
25
	public static String OPERATION_IMPORT_WIZARD_PAGE_DESCRIPTION;
26
	public static String OPERATION_IMPORT_WIZARD_PAGE_INFO_LABEL;
27
	public static String AVAILABLE_OPERATIONS_LABEL;
28
	public static String DUPLICATE_OPERATION;
29
	public static String NOT_DOC_LITERAL_MESSAGE;
30
	public static String CONFLICTED_MESSAGE;
31
	public static String INPUT_MESSAGE_NOT_DEFINED;
32
	public static String OUTPUT_MESSAGE_NOT_DEFINED;
33
	public static String IMPROPER_WSDL_FILE;
34
	public static String DEFINE_CAPABILITY_FROM_WSDL;
35
	public static String SPECIFY_EXISTING_WSDL;
36
37
	public static String IMPORT_PROPERTIES;
38
	public static String IMPORTING_PROPERTIES;
39
	public static String IMPORTING_PROPERTY;
40
	public static String DUPLICATE_PROPERTY;
41
	public static String PROPERTY_IMPORT_WIZARD_PAGE_TITLE;
42
	public static String PROPERTY_IMPORT_WIZARD_PAGE_DESCRIPTION;
43
	public static String AVAILABLE_PROPERTIES_LABEL;
44
	public static String DEFINE_CAPABILITY_FROM_XSD;
45
	public static String SPECIFY_EXISTING_XSD;
46
47
	static
48
	{
49
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
50
	}
51
52
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/ui/internal/namegenerator/NewWSDLMessageNameGenerator.java (+48 lines)
Added 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.ui.internal.namegenerator;
14
15
import javax.wsdl.Definition;
16
17
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
18
19
public class NewWSDLMessageNameGenerator implements INewNameGenerator
20
{
21
	private Definition _definition;
22
	private String _namePattern;
23
24
	public NewWSDLMessageNameGenerator(Definition definition, String namePattern)
25
	{
26
		_definition = definition;
27
		if (namePattern == null || namePattern.trim().equals(""))
28
			namePattern = "NewMessage";
29
		_namePattern = namePattern;
30
	}
31
32
	public NewWSDLMessageNameGenerator(Definition definition)
33
	{
34
		this(definition, null);
35
	}
36
37
	public String getNewName()
38
	{
39
		int count = 0;
40
		while (WsdlUtils.getWSDLMessage(_definition, _namePattern) != null)
41
		{
42
			_namePattern = _namePattern + count;
43
			count++;
44
		}
45
		return _namePattern;
46
	}
47
48
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/CapabilityStorage.java (+94 lines)
Added 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.internal;
14
15
import java.io.InputStream;
16
17
import org.eclipse.core.resources.IStorage;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.PlatformObject;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
23
24
/**
25
 * This class has been designed to use for opening any existing capability from
26
 * within MRT file.<br>
27
 * This class implements the IStorage interface which is used to represent a
28
 * storage object as a stream of bytes.<br>
29
 */
30
31
public class CapabilityStorage extends PlatformObject implements
32
		ICapabilityStorage
33
{
34
35
	private Capability _capability;
36
37
	public CapabilityStorage(Capability capability)
38
	{
39
		_capability = capability;
40
	}
41
42
	public InputStream getContents() throws CoreException
43
	{
44
		/*
45
		 * Definition definition =
46
		 * _capability.getWsdlDefinition().getDefinition(); String str =
47
		 * CapUtils.toString(definition.getDocumentationElement().getOwnerDocument());
48
		 * StringBufferInputStream stream = new StringBufferInputStream(str);
49
		 * return stream;
50
		 */
51
52
		// We use the getFullPath() method to load the definition in capability
53
		// editor
54
		return null;
55
	}
56
57
	public IPath getFullPath()
58
	{
59
		String path = null;
60
		if (_capability.getWsdlDefinition().getWSDLFileProtocalURI() != null)
61
			path = _capability.getWsdlDefinition().getWSDLFileProtocalURI()
62
					.toString();
63
		else if (_capability.getWsdlDefinition().getWSDLResourceProtocolURI() != null)
64
			path = _capability.getWsdlDefinition().getWSDLResourceProtocolURI()
65
					.toString();
66
		return new Path(path);
67
	}
68
69
	public String getName()
70
	{
71
		return _capability.getName();
72
	}
73
74
	public boolean isReadOnly()
75
	{
76
		if (getFullPath().toString().startsWith("platform:/plugin"))
77
			return true;
78
		return false;
79
	}
80
81
	public boolean exists()
82
	{
83
		// TODO Find out more efficient way to do this
84
		return _capability.getWsdlDefinition().getDefinition() != null;
85
	}
86
87
}
88
89
interface ICapabilityStorage extends IStorage
90
{
91
92
	boolean exists();
93
94
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/imports/xsd/PropertySchemaLabelProvider.java (+93 lines)
Added 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.xsd;
14
15
import org.eclipse.jface.resource.ImageRegistry;
16
import org.eclipse.jface.viewers.ILabelProvider;
17
import org.eclipse.jface.viewers.LabelProvider;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
21
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
22
import org.eclipse.xsd.XSDElementDeclaration;
23
import org.eclipse.xsd.XSDSchema;
24
25
public class PropertySchemaLabelProvider extends LabelProvider implements
26
		ILabelProvider
27
{
28
	private ImageRegistry imageRegistry;
29
	private final static String PROPERTY_NAMESPACE_KEY = "PropertyNamespace";
30
	private final static String PROPERTY_KEY = "Property";
31
32
	public PropertySchemaLabelProvider(Shell shell)
33
	{
34
		imageRegistry = new ImageRegistry(shell.getDisplay());
35
36
		Image propNamespaceImage = EclipseUtils.loadImage(shell.getDisplay(),
37
				"icons/obj16/capability_obj.gif");
38
		imageRegistry.put(PROPERTY_NAMESPACE_KEY, propNamespaceImage);
39
40
		Image propertyImage = EclipseUtils.loadImage(shell.getDisplay(),
41
				"icons/obj16/property_obj.gif");
42
		imageRegistry.put(PROPERTY_KEY, propertyImage);
43
	}
44
45
	public Image getImage(Object element)
46
	{
47
		if (element instanceof PropertyNamespace)
48
			return imageRegistry.get(PROPERTY_NAMESPACE_KEY);
49
		else if (element instanceof Property)
50
			return imageRegistry.get(PROPERTY_KEY);
51
		return null;
52
	}
53
54
	public String getText(Object element)
55
	{
56
		if (element instanceof PropertyNamespace)
57
		{
58
			/*
59
			 * XSDSchema schema = (XSDSchema) element; String schemaLocation =
60
			 * getSchemaLocation(schema); String namespace =
61
			 * schema.getTargetNamespace(); return namespace+" (
62
			 * "+schemaLocation+" )";
63
			 */
64
			PropertyNamespace propNamespace = (PropertyNamespace) element;
65
			return propNamespace.getNamespace();
66
		}
67
		else if (element instanceof Property)
68
		{
69
			Property property = (Property) element;
70
			XSDElementDeclaration propertyElement = property.getElement();
71
			return propertyElement.getName();
72
		}
73
		return element.toString();
74
	}
75
76
	private String getSchemaLocation(XSDSchema schema)
77
	{
78
		String location = schema.eResource().getURI().toString();
79
		if (location.startsWith("platform:/resource"))
80
		{
81
			int index = location.indexOf("platform:/resource")
82
					+ "platform:/resource".length();
83
			location = location.substring(index);
84
		}
85
		else if (location.startsWith("platform:/plugin"))
86
		{
87
			int index = location.indexOf("platform:/plugin")
88
					+ "platform:/plugin".length();
89
			location = location.substring(index);
90
		}
91
		return location;
92
	}
93
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/ui/internal/namegenerator/NewXSDElementNameGenerator.java (+47 lines)
Added 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.ui.internal.namegenerator;
14
15
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
16
import org.eclipse.xsd.XSDSchema;
17
18
public class NewXSDElementNameGenerator implements INewNameGenerator
19
{
20
	private XSDSchema _schema;
21
	private String _namePattern;
22
23
	public NewXSDElementNameGenerator(XSDSchema schema, String namePattern)
24
	{
25
		_schema = schema;
26
		if (namePattern == null || namePattern.trim().equals(""))
27
			namePattern = "NewElement";
28
		_namePattern = namePattern;
29
	}
30
31
	public NewXSDElementNameGenerator(XSDSchema schema)
32
	{
33
		this(schema, null);
34
	}
35
36
	public String getNewName()
37
	{
38
		int count = 0;
39
		while (XsdUtils.getXSDElementDeclarationOfName(_schema, _namePattern) != null)
40
		{
41
			_namePattern = _namePattern + count;
42
			count++;
43
		}
44
		return _namePattern;
45
	}
46
47
}

Return to bug 165544