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 161932 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/operation/internal/RemoveExceptionCommand.java (-25 / +25 lines)
Lines 45-53 Link Here
45
    public RemoveExceptionCommand(CapabilityDomain capabilityDomain,
45
    public RemoveExceptionCommand(CapabilityDomain capabilityDomain,
46
	    Operation operation, Fault fault)
46
	    Operation operation, Fault fault)
47
    {
47
    {
48
	_capabilityDomain = capabilityDomain;
48
		_capabilityDomain = capabilityDomain;
49
	_operation = operation;
49
		_operation = operation;
50
	_fault = fault;
50
		_fault = fault;
51
    }
51
    }
52
52
53
    /**
53
    /**
Lines 55-82 Link Here
55
     */
55
     */
56
    public void execute()
56
    public void execute()
57
    {
57
    {
58
	Definition definition = _capabilityDomain.getDefinition();
58
		Definition definition = _capabilityDomain.getCapability().getDefinition();
59
	Message faultMessage = _fault.getEMessage();
59
		Message faultMessage = _fault.getEMessage();
60
	// If the fault message falls in the same capability definition
60
		// If the fault message falls in the same capability definition
61
	// Then remove the fault message and xsd decalaration element for that
61
		// Then remove the fault message and xsd decalaration element for that
62
	if(faultMessage.getEnclosingDefinition().equals(definition))
62
		if(faultMessage.getEnclosingDefinition().equals(definition))
63
	{
63
		{
64
	    List parts = faultMessage.getEParts();
64
		    List parts = faultMessage.getEParts();
65
	    if(parts!=null && parts.size()!=0)
65
		    if(parts!=null && parts.size()!=0)
66
	    {
66
		    {
67
		Part part = (Part) parts.get(0);
67
			Part part = (Part) parts.get(0);
68
		XSDElementDeclaration faultElement = part.getElementDeclaration();
68
			XSDElementDeclaration faultElement = part.getElementDeclaration();
69
		// If faultElement defined in the same wsdl file
69
			// If faultElement defined in the same wsdl file
70
		// Then remove the faultElement
70
			// Then remove the faultElement
71
		XSDSchema faultSchema = WsdlUtils.getSchema(definition, faultElement.getTargetNamespace());
71
			XSDSchema faultSchema = WsdlUtils.getSchema(definition, faultElement.getTargetNamespace());
72
		if(faultSchema!=null)
72
			if(faultSchema!=null)
73
		    faultSchema.getContents().remove(faultElement);
73
			    faultSchema.getContents().remove(faultElement);
74
		 faultMessage.getEParts().remove(part);
74
			 faultMessage.getEParts().remove(part);
75
	    }	   
75
		    }	   
76
	    _fault.setEMessage(null);
76
		    _fault.setEMessage(null);
77
	    definition.getEMessages().remove(faultMessage);
77
		    definition.getEMessages().remove(faultMessage);
78
	}
78
		}
79
	_operation.getEFaults().remove(_fault);	
79
		_operation.getEFaults().remove(_fault);	
80
    }
80
    }
81
81
82
}
82
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/operation/internal/AddOperationCommand.java (-50 / +49 lines)
Lines 35-42 Link Here
35
public class AddOperationCommand
35
public class AddOperationCommand
36
{
36
{
37
37
38
    private Definition _definition;
39
40
    private Operation _newOperation;
38
    private Operation _newOperation;
41
39
42
    private Capability _capability;
40
    private Capability _capability;
Lines 47-55 Link Here
47
    public AddOperationCommand(CapabilityDomain capabilityDomain,
45
    public AddOperationCommand(CapabilityDomain capabilityDomain,
48
	    Operation newOperation)
46
	    Operation newOperation)
49
    {
47
    {
50
	_definition = capabilityDomain.getDefinition();
48
	    _capability = capabilityDomain.getCapability();
51
	_capability = capabilityDomain.getCapability();
49
	    _newOperation = newOperation;
52
	_newOperation = newOperation;
53
    }
50
    }
54
51
55
    /**
52
    /**
Lines 59-127 Link Here
59
     */
56
     */
60
    public void execute()
57
    public void execute()
61
    {
58
    {
62
59
	    Definition _definition = _capability.getDefinition();
63
	// Remember Old Refs
60
		// Remember Old Refs
64
	List faultMessages = new ArrayList();
61
		List faultMessages = new ArrayList();
65
	Message inputMessage = _newOperation.getEInput().getEMessage();
62
		Message inputMessage = _newOperation.getEInput().getEMessage();
66
	Message outputMessage = _newOperation.getEOutput().getEMessage();
63
		Message outputMessage = _newOperation.getEOutput().getEMessage();
67
64
	
68
	for (int i = 0; i < _newOperation.getEFaults().size(); i++)
65
		for (int i = 0; i < _newOperation.getEFaults().size(); i++)
69
	{
66
		{
70
	    Fault fault = (Fault) _newOperation.getEFaults().get(i);
67
		    Fault fault = (Fault) _newOperation.getEFaults().get(i);
71
	    faultMessages.add(fault.getEMessage());
68
		    faultMessages.add(fault.getEMessage());
72
	}
69
		}
73
70
	
74
	PortType portType = WsdlUtils.getPortType(_definition);
71
		PortType portType = WsdlUtils.getPortType(_definition);
75
	_newOperation.setEnclosingDefinition(portType.getEnclosingDefinition());
72
		_newOperation.setEnclosingDefinition(portType.getEnclosingDefinition());
76
	portType.addOperation(_newOperation);
73
		portType.addOperation(_newOperation);
77
78
	// Add Old Refs
79
	_newOperation.getEInput().setEMessage(inputMessage);
80
	_newOperation.getEOutput().setEMessage(outputMessage);
81
82
	for (int i = 0; i < faultMessages.size(); i++)
83
	{
84
	    Fault fault = (Fault) _newOperation.getEFaults().get(i);
85
	    Message faultMsg = (Message) faultMessages.get(i);
86
	    fault.setEMessage(faultMsg);
87
	}
88
	
74
	
89
	addAction(_newOperation.getEInput());
75
		// Add Old Refs
90
	addAction(_newOperation.getEOutput());
76
		_newOperation.getEInput().setEMessage(inputMessage);
77
		_newOperation.getEOutput().setEMessage(outputMessage);
91
	
78
	
92
	// Add this operation to capability
79
		for (int i = 0; i < faultMessages.size(); i++)
93
	_capability.getOperations().add(_newOperation);
80
		{
81
		    Fault fault = (Fault) _newOperation.getEFaults().get(i);
82
		    Message faultMsg = (Message) faultMessages.get(i);
83
		    fault.setEMessage(faultMsg);
84
		}
85
		
86
		addAction(_newOperation.getEInput());
87
		addAction(_newOperation.getEOutput());
88
		
89
		// Add this operation to capability
90
		_capability.getOperations().add(_newOperation);
94
    }
91
    }
95
92
96
    private void addAction(Input input)
93
    private void addAction(Input input)
97
    {
94
    {
98
	String action = getAction(input.getEMessage());
95
	    Definition _definition = _capability.getDefinition();
99
	Message inputMessage = input.getEMessage();
96
	    String action = getAction(input.getEMessage());
100
	input.getElement().setAttributeNS(WsdmConstants.WSA_URI, WsdmConstants.WSA_ACTION_NAME, action);
97
		Message inputMessage = input.getEMessage();
101
	input.setEMessage(inputMessage);
98
		input.getElement().setAttributeNS(WsdmConstants.WSA_URI, WsdmConstants.WSA_ACTION_NAME, action);
102
	_definition.addNamespace(WsdmConstants.WSA_PREFIX, WsdmConstants.WSA_URI);	
99
		input.setEMessage(inputMessage);
100
		_definition.addNamespace(WsdmConstants.WSA_PREFIX, WsdmConstants.WSA_URI);	
103
    }
101
    }
104
102
105
    private void addAction(Output output)
103
    private void addAction(Output output)
106
    {
104
    {
107
	String action = getAction(output.getEMessage());
105
	    Definition _definition = _capability.getDefinition();
108
	Message outputMessage = output.getEMessage();
106
	    String action = getAction(output.getEMessage());
109
	output.getElement().setAttributeNS(WsdmConstants.WSA_URI, WsdmConstants.WSA_ACTION_NAME, action);
107
		Message outputMessage = output.getEMessage();
110
	output.setEMessage(outputMessage);
108
		output.getElement().setAttributeNS(WsdmConstants.WSA_URI, WsdmConstants.WSA_ACTION_NAME, action);
111
	_definition.addNamespace(WsdmConstants.WSA_PREFIX, WsdmConstants.WSA_URI);	
109
		output.setEMessage(outputMessage);
110
		_definition.addNamespace(WsdmConstants.WSA_PREFIX, WsdmConstants.WSA_URI);	
112
    }
111
    }
113
112
114
    private String getAction(Message message)
113
    private String getAction(Message message)
115
    {
114
    {
116
	String uri = message.getQName().getNamespaceURI();
115
		String uri = message.getQName().getNamespaceURI();
117
	String name = message.getQName().getLocalPart();
116
		String name = message.getQName().getLocalPart();
118
	name = name.substring(0, 1).toUpperCase() + name.substring(1);
117
		name = name.substring(0, 1).toUpperCase() + name.substring(1);
119
	return uri + "/" + name;
118
		return uri + "/" + name;
120
    }
119
    }
121
    
120
    
122
    public Operation getOperation()
121
    public Operation getOperation()
123
    {
122
    {
124
	return _newOperation;
123
    	return _newOperation;
125
    }
124
    }
126
125
127
}
126
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/operation/internal/RemoveOperationCommand.java (-56 / +56 lines)
Lines 35-42 Link Here
35
public class RemoveOperationCommand
35
public class RemoveOperationCommand
36
{
36
{
37
37
38
    private Definition _definition;
39
40
    private Operation _operation;
38
    private Operation _operation;
41
39
42
    private Capability _capability;
40
    private Capability _capability;
Lines 49-58 Link Here
49
    public RemoveOperationCommand(CapabilityDomain capabilityDomain,
47
    public RemoveOperationCommand(CapabilityDomain capabilityDomain,
50
	    Operation operation)
48
	    Operation operation)
51
    {
49
    {
52
	_capabilityDomain = capabilityDomain;
50
		_capabilityDomain = capabilityDomain;
53
	_definition = capabilityDomain.getDefinition();
51
		_capability = capabilityDomain.getCapability();
54
	_capability = capabilityDomain.getCapability();
52
		_operation = operation;
55
	_operation = operation;
56
    }
53
    }
57
54
58
    /**
55
    /**
Lines 62-129 Link Here
62
     */
59
     */
63
    public void execute()
60
    public void execute()
64
    {
61
    {
65
	PortType portType = WsdlUtils.getPortType(_definition);
62
		Definition _definition = _capability.getDefinition();
66
	removeMessages();
63
	    PortType portType = WsdlUtils.getPortType(_definition);
67
	removeFaults();
64
		removeMessages();
68
	portType.getEOperations().remove(_operation);
65
		removeFaults();
69
66
		portType.getEOperations().remove(_operation);
70
	// Remove from the capability
67
	
71
	_capability.getOperations().remove(_operation);
68
		// Remove from the capability
69
		_capability.getOperations().remove(_operation);
72
    }
70
    }
73
71
74
    private void removeMessages()
72
    private void removeMessages()
75
    {
73
    {
76
	Message inpMsg = _operation.getEInput().getEMessage();
74
		Message inpMsg = _operation.getEInput().getEMessage();
77
	
75
		
78
	// If the input message falls in the same capability definition
76
		// If the input message falls in the same capability definition
79
	// Then remove the input message and xsd decalaration element for that
77
		// Then remove the input message and xsd decalaration element for that
80
	if(inpMsg.getEnclosingDefinition().equals(_definition))
78
		Definition _definition = _capability.getDefinition();
81
	{
79
		if(inpMsg.getEnclosingDefinition().equals(_definition))
82
	    removeElementDeclaration(inpMsg.getEParts());
80
		{
83
	    _definition.getEMessages().remove(inpMsg);
81
		    removeElementDeclaration(inpMsg.getEParts());
84
	}
82
		    _definition.getEMessages().remove(inpMsg);
85
	
83
		}
86
	// If the output message falls in the same capability definition
84
		
87
	// Then remove the output message and xsd decalaration element for that
85
		// If the output message falls in the same capability definition
88
	Message outMsg = _operation.getEOutput().getEMessage();
86
		// Then remove the output message and xsd decalaration element for that
89
	if(outMsg.getEnclosingDefinition().equals(_definition))
87
		Message outMsg = _operation.getEOutput().getEMessage();
90
	{
88
		if(outMsg.getEnclosingDefinition().equals(_definition))
91
	    removeElementDeclaration(outMsg.getEParts());
89
		{
92
	    _definition.getEMessages().remove(outMsg);
90
		    removeElementDeclaration(outMsg.getEParts());
93
	}
91
		    _definition.getEMessages().remove(outMsg);
92
		}
94
    }
93
    }
95
94
96
    private void removeElementDeclaration(List partList)
95
    private void removeElementDeclaration(List partList)
97
    {
96
    {
98
	if(partList == null)
97
	    Definition _definition = _capability.getDefinition();
99
	    return;
98
	    if(partList == null)
100
	
99
		    return;
101
	for (int i = 0; i < partList.size(); i++)
100
		
102
	{
101
		for (int i = 0; i < partList.size(); i++)
103
	    Part part = (Part) partList.get(i);
102
		{
104
	    XSDElementDeclaration element = part.getElementDeclaration();
103
		    Part part = (Part) partList.get(i);
105
	    if(element!=null)
104
		    XSDElementDeclaration element = part.getElementDeclaration();
106
	    {
105
		    if(element!=null)
107
		// If Element defined in the same wsdl file
106
		    {
108
		// Then remove the Element
107
			// If Element defined in the same wsdl file
109
		XSDSchema elementSchema = WsdlUtils.getSchema(_definition, element.getTargetNamespace());
108
			// Then remove the Element
110
		if(elementSchema!=null)
109
			XSDSchema elementSchema = WsdlUtils.getSchema(_definition, element.getTargetNamespace());
111
		    element.getSchema().getContents().remove(element);
110
			if(elementSchema!=null)
112
	    }
111
			    element.getSchema().getContents().remove(element);
113
	}
112
		    }
113
		}
114
    }
114
    }
115
115
116
    private void removeFaults()
116
    private void removeFaults()
117
    {
117
    {
118
	List faults = _operation.getEFaults();
118
		List faults = _operation.getEFaults();
119
	if(faults == null)
119
		if(faults == null)
120
	    return;
120
		    return;
121
	for (int i = 0; i < faults.size(); i++)
121
		for (int i = 0; i < faults.size(); i++)
122
	{
122
		{
123
	    Fault fault = (Fault) faults.get(i);
123
		    Fault fault = (Fault) faults.get(i);
124
	    RemoveExceptionCommand command = new RemoveExceptionCommand(_capabilityDomain, _operation, fault);
124
		    RemoveExceptionCommand command = new RemoveExceptionCommand(_capabilityDomain, _operation, fault);
125
	    command.execute();
125
		    command.execute();
126
	}
126
		}
127
    }
127
    }
128
128
129
}
129
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/operation/internal/AddExceptionCommand.java (-8 / +6 lines)
Lines 35-43 Link Here
35
     */
35
     */
36
    public AddExceptionCommand(CapabilityDomain capabilityDomain, Operation operation, Fault fault)
36
    public AddExceptionCommand(CapabilityDomain capabilityDomain, Operation operation, Fault fault)
37
    {
37
    {
38
	_capabilityDomain = capabilityDomain;
38
		_capabilityDomain = capabilityDomain;
39
	_operation = operation;
39
		_operation = operation;
40
	_fault = fault;
40
		_fault = fault;
41
    }
41
    }
42
42
43
    /**
43
    /**
Lines 46-56 Link Here
46
     */
46
     */
47
    public void execute()
47
    public void execute()
48
    {
48
    {
49
	Definition definition = _capabilityDomain.getDefinition();
49
		Definition definition = _capabilityDomain.getCapability().getDefinition();	
50
	
50
		definition.addMessage(_fault.getEMessage());	
51
	definition.addMessage(_fault.getEMessage());
51
		_operation.addFault(_fault);
52
	
53
	_operation.addFault(_fault);
54
    }
52
    }
55
53
56
}
54
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/CapabilityStorage.java (-2 / +2 lines)
Lines 15-26 Link Here
15
import java.io.InputStream;
15
import java.io.InputStream;
16
import java.io.StringBufferInputStream;
16
import java.io.StringBufferInputStream;
17
17
18
import org.apache.muse.util.xml.XmlUtils;
19
import org.eclipse.core.resources.IStorage;
18
import org.eclipse.core.resources.IStorage;
20
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.PlatformObject;
22
import org.eclipse.core.runtime.PlatformObject;
23
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
24
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
24
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
25
import org.eclipse.wst.wsdl.Definition;
25
import org.eclipse.wst.wsdl.Definition;
26
26
Lines 40-46 Link Here
40
	}
40
	}
41
	
41
	
42
	public InputStream getContents() throws CoreException {
42
	public InputStream getContents() throws CoreException {
43
		String str = XmlUtils.toString(_definition.getElement());
43
		String str = CapUtils.documentToString(_definition.getElement().getOwnerDocument());
44
		StringBufferInputStream stream = new StringBufferInputStream(str);
44
		StringBufferInputStream stream = new StringBufferInputStream(str);
45
		return stream;
45
		return stream;
46
	}
46
	}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/CapabilityEditor.java (-148 / +147 lines)
Lines 17-23 Link Here
17
import java.io.IOException;
17
import java.io.IOException;
18
import java.util.List;
18
import java.util.List;
19
19
20
import org.apache.muse.util.xml.XmlUtils;
21
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IProgressMonitor;
Lines 28-39 Link Here
28
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.source.internal.WsdlSourcePage;
27
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.source.internal.WsdlSourcePage;
29
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.source.internal.XsdSourcePage;
28
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.source.internal.XsdSourcePage;
30
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.topic.internal.TopicPage;
29
import org.eclipse.tptp.wsdm.tooling.editor.capability.pages.topic.internal.TopicPage;
30
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
31
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.ISourcePage;
31
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.ISourcePage;
32
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
32
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
33
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
33
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
34
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
34
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
35
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
35
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
36
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
36
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
37
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
37
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
38
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
38
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
Lines 74-87 Link Here
74
         */
74
         */
75
    IUIPage createOperationPage()
75
    IUIPage createOperationPage()
76
    {
76
    {
77
	IUIPage operationPage = new OperationPage(getContainer(), this,
77
		IUIPage operationPage = new OperationPage(getContainer(), this,
78
		Messages.OPERATION);
78
			Messages.OPERATION);
79
	operationPage.create();
79
		operationPage.create();
80
	_operationPageIndex = addPage(operationPage.getForm());
80
		_operationPageIndex = addPage(operationPage.getForm());
81
	setPageText(_operationPageIndex, Messages.OPERATIONS);
81
		setPageText(_operationPageIndex, Messages.OPERATIONS);
82
	addPropertyListener(operationPage);
82
		addPropertyListener(operationPage);
83
	_pages.add(operationPage);
83
		_pages.add(operationPage);
84
	return operationPage;
84
		return operationPage;
85
    }
85
    }
86
86
87
    /**
87
    /**
Lines 89-102 Link Here
89
         */
89
         */
90
    IUIPage createOverviewPage()
90
    IUIPage createOverviewPage()
91
    {
91
    {
92
	IUIPage overviewPage = new OverviewPage(getContainer(), this,
92
		IUIPage overviewPage = new OverviewPage(getContainer(), this,
93
		Messages.OVERVIEW);
93
			Messages.OVERVIEW);
94
	overviewPage.create();
94
		overviewPage.create();
95
	_overviewPageIndex = addPage(overviewPage.getForm());
95
		_overviewPageIndex = addPage(overviewPage.getForm());
96
	setPageText(_overviewPageIndex, Messages.OVERVIEW);
96
		setPageText(_overviewPageIndex, Messages.OVERVIEW);
97
	addPropertyListener(overviewPage);
97
		addPropertyListener(overviewPage);
98
	_pages.add(overviewPage);
98
		_pages.add(overviewPage);
99
	return overviewPage;
99
		return overviewPage;
100
    }
100
    }
101
101
102
    /**
102
    /**
Lines 104-117 Link Here
104
         */
104
         */
105
    IUIPage createPropertyPage()
105
    IUIPage createPropertyPage()
106
    {
106
    {
107
	IUIPage propertyPage = new PropertyPage(getContainer(), this,
107
		IUIPage propertyPage = new PropertyPage(getContainer(), this,
108
		Messages.PROPERTY);
108
			Messages.PROPERTY);
109
	propertyPage.create();
109
		propertyPage.create();
110
	_propertyPageIndex = addPage(propertyPage.getForm());
110
		_propertyPageIndex = addPage(propertyPage.getForm());
111
	setPageText(_propertyPageIndex, Messages.PROPERTIES);
111
		setPageText(_propertyPageIndex, Messages.PROPERTIES);
112
	addPropertyListener(propertyPage);
112
		addPropertyListener(propertyPage);
113
	_pages.add(propertyPage);
113
		_pages.add(propertyPage);
114
	return propertyPage;
114
		return propertyPage;
115
    }
115
    }
116
116
117
    /**
117
    /**
Lines 119-131 Link Here
119
         */
119
         */
120
    IUIPage createTopicPage()
120
    IUIPage createTopicPage()
121
    {
121
    {
122
	IUIPage topicPage = new TopicPage(getContainer(), this, Messages.TOPIC);
122
		IUIPage topicPage = new TopicPage(getContainer(), this, Messages.TOPIC);
123
	topicPage.create();
123
		topicPage.create();
124
	_topicPageIndex = addPage(topicPage.getForm());
124
		_topicPageIndex = addPage(topicPage.getForm());
125
	setPageText(_topicPageIndex, Messages.TOPICS);
125
		setPageText(_topicPageIndex, Messages.TOPICS);
126
	addPropertyListener(topicPage);
126
		addPropertyListener(topicPage);
127
	_pages.add(topicPage);
127
		_pages.add(topicPage);
128
	return topicPage;
128
		return topicPage;
129
    }
129
    }
130
130
131
    /**
131
    /**
Lines 133-144 Link Here
133
         */
133
         */
134
    ISourcePage createRMDSourcePage()
134
    ISourcePage createRMDSourcePage()
135
    {
135
    {
136
	ISourcePage rmdSourcePage = new RmdSourcePage(getContainer(), this);
136
		ISourcePage rmdSourcePage = new RmdSourcePage(getContainer(), this);
137
	rmdSourcePage.create();
137
		rmdSourcePage.create();
138
	_rmdSourcePageIndex = addPage(rmdSourcePage.getControl());
138
		_rmdSourcePageIndex = addPage(rmdSourcePage.getControl());
139
	setPageText(_rmdSourcePageIndex, Messages.RMD_SOURCE);
139
		setPageText(_rmdSourcePageIndex, Messages.RMD_SOURCE);
140
	_pages.add(rmdSourcePage);
140
		_pages.add(rmdSourcePage);
141
	return rmdSourcePage;
141
		return rmdSourcePage;
142
    }
142
    }
143
143
144
    /**
144
    /**
Lines 146-157 Link Here
146
         */
146
         */
147
    ISourcePage createWSDLSourcePage()
147
    ISourcePage createWSDLSourcePage()
148
    {
148
    {
149
	ISourcePage sourcePage = new WsdlSourcePage(getContainer(), this);
149
		ISourcePage sourcePage = new WsdlSourcePage(getContainer(), this);
150
	sourcePage.create();
150
		sourcePage.create();
151
	_wsdlSourcePageIndex = addPage(sourcePage.getControl());
151
		_wsdlSourcePageIndex = addPage(sourcePage.getControl());
152
	setPageText(_wsdlSourcePageIndex, Messages.WSDL_SOURCE);
152
		setPageText(_wsdlSourcePageIndex, Messages.WSDL_SOURCE);
153
	_pages.add(sourcePage);
153
		_pages.add(sourcePage);
154
	return sourcePage;
154
		return sourcePage;
155
    }
155
    }
156
156
157
    /**
157
    /**
Lines 159-170 Link Here
159
         */
159
         */
160
    ISourcePage createXSDSourcePage()
160
    ISourcePage createXSDSourcePage()
161
    {
161
    {
162
	ISourcePage sourcePage = new XsdSourcePage(getContainer(), this);
162
		ISourcePage sourcePage = new XsdSourcePage(getContainer(), this);
163
	sourcePage.create();
163
		sourcePage.create();
164
	_xsdSourcePageIndex = addPage(sourcePage.getControl());
164
		_xsdSourcePageIndex = addPage(sourcePage.getControl());
165
	setPageText(_xsdSourcePageIndex, Messages.XSD_SOURCE);
165
		setPageText(_xsdSourcePageIndex, Messages.XSD_SOURCE);
166
	_pages.add(sourcePage);
166
		_pages.add(sourcePage);
167
	return sourcePage;
167
		return sourcePage;
168
    }
168
    }
169
169
170
    /**
170
    /**
Lines 172-187 Link Here
172
         */
172
         */
173
    void saveMetaData(IProgressMonitor monitor)
173
    void saveMetaData(IProgressMonitor monitor)
174
    {
174
    {
175
	if (_capabilityDomain.getMetaDataDescriptor() != null)
175
		if (_capabilityDomain.getCapability().getMetadata() != null)
176
	{
176
		{
177
	    PropertyMetaDataDescriptor propertyMetaDataDescriptor = _capabilityDomain
177
		    MetadataDescriptor propertyMetaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
178
		    .getMetaDataDescriptor();
178
		    String metadataDescriptorName = _capabilityDomain.getCapability()
179
	    String metadataDescriptorName = _capabilityDomain.getCapability()
179
			    .getName()
180
		    .getName()
180
			    + "Descriptor";
181
		    + "Descriptor";
181
		    propertyMetaDataDescriptor
182
	    propertyMetaDataDescriptor
182
			    .setMetadataDescriptorName(metadataDescriptorName);	
183
		    .setMetadataDescriptorName(metadataDescriptorName);
183
		    propertyMetaDataDescriptor.saveMetrics();
184
	}
184
		}
185
    }
185
    }
186
186
187
    /**
187
    /**
Lines 189-209 Link Here
189
         */
189
         */
190
    void saveSchemas(IProgressMonitor monitor)
190
    void saveSchemas(IProgressMonitor monitor)
191
    {
191
    {
192
	List propertySchemas = _capabilityDomain.getPropertiesSchemas();
192
		List propertySchemas = _capabilityDomain.getPropertiesSchemas();
193
	if (propertySchemas == null || propertySchemas.size() == 0)
193
		if (propertySchemas == null || propertySchemas.size() == 0)
194
	    return;
194
		    return;
195
195
	
196
	for (int i = 0; i < propertySchemas.size(); i++)
196
		for (int i = 0; i < propertySchemas.size(); i++)
197
	{
197
		{
198
	    XSDSchema propertySchema = (XSDSchema) propertySchemas.get(i);
198
		    XSDSchema propertySchema = (XSDSchema) propertySchemas.get(i);
199
	    if (propertySchema != null)
199
		    if (propertySchema != null)
200
	    {
200
		    {
201
		String locationURI = propertySchema.getSchemaLocation();
201
				String locationURI = propertySchema.getSchemaLocation();
202
		if (locationURI.endsWith("xsd"))
202
				if (locationURI.endsWith("xsd"))
203
		    XsdUtils.serializeAndFormatXSD(propertySchema, locationURI,
203
				    XsdUtils.serializeAndFormatXSD(propertySchema, locationURI,
204
			    false, monitor);
204
					    false, monitor);
205
	    }
205
		    }
206
	}
206
		}
207
    }
207
    }
208
208
209
    /**
209
    /**
Lines 211-230 Link Here
211
         */
211
         */
212
    void saveTopics(IProgressMonitor monitor)
212
    void saveTopics(IProgressMonitor monitor)
213
    {
213
    {
214
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = _capabilityDomain
214
	    MetadataDescriptor propertyMetaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
215
		.getMetaDataDescriptor();
215
		if (propertyMetaDataDescriptor != null)
216
	if (propertyMetaDataDescriptor != null)
216
		{
217
	{
217
		    List topicSpaces = _capabilityDomain.getCapability()
218
	    List topicSpaces = _capabilityDomain.getCapability()
218
			    .getTopicSpaces();
219
		    .getTopicSpaces();
219
		    propertyMetaDataDescriptor.saveTopicSpaces(topicSpaces);
220
	    propertyMetaDataDescriptor.saveTopicSpaces(topicSpaces);
220
		    PortType pt = WsdlUtils.getPortType(_capabilityDomain.getCapability()
221
	    PortType pt = WsdlUtils.getPortType(_capabilityDomain
221
			    .getDefinition());
222
		    .getDefinition());
222
		    String rmdFileName = pt.getElement().getAttributeNS(
223
	    String rmdFileName = pt.getElement().getAttributeNS(
223
			    WsdmConstants.WSRMD_NS,
224
		    WsdmConstants.WSRMD_NS,
224
			    WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
225
		    WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
225
		    MetaDataUtils.save(propertyMetaDataDescriptor, monitor);
226
	    propertyMetaDataDescriptor.save(monitor);
226
		}
227
	}
228
    }
227
    }
229
228
230
    /**
229
    /**
Lines 232-274 Link Here
232
         */
231
         */
233
    void saveWSDL(IProgressMonitor monitor)
232
    void saveWSDL(IProgressMonitor monitor)
234
    {
233
    {
235
	ensureWSRFNamespaces();
234
		ensureWSRFNamespaces();
236
	Definition wsdlDefinition = _capabilityDomain.getDefinition();
235
		Definition wsdlDefinition = _capabilityDomain.getCapability().getDefinition();
237
	String wsdlURI = wsdlDefinition.eResource().getURI().toString();
236
		String wsdlURI = wsdlDefinition.eResource().getURI().toString();
238
	ByteArrayOutputStream baos = null;
237
		ByteArrayOutputStream baos = null;
239
	try
238
		try
240
	{
239
		{
241
	    baos = WsdlUtils.saveWSDLDefinition(
240
		    baos = WsdlUtils.saveWSDLDefinition(
242
	    	wsdlDefinition, wsdlURI, null);
241
		    	wsdlDefinition, wsdlURI, null);
243
	} catch (IOException e1)
242
		} catch (IOException e1)
244
	{
243
		{
245
	    WsdmToolingLog.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_ + " ", e1);
244
		    WsdmToolingLog.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_ + " ", e1);
246
	}
245
		}
247
246
	
248
	Document doc = CapUtils.parseToDOM(baos.toString());
247
		Document doc = CapUtils.parseToDOM(baos.toString());
249
	String serialized = CapUtils.prettySerializeDocument(doc);
248
		String serialized = CapUtils.documentToString(doc);
250
	ByteArrayInputStream baInputStream = new ByteArrayInputStream(
249
		ByteArrayInputStream baInputStream = new ByteArrayInputStream(
251
		serialized.getBytes());
250
			serialized.getBytes());
252
251
	
253
	try
252
		try
254
	{
253
		{
255
	    IFile wsdlFile = EclipseUtils.getIFile(wsdlURI);
254
		    IFile wsdlFile = EclipseUtils.getIFile(wsdlURI);
256
		wsdlFile.setContents(baInputStream, IFile.FORCE, monitor);
255
			wsdlFile.setContents(baInputStream, IFile.FORCE, monitor);
257
	} catch (CoreException e)
256
		} catch (CoreException e)
258
	{
257
		{
259
	    WsdmToolingLog.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_ + " ", e);
258
		    WsdmToolingLog.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_ + " ", e);
260
	}
259
		}
261
    }
260
    }
262
261
263
    private void ensureWSRFNamespaces()
262
    private void ensureWSRFNamespaces()
264
    {
263
    {
265
	Definition definition = _capabilityDomain.getDefinition();
264
		Definition definition = _capabilityDomain.getCapability().getDefinition();
266
	if (_capabilityDomain.getResourcePropertyElement() != null)
265
		if (_capabilityDomain.getResourcePropertyElement() != null)
267
	    WsdlUtils.createOrFindPrefix(definition, WsdmConstants.WSRP_NS,
266
		    WsdlUtils.createOrFindPrefix(definition, WsdmConstants.WSRP_NS,
268
		    "wsrp");
267
			    "wsrp");
269
	if (_capabilityDomain.getMetaDataDescriptor() != null)
268
		if (_capabilityDomain.getCapability().getMetadata() != null)
270
	    WsdlUtils.createOrFindPrefix(definition, WsdmConstants.WSRMD_NS,
269
		    WsdlUtils.createOrFindPrefix(definition, WsdmConstants.WSRMD_NS,
271
		    "wsrmd");
270
			    "wsrmd");
272
    }
271
    }
273
272
274
    /**
273
    /**
Lines 276-283 Link Here
276
         */
275
         */
277
    boolean loadWSDLSourcePage()
276
    boolean loadWSDLSourcePage()
278
    {
277
    {
279
	//return true;
278
		//return true;
280
	return false;
279
		return false;
281
    }
280
    }
282
281
283
    /**
282
    /**
Lines 285-292 Link Here
285
         */
284
         */
286
    boolean loadRMDSourcePage()
285
    boolean loadRMDSourcePage()
287
    {
286
    {
288
	// return _capabilityDomain.getMetaDataDescriptor()!=null;
287
		// return _capabilityDomain.getMetaDataDescriptor()!=null;
289
	return false;
288
		return false;
290
    }
289
    }
291
290
292
    /**
291
    /**
Lines 294-301 Link Here
294
         */
293
         */
295
    boolean loadXSDSourcePage()
294
    boolean loadXSDSourcePage()
296
    {
295
    {
297
	// return _capabilityDomain.getResourcePropertyElement()!=null;
296
		// return _capabilityDomain.getResourcePropertyElement()!=null;
298
	return false;
297
		return false;
299
    }
298
    }
300
299
301
    /**
300
    /**
Lines 323-343 Link Here
323
         */
322
         */
324
    void updateWSDLSourceFromForm()
323
    void updateWSDLSourceFromForm()
325
    {
324
    {
326
	IFileEditorInput modelFile = (IFileEditorInput) getEditorInput();
325
		IFileEditorInput modelFile = (IFileEditorInput) getEditorInput();
327
	String uri = modelFile.getFile().getFullPath().toString();
326
		String uri = modelFile.getFile().getFullPath().toString();
328
	ensureWSRFNamespaces();
327
		ensureWSRFNamespaces();
329
	ByteArrayOutputStream baos;
328
		ByteArrayOutputStream baos;
330
	try
329
		try
331
	{
330
		{
332
	    baos = WsdlUtils.saveWSDLDefinition(
331
		    baos = WsdlUtils.saveWSDLDefinition(
333
	    	_capabilityDomain.getDefinition(), uri, null);
332
		    	_capabilityDomain.getCapability().getDefinition(), uri, null);
334
	} catch (IOException e)
333
		} catch (IOException e)
335
	{
334
		{
336
	    return;
335
		    return;
337
	}
336
		}
338
	Document doc = CapUtils.parseToDOM(baos.toString());
337
		Document doc = CapUtils.parseToDOM(baos.toString());
339
	String serialized = CapUtils.prettySerializeDocument(doc);
338
		String serialized = CapUtils.documentToString(doc);
340
	_wsdlSourcePage.setText(serialized);
339
		_wsdlSourcePage.setText(serialized);
341
    }
340
    }
342
341
343
    /**
342
    /**
Lines 345-353 Link Here
345
         */
344
         */
346
    void updateXSDSourceFromForm()
345
    void updateXSDSourceFromForm()
347
    {
346
    {
348
	XSDSchema propSchema = getCapabilityDomain().getPropertySchema();
347
		XSDSchema propSchema = getCapabilityDomain().getPropertySchema();
349
	Document doc = propSchema.getDocument();
348
		Document doc = propSchema.getDocument();
350
	String text = XmlUtils.toString(doc);
349
		String text = CapUtils.documentToString(doc);
351
	_xsdSourcePage.setText(text);
350
		_xsdSourcePage.setText(text);
352
    }
351
    }
353
}
352
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/FormMetric.java (-106 / +42 lines)
Lines 12-36 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.internal;
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.internal;
14
14
15
import java.util.Iterator;
16
17
import org.eclipse.emf.ecore.EStructuralFeature;
18
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
19
import org.eclipse.emf.ecore.resource.ResourceSet;
15
import org.eclipse.emf.ecore.resource.ResourceSet;
20
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
16
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
21
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
17
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
22
import org.eclipse.emf.ecore.util.ExtendedMetaData;
18
import org.eclipse.emf.ecore.util.ExtendedMetaData;
23
import org.eclipse.emf.ecore.util.FeatureMap;
19
import org.eclipse.emf.ecore.xmi.XMLResource;
24
import org.eclipse.emf.ecore.xml.type.internal.QName;
25
import org.eclipse.emf.ecore.xml.type.internal.XMLDuration;
26
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
20
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics;
27
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
23
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
24
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
28
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
25
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
29
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.ChangeTypeType;
30
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.GatheringTimeType;
31
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.TimeScopeType;
32
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
33
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
34
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
26
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
35
27
36
/**
28
/**
Lines 63-75 Link Here
63
55
64
	public static final String[] COLUMN_NAMES = new String[] { CTYPE_COL, TSCOPE_COL, GTIME_COL, CINTERVAL_COL, GROUP_COL };
56
	public static final String[] COLUMN_NAMES = new String[] { CTYPE_COL, TSCOPE_COL, GTIME_COL, CINTERVAL_COL, GROUP_COL };
65
57
66
	private ChangeTypeType _changeType;
58
	private String _changeType;
67
	
59
	
68
	private TimeScopeType _timeScope;
60
	private String _timeScope;
69
	
61
	
70
	private GatheringTimeType _gatheringTime;
62
	private String _gatheringTime;
71
	
63
	
72
	private XMLDuration _calculationInterval;
64
	private String _calculationInterval;
73
	
65
	
74
	private PropertyType _metadata;
66
	private PropertyType _metadata;
75
	
67
	
Lines 93-110 Link Here
93
		_capabilityDomain = capabilityDomain;
85
		_capabilityDomain = capabilityDomain;
94
		_property = property;
86
		_property = property;
95
		_metadata = property.getMetaData();		
87
		_metadata = property.getMetaData();		
96
		_extendedMetaData = createExtendedMetaData();		
88
		_extendedMetaData = createExtendedMetaData();
89
		if(property.getMetrics()!=null)
90
		{
91
			_changeType = property.getMetrics().getChangeType();
92
			_timeScope = property.getMetrics().getTimeScope();
93
			_gatheringTime = property.getMetrics().getGatheringTime();
94
			_calculationInterval = property.getMetrics().getCalculationInterval();
95
		}		
97
	}
96
	}
98
	
97
	
99
	private PropertyType createNewPropertyMetadata()
98
	private PropertyType createNewPropertyMetadata()
100
	{
99
	{
101
		PropertyMetaDataDescriptor propertyMetaDataDescriptor = _capabilityDomain.getMetaDataDescriptor();
100
		MetadataDescriptor propertyMetaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
102
		PropertyType metadata = propertyMetaDataDescriptor.createNewPropertyType();
101
		PropertyType metadata = propertyMetaDataDescriptor.createNewPropertyType();
103
		_property.setMetaData(metadata);
102
		_property.setMetaData(metadata);
104
		String ns = _property.getElement().getTargetNamespace();
103
		String ns = _property.getElement().getTargetNamespace();
105
		String name = XsdUtils.getName(_property.getElement());
104
		String name = XsdUtils.getName(_property.getElement());
106
		String prefix = propertyMetaDataDescriptor.getOrCreatePrefix(ns);
105
		String prefix = propertyMetaDataDescriptor.getOrCreatePrefix(ns);
107
		metadata.setName(new QName(ns,name,prefix));
106
		metadata.setName(prefix+":"+name);
108
		return metadata;
107
		return metadata;
109
	}
108
	}
110
	
109
	
Lines 112-118 Link Here
112
	{
111
	{
113
		ResourceSet resourceSet = new ResourceSetImpl();
112
		ResourceSet resourceSet = new ResourceSetImpl();
114
		ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(resourceSet.getPackageRegistry());
113
		ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(resourceSet.getPackageRegistry());
115
		return extendedMetaData;
114
		resourceSet.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
115
		return extendedMetaData;	
116
	}
116
	}
117
	
117
	
118
	/**
118
	/**
Lines 122-128 Link Here
122
	{
122
	{
123
		if(_calculationInterval == null)
123
		if(_calculationInterval == null)
124
			return "";
124
			return "";
125
		return _calculationInterval.toString();
125
		return _calculationInterval;
126
	}
126
	}
127
127
128
	/**
128
	/**
Lines 132-138 Link Here
132
	{
132
	{
133
		if(_changeType == null)
133
		if(_changeType == null)
134
			return "";
134
			return "";
135
		return _changeType.getLiteral();
135
		return _changeType;
136
	}
136
	}
137
137
138
	/**
138
	/**
Lines 142-148 Link Here
142
	{
142
	{
143
		if(_gatheringTime == null)
143
		if(_gatheringTime == null)
144
			return "";
144
			return "";
145
		return _gatheringTime.getLiteral();
145
		return _gatheringTime;
146
	}
146
	}
147
147
148
	/**
148
	/**
Lines 152-158 Link Here
152
	{
152
	{
153
		if(_timeScope == null)
153
		if(_timeScope == null)
154
			return "";
154
			return "";
155
		return _timeScope.getLiteral();
155
		return _timeScope;
156
	}
156
	}
157
157
158
	/**
158
	/**
Lines 201-207 Link Here
201
	 */
201
	 */
202
	public void setColumnObject(String column, Object value) 
202
	public void setColumnObject(String column, Object value) 
203
	{		
203
	{		
204
		if(_capabilityDomain.getMetaDataDescriptor() == null)
204
		if(_capabilityDomain.getCapability().getMetadata() == null)
205
			MetaDataUtils.createMetaDataDescriptor(_capabilityDomain);
205
			MetaDataUtils.createMetaDataDescriptor(_capabilityDomain);
206
		
206
		
207
		if(_metadata == null)
207
		if(_metadata == null)
Lines 209-239 Link Here
209
		
209
		
210
		if (column.equals(CTYPE_COL)) 
210
		if (column.equals(CTYPE_COL)) 
211
		{
211
		{
212
			removeOldEntry(ChangeTypeType.class);
213
			String newChangeType = CTYPE_STR_ENUM[((Integer) value).intValue()];
212
			String newChangeType = CTYPE_STR_ENUM[((Integer) value).intValue()];
214
			EStructuralFeature _changeTypeESF = _extendedMetaData.demandFeature(WsdmConstants.MUWS_P2_NS, MetaDataUtils.CHANGE_TYPE, false);			
213
			createMetricsIfRequired();
215
			ChangeTypeType changeTypeType = MetaDataUtils.getChangeTypeType(newChangeType);
214
			_property.getMetrics().setChangeType(newChangeType);
216
			createNewEntry(_changeTypeESF,changeTypeType);				
215
			_changeType = newChangeType;
217
			return;
216
			return;
218
		}
217
		}
219
		
218
		
220
		if (column.equals(TSCOPE_COL)) 
219
		if (column.equals(TSCOPE_COL)) 
221
		{
220
		{
222
			removeOldEntry(TimeScopeType.class);
223
			String newTimeScope = TSCOPE_STR_ENUM[((Integer) value).intValue()];
221
			String newTimeScope = TSCOPE_STR_ENUM[((Integer) value).intValue()];
224
			EStructuralFeature _timeScopeESF = _extendedMetaData.demandFeature(WsdmConstants.MUWS_P2_NS, MetaDataUtils.TIME_SCOPE, false);			
222
			createMetricsIfRequired();
225
			TimeScopeType timeScopeType = MetaDataUtils.getTimeScopeType(newTimeScope);
223
			_property.getMetrics().setTimeScope(newTimeScope);
226
			createNewEntry(_timeScopeESF,timeScopeType);				
224
			_timeScope = newTimeScope;			
227
			return;
225
			return;
228
		}
226
		}
229
		
227
		
230
		if (column.equals(GTIME_COL)) 
228
		if (column.equals(GTIME_COL)) 
231
		{
229
		{
232
			removeOldEntry(GatheringTimeType.class);
233
			String newGTime = GTIME_STR_ENUM[((Integer) value).intValue()];
230
			String newGTime = GTIME_STR_ENUM[((Integer) value).intValue()];
234
			EStructuralFeature _gatheringTimeESF = _extendedMetaData.demandFeature(WsdmConstants.MUWS_P2_NS, MetaDataUtils.GATHERING_TIME, false);
231
			createMetricsIfRequired();
235
			GatheringTimeType gatheringTimeType = MetaDataUtils.getGatheringTimeType(newGTime);
232
			_property.getMetrics().setGatheringTime(newGTime);
236
			createNewEntry(_gatheringTimeESF,gatheringTimeType);				
233
			_gatheringTime = newGTime;			
237
			return;
234
			return;
238
		}
235
		}
239
		
236
		
Lines 242-290 Link Here
242
			String newCInterval = (String)value;
239
			String newCInterval = (String)value;
243
			if(newCInterval.equals("") || newCInterval.toUpperCase().equals("P"))
240
			if(newCInterval.equals("") || newCInterval.toUpperCase().equals("P"))
244
				return;
241
				return;
245
			removeOldEntry(XMLDuration.class);
242
			createMetricsIfRequired();
246
			EStructuralFeature _calculationIntervalESF = _extendedMetaData.demandFeature(WsdmConstants.MUWS_P2_NS, MetaDataUtils.CALCULATION_INTERVAL, false);
243
			_property.getMetrics().setCalculationInterval(newCInterval);
247
			XMLDuration duration = new XMLDuration(newCInterval);
244
			_calculationInterval = newCInterval;
248
			createNewEntry(_calculationIntervalESF,duration);
249
		}
245
		}
250
	}
246
	}
251
	
247
	
252
	private void createNewEntry(EStructuralFeature esf, Object value) 
248
	private void createMetricsIfRequired()
253
	{		
254
		createMetricsCapabilityEntry();
255
		FeatureMap fm = _metadata.getAny();
256
		fm.add(esf, value);		
257
	}
258
	
259
	private void removeOldEntry(Class typeClass)
260
	{
249
	{
261
		FeatureMap fm = _metadata.getAny();
250
		if(_property.getMetrics() == null)
262
		Iterator it = fm.iterator();
263
		while (it.hasNext())
264
		{
251
		{
265
			Object obj = it.next();
252
			Metrics metrics = CapabilitiesFactory.eINSTANCE.createMetrics();
266
			if (obj instanceof EStructuralFeatureImpl.SimpleFeatureMapEntry)
253
			_property.setMetrics(metrics);
267
			{
268
				EStructuralFeatureImpl.SimpleFeatureMapEntry entry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) obj;
269
				if(typeClass.isInstance(entry.getValue()))
270
				{
271
					fm.remove(entry);
272
					return;
273
				}					
274
			}
275
		}
254
		}
276
	}
255
	}
277
	
256
	
278
	private void createMetricsCapabilityEntry()
279
	{
280
		if(!MetaDataUtils.hasMetricsCapability(_metadata))
281
		{
282
			FeatureMap fm = _metadata.getAny();
283
			EStructuralFeature esf = _extendedMetaData.demandFeature(WsdmConstants.MUWS_P2_NS, "Capability", false);
284
			fm.add(esf, WsdmConstants.MUWS_METRICS_NS);
285
		}
286
	}
287
288
	/**
257
	/**
289
	 * Returns the metric property for selected column.  
258
	 * Returns the metric property for selected column.  
290
	 */
259
	 */
Lines 309-346 Link Here
309
				return new Integer(i);			
278
				return new Integer(i);			
310
		}
279
		}
311
		return new Integer(0);
280
		return new Integer(0);
312
	}
281
	}		
313
	
314
	/**
315
	 * Sets the change type for this metric. 
316
	 */
317
	public void setChangeType(ChangeTypeType changeType)
318
	{
319
		_changeType = changeType;
320
	}
321
	
322
	/**
323
	 * Sets the time scope for this metric. 
324
	 */
325
	public void setTimeScope(TimeScopeType timeScope)
326
	{
327
		_timeScope = timeScope;
328
	}
329
	
330
	/**
331
	 * Sets the gathering time for this metric. 
332
	 */
333
	public void setGatheringTime(GatheringTimeType gatheringTime)
334
	{
335
		_gatheringTime = gatheringTime;
336
	}
337
	
338
	/**
339
	 * Sets the calculation interval for this metric. 
340
	 */
341
	public void setCalculationInterval(XMLDuration calculationInterval)
342
	{
343
		_calculationInterval = calculationInterval;
344
	}
345
	
346
}
282
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/CapabilityDomain.java (-49 / +28 lines)
Lines 15-24 Link Here
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.core.resources.IFile;
18
import org.eclipse.tptp.wsdm.tooling.model.Activator;
19
import org.eclipse.tptp.wsdm.tooling.model.Activator;
19
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
21
import org.eclipse.wst.wsdl.Definition;
22
import org.eclipse.xsd.XSDElementDeclaration;
21
import org.eclipse.xsd.XSDElementDeclaration;
23
import org.eclipse.xsd.XSDSchema;
22
import org.eclipse.xsd.XSDSchema;
24
import org.osgi.framework.Bundle;
23
import org.osgi.framework.Bundle;
Lines 37-55 Link Here
37
36
38
    private Capability _capability;
37
    private Capability _capability;
39
38
40
    private Definition _definition;
41
    
42
    private XSDSchema _propertySchema;
39
    private XSDSchema _propertySchema;
43
40
44
    private List _propertiesSchemas;
41
    private List _propertiesSchemas;
45
42
46
    private XSDElementDeclaration _resourcePropertyElement;
43
    private XSDElementDeclaration _resourcePropertyElement;
47
44
48
    private PropertyMetaDataDescriptor _metaDataDescriptor;
49
50
    private Bundle _modelPlugin;
45
    private Bundle _modelPlugin;
51
46
52
    private Text _descriptionNode;
47
    private Text _descriptionNode;
48
    
49
    private IFile _capabilityFile;
53
50
54
    /**
51
    /**
55
     * Creates a new object of this class.
52
     * Creates a new object of this class.
Lines 57-64 Link Here
57
     */
54
     */
58
    public CapabilityDomain()
55
    public CapabilityDomain()
59
    {
56
    {
60
	_modelPlugin = Activator.getDefault().getBundle();
57
		_modelPlugin = Activator.getDefault().getBundle();
61
	_propertiesSchemas = new ArrayList();
58
		_propertiesSchemas = new ArrayList();
62
    }
59
    }
63
60
64
    /**
61
    /**
Lines 66-88 Link Here
66
     */
63
     */
67
    public Capability getCapability()
64
    public Capability getCapability()
68
    {
65
    {
69
	return _capability;
66
    	return _capability;
70
    }
67
    }
71
68
    
72
    /**
69
    /**
73
     * Returns the wsdl definition of capability domain.
70
     * Returns the capability file. 
74
     */
71
     */
75
    public Definition getDefinition()
72
    public IFile getCapabilityIFile()
76
    {
73
    {
77
	return _definition;
74
    	return _capabilityFile;
78
    }
75
    }
79
    
76
80
    /**
77
    /**
81
     * Returns the property schema of capability.
78
     * Returns the property schema of capability.
82
     */
79
     */
83
    public XSDSchema getPropertySchema()
80
    public XSDSchema getPropertySchema()
84
    {
81
    {
85
	return _propertySchema;
82
    	return _propertySchema;
86
    }
83
    }
87
84
88
    /**
85
    /**
Lines 90-104 Link Here
90
     */
87
     */
91
    public XSDElementDeclaration getResourcePropertyElement()
88
    public XSDElementDeclaration getResourcePropertyElement()
92
    {
89
    {
93
	return _resourcePropertyElement;
90
    	return _resourcePropertyElement;
94
    }
95
96
    /**
97
     * Returns the propertyMetaDataDescriptor of capability domain. 
98
     */
99
    public PropertyMetaDataDescriptor getMetaDataDescriptor()
100
    {
101
	return _metaDataDescriptor;
102
    }
91
    }
103
92
104
    /**
93
    /**
Lines 106-112 Link Here
106
     */
95
     */
107
    public Text getDescriptionNode()
96
    public Text getDescriptionNode()
108
    {
97
    {
109
	return _descriptionNode;
98
    	return _descriptionNode;
110
    }
99
    }
111
100
112
    /**
101
    /**
Lines 114-120 Link Here
114
     */
103
     */
115
    public List getPropertiesSchemas()
104
    public List getPropertiesSchemas()
116
    {
105
    {
117
	return _propertiesSchemas;
106
    	return _propertiesSchemas;
118
    }
107
    }
119
108
120
    /**
109
    /**
Lines 122-128 Link Here
122
     */
111
     */
123
    public Bundle getModelPlugin()
112
    public Bundle getModelPlugin()
124
    {
113
    {
125
	return _modelPlugin;
114
    	return _modelPlugin;
126
    }
115
    }
127
116
128
    /**
117
    /**
Lines 130-136 Link Here
130
     */
119
     */
131
    public void addPropertySchema(XSDSchema schema)
120
    public void addPropertySchema(XSDSchema schema)
132
    {
121
    {
133
	_propertiesSchemas.add(schema);
122
    	_propertiesSchemas.add(schema);
134
    }
123
    }
135
124
136
    /**
125
    /**
Lines 138-162 Link Here
138
     */
127
     */
139
    public void setCapability(Capability capability)
128
    public void setCapability(Capability capability)
140
    {
129
    {
141
	_capability = capability;
130
    	_capability = capability;
142
    }
131
    }
143
132
    
144
    /**
133
    /**
145
     * Sets the wsdl definition for capability domain.
134
     * Sets the capability file. 
146
     */
135
     */
147
    public void setDefinition(Definition definition)
136
    public void setCapabilityIFile(IFile capabilityFile)
148
    {
137
    {
149
	_definition = definition;
138
    	_capabilityFile = capabilityFile;
150
    }
139
    }
151
    
140
152
    /**
141
    /**
153
     * Sets the property schema for capability. 
142
     * Sets the property schema for capability. 
154
     */
143
     */
155
    public void setPropertySchema(XSDSchema propertySchema)
144
    public void setPropertySchema(XSDSchema propertySchema)
156
    {
145
    {
157
	_propertySchema = propertySchema;
146
		_propertySchema = propertySchema;
158
	if(!getPropertiesSchemas().contains(_propertySchema))
147
		if(!getPropertiesSchemas().contains(_propertySchema))
159
	    addPropertySchema(_propertySchema);
148
		    addPropertySchema(_propertySchema);
160
    }
149
    }
161
150
162
    /**
151
    /**
Lines 165-181 Link Here
165
    public void setResourcePropertyElement(
154
    public void setResourcePropertyElement(
166
	    XSDElementDeclaration resourcePropertyElement)
155
	    XSDElementDeclaration resourcePropertyElement)
167
    {
156
    {
168
	_resourcePropertyElement = resourcePropertyElement;
157
    	_resourcePropertyElement = resourcePropertyElement;
169
    }
170
171
    /**
172
     * Sets the propertyMetaDataDescriptor for capability domain.
173
     */
174
    public void setMetaDataDescriptor(
175
	    PropertyMetaDataDescriptor metaDataDescriptor)
176
    {
177
178
	_metaDataDescriptor = metaDataDescriptor;
179
    }
158
    }
180
159
181
    /**
160
    /**
Lines 183-189 Link Here
183
     */
162
     */
184
    public void setDescriptionNode(Text node)
163
    public void setDescriptionNode(Text node)
185
    {
164
    {
186
	_descriptionNode = node;
165
    	_descriptionNode = node;
187
    }
166
    }
188
    
167
    
189
}
168
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/internal/AbstractCapabilityEditor.java (-273 / +298 lines)
Lines 30-43 Link Here
30
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
30
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
31
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
31
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
32
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
32
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
33
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics;
33
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
34
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
35
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
34
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
36
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
35
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
37
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
36
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
38
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
37
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
38
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
40
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.IResourceChangeConsumer;
41
import org.eclipse.tptp.wsdm.tooling.util.internal.IResourceChangeConsumer;
40
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
41
import org.eclipse.tptp.wsdm.tooling.util.internal.ResourceChangeListener;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.ResourceChangeListener;
42
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
43
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
44
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
Lines 117-148 Link Here
117
         */
118
         */
118
    protected void createPages()
119
    protected void createPages()
119
    {
120
    {
120
	buildModel();
121
		buildModel();
121
	_overviewPage = createOverviewPage();	
122
		_overviewPage = createOverviewPage();	
122
	
123
		
123
	_propertyPage = createPropertyPage();	
124
		_propertyPage = createPropertyPage();	
124
	
125
		
125
	_operationPage = createOperationPage();	
126
		_operationPage = createOperationPage();	
126
	
127
		
127
	_topicPage = createTopicPage();	
128
		_topicPage = createTopicPage();	
128
	
129
		
129
	if (loadWSDLSourcePage())
130
		if (loadWSDLSourcePage())
130
	{
131
		{
131
	    _wsdlSourcePage = createWSDLSourcePage();
132
		    _wsdlSourcePage = createWSDLSourcePage();
132
	    _create_wsdl_source = true;
133
		    _create_wsdl_source = true;
133
	}
134
		}
134
	if (loadXSDSourcePage())
135
		if (loadXSDSourcePage())
135
	{
136
		{
136
	    _xsdSourcePage = createXSDSourcePage();
137
		    _xsdSourcePage = createXSDSourcePage();
137
	    _create_xsd_source = true;
138
		    _create_xsd_source = true;
138
	}
139
		}
139
	if (loadRMDSourcePage())
140
		if (loadRMDSourcePage())
140
	{
141
		{
141
	    _rmdSourcePage = createRMDSourcePage();
142
		    _rmdSourcePage = createRMDSourcePage();
142
	    _create_rmd_source = true;
143
		    _create_rmd_source = true;
143
	}
144
		}
144
	firePropertyChange(IEditorPart.PROP_DIRTY);
145
		firePropertyChange(IEditorPart.PROP_DIRTY);
145
	hookAllListeners();
146
		hookAllListeners();
146
    }
147
    }
147
148
148
    abstract IUIPage createOverviewPage();
149
    abstract IUIPage createOverviewPage();
Lines 184-200 Link Here
184
         */
185
         */
185
    protected void hookAllListeners()
186
    protected void hookAllListeners()
186
    {
187
    {
187
	_overviewPage.hookAllListeners();
188
		_overviewPage.hookAllListeners();
188
	_propertyPage.hookAllListeners();
189
		_propertyPage.hookAllListeners();
189
	_operationPage.hookAllListeners();
190
		_operationPage.hookAllListeners();
190
	_topicPage.hookAllListeners();
191
		_topicPage.hookAllListeners();
191
	if (_create_wsdl_source)
192
		if (_create_wsdl_source)
192
	    _wsdlSourcePage.hookAllListeners();
193
		    _wsdlSourcePage.hookAllListeners();
193
	if (_create_xsd_source)
194
		if (_create_xsd_source)
194
	    _xsdSourcePage.hookAllListeners();
195
		    _xsdSourcePage.hookAllListeners();
195
	if (_create_rmd_source)
196
		if (_create_rmd_source)
196
	    _rmdSourcePage.hookAllListeners();
197
		    _rmdSourcePage.hookAllListeners();
197
	_resourceChangeListener.addResourceChangeConsumer(this);
198
		_resourceChangeListener.addResourceChangeConsumer(this);
198
    }
199
    }
199
200
200
    /**
201
    /**
Lines 202-222 Link Here
202
         */
203
         */
203
    public void doSave(IProgressMonitor monitor)
204
    public void doSave(IProgressMonitor monitor)
204
    {
205
    {
205
	if (_overviewPage.isDirty() || _propertyPage.isDirty()
206
		if (_overviewPage.isDirty() || _propertyPage.isDirty()
206
		|| _operationPage.isDirty() || _topicPage.isDirty())
207
			|| _operationPage.isDirty() || _topicPage.isDirty())
207
	{
208
		{
208
	    saveSchemas(monitor);
209
		    saveSchemas(monitor);
209
	    saveMetaData(monitor);
210
		    saveMetaData(monitor);
210
	    saveTopics(monitor);
211
		    saveTopics(monitor);
211
	    saveWSDL(monitor);
212
		    saveWSDL(monitor);
212
213
	
213
	    _overviewPage.save();
214
		    _overviewPage.save();
214
	    _propertyPage.save();
215
		    _propertyPage.save();
215
	    _operationPage.save();
216
		    _operationPage.save();
216
	    _topicPage.save();
217
		    _topicPage.save();
217
	}
218
		}
218
219
	
219
	firePropertyChange(IEditorPart.PROP_DIRTY);
220
		firePropertyChange(IEditorPart.PROP_DIRTY);
220
    }
221
    }
221
222
222
    /**
223
    /**
Lines 231-237 Link Here
231
         */
232
         */
232
    public boolean isSaveAsAllowed()
233
    public boolean isSaveAsAllowed()
233
    {
234
    {
234
	return false;
235
    	return false;
235
    }
236
    }
236
237
237
    /**
238
    /**
Lines 239-264 Link Here
239
         */
240
         */
240
    public boolean isDirty()
241
    public boolean isDirty()
241
    {
242
    {
242
	if (super.isDirty())
243
		if (super.isDirty())
243
	    return true;
244
		    return true;
244
	if (isSourcePagesDirty())
245
		if (isSourcePagesDirty())
245
	    return true;
246
		    return true;
246
	return (_overviewPage.isDirty() || _propertyPage.isDirty()
247
		return (_overviewPage.isDirty() || _propertyPage.isDirty()
247
		|| _operationPage.isDirty() || _topicPage.isDirty());
248
			|| _operationPage.isDirty() || _topicPage.isDirty());
248
    }
249
    }
249
250
250
    private boolean isSourcePagesDirty()
251
    private boolean isSourcePagesDirty()
251
    {
252
    {
252
	boolean wsdlSourceDirty = false;
253
		boolean wsdlSourceDirty = false;
253
	boolean xsdSourceDirty = false;
254
		boolean xsdSourceDirty = false;
254
	boolean rmdSourceDirty = false;
255
		boolean rmdSourceDirty = false;
255
	if (_create_wsdl_source)
256
		if (_create_wsdl_source)
256
	    wsdlSourceDirty = _wsdlSourcePage.isDirty();
257
		    wsdlSourceDirty = _wsdlSourcePage.isDirty();
257
	if (_create_xsd_source)
258
		if (_create_xsd_source)
258
	    xsdSourceDirty = _xsdSourcePage.isDirty();
259
		    xsdSourceDirty = _xsdSourcePage.isDirty();
259
	if (_create_rmd_source)
260
		if (_create_rmd_source)
260
	    rmdSourceDirty = _rmdSourcePage.isDirty();
261
		    rmdSourceDirty = _rmdSourcePage.isDirty();
261
	return wsdlSourceDirty || xsdSourceDirty || rmdSourceDirty;
262
		return wsdlSourceDirty || xsdSourceDirty || rmdSourceDirty;
262
    }
263
    }
263
264
264
    /**
265
    /**
Lines 272-488 Link Here
272
         */
273
         */
273
    protected void buildModel()
274
    protected void buildModel()
274
    {
275
    {
275
	_capabilityDomain = new CapabilityDomain();
276
		_capabilityDomain = new CapabilityDomain();
276
	Capability capability = CapabilitiesFactory.eINSTANCE
277
		Capability capability = CapabilitiesFactory.eINSTANCE
277
		.createCapability();
278
			.createCapability();
278
	_capabilityDomain.setCapability(capability);
279
		_capabilityDomain.setCapability(capability);
279
	Definition wsdlDefinition = null;	
280
		Definition wsdlDefinition = null;	
280
	if(getEditorInput() instanceof IFileEditorInput)
281
		if(getEditorInput() instanceof IFileEditorInput)
281
	{
282
		{
282
		IFileEditorInput modelFileInput = (IFileEditorInput) getEditorInput();
283
			IFileEditorInput modelFileInput = (IFileEditorInput) getEditorInput();
283
		IFile capabilityFile = modelFileInput.getFile();
284
			IFile capabilityFile = modelFileInput.getFile();
284
		try {
285
			_capabilityDomain.setCapabilityIFile(capabilityFile);
285
			wsdlDefinition = WsdlUtils.getWSDLDefinition(capabilityFile);
286
			try 
286
		} catch (Exception e) {
287
			{
287
			WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_,e);
288
				wsdlDefinition = WsdlUtils.getWSDLDefinition(capabilityFile);
288
			    return;
289
			} 
289
		}
290
			catch (Exception e) 
290
	}
291
			{
291
	else if(getEditorInput() instanceof IStorageEditorInput)
292
				WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_,e);
292
	{
293
				    return;
293
		IStorageEditorInput input = (IStorageEditorInput)getEditorInput();
294
			}
294
		IStorage storage = null;
295
		}
295
		try {
296
		else if(getEditorInput() instanceof IStorageEditorInput)
296
			storage = input.getStorage();
297
		{
297
			_read_only = storage.isReadOnly();
298
			IStorageEditorInput input = (IStorageEditorInput)getEditorInput();
298
		} catch (CoreException e1) {
299
			IStorage storage = null;
299
			e1.printStackTrace();
300
			try 
300
		}
301
			{
301
		URI capFileURI = URI.createURI(storage.getFullPath().toString());		
302
				storage = input.getStorage();
302
		try {
303
				_read_only = storage.isReadOnly();
303
			wsdlDefinition = WsdlUtils.getWSDLDefinition(capFileURI);
304
			}
304
		} catch (Exception e) {
305
			catch (CoreException e1)
305
			WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_,e);
306
			{
306
			    return;
307
				e1.printStackTrace();
307
		}
308
			}
308
	}
309
			URI capFileURI = URI.createURI(storage.getFullPath().toString());		
309
	else
310
			try
310
		return;
311
			{
312
				wsdlDefinition = WsdlUtils.getWSDLDefinition(capFileURI);
313
			} 
314
			catch (Exception e) 
315
			{
316
				WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_,e);
317
				    return;
318
			}
319
		}
320
		else
321
			return;
322
		
323
		_capabilityDomain.getCapability().setDefinition(wsdlDefinition);
324
		
325
		Map metadataMap = WsdlUtils.getMetadataFromPortType(wsdlDefinition);
326
		String resourceProperties = (String) metadataMap
327
			.get(WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
328
		if (resourceProperties != null)
329
		{
330
		    XSDElementDeclaration resourcePropertyElement = WsdlUtils
331
			    .getResourcePropertyElement(wsdlDefinition,
332
				    resourceProperties);
333
		    _capabilityDomain
334
			    .setResourcePropertyElement(resourcePropertyElement);
335
		    List xsdSchemas = CapUtils.getPropertiesSchemas(wsdlDefinition,
336
			    resourcePropertyElement);
311
	
337
	
312
	_capabilityDomain.setDefinition(wsdlDefinition);
338
		    {
339
				// Extract the proper properties schema for capability
340
				XSDSchema tnsSchema = WsdlUtils.getSchema(wsdlDefinition,
341
					resourcePropertyElement.getSchema()
342
						.getTargetNamespace());
343
				XSDInclude include = XsdUtils.getFirstXSDInclude(tnsSchema);
344
				if (include != null)
345
				    _capabilityDomain.setPropertySchema(include
346
					    .getResolvedSchema());
347
				else if (xsdSchemas.size() != 0)
348
				{
349
				    XSDSchema propSchema = (XSDSchema) xsdSchemas.get(0);
350
				    _capabilityDomain.setPropertySchema(propSchema);
351
				}
352
		    }
313
	
353
	
314
	Map metadataMap = WsdlUtils.getMetadataFromPortType(wsdlDefinition);
354
		    for (int i = 0; i < xsdSchemas.size(); i++)
315
	String resourceProperties = (String) metadataMap
355
		    {
316
		.get(WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
356
				XSDSchema schema = (XSDSchema) xsdSchemas.get(i);
317
	if (resourceProperties != null)
357
				_capabilityDomain.addPropertySchema(schema);
318
	{
358
		    }
319
	    XSDElementDeclaration resourcePropertyElement = WsdlUtils
359
		}
320
		    .getResourcePropertyElement(wsdlDefinition,
360
	
321
			    resourceProperties);
361
		String metadataDescriptorLocation = (String) metadataMap
322
	    _capabilityDomain
362
			.get(WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
323
		    .setResourcePropertyElement(resourcePropertyElement);
363
		String metadataDescriptorName = (String) metadataMap
324
	    List xsdSchemas = CapUtils.getPropertiesSchemas(wsdlDefinition,
364
			.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
325
		    resourcePropertyElement);
365
		DocumentRoot rmdRoot = null;
326
366
		if (metadataDescriptorLocation != null
327
	    {
367
			&& metadataDescriptorName != null)
328
		// Extract the proper properties schema for capability
368
		{
329
		XSDSchema tnsSchema = WsdlUtils.getSchema(wsdlDefinition,
369
		    
330
			resourcePropertyElement.getSchema()
370
			String rmdFileLocation = _capabilityDomain.getCapability().getDefinition().eResource().getURI().trimSegments(1)+"/" + metadataDescriptorLocation;
331
				.getTargetNamespace());
371
			rmdRoot = MetaDataUtils.getDocumentRoot(URI.createURI(rmdFileLocation));
332
		XSDInclude include = XsdUtils.getFirstXSDInclude(tnsSchema);
372
			if(rmdRoot!=null)
333
		if (include != null)
373
				if(_capabilityDomain.getCapability().getMetadata()!=null)
334
		    _capabilityDomain.setPropertySchema(include
374
					_capabilityDomain.getCapability().getMetadata().setDocumentRoot(rmdRoot);			
335
			    .getResolvedSchema());
375
		}
336
		else if (xsdSchemas.size() != 0)
376
	
337
		{
377
		Definition definition = _capabilityDomain.getCapability().getDefinition();
338
		    XSDSchema propSchema = (XSDSchema) xsdSchemas.get(0);
378
		XSDSchema propSchema = _capabilityDomain.getPropertySchema();	
339
		    _capabilityDomain.setPropertySchema(propSchema);
379
		buildModel(definition, propSchema, rmdRoot);
340
		}
341
	    }
342
343
	    for (int i = 0; i < xsdSchemas.size(); i++)
344
	    {
345
		XSDSchema schema = (XSDSchema) xsdSchemas.get(i);
346
		_capabilityDomain.addPropertySchema(schema);
347
	    }
348
	}
349
350
	String metadataDescriptorLocation = (String) metadataMap
351
		.get(WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
352
	String metadataDescriptorName = (String) metadataMap
353
		.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
354
	DocumentRoot rmdRoot = null;
355
	if (metadataDescriptorLocation != null
356
		&& metadataDescriptorName != null)
357
	{
358
	    
359
		String rmdFileLocation = _capabilityDomain.getDefinition().eResource().getURI().trimSegments(1)+"/" + metadataDescriptorLocation;
360
		rmdRoot = MetaDataUtils.getDocumentRoot(URI.createURI(rmdFileLocation));
361
		if(rmdRoot!=null)
362
			if(_capabilityDomain.getMetaDataDescriptor()!=null)
363
				_capabilityDomain.getMetaDataDescriptor().setDocumentRoot(rmdRoot);			
364
	}
365
366
	Definition definition = _capabilityDomain.getDefinition();
367
	XSDSchema propSchema = _capabilityDomain.getPropertySchema();	
368
	buildModel(definition, propSchema, rmdRoot);
369
    }
380
    }
370
381
371
    private void buildModel(Definition definition, XSDSchema propSchema,
382
    private void buildModel(Definition definition, XSDSchema propSchema,
372
	    DocumentRoot rmdRoot)
383
	    DocumentRoot rmdRoot)
373
    {
384
    {
374
	_capabilityDomain.setDefinition(definition);
385
		_capabilityDomain.getCapability().setDefinition(definition);
375
	_capabilityDomain.setPropertySchema(propSchema);
386
		_capabilityDomain.setPropertySchema(propSchema);
376
	if(rmdRoot!=null)
387
		if(rmdRoot!=null)
377
		if(_capabilityDomain.getMetaDataDescriptor()!=null)
388
			if(_capabilityDomain.getCapability().getMetadata()!=null)
378
			_capabilityDomain.getMetaDataDescriptor().setDocumentRoot(rmdRoot);
389
				_capabilityDomain.getCapability().getMetadata().setDocumentRoot(rmdRoot);
379
390
	
380
	populateCapabilityInfo();
391
		populateCapabilityInfo();
381
392
	
382
	Map metadataMap = WsdlUtils.getMetadataFromPortType(definition);
393
		Map metadataMap = WsdlUtils.getMetadataFromPortType(definition);
383
	String resourceProperties = (String) metadataMap
394
		String resourceProperties = (String) metadataMap
384
		.get(WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
395
			.get(WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
385
	if (resourceProperties != null)
396
		if (resourceProperties != null)
386
	{
397
		{
387
	    XSDElementDeclaration resourcePropertyElement = WsdlUtils
398
		    XSDElementDeclaration resourcePropertyElement = WsdlUtils
388
		    .getResourcePropertyElement(definition, resourceProperties);
399
			    .getResourcePropertyElement(definition, resourceProperties);
389
	    _capabilityDomain
400
		    _capabilityDomain
390
		    .setResourcePropertyElement(resourcePropertyElement);
401
			    .setResourcePropertyElement(resourcePropertyElement);
391
	    createXSDModel();
402
		    createXSDModel();
392
	}
403
		}
393
	else
404
		else
394
	{
405
		{
395
	    _capabilityDomain.setResourcePropertyElement(null);
406
		    _capabilityDomain.setResourcePropertyElement(null);
396
	}
407
		}
397
408
	
398
	String metadataDescriptorName = (String) metadataMap
409
		String metadataDescriptorName = (String) metadataMap
399
		.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
410
			.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
400
	if (rmdRoot != null)
411
		if (rmdRoot != null)
401
	{
412
		{
402
	    populatePropertiesMetaData(rmdRoot, metadataDescriptorName);
413
		    populatePropertiesMetaData(rmdRoot, metadataDescriptorName);
403
	    populateCapabilityTopics();
414
		    populateCapabilityTopics();
404
	}
415
		}
405
416
	
406
	populateCapabilityOperations();
417
		populateCapabilityOperations();
407
    }
418
    }
408
419
409
    private void populateCapabilityInfo()
420
    private void populateCapabilityInfo()
410
    {
421
    {
411
	Definition wsdlDefinition = _capabilityDomain.getDefinition();
422
		Capability capability = _capabilityDomain.getCapability();
412
	Capability capability = _capabilityDomain.getCapability();
423
		Definition wsdlDefinition = capability.getDefinition();
413
	QName qname = wsdlDefinition.getQName();
424
		QName qname = wsdlDefinition.getQName();
414
	String localPart = qname.getLocalPart();
425
		String localPart = qname.getLocalPart();
415
	String ns = wsdlDefinition.getTargetNamespace();
426
		String ns = wsdlDefinition.getTargetNamespace();
416
	String prefix = wsdlDefinition.getPrefix(ns);
427
		String prefix = wsdlDefinition.getPrefix(ns);
417
	Text node = CapUtils.getDescriptionNode(wsdlDefinition);
428
		Text node = CapUtils.getDescriptionNode(wsdlDefinition);
418
	String description = "";
429
		String description = "";
419
	if (node != null)
430
		if (node != null)
420
	{
431
		{
421
	    description = node.getData();
432
		    description = node.getData();
422
	    _capabilityDomain.setDescriptionNode(node);
433
		    _capabilityDomain.setDescriptionNode(node);
423
	}
434
		}
424
	capability.setNamespace(ns);
435
		capability.setNamespace(ns);
425
	capability.setPrefix(prefix);
436
		capability.setPrefix(prefix);
426
	capability.setName(localPart);
437
		capability.setName(localPart);
427
	capability.setDescription(description);
438
		capability.setDescription(description);
428
    }
439
    }
429
440
430
    private void createXSDModel()
441
    private void createXSDModel()
431
    {
442
    {
432
	Definition definition = _capabilityDomain.getDefinition();
443
	    Capability capability = _capabilityDomain.getCapability();
433
	XSDElementDeclaration resourcePropertyElement = _capabilityDomain
444
	    Definition definition = capability.getDefinition();
434
		.getResourcePropertyElement();
445
		XSDElementDeclaration resourcePropertyElement = _capabilityDomain
435
	XSDElementDeclaration[] elements = CapUtils.getResolvedProperties(
446
			.getResourcePropertyElement();
436
		definition, resourcePropertyElement);
447
		XSDElementDeclaration[] elements = CapUtils.getResolvedProperties(
437
	Capability capability = _capabilityDomain.getCapability();
448
			definition, resourcePropertyElement);	
438
	capability.getProperties().clear();
449
		capability.getProperties().clear();
439
	for (int i = 0; i < elements.length; i++)
450
		for (int i = 0; i < elements.length; i++)
440
	{
451
		{
441
	    Property property = CapabilitiesFactory.eINSTANCE.createProperty();
452
		    Property property = CapabilitiesFactory.eINSTANCE.createProperty();
442
	    property.setElement(elements[i]);
453
		    property.setElement(elements[i]);
443
	    capability.getProperties().add(property);
454
		    capability.getProperties().add(property);
444
	}
455
		}
445
    }
456
    }
446
457
447
    private void populatePropertiesMetaData(DocumentRoot root,
458
    private void populatePropertiesMetaData(DocumentRoot root,
448
	    String metadataDescriptorName)
459
	    String metadataDescriptorName)
449
    {
460
    {
450
	Capability capability = _capabilityDomain.getCapability();
461
		Capability capability = _capabilityDomain.getCapability();
451
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = new PropertyMetaDataDescriptor(
462
		// TODO Check this out
452
		root, capability, metadataDescriptorName);
463
		MetadataDescriptor propertyMetaDataDescriptor = new MetadataDescriptor(capability, root, metadataDescriptorName);
453
	_capabilityDomain.setMetaDataDescriptor(propertyMetaDataDescriptor);
464
		PropertyType[] propertyType = propertyMetaDataDescriptor
454
	PropertyType[] propertyType = propertyMetaDataDescriptor
465
			.getPropertyTypes();
455
		.getPropertyTypes();
466
		for (int i = 0; i < propertyType.length; i++)
456
	for (int i = 0; i < propertyType.length; i++)
467
		{
457
	{
468
		    String propName = propertyType[i].getName();
458
	    String propertyName = ((org.eclipse.emf.ecore.xml.type.internal.QName) propertyType[i]
469
		    String prefix = extractPrefix(propName);
459
		    .getName()).getLocalPart();
470
		    String localName = extractName(propName);
460
	    String namespace = ((org.eclipse.emf.ecore.xml.type.internal.QName) propertyType[i]
471
		    String namespace = propertyMetaDataDescriptor.getNamespace(prefix);
461
		    .getName()).getNamespaceURI();
472
			Property property = CapUtils.getProperty(capability, namespace, localName);
462
	    Property property = CapUtils.getProperty(capability, namespace,
473
		    if (property != null)
463
		    propertyName);
474
		    {
464
	    if (property != null)
475
		    	property.setMetaData(propertyType[i]);
465
		property.setMetaData(propertyType[i]);
476
		    	Metrics metrics = propertyMetaDataDescriptor.getMetrics(propertyType[i]);
466
	}
477
		    	property.setMetrics(metrics);
478
		    }	    	
479
		}
480
    }
481
    
482
    private String extractPrefix(String str)
483
    {
484
    	if(str == null || str.trim().equals("") || str.indexOf(':') == -1)
485
    		return null;
486
    	return str.substring(0,str.indexOf(':'));   	
487
    }
488
    
489
    private String extractName(String str)
490
    {
491
    	if(str == null || str.trim().equals("") || str.indexOf(':') == -1)
492
    		return null;
493
    	return str.substring(str.indexOf(':')+1);    	
467
    }
494
    }
468
495
469
    private void populateCapabilityTopics()
496
    private void populateCapabilityTopics()
470
    {
497
    {
471
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = _capabilityDomain
498
		Capability capability = _capabilityDomain.getCapability();
472
		.getMetaDataDescriptor();
499
		MetadataDescriptor propertyMetaDataDescriptor = capability.getMetadata();	
473
	Capability capability = _capabilityDomain.getCapability();
500
		propertyMetaDataDescriptor.loadTopicSpaces();
474
	List topicSpaces = propertyMetaDataDescriptor.getTopicSpaces();
475
	capability.getTopicSpaces().addAll(topicSpaces);
476
    }
501
    }
477
502
478
    private void populateCapabilityOperations()
503
    private void populateCapabilityOperations()
479
    {
504
    {
480
	Definition wsdlDefinition = _capabilityDomain.getDefinition();
505
	    Capability capability = _capabilityDomain.getCapability();
481
	Capability capability = _capabilityDomain.getCapability();
506
	    Definition wsdlDefinition = capability.getDefinition();	
482
	Operation[] operations = WsdlUtils.getWSDLOperation(wsdlDefinition);
507
		Operation[] operations = WsdlUtils.getWSDLOperation(wsdlDefinition);
483
	capability.getOperations().clear();
508
		capability.getOperations().clear();
484
	for (int i = 0; i < operations.length; i++)
509
		for (int i = 0; i < operations.length; i++)
485
	    capability.getOperations().add(operations[i]);
510
		    capability.getOperations().add(operations[i]);
486
    }
511
    }
487
512
488
    /**
513
    /**
Lines 491-497 Link Here
491
         */
516
         */
492
    public void setDirty()
517
    public void setDirty()
493
    {
518
    {
494
	firePropertyChange(IEditorPart.PROP_DIRTY);
519
    	firePropertyChange(IEditorPart.PROP_DIRTY);
495
    }
520
    }
496
521
497
    /**
522
    /**
Lines 499-505 Link Here
499
         */
524
         */
500
    public void setActivePage(int index)
525
    public void setActivePage(int index)
501
    {
526
    {
502
	super.setActivePage(index);
527
    	super.setActivePage(index);
503
    }
528
    }
504
529
505
    /**
530
    /**
Lines 510-516 Link Here
510
         */
535
         */
511
    public CapabilityDomain getCapabilityDomain()
536
    public CapabilityDomain getCapabilityDomain()
512
    {
537
    {
513
	return _capabilityDomain;
538
    	return _capabilityDomain;
514
    }
539
    }
515
540
516
    /**
541
    /**
Lines 518-535 Link Here
518
         */
543
         */
519
    protected void pageChange(int newPageIndex)
544
    protected void pageChange(int newPageIndex)
520
    {
545
    {
521
	for(int i=0;i<_pages.size();i++)
546
		for(int i=0;i<_pages.size();i++)
522
	{
547
		{
523
	    IPage page = (IPage) _pages.get(i);
548
		    IPage page = (IPage) _pages.get(i);
524
	    page.pageChange(newPageIndex);
549
		    page.pageChange(newPageIndex);
525
	}
550
		}
526
	if (newPageIndex == _wsdlSourcePageIndex)
551
		if (newPageIndex == _wsdlSourcePageIndex)
527
	    updateWSDLSourceFromForm();
552
		    updateWSDLSourceFromForm();
528
	else if (newPageIndex == _xsdSourcePageIndex)
553
		else if (newPageIndex == _xsdSourcePageIndex)
529
	    updateXSDSourceFromForm();
554
		    updateXSDSourceFromForm();
530
	else if (newPageIndex == _rmdSourcePageIndex)
555
		else if (newPageIndex == _rmdSourcePageIndex)
531
	    updateRMDSourceFromForm();
556
		    updateRMDSourceFromForm();
532
	super.pageChange(newPageIndex);
557
		super.pageChange(newPageIndex);
533
    }
558
    }
534
559
535
    /**
560
    /**
Lines 538-546 Link Here
538
    public void init(IEditorSite site, IEditorInput editorInput)
563
    public void init(IEditorSite site, IEditorInput editorInput)
539
	    throws PartInitException
564
	    throws PartInitException
540
    {
565
    {
541
	super.init(site, editorInput);
566
		super.init(site, editorInput);
542
	// Update titles.
567
		// Update titles.
543
	setPartName(editorInput.getName());
568
		setPartName(editorInput.getName());
544
    }
569
    }
545
    
570
    
546
    public boolean isReadOnly()
571
    public boolean isReadOnly()
Lines 610-618 Link Here
610
    	}
635
    	}
611
    	
636
    	
612
    	// Remove rmd file of capability
637
    	// Remove rmd file of capability
613
    	if(_capabilityDomain.getMetaDataDescriptor()!=null)
638
    	if(_capabilityDomain.getCapability().getMetadata()!=null)
614
    	{
639
    	{
615
    		PropertyMetaDataDescriptor metadataDescriptor = _capabilityDomain.getMetaDataDescriptor();
640
    		MetadataDescriptor metadataDescriptor = _capabilityDomain.getCapability().getMetadata();
616
    		if(metadataDescriptor.getDocumentRoot()!=null)
641
    		if(metadataDescriptor.getDocumentRoot()!=null)
617
    		{
642
    		{
618
    			DocumentRoot rmdRoot = metadataDescriptor.getDocumentRoot();
643
    			DocumentRoot rmdRoot = metadataDescriptor.getDocumentRoot();
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/util/internal/MetaDataUtils.java (-523 / +407 lines)
Lines 24-42 Link Here
24
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.emf.common.util.URI;
26
import org.eclipse.emf.common.util.URI;
27
import org.eclipse.emf.ecore.EStructuralFeature;
28
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
27
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
29
import org.eclipse.emf.ecore.resource.Resource;
28
import org.eclipse.emf.ecore.resource.Resource;
30
import org.eclipse.emf.ecore.resource.ResourceSet;
29
import org.eclipse.emf.ecore.resource.ResourceSet;
31
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
30
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
32
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
33
import org.eclipse.emf.ecore.util.FeatureMap;
31
import org.eclipse.emf.ecore.util.FeatureMap;
34
import org.eclipse.emf.ecore.xml.type.AnyType;
32
import org.eclipse.emf.ecore.xml.type.AnyType;
35
import org.eclipse.emf.ecore.xml.type.internal.XMLDuration;
36
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
33
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
37
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.FormMetric;
38
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
34
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
39
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
35
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
40
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DefinitionsType;
36
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DefinitionsType;
41
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
37
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
42
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorFactory;
38
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorFactory;
Lines 49-61 Link Here
49
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.ValidValuesType;
45
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.ValidValuesType;
50
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl;
46
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl;
51
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.util.MetadataDescriptorResourceImpl;
47
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.util.MetadataDescriptorResourceImpl;
52
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.ChangeTypeType;
53
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.GatheringTimeType;
54
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.TimeScopeType;
55
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
48
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
56
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
49
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
50
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
57
import org.eclipse.tptp.wsdm.tooling.util.internal.MyMetadataDescriptorResourceFactoryImpl;
51
import org.eclipse.tptp.wsdm.tooling.util.internal.MyMetadataDescriptorResourceFactoryImpl;
58
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
52
import org.eclipse.tptp.wsdm.tooling.util.internal.RmdUtils;
59
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
53
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
60
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
54
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
61
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
55
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
Lines 64-609 Link Here
64
58
65
/**
59
/**
66
 * 
60
 * 
67
 * Utility class to deal with metadata of Capability properties. 
61
 * Utility class to deal with metadata of Capability properties.
68
 *
62
 * 
69
 */
63
 */
70
64
71
public class MetaDataUtils
65
public class MetaDataUtils
72
{
66
{
73
67
74
    public static final String CONSTANT = "constant";
68
	public static final String CONSTANT = "constant";
75
69
76
    public static final String APPENDABLE = "appendable";
70
	public static final String APPENDABLE = "appendable";
77
71
78
    public static final String MUTABLE = "mutable";
72
	public static final String MUTABLE = "mutable";
79
73
80
    public static final String WRITABLE = "read-write";
74
	public static final String WRITABLE = "read-write";
81
75
82
    public static final String READ_ONLY = "read-only";
76
	public static final String READ_ONLY = "read-only";
83
77
84
    public static final String UNKNOWN = "unknown";
78
	public static final String UNKNOWN = "unknown";
85
79
86
    public static final String CHANGE_TYPE = "ChangeType";
80
	private static MetadataDescriptorFactory _rmdFactory = new MetadataDescriptorFactoryImpl();
87
81
88
    public static final String TIME_SCOPE = "TimeScope";
82
	/**
89
83
	 * Returns the modifiability of given PropertyType.
90
    public static final String GATHERING_TIME = "GatheringTime";
84
	 * 
91
85
	 * @param propertyMetaData
92
    public static final String CALCULATION_INTERVAL = "CalculationInterval";
86
	 *            PropertyType metadata.
93
87
	 * 
94
    private static MetadataDescriptorFactory _rmdFactory = new MetadataDescriptorFactoryImpl();
88
	 * @return the modifiability of given PropertyType metadata.
95
89
	 */
96
    /**
90
	public static String getModifiability(PropertyType propertyMetaData)
97
     * Returns the modifiability of given PropertyType.
91
	{
98
     * 
92
		if (propertyMetaData == null)
99
     * @param propertyMetaData
93
			return UNKNOWN;
100
     * 	      PropertyType metadata.
94
		if (propertyMetaData.getModifiability() == null)
101
     * 
95
			return UNKNOWN;
102
     * @return the modifiability of given PropertyType metadata.
96
		return propertyMetaData.getModifiability().getLiteral();
103
     */
97
	}
104
    public static String getModifiability(PropertyType propertyMetaData)
98
105
    {
99
	/**
106
	if (propertyMetaData == null)
100
	 * Returns the mutability of given PropertyType.
107
	    return UNKNOWN;
101
	 * 
108
	if (propertyMetaData.getModifiability() == null)
102
	 * @param propertyMetaData
109
	    return UNKNOWN;
103
	 *            PropertyType metadata.
110
	return propertyMetaData.getModifiability().getLiteral();
104
	 * 
111
    }
105
	 * @return the mutability of given PropertyType metadata.
112
106
	 */
113
    /**
107
	public static String getMutability(PropertyType propertyMetaData)
114
     * Returns the mutability of given PropertyType.
108
	{
115
     * 
109
		if (propertyMetaData == null)
116
     * @param propertyMetaData
110
			return UNKNOWN;
117
     * 	      PropertyType metadata.
111
		if (propertyMetaData.getMutability() == null)
118
     * 
112
			return UNKNOWN;
119
     * @return the mutability of given PropertyType metadata.
113
		return propertyMetaData.getMutability().getLiteral();
120
     */
114
	}
121
    public static String getMutability(PropertyType propertyMetaData)
115
122
    {
116
	/**
123
	if (propertyMetaData == null)
117
	 * Create new MetadataRoot object.
124
	    return UNKNOWN;
118
	 * 
125
	if (propertyMetaData.getMutability() == null)
119
	 * @param targetNamespace
126
	    return UNKNOWN;
120
	 *            TargetNamespace to be used for new MetadataRoot object.
127
	return propertyMetaData.getMutability().getLiteral();
121
	 * 
128
    }
122
	 * @param descriptorName
129
123
	 *            Name to be used for MetadataDescriptorType.
130
    /**
124
	 * 
131
     * Create new MetadataRoot object.
125
	 * @return new MetadataRoot object.
132
     * 
126
	 */
133
     * @param targetNamespace
127
	public static DocumentRoot createNewMetadataRoot(String targetNamespace,
134
     * 	      TargetNamespace to be used for new MetadataRoot object.
128
			String descriptorName, String capabilityPortType,
135
     * 
129
			String capabilityFileName)
136
     * @param descriptorName
130
	{
137
     *        Name to be used for MetadataDescriptorType.
131
		DocumentRoot dr = _rmdFactory.createDocumentRoot();
138
     *         
132
		DefinitionsType def = _rmdFactory.createDefinitionsType();
139
     * @return new MetadataRoot object.
133
		dr.getXMLNSPrefixMap().put("muws-p1", WsdmConstants.MUWS_P1_NS);
140
     */
134
		dr.getXMLNSPrefixMap().put("muws-p2", WsdmConstants.MUWS_P2_NS);
141
    public static DocumentRoot createNewMetadataRoot(String targetNamespace,
135
		dr.getXMLNSPrefixMap().put("tns", targetNamespace);
142
	    String descriptorName)
136
		def.setTargetNamespace(targetNamespace);
143
    {
137
		MetadataDescriptorType mdtVal = _rmdFactory
144
	DocumentRoot dr = _rmdFactory.createDocumentRoot();
138
				.createMetadataDescriptorType();
145
	DefinitionsType def = _rmdFactory.createDefinitionsType();
139
		mdtVal.setName(descriptorName);
146
	dr.getXMLNSPrefixMap().put("muws-p1", WsdmConstants.MUWS_P1_NS);
140
		mdtVal.setInterface("tns:" + capabilityPortType);
147
	dr.getXMLNSPrefixMap().put("muws-p2", WsdmConstants.MUWS_P2_NS);
141
		mdtVal.setWsdlLocation(targetNamespace + " " + capabilityFileName);
148
	dr.getXMLNSPrefixMap().put("tns", targetNamespace);
142
		def.getMetadataDescriptor().add(mdtVal);
149
	def.setTargetNamespace(targetNamespace);
143
		dr.setDefinitions(def);
150
	MetadataDescriptorType mdtVal = _rmdFactory
144
		return dr;
151
		.createMetadataDescriptorType();
145
	}
152
	mdtVal.setName(descriptorName);
146
153
	def.getMetadataDescriptor().add(mdtVal);
147
	/**
154
	dr.setDefinitions(def);
148
	 * Returns the MetadataDescriptorType inside given MetadataRoot object.
155
	return dr;
149
	 * 
156
    }
150
	 * @param root
157
151
	 *            Given MetadataRoot object.
158
    /**
152
	 * 
159
     * Returns the MetadataDescriptorType inside given MetadataRoot object.
153
	 * @param name
160
     * 
154
	 *            Name of MetadataDescriptorType to be searched.
161
     * @param root
155
	 * 
162
     *        Given MetadataRoot object.
156
	 * @return the MetadataDescriptorType object.
163
     *        
157
	 */
164
     * @param name
158
	public static MetadataDescriptorType getMetadataDescriptorType(
165
     *        Name of MetadataDescriptorType to be searched.
159
			DocumentRoot root, String name)
166
     *        
160
	{
167
     * @return the MetadataDescriptorType object.
161
		List metaDescriptors = root.getDefinitions().getMetadataDescriptor();
168
     */
162
		for (int i = 0; i < metaDescriptors.size(); i++)
169
    public static MetadataDescriptorType getMetadataDescriptorType(
163
		{
170
	    DocumentRoot root, String name)
164
			MetadataDescriptorType mdtVal = (MetadataDescriptorType) metaDescriptors
171
    {
165
					.get(i);
172
	List metaDescriptors = root.getDefinitions().getMetadataDescriptor();
166
			if (mdtVal.getName().equals(name))
173
	for (int i = 0; i < metaDescriptors.size(); i++)
167
				return mdtVal;
174
	{
175
	    MetadataDescriptorType mdtVal = (MetadataDescriptorType) metaDescriptors
176
		    .get(i);
177
	    if (mdtVal.getName().equals(name))
178
		return mdtVal;
179
	}
180
	return null;
181
    }
182
183
    /**
184
     * Returns ModifiabilityType based on parameter passed.<br>
185
     * Parameter should be one of the following<br><br>
186
     * 
187
     *  <b>MetaDataUtils.READ_ONLY</b><br>
188
     *  <b>MetaDataUtils.WRITABLE</b><br>
189
     *  
190
     */
191
    public static ModifiabilityType getModifiabilityType(String modifiability)
192
    {
193
	if (modifiability.equals(READ_ONLY))
194
	    return ModifiabilityType.READ_ONLY_LITERAL;
195
	else if (modifiability.equals(WRITABLE))
196
	    return ModifiabilityType.READ_WRITE_LITERAL;
197
	return ModifiabilityType.READ_ONLY_LITERAL;
198
    }
199
200
    /**
201
     * Returns MutabilityType based on parameter passed.<br>
202
     * Parameter should be one of the following<br><br>
203
     * 
204
     *  <b>MetaDataUtils.CONSTANT</b><br>
205
     *  <b>MetaDataUtils.MUTABLE</b><br>
206
     *  <b>MetaDataUtils.APPENDABLE</b><br>
207
     */
208
    public static MutabilityType getMutabilityType(String mutability)
209
    {
210
	if (mutability.equals(CONSTANT))
211
	    return MutabilityType.CONSTANT_LITERAL;
212
	else if (mutability.equals(MUTABLE))
213
	    return MutabilityType.MUTABLE_LITERAL;
214
	else if (mutability.equals(APPENDABLE))
215
	    return MutabilityType.APPENDABLE_LITERAL;
216
	return MutabilityType.MUTABLE_LITERAL;
217
    }
218
    
219
    /**
220
     * Returns ChangeTypeType based on parameter passed.<br>
221
     * Parameter should be one of the following<br><br>
222
     * 
223
     *  <b>"Counter"</b><br>
224
     *  <b>"Gauge"</b><br>
225
     *  <b>"Unknown"</b><br>
226
     */
227
    public static ChangeTypeType getChangeTypeType(String changeType)
228
    {
229
    	if(changeType.equals(ChangeTypeType.COUNTER_LITERAL.getLiteral()))
230
    		return ChangeTypeType.COUNTER_LITERAL;
231
    	else if(changeType.equals(ChangeTypeType.GAUGE_LITERAL.getLiteral()))
232
    		return ChangeTypeType.GAUGE_LITERAL;
233
    	return ChangeTypeType.UNKNOWN_LITERAL;
234
    }
235
    
236
    /**
237
     * Returns TimeScopeType based on parameter passed.<br>
238
     * Parameter should be one of the following<br><br>
239
     * 
240
     *  <b>"Interval"</b><br>
241
     *  <b>"PointInTime"</b><br>
242
     *  <b>"SinceReset"</b><br>
243
     */    
244
    public static TimeScopeType getTimeScopeType(String timeScope)
245
    {
246
    	if(timeScope.equals(TimeScopeType.INTERVAL_LITERAL.getLiteral()))
247
    		return TimeScopeType.INTERVAL_LITERAL;
248
    	else if(timeScope.equals(TimeScopeType.POINT_IN_TIME_LITERAL.getLiteral()))
249
    		return TimeScopeType.POINT_IN_TIME_LITERAL;
250
    	return TimeScopeType.SINCE_RESET_LITERAL;
251
    }
252
    
253
    /**
254
     * Returns GatheringTimeType based on parameter passed.<br>
255
     * Parameter should be one of the following<br><br>
256
     * 
257
     *  <b>"OnChange"</b><br>
258
     *  <b>"OnDemand"</b><br>
259
     *  <b>"Periodic"</b><br>
260
     *  <b>"Unknown"</b><br>
261
     */
262
    public static GatheringTimeType getGatheringTimeType(String gatheringTime)
263
    {
264
    	if(gatheringTime.equals(GatheringTimeType.ON_CHANGE_LITERAL.getLiteral()))
265
    		return GatheringTimeType.ON_CHANGE_LITERAL;
266
    	else if(gatheringTime.equals(GatheringTimeType.ON_DEMAND_LITERAL.getLiteral()))
267
    		return GatheringTimeType.ON_DEMAND_LITERAL;
268
    	else if(gatheringTime.equals(GatheringTimeType.PERIODIC_LITERAL.getLiteral()))
269
    		return GatheringTimeType.PERIODIC_LITERAL;
270
    	return GatheringTimeType.UNKNOWN_LITERAL;
271
    }
272
273
    /**
274
     * Saves an MetadataRoot object. into IFile in formatted representation.     
275
     * 
276
     * @param root
277
     *        MetadataRoot object to be saved.
278
     *        
279
     * @param rmdFile
280
     *        Eclipse file to which MetadataRoot object will be saved.
281
     *        
282
     * @param monitor
283
     *        Progress monitor.
284
     */
285
    public static void serializeAndFormat(DocumentRoot root, IFile rmdFile,
286
	    IProgressMonitor monitor)
287
    {
288
	String fileURI = rmdFile.getFullPath().toString();
289
	ByteArrayOutputStream baos = saveRMD(root, fileURI, null);
290
	String serializedString = CapUtils.getSerializedDocument(baos
291
		.toString());
292
	ByteArrayInputStream baInputStream = new ByteArrayInputStream(
293
		serializedString.getBytes());
294
	try
295
	{
296
	    if (rmdFile.exists())
297
		rmdFile.setContents(baInputStream, IFile.FORCE, monitor);
298
	    else
299
		rmdFile.create(baInputStream, IFile.FORCE, monitor);
300
	} catch (CoreException e)
301
	{
302
	    WsdmToolingLog.logError(Messages.FAILED_TO_SAVE_RMD_ERROR_, e);
303
	}
304
    }
305
306
    /**
307
     * Saves an MetadataRoot object into ResourceSet and returns the ByteArrayOutputStream of the saved object.
308
     * 
309
     * @param root
310
     * 	      MetadataRoot object to be saved.
311
     * 
312
     * @param fileURI
313
     *        URI String of the file to which MetadataRoot object will be saved.
314
     *        
315
     * @param resourceSet
316
     *        ResourceSet used for saving it, if null ResourceSet specified then the method
317
     *        will create new ResourceSet.
318
     *        
319
     * @return ByteArrayOutputStream representation of the saved object.
320
     */
321
    public static ByteArrayOutputStream saveRMD(DocumentRoot root,
322
	    String fileURI, ResourceSet resourceSet)
323
    {
324
	ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
325
	try
326
	{
327
	    if (resourceSet == null)
328
	    {
329
		resourceSet = new ResourceSetImpl();
330
	    }
331
	    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
332
		    .put(Resource.Factory.Registry.DEFAULT_EXTENSION,new MyMetadataDescriptorResourceFactoryImpl());
333
	    URI uri = URI.createPlatformResourceURI(fileURI);
334
	    Resource resource = resourceSet.createResource(uri);
335
	    resource.getContents().add(root);
336
337
	    // Save resource to the file system.
338
	    Map options = new HashMap();
339
	    options.put(MetadataDescriptorResourceImpl.OPTION_LINE_WIDTH, new Integer(30));
340
	    resource.save(baOutputStream, options);
341
	} catch (Exception exception)
342
	{
343
	    exception.printStackTrace();
344
	    WsdmToolingLog.logError(Messages.FAILED_TO_SAVE_RMD_ERROR_, exception);
345
	}
346
	return baOutputStream;
347
    }
348
349
    /**
350
     * Returns the EMF based MetadataRoot object of the given RMD file.
351
     * 
352
     * @param file
353
     * 	      Any RMD file available in eclipse workbench
354
     * 
355
     * @return EMF based MetadataRoot object.
356
     */ 
357
    public static DocumentRoot getDocumentRoot(IFile file)
358
    {
359
	URI rmdURI = URI.createPlatformResourceURI(file.getFullPath()
360
		.toString());
361
	return getDocumentRoot(rmdURI);
362
    }
363
364
    /**
365
     * Returns the EMF based MetadataRoot object of the given URI of any RMD file.
366
     * 
367
     * @param rmdURI
368
     * 	      URI of any RMD file available in eclipse workbench
369
     * 
370
     * @return EMF based MetadataRoot object. 
371
     */  
372
    public static DocumentRoot getDocumentRoot(URI rmdURI)
373
    {
374
	DocumentRoot dr = null;
375
	ResourceSet resourceSet = new ResourceSetImpl();
376
377
	resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
378
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
379
			new MyMetadataDescriptorResourceFactoryImpl());
380
	resourceSet.getPackageRegistry().put(MetadataDescriptorPackage.eNS_URI,
381
			MetadataDescriptorPackage.eINSTANCE);
382
383
	Resource resourceWsdl = null;
384
	try
385
	{
386
	    resourceWsdl = resourceSet.getResource(rmdURI, true);
387
	} catch (Exception ex)
388
	{
389
	    WsdmToolingLog.logError(Messages.FAILED_TO_LOAD_RMD_ERROR_, ex);
390
	    return null;
391
	}
392
	List list = resourceWsdl.getContents();
393
394
	for (int i = 0; i < list.size(); i++)
395
	{
396
	    Object o = list.get(i);
397
	    if (o instanceof DocumentRoot)
398
	    {
399
		dr = (DocumentRoot) o;
400
	    }
401
	}
402
	return dr;
403
    }
404
405
    /**
406
     * Returns the valid values of given ValidValuesType.
407
     * 
408
     * @param validValuesType
409
     *        ValidValuesType of property metadata.
410
     *        
411
     * @return the valid values.
412
     */
413
    public static Object[] getValidValues(ValidValuesType validValuesType)
414
    {
415
	List validValues = new LinkedList();
416
	if (validValuesType == null)
417
	{
418
	    return (Object[]) validValues.toArray(new Object[0]);
419
	}
420
421
	FeatureMap fm = validValuesType.getAny();
422
	Iterator it = fm.iterator();
423
	while (it.hasNext())
424
	{
425
	    Object obj = it.next();
426
	    if (obj instanceof EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)
427
	    {
428
		EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry entry = (EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry) obj;
429
		AnyType value = (AnyType) entry.getValue();
430
		FeatureMap mixedMap = value.getMixed();
431
		Iterator mixedIt = mixedMap.iterator();
432
		while (mixedIt.hasNext())
433
		{
434
		    EStructuralFeatureImpl.SimpleFeatureMapEntry simpleEntry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) mixedIt
435
			    .next();
436
		    validValues.add(simpleEntry.getValue());
437
		}
168
		}
438
	    }
169
		return null;
439
	}
170
	}
440
	return (Object[]) validValues.toArray(new Object[0]);
441
    }
442
171
443
    /**
172
	/**
444
     * Returns the static values of given StaticValuesType.
173
	 * Returns ModifiabilityType based on parameter passed.<br>
445
     * 
174
	 * Parameter should be one of the following<br>
446
     * @param staticValuesType
175
	 * <br>
447
     *        StaticValuesType of property metadata.
176
	 * 
448
     *        
177
	 * <b>MetaDataUtils.READ_ONLY</b><br>
449
     * @return the static values.
178
	 * <b>MetaDataUtils.WRITABLE</b><br>
450
     */
179
	 * 
451
    public static Object[] getStaticValues(StaticValuesType staticValuesType)
180
	 */
452
    {
181
	public static ModifiabilityType getModifiabilityType(String modifiability)
453
	List staticValues = new LinkedList();
182
	{
454
	if (staticValuesType == null)
183
		if (modifiability.equals(READ_ONLY))
455
	{
184
			return ModifiabilityType.READ_ONLY_LITERAL;
456
	    return (Object[]) staticValues.toArray(new Object[0]);
185
		else if (modifiability.equals(WRITABLE))
457
	}
186
			return ModifiabilityType.READ_WRITE_LITERAL;
458
187
		return ModifiabilityType.READ_ONLY_LITERAL;
459
	FeatureMap fm = staticValuesType.getAny();
188
	}
460
	Iterator it = fm.iterator();
189
461
	while (it.hasNext())
190
	/**
462
	{
191
	 * Returns MutabilityType based on parameter passed.<br>
463
	    Object obj = it.next();
192
	 * Parameter should be one of the following<br>
464
	    if (obj instanceof EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)
193
	 * <br>
465
	    {
194
	 * 
466
		EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry entry = (EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry) obj;
195
	 * <b>MetaDataUtils.CONSTANT</b><br>
467
		AnyType value = (AnyType) entry.getValue();
196
	 * <b>MetaDataUtils.MUTABLE</b><br>
468
		FeatureMap mixedMap = value.getMixed();
197
	 * <b>MetaDataUtils.APPENDABLE</b><br>
469
		Iterator mixedIt = mixedMap.iterator();
198
	 */
470
		while (mixedIt.hasNext())
199
	public static MutabilityType getMutabilityType(String mutability)
471
		{
200
	{
472
		    EStructuralFeatureImpl.SimpleFeatureMapEntry simpleEntry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) mixedIt
201
		if (mutability.equals(CONSTANT))
473
			    .next();
202
			return MutabilityType.CONSTANT_LITERAL;
474
		    staticValues.add(simpleEntry.getValue());
203
		else if (mutability.equals(MUTABLE))
204
			return MutabilityType.MUTABLE_LITERAL;
205
		else if (mutability.equals(APPENDABLE))
206
			return MutabilityType.APPENDABLE_LITERAL;
207
		return MutabilityType.MUTABLE_LITERAL;
208
	}
209
210
	/**
211
	 * Saves an MetadataRoot object. into IFile in formatted representation.
212
	 * 
213
	 * @param root
214
	 *            MetadataRoot object to be saved.
215
	 * 
216
	 * @param rmdFile
217
	 *            Eclipse file to which MetadataRoot object will be saved.
218
	 * 
219
	 * @param monitor
220
	 *            Progress monitor.
221
	 */
222
	public static void serializeAndFormat(DocumentRoot root, IFile rmdFile,
223
			IProgressMonitor monitor)
224
	{
225
		String fileURI = rmdFile.getFullPath().toString();
226
		ByteArrayOutputStream baos = saveRMD(root, fileURI, null);
227
		String serializedString = CapUtils.getSerializedDocument(baos
228
				.toString());
229
		ByteArrayInputStream baInputStream = new ByteArrayInputStream(
230
				serializedString.getBytes());
231
		try
232
		{
233
			if (rmdFile.exists())
234
				rmdFile.setContents(baInputStream, IFile.FORCE, monitor);
235
			else
236
				rmdFile.create(baInputStream, IFile.FORCE, monitor);
237
		} catch (CoreException e)
238
		{
239
			WsdmToolingLog.logError(Messages.FAILED_TO_SAVE_RMD_ERROR_, e);
475
		}
240
		}
476
	    }
477
	}
241
	}
478
	return (Object[]) staticValues.toArray(new Object[0]);
479
    }
480
242
481
    /**
243
	/**
482
     * Returns FormMetric of given property metadata.
244
	 * Saves an MetadataRoot object into ResourceSet and returns the
483
     */
245
	 * ByteArrayOutputStream of the saved object.
484
    public static FormMetric getMetric(CapabilityDomain capabilityDomain,
246
	 * 
485
	    Property _property)
247
	 * @param root
486
    {
248
	 *            MetadataRoot object to be saved.
487
	FormMetric metric = new FormMetric(capabilityDomain, _property);
249
	 * 
488
	if (_property.getMetaData() == null)
250
	 * @param fileURI
489
	    return metric;
251
	 *            URI String of the file to which MetadataRoot object will be
490
	FeatureMap fm = _property.getMetaData().getAny();
252
	 *            saved.
491
	Iterator it = fm.iterator();
253
	 * 
492
	while (it.hasNext())
254
	 * @param resourceSet
493
	{
255
	 *            ResourceSet used for saving it, if null ResourceSet specified
494
	    Object obj = it.next();
256
	 *            then the method will create new ResourceSet.
495
	    if (obj instanceof EStructuralFeatureImpl.SimpleFeatureMapEntry)
257
	 * 
496
	    {
258
	 * @return ByteArrayOutputStream representation of the saved object.
497
		EStructuralFeatureImpl.SimpleFeatureMapEntry entry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) obj;
259
	 */
498
		if(entry.getValue() instanceof ChangeTypeType)
260
	public static ByteArrayOutputStream saveRMD(DocumentRoot root,
261
			String fileURI, ResourceSet resourceSet)
262
	{
263
		ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
264
		try
499
		{
265
		{
500
			ChangeTypeType changeType = (ChangeTypeType)entry.getValue();
266
			if (resourceSet == null)
501
			metric.setChangeType(changeType);
267
			{
502
		}
268
				resourceSet = new ResourceSetImpl();
503
		if(entry.getValue() instanceof TimeScopeType)
269
			}
270
			resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
271
					.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
272
							new MyMetadataDescriptorResourceFactoryImpl());
273
			URI uri = URI.createPlatformResourceURI(fileURI);
274
			Resource resource = resourceSet.createResource(uri);
275
			resource.getContents().add(root);
276
277
			// Save resource to the file system.
278
			Map options = new HashMap();
279
			options.put(MetadataDescriptorResourceImpl.OPTION_LINE_WIDTH,
280
					new Integer(30));
281
			resource.save(baOutputStream, options);
282
		} catch (Exception exception)
504
		{
283
		{
505
			TimeScopeType timeScope = (TimeScopeType)entry.getValue();
284
			exception.printStackTrace();
506
			metric.setTimeScope(timeScope);
285
			WsdmToolingLog.logError(Messages.FAILED_TO_SAVE_RMD_ERROR_,
286
					exception);
507
		}
287
		}
508
		if(entry.getValue() instanceof GatheringTimeType)
288
		return baOutputStream;
289
	}
290
291
	/**
292
	 * Returns the EMF based MetadataRoot object of the given RMD file.
293
	 * 
294
	 * @param file
295
	 *            Any RMD file available in eclipse workbench
296
	 * 
297
	 * @return EMF based MetadataRoot object.
298
	 */
299
	public static DocumentRoot getDocumentRoot(IFile file)
300
	{
301
		URI rmdURI = URI.createPlatformResourceURI(file.getFullPath()
302
				.toString());
303
		return getDocumentRoot(rmdURI);
304
	}
305
306
	/**
307
	 * Returns the EMF based MetadataRoot object of the given URI of any RMD
308
	 * file.
309
	 * 
310
	 * @param rmdURI
311
	 *            URI of any RMD file available in eclipse workbench
312
	 * 
313
	 * @return EMF based MetadataRoot object.
314
	 */
315
	public static DocumentRoot getDocumentRoot(URI rmdURI)
316
	{
317
		DocumentRoot dr = null;
318
		ResourceSet resourceSet = new ResourceSetImpl();
319
320
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
321
				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
322
						new MyMetadataDescriptorResourceFactoryImpl());
323
		resourceSet.getPackageRegistry().put(MetadataDescriptorPackage.eNS_URI,
324
				MetadataDescriptorPackage.eINSTANCE);
325
326
		Resource resourceWsdl = null;
327
		try
328
		{
329
			resourceWsdl = resourceSet.getResource(rmdURI, true);
330
		} catch (Exception ex)
509
		{
331
		{
510
			GatheringTimeType gatheringTime = (GatheringTimeType)entry.getValue();
332
			WsdmToolingLog.logError(Messages.FAILED_TO_LOAD_RMD_ERROR_, ex);
511
			metric.setGatheringTime(gatheringTime);
333
			return null;
512
		}
334
		}
513
		if(entry.getValue() instanceof XMLDuration)
335
		List list = resourceWsdl.getContents();
336
337
		for (int i = 0; i < list.size(); i++)
514
		{
338
		{
515
			XMLDuration calculationInterval = (XMLDuration)entry.getValue();
339
			Object o = list.get(i);
516
			metric.setCalculationInterval(calculationInterval);
340
			if (o instanceof DocumentRoot)
341
			{
342
				dr = (DocumentRoot) o;
343
			}
517
		}
344
		}
518
	    }
345
		return dr;
519
	}
346
	}
520
	return metric;
521
    }
522
347
523
    private static boolean isKindOf(EStructuralFeature esf, String kind)
348
	/**
524
    {
349
	 * Returns the valid values of given ValidValuesType.
525
	BasicExtendedMetaData.EStructuralFeatureExtendedMetaData emd = ((EStructuralFeatureImpl) esf)
350
	 * 
526
		.getExtendedMetaData();
351
	 * @param validValuesType
527
	return emd.getNamespace().equals(WsdmConstants.MUWS_P2_NS)
352
	 *            ValidValuesType of property metadata.
528
		&& emd.getName().equals(kind);
353
	 * 
529
    }
354
	 * @return the valid values.
530
355
	 */
531
    /**
356
	public static Object[] getValidValues(ValidValuesType validValuesType)
532
     * Returns true if the property metadata has Metrics defined for it.
357
	{
533
     * 
358
		List validValues = new LinkedList();
534
     * @param metadata
359
		if (validValuesType == null)
535
     *        PropertyType metadata.
360
		{
536
     *        
361
			return (Object[]) validValues.toArray(new Object[0]);
537
     * @return true if the property metadata has Metrics defined for it.
362
		}
538
     */
363
539
    public static boolean hasMetricsCapability(PropertyType metadata)
364
		FeatureMap fm = validValuesType.getAny();
540
    {
365
		Iterator it = fm.iterator();
541
	FeatureMap fm = metadata.getAny();
366
		while (it.hasNext())
542
	Iterator it = fm.iterator();
367
		{
543
	while (it.hasNext())
368
			Object obj = it.next();
544
	{
369
			if (obj instanceof EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)
545
	    Object obj = it.next();
370
			{
546
	    if (obj instanceof EStructuralFeatureImpl.SimpleFeatureMapEntry)
371
				EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry entry = (EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry) obj;
547
	    {
372
				AnyType value = (AnyType) entry.getValue();
548
		EStructuralFeatureImpl.SimpleFeatureMapEntry entry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) obj;
373
				FeatureMap mixedMap = value.getMixed();
549
		EStructuralFeature esf = entry.getEStructuralFeature();
374
				Iterator mixedIt = mixedMap.iterator();
550
		if (isKindOf(esf, "Capability"))
375
				while (mixedIt.hasNext())
551
		{
376
				{
552
		    if(entry.getValue() instanceof String)
377
					EStructuralFeatureImpl.SimpleFeatureMapEntry simpleEntry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) mixedIt
553
		    	if(entry.getValue().equals(WsdmConstants.MUWS_METRICS_NS))
378
							.next();
554
		    		return true;			
379
					validValues.add(simpleEntry.getValue());
380
				}
381
			}
555
		}
382
		}
556
	    }
383
		return (Object[]) validValues.toArray(new Object[0]);
557
	}
384
	}
558
	return false;
559
    }
560
385
561
    /**
386
	/**
562
     * This method is used to create new PropertyMetaDataDescriptor. 
387
	 * Returns the static values of given StaticValuesType.
563
     * PropertyMetaDataDescriptor is a wrapper class for an RMD representation.
388
	 * 
564
     * This method will be called from different pieces of capability editor, 
389
	 * @param staticValuesType
565
     * when there is no metadata defined for any property. So If some one has property
390
	 *            StaticValuesType of property metadata.
566
     * defined for capability but no metadata defined for it, this method will be used to create
391
	 * 
567
     * new PropertyMetaDataDescriptor for CapabilityDomain.
392
	 * @return the static values.
568
     * 
393
	 */
569
     * @param capabilityDomain
394
	public static Object[] getStaticValues(StaticValuesType staticValuesType)
570
     *        Capability editor based CapabilityDomain.
395
	{
571
     *        
396
		List staticValues = new LinkedList();
572
     * @return new PropertyMetaDataDescriptor created.
397
		if (staticValuesType == null)
573
     */
398
		{
574
    public static PropertyMetaDataDescriptor createMetaDataDescriptor(
399
			return (Object[]) staticValues.toArray(new Object[0]);
575
	    CapabilityDomain capabilityDomain)
400
		}
576
    {
401
577
	Capability capability = capabilityDomain.getCapability();
402
		FeatureMap fm = staticValuesType.getAny();
578
403
		Iterator it = fm.iterator();
579
	String targetNamespace = capabilityDomain.getDefinition()
404
		while (it.hasNext())
580
		.getTargetNamespace();
405
		{
581
	if (capabilityDomain.getPropertySchema() != null)
406
			Object obj = it.next();
582
	    targetNamespace = capabilityDomain.getPropertySchema()
407
			if (obj instanceof EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)
583
		    .getTargetNamespace();
408
			{
584
409
				EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry entry = (EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry) obj;
585
	String descriptorName = capability.getName() + "Descriptor";
410
				AnyType value = (AnyType) entry.getValue();
586
	DocumentRoot root = MetaDataUtils.createNewMetadataRoot(
411
				FeatureMap mixedMap = value.getMixed();
587
		targetNamespace, descriptorName);
412
				Iterator mixedIt = mixedMap.iterator();
588
	MetadataDescriptorType mdtVal = MetaDataUtils
413
				while (mixedIt.hasNext())
589
		.getMetadataDescriptorType(root, descriptorName);
414
				{
590
	PropertyMetaDataDescriptor metaDataDescriptor = new PropertyMetaDataDescriptor(
415
					EStructuralFeatureImpl.SimpleFeatureMapEntry simpleEntry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) mixedIt
591
		root, capability, descriptorName);
416
							.next();
592
	metaDataDescriptor.setDocumentRoot(root);
417
					staticValues.add(simpleEntry.getValue());
593
	metaDataDescriptor.setMetadataDescriptorType(mdtVal);
418
				}
594
	capabilityDomain.setMetaDataDescriptor(metaDataDescriptor);
419
			}
595
420
		}
596
	Definition definition = capabilityDomain.getDefinition();
421
		return (Object[]) staticValues.toArray(new Object[0]);
597
	String wsrmdPrefix = WsdlUtils.createOrFindPrefix(definition,
422
	}
598
		WsdmConstants.WSRMD_NS, "wsrmd");
599
	PortType pt = WsdlUtils.getPortType(definition);
600
	pt.getElement().setAttributeNS(WsdmConstants.WSRMD_NS,
601
		wsrmdPrefix + ":" + WsdlUtils.METADATA_DESCRIPTOR_KEY,
602
		descriptorName);
603
	pt.getElement().setAttributeNS(WsdmConstants.WSRMD_NS,
604
		wsrmdPrefix + ":" + WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY,
605
		capability.getName() + ".rmd");
606
423
607
	return metaDataDescriptor;
424
	/**
608
    }
425
	 * This method is used to create new PropertyMetaDataDescriptor.
426
	 * PropertyMetaDataDescriptor is a wrapper class for an RMD representation.
427
	 * This method will be called from different pieces of capability editor,
428
	 * when there is no metadata defined for any property. So If some one has
429
	 * property defined for capability but no metadata defined for it, this
430
	 * method will be used to create new PropertyMetaDataDescriptor for
431
	 * CapabilityDomain.
432
	 * 
433
	 * @param capabilityDomain
434
	 *            Capability editor based CapabilityDomain.
435
	 * 
436
	 * @return new PropertyMetaDataDescriptor created.
437
	 */
438
	public static MetadataDescriptor createMetaDataDescriptor(
439
			CapabilityDomain capabilityDomain)
440
	{
441
		Capability capability = capabilityDomain.getCapability();
442
443
		String targetNamespace = capability.getDefinition()
444
				.getTargetNamespace();
445
		if (capabilityDomain.getPropertySchema() != null)
446
			targetNamespace = capabilityDomain.getPropertySchema()
447
					.getTargetNamespace();
448
449
		String descriptorName = capability.getName() + "Descriptor";
450
		String capabilityPortType = WsdlUtils.getPortType(
451
				capability.getDefinition()).getQName().getLocalPart();
452
		String capabilityFileName = capabilityDomain.getCapabilityIFile()
453
				.getName();
454
		DocumentRoot root = MetaDataUtils.createNewMetadataRoot(
455
				targetNamespace, descriptorName, capabilityPortType,
456
				capabilityFileName);
457
		MetadataDescriptorType mdtVal = MetaDataUtils
458
				.getMetadataDescriptorType(root, descriptorName);
459
		MetadataDescriptor metaDataDescriptor = new MetadataDescriptor(
460
				capability, root, descriptorName);
461
		metaDataDescriptor.setDocumentRoot(root);
462
		metaDataDescriptor.setMetadataDescriptorType(mdtVal);
463
464
		Definition definition = capability.getDefinition();
465
		String wsrmdPrefix = WsdlUtils.createOrFindPrefix(definition,
466
				WsdmConstants.WSRMD_NS, "wsrmd");
467
		PortType pt = WsdlUtils.getPortType(definition);
468
		pt.getElement().setAttributeNS(WsdmConstants.WSRMD_NS,
469
				wsrmdPrefix + ":" + WsdlUtils.METADATA_DESCRIPTOR_KEY,
470
				descriptorName);
471
		pt.getElement().setAttributeNS(WsdmConstants.WSRMD_NS,
472
				wsrmdPrefix + ":" + WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY,
473
				capability.getName() + ".rmd");
474
475
		return metaDataDescriptor;
476
	}
477
478
	public static void save(MetadataDescriptor metadataDescriptor,
479
			IProgressMonitor monitor)
480
	{
481
		DocumentRoot _root = metadataDescriptor.getDocumentRoot();
482
		String rmdFileUri = _root.eResource().getURI().toString();
483
		IFile rmdFile = null;
484
		try
485
		{
486
			rmdFile = EclipseUtils.getIFile(rmdFileUri);
487
		} catch (CoreException e)
488
		{
489
			e.printStackTrace();
490
		}
491
		RmdUtils.serializeAndFormat(_root, rmdFile, monitor);
492
	}
609
}
493
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/property/internal/ChangePropertyNameMetaDataCommand.java (-13 / +11 lines)
Lines 12-21 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal;
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal;
14
14
15
import org.eclipse.emf.ecore.xml.type.internal.QName;
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
15
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
16
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
18
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
19
18
20
/**
19
/**
21
 * Command class to change the name of a property inside RMD.<br>
20
 * Command class to change the name of a property inside RMD.<br>
Lines 34-41 Link Here
34
    public ChangePropertyNameMetaDataCommand(CapabilityDomain capabilityDomain,
33
    public ChangePropertyNameMetaDataCommand(CapabilityDomain capabilityDomain,
35
	    Property property, String newName)
34
	    Property property, String newName)
36
    {
35
    {
37
	super(capabilityDomain, property);
36
		super(capabilityDomain, property);
38
	_newName = newName;
37
		_newName = newName;
39
    }
38
    }
40
39
41
    /**
40
    /**
Lines 43-57 Link Here
43
     */
42
     */
44
    public void execute()
43
    public void execute()
45
    {
44
    {
46
	PropertyMetaDataDescriptor metaDataDescriptor = _capabilityDomain
45
		MetadataDescriptor metaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
47
		.getMetaDataDescriptor();
46
		if (metaDataDescriptor == null)
48
	if (metaDataDescriptor == null)
47
		    return;
49
	    return;
48
		if (_metadata == null)
50
	if (_metadata == null)
49
		    return;
51
	    return;
50
		String ns = _property.getElement().getTargetNamespace();
52
	String ns = _property.getElement().getTargetNamespace();
51
		String prefix = metaDataDescriptor.getPrefix(ns);
53
	String prefix = metaDataDescriptor.getPrefix(ns);
52
		_metadata.setName(prefix+":"+_newName);
54
	_metadata.setName(new QName(ns, _newName, prefix));
55
    }
53
    }
56
54
57
}
55
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/property/internal/RemovePropertyCommand.java (-43 / +42 lines)
Lines 15-22 Link Here
15
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
15
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
16
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
16
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
18
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
19
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
19
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
21
import org.eclipse.xsd.XSDComplexTypeDefinition;
21
import org.eclipse.xsd.XSDComplexTypeDefinition;
22
import org.eclipse.xsd.XSDElementDeclaration;
22
import org.eclipse.xsd.XSDElementDeclaration;
Lines 52-62 Link Here
52
    public RemovePropertyCommand(CapabilityDomain capabilityDomain,
52
    public RemovePropertyCommand(CapabilityDomain capabilityDomain,
53
	    Property property)
53
	    Property property)
54
    {
54
    {
55
	_capabilityDomain = capabilityDomain;
55
		_capabilityDomain = capabilityDomain;
56
	_resourcePropertyElement = capabilityDomain
56
		_resourcePropertyElement = capabilityDomain
57
		.getResourcePropertyElement();
57
			.getResourcePropertyElement();
58
	_property = property;
58
		_property = property;
59
	_element = property.getElement();
59
		_element = property.getElement();
60
    }
60
    }
61
61
62
    /**
62
    /**
Lines 64-124 Link Here
64
     */
64
     */
65
    public void execute()
65
    public void execute()
66
    {
66
    {
67
	removeFromResourcePropertyElement();
67
		removeFromResourcePropertyElement();
68
	removeFromSchema();
68
		removeFromSchema();
69
	removeMetadata();
69
		removeMetadata();
70
	removeFromCapability();
70
		removeFromCapability();
71
    }
71
    }
72
72
73
    private void removeFromResourcePropertyElement()
73
    private void removeFromResourcePropertyElement()
74
    {
74
    {
75
	XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) _resourcePropertyElement
75
		XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) _resourcePropertyElement
76
		.getAnonymousTypeDefinition();
76
			.getAnonymousTypeDefinition();
77
	XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
77
		XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
78
	XSDElementDeclaration[] elementRefs = XsdUtils
78
		XSDElementDeclaration[] elementRefs = XsdUtils
79
		.getElementDeclarations(modelGroup);
79
			.getElementDeclarations(modelGroup);
80
	for (int i = 0; i < elementRefs.length; i++)
80
		for (int i = 0; i < elementRefs.length; i++)
81
	{
82
	    if (XsdUtils.isReferencedElement(elementRefs[i]))
83
	    {
84
		XSDElementDeclaration schemaElement = elementRefs[i]
85
			.getResolvedElementDeclaration();
86
		if (schemaElement.getName().equals(_element.getName())
87
			&& schemaElement.getTargetNamespace().equals(
88
				_element.getTargetNamespace()))
89
		{
81
		{
90
		    XsdUtils.removeElementDeclaration(modelGroup,
82
		    if (XsdUtils.isReferencedElement(elementRefs[i]))
91
			    elementRefs[i]);
83
		    {
92
		    if (elementRefs.length == 1)
84
				XSDElementDeclaration schemaElement = elementRefs[i]
93
			_resourcePropertyElement
85
					.getResolvedElementDeclaration();
94
				.setAnonymousTypeDefinition(null);
86
				if (schemaElement.getName().equals(_element.getName())
87
					&& schemaElement.getTargetNamespace().equals(
88
						_element.getTargetNamespace()))
89
				{
90
				    XsdUtils.removeElementDeclaration(modelGroup,
91
					    elementRefs[i]);
92
				    if (elementRefs.length == 1)
93
					_resourcePropertyElement
94
						.setAnonymousTypeDefinition(null);
95
				}
96
		    }
95
		}
97
		}
96
	    }
97
	}
98
98
99
    }
99
    }
100
100
101
    private void removeFromSchema()
101
    private void removeFromSchema()
102
    {
102
    {
103
	_element.getSchema().getContents().remove(_element);
103
    	_element.getSchema().getContents().remove(_element);
104
    }
104
    }
105
105
106
    private void removeFromCapability()
106
    private void removeFromCapability()
107
    {
107
    {
108
	Capability capability = _capabilityDomain.getCapability();
108
		Capability capability = _capabilityDomain.getCapability();
109
	capability.getProperties().remove(_property);
109
		capability.getProperties().remove(_property);
110
    }
110
    }
111
111
112
    private void removeMetadata()
112
    private void removeMetadata()
113
    {
113
    {
114
	PropertyMetaDataDescriptor metaDataDescriptor = _capabilityDomain
114
		MetadataDescriptor metaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
115
		.getMetaDataDescriptor();
115
		if (metaDataDescriptor == null)
116
	if (metaDataDescriptor == null)
116
		    return;
117
	    return;
117
		PropertyType metadata = _property.getMetaData();
118
	PropertyType metadata = _property.getMetaData();
118
		if (metadata == null)
119
	if (metadata == null)
119
		    return;
120
	    return;
120
		metaDataDescriptor.getMetadataDescriptorType().getProperty().remove(
121
	metaDataDescriptor.getMetadataDescriptorType().getProperty().remove(
121
			metadata);
122
		metadata);
123
    }
122
    }
124
}
123
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/property/internal/AddPropertyCommand.java (-93 / +93 lines)
Lines 63-73 Link Here
63
    public AddPropertyCommand(CapabilityDomain capabilityDomain,
63
    public AddPropertyCommand(CapabilityDomain capabilityDomain,
64
	    XSDElementDeclaration newProperty)
64
	    XSDElementDeclaration newProperty)
65
    {
65
    {
66
	_capabilityDomain = capabilityDomain;
66
		_capabilityDomain = capabilityDomain;
67
	_newProperty = newProperty;
67
		_newProperty = newProperty;
68
	_resourcePropertyElement = _capabilityDomain
68
		_resourcePropertyElement = _capabilityDomain
69
		.getResourcePropertyElement();
69
			.getResourcePropertyElement();
70
	_propertySchema = _capabilityDomain.getPropertySchema();
70
		_propertySchema = _capabilityDomain.getPropertySchema();
71
    }
71
    }
72
72
73
    /**
73
    /**
Lines 75-200 Link Here
75
     */
75
     */
76
    public void execute()
76
    public void execute()
77
    {
77
    {
78
	addPropertyToSchema();
78
		addPropertyToSchema();
79
	addPropertyToResourceElement();
79
		addPropertyToResourceElement();
80
	addPropertyToCapability();
80
		addPropertyToCapability();
81
    }
81
    }
82
82
83
    private void addPropertyToSchema()
83
    private void addPropertyToSchema()
84
    {
84
    {
85
	_propertySchema.getContents().add(_newProperty);
85
    	_propertySchema.getContents().add(_newProperty);
86
    }
86
    }
87
87
88
    private void addPropertyToResourceElement()
88
    private void addPropertyToResourceElement()
89
    {
89
    {
90
90
91
	if (_resourcePropertyElement == null)
91
		if (_resourcePropertyElement == null)
92
	{
92
		{
93
	    // No Resource property element is defined for the capability
93
		    // No Resource property element is defined for the capability
94
	    // So create new XSD Include and create new Resource property element
94
		    // So create new XSD Include and create new Resource property element
95
		createNewResourcePropertyElement();	    
95
			createNewResourcePropertyElement();	    
96
	}
96
		}
97
97
	
98
	XSDModelGroup modelGroup = getXSDModelGroup();
98
		XSDModelGroup modelGroup = getXSDModelGroup();
99
	XSDElementDeclaration propertyRef = XSDFactory.eINSTANCE
99
		XSDElementDeclaration propertyRef = XSDFactory.eINSTANCE
100
		.createXSDElementDeclaration();
100
			.createXSDElementDeclaration();
101
	propertyRef.setResolvedElementDeclaration(_newProperty);
101
		propertyRef.setResolvedElementDeclaration(_newProperty);
102
	XSDParticle simpleElementParticle = XSDFactory.eINSTANCE
102
		XSDParticle simpleElementParticle = XSDFactory.eINSTANCE
103
		.createXSDParticle();
103
			.createXSDParticle();
104
	simpleElementParticle.setContent(propertyRef);
104
		simpleElementParticle.setContent(propertyRef);
105
	modelGroup.getContents().add(simpleElementParticle);
105
		modelGroup.getContents().add(simpleElementParticle);
106
    }
106
    }
107
    
107
    
108
    private void createNewResourcePropertyElement()
108
    private void createNewResourcePropertyElement()
109
    {
109
    {
110
    Definition definition = _capabilityDomain.getDefinition();
110
	    Definition definition = _capabilityDomain.getCapability().getDefinition();
111
111
	
112
	String tns = _capabilityDomain.getDefinition().getTargetNamespace();
112
		String tns = _capabilityDomain.getCapability().getDefinition().getTargetNamespace();
113
	String rpElementName = _capabilityDomain.getCapability().getName()
113
		String rpElementName = _capabilityDomain.getCapability().getName()
114
		    + "Properties";
114
			    + "Properties";
115
	XSDSchema wsdlSchema = WsdlUtils.createOrFindSchema(
115
		XSDSchema wsdlSchema = WsdlUtils.createOrFindSchema(
116
	_capabilityDomain.getDefinition(), tns);
116
		_capabilityDomain.getCapability().getDefinition(), tns);
117
	    
117
		    
118
	// create new XSD Include
118
		// create new XSD Include
119
	createPropXSDInclude(wsdlSchema);
119
		createPropXSDInclude(wsdlSchema);
120
	    
120
		    
121
	// create new Resource property element
121
		// create new Resource property element
122
	_resourcePropertyElement = XSDFactory.eINSTANCE
122
		_resourcePropertyElement = XSDFactory.eINSTANCE
123
		    .createXSDElementDeclaration();
123
			    .createXSDElementDeclaration();
124
	wsdlSchema.getContents().add(_resourcePropertyElement);
124
		wsdlSchema.getContents().add(_resourcePropertyElement);
125
	_resourcePropertyElement.setName(rpElementName);
125
		_resourcePropertyElement.setName(rpElementName);
126
	_resourcePropertyElement.setAnonymousTypeDefinition(null);
126
		_resourcePropertyElement.setAnonymousTypeDefinition(null);
127
	_capabilityDomain
127
		_capabilityDomain
128
		    .setResourcePropertyElement(_resourcePropertyElement);
128
			    .setResourcePropertyElement(_resourcePropertyElement);
129
129
	
130
	String wsrpPrefix = WsdlUtils.createOrFindPrefix(definition,
130
		String wsrpPrefix = WsdlUtils.createOrFindPrefix(definition,
131
		    WsdmConstants.WSRP_NS, "wsrp");
131
			    WsdmConstants.WSRP_NS, "wsrp");
132
	PortType pt = WsdlUtils.getPortType(definition);
132
		PortType pt = WsdlUtils.getPortType(definition);
133
	String rpElementPrefix = WsdlUtils.getPrefix(definition, wsdlSchema
133
		String rpElementPrefix = WsdlUtils.getPrefix(definition, wsdlSchema
134
		    .getTargetNamespace());
134
			    .getTargetNamespace());
135
	pt.getElement().setAttributeNS(
135
		pt.getElement().setAttributeNS(
136
		    WsdmConstants.WSRP_NS,
136
			    WsdmConstants.WSRP_NS,
137
		    wsrpPrefix + ":"
137
			    wsrpPrefix + ":"
138
			    + WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY,
138
				    + WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY,
139
		    rpElementPrefix + ":" + rpElementName);
139
			    rpElementPrefix + ":" + rpElementName);
140
    }
140
    }
141
141
142
    private void createPropXSDInclude(XSDSchema schema)
142
    private void createPropXSDInclude(XSDSchema schema)
143
    {
143
    {
144
	String schemaLocation = _newProperty.getSchema().getSchemaLocation();
144
		String schemaLocation = _newProperty.getSchema().getSchemaLocation();
145
	int index = schemaLocation.lastIndexOf('/') + 1;
145
		int index = schemaLocation.lastIndexOf('/') + 1;
146
	String xsdFileName = schemaLocation.substring(index);
146
		String xsdFileName = schemaLocation.substring(index);
147
	XSDInclude include = XSDFactory.eINSTANCE.createXSDInclude();
147
		XSDInclude include = XSDFactory.eINSTANCE.createXSDInclude();
148
	include.setSchemaLocation(xsdFileName);
148
		include.setSchemaLocation(xsdFileName);
149
	schema.getContents().add(include);
149
		schema.getContents().add(include);
150
    }
150
    }
151
151
152
    private void addPropertyToCapability()
152
    private void addPropertyToCapability()
153
    {
153
    {
154
	_property = CapabilitiesFactory.eINSTANCE.createProperty();
154
		_property = CapabilitiesFactory.eINSTANCE.createProperty();
155
	_property.setElement(_newProperty);
155
		_property.setElement(_newProperty);
156
	Capability capability = _capabilityDomain.getCapability();
156
		Capability capability = _capabilityDomain.getCapability();
157
	capability.getProperties().add(_property);
157
		capability.getProperties().add(_property);
158
    }
158
    }
159
159
160
    private boolean isResourcePropertyElementEmpty()
160
    private boolean isResourcePropertyElementEmpty()
161
    {
161
    {
162
	if (_resourcePropertyElement.getAnonymousTypeDefinition() == null)
162
		if (_resourcePropertyElement.getAnonymousTypeDefinition() == null)
163
	    return true;
163
		    return true;
164
	return false;
164
		return false;
165
    }
165
    }
166
166
167
    private XSDModelGroup getXSDModelGroup()
167
    private XSDModelGroup getXSDModelGroup()
168
    {
168
    {
169
	XSDModelGroup modelGroup = null;
169
		XSDModelGroup modelGroup = null;
170
	if (isResourcePropertyElementEmpty())
170
		if (isResourcePropertyElementEmpty())
171
	{
171
		{
172
	    modelGroup = createNewXSDModelGroup();
172
		    modelGroup = createNewXSDModelGroup();
173
	}
173
		}
174
	else
174
		else
175
	{
175
		{
176
	    XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) _resourcePropertyElement
176
		    XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) _resourcePropertyElement
177
		    .getAnonymousTypeDefinition();
177
			    .getAnonymousTypeDefinition();
178
	    modelGroup = XsdUtils.getXSDModelGroup(typeDef);
178
		    modelGroup = XsdUtils.getXSDModelGroup(typeDef);
179
	}
179
		}
180
	return modelGroup;
180
		return modelGroup;
181
    }
181
    }
182
182
183
    private XSDModelGroup createNewXSDModelGroup()
183
    private XSDModelGroup createNewXSDModelGroup()
184
    {
184
    {
185
	XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
185
		XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
186
	modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
186
		modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
187
187
	
188
	XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
188
		XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
189
	xsdParticle.setContent(modelGroup);
189
		xsdParticle.setContent(modelGroup);
190
190
	
191
	XSDComplexTypeDefinition complexTypeDefiniton = XSDFactory.eINSTANCE
191
		XSDComplexTypeDefinition complexTypeDefiniton = XSDFactory.eINSTANCE
192
		.createXSDComplexTypeDefinition();
192
			.createXSDComplexTypeDefinition();
193
	complexTypeDefiniton.setContent(xsdParticle);
193
		complexTypeDefiniton.setContent(xsdParticle);
194
	_resourcePropertyElement
194
		_resourcePropertyElement
195
		.setAnonymousTypeDefinition(complexTypeDefiniton);
195
			.setAnonymousTypeDefinition(complexTypeDefiniton);
196
196
	
197
	return modelGroup;
197
		return modelGroup;
198
    }
198
    }
199
199
200
    /**
200
    /**
Lines 203-208 Link Here
203
     */
203
     */
204
    public Property getProperty()
204
    public Property getProperty()
205
    {
205
    {
206
	return _property;
206
		return _property;
207
    }
207
    }
208
}
208
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/property/internal/ChangeMutabilityCommand.java (-22 / +18 lines)
Lines 12-22 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal;
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal;
14
14
15
import org.eclipse.emf.ecore.xml.type.internal.QName;
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
15
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
17
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
19
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
19
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
21
20
22
/**
21
/**
Lines 37-44 Link Here
37
    public ChangeMutabilityCommand(CapabilityDomain capabilityDomain,
36
    public ChangeMutabilityCommand(CapabilityDomain capabilityDomain,
38
	    Property property, String mutability)
37
	    Property property, String mutability)
39
    {
38
    {
40
	super(capabilityDomain, property);
39
		super(capabilityDomain, property);
41
	_mutability = mutability;
40
		_mutability = mutability;
42
    }
41
    }
43
42
44
    /**
43
    /**
Lines 47-70 Link Here
47
     */
46
     */
48
    public void execute()
47
    public void execute()
49
    {
48
    {
50
	PropertyMetaDataDescriptor metaDataDescriptor = _capabilityDomain
49
		MetadataDescriptor metaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
51
		.getMetaDataDescriptor();
50
		if (metaDataDescriptor == null)
52
	if (_capabilityDomain.getMetaDataDescriptor() == null)
51
		    metaDataDescriptor = createMetaDataDescriptor();
53
	{
52
		
54
	    metaDataDescriptor = createMetaDataDescriptor();
53
		if (_metadata == null)
55
	}
54
		{
56
55
		    _metadata = metaDataDescriptor.createNewPropertyType();
57
	if (_metadata == null)
56
		    _property.setMetaData(_metadata);
58
	{
57
		    String ns = _property.getElement().getTargetNamespace();
59
	    _metadata = metaDataDescriptor.createNewPropertyType();
58
		    String name = XsdUtils.getName(_property.getElement());
60
	    _property.setMetaData(_metadata);
59
		    String prefix = metaDataDescriptor.getOrCreatePrefix(ns);
61
	    String ns = _property.getElement().getTargetNamespace();
60
		    _metadata.setName(prefix+":"+name);
62
	    String name = XsdUtils.getName(_property.getElement());
61
		}
63
	    String prefix = metaDataDescriptor.getOrCreatePrefix(ns);
62
	
64
	    _metadata.setName(new QName(ns, name, prefix));
63
		_metadata.setMutability(MetaDataUtils.getMutabilityType(_mutability));
65
	}
66
67
	_metadata.setMutability(MetaDataUtils.getMutabilityType(_mutability));
68
    }
64
    }
69
65
70
}
66
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/property/internal/ChangeModifiabilityCommand.java (-23 / +19 lines)
Lines 12-22 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal;
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.property.internal;
14
14
15
import org.eclipse.emf.ecore.xml.type.internal.QName;
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
15
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
17
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
19
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
19
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
21
20
22
/**
21
/**
Lines 37-44 Link Here
37
    public ChangeModifiabilityCommand(CapabilityDomain capabilityDomain,
36
    public ChangeModifiabilityCommand(CapabilityDomain capabilityDomain,
38
	    Property property, String modifiability)
37
	    Property property, String modifiability)
39
    {
38
    {
40
	super(capabilityDomain, property);
39
		super(capabilityDomain, property);
41
	_modifiability = modifiability;
40
		_modifiability = modifiability;
42
    }
41
    }
43
42
44
    /**
43
    /**
Lines 47-70 Link Here
47
     */
46
     */
48
    public void execute()
47
    public void execute()
49
    {
48
    {
50
	PropertyMetaDataDescriptor metaDataDescriptor = _capabilityDomain
49
		MetadataDescriptor metaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
51
		.getMetaDataDescriptor();
50
		if (metaDataDescriptor == null)
52
	if (_capabilityDomain.getMetaDataDescriptor() == null)
51
		    metaDataDescriptor = createMetaDataDescriptor();
53
	{
52
		
54
	    metaDataDescriptor = createMetaDataDescriptor();
53
		if (_metadata == null)
55
	}
54
		{
56
55
		    _metadata = metaDataDescriptor.createNewPropertyType();
57
	if (_metadata == null)
56
		    _property.setMetaData(_metadata);
58
	{
57
		    String ns = _property.getElement().getTargetNamespace();
59
	    _metadata = metaDataDescriptor.createNewPropertyType();
58
		    String name = XsdUtils.getName(_property.getElement());
60
	    _property.setMetaData(_metadata);
59
		    String prefix = metaDataDescriptor.getOrCreatePrefix(ns);
61
	    String ns = _property.getElement().getTargetNamespace();
60
		    _metadata.setName(prefix+":"+name);
62
	    String name = XsdUtils.getName(_property.getElement());
61
		}
63
	    String prefix = metaDataDescriptor.getOrCreatePrefix(ns);
62
	
64
	    _metadata.setName(new QName(ns, name, prefix));
63
		_metadata.setModifiability(MetaDataUtils
65
	}
64
			.getModifiabilityType(_modifiability));
66
67
	_metadata.setModifiability(MetaDataUtils
68
		.getModifiabilityType(_modifiability));
69
    }
65
    }
70
}
66
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/property/internal/MetaDataCommand.java (-8 / +7 lines)
Lines 15-23 Link Here
15
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
15
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
18
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
19
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
19
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
20
21
20
22
/**
21
/**
23
 * 
22
 * 
Lines 38-55 Link Here
38
     */
37
     */
39
    public MetaDataCommand(CapabilityDomain capabilityDomain, Property property)
38
    public MetaDataCommand(CapabilityDomain capabilityDomain, Property property)
40
    {
39
    {
41
	_capabilityDomain = capabilityDomain;
40
		_capabilityDomain = capabilityDomain;
42
	_property = property;
41
		_property = property;
43
	_metadata = property.getMetaData();
42
		_metadata = property.getMetaData();
44
    }
43
    }
45
44
46
    /**
45
    /**
47
     * Creates a new metaDataDescriptor for the property.
46
     * Creates a new metaDataDescriptor for the property.
48
     */
47
     */
49
    protected PropertyMetaDataDescriptor createMetaDataDescriptor()
48
    protected MetadataDescriptor createMetaDataDescriptor()
50
    {
49
    {
51
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = MetaDataUtils.createMetaDataDescriptor(_capabilityDomain);
50
	    MetadataDescriptor propertyMetaDataDescriptor = MetaDataUtils.createMetaDataDescriptor(_capabilityDomain);
52
	return propertyMetaDataDescriptor;
51
		return propertyMetaDataDescriptor;
53
    }
52
    }
54
53
55
}
54
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/operation/internal/ParamSection.java (-216 / +216 lines)
Lines 82-88 Link Here
82
    public ParamSection(CapabilityEditor editor, IUIPage page,
82
    public ParamSection(CapabilityEditor editor, IUIPage page,
83
	    ScrolledForm form, FormToolkit toolkit)
83
	    ScrolledForm form, FormToolkit toolkit)
84
    {
84
    {
85
	super(editor, page, form, toolkit);
85
    	super(editor, page, form, toolkit);
86
    }
86
    }
87
87
88
    /**
88
    /**
Lines 90-237 Link Here
90
         */
90
         */
91
    public void create()
91
    public void create()
92
    {
92
    {
93
	Composite sectionClient = createSection(Messages.PARAMETERS,
93
		Composite sectionClient = createSection(Messages.PARAMETERS,
94
		Messages.PARAM_OF_OP);
94
			Messages.PARAM_OF_OP);
95
	GridLayout layout = new GridLayout(2, false);
95
		GridLayout layout = new GridLayout(2, false);
96
	layout.marginWidth = LAYOUT_MARGIN_WIDTH;
96
		layout.marginWidth = LAYOUT_MARGIN_WIDTH;
97
	layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
97
		layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
98
	layout.horizontalSpacing = LAYOUT_HORIZONTAL_SPACING;
98
		layout.horizontalSpacing = LAYOUT_HORIZONTAL_SPACING;
99
	sectionClient.setLayout(layout);
99
		sectionClient.setLayout(layout);
100
	FormToolkit toolkit = getToolkit();
100
		FormToolkit toolkit = getToolkit();
101
101
	
102
	_paramViewer = new StructuredTableViewer(sectionClient, toolkit,
102
		_paramViewer = new StructuredTableViewer(sectionClient, toolkit,
103
		SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION,
103
			SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION,
104
		this);
104
			this);
105
	Table table = (Table) _paramViewer.getControl();
105
		Table table = (Table) _paramViewer.getControl();
106
	GridData gd = new GridData(GridData.FILL_BOTH);
106
		GridData gd = new GridData(GridData.FILL_BOTH);
107
	gd.widthHint = GridData.HORIZONTAL_ALIGN_FILL;
107
		gd.widthHint = GridData.HORIZONTAL_ALIGN_FILL;
108
	gd.heightHint = 100;
108
		gd.heightHint = 100;
109
	_paramViewer.getControl().setLayoutData(gd);
109
		_paramViewer.getControl().setLayoutData(gd);
110
110
	
111
	/*TableColumn column = new TableColumn(table, SWT.NONE, 0);
111
		/*TableColumn column = new TableColumn(table, SWT.NONE, 0);
112
	column.setText("");
112
		column.setText("");
113
	column.setWidth(20);
113
		column.setWidth(20);
114
	column.setResizable(false);*/
114
		column.setResizable(false);*/
115
115
	
116
	TableColumn column = new TableColumn(table, SWT.NONE, 0);
116
		TableColumn column = new TableColumn(table, SWT.NONE, 0);
117
	column.setText(Messages.PARAM_NAME);
117
		column.setText(Messages.PARAM_NAME);
118
	column.setWidth(100);
118
		column.setWidth(100);
119
119
	
120
	column = new TableColumn(table, SWT.NONE, 1);
120
		column = new TableColumn(table, SWT.NONE, 1);
121
	column.setText(Messages.PARAM_TYPE);
121
		column.setText(Messages.PARAM_TYPE);
122
	column.setWidth(100);
122
		column.setWidth(100);
123
123
	
124
	table.redraw();
124
		table.redraw();
125
	table.setHeaderVisible(true);
125
		table.setHeaderVisible(true);
126
	table.setLinesVisible(true);
126
		table.setLinesVisible(true);
127
	_paramViewer.setContentProvider(new ParamContentProvider());
127
		_paramViewer.setContentProvider(new ParamContentProvider());
128
	_paramViewer.setLabelProvider(new ParamLabelProvider());
128
		_paramViewer.setLabelProvider(new ParamLabelProvider());
129
129
	
130
	Composite buttonComposite = toolkit.createComposite(sectionClient);
130
		Composite buttonComposite = toolkit.createComposite(sectionClient);
131
	layout = new GridLayout();
131
		layout = new GridLayout();
132
	layout.marginHeight = 0;
132
		layout.marginHeight = 0;
133
	buttonComposite.setLayout(layout);
133
		buttonComposite.setLayout(layout);
134
	gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING
134
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING
135
		| GridData.VERTICAL_ALIGN_FILL);
135
			| GridData.VERTICAL_ALIGN_FILL);
136
	gd.horizontalSpan = 1;
136
		gd.horizontalSpan = 1;
137
	buttonComposite.setLayoutData(gd);
137
		buttonComposite.setLayoutData(gd);
138
138
	
139
	_addParameterButton = toolkit
139
		_addParameterButton = toolkit
140
		.createButton(
140
			.createButton(
141
			buttonComposite,
141
				buttonComposite,
142
			org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.ADD_BUTTON_LABEL,
142
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.ADD_BUTTON_LABEL,
143
			SWT.PUSH);
143
				SWT.PUSH);
144
	gd = new GridData(GridData.FILL_HORIZONTAL
144
		gd = new GridData(GridData.FILL_HORIZONTAL
145
		| GridData.VERTICAL_ALIGN_BEGINNING);
145
			| GridData.VERTICAL_ALIGN_BEGINNING);
146
	_addParameterButton.setLayoutData(gd);
146
		_addParameterButton.setLayoutData(gd);
147
	_addParameterButton.addListener(SWT.Selection, new Listener()
147
		_addParameterButton.addListener(SWT.Selection, new Listener()
148
	{
148
		{
149
	    public void handleEvent(Event event)
149
		    public void handleEvent(Event event)
150
	    {
150
		    {
151
		addParameter();
151
			addParameter();
152
	    }
152
		    }
153
	});
153
		});
154
154
	
155
	_editParameterButton = toolkit
155
		_editParameterButton = toolkit
156
		.createButton(
156
			.createButton(
157
			buttonComposite,
157
				buttonComposite,
158
			org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.EDIT_BUTTON_LABEL,
158
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.EDIT_BUTTON_LABEL,
159
			SWT.PUSH);
159
				SWT.PUSH);
160
	gd = new GridData(GridData.FILL_HORIZONTAL
160
		gd = new GridData(GridData.FILL_HORIZONTAL
161
		| GridData.VERTICAL_ALIGN_BEGINNING);
161
			| GridData.VERTICAL_ALIGN_BEGINNING);
162
	_editParameterButton.setLayoutData(gd);
162
		_editParameterButton.setLayoutData(gd);
163
	_editParameterButton.addListener(SWT.Selection, new Listener()
163
		_editParameterButton.addListener(SWT.Selection, new Listener()
164
	{
164
		{
165
	    public void handleEvent(Event event)
165
		    public void handleEvent(Event event)
166
	    {
166
		    {
167
		editParameter();
167
			editParameter();
168
	    }
168
		    }
169
	});
169
		});
170
	_editParameterButton.setEnabled(false);
170
		_editParameterButton.setEnabled(false);
171
171
	
172
	_removeParameterButton = toolkit
172
		_removeParameterButton = toolkit
173
		.createButton(
173
			.createButton(
174
			buttonComposite,
174
				buttonComposite,
175
			org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL,
175
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL,
176
			SWT.PUSH);
176
				SWT.PUSH);
177
	gd = new GridData(GridData.FILL_HORIZONTAL
177
		gd = new GridData(GridData.FILL_HORIZONTAL
178
		| GridData.VERTICAL_ALIGN_BEGINNING);
178
			| GridData.VERTICAL_ALIGN_BEGINNING);
179
	_removeParameterButton.setLayoutData(gd);
179
		_removeParameterButton.setLayoutData(gd);
180
	_removeParameterButton.addListener(SWT.Selection, new Listener()
180
		_removeParameterButton.addListener(SWT.Selection, new Listener()
181
	{
181
		{
182
	    public void handleEvent(Event event)
182
		    public void handleEvent(Event event)
183
	    {
183
		    {
184
		removeParameter();
184
			removeParameter();
185
	    }
185
		    }
186
	});
186
		});
187
	_removeParameterButton.setEnabled(false);
187
		_removeParameterButton.setEnabled(false);
188
    }
188
    }
189
189
190
    private void addParameter()
190
    private void addParameter()
191
    {
191
    {
192
	java.util.List paramList = (List) _paramViewer.getInput();
192
		java.util.List paramList = (List) _paramViewer.getInput();
193
	NewParameterDialog dlg = new NewParameterDialog(getForm().getShell(),
193
		NewParameterDialog dlg = new NewParameterDialog(getForm().getShell(),
194
		Messages.ADD_PARAM, paramList, null);
194
			Messages.ADD_PARAM, paramList, null);
195
	if (dlg.open() == Window.OK)
195
		if (dlg.open() == Window.OK)
196
	{
196
		{
197
	    InputParameter parameter = dlg.getParameter();
197
		    InputParameter parameter = dlg.getParameter();
198
	    AddParameterCommand command = new AddParameterCommand(
198
		    AddParameterCommand command = new AddParameterCommand(
199
		    _selectedOperation, parameter);
199
			    _selectedOperation, parameter);
200
	    command.execute();
200
		    command.execute();
201
	    _selectedParam = parameter;
201
		    _selectedParam = parameter;
202
	    _page.setDirty();
202
		    _page.setDirty();
203
	}
203
		}
204
    }
204
    }
205
    
205
    
206
    private void editParameter()
206
    private void editParameter()
207
    {
207
    {
208
	Object[] objects = _paramViewer.getSelectedObjets();
208
		Object[] objects = _paramViewer.getSelectedObjets();
209
	if (objects != null && objects.length != 0)
209
		if (objects != null && objects.length != 0)
210
	{
210
		{
211
	    InputParameter parameter = (InputParameter) objects[0];
211
		    InputParameter parameter = (InputParameter) objects[0];
212
	    java.util.List paramList = (List) _paramViewer.getInput();
212
		    java.util.List paramList = (List) _paramViewer.getInput();
213
	    NewParameterDialog dlg = new NewParameterDialog(getForm().getShell(),
213
		    NewParameterDialog dlg = new NewParameterDialog(getForm().getShell(),
214
			Messages.EDIT_PARAM, paramList, parameter);
214
				Messages.EDIT_PARAM, paramList, parameter);
215
	    if (dlg.open() == Window.OK)
215
		    if (dlg.open() == Window.OK)
216
	    {
216
		    {
217
		    _selectedParam = parameter;
217
			    _selectedParam = parameter;
218
		    _page.setDirty();
218
			    _page.setDirty();
219
	    }
219
		    }
220
	}
220
		}
221
    }
221
    }
222
222
223
    private void removeParameter()
223
    private void removeParameter()
224
    {
224
    {
225
	Object[] objects = _paramViewer.getSelectedObjets();
225
		Object[] objects = _paramViewer.getSelectedObjets();
226
	if (objects != null && objects.length != 0)
226
		if (objects != null && objects.length != 0)
227
	{
227
		{
228
	    InputParameter parameter = (InputParameter) objects[0];
228
		    InputParameter parameter = (InputParameter) objects[0];
229
	    RemoveParameterCommand command = new RemoveParameterCommand(
229
		    RemoveParameterCommand command = new RemoveParameterCommand(
230
		    _selectedOperation, parameter);
230
			    _selectedOperation, parameter);
231
	    command.execute();
231
		    command.execute();
232
	    _selectedParam = null;
232
		    _selectedParam = null;
233
	    _page.setDirty();
233
		    _page.setDirty();
234
	}
234
		}
235
    }
235
    }
236
236
237
    /**
237
    /**
Lines 239-248 Link Here
239
         */
239
         */
240
    public void refresh()
240
    public void refresh()
241
    {
241
    {
242
	if (_selectedParam != null)
242
		if (_selectedParam != null)
243
	{
243
		{
244
	    setFocusToParameter(_selectedParam);
244
		    setFocusToParameter(_selectedParam);
245
	}
245
		}
246
    }
246
    }
247
247
248
    /**
248
    /**
Lines 257-308 Link Here
257
         */
257
         */
258
    public void selectionChanged(SelectionChangedEvent event)
258
    public void selectionChanged(SelectionChangedEvent event)
259
    {
259
    {
260
	showSelectedOperationParameters();
260
		showSelectedOperationParameters();
261
	// TODO Remove this once able to handle WSDL Import properly
261
		// TODO Remove this once able to handle WSDL Import properly
262
	enableDisableParamSection();
262
		enableDisableParamSection();
263
    }
263
    }
264
264
265
    private void showSelectedOperationParameters()
265
    private void showSelectedOperationParameters()
266
    {
266
    {
267
	XSDElementDeclaration[] parameters = WsdlUtils
267
		XSDElementDeclaration[] parameters = WsdlUtils
268
		.getOperationParams(_selectedOperation);
268
			.getOperationParams(_selectedOperation);
269
	_editParameterButton.setEnabled(false);
269
		_editParameterButton.setEnabled(false);
270
	_removeParameterButton.setEnabled(false);
270
		_removeParameterButton.setEnabled(false);
271
	List paramList = new LinkedList();
271
		List paramList = new LinkedList();
272
	for (int i = 0; i < parameters.length; i++)
272
		for (int i = 0; i < parameters.length; i++)
273
	{
273
		{
274
	    String type = XsdUtils.getType(parameters[i]);
274
		    String type = XsdUtils.getType(parameters[i]);
275
	    XSDTypeDefinition typeDefinition = XsdUtils
275
		    XSDTypeDefinition typeDefinition = XsdUtils
276
		    .getXSDTypeDefinition(parameters[i]);
276
			    .getXSDTypeDefinition(parameters[i]);
277
	    DataType dataType = new DataType(type, typeDefinition);
277
		    DataType dataType = new DataType(type, typeDefinition);
278
	    boolean isArrayType = false;
278
		    boolean isArrayType = false;
279
	    if(parameters[i].eContainer() instanceof XSDParticle)
279
		    if(parameters[i].eContainer() instanceof XSDParticle)
280
	    {
280
		    {
281
	    	XSDParticle particle = (XSDParticle) parameters[i].eContainer();
281
		    	XSDParticle particle = (XSDParticle) parameters[i].eContainer();
282
	    	isArrayType = particle.getMaxOccurs()==-1?true:false;
282
		    	isArrayType = particle.getMaxOccurs()==-1?true:false;
283
	    }	    
283
		    }	    
284
	    InputParameter param = new InputParameter(parameters[i], dataType, isArrayType);
284
		    InputParameter param = new InputParameter(parameters[i], dataType, isArrayType);
285
	    paramList.add(param);
285
		    paramList.add(param);
286
	}
286
		}
287
	_paramViewer.setInput(paramList);
287
		_paramViewer.setInput(paramList);
288
    }
288
    }
289
289
290
    private void enableDisableParamSection()
290
    private void enableDisableParamSection()
291
    {
291
    {
292
	Definition capDefinition = _editor.getCapabilityDomain()
292
		Definition capDefinition = _editor.getCapabilityDomain().getCapability()
293
		.getDefinition();
293
			.getDefinition();
294
	Message operationMessage = _selectedOperation.getEInput().getEMessage();
294
		Message operationMessage = _selectedOperation.getEInput().getEMessage();
295
	boolean isImportedOperation = true;
295
		boolean isImportedOperation = true;
296
	if (operationMessage != null)
296
		if (operationMessage != null)
297
	    isImportedOperation = !operationMessage.getEnclosingDefinition()
297
		    isImportedOperation = !operationMessage.getEnclosingDefinition()
298
		    .equals(capDefinition);
298
			    .equals(capDefinition);
299
299
	
300
	_addParameterButton.setEnabled(!isImportedOperation && !_editor.isReadOnly());
300
		_addParameterButton.setEnabled(!isImportedOperation && !_editor.isReadOnly());
301
	_editParameterButton.setEnabled(!isImportedOperation
301
		_editParameterButton.setEnabled(!isImportedOperation
302
		&& _editParameterButton.getEnabled() && !_editor.isReadOnly());
302
			&& _editParameterButton.getEnabled() && !_editor.isReadOnly());
303
	_removeParameterButton.setEnabled(!isImportedOperation
303
		_removeParameterButton.setEnabled(!isImportedOperation
304
		&& _removeParameterButton.getEnabled() && !_editor.isReadOnly());
304
			&& _removeParameterButton.getEnabled() && !_editor.isReadOnly());
305
	_paramViewer.getControl().setEnabled(!isImportedOperation);
305
		_paramViewer.getControl().setEnabled(!isImportedOperation);
306
    }
306
    }
307
307
308
    /**
308
    /**
Lines 310-317 Link Here
310
         */
310
         */
311
    public void setSelectedObject(Object object)
311
    public void setSelectedObject(Object object)
312
    {
312
    {
313
	if (object instanceof Operation)
313
		if (object instanceof Operation)
314
	    _selectedOperation = (Operation) object;
314
		    _selectedOperation = (Operation) object;
315
    }
315
    }
316
316
317
    /**
317
    /**
Lines 326-338 Link Here
326
         */
326
         */
327
    public void handleSelectionChanged(SelectionChangedEvent event)
327
    public void handleSelectionChanged(SelectionChangedEvent event)
328
    {
328
    {
329
	Object[] objects = _paramViewer.getSelectedObjets();
329
		Object[] objects = _paramViewer.getSelectedObjets();
330
	_editParameterButton.setEnabled(objects.length != 0 && !_editor.isReadOnly());
330
		_editParameterButton.setEnabled(objects.length != 0 && !_editor.isReadOnly());
331
	_removeParameterButton.setEnabled(objects.length != 0 && !_editor.isReadOnly());
331
		_removeParameterButton.setEnabled(objects.length != 0 && !_editor.isReadOnly());
332
	if (objects.length > 0)
332
		if (objects.length > 0)
333
	{
333
		{
334
	    _selectedParam = (InputParameter) objects[0];
334
		    _selectedParam = (InputParameter) objects[0];
335
	}
335
		}
336
    }
336
    }
337
337
338
    /**
338
    /**
Lines 340-357 Link Here
340
         */
340
         */
341
    public void enable(boolean enabled)
341
    public void enable(boolean enabled)
342
    {
342
    {
343
	_addParameterButton.setEnabled(enabled);
343
		_addParameterButton.setEnabled(enabled);
344
	_editParameterButton.setEnabled(enabled);
344
		_editParameterButton.setEnabled(enabled);
345
	_removeParameterButton.setEnabled(enabled);
345
		_removeParameterButton.setEnabled(enabled);
346
	if (!enabled)
346
		if (!enabled)
347
	    _paramViewer.setInput(new LinkedList());
347
		    _paramViewer.setInput(new LinkedList());
348
    }
348
    }
349
349
350
    private void setFocusToParameter(InputParameter param)
350
    private void setFocusToParameter(InputParameter param)
351
    {
351
    {
352
	_selectedParam = param;
352
		_selectedParam = param;
353
	_paramViewer.setSelection(new StructuredSelection(_selectedParam),
353
		_paramViewer.setSelection(new StructuredSelection(_selectedParam),
354
		false);
354
			false);
355
    }
355
    }
356
356
357
}
357
}
Lines 361-372 Link Here
361
361
362
    public Object[] getElements(Object inputElement)
362
    public Object[] getElements(Object inputElement)
363
    {
363
    {
364
	if (inputElement instanceof Collection)
364
		if (inputElement instanceof Collection)
365
	{
365
		{
366
	    Collection c = (Collection) inputElement;
366
		    Collection c = (Collection) inputElement;
367
	    return c.toArray();
367
		    return c.toArray();
368
	}
368
		}
369
	return new Object[0];
369
		return new Object[0];
370
    }
370
    }
371
371
372
    public void dispose()
372
    public void dispose()
Lines 384-412 Link Here
384
384
385
    public String getColumnText(Object element, int columnIndex)
385
    public String getColumnText(Object element, int columnIndex)
386
    {
386
    {
387
	String text = "";
387
		String text = "";
388
	switch (columnIndex)
388
		switch (columnIndex)
389
	{
389
		{
390
	case 0:
390
			case 0:
391
	{
391
			{
392
	    InputParameter param = (InputParameter) element;
392
			    InputParameter param = (InputParameter) element;
393
	    text = param.getXSDElementDeclaration().getName();
393
			    text = param.getXSDElementDeclaration().getName();
394
	    break;
394
			    break;
395
	}
395
			}
396
	case 1:
396
			case 1:
397
	{
397
			{
398
	    InputParameter param = (InputParameter) element;
398
			    InputParameter param = (InputParameter) element;
399
	    XSDFeature featureDeclaration = param.getXSDElementDeclaration();
399
			    XSDFeature featureDeclaration = param.getXSDElementDeclaration();
400
	    text = XsdUtils.getType(featureDeclaration);
400
			    text = XsdUtils.getType(featureDeclaration);
401
	    if(param.isArrayType())
401
			    if(param.isArrayType())
402
	    	text = text+"[]";
402
			    	text = text+"[]";
403
	}
403
			}
404
	}
404
		}
405
	return text;
405
		return text;
406
    }
406
    }
407
407
408
    public Image getColumnImage(Object element, int columnIndex)
408
    public Image getColumnImage(Object element, int columnIndex)
409
    {
409
    {
410
	return null;
410
    	return null;
411
    }
411
    }
412
}
412
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/operation/internal/ListSection.java (-303 / +310 lines)
Lines 69-404 Link Here
69
public class ListSection extends AbstractPageSection implements IViewerClient
69
public class ListSection extends AbstractPageSection implements IViewerClient
70
{
70
{
71
71
72
    private StructuredTableViewer _operationsViewer;
72
	private StructuredTableViewer _operationsViewer;
73
73
74
    private Button _addOperationButton;
74
	private Button _addOperationButton;
75
75
76
    private Button _removeOperationButton;
76
	private Button _removeOperationButton;
77
77
78
    private Label _errorLabel;
78
	private Label _errorLabel;
79
79
80
    private Operation _selectedOperation;
80
	private Operation _selectedOperation;
81
    
81
82
    private Composite _sectionClient;
82
	private Composite _sectionClient;
83
    
83
84
    private Composite _buttonClient;
84
	private Composite _buttonClient;
85
85
86
    /**
86
	/**
87
     * Creates a new object of this class. 
87
	 * Creates a new object of this class.
88
     */
88
	 */
89
    ListSection(CapabilityEditor editor, IUIPage page, ScrolledForm form,
89
	ListSection(CapabilityEditor editor, IUIPage page, ScrolledForm form,
90
	    FormToolkit toolkit)
90
			FormToolkit toolkit)
91
    {
91
	{
92
	super(editor, page, form, toolkit);
92
		super(editor, page, form, toolkit);
93
    }
93
	}
94
94
95
    /**
95
	/**
96
         * Creates the section.
96
	 * Creates the section.
97
         */
97
	 */
98
    public void create()
98
	public void create()
99
    {
99
	{
100
    _sectionClient = createSection(Messages.OPERATIONS,
100
		_sectionClient = createSection(Messages.OPERATIONS,
101
		Messages.OPERATIONS_OF_CAP, 1, 3);
101
				Messages.OPERATIONS_OF_CAP, 1, 3);
102
	GridLayout layout = new GridLayout(2, false);
102
		GridLayout layout = new GridLayout(2, false);
103
	layout.marginWidth = LAYOUT_MARGIN_WIDTH;
103
		layout.marginWidth = LAYOUT_MARGIN_WIDTH;
104
	layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
104
		layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
105
	_sectionClient.setLayout(layout);
105
		_sectionClient.setLayout(layout);
106
	FormToolkit toolkit = getToolkit();
106
		FormToolkit toolkit = getToolkit();
107
107
108
	_operationsViewer = new StructuredTableViewer(_sectionClient, toolkit,
108
		_operationsViewer = new StructuredTableViewer(_sectionClient, toolkit,
109
		SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, this);
109
				SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, this);
110
110
111
	GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
111
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
112
	gd.heightHint = 50;
112
		gd.heightHint = 50;
113
	gd.widthHint = 50;
113
		gd.widthHint = 50;
114
	_operationsViewer.getControl().setLayoutData(gd);
114
		_operationsViewer.getControl().setLayoutData(gd);
115
	_operationsViewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
115
		_operationsViewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
116
		FormToolkit.TREE_BORDER);
116
				FormToolkit.TREE_BORDER);
117
117
118
	// Set up a label provider that knows about the capability (so can
118
		// Set up a label provider that knows about the capability (so can
119
	// extract SemanticDecorations from it)
119
		// extract SemanticDecorations from it)
120
	OperationContentProvider provider = new OperationContentProvider();
120
		OperationContentProvider provider = new OperationContentProvider();
121
	_operationsViewer.setContentProvider(provider);
121
		_operationsViewer.setContentProvider(provider);
122
	_operationsViewer.setLabelProvider(new OperationLabelProvider(getForm()
122
		_operationsViewer.setLabelProvider(new OperationLabelProvider(getForm()
123
		.getShell()));
123
				.getShell()));
124
	_operationsViewer.getControl().setSize(_operationsViewer.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT));
124
		_operationsViewer.getControl().setSize(
125
	
125
				_operationsViewer.getControl().computeSize(SWT.DEFAULT,
126
	_buttonClient = toolkit.createComposite(_sectionClient);
126
						SWT.DEFAULT));
127
	layout = new GridLayout();
127
128
	layout.marginHeight = 0;
128
		_buttonClient = toolkit.createComposite(_sectionClient);
129
	_buttonClient.setLayout(layout);
129
		layout = new GridLayout();
130
	gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_FILL, false, false);
130
		layout.marginHeight = 0;
131
	_buttonClient.setLayoutData(gd);
131
		_buttonClient.setLayout(layout);
132
132
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING,
133
	_addOperationButton = createPushButton(
133
				GridData.VERTICAL_ALIGN_FILL, false, false);
134
			_buttonClient,
134
		_buttonClient.setLayoutData(gd);
135
		toolkit,
135
136
		org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.ADD_BUTTON_LABEL,
136
		_addOperationButton = createPushButton(
137
		new Listener()
137
				_buttonClient,
138
				toolkit,
139
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.ADD_BUTTON_LABEL,
140
				new Listener() {
141
					public void handleEvent(Event event)
142
					{
143
						addOperation();
144
					}
145
				});
146
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
147
		gd.widthHint = 50;
148
		_addOperationButton.setLayoutData(gd);
149
		_addOperationButton.setEnabled(!_editor.isReadOnly());
150
151
		_removeOperationButton = createPushButton(
152
				_buttonClient,
153
				toolkit,
154
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL,
155
				new Listener() {
156
					public void handleEvent(Event event)
157
					{
158
						removeOperation();
159
					}
160
				});
161
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
162
		gd.widthHint = 50;
163
		_removeOperationButton.setLayoutData(gd);
164
		_removeOperationButton.setEnabled(false);
165
166
		_errorLabel = toolkit.createLabel(_sectionClient, "", SWT.WRAP);
167
		gd = new GridData();
168
		gd.grabExcessHorizontalSpace = true;
169
		gd.horizontalAlignment = SWT.FILL;
170
		gd.horizontalSpan = 2;
171
		_errorLabel.setLayoutData(gd);
172
	}
173
174
	private void addOperation()
175
	{
176
		CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
177
		NewOperationDialog dlg = new NewOperationDialog(getForm().getShell(),
178
				Messages.ADD_OPERATION, capabilityDomain);
179
		int choice = dlg.open();
180
		if (choice == Window.OK)
138
		{
181
		{
139
		    public void handleEvent(Event event)
182
			Operation operation = dlg.getOperation();
140
		    {
183
			AddOperationCommand command_1 = new AddOperationCommand(
141
			addOperation();
184
					capabilityDomain, operation);
142
		    }
185
			command_1.execute();
143
		});
186
			operation = command_1.getOperation();
144
	gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
187
145
	gd.widthHint = 50;
188
			// Change the return type of new operation
146
	_addOperationButton.setLayoutData(gd);
189
			DataType returnType = dlg.getReturnType();
147
	_addOperationButton.setEnabled(!_editor.isReadOnly());
190
			ChangeOperationReturnTypeCommand command_2 = new ChangeOperationReturnTypeCommand(
148
191
					operation, returnType);
149
	_removeOperationButton = createPushButton(
192
			command_2.execute();
150
			_buttonClient,
193
151
		toolkit,
194
			// Change the types of input parameters
152
		org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL,
195
			java.util.List paramList = dlg.getInputParams();
153
		new Listener()
196
			for (int i = 0; i < paramList.size(); i++)
197
			{
198
				InputParameter param = (InputParameter) paramList.get(i);
199
				ChangeInputParamTypeCommand command = new ChangeInputParamTypeCommand(
200
						param, param.getDataType());
201
				command.execute();
202
			}
203
204
			_selectedOperation = operation;
205
			_page.setDirty();
206
		}
207
	}
208
209
	private void removeOperation()
210
	{
211
		CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
212
		RemoveOperationCommand command = new RemoveOperationCommand(
213
				capabilityDomain, _selectedOperation);
214
		command.execute();
215
		_selectedOperation = null;
216
		_page.setDirty();
217
	}
218
219
	/**
220
	 * Refreshes the section.
221
	 */
222
	public void refresh()
223
	{
224
		Capability capability = _editor.getCapabilityDomain().getCapability();
225
		List operations = capability.getOperations();
226
		_operationsViewer.setInput(operations);
227
		if (operations.size() != 0 && _selectedOperation != null)
228
		{
229
			_page.enableSections(true);
230
			setFocusToOperation(_selectedOperation);
231
		}
232
		else
233
		{
234
			_page.enableSections(false);
235
		}
236
		updateErrorMessage();
237
	}
238
239
	private void updateErrorMessage()
240
	{
241
		Definition defintion = _editor.getCapabilityDomain().getCapability()
242
				.getDefinition();
243
		CapabilityWSDLValidator validator = new CapabilityWSDLValidator();
244
		IValidationReport report = validator.validate(defintion);
245
		boolean hasProblem = report.hasErrors() || report.hasWarnings();
246
		if (hasProblem)
154
		{
247
		{
155
		    public void handleEvent(Event event)
248
			// We have a problem, is it an error or just a warning?
156
		    {
249
			boolean hasError = false;
157
			removeOperation();
250
			String msg;
158
		    }
251
			if (report.hasErrors())
252
			{
253
				hasError = true;
254
				msg = report.getErrorMessages()[0].getMessage();
255
			}
256
			else
257
			{
258
				msg = report.getWarningMessages()[0].getMessage();
259
			}
260
			_errorLabel.setBackground(getForm().getDisplay().getSystemColor(
261
					hasError ? SWT.COLOR_RED : SWT.COLOR_YELLOW));
262
			_errorLabel.setForeground(getForm().getDisplay().getSystemColor(
263
					hasError ? SWT.COLOR_WHITE : SWT.COLOR_BLACK));
264
			_errorLabel.setText(" " + msg + " ");
265
		}
266
		else
267
		{
268
			_errorLabel.setBackground(getForm().getBackground());
269
			_errorLabel.setForeground(getForm().getForeground());
270
			_errorLabel.setText("");
271
		}
272
	}
273
274
	/**
275
	 * Handle double click.
276
	 */
277
	public void handleDoubleClick()
278
	{
279
	}
280
281
	/**
282
	 * Handle selection changed.
283
	 */
284
	public void handleSelectionChanged(SelectionChangedEvent event)
285
	{
286
		Object[] objects = _operationsViewer.getSelectedObjets();
287
		_removeOperationButton.setEnabled(objects.length > 0
288
				&& !_editor.isReadOnly());
289
		if (objects.length > 0)
290
		{
291
			_selectedOperation = (Operation) objects[0];
292
			_page.enableSections(true);
293
			List sections = _page.getSections();
294
			for (int i = 0; i < sections.size(); i++)
295
			{
296
				IPageSection section = (IPageSection) sections.get(i);
297
				section.setSelectedObject(_selectedOperation);
298
				section.selectionChanged(event);
299
			}
300
		}
301
	}
302
303
	/**
304
	 * Initialized control listeners.
305
	 */
306
	public void hookAllListeners()
307
	{
308
		getForm().addControlListener(new ControlAdapter() {
309
			public void controlResized(ControlEvent e)
310
			{
311
				Rectangle formBounds = getForm().getClientArea();
312
				Rectangle sectionClientBounds = _sectionClient.getClientArea();
313
				Rectangle buttonCompositeBounds = _buttonClient.getClientArea();
314
				int width = sectionClientBounds.width
315
						- buttonCompositeBounds.width - 20;
316
				int height = Math.min(formBounds.height,
317
						sectionClientBounds.height) - 100;
318
				Table table = (Table) _operationsViewer.getControl();
319
				table.setSize(width, height);
320
			}
159
		});
321
		});
160
	gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
322
	}
161
	gd.widthHint = 50;
162
	_removeOperationButton.setLayoutData(gd);
163
	_removeOperationButton.setEnabled(false);
164
165
	_errorLabel = toolkit.createLabel(_sectionClient, "", SWT.WRAP);
166
	gd = new GridData();
167
	gd.grabExcessHorizontalSpace = true;
168
	gd.horizontalAlignment = SWT.FILL;
169
	gd.horizontalSpan = 2;
170
	_errorLabel.setLayoutData(gd);
171
    }
172
173
    private void addOperation()
174
    {
175
	CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
176
	NewOperationDialog dlg = new NewOperationDialog(getForm().getShell(),
177
		Messages.ADD_OPERATION, capabilityDomain);
178
	int choice = dlg.open();
179
	if (choice == Window.OK)
180
	{
181
	    Operation operation = dlg.getOperation();
182
	    AddOperationCommand command_1 = new AddOperationCommand(
183
		    capabilityDomain, operation);
184
	    command_1.execute();
185
	    operation = command_1.getOperation();
186
187
	    // Change the return type of new operation
188
	    DataType returnType = dlg.getReturnType();
189
	    ChangeOperationReturnTypeCommand command_2 = new ChangeOperationReturnTypeCommand(
190
		    operation, returnType);
191
	    command_2.execute();
192
	    
193
	    // Change the types of input parameters
194
	    java.util.List paramList = dlg.getInputParams();
195
	    for(int i=0;i<paramList.size();i++)
196
	    {
197
		InputParameter param = (InputParameter) paramList.get(i);
198
		ChangeInputParamTypeCommand command = new ChangeInputParamTypeCommand(param, param.getDataType());
199
		command.execute();
200
	    }
201
323
202
	    _selectedOperation = operation;
324
	/**
203
	    _page.setDirty();
325
	 * Handle viewer selection changed.
326
	 */
327
	public void selectionChanged(SelectionChangedEvent event)
328
	{
204
	}
329
	}
205
    }
206
330
207
    private void removeOperation()
331
	/**
208
    {
332
	 * Update its selected object.
209
	CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
333
	 */
210
	RemoveOperationCommand command = new RemoveOperationCommand(
334
	public void setSelectedObject(Object object)
211
		capabilityDomain, _selectedOperation);
335
	{
212
	command.execute();
336
		if (object instanceof Operation)
213
	_selectedOperation = null;
337
			this._selectedOperation = (Operation) object;
214
	_page.setDirty();
338
	}
215
    }
339
216
340
	private void setFocusToOperation(Operation operation)
217
    /**
341
	{
218
         * Refreshes the section.
342
		_selectedOperation = operation;
219
         */
343
		_operationsViewer.setSelection(new StructuredSelection(operation),
220
    public void refresh()
344
				false);
221
    {
345
	}
222
	Capability capability = _editor.getCapabilityDomain().getCapability();
346
223
	List operations = capability.getOperations();
347
	/**
224
	_operationsViewer.setInput(operations);
348
	 * Enable or disable the section based on parameter passed.
225
	if (operations.size() != 0 && _selectedOperation != null)
349
	 */
226
	{
350
	public void enable(boolean enabled)
227
	    _page.enableSections(true);
351
	{
228
	    setFocusToOperation(_selectedOperation);
352
	}
229
	}
230
	else
231
	{
232
	    _page.enableSections(false);
233
	}
234
	updateErrorMessage();
235
    }
236
237
    private void updateErrorMessage()
238
    {
239
	Definition defintion = _editor.getCapabilityDomain().getDefinition();
240
	CapabilityWSDLValidator validator = new CapabilityWSDLValidator();
241
	IValidationReport report = validator.validate(defintion);
242
	boolean hasProblem = report.hasErrors() || report.hasWarnings();
243
	if (hasProblem)
244
	{
245
	    // We have a problem, is it an error or just a warning?
246
	    boolean hasError = false;
247
	    String msg;
248
	    if (report.hasErrors())
249
	    {
250
		hasError = true;
251
		msg = report.getErrorMessages()[0].getMessage();
252
	    }
253
	    else
254
	    {
255
		msg = report.getWarningMessages()[0].getMessage();
256
	    }
257
	    _errorLabel.setBackground(getForm().getDisplay().getSystemColor(
258
		    hasError ? SWT.COLOR_RED : SWT.COLOR_YELLOW));
259
	    _errorLabel.setForeground(getForm().getDisplay().getSystemColor(
260
		    hasError ? SWT.COLOR_WHITE : SWT.COLOR_BLACK));
261
	    _errorLabel.setText(" " + msg + " ");
262
	}
263
	else
264
	{
265
	    _errorLabel.setBackground(getForm().getBackground());
266
	    _errorLabel.setForeground(getForm().getForeground());
267
	    _errorLabel.setText("");
268
	}
269
    }
270
271
    /**
272
         * Handle double click.
273
         */
274
    public void handleDoubleClick()
275
    {
276
    }
277
278
    /**
279
         * Handle selection changed.
280
         */
281
    public void handleSelectionChanged(SelectionChangedEvent event)
282
    {
283
	Object[] objects = _operationsViewer.getSelectedObjets();
284
	_removeOperationButton.setEnabled(objects.length > 0 && !_editor.isReadOnly());
285
	if (objects.length > 0)
286
	{
287
	    _selectedOperation = (Operation) objects[0];
288
	    _page.enableSections(true);
289
	    List sections = _page.getSections();
290
	    for (int i = 0; i < sections.size(); i++)
291
	    {
292
		IPageSection section = (IPageSection) sections.get(i);
293
		section.setSelectedObject(_selectedOperation);
294
		section.selectionChanged(event);
295
	    }
296
	}
297
    }
298
299
    /**
300
         * Initialized control listeners.
301
         */
302
    public void hookAllListeners()
303
    {
304
    	getForm().addControlListener(new ControlAdapter() {
305
    	    public void controlResized(ControlEvent e) {
306
    	    	Rectangle formBounds = getForm().getClientArea();
307
    	        Rectangle sectionClientBounds = _sectionClient.getClientArea();
308
    	        Rectangle buttonCompositeBounds = _buttonClient.getClientArea();
309
    	        int width = sectionClientBounds.width-buttonCompositeBounds.width-20;
310
    	        int height = Math.min(formBounds.height, sectionClientBounds.height)-100;
311
    	        Table table = (Table) _operationsViewer.getControl();
312
    	        table.setSize(width,height);    	        
313
    	    }
314
    	});
315
    }
316
317
    /**
318
         * Handle viewer selection changed.
319
         */
320
    public void selectionChanged(SelectionChangedEvent event)
321
    {
322
    }
323
324
    /**
325
         * Update its selected object.
326
         */
327
    public void setSelectedObject(Object object)
328
    {
329
	if (object instanceof Operation)
330
	    this._selectedOperation = (Operation) object;
331
    }
332
333
    private void setFocusToOperation(Operation operation)
334
    {
335
	_selectedOperation = operation;
336
	_operationsViewer.setSelection(new StructuredSelection(operation),
337
		false);
338
    }
339
340
    /**
341
         * Enable or disable the section based on parameter passed.
342
         */
343
    public void enable(boolean enabled)
344
    {
345
    }
346
353
347
}
354
}
348
355
349
class OperationContentProvider implements IStructuredContentProvider
356
class OperationContentProvider implements IStructuredContentProvider
350
{
357
{
351
358
352
    public Object[] getElements(Object inputElement)
359
	public Object[] getElements(Object inputElement)
353
    {
360
	{
354
	if (inputElement instanceof Collection)
361
		if (inputElement instanceof Collection)
355
	{
362
		{
356
	    Collection c = (Collection) inputElement;
363
			Collection c = (Collection) inputElement;
357
	    return c.toArray();
364
			return c.toArray();
358
	}
365
		}
359
	return new Object[0];
366
		return new Object[0];
360
    }
367
	}
361
368
362
    public void dispose()
369
	public void dispose()
363
    {
370
	{
364
    }
371
	}
365
372
366
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
373
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
367
    {
374
	{
368
    }
375
	}
369
}
376
}
370
377
371
class OperationLabelProvider extends LabelProvider
378
class OperationLabelProvider extends LabelProvider
372
{
379
{
373
380
374
    private final static String OPERATION_KEY = "Operation";
381
	private final static String OPERATION_KEY = "Operation";
375
382
376
    private ImageRegistry imageRegistry;
383
	private ImageRegistry imageRegistry;
377
384
378
    public OperationLabelProvider(Shell shell)
385
	public OperationLabelProvider(Shell shell)
379
    {
386
	{
380
	imageRegistry = new ImageRegistry(shell.getDisplay());
387
		imageRegistry = new ImageRegistry(shell.getDisplay());
381
388
382
	Image imgOp = EclipseUtils.loadImage(shell.getDisplay(),
389
		Image imgOp = EclipseUtils.loadImage(shell.getDisplay(),
383
		"icons/obj16/userOperation_obj.gif");
390
				"icons/obj16/userOperation_obj.gif");
384
	imageRegistry.put(OPERATION_KEY, imgOp);
391
		imageRegistry.put(OPERATION_KEY, imgOp);
385
392
386
    }
393
	}
387
394
388
    public Image getImage(Object element)
395
	public Image getImage(Object element)
389
    {
396
	{
390
	if (element instanceof Operation)
397
		if (element instanceof Operation)
391
	    return imageRegistry.get(OPERATION_KEY);
398
			return imageRegistry.get(OPERATION_KEY);
392
	return null;
399
		return null;
393
    }
400
	}
394
401
395
    public String getText(Object element)
402
	public String getText(Object element)
396
    {
397
	if (element instanceof Operation)
398
	{
403
	{
399
	    Operation operation = (Operation) element;
404
		if (element instanceof Operation)
400
	    return operation.getName();
405
		{
406
			Operation operation = (Operation) element;
407
			return operation.getName();
408
		}
409
		return null;
401
	}
410
	}
402
	return null;
403
    }
404
}
411
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/operation/internal/NewExceptionDialog.java (-217 / +219 lines)
Lines 52-282 Link Here
52
/**
52
/**
53
 * 
53
 * 
54
 * Popup dialog to add a new exception to an operation.
54
 * Popup dialog to add a new exception to an operation.
55
 *
55
 * 
56
 */
56
 */
57
57
58
public class NewExceptionDialog extends Dialog
58
public class NewExceptionDialog extends Dialog
59
{
59
{
60
60
61
    private final String _title;
61
	private final String _title;
62
62
63
    private Table _faultsTable;
63
	private Table _faultsTable;
64
64
65
    private TableViewer _faultsViewer;
65
	private TableViewer _faultsViewer;
66
66
67
    private CapabilityDomain _capabilityDomain;
67
	private CapabilityDomain _capabilityDomain;
68
68
69
    private Operation _operation;
69
	private Operation _operation;
70
70
71
    private Label _errorImage;
71
	private Label _errorImage;
72
72
73
    private Label _errorLabel;
73
	private Label _errorLabel;
74
74
75
    private Fault _fault;
75
	private Fault _fault;
76
76
77
    /**
77
	/**
78
     * Creates a new instance of this class.
78
	 * Creates a new instance of this class.
79
     * 
79
	 * 
80
     * @param parentShell
80
	 * @param parentShell
81
     *        Shell.
81
	 *            Shell.
82
     *        
82
	 * 
83
     * @param dialogTitle
83
	 * @param dialogTitle
84
     *        Title of this dialog.
84
	 *            Title of this dialog.
85
     *        
85
	 * 
86
     * @param capabilityDomain
86
	 * @param capabilityDomain
87
     *        Capability domain of capability editor.
87
	 *            Capability domain of capability editor.
88
     *        
88
	 * 
89
     * @param operation
89
	 * @param operation
90
     *        WSDL operation to which this new fault will be added. 
90
	 *            WSDL operation to which this new fault will be added.
91
     */
91
	 */
92
    public NewExceptionDialog(Shell parentShell, String dialogTitle,
92
	public NewExceptionDialog(Shell parentShell, String dialogTitle,
93
	    CapabilityDomain capabilityDomain, Operation operation)
93
			CapabilityDomain capabilityDomain, Operation operation)
94
    {
94
	{
95
	super(parentShell);
95
		super(parentShell);
96
	setShellStyle(getShellStyle() | SWT.RESIZE);
96
		setShellStyle(getShellStyle() | SWT.RESIZE);
97
	_title = dialogTitle;
97
		_title = dialogTitle;
98
	_capabilityDomain = capabilityDomain;
98
		_capabilityDomain = capabilityDomain;
99
	_operation = operation;
99
		_operation = operation;
100
    }
100
	}
101
101
102
    protected void configureShell(Shell shell)
102
	protected void configureShell(Shell shell)
103
    {
103
	{
104
	super.configureShell(shell);
104
		super.configureShell(shell);
105
	if (_title != null)
105
		if (_title != null)
106
	    shell.setText(_title);
106
			shell.setText(_title);
107
    }
107
	}
108
108
109
    protected Control createDialogArea(Composite parent)
109
	protected Control createDialogArea(Composite parent)
110
    {
110
	{
111
	Composite composite = (Composite) super.createDialogArea(parent);
111
		Composite composite = (Composite) super.createDialogArea(parent);
112
	GridLayout layout = new GridLayout();
112
		GridLayout layout = new GridLayout();
113
	layout.numColumns = 2;
113
		layout.numColumns = 2;
114
	composite.setLayout(layout);
114
		composite.setLayout(layout);
115
115
116
	Label exceptionTypeLabel = new Label(composite, SWT.NONE);
116
		Label exceptionTypeLabel = new Label(composite, SWT.NONE);
117
	exceptionTypeLabel.setText(Messages.EXCPETION_TYPE_TYPE);
117
		exceptionTypeLabel.setText(Messages.EXCPETION_TYPE_TYPE);
118
	GridData gd = new GridData();
118
		GridData gd = new GridData();
119
	gd.horizontalSpan = 2;
119
		gd.horizontalSpan = 2;
120
	exceptionTypeLabel.setLayoutData(gd);
120
		exceptionTypeLabel.setLayoutData(gd);
121
121
122
	_faultsTable = new Table(composite, SWT.V_SCROLL | SWT.H_SCROLL
122
		_faultsTable = new Table(composite, SWT.V_SCROLL | SWT.H_SCROLL
123
		| SWT.FULL_SELECTION);
123
				| SWT.FULL_SELECTION);
124
	_faultsViewer = new TableViewer(_faultsTable);
124
		_faultsViewer = new TableViewer(_faultsTable);
125
	gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
125
		gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
126
	gd.heightHint = 225;
126
		gd.heightHint = 225;
127
	gd.widthHint = 200;
127
		gd.widthHint = 200;
128
	gd.horizontalSpan = ((GridLayout) composite.getLayout()).numColumns;
128
		gd.horizontalSpan = ((GridLayout) composite.getLayout()).numColumns;
129
129
130
	TableColumn column = new TableColumn(_faultsTable, SWT.NONE, 0);
130
		TableColumn column = new TableColumn(_faultsTable, SWT.NONE, 0);
131
	column.setText("");
131
		column.setText("");
132
	column.setWidth(20);
132
		column.setWidth(20);
133
	column.setResizable(false);
133
		column.setResizable(false);
134
134
135
	column = new TableColumn(_faultsTable, SWT.NONE, 1);
135
		column = new TableColumn(_faultsTable, SWT.NONE, 1);
136
	column.setText(Messages.EXCPETION_TYPE);
136
		column.setText(Messages.EXCPETION_TYPE);
137
	column.setWidth(100);
137
		column.setWidth(100);
138
138
139
	_faultsTable.redraw();
139
		_faultsTable.redraw();
140
	_faultsTable.setHeaderVisible(true);
140
		_faultsTable.setHeaderVisible(true);
141
	_faultsTable.setLinesVisible(true);
141
		_faultsTable.setLinesVisible(true);
142
142
143
	_faultsViewer.getControl().setLayoutData(gd);
143
		_faultsViewer.getControl().setLayoutData(gd);
144
	_faultsViewer.setContentProvider(new ExceptionContentProvider());
144
		_faultsViewer.setContentProvider(new ExceptionContentProvider());
145
	_faultsViewer.setLabelProvider(new ExceptionLabelProvider());
145
		_faultsViewer.setLabelProvider(new ExceptionLabelProvider());
146
	_faultsViewer
146
		_faultsViewer
147
		.addSelectionChangedListener(new ISelectionChangedListener()
147
				.addSelectionChangedListener(new ISelectionChangedListener() {
148
					public void selectionChanged(SelectionChangedEvent event)
149
					{
150
						getButton(IDialogConstants.OK_ID).setEnabled(true);
151
					}
152
				});
153
154
		_errorImage = new Label(composite, SWT.NONE);
155
		_errorLabel = new Label(composite, SWT.NONE);
156
157
		hookAllListeners();
158
		initializeControls();
159
160
		applyDialogFont(composite);
161
		return composite;
162
	}
163
164
	private void hookAllListeners()
165
	{
166
	}
167
168
	protected Control createButtonBar(Composite parent)
169
	{
170
		Control ret = super.createButtonBar(parent);
171
		getButton(IDialogConstants.OK_ID).setEnabled(false);
172
		return ret;
173
	}
174
175
	private void initializeControls()
176
	{
177
		boolean baseFaultExists = false;
178
		java.util.List faultElements = WsdlUtils
179
				.getOperationFaultElements(_operation);
180
		for (int i = 0; i < faultElements.size(); i++)
181
		{
182
			XSDElementDeclaration faultElement = (XSDElementDeclaration) faultElements
183
					.get(i);
184
			String type = WsdlUtils.getFaultType(faultElement);
185
			if ("BaseFaultType".equals(type))
186
				baseFaultExists = true;
187
		}
188
		java.util.List list = new ArrayList();
189
		if (!baseFaultExists)
148
		{
190
		{
149
		    public void selectionChanged(SelectionChangedEvent event)
191
			Fault baseFault = createBaseFaultFault();
150
		    {
192
			list.add(baseFault);
151
			getButton(IDialogConstants.OK_ID).setEnabled(true);
193
			_faultsViewer.getTable().setBackground(
152
		    }
194
					getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
153
		});
195
			_errorImage.setImage(null);
154
196
			_errorLabel.setText("");
155
	_errorImage = new Label(composite, SWT.NONE);
197
		} else
156
	_errorLabel = new Label(composite, SWT.NONE);
198
		{
157
199
			_faultsViewer.getTable().setBackground(
158
	hookAllListeners();
200
					getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
159
	initializeControls();
201
			Image image = getShell().getDisplay()
160
202
					.getSystemImage(SWT.ICON_ERROR);
161
	applyDialogFont(composite);
203
			_errorImage.setImage(image);
162
	return composite;
204
			GridData gd = new GridData();
163
    }
205
			gd.heightHint = 12;
164
206
			gd.widthHint = 12;
165
    private void hookAllListeners()
207
			_errorImage.setLayoutData(gd);
166
    {
208
			_errorLabel.setText(Messages.NO_ENTRIES_AVAIL_INFO_);
167
    }
209
		}
168
210
		_faultsViewer.setInput(list);
169
    protected Control createButtonBar(Composite parent)
211
	}
170
    {
212
171
	Control ret = super.createButtonBar(parent);
213
	private Fault createBaseFaultFault()
172
	getButton(IDialogConstants.OK_ID).setEnabled(false);
214
	{
173
	return ret;
215
		Definition definition = _capabilityDomain.getCapability()
174
    }
216
				.getDefinition();
175
217
176
    private void initializeControls()
218
		Fault fault = WSDLFactory.eINSTANCE.createFault();
177
    {
219
		fault.setName(_operation.getName() + "Fault");
178
	boolean baseFaultExists = false;
220
		fault.setEnclosingDefinition(definition);
179
	java.util.List faultElements = WsdlUtils
221
180
		.getOperationFaultElements(_operation);
222
		Message faultMessage = WSDLFactory.eINSTANCE.createMessage();
181
	for (int i = 0; i < faultElements.size(); i++)
223
		faultMessage.setQName(new QName(definition.getTargetNamespace(),
182
	{
224
				_operation.getName() + "Fault"));
183
	    XSDElementDeclaration faultElement = (XSDElementDeclaration) faultElements
225
		faultMessage.setEnclosingDefinition(definition);
184
		    .get(i);
226
185
	    String type = WsdlUtils.getFaultType(faultElement);
227
		Part faultPart = WSDLFactory.eINSTANCE.createPart();
186
	    if ("BaseFaultType".equals(type))
228
		faultPart.setName(_operation.getName() + "Fault");
187
		baseFaultExists = true;
229
		faultPart.setEnclosingDefinition(definition);
188
	}
230
		XSDElementDeclaration faultElement = createBaseFaultElement();
189
	java.util.List list = new ArrayList();
231
		faultPart.setElementDeclaration(faultElement);
190
	if (!baseFaultExists)
232
		faultPart.setElementName(new QName(faultElement.getTargetNamespace(),
191
	{
233
				faultElement.getName()));
192
	    Fault baseFault = createBaseFaultFault();
234
193
	    list.add(baseFault);
235
		faultMessage.addPart(faultPart);
194
	    _faultsViewer.getTable().setBackground(
236
195
		    getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
237
		fault.setEMessage(faultMessage);
196
	    _errorImage.setImage(null);
238
197
	    _errorLabel.setText("");
239
		return fault;
198
	}
240
	}
199
	else
241
200
	{
242
	private XSDElementDeclaration createBaseFaultElement()
201
	    _faultsViewer.getTable().setBackground(
243
	{
202
		    getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
244
		Definition definition = _capabilityDomain.getCapability()
203
	    Image image = getShell().getDisplay()
245
				.getDefinition();
204
		    .getSystemImage(SWT.ICON_ERROR);
246
		XSDSchema typesSchema = WsdlUtils.getSchema(definition, definition
205
	    _errorImage.setImage(image);
247
				.getTargetNamespace());
206
	    GridData gd = new GridData();
248
207
	    gd.heightHint = 12;
249
		XSDElementDeclaration faultElement = XSDFactory.eINSTANCE
208
	    gd.widthHint = 12;
250
				.createXSDElementDeclaration();
209
	    _errorImage.setLayoutData(gd);
251
		faultElement.setName(_operation.getName() + "Fault");
210
	    _errorLabel.setText(Messages.NO_ENTRIES_AVAIL_INFO_);
252
		typesSchema.getContents().add(faultElement);
211
	}
253
212
	_faultsViewer.setInput(list);
254
		XSDComplexTypeDefinition complexTypeDefinition = XSDFactory.eINSTANCE
213
    }
255
				.createXSDComplexTypeDefinition();
214
    
256
		complexTypeDefinition
215
    private Fault createBaseFaultFault()
257
				.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
216
    {
258
		XSDSimpleTypeDefinition simpleTypeDef = XSDFactory.eINSTANCE
217
	Definition definition = _capabilityDomain.getDefinition();
259
				.createXSDSimpleTypeDefinition();
218
	
260
		simpleTypeDef.setName("BaseFaultType");
219
	Fault fault = WSDLFactory.eINSTANCE.createFault();
261
		simpleTypeDef.setTargetNamespace(WsdmConstants.WSBF_NS);
220
	fault.setName(_operation.getName() + "Fault");
262
		complexTypeDefinition.setBaseTypeDefinition(simpleTypeDef);
221
	fault.setEnclosingDefinition(definition);
263
222
	
264
		faultElement.setAnonymousTypeDefinition(complexTypeDefinition);
223
	Message faultMessage = WSDLFactory.eINSTANCE.createMessage();
265
		return faultElement;
224
	faultMessage.setQName(new QName(definition.getTargetNamespace(),_operation.getName() + "Fault"));
266
	}
225
	faultMessage.setEnclosingDefinition(definition);
267
226
	
268
	protected void okPressed()
227
	Part faultPart = WSDLFactory.eINSTANCE.createPart();
269
	{
228
	faultPart.setName(_operation.getName() + "Fault");
270
		StructuredSelection ss = (StructuredSelection) _faultsViewer
229
	faultPart.setEnclosingDefinition(definition);	
271
				.getSelection();
230
	XSDElementDeclaration faultElement = createBaseFaultElement();
272
		_fault = (Fault) ss.toArray()[0];
231
	faultPart.setElementDeclaration(faultElement);
273
		super.okPressed();
232
	faultPart.setElementName(new QName(faultElement.getTargetNamespace(), faultElement.getName()));
274
	}
233
	
275
234
	faultMessage.addPart(faultPart);
276
	/**
235
	
277
	 * 
236
	fault.setEMessage(faultMessage);
278
	 * @return New wsdl fault.
237
	
279
	 */
238
	return fault;	
280
	public Fault getFault()
239
    }
281
	{
240
282
		return _fault;
241
    private XSDElementDeclaration createBaseFaultElement()
283
	}
242
    {
243
	Definition definition = _capabilityDomain.getDefinition();
244
	XSDSchema typesSchema = WsdlUtils.getSchema(definition, definition
245
		.getTargetNamespace());
246
247
	XSDElementDeclaration faultElement = XSDFactory.eINSTANCE
248
		.createXSDElementDeclaration();
249
	faultElement.setName(_operation.getName() + "Fault");
250
	typesSchema.getContents().add(faultElement);
251
252
	XSDComplexTypeDefinition complexTypeDefinition = XSDFactory.eINSTANCE
253
		.createXSDComplexTypeDefinition();
254
	complexTypeDefinition
255
		.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
256
	XSDSimpleTypeDefinition simpleTypeDef = XSDFactory.eINSTANCE
257
		.createXSDSimpleTypeDefinition();
258
	simpleTypeDef.setName("BaseFaultType");
259
	simpleTypeDef.setTargetNamespace(WsdmConstants.WSBF_NS);
260
	complexTypeDefinition.setBaseTypeDefinition(simpleTypeDef);
261
262
	faultElement.setAnonymousTypeDefinition(complexTypeDefinition);
263
	return faultElement;
264
    }
265
266
    protected void okPressed()
267
    {
268
	StructuredSelection ss = (StructuredSelection) _faultsViewer
269
		.getSelection();
270
	_fault = (Fault) ss.toArray()[0];
271
	super.okPressed();
272
    }
273
274
    /**
275
     * 
276
     * @return New wsdl fault.
277
     */
278
    public Fault getFault()
279
    {
280
	return _fault;
281
    }
282
}
284
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/operation/internal/NewOperationDialog.java (-600 / +604 lines)
Lines 13-19 Link Here
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.pages.operation.internal;
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.pages.operation.internal;
14
14
15
import java.util.Arrays;
15
import java.util.Arrays;
16
import java.util.Collection;
17
import java.util.LinkedList;
16
import java.util.LinkedList;
18
17
19
import javax.xml.namespace.QName;
18
import javax.xml.namespace.QName;
Lines 22-44 Link Here
22
import org.eclipse.jface.dialogs.IDialogConstants;
21
import org.eclipse.jface.dialogs.IDialogConstants;
23
import org.eclipse.jface.dialogs.MessageDialog;
22
import org.eclipse.jface.dialogs.MessageDialog;
24
import org.eclipse.jface.viewers.ColumnWeightData;
23
import org.eclipse.jface.viewers.ColumnWeightData;
25
import org.eclipse.jface.viewers.IBaseLabelProvider;
26
import org.eclipse.jface.viewers.ISelection;
24
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelectionChangedListener;
25
import org.eclipse.jface.viewers.ISelectionChangedListener;
28
import org.eclipse.jface.viewers.IStructuredContentProvider;
29
import org.eclipse.jface.viewers.ITableLabelProvider;
30
import org.eclipse.jface.viewers.LabelProvider;
31
import org.eclipse.jface.viewers.SelectionChangedEvent;
26
import org.eclipse.jface.viewers.SelectionChangedEvent;
32
import org.eclipse.jface.viewers.StructuredSelection;
27
import org.eclipse.jface.viewers.StructuredSelection;
33
import org.eclipse.jface.viewers.TableLayout;
28
import org.eclipse.jface.viewers.TableLayout;
34
import org.eclipse.jface.viewers.TableViewer;
29
import org.eclipse.jface.viewers.TableViewer;
35
import org.eclipse.jface.viewers.TreeViewer;
30
import org.eclipse.jface.viewers.TreeViewer;
36
import org.eclipse.jface.viewers.Viewer;
37
import org.eclipse.jface.window.Window;
31
import org.eclipse.jface.window.Window;
38
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.events.ModifyEvent;
33
import org.eclipse.swt.events.ModifyEvent;
40
import org.eclipse.swt.events.ModifyListener;
34
import org.eclipse.swt.events.ModifyListener;
41
import org.eclipse.swt.graphics.Image;
42
import org.eclipse.swt.layout.GridData;
35
import org.eclipse.swt.layout.GridData;
43
import org.eclipse.swt.layout.GridLayout;
36
import org.eclipse.swt.layout.GridLayout;
44
import org.eclipse.swt.widgets.Button;
37
import org.eclipse.swt.widgets.Button;
Lines 61-67 Link Here
61
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
54
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
62
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages;
55
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages;
63
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
56
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
64
import org.eclipse.tptp.wsdm.tooling.util.internal.ResourcePropertiesProvider;
65
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
57
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
66
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
58
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
67
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
59
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
Lines 79-690 Link Here
79
import org.eclipse.xsd.XSDDerivationMethod;
71
import org.eclipse.xsd.XSDDerivationMethod;
80
import org.eclipse.xsd.XSDElementDeclaration;
72
import org.eclipse.xsd.XSDElementDeclaration;
81
import org.eclipse.xsd.XSDFactory;
73
import org.eclipse.xsd.XSDFactory;
82
import org.eclipse.xsd.XSDFeature;
83
import org.eclipse.xsd.XSDModelGroup;
74
import org.eclipse.xsd.XSDModelGroup;
84
import org.eclipse.xsd.XSDParticle;
75
import org.eclipse.xsd.XSDParticle;
85
import org.eclipse.xsd.XSDSchema;
76
import org.eclipse.xsd.XSDSchema;
86
import org.eclipse.xsd.XSDSimpleTypeDefinition;
77
import org.eclipse.xsd.XSDSimpleTypeDefinition;
87
78
88
/**
79
/**
89
 * Popup dialog to create new operation in capability. 
80
 * Popup dialog to create new operation in capability.
90
 * 
81
 * 
91
 */
82
 */
92
83
93
public class NewOperationDialog extends Dialog
84
public class NewOperationDialog extends Dialog {
94
{
95
85
96
    private final String _title;
86
	private final String _title;
97
87
98
    private Text _methodName;
88
	private Text _methodName;
99
89
100
    private TreeViewer _dataTypeViewer;
90
	private TreeViewer _dataTypeViewer;
101
    
91
102
    private Button _importTypeButton;
92
	private Button _importTypeButton;
103
93
104
    private Table _parametersTable;
94
	private Table _parametersTable;
105
95
106
    private TableViewer _paramViewer;
96
	private TableViewer _paramViewer;
107
97
108
    private Button _addParameterButton;
98
	private Button _addParameterButton;
109
    
99
110
    private Button _editParameterButton;
100
	private Button _editParameterButton;
111
101
112
    private Button _removeParameterButton;
102
	private Button _removeParameterButton;
113
103
114
    private Operation _operation;
104
	private Operation _operation;
115
105
116
    private final String DEFAULT_OPERATION_NAME = "foo";
106
	private final String DEFAULT_OPERATION_NAME = "foo";
117
107
118
    private XSDSchema _typesSchema;
108
	private XSDSchema _typesSchema;
119
109
120
    private Definition _definition;
110
	private Definition _definition;
121
111
122
    private java.util.List _paramList = new LinkedList();
112
	private java.util.List _paramList = new LinkedList();
123
113
124
    private Capability _model;
114
	private Capability _model;
125
115
126
    private CapabilityDomain _capabilityDomain;
116
	private CapabilityDomain _capabilityDomain;
127
117
128
    private static final String BASE_FAULT_FILE = "platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/WS-BaseFaults-1_2.xsd";
118
	private static final String BASE_FAULT_FILE = "platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/WS-BaseFaults-1_2.xsd";
129
    
119
130
    private DataType _returnType; 
120
	private DataType _returnType;
131
121
132
    /**
122
	/**
133
     * Creates a new instance of this class.
123
	 * Creates a new instance of this class.
134
     * 
124
	 * 
135
     * @param parentShell
125
	 * @param parentShell
136
     *        Shell.
126
	 *            Shell.
137
     *        
127
	 * 
138
     * @param dialogTitle
128
	 * @param dialogTitle
139
     *        Title of this dialog.
129
	 *            Title of this dialog.
140
     *        
130
	 * 
141
     * @param capabilityDomain
131
	 * @param capabilityDomain
142
     *        Capability domain of capability editor.
132
	 *            Capability domain of capability editor.
143
     *        
133
	 * 
144
     */
134
	 */
145
    public NewOperationDialog(Shell parentShell, String dialogTitle,
135
	public NewOperationDialog(Shell parentShell, String dialogTitle,
146
	    CapabilityDomain capabilityDomain)
136
			CapabilityDomain capabilityDomain)
147
    {
137
	{
148
	super(parentShell);
138
		super(parentShell);
149
	setShellStyle(getShellStyle() | SWT.RESIZE);
139
		setShellStyle(getShellStyle() | SWT.RESIZE);
150
	_title = dialogTitle;
140
		_title = dialogTitle;
151
	_definition = capabilityDomain.getDefinition();
141
		_model = capabilityDomain.getCapability();
152
	_model = capabilityDomain.getCapability();
142
		_definition = _model.getDefinition();
153
	_capabilityDomain = capabilityDomain;
143
		_capabilityDomain = capabilityDomain;
154
	_operation = WSDLFactory.eINSTANCE.createOperation();
144
		_operation = WSDLFactory.eINSTANCE.createOperation();
155
	_operation.setName(DEFAULT_OPERATION_NAME);
145
		_operation.setName(DEFAULT_OPERATION_NAME);
156
    }
146
	}
157
147
158
    protected void configureShell(Shell shell)
148
	protected void configureShell(Shell shell) 
159
    {
149
	{
160
	super.configureShell(shell);
150
		super.configureShell(shell);
161
	if (_title != null)
151
		if (_title != null)
162
	    shell.setText(_title);
152
			shell.setText(_title);
163
    }
153
	}
164
154
165
    protected Control createDialogArea(Composite parent)
155
	protected Control createDialogArea(Composite parent) 
166
    {
156
	{
167
	Composite container = (Composite) super.createDialogArea(parent);
157
		Composite container = (Composite) super.createDialogArea(parent);
168
	GridLayout layout = new GridLayout(2, true);
158
		GridLayout layout = new GridLayout(2, true);
169
	container.setLayout(layout);
159
		container.setLayout(layout);
170
160
171
	Composite lhsComposite = new Composite(container, SWT.NONE);
161
		Composite lhsComposite = new Composite(container, SWT.NONE);
172
	layout = new GridLayout(2, false);
162
		layout = new GridLayout(2, false);
173
	layout.verticalSpacing = 5;
163
		layout.verticalSpacing = 5;
174
	lhsComposite.setLayout(layout);
164
		lhsComposite.setLayout(layout);
175
	GridData gd = new GridData();
165
		GridData gd = new GridData();
176
	gd.grabExcessHorizontalSpace = true;
166
		gd.grabExcessHorizontalSpace = true;
177
	lhsComposite.setLayoutData(gd);
167
		lhsComposite.setLayoutData(gd);
178
168
179
	Composite rhsComposite = new Composite(container, SWT.NONE);
169
		Composite rhsComposite = new Composite(container, SWT.NONE);
180
	layout = new GridLayout();
170
		layout = new GridLayout();
181
	layout.verticalSpacing = 5;
171
		layout.verticalSpacing = 5;
182
	rhsComposite.setLayout(layout);
172
		rhsComposite.setLayout(layout);
183
	gd = new GridData();
173
		gd = new GridData();
184
	gd.grabExcessHorizontalSpace = true;
174
		gd.grabExcessHorizontalSpace = true;
185
	rhsComposite.setLayoutData(gd);
175
		rhsComposite.setLayoutData(gd);
186
	
176
187
	createLeftCompositeArea(lhsComposite);
177
		createLeftCompositeArea(lhsComposite);
188
	createRightCompositeArea(rhsComposite);
178
		createRightCompositeArea(rhsComposite);
189
	
179
190
	initializeControls();
180
		initializeControls();
191
	hookAllListeners();
181
		hookAllListeners();
192
182
193
	applyDialogFont(container);
183
		applyDialogFont(container);
194
	return container;
184
		return container;
195
    }
185
	}
196
    
186
197
    private void createLeftCompositeArea(Composite lhsComposite)
187
	private void createLeftCompositeArea(Composite lhsComposite) 
198
    {
188
	{
199
	Label methodNameLabel = new Label(lhsComposite, SWT.NONE);
189
		Label methodNameLabel = new Label(lhsComposite, SWT.NONE);
200
	methodNameLabel.setText(Messages.OP_NAME);
190
		methodNameLabel.setText(Messages.OP_NAME);
201
	GridData gd = new GridData();
191
		GridData gd = new GridData();
202
	gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
192
		gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
203
	methodNameLabel.setLayoutData(gd);
193
		methodNameLabel.setLayoutData(gd);
204
194
205
	_methodName = new Text(lhsComposite, SWT.SINGLE | SWT.BORDER);
195
		_methodName = new Text(lhsComposite, SWT.SINGLE | SWT.BORDER);
206
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
196
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
207
	gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
197
		gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
208
	_methodName.setLayoutData(gd);
198
		_methodName.setLayoutData(gd);
209
199
210
	Label returnTypeLabel = new Label(lhsComposite, SWT.NONE);
200
		Label returnTypeLabel = new Label(lhsComposite, SWT.NONE);
211
	returnTypeLabel.setText(Messages.OP_RETURN_TYPE);
201
		returnTypeLabel.setText(Messages.OP_RETURN_TYPE);
212
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
202
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
213
	gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
203
		gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
214
	returnTypeLabel.setLayoutData(gd);
204
		returnTypeLabel.setLayoutData(gd);
215
205
216
	_dataTypeViewer = new TreeViewer(lhsComposite, SWT.BORDER | SWT.H_SCROLL
206
		_dataTypeViewer = new TreeViewer(lhsComposite, SWT.BORDER
217
			| SWT.V_SCROLL);
207
				| SWT.H_SCROLL | SWT.V_SCROLL);
218
	GridData data = new GridData();
208
		GridData data = new GridData();
219
	data.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
209
		data.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
220
	data.heightHint = 220;
210
		data.heightHint = 220;
221
	data.widthHint = 200;
211
		data.widthHint = 200;
222
	data.grabExcessHorizontalSpace = true;
212
		data.grabExcessHorizontalSpace = true;
223
	data.grabExcessVerticalSpace = true;
213
		data.grabExcessVerticalSpace = true;
224
	_dataTypeViewer.getControl().setLayoutData(data);
214
		_dataTypeViewer.getControl().setLayoutData(data);
225
	DataTypesContentProvider contentProvider = new DataTypesContentProvider();
215
		DataTypesContentProvider contentProvider = new DataTypesContentProvider();
226
	_dataTypeViewer.setContentProvider(contentProvider);
216
		_dataTypeViewer.setContentProvider(contentProvider);
227
	_dataTypeViewer.setLabelProvider(contentProvider.getLabelProvider());
217
		_dataTypeViewer.setLabelProvider(contentProvider.getLabelProvider());
228
	_dataTypeViewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
218
		_dataTypeViewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
229
			FormToolkit.TREE_BORDER);
219
				FormToolkit.TREE_BORDER);
230
	
220
231
	_importTypeButton = new Button(lhsComposite, SWT.PUSH);
221
		_importTypeButton = new Button(lhsComposite, SWT.PUSH);
232
	_importTypeButton.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.IMPORT_COMPLEX_DATA_TYPE);
222
		_importTypeButton
233
	data = new GridData();
223
				.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.IMPORT_COMPLEX_DATA_TYPE);
234
	data.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
224
		data = new GridData();
235
	_importTypeButton.setLayoutData(data);
225
		data.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
236
    }
226
		_importTypeButton.setLayoutData(data);
237
    
227
	}
238
    private void createRightCompositeArea(Composite rhsComposite)
228
239
    {
229
	private void createRightCompositeArea(Composite rhsComposite) 
240
	Label parametersLabel = new Label(rhsComposite, SWT.NONE);
230
	{
241
	parametersLabel.setText(Messages.PARAMETERS);
231
		Label parametersLabel = new Label(rhsComposite, SWT.NONE);
242
	GridData data = new GridData();
232
		parametersLabel.setText(Messages.PARAMETERS);
243
	data.horizontalSpan = ((GridLayout) rhsComposite.getLayout()).numColumns;
233
		GridData data = new GridData();
244
	parametersLabel.setLayoutData(data);
234
		data.horizontalSpan = ((GridLayout) rhsComposite.getLayout()).numColumns;
245
235
		parametersLabel.setLayoutData(data);
246
	_parametersTable = new Table(rhsComposite, SWT.V_SCROLL | SWT.H_SCROLL
236
247
		| SWT.FULL_SELECTION);
237
		_parametersTable = new Table(rhsComposite, SWT.V_SCROLL | SWT.H_SCROLL
248
	_paramViewer = new TableViewer(_parametersTable);
238
				| SWT.FULL_SELECTION);
249
	GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
239
		_paramViewer = new TableViewer(_parametersTable);
250
	gd = new GridData();
240
		GridData gd = new GridData(GridData.FILL_HORIZONTAL
251
	gd.heightHint = 225;
241
				| GridData.FILL_VERTICAL);
252
	gd.widthHint = 200;
242
		gd = new GridData();
253
	gd.horizontalSpan = ((GridLayout) rhsComposite.getLayout()).numColumns;
243
		gd.heightHint = 225;
254
	_paramViewer.getControl().setLayoutData(gd);
244
		gd.widthHint = 200;
255
245
		gd.horizontalSpan = ((GridLayout) rhsComposite.getLayout()).numColumns;
256
	String[] header = new String[] { Messages.PARAM_NAME, Messages.PARAM_TYPE };
246
		_paramViewer.getControl().setLayoutData(gd);
257
	for (int i = 0; i < header.length; i++)
247
258
	{
248
		String[] header = new String[] { Messages.PARAM_NAME,
259
	    TableColumn col = new TableColumn(_paramViewer.getTable(),
249
				Messages.PARAM_TYPE };
260
		    SWT.CENTER);
250
		for (int i = 0; i < header.length; i++) 
261
	    col.setText(header[i]);
251
		{
262
	    col.setWidth(50);
252
			TableColumn col = new TableColumn(_paramViewer.getTable(),
263
	}
253
					SWT.CENTER);
264
254
			col.setText(header[i]);
265
	TableLayout tl = new TableLayout();
255
			col.setWidth(50);
266
	tl.addColumnData(new ColumnWeightData(50));
256
		}
267
	tl.addColumnData(new ColumnWeightData(50));
257
268
	_paramViewer.getTable().setLayout(tl);
258
		TableLayout tl = new TableLayout();
269
259
		tl.addColumnData(new ColumnWeightData(50));
270
	_paramViewer.getTable().setHeaderVisible(true);
260
		tl.addColumnData(new ColumnWeightData(50));
271
	_paramViewer.getTable().setLinesVisible(true);
261
		_paramViewer.getTable().setLayout(tl);
272
262
273
	_paramViewer.setContentProvider(new ParamContentProvider());
263
		_paramViewer.getTable().setHeaderVisible(true);
274
	_paramViewer.setLabelProvider(new ParamLabelProvider());
264
		_paramViewer.getTable().setLinesVisible(true);
275
265
276
	Composite paramButtonComposite = new Composite(rhsComposite, SWT.NULL);
266
		_paramViewer.setContentProvider(new ParamContentProvider());
277
	GridLayout layout = new GridLayout(3, false);
267
		_paramViewer.setLabelProvider(new ParamLabelProvider());
278
	layout.marginWidth = 0;
268
279
	paramButtonComposite.setLayout(layout);
269
		Composite paramButtonComposite = new Composite(rhsComposite, SWT.NULL);
280
270
		GridLayout layout = new GridLayout(3, false);
281
	_addParameterButton = new Button(paramButtonComposite, SWT.PUSH);
271
		layout.marginWidth = 0;
282
	_addParameterButton.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.ADD_BUTTON_LABEL);
272
		paramButtonComposite.setLayout(layout);
283
	
273
284
	_editParameterButton = new Button(paramButtonComposite, SWT.PUSH);
274
		_addParameterButton = new Button(paramButtonComposite, SWT.PUSH);
285
	_editParameterButton.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.EDIT_BUTTON_LABEL);
275
		_addParameterButton
286
	
276
				.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.ADD_BUTTON_LABEL);
287
	_removeParameterButton = new Button(paramButtonComposite, SWT.PUSH);
277
288
	_removeParameterButton.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL);	
278
		_editParameterButton = new Button(paramButtonComposite, SWT.PUSH);
289
    }
279
		_editParameterButton
290
    
280
				.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.EDIT_BUTTON_LABEL);
291
    /**
281
292
     * 
282
		_removeParameterButton = new Button(paramButtonComposite, SWT.PUSH);
293
     * @return New operation.
283
		_removeParameterButton
294
     */
284
				.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL);
295
    public Operation getOperation()
285
	}
296
    {
286
297
	return _operation;
287
	/**
298
    }
288
	 * 
299
    
289
	 * @return New operation.
300
    /**
290
	 */
301
     * 
291
	public Operation getOperation() 
302
     * @return Data type for operation return type.
292
	{
303
     */
293
		return _operation;
304
    public DataType getReturnType()
294
	}
305
    {
295
306
	return _returnType;
296
	/**
307
    }
297
	 * 
308
    
298
	 * @return Data type for operation return type.
309
    /**
299
	 */
310
     * 
300
	public DataType getReturnType() 
311
     * @return Input parameter for operation.
301
	{
312
     */
302
		return _returnType;
313
    public java.util.List getInputParams()
303
	}
314
    {
304
315
	return _paramList;
305
	/**
316
    }
306
	 * 
317
307
	 * @return Input parameter for operation.
318
    private void hookAllListeners()
308
	 */
319
    {
309
	public java.util.List getInputParams() 
320
	_methodName.addModifyListener(new ModifyListener()
310
	{
321
	{
311
		return _paramList;
322
	    public void modifyText(ModifyEvent e)
312
	}
323
	    {
313
324
		getButton(IDialogConstants.OK_ID).setEnabled(
314
	private void hookAllListeners() 
325
			!_methodName.getText().trim().equals(""));
315
	{
326
	    }
316
		_methodName.addModifyListener(new ModifyListener() 
327
	});
317
		{
328
	_dataTypeViewer.addSelectionChangedListener(new ISelectionChangedListener(){
318
			public void modifyText(ModifyEvent e) 
329
		public void selectionChanged(SelectionChangedEvent event) {	
319
			{
330
			getButton(IDialogConstants.OK_ID).setEnabled(getSelectedViewerObject() instanceof DataType);
320
				getButton(IDialogConstants.OK_ID).setEnabled(
331
		}});
321
						!_methodName.getText().trim().equals(""));
332
	_importTypeButton.addListener(SWT.Selection, new Listener()
322
			}
333
	{
323
		});
334
	    public void handleEvent(Event event)
324
		_dataTypeViewer
335
	    {
325
				.addSelectionChangedListener(new ISelectionChangedListener() 
336
		importComplexTypes();
326
				{
337
	    }
327
					public void selectionChanged(SelectionChangedEvent event) 
338
	});	
328
					{
339
	_addParameterButton.addListener(SWT.Selection, new Listener()
329
						getButton(IDialogConstants.OK_ID).setEnabled(
340
	{
330
								getSelectedViewerObject() instanceof DataType);
341
	    public void handleEvent(Event event)
331
					}
342
	    {
332
				});
343
		addParameter();
333
		_importTypeButton.addListener(SWT.Selection, new Listener() 
344
	    }
334
		{
345
	});
335
			public void handleEvent(Event event) 
346
	_editParameterButton.addListener(SWT.Selection, new Listener()
336
			{
347
	{
337
				importComplexTypes();
348
	    public void handleEvent(Event event)
338
			}
349
	    {
339
		});
350
		editParameter();
340
		_addParameterButton.addListener(SWT.Selection, new Listener() 
351
	    }
341
		{
352
	});	
342
			public void handleEvent(Event event) 
353
	_removeParameterButton.addListener(SWT.Selection, new Listener()
343
			{
354
	{
344
				addParameter();
355
	    public void handleEvent(Event event)
345
			}
356
	    {
346
		});
357
		removeParameter();
347
		_editParameterButton.addListener(SWT.Selection, new Listener() 
358
	    }
348
		{
359
	});
349
			public void handleEvent(Event event) 
360
	_paramViewer.addSelectionChangedListener(new ISelectionChangedListener()
350
			{
361
	{
351
				editParameter();
362
	    public void selectionChanged(SelectionChangedEvent event)
352
			}
363
	    {
353
		});
364
		ISelection selection = event.getSelection();
354
		_removeParameterButton.addListener(SWT.Selection, new Listener() 
365
		_editParameterButton.setEnabled(!selection.isEmpty());
355
		{
366
		_removeParameterButton.setEnabled(!selection.isEmpty());
356
			public void handleEvent(Event event) 
367
	    }
357
			{
368
	});
358
				removeParameter();
369
    }
359
			}
370
    
360
		});
371
    private void importComplexTypes()
361
		_paramViewer
372
    {
362
				.addSelectionChangedListener(new ISelectionChangedListener() 
373
	ImportComplexTypeAction action = new ImportComplexTypeAction(getShell());
363
				{
374
	action.run();
364
					public void selectionChanged(SelectionChangedEvent event)
375
	
365
					{
376
	_dataTypeViewer.refresh();
366
						ISelection selection = event.getSelection();
377
	
367
						_editParameterButton.setEnabled(!selection.isEmpty());
378
	DataTypesCollection instance = DataTypesCollection.getInstance();	
368
						_removeParameterButton.setEnabled(!selection.isEmpty());
379
	DataType stringDataType = instance.getDataType("string");
369
					}
380
	_dataTypeViewer.setSelection(new StructuredSelection(stringDataType), true);
370
				});
381
    }
371
	}
382
    
372
383
    private void addParameter()
373
	private void importComplexTypes() 
384
    {
374
	{
385
	NewParameterDialog dlg = new NewParameterDialog(getShell(),
375
		ImportComplexTypeAction action = new ImportComplexTypeAction(getShell());
386
		Messages.ADD_PARAM, _paramList, null);
376
		action.run();
387
	if (dlg.open() == Window.OK)
377
388
	{
378
		_dataTypeViewer.refresh();
389
	    InputParameter parameter = dlg.getParameter();
379
390
	    _paramList.add(parameter);
380
		DataTypesCollection instance = DataTypesCollection.getInstance();
391
	    refreshParamTable();
381
		DataType stringDataType = instance.getDataType("string");
392
	}
382
		_dataTypeViewer.setSelection(new StructuredSelection(stringDataType),
393
    }
383
				true);
394
    
384
	}
395
    private void editParameter()
385
396
    {
386
	private void addParameter() 
397
	InputParameter parameter = getSelectedParameter();
387
	{
398
	NewParameterDialog dlg = new NewParameterDialog(getShell(),
388
		NewParameterDialog dlg = new NewParameterDialog(getShell(),
399
		Messages.EDIT_PARAM, _paramList, parameter);
389
				Messages.ADD_PARAM, _paramList, null);
400
	if (dlg.open() == Window.OK)
390
		if (dlg.open() == Window.OK) 
401
	{
391
		{
402
	    //InputParameter editedParameter = dlg.getParameter();
392
			InputParameter parameter = dlg.getParameter();
403
	    //_paramList.add(parameter);
393
			_paramList.add(parameter);
404
	    refreshParamTable();
394
			refreshParamTable();
405
	}
395
		}
406
    }
396
	}
407
    
397
408
    private void removeParameter()
398
	private void editParameter() 
409
    {
399
	{
410
	InputParameter parameter = getSelectedParameter();
400
		InputParameter parameter = getSelectedParameter();
411
	_paramList.remove(parameter);
401
		NewParameterDialog dlg = new NewParameterDialog(getShell(),
412
	_removeParameterButton.setEnabled(_paramList.size() != 0);
402
				Messages.EDIT_PARAM, _paramList, parameter);
413
	refreshParamTable();
403
		if (dlg.open() == Window.OK) 
414
    }
404
		{
415
405
			// InputParameter editedParameter = dlg.getParameter();
416
    protected Control createButtonBar(Composite parent)
406
			// _paramList.add(parameter);
417
    {
407
			refreshParamTable();
418
	Control ret = super.createButtonBar(parent);
408
		}
419
	return ret;
409
	}
420
    }
410
421
411
	private void removeParameter() 
422
    private void refreshParamTable()
412
	{
423
    {
413
		InputParameter parameter = getSelectedParameter();
424
	_paramViewer.setInput(_paramList);
414
		_paramList.remove(parameter);
425
    }
415
		_removeParameterButton.setEnabled(_paramList.size() != 0);
426
416
		refreshParamTable();
427
    private InputParameter getSelectedParameter()
417
	}
428
    {
418
429
	ISelection selection = _paramViewer.getSelection();
419
	protected Control createButtonBar(Composite parent) 
430
	InputParameter selectedParam = null;
420
	{
431
	if (selection instanceof StructuredSelection)
421
		Control ret = super.createButtonBar(parent);
432
	{
422
		return ret;
433
	    StructuredSelection ss = (StructuredSelection) selection;
423
	}
434
	    Object selected = ss.getFirstElement();
424
435
	    if (selected instanceof InputParameter)
425
	private void refreshParamTable() 
436
	    {
426
	{
437
		selectedParam = (InputParameter) selected;
427
		_paramViewer.setInput(_paramList);
438
	    }
428
	}
439
	}
429
440
	return selectedParam;
430
	private InputParameter getSelectedParameter() 
441
    }
431
	{
442
432
		ISelection selection = _paramViewer.getSelection();
443
    private void initializeControls()
433
		InputParameter selectedParam = null;
444
    {
434
		if (selection instanceof StructuredSelection) 
445
	NewNameGenerator nameGenerator = new NewNameGenerator("operation");
435
		{
446
	String opName = nameGenerator.getNextName();
436
			StructuredSelection ss = (StructuredSelection) selection;
447
	while (operationAlreadyExists(opName))
437
			Object selected = ss.getFirstElement();
448
	{
438
			if (selected instanceof InputParameter) 
449
	    opName = nameGenerator.getNextName();
439
				selectedParam = (InputParameter) selected;			
450
	}
440
		}
451
441
		return selectedParam;
452
	_methodName.setText(opName);
442
	}
453
	
443
454
	DataTypesCollection instance = DataTypesCollection.getInstance();
444
	private void initializeControls() 
455
	DataTypeCategory[] categories = instance.getDataTypeCategories();	
445
	{
456
	_dataTypeViewer.setInput(Arrays.asList(categories));
446
		NewNameGenerator nameGenerator = new NewNameGenerator("operation");
457
	_dataTypeViewer.refresh();
447
		String opName = nameGenerator.getNextName();
458
	DataType voidDataType = instance.getDataType("void");
448
		while (operationAlreadyExists(opName)) 
459
	_dataTypeViewer.setSelection(new StructuredSelection(voidDataType), true);
449
			opName = nameGenerator.getNextName();
460
	
450
		
461
	_editParameterButton.setEnabled(false);
451
		_methodName.setText(opName);
462
	_removeParameterButton.setEnabled(false);
452
463
	_methodName.setSelection(0, _methodName.getCharCount());
453
		DataTypesCollection instance = DataTypesCollection.getInstance();
464
    }
454
		DataTypeCategory[] categories = instance.getDataTypeCategories();
465
455
		_dataTypeViewer.setInput(Arrays.asList(categories));
466
    private boolean operationAlreadyExists(String name)
456
		_dataTypeViewer.refresh();
467
    {
457
		DataType voidDataType = instance.getDataType("void");
468
	if (CapUtils.getInstancesOfOperation(_model, name) >= 1)
458
		_dataTypeViewer.setSelection(new StructuredSelection(voidDataType),
469
	    return true;
459
				true);
470
	return false;
460
471
    }
461
		_editParameterButton.setEnabled(false);
472
462
		_removeParameterButton.setEnabled(false);
473
    private boolean validOperation()
463
		_methodName.setSelection(0, _methodName.getCharCount());
474
    {
475
	// Check for valid java identifier name
476
	String msg = CapUtils.validateJavaIdentifier(_operation.getName());
477
	if (msg != null)
478
	{
479
	    MessageDialog.openError(getShell(), "ERROR",
480
		    Messages.OP_NOT_VALID_JAVA_ID_WARN_);
481
	    return false;
482
	}
483
	if (operationAlreadyExists(_operation.getName()))
484
	{
485
	    MessageDialog.openError(getShell(), "ERROR",
486
		    Messages.OPERATION_ALREADY_EXISTS_WARN_);
487
	    return false;
488
	}
464
	}
489
	if (CapUtils.isOperationNameConflicted(_operation.getName()))
465
466
	private boolean operationAlreadyExists(String name) 
490
	{
467
	{
491
		MessageDialog.openError(getShell(), "ERROR",
468
		if (CapUtils.getInstancesOfOperation(_model, name) >= 1)
492
		    Messages.bind(Messages.CONFLICTED_OPERATION_WARN_, _operation.getName()));
469
			return true;
493
		return false;
470
		return false;
494
	}
471
	}
495
	// TODO Check for operation overloading
472
496
	return true;
473
	private boolean validOperation() 
497
    }
474
	{
498
475
		// Check for valid java identifier name
499
    protected void okPressed()
476
		String msg = CapUtils.validateJavaIdentifier(_operation.getName());
500
    {
477
		if (msg != null) 
501
478
		{
502
	_typesSchema = WsdlUtils.createOrFindSchema(_definition, _definition
479
			MessageDialog.openError(getShell(), "ERROR",
503
		.getTargetNamespace());
480
					Messages.OP_NOT_VALID_JAVA_ID_WARN_);
504
	WsdlUtils.createOrFindPrefix(_definition, WsdmConstants.WSBF_NS, "wsbf");
481
			return false;
505
	XsdUtils.createImportStatement(_typesSchema, WsdmConstants.WSBF_NS,
482
		}
506
		getBaseFaultFileURI());
483
		if (operationAlreadyExists(_operation.getName())) 
507
484
		{
508
	_operation.setName(_methodName.getText());
485
			MessageDialog.openError(getShell(), "ERROR",
509
486
					Messages.OPERATION_ALREADY_EXISTS_WARN_);
510
	if (!validOperation())
487
			return false;
511
	{
488
		}
512
	    _methodName.setSelection(0, _methodName.getCharCount());
489
		if (CapUtils.isOperationNameConflicted(_operation.getName())) 
513
	    _methodName.forceFocus();
490
		{
514
	    return;
491
			MessageDialog.openError(getShell(), "ERROR", Messages.bind(
515
	}
492
					Messages.CONFLICTED_OPERATION_WARN_, _operation.getName()));
516
493
			return false;
517
	_operation.setEnclosingDefinition(_definition);
494
		}
518
495
		// TODO Check for operation overloading
519
	Input input = prepareOperationInput();
496
		return true;
520
	_operation.setEInput(input);
497
	}
521
498
522
	Output output = prepareOperationOutput();
499
	protected void okPressed() 
523
	_operation.setEOutput(output);
500
	{
524
501
525
	Fault fault = prepareOperationFault();
502
		_typesSchema = WsdlUtils.createOrFindSchema(_definition, _definition
526
	_operation.addFault(fault);
503
				.getTargetNamespace());
527
504
		WsdlUtils
528
	super.okPressed();
505
				.createOrFindPrefix(_definition, WsdmConstants.WSBF_NS, "wsbf");
529
    }
506
		XsdUtils.createImportStatement(_typesSchema, WsdmConstants.WSBF_NS,
530
507
				getBaseFaultFileURI());
531
    private String getBaseFaultFileURI()
508
532
    {
509
		_operation.setName(_methodName.getText());
533
//	String containerPath = _capabilityDomain.getCapabilityFile()
510
534
//		.getLocation().toString();
511
		if (!validOperation()) 
535
//
512
		{
536
//	Bundle modelPlugin = _capabilityDomain.getModelPlugin();
513
			_methodName.setSelection(0, _methodName.getCharCount());
537
//	Path BASE_FAULT_PATH = new Path(BASE_FAULT_FILE);
514
			_methodName.forceFocus();
538
//	String filePath = EclipseUtils.getResolvedPath(modelPlugin,
515
			return;
539
//		BASE_FAULT_PATH);
516
		}
540
//	filePath = EclipseUtils.replaceAll(filePath, '\\', '/');
517
541
//	return EclipseUtils.getRelativePath(containerPath, filePath, '/');
518
		_operation.setEnclosingDefinition(_definition);
542
	return BASE_FAULT_FILE;
519
543
    }
520
		Input input = prepareOperationInput();
544
521
		_operation.setEInput(input);
545
    private Input prepareOperationInput()
522
546
    {
523
		Output output = prepareOperationOutput();
547
	Input input = WSDLFactory.eINSTANCE.createInput();
524
		_operation.setEOutput(output);
548
	input.setEnclosingDefinition(_definition);
525
549
	input.setName(_methodName.getText() + "Request");	
526
		Fault fault = prepareOperationFault();
550
	Message inputMessage = prepareInputMessage();
527
		_operation.addFault(fault);
551
	input.setMessage(inputMessage);
528
552
	return input;
529
		super.okPressed();
553
    }
530
	}
554
531
555
    private Output prepareOperationOutput()
532
	private String getBaseFaultFileURI() 
556
    {
533
	{
557
	Output output = WSDLFactory.eINSTANCE.createOutput();
534
		// String containerPath = _capabilityDomain.getCapabilityFile()
558
	output.setEnclosingDefinition(_definition);
535
		// .getLocation().toString();
559
	output.setName(_methodName.getText() + "Response");	
536
		//
560
	Message outputMessage = prepareOutputMessage();
537
		// Bundle modelPlugin = _capabilityDomain.getModelPlugin();
561
	output.setMessage(outputMessage);
538
		// Path BASE_FAULT_PATH = new Path(BASE_FAULT_FILE);
562
	return output;
539
		// String filePath = EclipseUtils.getResolvedPath(modelPlugin,
563
    }
540
		// BASE_FAULT_PATH);
564
541
		// filePath = EclipseUtils.replaceAll(filePath, '\\', '/');
565
    private Fault prepareOperationFault()
542
		// return EclipseUtils.getRelativePath(containerPath, filePath, '/');
566
    {
543
		return BASE_FAULT_FILE;
567
	Fault fault = WSDLFactory.eINSTANCE.createFault();
544
	}
568
	fault.setEnclosingDefinition(_definition);
545
569
	fault.setName(_methodName.getText() + "Fault");	
546
	private Input prepareOperationInput() 
570
	Message faultMessage = prepareFaultMessage();
547
	{
571
	fault.setMessage(faultMessage);
548
		Input input = WSDLFactory.eINSTANCE.createInput();
572
	return fault;
549
		input.setEnclosingDefinition(_definition);
573
    }
550
		input.setName(_methodName.getText() + "Request");
574
551
		Message inputMessage = prepareInputMessage();
575
    private Message prepareInputMessage()
552
		input.setMessage(inputMessage);
576
    {
553
		return input;
577
	XSDElementDeclaration inputParamHolderElement = prepareInputElement();
554
	}
578
	String name = _methodName.getText() + "Request";
555
579
	return prepareMessage(name, inputParamHolderElement);
556
	private Output prepareOperationOutput() 
580
    }
557
	{
581
558
		Output output = WSDLFactory.eINSTANCE.createOutput();
582
    private Message prepareOutputMessage()
559
		output.setEnclosingDefinition(_definition);
583
    {
560
		output.setName(_methodName.getText() + "Response");
584
	XSDElementDeclaration outputElement = prepareOutputElement();
561
		Message outputMessage = prepareOutputMessage();
585
	String name = _methodName.getText() + "Response";
562
		output.setMessage(outputMessage);
586
	return prepareMessage(name, outputElement);
563
		return output;
587
    }
564
	}
588
565
589
    private Message prepareFaultMessage()
566
	private Fault prepareOperationFault() 
590
    {
567
	{
591
	XSDElementDeclaration faultElement = prepareFaultElement();
568
		Fault fault = WSDLFactory.eINSTANCE.createFault();
592
	String name = _methodName.getText() + "Fault";
569
		fault.setEnclosingDefinition(_definition);
593
	return prepareMessage(name, faultElement);
570
		fault.setName(_methodName.getText() + "Fault");
594
    }
571
		Message faultMessage = prepareFaultMessage();
595
572
		fault.setMessage(faultMessage);
596
    private Message prepareMessage(String name,
573
		return fault;
597
	    XSDElementDeclaration elementDeclaration)
574
	}
598
    {
575
599
576
	private Message prepareInputMessage() 
600
	Part part = WSDLFactory.eINSTANCE.createPart();
577
	{
601
	part.setEnclosingDefinition(_definition);
578
		XSDElementDeclaration inputParamHolderElement = prepareInputElement();
602
	part.setName(name);
579
		String name = _methodName.getText() + "Request";
603
	part.setElementName(new QName(elementDeclaration.getTargetNamespace(),
580
		return prepareMessage(name, inputParamHolderElement);
604
		elementDeclaration.getName()));
581
	}
605
	part.setElementDeclaration(elementDeclaration);
582
606
	//((PartImpl) part).reconcileReferences(false);
583
	private Message prepareOutputMessage()
607
584
	{
608
	Message message = WSDLFactory.eINSTANCE.createMessage();
585
		XSDElementDeclaration outputElement = prepareOutputElement();
609
	message.setEnclosingDefinition(_definition);
586
		String name = _methodName.getText() + "Response";
610
	message.setQName(new QName(_definition.getTargetNamespace(), name));	
587
		return prepareMessage(name, outputElement);
611
	message.addPart(part);
588
	}
612
	_definition.addMessage(message);
589
613
590
	private Message prepareFaultMessage() 
614
	return message;
591
	{
615
    }
592
		XSDElementDeclaration faultElement = prepareFaultElement();
616
593
		String name = _methodName.getText() + "Fault";
617
    private XSDElementDeclaration prepareInputElement()
594
		return prepareMessage(name, faultElement);
618
    {
595
	}
619
	XSDElementDeclaration inputParamHolderElement = XSDFactory.eINSTANCE
596
620
		.createXSDElementDeclaration();
597
	private Message prepareMessage(String name,
621
	inputParamHolderElement.setName(_methodName.getText());
598
			XSDElementDeclaration elementDeclaration) 
622
	_typesSchema.getContents().add(inputParamHolderElement);
599
	{
623
	if (_paramList.size() == 0)
600
624
	{
601
		Part part = WSDLFactory.eINSTANCE.createPart();
625
	    inputParamHolderElement.setAnonymousTypeDefinition(null);
602
		part.setEnclosingDefinition(_definition);
626
	    return inputParamHolderElement;
603
		part.setName(name);
627
	}
604
		part.setElementName(new QName(elementDeclaration.getTargetNamespace(),
628
605
				elementDeclaration.getName()));
629
	XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
606
		part.setElementDeclaration(elementDeclaration);
630
	modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
607
		// ((PartImpl) part).reconcileReferences(false);
631
	XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
608
632
	xsdParticle.setContent(modelGroup);
609
		Message message = WSDLFactory.eINSTANCE.createMessage();
633
	XSDComplexTypeDefinition complexTypeDefiniton = XSDFactory.eINSTANCE
610
		message.setEnclosingDefinition(_definition);
634
		.createXSDComplexTypeDefinition();
611
		message.setQName(new QName(_definition.getTargetNamespace(), name));
635
	complexTypeDefiniton.setContent(xsdParticle);
612
		message.addPart(part);
636
	inputParamHolderElement
613
		_definition.addMessage(message);
637
		.setAnonymousTypeDefinition(complexTypeDefiniton);
614
638
	inputParamHolderElement.setTypeDefinition(complexTypeDefiniton);
615
		return message;
639
616
	}
640
	for (int i = 0; i < _paramList.size(); i++)
617
641
	{
618
	private XSDElementDeclaration prepareInputElement() 
642
	    InputParameter parameter = (InputParameter) _paramList.get(i);
619
	{
643
	    XSDParticle simpleElementParticle = XSDFactory.eINSTANCE
620
		XSDElementDeclaration inputParamHolderElement = XSDFactory.eINSTANCE
644
		    .createXSDParticle();
621
				.createXSDElementDeclaration();
645
	    if(parameter.isArrayType())
622
		inputParamHolderElement.setName(_methodName.getText());
646
	    	simpleElementParticle.setMaxOccurs(-1);	    
623
		_typesSchema.getContents().add(inputParamHolderElement);
647
	    simpleElementParticle.setContent(parameter.getXSDElementDeclaration());
624
		if (_paramList.size() == 0) 
648
	    modelGroup.getContents().add(simpleElementParticle);
625
		{
649
	}
626
			inputParamHolderElement.setAnonymousTypeDefinition(null);
650
	return inputParamHolderElement;
627
			return inputParamHolderElement;
651
    }
628
		}
652
629
653
    private XSDElementDeclaration prepareOutputElement()
630
		XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
654
    {
631
		modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
655
	XSDElementDeclaration outputTypeElement = XSDFactory.eINSTANCE
632
		XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
656
		.createXSDElementDeclaration();
633
		xsdParticle.setContent(modelGroup);
657
	outputTypeElement.setName(_methodName.getText() + "Response");
634
		XSDComplexTypeDefinition complexTypeDefiniton = XSDFactory.eINSTANCE
658
	_typesSchema.getContents().add(outputTypeElement);
635
				.createXSDComplexTypeDefinition();
659
	_returnType = (DataType) getSelectedViewerObject();	
636
		complexTypeDefiniton.setContent(xsdParticle);
660
	return outputTypeElement;
637
		inputParamHolderElement
661
    }
638
				.setAnonymousTypeDefinition(complexTypeDefiniton);
662
639
		inputParamHolderElement.setTypeDefinition(complexTypeDefiniton);
663
    private XSDElementDeclaration prepareFaultElement()
640
664
    {
641
		for (int i = 0; i < _paramList.size(); i++) 
665
	XSDElementDeclaration faultElement = XSDFactory.eINSTANCE
642
		{
666
		.createXSDElementDeclaration();
643
			InputParameter parameter = (InputParameter) _paramList.get(i);
667
	faultElement.setName(_methodName.getText() + "Fault");
644
			XSDParticle simpleElementParticle = XSDFactory.eINSTANCE
668
	_typesSchema.getContents().add(faultElement);
645
					.createXSDParticle();
669
646
			if (parameter.isArrayType())
670
	XSDComplexTypeDefinition complexTypeDefinition = XSDFactory.eINSTANCE
647
				simpleElementParticle.setMaxOccurs(-1);
671
		.createXSDComplexTypeDefinition();
648
			simpleElementParticle.setContent(parameter
672
	complexTypeDefinition
649
					.getXSDElementDeclaration());
673
		.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
650
			modelGroup.getContents().add(simpleElementParticle);
674
	XSDSimpleTypeDefinition simpleTypeDef = XSDFactory.eINSTANCE
651
		}
675
		.createXSDSimpleTypeDefinition();
652
		return inputParamHolderElement;
676
	simpleTypeDef.setName("BaseFaultType");
653
	}
677
	simpleTypeDef.setTargetNamespace(WsdmConstants.WSBF_NS);
654
678
	complexTypeDefinition.setBaseTypeDefinition(simpleTypeDef);
655
	private XSDElementDeclaration prepareOutputElement() 
679
656
	{
680
	faultElement.setAnonymousTypeDefinition(complexTypeDefinition);
657
		XSDElementDeclaration outputTypeElement = XSDFactory.eINSTANCE
681
	faultElement.setTypeDefinition(complexTypeDefinition);
658
				.createXSDElementDeclaration();
682
	return faultElement;
659
		outputTypeElement.setName(_methodName.getText() + "Response");
683
    }
660
		_typesSchema.getContents().add(outputTypeElement);
684
    
661
		_returnType = (DataType) getSelectedViewerObject();
685
    private Object getSelectedViewerObject(){
662
		return outputTypeElement;
686
    	StructuredSelection ss = (StructuredSelection) _dataTypeViewer.getSelection();
663
	}
687
    	Object[] selectedObjects = ss.toArray();
664
688
    	return selectedObjects[0];
665
	private XSDElementDeclaration prepareFaultElement() 
689
    }   
666
	{
667
		XSDElementDeclaration faultElement = XSDFactory.eINSTANCE
668
				.createXSDElementDeclaration();
669
		faultElement.setName(_methodName.getText() + "Fault");
670
		_typesSchema.getContents().add(faultElement);
671
672
		XSDComplexTypeDefinition complexTypeDefinition = XSDFactory.eINSTANCE
673
				.createXSDComplexTypeDefinition();
674
		complexTypeDefinition
675
				.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
676
		XSDSimpleTypeDefinition simpleTypeDef = XSDFactory.eINSTANCE
677
				.createXSDSimpleTypeDefinition();
678
		simpleTypeDef.setName("BaseFaultType");
679
		simpleTypeDef.setTargetNamespace(WsdmConstants.WSBF_NS);
680
		complexTypeDefinition.setBaseTypeDefinition(simpleTypeDef);
681
682
		faultElement.setAnonymousTypeDefinition(complexTypeDefinition);
683
		faultElement.setTypeDefinition(complexTypeDefinition);
684
		return faultElement;
685
	}
686
687
	private Object getSelectedViewerObject() 
688
	{
689
		StructuredSelection ss = (StructuredSelection) _dataTypeViewer
690
				.getSelection();
691
		Object[] selectedObjects = ss.toArray();
692
		return selectedObjects[0];
693
	}
690
}
694
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/operation/internal/DetailsSection.java (-202 / +216 lines)
Lines 54-268 Link Here
54
public class DetailsSection extends AbstractPageSection
54
public class DetailsSection extends AbstractPageSection
55
{
55
{
56
56
57
    private Text _operationNameText;
57
	private Text _operationNameText;
58
58
59
    private Text _operationReturnType;
59
	private Text _operationReturnType;
60
    
60
61
    private Button _changeReturnTypeButton;
61
	private Button _changeReturnTypeButton;
62
    
62
63
    private Button _importTypeButton;
63
	private Button _importTypeButton;
64
64
65
    private Operation _selectedOperation;
65
	private Operation _selectedOperation;
66
66
67
    /**
67
	/**
68
     * Creates a new object of this class. 
68
	 * Creates a new object of this class.
69
     */
69
	 */
70
    DetailsSection(CapabilityEditor editor, IUIPage page, ScrolledForm form,
70
	DetailsSection(CapabilityEditor editor, IUIPage page, ScrolledForm form,
71
	    FormToolkit toolkit)
71
			FormToolkit toolkit)
72
    {
72
	{
73
	super(editor, page, form, toolkit);
73
		super(editor, page, form, toolkit);
74
    }
74
	}
75
75
76
    /**
76
	/**
77
     * Creates the section.
77
	 * Creates the section.
78
     */
78
	 */
79
    public void create()
79
	public void create()
80
    {
80
	{
81
	Composite sectionClient = createSection(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.DETAILS_LABEL,
81
		Composite sectionClient = createSection(
82
		Messages.DETAILS_OF_OP);
82
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.DETAILS_LABEL,
83
	GridLayout layout = new GridLayout(3, false);
83
				Messages.DETAILS_OF_OP);
84
	layout.marginWidth = LAYOUT_MARGIN_WIDTH;
84
		GridLayout layout = new GridLayout(3, false);
85
	layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
85
		layout.marginWidth = LAYOUT_MARGIN_WIDTH;
86
	layout.horizontalSpacing = LAYOUT_HORIZONTAL_SPACING;
86
		layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
87
	sectionClient.setLayout(layout);
87
		layout.horizontalSpacing = LAYOUT_HORIZONTAL_SPACING;
88
	FormToolkit toolkit = getToolkit();
88
		sectionClient.setLayout(layout);
89
89
		FormToolkit toolkit = getToolkit();
90
	Label operationNameLabel = toolkit.createLabel(sectionClient,
90
91
		Messages.OP_NAME);
91
		Label operationNameLabel = toolkit.createLabel(sectionClient,
92
	GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, SWT.NONE, false, false);
92
				Messages.OP_NAME);
93
	operationNameLabel.setLayoutData(gd);
93
		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING,
94
94
				SWT.NONE, false, false);
95
	_operationNameText = toolkit.createText(sectionClient, "", SWT.SINGLE
95
		operationNameLabel.setLayoutData(gd);
96
		| SWT.BORDER);
96
97
	gd = new GridData(SWT.FILL, SWT.NONE, true, false);
97
		_operationNameText = toolkit.createText(sectionClient, "", SWT.SINGLE
98
	gd.minimumWidth = SWT.DEFAULT;
98
				| SWT.BORDER);
99
	gd.horizontalSpan = 2;
99
		gd = new GridData(SWT.FILL, SWT.NONE, true, false);
100
	_operationNameText.setLayoutData(gd);
100
		gd.minimumWidth = SWT.DEFAULT;
101
101
		gd.horizontalSpan = 2;
102
	Label operationReturnTypeLabel = toolkit.createLabel(sectionClient,
102
		_operationNameText.setLayoutData(gd);
103
		Messages.OP_RETURN_TYPE);
103
104
	gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, SWT.NONE, false, false);
104
		Label operationReturnTypeLabel = toolkit.createLabel(sectionClient,
105
	operationReturnTypeLabel.setLayoutData(gd);
105
				Messages.OP_RETURN_TYPE);
106
106
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, SWT.NONE, false,
107
	_operationReturnType = new Text(sectionClient, SWT.SINGLE | SWT.BORDER);
107
				false);
108
	gd = new GridData(SWT.FILL, SWT.NONE, true, false);
108
		operationReturnTypeLabel.setLayoutData(gd);
109
	_operationReturnType.setLayoutData(gd);
109
110
	_operationReturnType.setEditable(false);
110
		_operationReturnType = new Text(sectionClient, SWT.SINGLE | SWT.BORDER);
111
	
111
		gd = new GridData(SWT.FILL, SWT.NONE, true, false);
112
	_changeReturnTypeButton = createPushButton(sectionClient, toolkit,
112
		_operationReturnType.setLayoutData(gd);
113
			org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.CHANGE_BUTTON_LABEL, 
113
		_operationReturnType.setEditable(false);
114
			new Listener()
114
115
		_changeReturnTypeButton = createPushButton(
116
				sectionClient,
117
				toolkit,
118
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.CHANGE_BUTTON_LABEL,
119
				new Listener() {
120
					public void handleEvent(Event event)
121
					{
122
						changeOperationReturnType();
123
					}
124
				});
125
		gd = new GridData(GridData.END, SWT.NONE, false, false);
126
		_changeReturnTypeButton.setLayoutData(gd);
127
128
		_importTypeButton = createPushButton(
129
				sectionClient,
130
				toolkit,
131
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.IMPORT_COMPLEX_DATA_TYPE,
132
				new Listener() {
133
					public void handleEvent(Event event)
134
					{
135
						importComplexTypes();
136
					}
137
				});
138
		gd = new GridData(GridData.END, SWT.NONE, false, false);
139
		gd.horizontalSpan = 3;
140
		_importTypeButton.setLayoutData(gd);
141
		_importTypeButton.setEnabled(!_editor.isReadOnly());
142
143
		enable(!_editor.isReadOnly());
144
	}
145
146
	private void importComplexTypes()
147
	{
148
		ImportComplexTypeAction action = new ImportComplexTypeAction(getForm()
149
				.getShell());
150
		action.run();
151
	}
152
153
	/**
154
	 * Refreshes the section.
155
	 */
156
	public void refresh()
157
	{
158
	}
159
160
	/**
161
	 * Initializes control listeners.
162
	 */
163
	public void hookAllListeners()
164
	{
165
		_operationNameText.addModifyListener(new ModifyListener() {
166
			public void modifyText(ModifyEvent e)
115
			{
167
			{
116
		    		public void handleEvent(Event event)
168
				changeOperationName();
117
		    		{
169
			}
118
		    			changeOperationReturnType();
119
		    		}
120
			});
121
	gd = new GridData(GridData.END, SWT.NONE, false, false);
122
	_changeReturnTypeButton.setLayoutData(gd);
123
	
124
	_importTypeButton = createPushButton(sectionClient, toolkit, 
125
		org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.IMPORT_COMPLEX_DATA_TYPE, 
126
		new Listener()
127
		{
128
	    		public void handleEvent(Event event)
129
	    		{
130
	    		    importComplexTypes();
131
	    		}
132
		});
170
		});
133
	gd = new GridData(GridData.END, SWT.NONE, false, false);
171
	}
134
	gd.horizontalSpan = 3;	
172
135
	_importTypeButton.setLayoutData(gd);
173
	private void changeOperationName()
136
	_importTypeButton.setEnabled(!_editor.isReadOnly());
174
	{
137
	
175
		if (_selectedOperation != null)
138
	enable(!_editor.isReadOnly());
176
		{
139
    }
177
			String newName = _operationNameText.getText();
140
    
178
			String oldName = _selectedOperation.getName();
141
    private void importComplexTypes()
179
			if (!newName.equals(oldName))
142
    {
180
			{
143
	ImportComplexTypeAction action = new ImportComplexTypeAction(getForm().getShell());
181
				ChangeOperationNameCommand command = new ChangeOperationNameCommand(
144
	action.run();
182
						_selectedOperation, newName);
145
	}
183
				command.execute();
146
184
				_page.setDirty();
147
    /**
185
			}
148
     * Refreshes the section.
186
		}
149
     */
187
	}
150
    public void refresh()
188
151
    {
189
	private void changeOperationReturnType()
152
    }
190
	{
153
191
		if (_selectedOperation != null)
154
    /**
192
		{
155
     * Initializes control listeners.
193
			ChangeDataTypeDialog dialog = new ChangeDataTypeDialog(getForm()
156
     */
194
					.getShell(), Messages.CHANGE_RETURN_TYPE, true);
157
    public void hookAllListeners()
195
			if (dialog.open() == Window.OK)
158
    {
196
			{
159
	_operationNameText.addModifyListener(new ModifyListener()
197
				DataType dataType = dialog.getNewDataType();
160
	{
198
				ChangeOperationReturnTypeCommand command = new ChangeOperationReturnTypeCommand(
161
	    public void modifyText(ModifyEvent e)
199
						_selectedOperation, dataType);
162
	    {
200
				command.execute();
163
		changeOperationName();
201
				_page.setDirty();
164
	    }
202
			}
165
	});
203
		}
166
	}
204
	}
167
    
205
168
    private void changeOperationName()
206
	private String getSelectedOpReturnType()
169
    {
207
	{
170
	if (_selectedOperation != null)
208
		XSDElementDeclaration returnTypeDeclaration = WsdlUtils
171
	{
209
				.getReturnTypeElement(_selectedOperation);
172
	    String newName = _operationNameText.getText();
210
		return XsdUtils.getType(returnTypeDeclaration);
173
	    String oldName = _selectedOperation.getName();
211
	}
174
	    if (!newName.equals(oldName))
212
175
	    {
213
	/**
176
		ChangeOperationNameCommand command = new ChangeOperationNameCommand(
214
	 * Handle viewer selection changed.
177
			_selectedOperation, newName);
215
	 */
178
		command.execute();
216
	public void selectionChanged(SelectionChangedEvent event)
179
		_page.setDirty();
180
	    }
181
	}
182
    }
183
    
184
    private void changeOperationReturnType()
185
    {
186
	if (_selectedOperation != null)
187
	{
217
	{
188
		ChangeDataTypeDialog dialog = new ChangeDataTypeDialog(getForm().getShell(),Messages.CHANGE_RETURN_TYPE, true);
218
		showOpNameDetails();
189
		if(dialog.open() == Window.OK)
219
		showOpReturnTypeDetails();
220
		// TODO Remove this once able to handle WSDL Import properly
221
		enableDisableReturnType();
222
	}
223
224
	private void showOpNameDetails()
225
	{
226
		_operationNameText.setEnabled(!_editor.isReadOnly());
227
		String operationName = WsdlUtils.getOperationName(_selectedOperation);
228
		if (!_operationNameText.getText().equals(operationName))
229
			_operationNameText.setText(operationName);
230
	}
231
232
	private void showOpReturnTypeDetails()
233
	{
234
		Part returnTypePart = WsdlUtils
235
				.getReturnTypeMessagePart(_selectedOperation);
236
		XSDElementDeclaration returnTypeDeclaration = returnTypePart
237
				.getElementDeclaration();
238
		if (returnTypeDeclaration == null)
190
		{
239
		{
191
			DataType dataType = dialog.getNewDataType();
240
			_operationReturnType.setText("void");
192
			ChangeOperationReturnTypeCommand command = new ChangeOperationReturnTypeCommand(_selectedOperation, dataType);
241
			return;
193
			command.execute();
194
			_page.setDirty();
195
		}
242
		}
243
		String type = XsdUtils.getType(returnTypeDeclaration);
244
		_operationReturnType.setText(type);
196
	}
245
	}
197
    }
198
246
199
    private String getSelectedOpReturnType()
247
	private void enableDisableReturnType()
200
    {
248
	{
201
	XSDElementDeclaration returnTypeDeclaration = WsdlUtils
249
		Definition capDefinition = _editor.getCapabilityDomain()
202
		.getReturnTypeElement(_selectedOperation);
250
				.getCapability().getDefinition();
203
	return XsdUtils.getType(returnTypeDeclaration);
251
		Message operationMessage = _selectedOperation.getEInput().getEMessage();
204
    }
252
		boolean isImportedOperation = true;
205
253
		if (operationMessage != null)
206
    /**
254
			isImportedOperation = !operationMessage.getEnclosingDefinition()
207
     * Handle viewer selection changed.
255
					.equals(capDefinition);
208
     */
256
209
    public void selectionChanged(SelectionChangedEvent event)
257
		_operationReturnType.setEnabled(!isImportedOperation
210
    {
258
				&& !_editor.isReadOnly());
211
	showOpNameDetails();
259
		_changeReturnTypeButton.setEnabled(!isImportedOperation
212
	showOpReturnTypeDetails();
260
				&& !_editor.isReadOnly());
213
	// TODO Remove this once able to handle WSDL Import properly
261
	}
214
	enableDisableReturnType();
262
215
    }
263
	/**
216
264
	 * Update its selected object.
217
    private void showOpNameDetails()
265
	 */
218
    {
266
	public void setSelectedObject(Object object)
219
	_operationNameText.setEnabled(!_editor.isReadOnly());
267
	{
220
   	String operationName = WsdlUtils.getOperationName(_selectedOperation);	
268
		if (object instanceof Operation)
221
	if (!_operationNameText.getText().equals(operationName))
269
			_selectedOperation = (Operation) object;
222
	    _operationNameText.setText(operationName);
270
	}
223
    }
271
224
272
	/**
225
    private void showOpReturnTypeDetails()
273
	 * Enable or disable the section based on parameter passed.
226
    {
274
	 */
227
	Part returnTypePart = WsdlUtils.getReturnTypeMessagePart(_selectedOperation);
275
	public void enable(boolean enabled)
228
	XSDElementDeclaration returnTypeDeclaration = returnTypePart.getElementDeclaration();
276
	{
229
	if(returnTypeDeclaration == null){
277
		_operationNameText.setEnabled(enabled);
230
		_operationReturnType.setText("void");
278
		_operationReturnType.setEnabled(enabled);
231
		return;
279
		_changeReturnTypeButton.setEnabled(enabled);
232
	}
280
	}
233
	String type = XsdUtils.getType(returnTypeDeclaration);
234
	_operationReturnType.setText(type);
235
	}
236
    
237
    private void enableDisableReturnType()
238
    {
239
	Definition capDefinition = _editor.getCapabilityDomain().getDefinition();	
240
	Message operationMessage = _selectedOperation.getEInput().getEMessage();
241
	boolean isImportedOperation = true;
242
	if(operationMessage != null)
243
	    isImportedOperation = !operationMessage.getEnclosingDefinition().equals(capDefinition);
244
	
245
	_operationReturnType.setEnabled(!isImportedOperation && !_editor.isReadOnly());
246
	_changeReturnTypeButton.setEnabled(!isImportedOperation && !_editor.isReadOnly());
247
    }
248
249
    /**
250
     * Update its selected object.
251
     */
252
    public void setSelectedObject(Object object)
253
    {
254
	if (object instanceof Operation)
255
	    _selectedOperation = (Operation) object;
256
    }
257
258
    /**
259
     * Enable or disable the section based on parameter passed.
260
     */
261
    public void enable(boolean enabled)
262
    {
263
	_operationNameText.setEnabled(enabled);
264
	_operationReturnType.setEnabled(enabled);
265
	_changeReturnTypeButton.setEnabled(enabled);
266
    }
267
281
268
}
282
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/overview/internal/DetailsSection.java (-254 / +255 lines)
Lines 51-316 Link Here
51
public class DetailsSection extends AbstractPageSection
51
public class DetailsSection extends AbstractPageSection
52
{
52
{
53
53
54
    private Text _capabilityNameText;
54
	private Text _capabilityNameText;
55
55
56
    private Text _namespaceText;
56
	private Text _namespaceText;
57
57
58
    private Text _descriptionText;
58
	private Text _descriptionText;
59
59
60
    private Label _errorLabel;
60
	private Label _errorLabel;
61
61
62
    private String _capabilityName;
62
	private String _capabilityName;
63
63
64
    private String _namespace;
64
	private String _namespace;
65
65
66
    private String _description;
66
	private String _description;
67
67
68
    private boolean _dialogThrown = false;
68
	private boolean _dialogThrown = false;
69
69
70
    /**
70
	/**
71
         * Creates a new object of this class.
71
	 * Creates a new object of this class.
72
         */
72
	 */
73
    DetailsSection(CapabilityEditor editor, IUIPage overviewPage,
73
	DetailsSection(CapabilityEditor editor, IUIPage overviewPage,
74
	    ScrolledForm form, FormToolkit toolkit)
74
			ScrolledForm form, FormToolkit toolkit)
75
    {
75
	{
76
	super(editor, overviewPage, form, toolkit);
76
		super(editor, overviewPage, form, toolkit);
77
    }
77
	}
78
78
79
    /**
79
	/**
80
         * Creates the section.
80
	 * Creates the section.
81
         */
81
	 */
82
    public void create()
82
	public void create()
83
    {
83
	{
84
	Composite sectionClient = createSection(Messages.GENERAL_INFO,
84
		Composite sectionClient = createSection(Messages.GENERAL_INFO,
85
		Messages.GENERAL_INFO_OF_CAP);
85
				Messages.GENERAL_INFO_OF_CAP);
86
	GridLayout layout = new GridLayout(2, false);
86
		GridLayout layout = new GridLayout(2, false);
87
	layout.marginWidth = LAYOUT_MARGIN_WIDTH;
87
		layout.marginWidth = LAYOUT_MARGIN_WIDTH;
88
	layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
88
		layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
89
	layout.horizontalSpacing = LAYOUT_HORIZONTAL_SPACING;
89
		layout.horizontalSpacing = LAYOUT_HORIZONTAL_SPACING;
90
	sectionClient.setLayout(layout);
90
		sectionClient.setLayout(layout);
91
	FormToolkit toolkit = getToolkit();
91
		FormToolkit toolkit = getToolkit();
92
92
93
	Label capabilityNameLabel = toolkit.createLabel(sectionClient,
93
		Label capabilityNameLabel = toolkit.createLabel(sectionClient,
94
		Messages.CAP_NAME);
94
				Messages.CAP_NAME);
95
	GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, SWT.NONE, false, false);
95
		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING,
96
	capabilityNameLabel.setLayoutData(gd);
96
				SWT.NONE, false, false);
97
97
		capabilityNameLabel.setLayoutData(gd);
98
	_capabilityNameText = toolkit.createText(sectionClient, "", SWT.SINGLE
98
99
		| SWT.BORDER);
99
		_capabilityNameText = toolkit.createText(sectionClient, "", SWT.SINGLE
100
	gd = new GridData(SWT.FILL, SWT.NONE, true, false);
100
				| SWT.BORDER);
101
	gd.minimumWidth = SWT.DEFAULT;
101
		gd = new GridData(SWT.FILL, SWT.NONE, true, false);
102
	_capabilityNameText.setLayoutData(gd);
102
		gd.minimumWidth = SWT.DEFAULT;
103
	_capabilityNameText.setEditable(!_editor.isReadOnly());
103
		_capabilityNameText.setLayoutData(gd);
104
104
		_capabilityNameText.setEditable(!_editor.isReadOnly());
105
	Label namespaceLabel = toolkit.createLabel(sectionClient,
105
106
		Messages.CAP_NAMESPACE);
106
		Label namespaceLabel = toolkit.createLabel(sectionClient,
107
	gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, SWT.NONE, false, false);
107
				Messages.CAP_NAMESPACE);
108
	namespaceLabel.setLayoutData(gd);
108
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, SWT.NONE, false,
109
109
				false);
110
	_namespaceText = toolkit.createText(sectionClient, "", SWT.SINGLE
110
		namespaceLabel.setLayoutData(gd);
111
		| SWT.BORDER);
111
112
	gd = new GridData(SWT.FILL, SWT.NONE, true, false);
112
		_namespaceText = toolkit.createText(sectionClient, "", SWT.SINGLE
113
	gd.minimumWidth = SWT.DEFAULT;
113
				| SWT.BORDER);
114
	_namespaceText.setLayoutData(gd);
114
		gd = new GridData(SWT.FILL, SWT.NONE, true, false);
115
	_namespaceText.setEditable(!_editor.isReadOnly());
115
		gd.minimumWidth = SWT.DEFAULT;
116
116
		_namespaceText.setLayoutData(gd);
117
	Label descriptionLabel = toolkit.createLabel(sectionClient,
117
		_namespaceText.setEditable(!_editor.isReadOnly());
118
		Messages.CAP_DESCRIPTION);
118
119
	gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, SWT.NONE, false, false);
119
		Label descriptionLabel = toolkit.createLabel(sectionClient,
120
	descriptionLabel.setLayoutData(gd);
120
				Messages.CAP_DESCRIPTION);
121
121
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, SWT.NONE, false,
122
	_descriptionText = toolkit.createText(sectionClient, "", SWT.SINGLE
122
				false);
123
		| SWT.BORDER);
123
		descriptionLabel.setLayoutData(gd);
124
	gd = new GridData(SWT.FILL, SWT.NONE, true, false);
124
125
	gd.minimumWidth = SWT.DEFAULT;
125
		_descriptionText = toolkit.createText(sectionClient, "", SWT.SINGLE
126
	_descriptionText.setLayoutData(gd);
126
				| SWT.BORDER);
127
	_descriptionText.setEditable(!_editor.isReadOnly());
127
		gd = new GridData(SWT.FILL, SWT.NONE, true, false);
128
128
		gd.minimumWidth = SWT.DEFAULT;
129
	_errorLabel = toolkit.createLabel(sectionClient, "", SWT.WRAP);
129
		_descriptionText.setLayoutData(gd);
130
	gd = new GridData(GridData.FILL_HORIZONTAL);
130
		_descriptionText.setEditable(!_editor.isReadOnly());
131
	gd.horizontalSpan = 2;
131
132
	_errorLabel.setLayoutData(gd);
132
		_errorLabel = toolkit.createLabel(sectionClient, "", SWT.WRAP);
133
    }
133
		gd = new GridData(GridData.FILL_HORIZONTAL);
134
134
		gd.horizontalSpan = 2;
135
    /**
135
		_errorLabel.setLayoutData(gd);
136
         * Refreshes the section.
136
	}
137
         */
137
138
    public void refresh()
138
	/**
139
    {
139
	 * Refreshes the section.
140
	Capability model = _editor.getCapabilityDomain().getCapability();
140
	 */
141
	_capabilityName = model.getName();
141
	public void refresh()
142
	_namespace = model.getNamespace();
142
	{
143
	_description = model.getDescription();
143
		Capability model = _editor.getCapabilityDomain().getCapability();
144
	if (!_capabilityNameText.getText().equals(_capabilityName))
144
		_capabilityName = model.getName();
145
	    _capabilityNameText.setText(_capabilityName);
145
		_namespace = model.getNamespace();
146
	if (!_namespaceText.getText().equals(_namespace))
146
		_description = model.getDescription();
147
	    _namespaceText.setText(_namespace);
147
		if (!_capabilityNameText.getText().equals(_capabilityName))
148
	if (!_descriptionText.getText().equals(_description))
148
			_capabilityNameText.setText(_capabilityName);
149
	    _descriptionText.setText(_description);
149
		if (!_namespaceText.getText().equals(_namespace))
150
	updateErrorMessage();
150
			_namespaceText.setText(_namespace);
151
    }
151
		if (!_descriptionText.getText().equals(_description))
152
152
			_descriptionText.setText(_description);
153
    /**
153
		updateErrorMessage();
154
         * Initializes control listeners.
154
	}
155
         */
155
156
    public void hookAllListeners()
156
	/**
157
    {
157
	 * Initializes control listeners.
158
	_capabilityNameText.addModifyListener(new ModifyListener()
158
	 */
159
	{
159
	public void hookAllListeners()
160
	    public void modifyText(ModifyEvent e)
160
	{
161
	    {
161
		_capabilityNameText.addModifyListener(new ModifyListener() {
162
		changeCapabilityName();
162
			public void modifyText(ModifyEvent e)
163
	    }
163
			{
164
	});
164
				changeCapabilityName();
165
	_capabilityNameText.addFocusListener(new FocusAdapter(){
165
			}
166
	    public void focusGained(FocusEvent e)
166
		});
167
	    {
167
		_capabilityNameText.addFocusListener(new FocusAdapter() {
168
		_dialogThrown = false;
168
			public void focusGained(FocusEvent e)
169
	    }
169
			{
170
	});
170
				_dialogThrown = false;
171
	_namespaceText.addModifyListener(new ModifyListener()
171
			}
172
	{
172
		});
173
	    public void modifyText(ModifyEvent e)
173
		_namespaceText.addModifyListener(new ModifyListener() {
174
	    {
174
			public void modifyText(ModifyEvent e)
175
		changeCapabilityNamespace();
175
			{
176
	    }
176
				changeCapabilityNamespace();
177
	});
177
			}
178
	_namespaceText.addFocusListener(new FocusAdapter()
178
		});
179
	{
179
		_namespaceText.addFocusListener(new FocusAdapter() {
180
	    public void focusGained(FocusEvent e)
180
			public void focusGained(FocusEvent e)
181
	    {
181
			{
182
		if (!_dialogThrown)
182
				if (!_dialogThrown)
183
				{
184
					Definition definition = _editor.getCapabilityDomain()
185
							.getCapability().getDefinition();
186
					List importsWsdl = definition.getImports(definition
187
							.getTargetNamespace());
188
					if (importsWsdl.size() > 0)
189
					{
190
						_dialogThrown = true;
191
						boolean ok = MessageDialog
192
								.openConfirm(
193
										getForm().getShell(),
194
										org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.CONFIRM_MESSAGE,
195
										Messages.IMPORT_WSDL_NS_CHANGE_MESSAGE);
196
						if (!ok)
197
							_capabilityNameText.setFocus();
198
					}
199
200
				}
201
			}
202
		});
203
		_descriptionText.addModifyListener(new ModifyListener() {
204
			public void modifyText(ModifyEvent e)
205
			{
206
				changeCapabilityDescription();
207
			}
208
		});
209
		_descriptionText.addFocusListener(new FocusAdapter() {
210
			public void focusGained(FocusEvent e)
211
			{
212
				_dialogThrown = false;
213
			}
214
		});
215
	}
216
217
	private void changeCapabilityName()
218
	{
219
		if (!_capabilityNameText.getText().equals(_capabilityName))
220
		{
221
			CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
222
			String newName = _capabilityNameText.getText();
223
			ChangeCapabilityNameCommand command = new ChangeCapabilityNameCommand(
224
					capabilityDomain, newName);
225
			command.execute();
226
			_page.setDirty();
227
		}
228
	}
229
230
	private void changeCapabilityNamespace()
231
	{
232
		if (!_namespaceText.getText().equals(_namespace))
233
		{
234
			CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
235
			String newNS = _namespaceText.getText();
236
			ChangeCapabilityNamespaceCommand command = new ChangeCapabilityNamespaceCommand(
237
					capabilityDomain, newNS);
238
			command.execute();
239
			_page.setDirty();
240
		}
241
	}
242
243
	private void changeCapabilityDescription()
244
	{
245
		if (!_descriptionText.getText().equals(_description))
246
		{
247
			CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
248
			String newDescription = _descriptionText.getText();
249
			ChangeCapabilityDescriptionCommand command = new ChangeCapabilityDescriptionCommand(
250
					capabilityDomain, newDescription);
251
			command.execute();
252
			_page.setDirty();
253
		}
254
	}
255
256
	/**
257
	 * Handle viewer selection changed.
258
	 */
259
	public void selectionChanged(SelectionChangedEvent event)
260
	{
261
	}
262
263
	/**
264
	 * Update its selected object.
265
	 */
266
	public void setSelectedObject(Object object)
267
	{
268
	}
269
270
	/**
271
	 * Enable or disable the section based on parameter passed.
272
	 */
273
	public void enable(boolean enabled)
274
	{
275
	}
276
277
	private void updateErrorMessage()
278
	{
279
		Definition defintion = _editor.getCapabilityDomain().getCapability()
280
				.getDefinition();
281
		CapabilityWSDLValidator validator = new CapabilityWSDLValidator();
282
		IValidationReport report = validator.validate(defintion);
283
		boolean hasProblem = report.hasErrors() || report.hasWarnings();
284
		if (hasProblem)
183
		{
285
		{
184
		    Definition definition =  _editor.getCapabilityDomain().getDefinition();
286
			// We have a problem, is it an error or just a warning?
185
		    List importsWsdl = definition.getImports(definition
287
			boolean hasError = false;
186
			    .getTargetNamespace());
288
			String msg;
187
		    if (importsWsdl.size() > 0)
289
			if (report.hasErrors())
188
		    {
290
			{
189
			_dialogThrown = true;
291
				hasError = true;
190
			boolean ok = MessageDialog
292
				msg = report.getErrorMessages()[0].getMessage();
191
			.openConfirm(
293
			}
192
				getForm().getShell(),
294
			else
193
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.CONFIRM_MESSAGE,
295
			{
194
				Messages.IMPORT_WSDL_NS_CHANGE_MESSAGE);
296
				msg = report.getWarningMessages()[0].getMessage();
195
			if(!ok)
297
			}
196
			    _capabilityNameText.setFocus();
298
			_errorLabel.setBackground(getForm().getDisplay().getSystemColor(
197
		    }
299
					hasError ? SWT.COLOR_RED : SWT.COLOR_YELLOW));
198
			
300
			_errorLabel.setForeground(getForm().getDisplay().getSystemColor(
301
					hasError ? SWT.COLOR_WHITE : SWT.COLOR_BLACK));
302
			_errorLabel.setText(" " + msg + " ");
199
		}
303
		}
200
	    }    
304
		else
201
	});
305
		{
202
	_descriptionText.addModifyListener(new ModifyListener()
306
			_errorLabel.setBackground(getForm().getBackground());
203
	{
307
			_errorLabel.setForeground(getForm().getForeground());
204
	    public void modifyText(ModifyEvent e)
308
			_errorLabel.setText("");
205
	    {
309
		}
206
		changeCapabilityDescription();
310
	}
207
	    }
311
208
	});
312
	public void pageChange(int newPageIndex)
209
	_descriptionText.addFocusListener(new FocusAdapter(){
313
	{
210
	    public void focusGained(FocusEvent e)
211
	    {
212
		_dialogThrown = false;
314
		_dialogThrown = false;
213
	    }
315
	}
214
	});	
215
    }
216
217
    private void changeCapabilityName()
218
    {
219
	if (!_capabilityNameText.getText().equals(_capabilityName))
220
	{
221
	    CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
222
	    String newName = _capabilityNameText.getText();
223
	    ChangeCapabilityNameCommand command = new ChangeCapabilityNameCommand(
224
		    capabilityDomain, newName);
225
	    command.execute();
226
	    _page.setDirty();
227
	}
228
    }
229
230
    private void changeCapabilityNamespace()
231
    {
232
	if (!_namespaceText.getText().equals(_namespace))
233
	{
234
	    CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
235
	    String newNS = _namespaceText.getText();
236
	    ChangeCapabilityNamespaceCommand command = new ChangeCapabilityNamespaceCommand(
237
		    capabilityDomain, newNS);
238
	    command.execute();
239
	    _page.setDirty();
240
	}
241
    }
242
243
    private void changeCapabilityDescription()
244
    {
245
	if (!_descriptionText.getText().equals(_description))
246
	{
247
	    CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
248
	    String newDescription = _descriptionText.getText();
249
	    ChangeCapabilityDescriptionCommand command = new ChangeCapabilityDescriptionCommand(
250
		    capabilityDomain, newDescription);
251
	    command.execute();
252
	    _page.setDirty();
253
	}
254
    }
255
256
    /**
257
         * Handle viewer selection changed.
258
         */
259
    public void selectionChanged(SelectionChangedEvent event)
260
    {
261
    }
262
263
    /**
264
         * Update its selected object.
265
         */
266
    public void setSelectedObject(Object object)
267
    {
268
    }
269
270
    /**
271
         * Enable or disable the section based on parameter passed.
272
         */
273
    public void enable(boolean enabled)
274
    {
275
    }
276
277
    private void updateErrorMessage()
278
    {
279
	Definition defintion = _editor.getCapabilityDomain().getDefinition();
280
	CapabilityWSDLValidator validator = new CapabilityWSDLValidator();
281
	IValidationReport report = validator.validate(defintion);
282
	boolean hasProblem = report.hasErrors() || report.hasWarnings();
283
	if (hasProblem)
284
	{
285
	    // We have a problem, is it an error or just a warning?
286
	    boolean hasError = false;
287
	    String msg;
288
	    if (report.hasErrors())
289
	    {
290
		hasError = true;
291
		msg = report.getErrorMessages()[0].getMessage();
292
	    }
293
	    else
294
	    {
295
		msg = report.getWarningMessages()[0].getMessage();
296
	    }
297
	    _errorLabel.setBackground(getForm().getDisplay().getSystemColor(
298
		    hasError ? SWT.COLOR_RED : SWT.COLOR_YELLOW));
299
	    _errorLabel.setForeground(getForm().getDisplay().getSystemColor(
300
		    hasError ? SWT.COLOR_WHITE : SWT.COLOR_BLACK));
301
	    _errorLabel.setText(" " + msg + " ");
302
	}
303
	else
304
	{
305
	    _errorLabel.setBackground(getForm().getBackground());
306
	    _errorLabel.setForeground(getForm().getForeground());
307
	    _errorLabel.setText("");
308
	}
309
    }
310
311
    public void pageChange(int newPageIndex)
312
    {
313
	_dialogThrown = false;
314
    }
315
316
316
}
317
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/topic/internal/AddRootTopicCommand.java (-66 / +62 lines)
Lines 10-115 Link Here
10
 *     IBM Corporation - initial API and implementation
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
11
 *******************************************************************************/
12
12
13
14
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.topic.internal;
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.command.topic.internal;
15
14
16
import java.util.List;
15
import java.util.List;
17
16
18
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
17
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
19
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
18
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
19
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
23
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
23
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
24
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
24
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
25
import org.eclipse.tptp.wsdm.tooling.util.internal.TopicUtils;
26
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
25
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
27
26
28
29
/**
27
/**
30
 * 
28
 * 
31
 * Command class to add new root topic to topicspace.<br>
29
 * Command class to add new root topic to topicspace.<br>
32
 * If the given topicnamespace doesn't exists in model then it will create new TopicSpace.<br>
30
 * If the given topicnamespace doesn't exists in model then it will create new
33
 * If RMD doesn't contain any <b>TopicExpression</b> property then it will create new TopicExpression property in RMD.
31
 * TopicSpace.<br>
32
 * If RMD doesn't contain any <b>TopicExpression</b> property then it will
33
 * create new TopicExpression property in RMD.
34
 * 
34
 * 
35
 * 
35
 *
36
 */
36
 */
37
37
38
public class AddRootTopicCommand
38
public class AddRootTopicCommand
39
{
39
{
40
40
41
    private Capability _capability;
41
	private Capability _capability;
42
42
43
    private String _topicNamespace;
43
	private String _topicNamespace;
44
44
45
    private Topic _rootTopic;
45
	private Topic _rootTopic;
46
46
47
    private CapabilityDomain _capabilityDomain;
47
	private CapabilityDomain _capabilityDomain;
48
48
49
    /**
49
	/**
50
     * Creates a new object of this class. 
50
	 * Creates a new object of this class.
51
     */
51
	 */
52
    public AddRootTopicCommand(CapabilityDomain capabilityDomain,
52
	public AddRootTopicCommand(CapabilityDomain capabilityDomain,
53
	    String topicNamespace, Topic rootTopic)
53
			String topicNamespace, Topic rootTopic)
54
    {
55
	_capabilityDomain = capabilityDomain;
56
	_capability = capabilityDomain.getCapability();
57
	_topicNamespace = topicNamespace;
58
	_rootTopic = rootTopic;
59
    }
60
61
    /**
62
     * Execute the command. 
63
     */
64
    public void execute()
65
    {
66
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = _capabilityDomain
67
		.getMetaDataDescriptor();
68
	if (propertyMetaDataDescriptor == null)
69
	{
54
	{
70
	    propertyMetaDataDescriptor = createMetaDataDescriptor();
55
		_capabilityDomain = capabilityDomain;
56
		_capability = capabilityDomain.getCapability();
57
		_topicNamespace = topicNamespace;
58
		_rootTopic = rootTopic;
71
	}
59
	}
72
60
73
	PropertyType topicExpressionProperty = propertyMetaDataDescriptor
61
	/**
74
		.getTopicExpressionProperty();
62
	 * Execute the command.
75
	if (topicExpressionProperty == null)
63
	 */
64
	public void execute()
76
	{
65
	{
77
	    propertyMetaDataDescriptor.createTopicExpressionProperty();
66
		MetadataDescriptor propertyMetaDataDescriptor = _capabilityDomain
67
				.getCapability().getMetadata();
68
		if (propertyMetaDataDescriptor == null)
69
			propertyMetaDataDescriptor = createMetaDataDescriptor();
70
71
		PropertyType topicExpressionProperty = propertyMetaDataDescriptor
72
				.getTopicExpressionProperty();
73
		if (topicExpressionProperty == null)
74
			propertyMetaDataDescriptor.createTopicExpressionProperty();
75
76
		TopicSpace topicSpace = getTopicSpace();
77
		if (topicSpace == null)
78
		{
79
			topicSpace = CapabilitiesFactory.eINSTANCE.createTopicSpace();
80
			topicSpace.setName(_topicNamespace);
81
			topicSpace.setNamespace(_topicNamespace);
82
			_capability.getTopicSpaces().add(topicSpace);
83
		}
84
85
		_rootTopic.setParent(null);
86
		topicSpace.getRootTopics().add(_rootTopic);
78
	}
87
	}
79
88
80
	TopicSpace topicSpace = getTopicSpace();
89
	private TopicSpace getTopicSpace()
81
	if (topicSpace == null)
82
	{
90
	{
83
	    topicSpace = TopicUtils.createNewTopicSpace();
91
		if (_capability.getTopicSpaces() == null)
84
	    topicSpace.setName(_topicNamespace);
92
			return null;
85
	    topicSpace.setNamespace(_topicNamespace);
93
		List topicSpaces = _capability.getTopicSpaces();
86
	    _capability.getTopicSpaces().add(topicSpace);
94
		for (int i = 0; i < topicSpaces.size(); i++)
95
		{
96
			TopicSpace topicSpace = (TopicSpace) topicSpaces.get(i);
97
			if (topicSpace.getNamespace().equals(_topicNamespace))
98
				return topicSpace;
99
		}
100
		return null;
87
	}
101
	}
88
102
89
	_rootTopic.setParent(null);
103
	private MetadataDescriptor createMetaDataDescriptor()
90
	topicSpace.getRootTopics().add(_rootTopic);
91
    }
92
93
    private TopicSpace getTopicSpace()
94
    {
95
	if (_capability.getTopicSpaces() == null)
96
	    return null;
97
	List topicSpaces = _capability.getTopicSpaces();
98
	for (int i = 0; i < topicSpaces.size(); i++)
99
	{
104
	{
100
	    TopicSpace topicSpace = (TopicSpace) topicSpaces.get(i);
105
		MetadataDescriptor propertyMetaDataDescriptor = MetaDataUtils
101
	    if (topicSpace.getNamespace().equals(_topicNamespace))
106
				.createMetaDataDescriptor(_capabilityDomain);
102
		return topicSpace;
107
		propertyMetaDataDescriptor.getDocumentRoot().getXMLNSPrefixMap().put(
108
				"wsnt", WsdmConstants.WSNT_NS);
109
		return propertyMetaDataDescriptor;
103
	}
110
	}
104
	return null;
105
    }
106
107
    private PropertyMetaDataDescriptor createMetaDataDescriptor()
108
    {
109
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = MetaDataUtils
110
		.createMetaDataDescriptor(_capabilityDomain);
111
	propertyMetaDataDescriptor.getDocumentRoot().getXMLNSPrefixMap().put(
112
		"wsnt", WsdmConstants.WSNT_NS);
113
	return propertyMetaDataDescriptor;
114
    }
115
}
111
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/topic/internal/RemoveTopicNamespaceCommand.java (-12 / +11 lines)
Lines 16-22 Link Here
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
16
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
19
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
19
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
20
20
21
/**
21
/**
22
 * 
22
 * 
Lines 39-47 Link Here
39
    public RemoveTopicNamespaceCommand(CapabilityDomain capabilityDomain,
39
    public RemoveTopicNamespaceCommand(CapabilityDomain capabilityDomain,
40
	    TopicSpace topicSpace)
40
	    TopicSpace topicSpace)
41
    {
41
    {
42
	_capabilityDomain = capabilityDomain;
42
		_capabilityDomain = capabilityDomain;
43
	_capability = capabilityDomain.getCapability();
43
		_capability = capabilityDomain.getCapability();
44
	_topicSpace = topicSpace;
44
		_topicSpace = topicSpace;
45
    }
45
    }
46
46
47
    /**
47
    /**
Lines 50-66 Link Here
50
     */
50
     */
51
    public void execute()
51
    public void execute()
52
    {
52
    {
53
	removeNSFromMetadata();
53
		removeNSFromMetadata();
54
	_capability.getTopicSpaces().remove(_topicSpace);
54
		_capability.getTopicSpaces().remove(_topicSpace);
55
    }
55
    }
56
56
57
    private void removeNSFromMetadata()
57
    private void removeNSFromMetadata()
58
    {
58
    {
59
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = _capabilityDomain
59
		MetadataDescriptor metaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
60
		.getMetaDataDescriptor();
60
		String prefix = metaDataDescriptor.getPrefix(_topicSpace
61
	String prefix = propertyMetaDataDescriptor.getPrefix(_topicSpace
61
			.getNamespace());
62
		.getNamespace());
62
		metaDataDescriptor.getDocumentRoot().getXMLNSPrefixMap()
63
	propertyMetaDataDescriptor.getDocumentRoot().getXMLNSPrefixMap()
63
			.remove(prefix);
64
		.remove(prefix);
65
    }
64
    }
66
}
65
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/property/internal/MetricsSection.java (-230 / +245 lines)
Lines 38-44 Link Here
38
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
38
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
39
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
39
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
40
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.FormMetric;
40
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.FormMetric;
41
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
42
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractPageSection;
41
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractPageSection;
43
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
42
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
44
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
43
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
Lines 56-322 Link Here
56
public class MetricsSection extends AbstractPageSection
55
public class MetricsSection extends AbstractPageSection
57
{
56
{
58
57
59
    private TableViewer _metricsViewer;
58
	private TableViewer _metricsViewer;
60
59
61
    private Property _selectedProperty;
60
	private Property _selectedProperty;
62
61
63
    /**
62
	/**
64
     * Creates the new object of this class. 
63
	 * Creates the new object of this class.
65
     */
64
	 */
66
    MetricsSection(CapabilityEditor editor, IUIPage page, ScrolledForm form,
65
	MetricsSection(CapabilityEditor editor, IUIPage page, ScrolledForm form,
67
	    FormToolkit toolkit)
66
			FormToolkit toolkit)
68
    {
67
	{
69
	super(editor, page, form, toolkit);
68
		super(editor, page, form, toolkit);
70
    }
69
	}
71
70
72
    /**
71
	/**
73
     * Creates the section.
72
	 * Creates the section.
74
     */
73
	 */
75
    public void create()
74
	public void create()
76
    {
75
	{
77
	Composite sectionClient = createSection(Messages.METRICS,
76
		Composite sectionClient = createSection(Messages.METRICS,
78
		Messages.METRICS_OF_PROP);
77
				Messages.METRICS_OF_PROP);
79
	GridLayout layout = new GridLayout();
78
		GridLayout layout = new GridLayout();
80
	layout.marginWidth = LAYOUT_MARGIN_WIDTH;
79
		layout.marginWidth = LAYOUT_MARGIN_WIDTH;
81
	layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
80
		layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
82
	layout.horizontalSpacing = LAYOUT_HORIZONTAL_SPACING;
81
		layout.horizontalSpacing = LAYOUT_HORIZONTAL_SPACING;
83
	sectionClient.setLayout(layout);
82
		sectionClient.setLayout(layout);
84
	
83
85
	Table swtTable = getToolkit().createTable(
84
		Table swtTable = getToolkit().createTable(
86
		sectionClient,
85
				sectionClient,
87
		SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL
86
				SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL
88
			| SWT.MULTI);
87
						| SWT.MULTI);
89
	_metricsViewer = new TableViewer(swtTable);
88
		_metricsViewer = new TableViewer(swtTable);
90
	GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
89
		GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
91
	_metricsViewer.getControl().setLayoutData(gd);
90
		_metricsViewer.getControl().setLayoutData(gd);
92
91
93
	Table table = _metricsViewer.getTable();
92
		Table table = _metricsViewer.getTable();
94
93
95
	TableColumn column = new TableColumn(table, SWT.NONE, 0);
94
		TableColumn column = new TableColumn(table, SWT.NONE, 0);
96
	column.setText(Messages.CHANGE_TYPE);
95
		column.setText(Messages.CHANGE_TYPE);
97
	column.setWidth(50);
96
		column.setWidth(50);
98
97
99
	column = new TableColumn(table, SWT.NONE, 1);
98
		column = new TableColumn(table, SWT.NONE, 1);
100
	column.setText(Messages.TIME_SCOPE); 
99
		column.setText(Messages.TIME_SCOPE);
101
	column.setWidth(50);
100
		column.setWidth(50);
102
101
103
	column = new TableColumn(table, SWT.NONE, 2);
102
		column = new TableColumn(table, SWT.NONE, 2);
104
	column.setText(Messages.GATHERING_TIME);
103
		column.setText(Messages.GATHERING_TIME);
105
	column.setWidth(50);
104
		column.setWidth(50);
106
105
107
	column = new TableColumn(table, SWT.NONE, 3);
106
		column = new TableColumn(table, SWT.NONE, 3);
108
	column.setText(Messages.CALCULATION_INTERVAL);
107
		column.setText(Messages.CALCULATION_INTERVAL);
109
	column.setWidth(50);
108
		column.setWidth(50);
110
109
111
	column = new TableColumn(table, SWT.NONE, 4);
110
		column = new TableColumn(table, SWT.NONE, 4);
112
	column.setText(Messages.METRIC_GROUP);
111
		column.setText(Messages.METRIC_GROUP);
113
	column.setWidth(50);
112
		column.setWidth(50);
114
113
115
	table.redraw();
114
		table.redraw();
116
	table.setHeaderVisible(true);
115
		table.setHeaderVisible(true);
117
	table.setLinesVisible(true);
116
		table.setLinesVisible(true);
118
117
119
	MetricsContentProvider contentProvider = new MetricsContentProvider(
118
		MetricsContentProvider contentProvider = new MetricsContentProvider(
120
		getForm().getShell());
119
				getForm().getShell());
121
	_metricsViewer.setContentProvider(contentProvider);
120
		_metricsViewer.setContentProvider(contentProvider);
122
	_metricsViewer.setLabelProvider(contentProvider.getLabelProvider());
121
		_metricsViewer.setLabelProvider(contentProvider.getLabelProvider());
123
124
	attachCellEditors();
125
	
126
	enable(!_editor.isReadOnly());
127
    }
128
129
    private void attachCellEditors()
130
    {
131
	// Assign 'names' to each column
132
	_metricsViewer.setColumnProperties(FormMetric.COLUMN_NAMES);
133
122
134
	Table table = _metricsViewer.getTable();
123
		attachCellEditors();
135
	_metricsViewer.setCellEditors(new CellEditor[] {
124
125
		enable(!_editor.isReadOnly());
126
	}
127
128
	private void attachCellEditors()
129
	{
130
		// Assign 'names' to each column
131
		_metricsViewer.setColumnProperties(FormMetric.COLUMN_NAMES);
132
133
		Table table = _metricsViewer.getTable();
134
		_metricsViewer.setCellEditors(new CellEditor[] {
136
		// Change type
135
		// Change type
137
		new ComboBoxCellEditor(table, FormMetric.CTYPE_STR_ENUM,
136
				new ComboBoxCellEditor(table, FormMetric.CTYPE_STR_ENUM,
138
			SWT.READ_ONLY),
137
						SWT.READ_ONLY),
139
		// Time scope
138
				// Time scope
140
		new ComboBoxCellEditor(table, FormMetric.TSCOPE_STR_ENUM,
139
				new ComboBoxCellEditor(table, FormMetric.TSCOPE_STR_ENUM,
141
			SWT.READ_ONLY),
140
						SWT.READ_ONLY),
142
		// Gathering time
141
				// Gathering time
143
		new ComboBoxCellEditor(table, FormMetric.GTIME_STR_ENUM,
142
				new ComboBoxCellEditor(table, FormMetric.GTIME_STR_ENUM,
144
			SWT.READ_ONLY),
143
						SWT.READ_ONLY),
145
		// Calculation interval
144
				// Calculation interval
146
		new XsdDurationCellEditor(table),
145
				new XsdDurationCellEditor(table),
147
		// Metric group
146
				// Metric group
148
		new TextCellEditor(table, SWT.RIGHT | SWT.READ_ONLY), });
147
				new TextCellEditor(table, SWT.RIGHT | SWT.READ_ONLY), });
148
149
		_metricsViewer.setCellModifier(new ICellModifier() {
150
			public boolean canModify(Object element, String property)
151
			{
152
				if (element instanceof FormMetric)
153
				{
154
					FormMetric metric = (FormMetric) element;
155
					return metric.canModify(property);
156
				}
157
				throw new IllegalStateException(NLS.bind(
158
						Messages.UNEXPECTED_TYPE_ERROR_, element.getClass()));
159
			}
160
161
			public Object getValue(Object element, String property)
162
			{
163
				if (element instanceof FormMetric)
164
				{
165
					FormMetric metric = (FormMetric) element;
166
					return metric.getColumnObject(property);
167
				}
168
				throw new IllegalStateException(NLS.bind(
169
						Messages.UNEXPECTED_TYPE_ERROR_, element.getClass()));
170
			}
171
172
			public void modify(Object element, String property, Object value)
173
			{
174
				TableItem ti = null;
175
				if (element instanceof TableItem)
176
					ti = (TableItem) element;
177
				else if (element instanceof Table)
178
				{
179
					Table table = (Table) element;
180
					ti = table.getItem(0);
181
				}
182
				else
183
					return;
184
185
				FormMetric metric = (FormMetric) ti.getData();
186
				metric.setColumnObject(property, value);
187
				_page.setDirty();
188
				/*
189
				 * CapabilityDomain capabilityDomain = _editor
190
				 * .getCapabilityDomain(); metric =
191
				 * MetaDataUtils.getMetric(capabilityDomain, _selectedProperty);
192
				 * _metricsViewer.setInput(metric);
193
				 */
194
			}
195
		});
196
	}
149
197
150
	_metricsViewer.setCellModifier(new ICellModifier()
198
	/**
199
	 * Refreshes the section.
200
	 */
201
	public void refresh()
151
	{
202
	{
152
	    public boolean canModify(Object element, String property)
203
		_metricsViewer.refresh();
153
	    {
204
	}
154
		if (element instanceof FormMetric)
205
206
	/**
207
	 * Initializes control listeners.
208
	 */
209
	public void hookAllListeners()
210
	{
211
	}
212
213
	/**
214
	 * Handle viewer selection changed.
215
	 */
216
	public void selectionChanged(SelectionChangedEvent event)
217
	{
218
		_metricsViewer.getTable().setEnabled(
219
				_selectedProperty != null && !_editor.isReadOnly());
220
		if (_selectedProperty != null)
155
		{
221
		{
156
		    FormMetric metric = (FormMetric) element;
222
			FormMetric metric = createMetricFromProperty();
157
		    return metric.canModify(property);
223
			_metricsViewer.setInput(metric);
158
		}
224
		}
159
		throw new IllegalStateException(NLS.bind(Messages.UNEXPECTED_TYPE_ERROR_, element.getClass()));		
225
	}
160
	    }
161
226
162
	    public Object getValue(Object element, String property)
227
	private FormMetric createMetricFromProperty()
163
	    {
228
	{
164
		if (element instanceof FormMetric)
229
		CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
230
		FormMetric formMetric = new FormMetric(capabilityDomain,
231
				_selectedProperty);
232
		return formMetric;
233
	}
234
235
	/**
236
	 * Update its selected object.
237
	 */
238
	public void setSelectedObject(Object object)
239
	{
240
		_selectedProperty = null;
241
		if (object instanceof Property)
165
		{
242
		{
166
		    FormMetric metric = (FormMetric) element;
243
			_selectedProperty = (Property) object;
167
		    return metric.getColumnObject(property);
168
		}
244
		}
169
		throw new IllegalStateException(NLS.bind(Messages.UNEXPECTED_TYPE_ERROR_, element.getClass()));
245
	}
170
	    }
171
246
172
	    public void modify(Object element, String property, Object value)
247
	/**
173
	    {
248
	 * Enable or disable the section based on parameter passed.
174
		TableItem ti = (TableItem) element;
249
	 */
175
		FormMetric metric = (FormMetric) ti.getData();
250
	public void enable(boolean enabled)
176
		metric.setColumnObject(property, value);
251
	{
177
		_page.setDirty();
252
		_metricsViewer.getTable().setEnabled(enabled);
178
		CapabilityDomain capabilityDomain = _editor
253
	}
179
			.getCapabilityDomain();
180
		metric = MetaDataUtils.getMetric(capabilityDomain,
181
			_selectedProperty);
182
		_metricsViewer.setInput(metric);
183
	    }
184
	});
185
    }
186
187
    /**
188
     * Refreshes the section.
189
     */
190
    public void refresh()
191
    {	
192
    }
193
194
    /**
195
     * Initializes control listeners.
196
     */
197
    public void hookAllListeners()
198
    {
199
    }
200
201
    /**
202
     * Handle viewer selection changed.
203
     */
204
    public void selectionChanged(SelectionChangedEvent event)
205
    {
206
	_metricsViewer.getTable().setEnabled(_selectedProperty != null && !_editor.isReadOnly());
207
	if (_selectedProperty != null)
208
	{
209
	    FormMetric metric = createMetricFromProperty();
210
	    _metricsViewer.setInput(metric);
211
	}
212
    }
213
214
    private FormMetric createMetricFromProperty()
215
    {
216
	CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
217
	FormMetric metric = MetaDataUtils.getMetric(capabilityDomain,
218
		_selectedProperty);
219
	return metric;
220
    }
221
222
    /**
223
     * Update its selected object.
224
     */
225
    public void setSelectedObject(Object object)
226
    {
227
	_selectedProperty = null;
228
	if (object instanceof Property)
229
	{
230
	    _selectedProperty = (Property) object;
231
	}
232
    }
233
234
    /**
235
     * Enable or disable the section based on parameter passed.
236
     */
237
    public void enable(boolean enabled)
238
    {
239
	_metricsViewer.getTable().setEnabled(enabled);
240
    }
241
}
254
}
242
255
243
class XsdDurationCellEditor extends DialogCellEditor
256
class XsdDurationCellEditor extends DialogCellEditor
244
{
257
{
245
258
246
    public XsdDurationCellEditor(Table table)
259
	public XsdDurationCellEditor(Table table)
247
    {
248
	super(table);
249
    }
250
251
    protected Object openDialogBox(Control cellEditorWindow)
252
    {
253
	String duration = (String) doGetValue();
254
	if (duration == null)
255
	    duration = "PT1M";
256
	XsdDurationDialog dlg = new XsdDurationDialog(cellEditorWindow
257
		.getShell(), duration);
258
	if (dlg.open() == XsdDurationDialog.OK)
259
	{
260
	{
260
	    return dlg.getXsdDuration();
261
		super(table);
261
	}
262
	}
262
263
263
	return null;
264
	protected Object openDialogBox(Control cellEditorWindow)
264
    }
265
	{
266
		String duration = (String) doGetValue();
267
		if (duration == null)
268
			duration = "PT1M";
269
		XsdDurationDialog dlg = new XsdDurationDialog(cellEditorWindow
270
				.getShell(), duration);
271
		if (dlg.open() == XsdDurationDialog.OK)
272
		{
273
			return dlg.getXsdDuration();
274
		}
275
276
		return null;
277
	}
265
278
266
}
279
}
267
280
268
class MetricsContentProvider implements IStructuredContentProvider
281
class MetricsContentProvider implements IStructuredContentProvider
269
{
282
{
270
283
271
    private final Shell shell;
284
	private final Shell shell;
285
286
	public MetricsContentProvider(Shell _shell)
287
	{
288
		this.shell = _shell;
289
	}
290
291
	public Object[] getElements(Object element)
292
	{
293
		if (element instanceof FormMetric)
294
		{
295
			return new Object[] { element };
296
		}
297
		throw new IllegalStateException(NLS.bind(
298
				Messages.UNEXPECTED_TYPE_ERROR_, element.getClass()));
299
	}
300
301
	public void dispose()
302
	{
303
	}
304
305
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
306
	{
307
	}
272
308
273
    public MetricsContentProvider(Shell _shell)
309
	public IBaseLabelProvider getLabelProvider()
274
    {
310
	{
275
	this.shell = _shell;
311
		return new MetricsLabelProvider(shell);
276
    }
312
	}
277
278
    public Object[] getElements(Object element)
279
    {
280
	if (element instanceof FormMetric)
281
	{
282
	    return new Object[] { element };
283
	}
284
	throw new IllegalStateException(NLS.bind(Messages.UNEXPECTED_TYPE_ERROR_, element.getClass()));
285
    }
286
287
    public void dispose()
288
    {
289
    }
290
291
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
292
    {
293
    }
294
295
    public IBaseLabelProvider getLabelProvider()
296
    {
297
	return new MetricsLabelProvider(shell);
298
    }
299
}
313
}
300
314
301
class MetricsLabelProvider extends LabelProvider implements ITableLabelProvider
315
class MetricsLabelProvider extends LabelProvider implements ITableLabelProvider
302
{
316
{
303
317
304
    public MetricsLabelProvider(Shell _shell)
318
	public MetricsLabelProvider(Shell _shell)
305
    {
319
	{
306
    }
320
	}
307
321
308
    public Image getColumnImage(Object element, int columnIndex)
322
	public Image getColumnImage(Object element, int columnIndex)
309
    {
323
	{
310
	return null;
324
		return null;
311
    }
325
	}
312
326
313
    public String getColumnText(Object element, int columnIndex)
327
	public String getColumnText(Object element, int columnIndex)
314
    {
315
	if (element instanceof FormMetric)
316
	{
328
	{
317
	    FormMetric metric = (FormMetric) element;
329
		if (element instanceof FormMetric)
318
	    return metric.getColumnText(columnIndex);
330
		{
331
			FormMetric metric = (FormMetric) element;
332
			return metric.getColumnText(columnIndex);
333
		}
334
		throw new IllegalStateException(NLS.bind(
335
				Messages.UNEXPECTED_TYPE_ERROR_, element.getClass()));
319
	}
336
	}
320
	throw new IllegalStateException(NLS.bind(Messages.UNEXPECTED_TYPE_ERROR_, element.getClass()));
321
    }
322
}
337
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/property/internal/NewPropertyDialog.java (-612 / +616 lines)
Lines 60-686 Link Here
60
public class NewPropertyDialog extends Dialog
60
public class NewPropertyDialog extends Dialog
61
{
61
{
62
62
63
    private final String _title;
63
	private final String _title;
64
64
65
    private Text _propertyName;
65
	private Text _propertyName;
66
66
67
    private TreeViewer _dataTypeViewer;
67
	private TreeViewer _dataTypeViewer;
68
68
69
    private Button _importButton;
69
	private Button _importButton;
70
70
71
    private Button _writableButton;
71
	private Button _writableButton;
72
72
73
    private Button _readonlyButton;
73
	private Button _readonlyButton;
74
74
75
    private String _modifiability;
75
	private String _modifiability;
76
76
77
    private String _mutability;
77
	private String _mutability;
78
78
79
    private Button _propConstant;
79
	private Button _propConstant;
80
80
81
    private Button _propAppendable;
81
	private Button _propAppendable;
82
82
83
    private Button _propMutable;
83
	private Button _propMutable;
84
84
85
    private Button _button1to1;
85
	private Button _button1to1;
86
86
87
    private Button _button0to1;
87
	private Button _button0to1;
88
88
89
    private Button _button0toN;
89
	private Button _button0toN;
90
90
91
    private Button _button1toN;
91
	private Button _button1toN;
92
92
93
    private Button _buttonXtoY;
93
	private Button _buttonXtoY;
94
94
95
    private Text _propMinOccurs;
95
	private Text _propMinOccurs;
96
96
97
    private Text _propMaxOccurs;
97
	private Text _propMaxOccurs;
98
98
99
    private Listener _minMaxListener;
99
	private Listener _minMaxListener;
100
100
101
    private XSDElementDeclaration _property;
101
	private XSDElementDeclaration _property;
102
102
103
    private CapabilityDomain _capabilityDomain;
103
	private CapabilityDomain _capabilityDomain;
104
104
105
    private int _minoccurs;
105
	private int _minoccurs;
106
106
107
    private int _maxoccurs;
107
	private int _maxoccurs;
108
    
108
109
    private DataType _dataType;
109
	private DataType _dataType;
110
110
111
    /**
111
	/**
112
     * Creates the dialog for new property.
112
	 * Creates the dialog for new property.
113
     * 
113
	 * 
114
     * @param parentShell
114
	 * @param parentShell
115
     *        Shell.
115
	 *            Shell.
116
     *        
116
	 * 
117
     * @param dialogTitle
117
	 * @param dialogTitle
118
     *        Title for this dialog.
118
	 *            Title for this dialog.
119
     *        
119
	 * 
120
     * @param capabilityDomain
120
	 * @param capabilityDomain
121
     *        Capability domain for capability editor.
121
	 *            Capability domain for capability editor.
122
     *        
122
	 * 
123
     */
123
	 */
124
    public NewPropertyDialog(Shell parentShell, String dialogTitle,
124
	public NewPropertyDialog(Shell parentShell, String dialogTitle,
125
	    CapabilityDomain capabilityDomain)
125
			CapabilityDomain capabilityDomain)
126
    {
126
	{
127
	super(parentShell);
127
		super(parentShell);
128
	setShellStyle(getShellStyle() | SWT.RESIZE);
128
		setShellStyle(getShellStyle() | SWT.RESIZE);
129
	_title = dialogTitle;
129
		_title = dialogTitle;
130
	_capabilityDomain = capabilityDomain;
130
		_capabilityDomain = capabilityDomain;
131
	_property = XSDFactory.eINSTANCE.createXSDElementDeclaration();
131
		_property = XSDFactory.eINSTANCE.createXSDElementDeclaration();
132
    }
132
	}
133
133
134
    /**
134
	/**
135
     * Configure the shell.
135
	 * Configure the shell.
136
     */
136
	 */
137
    protected void configureShell(Shell shell)
137
	protected void configureShell(Shell shell)
138
    {
138
	{
139
	super.configureShell(shell);
139
		super.configureShell(shell);
140
	if (_title != null)
140
		if (_title != null)
141
	    shell.setText(_title);
141
			shell.setText(_title);
142
    }
142
	}
143
143
144
    /**
144
	/**
145
     * Creates the dialog area.
145
	 * Creates the dialog area.
146
     */
146
	 */
147
    protected Control createDialogArea(Composite parent)
147
	protected Control createDialogArea(Composite parent)
148
    {
148
	{
149
	Composite container = (Composite) super.createDialogArea(parent);
149
		Composite container = (Composite) super.createDialogArea(parent);
150
	GridLayout layout = new GridLayout(2, true);
150
		GridLayout layout = new GridLayout(2, true);
151
	container.setLayout(layout);
151
		container.setLayout(layout);
152
152
153
	Composite lhsComposite = new Composite(container, SWT.NONE);
153
		Composite lhsComposite = new Composite(container, SWT.NONE);
154
	layout = new GridLayout(1, true);
154
		layout = new GridLayout(1, true);
155
	layout.verticalSpacing = 5;
155
		layout.verticalSpacing = 5;
156
	lhsComposite.setLayout(layout);
156
		lhsComposite.setLayout(layout);
157
	GridData gd = new GridData();
157
		GridData gd = new GridData();
158
	gd.grabExcessHorizontalSpace = true;
158
		gd.grabExcessHorizontalSpace = true;
159
	lhsComposite.setLayoutData(gd);
159
		lhsComposite.setLayoutData(gd);
160
160
161
	Composite rhsComposite = new Composite(container, SWT.NONE);
161
		Composite rhsComposite = new Composite(container, SWT.NONE);
162
	layout = new GridLayout(1, true);
162
		layout = new GridLayout(1, true);
163
	layout.verticalSpacing = 5;
163
		layout.verticalSpacing = 5;
164
	rhsComposite.setLayout(layout);
164
		rhsComposite.setLayout(layout);
165
	gd = new GridData();
165
		gd = new GridData();
166
	gd.grabExcessHorizontalSpace = true;
166
		gd.grabExcessHorizontalSpace = true;
167
	rhsComposite.setLayoutData(gd);
167
		rhsComposite.setLayoutData(gd);
168
168
169
	createLeftCompositeArea(lhsComposite);
169
		createLeftCompositeArea(lhsComposite);
170
	createRightCompositeArea(rhsComposite);
170
		createRightCompositeArea(rhsComposite);
171
	
171
172
	initializeControls();
172
		initializeControls();
173
	hookAllListeners();
173
		hookAllListeners();
174
174
175
	applyDialogFont(container);
175
		applyDialogFont(container);
176
	return container;
176
		return container;
177
    }
177
	}
178
    
178
179
    private void createLeftCompositeArea(Composite lhsComposite)
179
	private void createLeftCompositeArea(Composite lhsComposite)
180
    {
180
	{
181
	Label propertyNameLabel = new Label(lhsComposite, SWT.NONE);
181
		Label propertyNameLabel = new Label(lhsComposite, SWT.NONE);
182
	propertyNameLabel.setText(Messages.PROP_NAME);
182
		propertyNameLabel.setText(Messages.PROP_NAME);
183
	GridData gd = new GridData();
183
		GridData gd = new GridData();
184
	gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
184
		gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
185
	propertyNameLabel.setLayoutData(gd);
185
		propertyNameLabel.setLayoutData(gd);
186
186
187
	_propertyName = new Text(lhsComposite, SWT.SINGLE | SWT.BORDER);
187
		_propertyName = new Text(lhsComposite, SWT.SINGLE | SWT.BORDER);
188
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
188
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
189
	gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
189
		gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
190
	_propertyName.setLayoutData(gd);
190
		_propertyName.setLayoutData(gd);
191
191
192
	Label propertyTypeLabel = new Label(lhsComposite, SWT.NONE);
192
		Label propertyTypeLabel = new Label(lhsComposite, SWT.NONE);
193
	propertyTypeLabel.setText(Messages.PROP_TYPE);
193
		propertyTypeLabel.setText(Messages.PROP_TYPE);
194
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
194
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
195
	gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
195
		gd.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
196
	propertyTypeLabel.setLayoutData(gd);
196
		propertyTypeLabel.setLayoutData(gd);
197
197
198
	_dataTypeViewer = new TreeViewer(lhsComposite, SWT.BORDER | SWT.H_SCROLL
198
		_dataTypeViewer = new TreeViewer(lhsComposite, SWT.BORDER
199
		| SWT.V_SCROLL);
199
				| SWT.H_SCROLL | SWT.V_SCROLL);
200
	GridData data = new GridData();
200
		GridData data = new GridData();
201
	data.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
201
		data.horizontalSpan = ((GridLayout) lhsComposite.getLayout()).numColumns;
202
	data.heightHint = 220;
202
		data.heightHint = 220;
203
	data.widthHint = 200;
203
		data.widthHint = 200;
204
	data.horizontalAlignment = GridData.FILL;
204
		data.horizontalAlignment = GridData.FILL;
205
	data.verticalAlignment = GridData.FILL;
205
		data.verticalAlignment = GridData.FILL;
206
	data.grabExcessHorizontalSpace = true;
206
		data.grabExcessHorizontalSpace = true;
207
	data.grabExcessVerticalSpace = true;
207
		data.grabExcessVerticalSpace = true;
208
	_dataTypeViewer.getControl().setLayoutData(data);
208
		_dataTypeViewer.getControl().setLayoutData(data);
209
	DataTypesContentProvider contentProvider = new DataTypesContentProvider();
209
		DataTypesContentProvider contentProvider = new DataTypesContentProvider();
210
	_dataTypeViewer.setContentProvider(contentProvider);
210
		_dataTypeViewer.setContentProvider(contentProvider);
211
	_dataTypeViewer.setLabelProvider(contentProvider.getLabelProvider());
211
		_dataTypeViewer.setLabelProvider(contentProvider.getLabelProvider());
212
	_dataTypeViewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
212
		_dataTypeViewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
213
			FormToolkit.TREE_BORDER);
213
				FormToolkit.TREE_BORDER);
214
	
214
215
	_importButton = new Button(lhsComposite, SWT.PUSH);
215
		_importButton = new Button(lhsComposite, SWT.PUSH);
216
	_importButton.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.IMPORT_COMPLEX_DATA_TYPE);
216
		_importButton
217
    }
217
				.setText(org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.IMPORT_COMPLEX_DATA_TYPE);
218
    
218
	}
219
    private void createRightCompositeArea(Composite rhsComposite)
219
220
    {
220
	private void createRightCompositeArea(Composite rhsComposite)
221
	Group modifiabilityGroup = new Group(rhsComposite, SWT.SHADOW_IN);
221
	{
222
	GridLayout layout = new GridLayout(1, true);
222
		Group modifiabilityGroup = new Group(rhsComposite, SWT.SHADOW_IN);
223
	modifiabilityGroup.setLayout(layout);
223
		GridLayout layout = new GridLayout(1, true);
224
	GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
224
		modifiabilityGroup.setLayout(layout);
225
	gd.grabExcessHorizontalSpace = true;
225
		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
226
	modifiabilityGroup.setLayoutData(gd);
226
		gd.grabExcessHorizontalSpace = true;
227
	modifiabilityGroup.setText(Messages.MAKE_THIS_PROP_LABEL);
227
		modifiabilityGroup.setLayoutData(gd);
228
	_writableButton = new Button(modifiabilityGroup, SWT.RADIO);
228
		modifiabilityGroup.setText(Messages.MAKE_THIS_PROP_LABEL);
229
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
229
		_writableButton = new Button(modifiabilityGroup, SWT.RADIO);
230
	gd.horizontalSpan = ((GridLayout) modifiabilityGroup.getLayout()).numColumns;
230
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
231
	_writableButton.setLayoutData(gd);
231
		gd.horizontalSpan = ((GridLayout) modifiabilityGroup.getLayout()).numColumns;
232
	_writableButton.setText(Messages.WRITABLE);
232
		_writableButton.setLayoutData(gd);
233
	_readonlyButton = new Button(modifiabilityGroup, SWT.RADIO);
233
		_writableButton.setText(Messages.WRITABLE);
234
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
234
		_readonlyButton = new Button(modifiabilityGroup, SWT.RADIO);
235
	gd.horizontalSpan = ((GridLayout) modifiabilityGroup.getLayout()).numColumns;
235
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
236
	_readonlyButton.setLayoutData(gd);
236
		gd.horizontalSpan = ((GridLayout) modifiabilityGroup.getLayout()).numColumns;
237
	_readonlyButton.setText(Messages.READ_ONLY);
237
		_readonlyButton.setLayoutData(gd);
238
238
		_readonlyButton.setText(Messages.READ_ONLY);
239
	Group mutability = new Group(rhsComposite, SWT.SHADOW_IN);
239
240
	layout = new GridLayout(1, true);
240
		Group mutability = new Group(rhsComposite, SWT.SHADOW_IN);
241
	mutability.setLayout(layout);
241
		layout = new GridLayout(1, true);
242
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
242
		mutability.setLayout(layout);
243
	gd.grabExcessHorizontalSpace = true;
243
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
244
	mutability.setLayoutData(gd);
244
		gd.grabExcessHorizontalSpace = true;
245
	mutability.setText(Messages.MUTABILITY);
245
		mutability.setLayoutData(gd);
246
	_propMutable = new Button(mutability, SWT.RADIO);
246
		mutability.setText(Messages.MUTABILITY);
247
	_propMutable.setText(Messages.MUTABLE);
247
		_propMutable = new Button(mutability, SWT.RADIO);
248
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
248
		_propMutable.setText(Messages.MUTABLE);
249
	gd.horizontalSpan = ((GridLayout) mutability.getLayout()).numColumns;
249
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
250
	_propMutable.setLayoutData(gd);
250
		gd.horizontalSpan = ((GridLayout) mutability.getLayout()).numColumns;
251
	_propConstant = new Button(mutability, SWT.RADIO);
251
		_propMutable.setLayoutData(gd);
252
	_propConstant.setText(Messages.CONSTANT);
252
		_propConstant = new Button(mutability, SWT.RADIO);
253
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
253
		_propConstant.setText(Messages.CONSTANT);
254
	gd.horizontalSpan = ((GridLayout) mutability.getLayout()).numColumns;
254
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
255
	_propConstant.setLayoutData(gd);
255
		gd.horizontalSpan = ((GridLayout) mutability.getLayout()).numColumns;
256
	_propAppendable = new Button(mutability, SWT.RADIO);
256
		_propConstant.setLayoutData(gd);
257
	_propAppendable.setText(Messages.APPENDABLE);
257
		_propAppendable = new Button(mutability, SWT.RADIO);
258
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
258
		_propAppendable.setText(Messages.APPENDABLE);
259
	gd.horizontalSpan = ((GridLayout) mutability.getLayout()).numColumns;
259
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
260
	_propAppendable.setLayoutData(gd);
260
		gd.horizontalSpan = ((GridLayout) mutability.getLayout()).numColumns;
261
261
		_propAppendable.setLayoutData(gd);
262
	Group cardinality = new Group(rhsComposite, SWT.SHADOW_IN);
262
263
	layout = new GridLayout(1, true);
263
		Group cardinality = new Group(rhsComposite, SWT.SHADOW_IN);
264
	cardinality.setLayout(layout);
264
		layout = new GridLayout(1, true);
265
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
265
		cardinality.setLayout(layout);
266
	gd.grabExcessHorizontalSpace = true;
266
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
267
	cardinality.setLayoutData(gd);
267
		gd.grabExcessHorizontalSpace = true;
268
	cardinality.setText(Messages.CARDINALITY);
268
		cardinality.setLayoutData(gd);
269
	_button1to1 = new Button(cardinality, SWT.RADIO);
269
		cardinality.setText(Messages.CARDINALITY);
270
	_button1to1.setText(Messages.ALWAYS_PRESENT_LABEL);
270
		_button1to1 = new Button(cardinality, SWT.RADIO);
271
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
271
		_button1to1.setText(Messages.ALWAYS_PRESENT_LABEL);
272
	gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
272
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
273
	_button1to1.setLayoutData(gd);
273
		gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
274
	_button0to1 = new Button(cardinality, SWT.RADIO);
274
		_button1to1.setLayoutData(gd);
275
	_button0to1.setText(Messages.OPTIONAL_LABEL);
275
		_button0to1 = new Button(cardinality, SWT.RADIO);
276
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
276
		_button0to1.setText(Messages.OPTIONAL_LABEL);
277
	gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
277
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
278
	_button0to1.setLayoutData(gd);
278
		gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
279
	_button0toN = new Button(cardinality, SWT.RADIO);
279
		_button0to1.setLayoutData(gd);
280
	_button0toN.setText(Messages.ZERO_TO_UNBOUNDED_LABEL);
280
		_button0toN = new Button(cardinality, SWT.RADIO);
281
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
281
		_button0toN.setText(Messages.ZERO_TO_UNBOUNDED_LABEL);
282
	gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
282
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
283
	_button0toN.setLayoutData(gd);
283
		gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
284
	_button1toN = new Button(cardinality, SWT.RADIO);
284
		_button0toN.setLayoutData(gd);
285
	_button1toN.setText(Messages.ONE_TO_UNBOUNDED_LABEL);
285
		_button1toN = new Button(cardinality, SWT.RADIO);
286
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
286
		_button1toN.setText(Messages.ONE_TO_UNBOUNDED_LABEL);
287
	gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
287
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
288
	_button1toN.setLayoutData(gd);
288
		gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
289
	_buttonXtoY = new Button(cardinality, SWT.RADIO);
289
		_button1toN.setLayoutData(gd);
290
	_buttonXtoY.setText(Messages.OTHER_LABEL);
290
		_buttonXtoY = new Button(cardinality, SWT.RADIO);
291
	gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
291
		_buttonXtoY.setText(Messages.OTHER_LABEL);
292
	gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
292
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
293
	_buttonXtoY.setLayoutData(gd);
293
		gd.horizontalSpan = ((GridLayout) cardinality.getLayout()).numColumns;
294
294
		_buttonXtoY.setLayoutData(gd);
295
	Composite otherComposite = new Composite(cardinality, SWT.NONE);
295
296
	layout = new GridLayout(5, false);
296
		Composite otherComposite = new Composite(cardinality, SWT.NONE);
297
	otherComposite.setLayout(layout);
297
		layout = new GridLayout(5, false);
298
298
		otherComposite.setLayout(layout);
299
	Label label = new Label(otherComposite, SWT.NONE);
299
300
	label.setText(Messages.SQUARE_OPEN_BRACKET);
300
		Label label = new Label(otherComposite, SWT.NONE);
301
	gd = new GridData();
301
		label.setText(Messages.SQUARE_OPEN_BRACKET);
302
	gd.horizontalSpan = 1;
302
		gd = new GridData();
303
	gd.horizontalIndent = 15;
303
		gd.horizontalSpan = 1;
304
	label.setLayoutData(gd);
304
		gd.horizontalIndent = 15;
305
305
		label.setLayoutData(gd);
306
	_propMinOccurs = new Text(otherComposite, SWT.SINGLE | SWT.BORDER);
306
307
	_propMinOccurs.setText(Messages.ZERO);
307
		_propMinOccurs = new Text(otherComposite, SWT.SINGLE | SWT.BORDER);
308
	gd = new GridData();
308
		_propMinOccurs.setText(Messages.ZERO);
309
	gd.horizontalSpan = 1; 
309
		gd = new GridData();
310
	gd.widthHint = 40;
310
		gd.horizontalSpan = 1;
311
	gd.grabExcessHorizontalSpace = true;
311
		gd.widthHint = 40;
312
	_propMinOccurs.setLayoutData(gd);
312
		gd.grabExcessHorizontalSpace = true;
313
313
		_propMinOccurs.setLayoutData(gd);
314
	label = new Label(otherComposite, SWT.NONE);
314
315
	label.setText(Messages.DOTS);
315
		label = new Label(otherComposite, SWT.NONE);
316
	gd = new GridData();
316
		label.setText(Messages.DOTS);
317
	gd.horizontalSpan = 1;
317
		gd = new GridData();
318
	label.setLayoutData(gd);
318
		gd.horizontalSpan = 1;
319
319
		label.setLayoutData(gd);
320
	_propMaxOccurs = new Text(otherComposite, SWT.SINGLE | SWT.BORDER);
320
321
	_propMaxOccurs.setText(Messages.ONE);
321
		_propMaxOccurs = new Text(otherComposite, SWT.SINGLE | SWT.BORDER);
322
	gd = new GridData();
322
		_propMaxOccurs.setText(Messages.ONE);
323
	gd.horizontalSpan = 1;
323
		gd = new GridData();
324
	gd.widthHint = 40;
324
		gd.horizontalSpan = 1;
325
	gd.grabExcessHorizontalSpace = true;
325
		gd.widthHint = 40;
326
	_propMaxOccurs.setLayoutData(gd);
326
		gd.grabExcessHorizontalSpace = true;
327
327
		_propMaxOccurs.setLayoutData(gd);
328
	label = new Label(otherComposite, SWT.NONE);
328
329
	label.setText(Messages.SQUARE_END_BRACKET);
329
		label = new Label(otherComposite, SWT.NONE);
330
	gd = new GridData();
330
		label.setText(Messages.SQUARE_END_BRACKET);
331
	gd.horizontalSpan = 1;
331
		gd = new GridData();
332
	label.setLayoutData(gd);
332
		gd.horizontalSpan = 1;
333
    }
333
		label.setLayoutData(gd);
334
334
	}
335
    /**
335
336
     * Creates button bar.
336
	/**
337
     */
337
	 * Creates button bar.
338
    protected Control createButtonBar(Composite parent)
338
	 */
339
    {
339
	protected Control createButtonBar(Composite parent)
340
	Control ret = super.createButtonBar(parent);
340
	{
341
	return ret;
341
		Control ret = super.createButtonBar(parent);
342
    }
342
		return ret;
343
343
	}
344
    private void initializeControls()
344
345
    {
345
	private void initializeControls()
346
	NewNameGenerator nameGenerator = new NewNameGenerator("property");
346
	{
347
	String propName = nameGenerator.getNextName();
347
		NewNameGenerator nameGenerator = new NewNameGenerator("property");
348
	while (propertyAlreadyExists(propName))
348
		String propName = nameGenerator.getNextName();
349
	{
349
		while (propertyAlreadyExists(propName))
350
	    propName = nameGenerator.getNextName();
350
		{
351
	}
351
			propName = nameGenerator.getNextName();
352
352
		}
353
	_propertyName.setText(propName);
353
354
	
354
		_propertyName.setText(propName);
355
	DataTypesCollection instance = DataTypesCollection.getInstance();
355
356
	DataTypeCategory[] categories = instance.getDataTypeCategories(false);	
356
		DataTypesCollection instance = DataTypesCollection.getInstance();
357
	_dataTypeViewer.setInput(Arrays.asList(categories));
357
		DataTypeCategory[] categories = instance.getDataTypeCategories(false);
358
	_dataTypeViewer.refresh();
358
		_dataTypeViewer.setInput(Arrays.asList(categories));
359
	
359
		_dataTypeViewer.refresh();
360
	DataType stringDataType = instance.getDataType("string");
360
361
	_dataTypeViewer.setSelection(new StructuredSelection(stringDataType), true);
361
		DataType stringDataType = instance.getDataType("string");
362
	_writableButton.setSelection(true);
362
		_dataTypeViewer.setSelection(new StructuredSelection(stringDataType),
363
	_propMutable.setSelection(true);
363
				true);
364
	_propAppendable.setEnabled(false);
364
		_writableButton.setSelection(true);
365
	_button1to1.setSelection(true);
365
		_propMutable.setSelection(true);
366
	_propMinOccurs.setEnabled(false);
366
		_propAppendable.setEnabled(false);
367
	_propMaxOccurs.setEnabled(false);
367
		_button1to1.setSelection(true);
368
	_propertyName.setSelection(0, _propertyName.getCharCount());
368
		_propMinOccurs.setEnabled(false);
369
    }
369
		_propMaxOccurs.setEnabled(false);
370
370
		_propertyName.setSelection(0, _propertyName.getCharCount());
371
    /**
371
	}
372
     * Creates new property.
372
373
     */
373
	/**
374
    protected void okPressed()
374
	 * Creates new property.
375
    {
375
	 */
376
	_property.setName(_propertyName.getText());
376
	protected void okPressed()
377
378
	if (!validProperty())
379
	{
380
	    _propertyName.setSelection(0, _propertyName.getCharCount());
381
	    _propertyName.forceFocus();
382
	    return;
383
	}
384
385
	_dataType = (DataType) getSelectedViewerObject();
386
	
387
	XSDSchema propertySchema = _capabilityDomain.getPropertySchema();
388
	if (propertySchema == null)
389
	{
390
	    propertySchema = createNewXSDSchema();
391
	    _capabilityDomain.setPropertySchema(propertySchema);
392
	}
393
394
	_modifiability = buildModifiabilityFromControls();
395
	buildCardinalityFromControls();
396
	_mutability = buildMutabilityFromControls();
397
398
	super.okPressed();
399
    }
400
    
401
    private Object getSelectedViewerObject(){
402
    	StructuredSelection ss = (StructuredSelection) _dataTypeViewer.getSelection();
403
    	Object[] selectedObjects = ss.toArray();
404
    	return selectedObjects[0];
405
    }
406
407
    private XSDSchema createNewXSDSchema()
408
    {
409
	Capability capability = _capabilityDomain.getCapability();
410
	String targetNamespace = capability.getNamespace();
411
	XSDSchema propertySchema = XsdUtils.createNewXSDSchema(targetNamespace);
412
	Definition wsdlDefinition = _capabilityDomain.getDefinition();
413
	String wsdlPath = WsdlUtils.getWSDLFileLocation(wsdlDefinition);
414
	String wsdlContainer = wsdlPath.substring(0, wsdlPath.lastIndexOf("/"));
415
	String capabilityName = capability.getName();
416
	propertySchema.setSchemaLocation(wsdlContainer + "/" + capabilityName
417
		+ ".xsd");
418
419
	return propertySchema;
420
    }
421
422
    private boolean propertyAlreadyExists(String name)
423
    {
424
	Capability model = _capabilityDomain.getCapability();
425
	if (CapUtils.getInstancesOfProperty(model, name) >= 1)
426
	    return true;
427
	return false;
428
    }
429
430
    private boolean validProperty()
431
    {
432
	// Check for duplicate property name
433
	if (propertyAlreadyExists(_property.getName()))
434
	{
435
	    MessageDialog.openError(getShell(), "ERROR",
436
		    Messages.PROP_ALREADY_EXISTS_WARN_);
437
	    return false;
438
	}
439
	// Check for valid java identifier
440
	String msg = CapUtils.validateJavaIdentifier(_property.getName());
441
	if (msg != null)
442
	{
443
	    MessageDialog.openError(getShell(), "ERROR",
444
		    Messages.PROP_NOT_VALID_JAVA_ID_WARN_);
445
	    return false;
446
	}
447
	return true;
448
    }
449
450
    private String buildMutabilityFromControls()
451
    {
452
	if (_propConstant.getSelection())
453
	{
454
	    return "constant";
455
	}
456
	else if (_propAppendable.getSelection())
457
	{
458
	    return "appendable";
459
	}
460
	else if (_propMutable.getSelection())
461
	{
462
	    return "mutable";
463
	}
464
	return "unknown";
465
    }
466
467
    private String buildModifiabilityFromControls()
468
    {
469
	if (_readonlyButton.getSelection())
470
	    return "read-only";
471
	return "read-write";
472
    }
473
474
    private void enableDisableAppendable()
475
    {
476
	_propAppendable.setEnabled(true);
477
	if (_button1to1.getSelection() || _button0to1.getSelection())
478
	{
479
	    _propAppendable.setSelection(false);
480
	    _propAppendable.setEnabled(false);
481
	}
482
483
    }
484
485
    private void enableDisableMinMax()
486
    {
487
	_propMinOccurs.setEnabled(_buttonXtoY.getSelection());
488
	_propMaxOccurs.setEnabled(_buttonXtoY.getSelection());
489
	if (_buttonXtoY.getSelection())
490
	{
491
	    if (_propMinOccurs.getText().trim().equals("")
492
		    || _propMaxOccurs.getText().trim().equals(""))
493
		getButton(IDialogConstants.OK_ID).setEnabled(false);
494
	}
495
	else
496
	    getButton(IDialogConstants.OK_ID).setEnabled(true);
497
	if (_propertyName.getText().trim().equals(""))
498
	    getButton(IDialogConstants.OK_ID).setEnabled(false);
499
    }
500
501
    private void buildCardinalityFromControls()
502
    {
503
	if (_button1to1.getSelection())
504
	{
505
	    _minoccurs = _maxoccurs = 1;
506
	}
507
	else if (_button0to1.getSelection())
508
	{
509
	    _minoccurs = 0;
510
	    _maxoccurs = 1;
511
	}
512
	else if (_button0toN.getSelection())
513
	{
514
	    _minoccurs = 0;
515
	    _maxoccurs = -1;
516
	}
517
	else if (_button1toN.getSelection())
518
	{
519
	    _minoccurs = 1;
520
	    _maxoccurs = -1;
521
	}
522
	else
523
	{
524
	    try
525
	    {
526
		_minoccurs = Integer.parseInt(_propMinOccurs.getText());
527
		_maxoccurs = Integer.parseInt(_propMaxOccurs.getText());
528
	    } catch (NumberFormatException nfe)
529
	    {
530
		_minoccurs = 1;
531
		_maxoccurs = 1;
532
		WsdmToolingLog.logError(Messages.FAILED_TO_PARSE_MIN_MAX_FIELDS_ERROR_ + " ",
533
			nfe);
534
	    }
535
	}
536
    }
537
538
    /**
539
         * 
540
         * @return New property.
541
         */
542
    public XSDElementDeclaration getProperty()
543
    {
544
	return _property;
545
    }
546
547
    private void hookAllListeners()
548
    {
549
	_propertyName.addModifyListener(new ModifyListener()
550
	{
377
	{
378
		_property.setName(_propertyName.getText());
551
379
552
	    public void modifyText(ModifyEvent e)
380
		if (!validProperty())
553
	    {
381
		{
554
		if (_propertyName.getText().trim().equals(""))
382
			_propertyName.setSelection(0, _propertyName.getCharCount());
555
		    getButton(IDialogConstants.OK_ID).setEnabled(false);
383
			_propertyName.forceFocus();
556
		else
384
			return;
385
		}
386
387
		_dataType = (DataType) getSelectedViewerObject();
388
389
		XSDSchema propertySchema = _capabilityDomain.getPropertySchema();
390
		if (propertySchema == null)
391
		{
392
			propertySchema = createNewXSDSchema();
393
			_capabilityDomain.setPropertySchema(propertySchema);
394
		}
395
396
		_modifiability = buildModifiabilityFromControls();
397
		buildCardinalityFromControls();
398
		_mutability = buildMutabilityFromControls();
399
400
		super.okPressed();
401
	}
402
403
	private Object getSelectedViewerObject()
404
	{
405
		StructuredSelection ss = (StructuredSelection) _dataTypeViewer
406
				.getSelection();
407
		Object[] selectedObjects = ss.toArray();
408
		return selectedObjects[0];
409
	}
410
411
	private XSDSchema createNewXSDSchema()
412
	{
413
		Capability capability = _capabilityDomain.getCapability();
414
		String targetNamespace = capability.getNamespace();
415
		XSDSchema propertySchema = XsdUtils.createNewXSDSchema(targetNamespace);
416
		Definition wsdlDefinition = capability.getDefinition();
417
		String wsdlPath = WsdlUtils.getWSDLFileLocation(wsdlDefinition);
418
		String wsdlContainer = wsdlPath.substring(0, wsdlPath.lastIndexOf("/"));
419
		String capabilityName = capability.getName();
420
		propertySchema.setSchemaLocation(wsdlContainer + "/" + capabilityName
421
				+ ".xsd");
422
423
		return propertySchema;
424
	}
425
426
	private boolean propertyAlreadyExists(String name)
427
	{
428
		Capability model = _capabilityDomain.getCapability();
429
		if (CapUtils.getInstancesOfProperty(model, name) >= 1)
430
			return true;
431
		return false;
432
	}
433
434
	private boolean validProperty()
435
	{
436
		// Check for duplicate property name
437
		if (propertyAlreadyExists(_property.getName()))
438
		{
439
			MessageDialog.openError(getShell(), "ERROR",
440
					Messages.PROP_ALREADY_EXISTS_WARN_);
441
			return false;
442
		}
443
		// Check for valid java identifier
444
		String msg = CapUtils.validateJavaIdentifier(_property.getName());
445
		if (msg != null)
446
		{
447
			MessageDialog.openError(getShell(), "ERROR",
448
					Messages.PROP_NOT_VALID_JAVA_ID_WARN_);
449
			return false;
450
		}
451
		return true;
452
	}
453
454
	private String buildMutabilityFromControls()
455
	{
456
		if (_propConstant.getSelection())
457
		{
458
			return "constant";
459
		}
460
		else if (_propAppendable.getSelection())
461
		{
462
			return "appendable";
463
		}
464
		else if (_propMutable.getSelection())
465
		{
466
			return "mutable";
467
		}
468
		return "unknown";
469
	}
470
471
	private String buildModifiabilityFromControls()
472
	{
473
		if (_readonlyButton.getSelection())
474
			return "read-only";
475
		return "read-write";
476
	}
477
478
	private void enableDisableAppendable()
479
	{
480
		_propAppendable.setEnabled(true);
481
		if (_button1to1.getSelection() || _button0to1.getSelection())
482
		{
483
			_propAppendable.setSelection(false);
484
			_propAppendable.setEnabled(false);
485
		}
486
487
	}
488
489
	private void enableDisableMinMax()
490
	{
491
		_propMinOccurs.setEnabled(_buttonXtoY.getSelection());
492
		_propMaxOccurs.setEnabled(_buttonXtoY.getSelection());
493
		if (_buttonXtoY.getSelection())
557
		{
494
		{
558
		    if (_buttonXtoY.getSelection())
559
		    {
560
			if (_propMinOccurs.getText().trim().equals("")
495
			if (_propMinOccurs.getText().trim().equals("")
561
				|| _propMaxOccurs.getText().trim().equals(""))
496
					|| _propMaxOccurs.getText().trim().equals(""))
562
			    getButton(IDialogConstants.OK_ID).setEnabled(false);
497
				getButton(IDialogConstants.OK_ID).setEnabled(false);
563
			else
498
		}
564
			    getButton(IDialogConstants.OK_ID).setEnabled(true);
499
		else
565
		    }
566
		    else
567
			getButton(IDialogConstants.OK_ID).setEnabled(true);
500
			getButton(IDialogConstants.OK_ID).setEnabled(true);
501
		if (_propertyName.getText().trim().equals(""))
502
			getButton(IDialogConstants.OK_ID).setEnabled(false);
503
	}
504
505
	private void buildCardinalityFromControls()
506
	{
507
		if (_button1to1.getSelection())
508
		{
509
			_minoccurs = _maxoccurs = 1;
510
		}
511
		else if (_button0to1.getSelection())
512
		{
513
			_minoccurs = 0;
514
			_maxoccurs = 1;
515
		}
516
		else if (_button0toN.getSelection())
517
		{
518
			_minoccurs = 0;
519
			_maxoccurs = -1;
520
		}
521
		else if (_button1toN.getSelection())
522
		{
523
			_minoccurs = 1;
524
			_maxoccurs = -1;
568
		}
525
		}
526
		else
527
		{
528
			try
529
			{
530
				_minoccurs = Integer.parseInt(_propMinOccurs.getText());
531
				_maxoccurs = Integer.parseInt(_propMaxOccurs.getText());
532
			} catch (NumberFormatException nfe)
533
			{
534
				_minoccurs = 1;
535
				_maxoccurs = 1;
536
				WsdmToolingLog.logError(
537
						Messages.FAILED_TO_PARSE_MIN_MAX_FIELDS_ERROR_ + " ",
538
						nfe);
539
			}
540
		}
541
	}
542
543
	/**
544
	 * 
545
	 * @return New property.
546
	 */
547
	public XSDElementDeclaration getProperty()
548
	{
549
		return _property;
550
	}
551
552
	private void hookAllListeners()
553
	{
554
		_propertyName.addModifyListener(new ModifyListener() {
555
556
			public void modifyText(ModifyEvent e)
557
			{
558
				if (_propertyName.getText().trim().equals(""))
559
					getButton(IDialogConstants.OK_ID).setEnabled(false);
560
				else
561
				{
562
					if (_buttonXtoY.getSelection())
563
					{
564
						if (_propMinOccurs.getText().trim().equals("")
565
								|| _propMaxOccurs.getText().trim().equals(""))
566
							getButton(IDialogConstants.OK_ID).setEnabled(false);
567
						else
568
							getButton(IDialogConstants.OK_ID).setEnabled(true);
569
					}
570
					else
571
						getButton(IDialogConstants.OK_ID).setEnabled(true);
572
				}
573
574
			}
575
		});
576
577
		_dataTypeViewer
578
				.addSelectionChangedListener(new ISelectionChangedListener() {
579
					public void selectionChanged(SelectionChangedEvent event)
580
					{
581
						getButton(IDialogConstants.OK_ID).setEnabled(true);
582
						Object selectedObject = getSelectedViewerObject();
583
						if (!(selectedObject instanceof DataType))
584
							getButton(IDialogConstants.OK_ID).setEnabled(false);
585
					}
586
				});
587
588
		_propMinOccurs.addModifyListener(new ModifyListener() {
589
590
			public void modifyText(ModifyEvent e)
591
			{
592
				if (_propMinOccurs.getText().trim().equals("")
593
						|| _propMaxOccurs.getText().trim().equals(""))
594
					getButton(IDialogConstants.OK_ID).setEnabled(false);
595
				else if (!_propertyName.getText().trim().equals(""))
596
					getButton(IDialogConstants.OK_ID).setEnabled(true);
597
			}
598
		});
599
		_propMaxOccurs.addModifyListener(new ModifyListener() {
600
601
			public void modifyText(ModifyEvent e)
602
			{
603
				if (_propMinOccurs.getText().trim().equals("")
604
						|| _propMaxOccurs.getText().trim().equals(""))
605
					getButton(IDialogConstants.OK_ID).setEnabled(false);
606
				else if (!_propertyName.getText().trim().equals(""))
607
					getButton(IDialogConstants.OK_ID).setEnabled(true);
608
			}
609
		});
610
		_minMaxListener = new Listener() {
611
			public void handleEvent(Event event)
612
			{
613
				enableDisableAppendable();
614
				enableDisableMinMax();
615
			}
616
		};
617
618
		_button1to1.addListener(SWT.Selection, _minMaxListener);
619
		_button0to1.addListener(SWT.Selection, _minMaxListener);
620
		_button0toN.addListener(SWT.Selection, _minMaxListener);
621
		_button1toN.addListener(SWT.Selection, _minMaxListener);
622
		_buttonXtoY.addListener(SWT.Selection, _minMaxListener);
623
624
		_importButton.addSelectionListener(new SelectionAdapter() {
625
			public void widgetSelected(SelectionEvent e)
626
			{
627
				importComplexTypes();
628
			}
629
		});
630
	}
631
632
	private void importComplexTypes()
633
	{
634
		ImportComplexTypeAction action = new ImportComplexTypeAction(getShell());
635
		action.run();
636
637
		_dataTypeViewer.refresh();
638
639
		DataTypesCollection instance = DataTypesCollection.getInstance();
640
		DataType stringDataType = instance.getDataType("string");
641
		_dataTypeViewer.setSelection(new StructuredSelection(stringDataType),
642
				true);
643
	}
644
645
	/**
646
	 * 
647
	 * @return MinOcuurs of new property.
648
	 */
649
	public int getMinOcuurs()
650
	{
651
		return _minoccurs;
652
	}
653
654
	/**
655
	 * 
656
	 * @return MaxOccurs of new property.
657
	 */
658
	public int getMaxOccurs()
659
	{
660
		return _maxoccurs;
661
	}
662
663
	/**
664
	 * 
665
	 * @return Modifiability of new property.
666
	 */
667
	public String getModifiability()
668
	{
669
		return _modifiability;
670
	}
671
672
	/**
673
	 * 
674
	 * @return Mutability of new property.
675
	 */
676
	public String getMutability()
677
	{
678
		return _mutability;
679
	}
680
681
	/**
682
	 * Return the data type selected for new property
683
	 * 
684
	 */
685
	public DataType getDataType()
686
	{
687
		return _dataType;
688
	}
569
689
570
	    }
571
	});
572
	
573
	_dataTypeViewer.addSelectionChangedListener(new ISelectionChangedListener(){
574
		public void selectionChanged(SelectionChangedEvent event) {
575
			getButton(IDialogConstants.OK_ID).setEnabled(true);
576
			Object selectedObject = getSelectedViewerObject();			
577
			if(!(selectedObject instanceof DataType))
578
				getButton(IDialogConstants.OK_ID).setEnabled(false);
579
		}});
580
	
581
	_propMinOccurs.addModifyListener(new ModifyListener()
582
	{
583
584
	    public void modifyText(ModifyEvent e)
585
	    {
586
		if (_propMinOccurs.getText().trim().equals("")
587
			|| _propMaxOccurs.getText().trim().equals(""))
588
		    getButton(IDialogConstants.OK_ID).setEnabled(false);
589
		else if (!_propertyName.getText().trim().equals(""))
590
		    getButton(IDialogConstants.OK_ID).setEnabled(true);
591
	    }
592
	});
593
	_propMaxOccurs.addModifyListener(new ModifyListener()
594
	{
595
596
	    public void modifyText(ModifyEvent e)
597
	    {
598
		if (_propMinOccurs.getText().trim().equals("")
599
			|| _propMaxOccurs.getText().trim().equals(""))
600
		    getButton(IDialogConstants.OK_ID).setEnabled(false);
601
		else if (!_propertyName.getText().trim().equals(""))
602
		    getButton(IDialogConstants.OK_ID).setEnabled(true);
603
	    }
604
	});
605
	_minMaxListener = new Listener()
606
	{
607
	    public void handleEvent(Event event)
608
	    {
609
		enableDisableAppendable();
610
		enableDisableMinMax();
611
	    }
612
	};
613
614
	_button1to1.addListener(SWT.Selection, _minMaxListener);
615
	_button0to1.addListener(SWT.Selection, _minMaxListener);
616
	_button0toN.addListener(SWT.Selection, _minMaxListener);
617
	_button1toN.addListener(SWT.Selection, _minMaxListener);
618
	_buttonXtoY.addListener(SWT.Selection, _minMaxListener);
619
620
	_importButton.addSelectionListener(new SelectionAdapter()
621
	{
622
	    public void widgetSelected(SelectionEvent e)
623
	    {
624
		importComplexTypes();
625
	    }
626
	});
627
    }
628
    
629
    private void importComplexTypes()
630
    {	
631
	ImportComplexTypeAction action = new ImportComplexTypeAction(getShell());
632
	action.run();
633
	
634
	_dataTypeViewer.refresh();
635
	
636
	DataTypesCollection instance = DataTypesCollection.getInstance();	
637
	DataType stringDataType = instance.getDataType("string");
638
	_dataTypeViewer.setSelection(new StructuredSelection(stringDataType), true);	
639
    }
640
641
    /**
642
         * 
643
         * @return MinOcuurs of new property.
644
         */
645
    public int getMinOcuurs()
646
    {
647
	return _minoccurs;
648
    }
649
650
    /**
651
         * 
652
         * @return MaxOccurs of new property.
653
         */
654
    public int getMaxOccurs()
655
    {
656
	return _maxoccurs;
657
    }
658
659
    /**
660
         * 
661
         * @return Modifiability of new property.
662
         */
663
    public String getModifiability()
664
    {
665
	return _modifiability;
666
    }
667
668
    /**
669
         * 
670
         * @return Mutability of new property.
671
         */
672
    public String getMutability()
673
    {
674
	return _mutability;
675
    }
676
    
677
    /**
678
     * Return the data type selected for new property
679
     * 
680
     */
681
     public DataType getDataType()
682
     {
683
	 return _dataType;
684
     }
685
     
686
} // end class NewPropertyDialog
690
} // end class NewPropertyDialog
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/property/internal/ListSection.java (-312 / +332 lines)
Lines 65-393 Link Here
65
public class ListSection extends AbstractPageSection implements IViewerClient
65
public class ListSection extends AbstractPageSection implements IViewerClient
66
{
66
{
67
67
68
    private StructuredTreeViewer _properties;
68
	private StructuredTreeViewer _properties;
69
69
70
    private ResourcePropertiesContentProvider _provider;
70
	private ResourcePropertiesContentProvider _provider;
71
71
72
    private Button _addPropertyButton;
72
	private Button _addPropertyButton;
73
73
74
    private Button _editMetadataButton;
74
	private Button _editMetadataButton;
75
75
76
    private Button _removePropertyButton;
76
	private Button _removePropertyButton;
77
78
    private Label _errorLabel;
79
80
    private Object _selectedObject;
81
    
82
    private Composite _sectionClient;
83
    
84
    private Composite _buttonClient;
85
86
    /**
87
     * Creates the new object of this class. 
88
     */
89
    ListSection(CapabilityEditor editor, IUIPage propertyPage,
90
	    ScrolledForm form, FormToolkit toolkit)
91
    {
92
	super(editor, propertyPage, form, toolkit);
93
    }
94
95
    /**
96
     * Creates the section.
97
     */
98
    public void create()
99
    {
100
    _sectionClient = createSection(Messages.PROPERTIES,
101
		Messages.PROPS_USED, 1, 4);
102
	GridLayout layout = new GridLayout(2, false);
103
	layout.marginWidth = LAYOUT_MARGIN_WIDTH;
104
	layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
105
	_sectionClient.setLayout(layout);
106
	FormToolkit toolkit = getToolkit();
107
108
	_properties = new StructuredTreeViewer(_sectionClient, toolkit,
109
		SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, this);
110
111
	GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
112
	gd.heightHint = 50;
113
	gd.widthHint = 50;
114
	_properties.getControl().setLayoutData(gd);
115
	_properties.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
116
		FormToolkit.TREE_BORDER);	
117
118
	// Set up a label provider that knows about the capability (so can
119
	// extract SemanticDecorations from it)
120
	_provider = new ResourcePropertiesContentProvider();
121
	_properties.setContentProvider(_provider);
122
	_properties.setLabelProvider(new ResourcePropertiesLabelProvider(
123
		getForm().getShell()));
124
	_properties.getControl().setSize(_properties.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT));
125
126
	_buttonClient = toolkit.createComposite(_sectionClient);
127
	layout = new GridLayout();
128
	layout.marginHeight = 0;
129
	_buttonClient.setLayout(layout);
130
	gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_FILL, false, false);
131
	_buttonClient.setLayoutData(gd);
132
77
133
	_addPropertyButton = createPushButton(_buttonClient, toolkit, org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.ADD_BUTTON_LABEL,
78
	private Label _errorLabel;
134
		new Listener()
79
80
	private Object _selectedObject;
81
82
	private Composite _sectionClient;
83
84
	private Composite _buttonClient;
85
86
	/**
87
	 * Creates the new object of this class.
88
	 */
89
	ListSection(CapabilityEditor editor, IUIPage propertyPage,
90
			ScrolledForm form, FormToolkit toolkit)
91
	{
92
		super(editor, propertyPage, form, toolkit);
93
	}
94
95
	/**
96
	 * Creates the section.
97
	 */
98
	public void create()
99
	{
100
		_sectionClient = createSection(Messages.PROPERTIES,
101
				Messages.PROPS_USED, 1, 4);
102
		GridLayout layout = new GridLayout(2, false);
103
		layout.marginWidth = LAYOUT_MARGIN_WIDTH;
104
		layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
105
		_sectionClient.setLayout(layout);
106
		FormToolkit toolkit = getToolkit();
107
108
		_properties = new StructuredTreeViewer(_sectionClient, toolkit,
109
				SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, this);
110
111
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
112
		gd.heightHint = 50;
113
		gd.widthHint = 50;
114
		_properties.getControl().setLayoutData(gd);
115
		_properties.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
116
				FormToolkit.TREE_BORDER);
117
118
		// Set up a label provider that knows about the capability (so can
119
		// extract SemanticDecorations from it)
120
		_provider = new ResourcePropertiesContentProvider();
121
		_properties.setContentProvider(_provider);
122
		_properties.setLabelProvider(new ResourcePropertiesLabelProvider(
123
				getForm().getShell()));
124
		_properties.getControl().setSize(
125
				_properties.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT));
126
127
		_buttonClient = toolkit.createComposite(_sectionClient);
128
		layout = new GridLayout();
129
		layout.marginHeight = 0;
130
		_buttonClient.setLayout(layout);
131
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING,
132
				GridData.VERTICAL_ALIGN_FILL, false, false);
133
		_buttonClient.setLayoutData(gd);
134
135
		_addPropertyButton = createPushButton(
136
				_buttonClient,
137
				toolkit,
138
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.ADD_BUTTON_LABEL,
139
				new Listener() {
140
					public void handleEvent(Event event)
141
					{
142
						addProperty();
143
					}
144
				});
145
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
146
		gd.widthHint = 80;
147
		_addPropertyButton.setLayoutData(gd);
148
		_addPropertyButton.setEnabled(!_editor.isReadOnly());
149
150
		_editMetadataButton = createPushButton(_buttonClient, toolkit,
151
				Messages.EDIT_METADATA_LABEL, new Listener() {
152
					public void handleEvent(Event event)
153
					{
154
						editMetadata();
155
					}
156
				});
157
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
158
		gd.widthHint = 80;
159
		_editMetadataButton.setLayoutData(gd);
160
		_editMetadataButton.setEnabled(false);
161
162
		_removePropertyButton = createPushButton(
163
				_buttonClient,
164
				toolkit,
165
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL,
166
				new Listener() {
167
					public void handleEvent(Event event)
168
					{
169
						removeProperty();
170
					}
171
				});
172
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
173
		gd.widthHint = 80;
174
		_removePropertyButton.setLayoutData(gd);
175
		_removePropertyButton.setEnabled(false);
176
177
		_errorLabel = toolkit.createLabel(_sectionClient, "", SWT.WRAP);
178
		gd = new GridData();
179
		gd.horizontalSpan = 2;
180
		gd.grabExcessHorizontalSpace = true;
181
		gd.horizontalAlignment = SWT.FILL;
182
		_errorLabel.setLayoutData(gd);
183
	}
184
185
	private void addProperty()
186
	{
187
		CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
188
		NewPropertyDialog dlg = new NewPropertyDialog(getForm().getShell(),
189
				Messages.ADD_PROPERTY, capabilityDomain);
190
		int choice = dlg.open();
191
		if (choice == Window.OK)
135
		{
192
		{
136
		    public void handleEvent(Event event)
193
			XSDElementDeclaration propertyElement = dlg.getProperty();
137
		    {
194
			AddPropertyCommand command_1 = new AddPropertyCommand(
138
			addProperty();
195
					capabilityDomain, propertyElement);
139
		    }
196
			command_1.execute();
140
		});
197
			Property property = command_1.getProperty();
141
	gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
198
142
	gd.widthHint = 80;
199
			DataType dataType = dlg.getDataType();
143
	_addPropertyButton.setLayoutData(gd);
200
			ChangePropertyTypeCommand command_2 = new ChangePropertyTypeCommand(
144
	_addPropertyButton.setEnabled(!_editor.isReadOnly());
201
					capabilityDomain, property, dataType);
202
			command_2.execute();
203
204
			int minoccurs = dlg.getMinOcuurs();
205
			int maxoccurs = dlg.getMaxOccurs();
206
			ChangePropertyCardinalityCommand command_3 = new ChangePropertyCardinalityCommand(
207
					capabilityDomain, property, minoccurs, maxoccurs);
208
			command_3.execute();
209
210
			ChangeModifiabilityCommand command_4 = new ChangeModifiabilityCommand(
211
					capabilityDomain, property, dlg.getModifiability());
212
			command_4.execute();
213
214
			ChangeMutabilityCommand command_5 = new ChangeMutabilityCommand(
215
					capabilityDomain, property, dlg.getMutability());
216
			command_5.execute();
217
218
			_selectedObject = property;
219
			_page.setDirty();
220
		}
221
	}
145
222
146
	_editMetadataButton = createPushButton(_buttonClient, toolkit,
223
	private void editMetadata()
147
		Messages.EDIT_METADATA_LABEL, new Listener()
224
	{
225
		CapabilityDomain capabilityDomain = (CapabilityDomain) _editor
226
				.getCapabilityDomain();
227
		Property property = (Property) _selectedObject;
228
		MetadataPropertyDialog dlg = new MetadataPropertyDialog(getForm()
229
				.getShell(), capabilityDomain, property);
230
		int choice = dlg.open();
231
		if (choice == Window.OK)
148
		{
232
		{
149
		    public void handleEvent(Event event)
233
			_page.setDirty();
150
		    {
234
		}
151
			editMetadata();
235
	}
152
		    }
153
		});
154
	gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
155
	gd.widthHint = 80;
156
	_editMetadataButton.setLayoutData(gd);
157
	_editMetadataButton.setEnabled(false);
158
236
159
	_removePropertyButton = createPushButton(_buttonClient, toolkit,
237
	private void removeProperty()
160
		org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL, new Listener()
238
	{
239
		Property property = (Property) _selectedObject;
240
		CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
241
		RemovePropertyCommand command = new RemovePropertyCommand(
242
				capabilityDomain, property);
243
		command.execute();
244
		_selectedObject = null;
245
		_page.setDirty();
246
	}
247
248
	/**
249
	 * Handle double click.
250
	 */
251
	public void handleDoubleClick()
252
	{
253
	}
254
255
	/**
256
	 * Handle selection changed.
257
	 */
258
	public void handleSelectionChanged(SelectionChangedEvent event)
259
	{
260
		Object[] objects = _properties.getSelectedObjets();
261
		_removePropertyButton.setEnabled(objects.length > 0
262
				&& !_editor.isReadOnly());
263
		_editMetadataButton.setEnabled(objects.length > 0
264
				&& !_editor.isReadOnly());
265
		if (objects.length > 0)
161
		{
266
		{
162
		    public void handleEvent(Event event)
267
			_selectedObject = objects[0];
163
		    {
268
			_editMetadataButton.setEnabled(_selectedObject instanceof Property
164
			removeProperty();
269
					&& !_editor.isReadOnly());
165
		    }
270
			_removePropertyButton
166
		});
271
					.setEnabled(_selectedObject instanceof Property
167
	gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
272
							&& !_editor.isReadOnly());
168
	gd.widthHint = 80;
273
			List sections = _page.getSections();
169
	_removePropertyButton.setLayoutData(gd);
274
			for (int i = 0; i < sections.size(); i++)
170
	_removePropertyButton.setEnabled(false);
275
			{
171
276
				IPageSection section = (IPageSection) sections.get(i);
172
	_errorLabel = toolkit.createLabel(_sectionClient, "", SWT.WRAP );
277
				section.setSelectedObject(_selectedObject);
173
	gd = new GridData();
278
				section.selectionChanged(event);
174
	gd.horizontalSpan = 2;
279
			}
175
	gd.grabExcessHorizontalSpace = true;
280
		}
176
	gd.horizontalAlignment = SWT.FILL;
281
	}
177
	_errorLabel.setLayoutData(gd);
282
178
    }
283
	/**
179
284
	 * Refreshes the section.
180
    private void addProperty()
285
	 */
181
    {
286
	public void refresh()
182
	CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
287
	{
183
	NewPropertyDialog dlg = new NewPropertyDialog(getForm().getShell(),
288
		List propertiesList = _editor.getCapabilityDomain().getCapability()
184
		Messages.ADD_PROPERTY, capabilityDomain);
289
				.getProperties();
185
	int choice = dlg.open();
290
		_properties.setInput(propertiesList);
186
	if (choice == Window.OK)
291
		if (propertiesList.size() != 0 && _selectedObject != null)
187
	{
292
		{
188
	    XSDElementDeclaration propertyElement = dlg.getProperty();
293
			_page.enableSections(true);
189
	    AddPropertyCommand command_1 = new AddPropertyCommand(
294
			setFocusToProperty(_selectedObject);
190
		    capabilityDomain, propertyElement);
295
		}
191
	    command_1.execute();
192
	    Property property = command_1.getProperty();
193
	    
194
	    DataType dataType = dlg.getDataType();
195
	    ChangePropertyTypeCommand command_2 = new ChangePropertyTypeCommand(capabilityDomain, property, dataType);
196
	    command_2.execute();
197
198
	    int minoccurs = dlg.getMinOcuurs();
199
	    int maxoccurs = dlg.getMaxOccurs();
200
	    ChangePropertyCardinalityCommand command_3 = new ChangePropertyCardinalityCommand(
201
		    capabilityDomain, property, minoccurs, maxoccurs);
202
	    command_3.execute();
203
204
	    ChangeModifiabilityCommand command_4 = new ChangeModifiabilityCommand(
205
		    capabilityDomain, property, dlg.getModifiability());
206
	    command_4.execute();
207
208
	    ChangeMutabilityCommand command_5 = new ChangeMutabilityCommand(
209
		    capabilityDomain, property, dlg.getMutability());
210
	    command_5.execute();
211
212
	    _selectedObject = property;
213
	    _page.setDirty();
214
	}
215
    }
216
217
    private void editMetadata()
218
    {
219
	CapabilityDomain capabilityDomain = (CapabilityDomain) _editor
220
		.getCapabilityDomain();
221
	Property property = (Property) _selectedObject;
222
	MetadataPropertyDialog dlg = new MetadataPropertyDialog(getForm()
223
		.getShell(), capabilityDomain, property);
224
	int choice = dlg.open();
225
	if (choice == Window.OK)
226
	{
227
	    _page.setDirty();
228
	}
229
    }
230
231
    private void removeProperty()
232
    {
233
	Property property = (Property) _selectedObject;
234
	CapabilityDomain capabilityDomain = _editor.getCapabilityDomain();
235
	RemovePropertyCommand command = new RemovePropertyCommand(
236
		capabilityDomain, property);
237
	command.execute();
238
	_selectedObject = null;
239
	_page.setDirty();
240
    }
241
242
    /**
243
     * Handle double click.
244
     */
245
    public void handleDoubleClick()
246
    {
247
    }
248
249
    /**
250
     * Handle selection changed.
251
     */
252
    public void handleSelectionChanged(SelectionChangedEvent event)
253
    {
254
	Object[] objects = _properties.getSelectedObjets();
255
	_removePropertyButton.setEnabled(objects.length > 0 && !_editor.isReadOnly());
256
	_editMetadataButton.setEnabled(objects.length > 0 && !_editor.isReadOnly());
257
	if (objects.length > 0)
258
	{
259
	    _selectedObject = objects[0];
260
	    _editMetadataButton.setEnabled(_selectedObject instanceof Property && !_editor.isReadOnly());
261
	    _removePropertyButton.setEnabled(_selectedObject instanceof Property && !_editor.isReadOnly());
262
	    List sections = _page.getSections();
263
	    for (int i = 0; i < sections.size(); i++)
264
	    {
265
		IPageSection section = (IPageSection) sections.get(i);
266
		section.setSelectedObject(_selectedObject);
267
		section.selectionChanged(event);
268
	    }
269
	}
270
    }
271
272
    /**
273
     * Refreshes the section.
274
     */
275
    public void refresh()
276
    {
277
	List propertiesList = _editor.getCapabilityDomain().getCapability()
278
		.getProperties();
279
	_properties.setInput(propertiesList);
280
	if (propertiesList.size() != 0 && _selectedObject != null)
281
	{
282
	    _page.enableSections(true);
283
	    setFocusToProperty(_selectedObject);
284
	}
285
	else
286
	{
287
	    _page.enableSections(false);
288
	}
289
	updateErrorMessage();
290
    }
291
    
292
    private void updateErrorMessage()
293
    {
294
	Definition defintion = _editor.getCapabilityDomain().getDefinition();
295
	XSDSchema propSchema = _editor.getCapabilityDomain().getPropertySchema();
296
	if(propSchema == null)
297
	    return;
298
	if(_editor.getCapabilityDomain().getMetaDataDescriptor() == null)
299
	    return;
300
	DocumentRoot root = _editor.getCapabilityDomain().getMetaDataDescriptor().getDocumentRoot();
301
	
302
	CapabilityXSDValidator xsdValidator = new CapabilityXSDValidator();
303
	IValidationReport xsdReport = xsdValidator.validate(defintion,propSchema);	
304
	boolean xsdHasProblem = xsdReport.hasErrors() || xsdReport.hasWarnings();
305
	
306
	CapabilityRMDValidator rmdValidator = new CapabilityRMDValidator();
307
	IValidationReport rmdReport = rmdValidator.validate(defintion,root);
308
	boolean rmdHasProblem = rmdReport.hasErrors() || rmdReport.hasWarnings();
309
	
310
	boolean hasProblem = xsdHasProblem || rmdHasProblem;
311
	
312
	if (hasProblem)
313
	{
314
	    // We have a problem, is it an error or just a warning?
315
	    boolean hasError = false;
316
	    String msg;
317
	    if (xsdReport.hasErrors() || rmdReport.hasErrors())
318
	    {
319
		hasError = true;
320
		if(xsdReport.hasErrors())
321
		    msg = xsdReport.getErrorMessages()[0].getMessage();
322
		else
296
		else
323
		    msg = rmdReport.getErrorMessages()[0].getMessage();
297
		{
324
	    }
298
			_page.enableSections(false);
325
	    else
299
		}
326
	    {		
300
		updateErrorMessage();
327
		if(xsdReport.hasWarnings())
301
	}
328
		    msg = xsdReport.getWarningMessages()[0].getMessage();
302
303
	private void updateErrorMessage()
304
	{
305
		Definition defintion = _editor.getCapabilityDomain().getCapability()
306
				.getDefinition();
307
		XSDSchema propSchema = _editor.getCapabilityDomain()
308
				.getPropertySchema();
309
		if (propSchema == null)
310
			return;
311
		if (_editor.getCapabilityDomain().getCapability().getMetadata() == null)
312
			return;
313
		DocumentRoot root = _editor.getCapabilityDomain().getCapability()
314
				.getMetadata().getDocumentRoot();
315
316
		CapabilityXSDValidator xsdValidator = new CapabilityXSDValidator();
317
		IValidationReport xsdReport = xsdValidator.validate(defintion,
318
				propSchema);
319
		boolean xsdHasProblem = xsdReport.hasErrors()
320
				|| xsdReport.hasWarnings();
321
322
		CapabilityRMDValidator rmdValidator = new CapabilityRMDValidator();
323
		IValidationReport rmdReport = rmdValidator.validate(defintion, root);
324
		boolean rmdHasProblem = rmdReport.hasErrors()
325
				|| rmdReport.hasWarnings();
326
327
		boolean hasProblem = xsdHasProblem || rmdHasProblem;
328
329
		if (hasProblem)
330
		{
331
			// We have a problem, is it an error or just a warning?
332
			boolean hasError = false;
333
			String msg;
334
			if (xsdReport.hasErrors() || rmdReport.hasErrors())
335
			{
336
				hasError = true;
337
				if (xsdReport.hasErrors())
338
					msg = xsdReport.getErrorMessages()[0].getMessage();
339
				else
340
					msg = rmdReport.getErrorMessages()[0].getMessage();
341
			}
342
			else
343
			{
344
				if (xsdReport.hasWarnings())
345
					msg = xsdReport.getWarningMessages()[0].getMessage();
346
				else
347
					msg = rmdReport.getWarningMessages()[0].getMessage();
348
			}
349
			_errorLabel.setBackground(getForm().getDisplay().getSystemColor(
350
					hasError ? SWT.COLOR_RED : SWT.COLOR_YELLOW));
351
			_errorLabel.setForeground(getForm().getDisplay().getSystemColor(
352
					hasError ? SWT.COLOR_WHITE : SWT.COLOR_BLACK));
353
			_errorLabel.setText(" " + msg + " ");
354
		}
329
		else
355
		else
330
		    msg = rmdReport.getWarningMessages()[0].getMessage();
356
		{
331
	    }
357
			_errorLabel.setBackground(getForm().getBackground());
332
	    _errorLabel.setBackground(getForm().getDisplay().getSystemColor(
358
			_errorLabel.setForeground(getForm().getForeground());
333
		    hasError ? SWT.COLOR_RED : SWT.COLOR_YELLOW));
359
			_errorLabel.setText("");
334
	    _errorLabel.setForeground(getForm().getDisplay().getSystemColor(
360
		}
335
		    hasError ? SWT.COLOR_WHITE : SWT.COLOR_BLACK));
361
	}
336
	    _errorLabel.setText(" " + msg + " ");
362
337
	}
363
	/**
338
	else
364
	 * Update its selected object.
339
	{
365
	 */
340
	    _errorLabel.setBackground(getForm().getBackground());
366
	public void setSelectedObject(Object object)
341
	    _errorLabel.setForeground(getForm().getForeground());
367
	{
342
	    _errorLabel.setText("");
368
		_selectedObject = object;
343
	}	
369
	}
344
    }
370
345
371
	/**
346
    /**
372
	 * Handle viewer selection changed.
347
     * Update its selected object.
373
	 */
348
     */
374
	public void selectionChanged(SelectionChangedEvent event)
349
    public void setSelectedObject(Object object)
375
	{
350
    {
376
	}
351
	_selectedObject = object;
377
352
    }
378
	/**
353
379
	 * Initializes control listeners.
354
    /**
380
	 */
355
     * Handle viewer selection changed.
381
	public void hookAllListeners()
356
     */
382
	{
357
    public void selectionChanged(SelectionChangedEvent event)
383
		getForm().addControlListener(new ControlAdapter() {
358
    {
384
			public void controlResized(ControlEvent e)
359
    }
385
			{
360
386
				Rectangle formBounds = getForm().getClientArea();
361
    /**
387
				Rectangle sectionClientBounds = _sectionClient.getClientArea();
362
     * Initializes control listeners.
388
				Rectangle buttonCompositeBounds = _buttonClient.getClientArea();
363
     */
389
				int width = sectionClientBounds.width
364
    public void hookAllListeners()
390
						- buttonCompositeBounds.width - 20;
365
    {
391
				int height = Math.min(formBounds.height,
366
    	getForm().addControlListener(new ControlAdapter() {
392
						sectionClientBounds.height) - 100;
367
    	    public void controlResized(ControlEvent e) {
393
				Tree tree = (Tree) _properties.getControl();
368
    	    	Rectangle formBounds = getForm().getClientArea();
394
				tree.setSize(width, height);
369
    	        Rectangle sectionClientBounds = _sectionClient.getClientArea();
395
			}
370
    	        Rectangle buttonCompositeBounds = _buttonClient.getClientArea();
396
		});
371
    	        int width = sectionClientBounds.width-buttonCompositeBounds.width-20;
397
	}
372
    	        int height = Math.min(formBounds.height, sectionClientBounds.height)-100;
398
373
    	        Tree tree = (Tree) _properties.getControl();
399
	/**
374
    	        tree.setSize(width,height);    	        
400
	 * Enable or disable the section based on parameter passed.
375
    	    }
401
	 */
376
    	});
402
	public void enable(boolean enabled)
377
    }
403
	{
378
404
		// TODO Auto-generated method stub
379
    /**
405
	}
380
     * Enable or disable the section based on parameter passed.
406
381
     */
407
	private void setFocusToProperty(Object property)
382
    public void enable(boolean enabled)
408
	{
383
    {
409
		_selectedObject = property;
384
	// TODO Auto-generated method stub
410
		_properties.setSelection(new StructuredSelection(property), false);
385
    }
411
	}
386
387
    private void setFocusToProperty(Object property)
388
    {
389
	_selectedObject = property;
390
	_properties.setSelection(new StructuredSelection(property), false);
391
    }
392
412
393
}
413
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/property/internal/MetadataPropertyDialog.java (-681 / +686 lines)
Lines 23-29 Link Here
23
import org.eclipse.emf.ecore.util.FeatureMapUtil;
23
import org.eclipse.emf.ecore.util.FeatureMapUtil;
24
import org.eclipse.emf.ecore.xml.type.AnyType;
24
import org.eclipse.emf.ecore.xml.type.AnyType;
25
import org.eclipse.emf.ecore.xml.type.XMLTypeFactory;
25
import org.eclipse.emf.ecore.xml.type.XMLTypeFactory;
26
import org.eclipse.emf.ecore.xml.type.internal.QName;
27
import org.eclipse.jface.dialogs.Dialog;
26
import org.eclipse.jface.dialogs.Dialog;
28
import org.eclipse.jface.dialogs.IDialogConstants;
27
import org.eclipse.jface.dialogs.IDialogConstants;
29
import org.eclipse.jface.dialogs.IInputValidator;
28
import org.eclipse.jface.dialogs.IInputValidator;
Lines 46-51 Link Here
46
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
45
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
47
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
46
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils;
48
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
47
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
48
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
49
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorFactory;
49
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorFactory;
50
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
50
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
51
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.StaticValuesType;
51
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.StaticValuesType;
Lines 53-792 Link Here
53
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.ValidValuesType;
53
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.ValidValuesType;
54
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl;
54
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl;
55
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.property.internal.Messages;
55
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.property.internal.Messages;
56
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
57
import org.eclipse.tptp.wsdm.tooling.util.internal.Validation;
56
import org.eclipse.tptp.wsdm.tooling.util.internal.Validation;
58
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
57
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
59
58
60
/**
59
/**
61
 * 
60
 * 
62
 * Popup dialog to define metadata ( such as enumarated values, default values, ranged values )
61
 * Popup dialog to define metadata ( such as enumarated values, default values,
63
 * for a property.
62
 * ranged values ) for a property.
64
 *
63
 * 
65
 */
64
 */
66
65
67
public class MetadataPropertyDialog extends Dialog
66
public class MetadataPropertyDialog extends Dialog
68
{
67
{
69
68
70
    private List _listDefault;
69
	private List _listDefault;
71
72
    private Group _extraSchema;
73
70
74
    private Button _propUnlimited;
71
	private Group _extraSchema;
75
72
76
    private Button _propValidValues;
73
	private Button _propUnlimited;
77
74
78
    private List _listValidEnum;
75
	private Button _propValidValues;
79
76
80
    private Button _propValidRange;
77
	private List _listValidEnum;
78
79
	private Button _propValidRange;
80
81
	private Label _labelMin;
82
83
	private Label _labelMax;
84
85
	private Text _fieldMin;
86
87
	private Text _fieldMax;
88
89
	private Button _buttonAddEnum;
90
91
	private Button _buttonEditEnum;
92
93
	private Button _buttonDelEnum;
94
95
	private Button _buttonAddDefault;
96
97
	private Button _buttonDelDefault;
98
99
	private Button _buttonEditDefault;
100
101
	private Property _property;
102
103
	private MetadataDescriptorFactory _rmdFactory = new MetadataDescriptorFactoryImpl();
104
105
	private ExtendedMetaData _extendedMetaData;
106
107
	private CapabilityDomain _capabilityDomain;
108
109
	/**
110
	 * Creates a dialog for providing intial values and static vlaues for
111
	 * property.<br>
112
	 * 
113
	 * @param parentShell
114
	 *            Shell.
115
	 * 
116
	 * @param capabilityDomain
117
	 *            Capability domain of capability editor.
118
	 * 
119
	 * @param property
120
	 *            Property selected for metadata editing.
121
	 */
122
	protected MetadataPropertyDialog(Shell parentShell,
123
			CapabilityDomain capabilityDomain, Property property)
124
	{
125
		super(parentShell);
126
		_property = property;
127
		_extendedMetaData = createExtendedMetaData();
128
		_capabilityDomain = capabilityDomain;
129
	}
130
131
	private ExtendedMetaData createExtendedMetaData()
132
	{
133
		ResourceSet resourceSet = new ResourceSetImpl();
134
		ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(
135
				resourceSet.getPackageRegistry());
136
		return extendedMetaData;
137
	}
138
139
	/**
140
	 * Configure the shell.
141
	 */
142
	protected void configureShell(Shell shell)
143
	{
144
		super.configureShell(shell);
145
		String propName = XsdUtils.getName(_property.getElement());
146
		shell.setText(NLS.bind(Messages.EDIT_PROPERTY_DEFINITION, propName));
147
	}
148
149
	/**
150
	 * Creates the dialog area.
151
	 */
152
	protected Control createDialogArea(Composite parent)
153
	{
154
		Composite composite = (Composite) super.createDialogArea(parent);
155
156
		GridLayout layout = new GridLayout(2, false);
157
		composite.setLayout(layout);
158
159
		createValidValuesGroup(composite);
160
		createDefaultValuesGroup(composite);
161
162
		applyDialogFont(composite);
163
		return composite;
164
	}
165
166
	private void createValidValuesGroup(Composite parent)
167
	{
168
		_extraSchema = new Group(parent, SWT.LEFT | SWT.BOTTOM);
169
		_extraSchema.setText(Messages.PROP_VALUE_RESTRICTION);
170
171
		GridLayout layout = new GridLayout(2, false);
172
		_extraSchema.setLayout(layout);
173
174
		GridData gd = new GridData(GridData.FILL_VERTICAL);
175
		_extraSchema.setLayoutData(gd);
176
177
		_propUnlimited = new Button(_extraSchema, SWT.RADIO);
178
		_propUnlimited.setText(Messages.UNRESTRICTED_LABEL);
179
		setSpan(_propUnlimited, 2);
180
		_propUnlimited.addListener(SWT.Selection, new Listener() {
181
			public void handleEvent(Event event)
182
			{
183
				enableDisableOnValidationType();
184
			}
185
		});
186
187
		_propValidValues = new Button(_extraSchema, SWT.RADIO);
188
		_propValidValues.setText(Messages.ENUMARATED_LABEL);
189
		setSpan(_propValidValues, 2);
190
		_propValidValues.addListener(SWT.Selection, new Listener() {
191
			public void handleEvent(Event event)
192
			{
193
				enableDisableOnValidationType();
194
			}
195
		});
196
197
		createAddRemoveEnumButtons(_extraSchema);
198
199
		_propValidRange = new Button(_extraSchema, SWT.RADIO);
200
		_propValidRange.setText(Messages.RANGED_LABEL);
201
		setSpan(_propValidRange, 2);
202
		_propValidRange.addListener(SWT.Selection, new Listener() {
203
			public void handleEvent(Event event)
204
			{
205
				enableDisableOnValidationType();
206
			}
207
		});
208
209
		_labelMin = new Label(_extraSchema, SWT.NONE);
210
		_labelMin.setText(Messages.MIN_LABLE);
211
		_labelMax = new Label(_extraSchema, SWT.NONE);
212
		_labelMax.setText(Messages.MAX_LABEL);
213
		_fieldMin = new Text(_extraSchema, SWT.LEFT | SWT.BORDER);
214
		gd = new GridData(GridData.FILL);
215
		gd.widthHint = 60;
216
		_fieldMin.setLayoutData(gd);
217
		_fieldMax = new Text(_extraSchema, SWT.LEFT | SWT.BORDER);
218
		gd = new GridData(GridData.FILL);
219
		gd.widthHint = 60;
220
		_fieldMax.setLayoutData(gd);
221
	}
222
223
	private void createDefaultValuesGroup(Composite parent)
224
	{
225
		Group composite = new Group(parent, SWT.LEFT | SWT.BOTTOM);
226
		composite.setText(Messages.DEFAULT_PROP_VALUES_LABEL);
227
228
		GridLayout layout = new GridLayout(3, false);
229
		composite.setLayout(layout);
230
231
		GridData gdMain = new GridData();
232
		gdMain.verticalAlignment = GridData.FILL;
233
		composite.setLayoutData(gdMain);
234
235
		_listDefault = new List(composite, SWT.MULTI | SWT.BORDER
236
				| SWT.H_SCROLL | SWT.V_SCROLL);
237
		GridData gd = new GridData();
238
		gd.heightHint = 146;
239
		gd.widthHint = 200;
240
		gd.horizontalSpan = 3;
241
		_listDefault.setLayoutData(gd);
242
243
		_listDefault.addListener(SWT.Selection, new Listener() {
244
245
			public void handleEvent(Event event)
246
			{
247
				selectedDefault();
248
			}
249
		});
250
251
		_buttonAddDefault = new Button(composite, SWT.PUSH);
252
		_buttonAddDefault.setText(Messages.ADD_DEFAULT_LABEL);
253
		_buttonAddDefault.addListener(SWT.Selection, new Listener() {
254
			public void handleEvent(Event event)
255
			{
256
				addNewDefault();
257
			}
258
		});
259
260
		_buttonEditDefault = new Button(composite, SWT.PUSH);
261
		_buttonEditDefault.setText(Messages.EDIT_DEFAULT_LABEL);
262
		_buttonEditDefault.addListener(SWT.Selection, new Listener() {
263
			public void handleEvent(Event event)
264
			{
265
				editDefault();
266
			}
267
		});
268
269
		_buttonDelDefault = new Button(composite, SWT.PUSH);
270
		_buttonDelDefault.setText(Messages.REMOVE_DEFAULT_LABEL);
271
		_buttonDelDefault.addListener(SWT.Selection, new Listener() {
272
			public void handleEvent(Event event)
273
			{
274
				delDefault();
275
			}
276
		});
277
	}
278
279
	/**
280
	 * <pre>
281
	 *   [Add] [Remove]
282
	 * </pre>
283
	 */
284
	private void createAddRemoveEnumButtons(Composite parent)
285
	{
286
		Composite panelAddDel = new Composite(parent, SWT.NONE);
287
		setSpan(panelAddDel, 2);
288
		GridLayout layout = new GridLayout(3, false);
289
		panelAddDel.setLayout(layout);
290
291
		_listValidEnum = new List(panelAddDel, SWT.MULTI | SWT.BORDER
292
				| SWT.H_SCROLL | SWT.V_SCROLL);
293
		GridData gdEnum = new GridData();
294
		gdEnum.heightHint = 100;
295
		gdEnum.widthHint = 200;
296
		gdEnum.horizontalSpan = 3;
297
		_listValidEnum.setLayoutData(gdEnum);
298
299
		_listValidEnum.addListener(SWT.Selection, new Listener() {
300
			public void handleEvent(Event event)
301
			{
302
				selectedEnumeration();
303
			}
304
		});
305
306
		_buttonAddEnum = new Button(panelAddDel, SWT.PUSH);
307
		_buttonAddEnum.setText(Messages.ADD_ENUM_LABEL);
308
		_buttonAddEnum.addListener(SWT.Selection, new Listener() {
309
			public void handleEvent(Event event)
310
			{
311
				addNewValidValueEnum();
312
			}
313
		});
314
315
		_buttonEditEnum = new Button(panelAddDel, SWT.PUSH);
316
		_buttonEditEnum.setText(Messages.EDIT_ENUM_LABEL);
317
		_buttonEditEnum.addListener(SWT.Selection, new Listener() {
318
			public void handleEvent(Event event)
319
			{
320
				editValidValueEnum();
321
			}
322
		});
323
324
		_buttonDelEnum = new Button(panelAddDel, SWT.PUSH);
325
		_buttonDelEnum.setText(Messages.REMOVE_ENUM_LABEL);
326
		_buttonDelEnum.addListener(SWT.Selection, new Listener() {
327
			public void handleEvent(Event event)
328
			{
329
				delValidValueEnum();
330
			}
331
		});
81
332
82
    private Label _labelMin;
333
		selectedEnumeration();
334
	}
83
335
84
    private Label _labelMax;
336
	/**
337
	 * User clicked hoping for new enum value creation function
338
	 */
339
	protected void addNewValidValueEnum()
340
	{
341
		IInputValidator validator = new IInputValidator() {
342
			public String isValid(String newText)
343
			{
344
				/*
345
				 * if (!Validation.isNCName(newText)) return "";
346
				 */
347
				if (newText.equals(""))
348
					return "";
349
				if (_listValidEnum.indexOf(newText) != -1)
350
					return Messages.DUPLICATE_VALUE_LABEL;
351
				if (!isValidUserInputAgainstPropertyType(newText))
352
					return Messages.INVALID_RESTRICTED_VALUE_FOR_PROPERTY;
353
				return null;
354
			}
355
		};
356
357
		InputDialog dlg = new InputDialog(getShell(),
358
				Messages.VALID_VALUE_ENUM_LABEL, Messages.NEW_ENUM_VALUE_LABEL,
359
				"", validator);
85
360
86
    private Text _fieldMin;
361
		int choice = dlg.open();
362
		if (choice == Window.OK)
363
		{
364
			String newEnum = dlg.getValue().trim();
365
			_listValidEnum.add(newEnum);
366
		}
367
	}
87
368
88
    private Text _fieldMax;
369
	protected void editValidValueEnum()
370
	{
371
		IInputValidator validator = new IInputValidator() {
372
			public String isValid(String newText)
373
			{
374
				/*
375
				 * if (!Validation.isNCName(newText)) return "";
376
				 */
377
				if (newText.equals(""))
378
					return "";
379
				if (_listValidEnum.indexOf(newText) != -1)
380
					return Messages.DUPLICATE_VALUE_LABEL;
381
				if (!isValidUserInputAgainstPropertyType(newText))
382
					return Messages.INVALID_RESTRICTED_VALUE_FOR_PROPERTY;
383
				return null;
384
			}
385
		};
386
387
		InputDialog dlg = new InputDialog(getShell(),
388
				Messages.VALID_VALUE_ENUM_LABEL,
389
				Messages.EDIT_ENUM_VALUE_LABEL,
390
				_listValidEnum.getSelection()[0], validator);
89
391
90
    private Button _buttonAddEnum;
392
		int choice = dlg.open();
393
		if (choice == Window.OK)
394
		{
395
			String newEnum = dlg.getValue().trim();
396
			_listValidEnum.remove(_listValidEnum.getSelectionIndices());
397
			_listValidEnum.add(newEnum);
398
			selectedEnumeration();
399
		}
400
	}
91
401
92
    private Button _buttonEditEnum;
402
	/**
403
	 * User clicked hoping to remove enum(s)
404
	 */
405
	protected void delValidValueEnum()
406
	{
407
		// Remove from GUI
408
		_listValidEnum.remove(_listValidEnum.getSelectionIndices());
409
		selectedEnumeration();
410
	}
93
411
94
    private Button _buttonDelEnum;
412
	private void addDefault(String newDef)
413
	{
414
		newDef = newDef.trim();
95
415
96
    private Button _buttonAddDefault;
416
		// changedDefaults = true;
417
		selectedDefault();
97
418
98
    private Button _buttonDelDefault;
419
		// If the restriction is 'enumerated', ensure the added default is legal
420
		// by adding it to the enumeration if it isn't already there
421
		if (_propValidValues.getSelection())
422
		{
423
			if (!Arrays.asList(_listValidEnum.getItems()).contains(newDef))
424
			{
425
				_listValidEnum.add(newDef);
426
			}
427
		}
428
	}
99
429
100
    private Button _buttonEditDefault;
430
	protected void addNewDefault()
431
	{
432
		IInputValidator validator = new IInputValidator() {
433
			public String isValid(String newText)
434
			{
435
				/*
436
				 * if (!Validation.isNCName(newText)) return "";
437
				 */
438
				if (newText.equals(""))
439
					return "";
440
				if (_listDefault.indexOf(newText) != -1)
441
					return Messages.DUPLICATE_VALUE_LABEL;
442
				if (!isValidUserInputAgainstPropertyType(newText))
443
					return Messages.INVALID_RESTRICTED_VALUE_FOR_PROPERTY;
444
				return null;
445
			}
446
		};
447
448
		InputDialog dlg = new InputDialog(getShell(),
449
				Messages.DEFAULT_VALUE_LABEL, Messages.NEW_DEFAULT_VALUE_LABEL,
450
				"", validator);
101
451
102
    private Property _property;
452
		int choice = dlg.open();
453
		if (choice == Window.OK)
454
		{
455
			String newDef = dlg.getValue();
456
			_listDefault.add(newDef.trim());
457
			addDefault(newDef);
458
		}
459
	}
103
460
104
    private MetadataDescriptorFactory _rmdFactory = new MetadataDescriptorFactoryImpl();
461
	protected void editDefault()
462
	{
463
		IInputValidator validator = new IInputValidator() {
464
			public String isValid(String newText)
465
			{
466
				/*
467
				 * if (newText.equals("")) return "";
468
				 */
469
				if (newText.equals(""))
470
					return "";
471
				if (_listDefault.indexOf(newText) != -1)
472
					return Messages.DUPLICATE_VALUE_LABEL;
473
				if (!isValidUserInputAgainstPropertyType(newText))
474
					return Messages.INVALID_RESTRICTED_VALUE_FOR_PROPERTY;
475
				return null;
476
			}
477
		};
478
479
		InputDialog dlg = new InputDialog(getShell(),
480
				Messages.DEFAULT_VALUE_LABEL,
481
				Messages.EDIT_DEFAULT_VALUE_LABEL,
482
				_listDefault.getSelection()[0], validator);
105
483
106
    private ExtendedMetaData _extendedMetaData;
484
		int choice = dlg.open();
485
		if (choice == Window.OK)
486
		{
487
			String newDef = dlg.getValue().trim();
107
488
108
    private CapabilityDomain _capabilityDomain;
489
			if (newDef.equals(""))
490
				return; // Do not allow empty value
109
491
110
    /**
492
			if (_listDefault.indexOf(newDef) == -1)
111
     * Creates a dialog for providing intial values and static vlaues for property.<br>
493
			{ // Do not duplicate
112
     * 
494
				int[] indices = _listDefault.getSelectionIndices();
113
     * @param parentShell
495
				_listDefault.remove(indices);
114
     *        Shell.
496
				_listDefault.add(newDef, indices[0]);
115
     *        
497
			}
116
     * @param capabilityDomain
498
117
     *        Capability domain of capability editor.
499
			// If the restriction is 'enumerated', ensure the added default
118
     *         
500
			// is legal
119
     * @param property
501
			// by adding it to the enumeration if it isn't already there
120
     *        Property selected for metadata editing.
502
			if (_propValidValues.getSelection())
121
     */
503
			{
122
    protected MetadataPropertyDialog(Shell parentShell,
504
				if (!Arrays.asList(_listValidEnum.getItems()).contains(newDef))
123
	    CapabilityDomain capabilityDomain, Property property)
505
				{
124
    {
506
					_listValidEnum.add(newDef);
125
	super(parentShell);
507
				}
126
	_property = property;
508
				// TODO Remove the old, pre-edit from the enumeration?
127
	_extendedMetaData = createExtendedMetaData();
509
			}
128
	_capabilityDomain = capabilityDomain;
510
		}
129
    }
511
	}
130
512
131
    private ExtendedMetaData createExtendedMetaData()
513
	protected void delDefault()
132
    {
514
	{
133
	ResourceSet resourceSet = new ResourceSetImpl();
515
		int[] indices = _listDefault.getSelectionIndices();
134
	ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(
516
		_listDefault.remove(indices);
135
		resourceSet.getPackageRegistry());
517
		selectedDefault();
136
	return extendedMetaData;
518
	}
137
    }
138
519
139
    /**
520
	/**
140
     * Configure the shell.
521
	 * 
141
     */
522
	 */
142
    protected void configureShell(Shell shell)
523
	protected void selectedDefault()
143
    {
524
	{
144
	super.configureShell(shell);
525
		_buttonDelDefault.setEnabled(_listDefault.getSelectionCount() > 0);
145
	String propName = XsdUtils.getName(_property.getElement());
526
		_buttonEditDefault.setEnabled(_listDefault.getSelectionCount() > 0);
146
	shell.setText(NLS.bind(Messages.EDIT_PROPERTY_DEFINITION,propName));
527
	}
147
    }
148
528
149
    /**
529
	protected void selectedEnumeration()
150
     * Creates the dialog area.
530
	{
151
     */
531
		_buttonAddEnum.setEnabled(_propValidValues.getSelection());
152
    protected Control createDialogArea(Composite parent)
532
		_buttonDelEnum.setEnabled(_listValidEnum.getSelectionCount() > 0);
153
    {
533
		_buttonEditEnum.setEnabled(_listValidEnum.getSelectionCount() > 0);
154
	Composite composite = (Composite) super.createDialogArea(parent);
534
	}
155
535
156
	GridLayout layout = new GridLayout(2, false);
536
	protected void selectedRange()
157
	composite.setLayout(layout);
537
	{
538
		_fieldMin.setEnabled(_propValidRange.getSelection());
539
		_fieldMax.setEnabled(_propValidRange.getSelection());
540
	}
158
541
159
	createValidValuesGroup(composite);
542
	protected void createButtonsForButtonBar(Composite parent)
160
	createDefaultValuesGroup(composite);
543
	{
544
		// Because we call Dialog.createButton(), rather than Button's
545
		// constructor,
546
		// we get Dialog's handling of buttons (which is to call
547
		// buttonPressed()).
548
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
549
				true);
550
		createButton(parent, IDialogConstants.CANCEL_ID,
551
				IDialogConstants.CANCEL_LABEL, false);
552
		initializeWidgets();
553
	}
161
554
162
	applyDialogFont(composite);
555
	private void initializeWidgets()
163
	return composite;
556
	{
164
    }
557
		PropertyType metadata = _property.getMetaData();
558
		if (metadata == null)
559
		{
560
			_propUnlimited.setSelection(true);
561
			selectedDefault();
562
			enableDisableOnValidationType();
563
			return;
564
		}
165
565
166
    private void createValidValuesGroup(Composite parent)
566
		Object[] validValues = MetaDataUtils.getValidValues(metadata
167
    {
567
				.getValidValues());
168
	_extraSchema = new Group(parent, SWT.LEFT | SWT.BOTTOM);
568
		if (validValues.length != 0)
169
	_extraSchema.setText(Messages.PROP_VALUE_RESTRICTION);
569
		{
570
			for (int i = 0; i < validValues.length; i++)
571
				_listValidEnum.add((String) validValues[i]);
572
			_propValidValues.setSelection(true);
573
			selectedEnumeration();
574
		}
170
575
171
	GridLayout layout = new GridLayout(2, false);
576
		if (metadata.getValidValueRange() != null)
172
	_extraSchema.setLayout(layout);
577
		{
578
			_fieldMin.setText((String) metadata.getValidValueRange()
579
					.getLowerBound());
580
			_fieldMax.setText((String) metadata.getValidValueRange()
581
					.getUpperBound());
582
			_propValidRange.setSelection(true);
583
			selectedRange();
584
		}
173
585
174
	GridData gd = new GridData(GridData.FILL_VERTICAL);
586
		Object[] defaultValues = MetaDataUtils.getStaticValues(metadata
175
	_extraSchema.setLayoutData(gd);
587
				.getStaticValues());
588
		if (defaultValues.length != 0)
589
		{
590
			for (int i = 0; i < defaultValues.length; i++)
591
				_listDefault.add((String) defaultValues[i]);
592
		}
176
593
177
	_propUnlimited = new Button(_extraSchema, SWT.RADIO);
594
		selectedDefault();
178
	_propUnlimited.setText(Messages.UNRESTRICTED_LABEL);
179
	setSpan(_propUnlimited, 2);
180
	_propUnlimited.addListener(SWT.Selection, new Listener()
181
	{
182
	    public void handleEvent(Event event)
183
	    {
184
		enableDisableOnValidationType();
595
		enableDisableOnValidationType();
185
	    }
596
	}
186
	});
187
597
188
	_propValidValues = new Button(_extraSchema, SWT.RADIO);
598
	protected void okPressed()
189
	_propValidValues.setText(Messages.ENUMARATED_LABEL);
190
	setSpan(_propValidValues, 2);
191
	_propValidValues.addListener(SWT.Selection, new Listener()
192
	{
599
	{
193
	    public void handleEvent(Event event)
600
		MetadataDescriptor propertyMetaDataDescriptor = _capabilityDomain
194
	    {
601
				.getCapability().getMetadata();
195
		enableDisableOnValidationType();
602
		if (propertyMetaDataDescriptor == null)
196
	    }
603
		{
197
	});
604
			propertyMetaDataDescriptor = createMetaDataDescriptor();
605
			_capabilityDomain.getCapability().setMetadata(
606
					propertyMetaDataDescriptor);
607
		}
198
608
199
	createAddRemoveEnumButtons(_extraSchema);
609
		PropertyType metadata = _property.getMetaData();
610
		if (metadata == null)
611
		{
612
			metadata = propertyMetaDataDescriptor.createNewPropertyType();
613
			_property.setMetaData(metadata);
614
			String ns = _property.getElement().getTargetNamespace();
615
			String name = XsdUtils.getName(_property.getElement());
616
			String prefix = propertyMetaDataDescriptor.getOrCreatePrefix(ns);
617
			metadata.setName(prefix + ":" + name);
618
		}
200
619
201
	_propValidRange = new Button(_extraSchema, SWT.RADIO);
620
		metadata.setStaticValues(null);
202
	_propValidRange.setText(Messages.RANGED_LABEL);
621
		metadata.setValidValueRange(null);
203
	setSpan(_propValidRange, 2);
622
		metadata.setValidValues(null);
204
	_propValidRange.addListener(SWT.Selection, new Listener()
205
	{
206
	    public void handleEvent(Event event)
207
	    {
208
		enableDisableOnValidationType();
209
	    }
210
	});
211
623
212
	_labelMin = new Label(_extraSchema, SWT.NONE);
624
		if (_propValidValues.getSelection())
213
	_labelMin.setText(Messages.MIN_LABLE);
625
		{
214
	_labelMax = new Label(_extraSchema, SWT.NONE);
626
			if (_listValidEnum.getItemCount() > 0)
215
	_labelMax.setText(Messages.MAX_LABEL);
627
			{
216
	_fieldMin = new Text(_extraSchema, SWT.LEFT | SWT.BORDER);
628
				ValidValuesType validValuesType = _rmdFactory
217
	gd = new GridData(GridData.FILL);
629
						.createValidValuesType();
218
	gd.widthHint = 60;
630
				FeatureMap fm = validValuesType.getAny();
219
	_fieldMin.setLayoutData(gd);
631
				for (int i = 0; i < _listValidEnum.getItemCount(); i++)
220
	_fieldMax = new Text(_extraSchema, SWT.LEFT | SWT.BORDER);
632
				{
221
	gd = new GridData(GridData.FILL);
633
					String value = _listValidEnum.getItem(i);
222
	gd.widthHint = 60;
634
					addValue(fm, value);
223
	_fieldMax.setLayoutData(gd);
635
				}
224
    }
636
				metadata.setValidValues(validValuesType);
225
637
			}
226
    private void createDefaultValuesGroup(Composite parent)
638
		}
227
    {
639
		else if (_propValidRange.getSelection())
228
	Group composite = new Group(parent, SWT.LEFT | SWT.BOTTOM);
640
		{
229
	composite.setText(Messages.DEFAULT_PROP_VALUES_LABEL);
641
			ValidValueRangeType validValueRange = _rmdFactory
230
642
					.createValidValueRangeType();
231
	GridLayout layout = new GridLayout(3, false);
643
			validValueRange.setLowerBound(_fieldMin.getText());
232
	composite.setLayout(layout);
644
			validValueRange.setUpperBound(_fieldMax.getText());
233
645
			metadata.setValidValueRange(validValueRange);
234
	GridData gdMain = new GridData();
646
		}
235
	gdMain.verticalAlignment = GridData.FILL;
236
	composite.setLayoutData(gdMain);
237
238
	_listDefault = new List(composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL
239
		| SWT.V_SCROLL);
240
	GridData gd = new GridData();
241
	gd.heightHint = 146;
242
	gd.widthHint = 200;
243
	gd.horizontalSpan = 3;
244
	_listDefault.setLayoutData(gd);
245
647
246
	_listDefault.addListener(SWT.Selection, new Listener()
648
		if (_listDefault.getItemCount() > 0)
247
	{
649
		{
650
			StaticValuesType staticValuesType = _rmdFactory
651
					.createStaticValuesType();
652
			FeatureMap fm = staticValuesType.getAny();
653
			for (int i = 0; i < _listDefault.getItemCount(); i++)
654
			{
655
				String value = _listDefault.getItem(i);
656
				addValue(fm, value);
657
			}
658
			metadata.setStaticValues(staticValuesType);
659
		}
248
660
249
	    public void handleEvent(Event event)
661
		super.okPressed();
250
	    {
662
	}
251
		selectedDefault();
663
252
	    }
664
	private void addValue(FeatureMap fm, String value)
253
	});
665
	{
666
		String namespace = _property.getElement().getTargetNamespace();
667
		String name = XsdUtils.getName(_property.getElement());
668
		EStructuralFeature esf = _extendedMetaData.demandFeature(namespace,
669
				name, true);
670
		AnyType anyType = XMLTypeFactory.eINSTANCE.createAnyType();
671
		FeatureMapUtil.addText(anyType.getAny(), value);
672
		fm.add(esf, anyType);
673
	}
254
674
255
	_buttonAddDefault = new Button(composite, SWT.PUSH);
675
	private void setSpan(Control c, int newSpan)
256
	_buttonAddDefault.setText(Messages.ADD_DEFAULT_LABEL);
676
	{
257
	_buttonAddDefault.addListener(SWT.Selection, new Listener()
677
		GridData gd = new GridData();
258
	{
678
		gd.horizontalSpan = newSpan;
259
	    public void handleEvent(Event event)
679
		c.setLayoutData(gd);
260
	    {
680
	}
261
		addNewDefault();
262
	    }
263
	});
264
265
	_buttonEditDefault = new Button(composite, SWT.PUSH);
266
	_buttonEditDefault.setText(Messages.EDIT_DEFAULT_LABEL);
267
	_buttonEditDefault.addListener(SWT.Selection, new Listener()
268
	{
269
	    public void handleEvent(Event event)
270
	    {
271
		editDefault();
272
	    }
273
	});
274
275
	_buttonDelDefault = new Button(composite, SWT.PUSH);
276
	_buttonDelDefault.setText(Messages.REMOVE_DEFAULT_LABEL);
277
	_buttonDelDefault.addListener(SWT.Selection, new Listener()
278
	{
279
	    public void handleEvent(Event event)
280
	    {
281
		delDefault();
282
	    }
283
	});	
284
    }
285
286
    /**
287
         * <pre>
288
         *  [Add] [Remove]
289
         * </pre>
290
         */
291
    private void createAddRemoveEnumButtons(Composite parent)
292
    {
293
	Composite panelAddDel = new Composite(parent, SWT.NONE);
294
	setSpan(panelAddDel, 2);
295
	GridLayout layout = new GridLayout(3, false);
296
	panelAddDel.setLayout(layout);
297
298
	_listValidEnum = new List(panelAddDel, SWT.MULTI | SWT.BORDER
299
		| SWT.H_SCROLL | SWT.V_SCROLL);
300
	GridData gdEnum = new GridData();
301
	gdEnum.heightHint = 100;
302
	gdEnum.widthHint = 200;
303
	gdEnum.horizontalSpan = 3;
304
	_listValidEnum.setLayoutData(gdEnum);
305
681
306
	_listValidEnum.addListener(SWT.Selection, new Listener()
682
	/**
683
	 * Turn the extra-schema validation extra controls on/off based on radio
684
	 * button selection
685
	 */
686
	private void enableDisableOnValidationType()
307
	{
687
	{
308
	    public void handleEvent(Event event)
688
		enableEnumControls(_propValidValues.getSelection());
309
	    {
689
		enableRangeControls(_propValidRange.getSelection());
310
		selectedEnumeration();
690
	}
311
	    }
312
	});
313
691
314
	_buttonAddEnum = new Button(panelAddDel, SWT.PUSH);
692
	/**
315
	_buttonAddEnum.setText(Messages.ADD_ENUM_LABEL);
693
	 * Turn the enumeration controls (the list of valid enums and the 'add'
316
	_buttonAddEnum.addListener(SWT.Selection, new Listener()
694
	 * button on/off
317
	{
695
	 */
318
	    public void handleEvent(Event event)
696
	private void enableEnumControls(boolean b)
319
	    {
320
		addNewValidValueEnum();
321
	    }
322
	});
323
324
	_buttonEditEnum = new Button(panelAddDel, SWT.PUSH);
325
	_buttonEditEnum.setText(Messages.EDIT_ENUM_LABEL);
326
	_buttonEditEnum.addListener(SWT.Selection, new Listener()
327
	{
328
	    public void handleEvent(Event event)
329
	    {
330
		editValidValueEnum();
331
	    }
332
	});
333
334
	_buttonDelEnum = new Button(panelAddDel, SWT.PUSH);
335
	_buttonDelEnum.setText(Messages.REMOVE_ENUM_LABEL);
336
	_buttonDelEnum.addListener(SWT.Selection, new Listener()
337
	{
338
	    public void handleEvent(Event event)
339
	    {
340
		delValidValueEnum();
341
	    }
342
	});
343
344
	selectedEnumeration();
345
    }
346
347
    /**
348
         * User clicked hoping for new enum value creation function
349
         */
350
    protected void addNewValidValueEnum()
351
    {
352
	IInputValidator validator = new IInputValidator()
353
	{
354
	    public String isValid(String newText)
355
	    {
356
		/*if (!Validation.isNCName(newText))
357
		    return "";*/
358
		if(newText.equals(""))
359
		    return "";
360
		if (_listValidEnum.indexOf(newText) != -1)
361
		    return Messages.DUPLICATE_VALUE_LABEL;
362
		if(!isValidUserInputAgainstPropertyType(newText))
363
			return Messages.INVALID_RESTRICTED_VALUE_FOR_PROPERTY;
364
		return null;
365
	    }
366
	};
367
368
	InputDialog dlg = new InputDialog(getShell(),
369
		Messages.VALID_VALUE_ENUM_LABEL, Messages.NEW_ENUM_VALUE_LABEL, "", validator);
370
371
	int choice = dlg.open();
372
	if (choice == Window.OK)
373
	{
374
	    String newEnum = dlg.getValue().trim();
375
	    _listValidEnum.add(newEnum);
376
	}
377
    }
378
379
    protected void editValidValueEnum()
380
    {
381
	IInputValidator validator = new IInputValidator()
382
	{
383
	    public String isValid(String newText)
384
	    {
385
		/*if (!Validation.isNCName(newText))
386
		    return "";*/
387
		if(newText.equals(""))
388
		    return "";
389
		if (_listValidEnum.indexOf(newText) != -1)
390
		    return Messages.DUPLICATE_VALUE_LABEL;
391
		if(!isValidUserInputAgainstPropertyType(newText))
392
			return Messages.INVALID_RESTRICTED_VALUE_FOR_PROPERTY;
393
		return null;
394
	    }
395
	};
396
397
	InputDialog dlg = new InputDialog(getShell(),
398
		Messages.VALID_VALUE_ENUM_LABEL, Messages.EDIT_ENUM_VALUE_LABEL, _listValidEnum
399
			.getSelection()[0], validator);
400
401
	int choice = dlg.open();
402
	if (choice == Window.OK)
403
	{
404
	    String newEnum = dlg.getValue().trim();
405
	    _listValidEnum.remove(_listValidEnum.getSelectionIndices());
406
	    _listValidEnum.add(newEnum);
407
	    selectedEnumeration();
408
	}
409
    }
410
411
    /**
412
         * User clicked hoping to remove enum(s)
413
         */
414
    protected void delValidValueEnum()
415
    {
416
	// Remove from GUI
417
	_listValidEnum.remove(_listValidEnum.getSelectionIndices());
418
	selectedEnumeration();
419
    }
420
421
    private void addDefault(String newDef)
422
    {
423
	newDef = newDef.trim();
424
425
	// changedDefaults = true;
426
	selectedDefault();
427
428
	// If the restriction is 'enumerated', ensure the added default is legal
429
	// by adding it to the enumeration if it isn't already there
430
	if (_propValidValues.getSelection())
431
	{
432
	    if (!Arrays.asList(_listValidEnum.getItems()).contains(newDef))
433
	    {
434
		_listValidEnum.add(newDef);
435
	    }
436
	}
437
    }
438
439
    protected void addNewDefault()
440
    {
441
	IInputValidator validator = new IInputValidator()
442
	{
443
	    public String isValid(String newText)
444
	    {
445
		/*if (!Validation.isNCName(newText))
446
		    return "";*/
447
		if(newText.equals(""))
448
		    return "";
449
		if (_listDefault.indexOf(newText) != -1)
450
		    return Messages.DUPLICATE_VALUE_LABEL;
451
		if(!isValidUserInputAgainstPropertyType(newText))
452
			return Messages.INVALID_RESTRICTED_VALUE_FOR_PROPERTY;
453
		return null;
454
	    }
455
	};
456
457
	InputDialog dlg = new InputDialog(getShell(), Messages.DEFAULT_VALUE_LABEL,
458
		Messages.NEW_DEFAULT_VALUE_LABEL, "", validator);
459
460
	int choice = dlg.open();
461
	if (choice == Window.OK)
462
	{
463
	    String newDef = dlg.getValue();
464
	    _listDefault.add(newDef.trim());
465
	    addDefault(newDef);
466
	}
467
    }
468
469
    protected void editDefault()
470
    {
471
	IInputValidator validator = new IInputValidator()
472
	{
473
	    public String isValid(String newText)
474
	    {
475
		/*if (newText.equals(""))
476
		    return "";*/
477
		if(newText.equals(""))
478
		    return "";
479
		if (_listDefault.indexOf(newText) != -1)
480
		    return Messages.DUPLICATE_VALUE_LABEL;
481
		if(!isValidUserInputAgainstPropertyType(newText))
482
			return Messages.INVALID_RESTRICTED_VALUE_FOR_PROPERTY;
483
		return null;
484
	    }
485
	};
486
487
	InputDialog dlg = new InputDialog(getShell(), Messages.DEFAULT_VALUE_LABEL,
488
		Messages.EDIT_DEFAULT_VALUE_LABEL, _listDefault.getSelection()[0], validator);
489
490
	int choice = dlg.open();
491
	if (choice == Window.OK)
492
	{
697
	{
493
	    String newDef = dlg.getValue().trim();
698
		_listValidEnum.setEnabled(b);
699
		if (b)
700
			selectedEnumeration();
701
		else
702
		{
703
			_buttonAddEnum.setEnabled(b);
704
			_buttonEditEnum.setEnabled(b);
705
			_buttonDelEnum.setEnabled(b);
706
		}
707
	}
494
708
495
	    if (newDef.equals(""))
709
	/** Turn the min/max controls on/off */
496
		return; // Do not allow empty value
710
	private void enableRangeControls(boolean b)
711
	{
712
		_labelMin.setEnabled(b);
713
		_labelMax.setEnabled(b);
714
		_fieldMin.setEnabled(b);
715
		_fieldMax.setEnabled(b);
716
	}
497
717
498
	    if (_listDefault.indexOf(newDef) == -1)
718
	protected MetadataDescriptor createMetaDataDescriptor()
499
	    { // Do not duplicate
719
	{
500
		int[] indices = _listDefault.getSelectionIndices();
720
		MetadataDescriptor propertyMetaDataDescriptor = MetaDataUtils
501
		_listDefault.remove(indices);
721
				.createMetaDataDescriptor(_capabilityDomain);
502
		_listDefault.add(newDef, indices[0]);
722
		return propertyMetaDataDescriptor;
503
	    }
723
	}
504
724
505
	    // If the restriction is 'enumerated', ensure the added default
725
	// NOTE: Fix for Bugzilla Bug 167370 : Default values dialog in capability
506
                // is legal
726
	// editor does not accept values
507
	    // by adding it to the enumeration if it isn't already there
727
	// with spaces or numbers and is not validated.
508
	    if (_propValidValues.getSelection())
728
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167370
509
	    {
729
	private boolean isValidUserInputAgainstPropertyType(String userInput)
510
		if (!Arrays.asList(_listValidEnum.getItems()).contains(newDef))
730
	{
511
		{
731
		String propType = XsdUtils.getType(_property.getElement());
512
		    _listValidEnum.add(newDef);
732
		if (propType == null || propType.equals(""))
513
		}
733
			return true;
514
		// TODO Remove the old, pre-edit from the enumeration?
734
		if (propType.equals("integer") || propType.equals("int"))
515
	    }
735
		{
516
	}
736
			try
517
    }
737
			{
518
738
				Integer.parseInt(userInput);
519
    protected void delDefault()
739
			} catch (Exception e)
520
    {
740
			{
521
	int[] indices = _listDefault.getSelectionIndices();
741
				return false;
522
	_listDefault.remove(indices);
742
			}
523
	selectedDefault();
743
		}
524
    }
744
		else if (propType.equals("float"))
525
745
		{
526
    /**
746
			try
527
         * 
747
			{
528
         */
748
				Float.parseFloat(userInput);
529
    protected void selectedDefault()
749
			} catch (Exception e)
530
    {
750
			{
531
	_buttonDelDefault.setEnabled(_listDefault.getSelectionCount() > 0);
751
				return false;
532
	_buttonEditDefault.setEnabled(_listDefault.getSelectionCount() > 0);
752
			}
533
    }
753
		}
534
754
		else if (propType.equals("short"))
535
    protected void selectedEnumeration()
755
		{
536
    {
756
			try
537
	_buttonAddEnum.setEnabled(_propValidValues.getSelection());
757
			{
538
	_buttonDelEnum.setEnabled(_listValidEnum.getSelectionCount() > 0);
758
				Short.parseShort(userInput);
539
	_buttonEditEnum.setEnabled(_listValidEnum.getSelectionCount() > 0);
759
			} catch (Exception e)
540
    }
760
			{
541
761
				return false;
542
    protected void selectedRange()
762
			}
543
    {
763
		}
544
	_fieldMin.setEnabled(_propValidRange.getSelection());
764
		else if (propType.equals("long"))
545
	_fieldMax.setEnabled(_propValidRange.getSelection());
765
		{
546
    }
766
			try
547
767
			{
548
    protected void createButtonsForButtonBar(Composite parent)
768
				Long.parseLong(userInput);
549
    {
769
			} catch (Exception e)
550
	// Because we call Dialog.createButton(), rather than Button's
770
			{
551
        // constructor,
771
				return false;
552
	// we get Dialog's handling of buttons (which is to call
772
			}
553
        // buttonPressed()).
773
		}
554
	createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
774
		else if (propType.equals("double"))
555
		true);
775
		{
556
	createButton(parent, IDialogConstants.CANCEL_ID,
776
			try
557
		IDialogConstants.CANCEL_LABEL, false);
777
			{
558
	initializeWidgets();
778
				Double.parseDouble(userInput);
559
    }
779
			} catch (Exception e)
560
780
			{
561
    private void initializeWidgets()
781
				return false;
562
    {
782
			}
563
	PropertyType metadata = _property.getMetaData();
783
		}
564
	if (metadata == null)
784
		else if (propType.equals("boolean"))
565
	{
785
		{
566
	    _propUnlimited.setSelection(true);
786
			if (!userInput.equals("true"))
567
	    selectedDefault();
787
				if (!userInput.equals("false"))
568
	    enableDisableOnValidationType();
788
					return false;
569
	    return;
789
		}
570
	}
790
		else if (propType.equals("NCName"))
571
791
		{
572
	Object[] validValues = MetaDataUtils.getValidValues(metadata
792
			return Validation.isNCName(userInput);
573
		.getValidValues());
793
		}
574
	if (validValues.length != 0)
794
		return true;
575
	{
795
	}
576
	    for (int i = 0; i < validValues.length; i++)
577
		_listValidEnum.add((String) validValues[i]);
578
	    _propValidValues.setSelection(true);
579
	    selectedEnumeration();
580
	}
581
582
	if (metadata.getValidValueRange() != null)
583
	{
584
	    _fieldMin.setText((String) metadata.getValidValueRange()
585
		    .getLowerBound());
586
	    _fieldMax.setText((String) metadata.getValidValueRange()
587
		    .getUpperBound());
588
	    _propValidRange.setSelection(true);
589
	    selectedRange();
590
	}
591
592
	Object[] defaultValues = MetaDataUtils.getStaticValues(metadata
593
		.getStaticValues());
594
	if (defaultValues.length != 0)
595
	{
596
	    for (int i = 0; i < defaultValues.length; i++)
597
		_listDefault.add((String) defaultValues[i]);
598
	}
599
600
	selectedDefault();
601
	enableDisableOnValidationType();
602
    }
603
604
    protected void okPressed()
605
    {
606
607
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = _capabilityDomain
608
		.getMetaDataDescriptor();
609
	if (propertyMetaDataDescriptor == null)
610
	{
611
	    propertyMetaDataDescriptor = createMetaDataDescriptor();
612
	    _capabilityDomain.setMetaDataDescriptor(propertyMetaDataDescriptor);
613
	}
614
615
	PropertyType metadata = _property.getMetaData();
616
	if (metadata == null)
617
	{
618
	    metadata = propertyMetaDataDescriptor.createNewPropertyType();
619
	    _property.setMetaData(metadata);
620
	    String ns = _property.getElement().getTargetNamespace();
621
	    String name = XsdUtils.getName(_property.getElement());
622
	    String prefix = propertyMetaDataDescriptor.getOrCreatePrefix(ns);
623
	    metadata.setName(new QName(ns, name, prefix));
624
	}
625
626
	metadata.setStaticValues(null);
627
	metadata.setValidValueRange(null);
628
	metadata.setValidValues(null);
629
630
	if (_propValidValues.getSelection())
631
	{
632
	    if (_listValidEnum.getItemCount() > 0)
633
	    {
634
		ValidValuesType validValuesType = _rmdFactory
635
			.createValidValuesType();
636
		FeatureMap fm = validValuesType.getAny();
637
		for (int i = 0; i < _listValidEnum.getItemCount(); i++)
638
		{
639
		    String value = _listValidEnum.getItem(i);
640
		    addValue(fm, value);
641
		}
642
		metadata.setValidValues(validValuesType);
643
	    }
644
	}
645
	else if (_propValidRange.getSelection())
646
	{
647
	    ValidValueRangeType validValueRange = _rmdFactory
648
		    .createValidValueRangeType();
649
	    validValueRange.setLowerBound(_fieldMin.getText());
650
	    validValueRange.setUpperBound(_fieldMax.getText());
651
	    metadata.setValidValueRange(validValueRange);
652
	}
653
654
	if (_listDefault.getItemCount() > 0)
655
	{
656
	    StaticValuesType staticValuesType = _rmdFactory
657
		    .createStaticValuesType();
658
	    FeatureMap fm = staticValuesType.getAny();
659
	    for (int i = 0; i < _listDefault.getItemCount(); i++)
660
	    {
661
		String value = _listDefault.getItem(i);
662
		addValue(fm, value);
663
	    }
664
	    metadata.setStaticValues(staticValuesType);
665
	}
666
667
	super.okPressed();
668
    }
669
670
    private void addValue(FeatureMap fm, String value)
671
    {
672
	String namespace = _property.getElement().getTargetNamespace();
673
	String name = XsdUtils.getName(_property.getElement());
674
	EStructuralFeature esf = _extendedMetaData.demandFeature(namespace,
675
		name, true);
676
	AnyType anyType = XMLTypeFactory.eINSTANCE.createAnyType();
677
	FeatureMapUtil.addText(anyType.getAny(), value);
678
	fm.add(esf, anyType);
679
    }
680
681
    private void setSpan(Control c, int newSpan)
682
    {
683
	GridData gd = new GridData();
684
	gd.horizontalSpan = newSpan;
685
	c.setLayoutData(gd);
686
    }
687
688
    /**
689
         * Turn the extra-schema validation extra controls on/off based on radio
690
         * button selection
691
         */
692
    private void enableDisableOnValidationType()
693
    {
694
	enableEnumControls(_propValidValues.getSelection());
695
	enableRangeControls(_propValidRange.getSelection());
696
    }
697
698
    /**
699
         * Turn the enumeration controls (the list of valid enums and the 'add'
700
         * button on/off
701
         */
702
    private void enableEnumControls(boolean b)
703
    {
704
	_listValidEnum.setEnabled(b);
705
	if (b)
706
	    selectedEnumeration();
707
	else
708
	{
709
	    _buttonAddEnum.setEnabled(b);
710
	    _buttonEditEnum.setEnabled(b);
711
	    _buttonDelEnum.setEnabled(b);
712
	}
713
    }
714
715
    /** Turn the min/max controls on/off */
716
    private void enableRangeControls(boolean b)
717
    {
718
	_labelMin.setEnabled(b);
719
	_labelMax.setEnabled(b);
720
	_fieldMin.setEnabled(b);
721
	_fieldMax.setEnabled(b);
722
    }
723
724
    protected PropertyMetaDataDescriptor createMetaDataDescriptor()
725
    {
726
	PropertyMetaDataDescriptor propertyMetaDataDescriptor = MetaDataUtils
727
		.createMetaDataDescriptor(_capabilityDomain);
728
	return propertyMetaDataDescriptor;
729
    }
730
    
731
    // NOTE: Fix for Bugzilla Bug 167370 : Default values dialog in capability editor does not accept values 
732
    // with spaces or numbers and is not validated.    
733
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=167370
734
    private boolean isValidUserInputAgainstPropertyType(String userInput)
735
    {
736
    	String propType = XsdUtils.getType(_property.getElement());
737
    	if(propType == null || propType.equals(""))
738
    		return true;
739
    	if(propType.equals("integer") || propType.equals("int"))
740
    	{
741
    		try{
742
    			Integer.parseInt(userInput);
743
    		}catch(Exception e){
744
    			return false;
745
    		}   			
746
    	}
747
    	else if(propType.equals("float"))
748
    	{
749
    		try{
750
    			Float.parseFloat(userInput);
751
    		}catch(Exception e){
752
    			return false;
753
    		}   			
754
    	}
755
    	else if(propType.equals("short"))
756
    	{
757
    		try{
758
    			Short.parseShort(userInput);
759
    		}catch(Exception e){
760
    			return false;
761
    		}   			
762
    	}
763
    	else if(propType.equals("long"))
764
    	{
765
    		try{
766
    			Long.parseLong(userInput);
767
    		}catch(Exception e){
768
    			return false;
769
    		}   			
770
    	}
771
    	else if(propType.equals("double"))
772
    	{
773
    		try{
774
    			Double.parseDouble(userInput);
775
    		}catch(Exception e){
776
    			return false;
777
    		}   			
778
    	}
779
    	else if(propType.equals("boolean"))
780
    	{
781
    		if(!userInput.equals("true"))
782
    			if(!userInput.equals("false"))
783
    				return false;
784
    	}
785
    	else if(propType.equals("NCName"))
786
    	{
787
    		return Validation.isNCName(userInput);
788
    	}
789
    	return true;
790
    }
791
796
792
}
797
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/overview/internal/ChangeCapabilityDescriptionCommand.java (-35 / +34 lines)
Lines 42-49 Link Here
42
    public ChangeCapabilityDescriptionCommand(
42
    public ChangeCapabilityDescriptionCommand(
43
	    CapabilityDomain capabilityDomain, String newDescription)
43
	    CapabilityDomain capabilityDomain, String newDescription)
44
    {
44
    {
45
	_capabilityDomain = capabilityDomain;
45
		_capabilityDomain = capabilityDomain;
46
	_newDescription = newDescription;
46
		_newDescription = newDescription;
47
    }
47
    }
48
48
49
    /**
49
    /**
Lines 51-94 Link Here
51
     */
51
     */
52
    public void execute()
52
    public void execute()
53
    {
53
    {
54
		if (_capabilityDomain.getDescriptionNode() != null)
55
		{
56
		    _capabilityDomain.getDescriptionNode().setData(_newDescription);
57
		    _capabilityDomain.getCapability().setDescription(_newDescription);
58
		    return;
59
		}
54
60
55
	if (_capabilityDomain.getDescriptionNode() != null)
61
		Definition definition = _capabilityDomain.getCapability().getDefinition();
56
	{
62
		XSDSchema tnsSchema = WsdlUtils.createOrFindSchema(definition,
57
	    _capabilityDomain.getDescriptionNode().setData(_newDescription);
63
			definition.getTargetNamespace());
58
	    _capabilityDomain.getCapability().setDescription(_newDescription);
64
		List annotations = tnsSchema.getAnnotations();
59
	    return;
65
		Text descriptionNode = null;
60
	}
66
		if (annotations != null && annotations.size() != 0)
61
67
		{
62
	Definition definition = _capabilityDomain.getDefinition();
68
		    XSDAnnotation annotation = (XSDAnnotation) annotations.get(0);
63
	XSDSchema tnsSchema = WsdlUtils.createOrFindSchema(definition,
69
		    Element documentation = annotation.createUserInformation(null);
64
		definition.getTargetNamespace());
70
		    annotation.getElement().appendChild(documentation);
65
	List annotations = tnsSchema.getAnnotations();
71
		    descriptionNode = documentation.getOwnerDocument().createTextNode(_newDescription);
66
	Text descriptionNode = null;
72
		    documentation.appendChild(descriptionNode);
67
	if (annotations != null && annotations.size() != 0)
73
		}
68
	{
74
		else
69
	    XSDAnnotation annotation = (XSDAnnotation) annotations.get(0);
75
		{
70
	    Element documentation = annotation.createUserInformation(null);
76
		    descriptionNode = createNewAnnotation(tnsSchema);
71
	    annotation.getElement().appendChild(documentation);
77
		}
72
	    descriptionNode = documentation.getOwnerDocument().createTextNode(_newDescription);
78
		_capabilityDomain.setDescriptionNode(descriptionNode);
73
	    documentation.appendChild(descriptionNode);
79
		_capabilityDomain.getCapability().setDescription(_newDescription);
74
	}
75
	else
76
	{
77
	    descriptionNode = createNewAnnotation(tnsSchema);
78
	}
79
	_capabilityDomain.setDescriptionNode(descriptionNode);
80
	_capabilityDomain.getCapability().setDescription(_newDescription);
81
    }
80
    }
82
81
83
    private Text createNewAnnotation(XSDSchema schema)
82
    private Text createNewAnnotation(XSDSchema schema)
84
    {
83
    {
85
	XSDAnnotation annotation = XSDFactory.eINSTANCE.createXSDAnnotation();
84
		XSDAnnotation annotation = XSDFactory.eINSTANCE.createXSDAnnotation();
86
	schema.getContents().add(0, annotation);
85
		schema.getContents().add(0, annotation);
87
	Element documentation = annotation.createUserInformation(null);
86
		Element documentation = annotation.createUserInformation(null);
88
	annotation.getElement().appendChild(documentation);
87
		annotation.getElement().appendChild(documentation);
89
	Text node = documentation.getOwnerDocument().createTextNode(_newDescription);
88
		Text node = documentation.getOwnerDocument().createTextNode(_newDescription);
90
	documentation.appendChild(node);
89
		documentation.appendChild(node);
91
	return node;
90
		return node;
92
    }
91
    }
93
92
94
}
93
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/overview/internal/ChangeCapabilityNameCommand.java (-48 / +50 lines)
Lines 16-22 Link Here
16
16
17
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
17
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
19
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
19
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
20
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
21
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
21
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants;
22
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
22
import org.eclipse.tptp.wsdm.tooling.util.internal.XsdUtils;
Lines 50-57 Link Here
50
    public ChangeCapabilityNameCommand(CapabilityDomain capabilityDomain,
50
    public ChangeCapabilityNameCommand(CapabilityDomain capabilityDomain,
51
	    String newName)
51
	    String newName)
52
    {
52
    {
53
	_capabilityDomain = capabilityDomain;
53
		_capabilityDomain = capabilityDomain;
54
	_newName = newName;
54
		_newName = newName;
55
    }
55
    }
56
56
57
    /**
57
    /**
Lines 59-117 Link Here
59
     */
59
     */
60
    public void execute()
60
    public void execute()
61
    {
61
    {
62
	Capability capability = _capabilityDomain.getCapability();
62
		Capability capability = _capabilityDomain.getCapability();
63
	capability.setName(_newName);
63
		capability.setName(_newName);
64
	Definition definition = _capabilityDomain.getDefinition();
64
		Definition definition = capability.getDefinition();
65
	String namespace = definition.getTargetNamespace();
65
		String namespace = definition.getTargetNamespace();
66
	definition.setQName(new QName(namespace, _newName));
66
		definition.setQName(new QName(namespace, _newName));
67
67
	
68
	PortType pt = WsdlUtils.getPortType(definition);
68
		PortType pt = WsdlUtils.getPortType(definition);
69
	if (pt != null)
69
		if (pt != null)
70
	    pt.setQName(new QName(namespace, _newName + "PortType"));
70
		    pt.setQName(new QName(namespace, _newName + "PortType"));
71
71
	
72
	changeMetadescriptorName(pt);
72
		changeMetadescriptorName(pt);
73
73
	
74
	changeResourcePropertiesName(pt);
74
		changeResourcePropertiesName(pt);
75
    }
75
    }
76
    
76
    
77
    private void changeMetadescriptorName(PortType pt)
77
    private void changeMetadescriptorName(PortType pt)
78
    {
78
    {
79
	PropertyMetaDataDescriptor metaDataDescriptor = _capabilityDomain.getMetaDataDescriptor();
79
		MetadataDescriptor metaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
80
	if (metaDataDescriptor != null)
80
		if (metaDataDescriptor != null)
81
	{
81
		{
82
	    String metaDataDescriptorName = _newName + "Descriptor";
82
		    String metaDataDescriptorName = _newName + "Descriptor";
83
	    metaDataDescriptor.setMetadataDescriptorName(metaDataDescriptorName);
83
		    metaDataDescriptor.setMetadataDescriptorName(metaDataDescriptorName);
84
	    if (pt != null)
84
		    String prefix = metaDataDescriptor.getPrefix(_capabilityDomain.getCapability().getNamespace());
85
	    {
85
		    metaDataDescriptor.getMetadataDescriptorType().setInterface(prefix+":"+_newName+"PortType");	    
86
		Attr attribute = pt.getElement().getAttributeNodeNS(
86
		    if (pt != null)
87
			WsdmConstants.WSRMD_NS,
87
		    {
88
			WsdlUtils.METADATA_DESCRIPTOR_KEY);
88
				Attr attribute = pt.getElement().getAttributeNodeNS(
89
		if (attribute != null)
89
					WsdmConstants.WSRMD_NS,
90
		    attribute.setNodeValue(metaDataDescriptorName);
90
					WsdlUtils.METADATA_DESCRIPTOR_KEY);
91
	    }
91
				if (attribute != null)
92
	}
92
				    attribute.setNodeValue(metaDataDescriptorName);
93
		    }
94
		}
93
    }
95
    }
94
    
96
    
95
    private void changeResourcePropertiesName(PortType pt)
97
    private void changeResourcePropertiesName(PortType pt)
96
    {
98
    {
97
	Definition definition = _capabilityDomain.getDefinition();
99
		Definition definition = _capabilityDomain.getCapability().getDefinition();
98
	XSDElementDeclaration resourcePropertyElement = _capabilityDomain.getResourcePropertyElement();
100
		XSDElementDeclaration resourcePropertyElement = _capabilityDomain.getResourcePropertyElement();
99
	if (resourcePropertyElement != null)
101
		if (resourcePropertyElement != null)
100
	{
102
		{
101
	    String rpElementName = _newName + "Properties";
103
		    String rpElementName = _newName + "Properties";
102
	    XsdUtils.setName(resourcePropertyElement, rpElementName);
104
		    XsdUtils.setName(resourcePropertyElement, rpElementName);
103
	    if (pt != null)
105
		    if (pt != null)
104
	    {
106
		    {
105
		Attr attribute = pt.getElement().getAttributeNodeNS(
107
				Attr attribute = pt.getElement().getAttributeNodeNS(
106
			WsdmConstants.WSRP_NS,
108
					WsdmConstants.WSRP_NS,
107
			WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
109
					WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
108
		String rpElementPrefix = WsdlUtils.getPrefix(definition,
110
				String rpElementPrefix = WsdlUtils.getPrefix(definition,
109
			resourcePropertyElement.getTargetNamespace());
111
					resourcePropertyElement.getTargetNamespace());
110
		if (attribute != null)
112
				if (attribute != null)
111
		    attribute.setNodeValue(rpElementPrefix + ":"
113
				    attribute.setNodeValue(rpElementPrefix + ":"
112
			    + rpElementName);
114
					    + rpElementName);
113
	    }
115
		    }
114
	}
116
		}
115
    }
117
    }
116
118
117
}
119
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/command/overview/internal/ChangeCapabilityNamespaceCommand.java (-141 / +119 lines)
Lines 18-28 Link Here
18
18
19
import org.eclipse.emf.common.util.EMap;
19
import org.eclipse.emf.common.util.EMap;
20
import org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
20
import org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
21
import org.eclipse.emf.ecore.xml.type.internal.QName;
22
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
21
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityDomain;
23
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
24
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
25
import org.eclipse.tptp.wsdm.tooling.util.internal.PropertyMetaDataDescriptor;
26
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
23
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
27
import org.eclipse.wst.wsdl.Definition;
24
import org.eclipse.wst.wsdl.Definition;
28
import org.eclipse.wst.wsdl.Message;
25
import org.eclipse.wst.wsdl.Message;
Lines 58-101 Link Here
58
    public ChangeCapabilityNamespaceCommand(CapabilityDomain capabilityDomain,
55
    public ChangeCapabilityNamespaceCommand(CapabilityDomain capabilityDomain,
59
	    String newNS)
56
	    String newNS)
60
    {
57
    {
61
	_capabilityDomain = capabilityDomain;
58
		_capabilityDomain = capabilityDomain;
62
	_oldNamespace = capabilityDomain.getCapability().getNamespace();
59
		_oldNamespace = capabilityDomain.getCapability().getNamespace();
63
	_newNamespace = newNS;
60
		_newNamespace = newNS;
64
    }
61
    }
65
62
66
    private void changeAllOldNSInSchemas()
63
    private void changeAllOldNSInSchemas()
67
    {
64
    {
68
	Definition definition = _capabilityDomain.getDefinition();
65
		Definition definition = _capabilityDomain.getCapability().getDefinition();
69
	XSDSchema[] schemas = WsdlUtils.getXSDSchemas(definition);
66
		XSDSchema[] schemas = WsdlUtils.getXSDSchemas(definition);
70
	if (schemas == null)
67
		if (schemas == null)
71
	{
68
		{
72
	    // No WSDL Types found
69
		    // No WSDL Types found
73
	    return;
70
		    return;
74
	}
71
		}
75
72
	
76
	for (int i = 0; i < schemas.length; i++)
73
		for (int i = 0; i < schemas.length; i++)
77
	    changeNS(schemas[i]);	
74
		    changeNS(schemas[i]);	
78
    }
75
    }
79
76
80
    private void changeNS(XSDSchema schema)
77
    private void changeNS(XSDSchema schema)
81
    {
78
    {
82
	changeAllOldNS(schema);
79
		changeAllOldNS(schema);
83
	if (schema.getTargetNamespace().equals(_oldNamespace))
80
		if (schema.getTargetNamespace().equals(_oldNamespace))
84
	    schema.setTargetNamespace(_newNamespace);
81
		    schema.setTargetNamespace(_newNamespace);
85
    }
82
    }
86
83
87
    private void changeAllOldNS(XSDSchema schema)
84
    private void changeAllOldNS(XSDSchema schema)
88
    {
85
    {
89
	Map nsMap = schema.getQNamePrefixToNamespaceMap();
86
		Map nsMap = schema.getQNamePrefixToNamespaceMap();
90
	Iterator keyIt = nsMap.keySet().iterator();
87
		Iterator keyIt = nsMap.keySet().iterator();
91
	Iterator valueIt = nsMap.values().iterator();
88
		Iterator valueIt = nsMap.values().iterator();
92
	while (keyIt.hasNext())
89
		while (keyIt.hasNext())
93
	{
90
		{
94
	    String key = (String) keyIt.next();
91
		    String key = (String) keyIt.next();
95
	    String value = (String) valueIt.next();
92
		    String value = (String) valueIt.next();
96
	    if (value.equals(_oldNamespace))
93
		    if (value.equals(_oldNamespace))
97
		nsMap.put(key, _newNamespace);
94
			nsMap.put(key, _newNamespace);
98
	}
95
		}
99
    }
96
    }
100
97
101
    /**
98
    /**
Lines 103-243 Link Here
103
     */
100
     */
104
    public void execute()
101
    public void execute()
105
    {
102
    {
106
	changeAllOldNSInSchemas();
103
		changeAllOldNSInSchemas();
107
	changeAllOldNSInDef();
104
		changeAllOldNSInDef();
108
	changeAllMessagesQName();
105
		changeAllMessagesQName();
109
	changeAllOldNSInMetadata();
106
		changeAllOldNSInMetadata();
110
	changePropNS();
107
		changePropNS();
111
108
	
112
	_capabilityDomain.getCapability().setNamespace(_newNamespace);
109
		_capabilityDomain.getCapability().setNamespace(_newNamespace);
113
	Definition definition = _capabilityDomain.getDefinition();
110
		Definition definition = _capabilityDomain.getCapability().getDefinition();
114
	String name = definition.getQName().getLocalPart();
111
		String name = definition.getQName().getLocalPart();
115
	definition.setQName(new javax.xml.namespace.QName(_newNamespace, name));
112
		definition.setQName(new javax.xml.namespace.QName(_newNamespace, name));
116
	definition.setTargetNamespace(_newNamespace);	
113
		definition.setTargetNamespace(_newNamespace);	
117
    }
114
    }
118
115
119
    private void changePropNS()
116
    private void changePropNS()
120
    {
117
    {
121
	List propSchemas = _capabilityDomain.getPropertiesSchemas();
118
		List propSchemas = _capabilityDomain.getPropertiesSchemas();
122
	if(propSchemas == null)
119
		if(propSchemas == null)
123
	    return;
120
		    return;
124
	for(int i=0;i<propSchemas.size();i++)
121
		for(int i=0;i<propSchemas.size();i++)
125
	{
122
		{
126
	    XSDSchema propSchema = (XSDSchema) propSchemas.get(i);
123
		    XSDSchema propSchema = (XSDSchema) propSchemas.get(i);
127
	    changeNS(propSchema);
124
		    changeNS(propSchema);
128
	}
125
		}
129
    }
126
    }
130
127
131
    private void changeAllOldNSInDef()
128
    private void changeAllOldNSInDef()
132
    {
129
    {
133
	Definition definition = _capabilityDomain.getDefinition();
130
		Definition definition = _capabilityDomain.getCapability().getDefinition();
134
	
131
		
135
	// Change the definition element
132
		// Change the definition element
136
	NamedNodeMap map = definition.getElement().getAttributes();
133
		NamedNodeMap map = definition.getElement().getAttributes();
137
	for (int i = 0; i < map.getLength(); i++)
134
		for (int i = 0; i < map.getLength(); i++)
138
	{
135
		{
139
	    if (map.item(i) instanceof Attr)
136
		    if (map.item(i) instanceof Attr)
140
	    {
137
		    {
141
		Attr attribute = (Attr) map.item(i);
138
				Attr attribute = (Attr) map.item(i);
142
		if (attribute.getNodeValue().equals(_oldNamespace))
139
				if (attribute.getNodeValue().equals(_oldNamespace))
143
		    attribute.setNodeValue(_newNamespace);
140
				    attribute.setNodeValue(_newNamespace);
144
	    }
141
		    }
145
	}
142
		}
146
	
143
		
147
	// Change the definition namespace map
144
		// Change the definition namespace map
148
	Map nsMap = definition.getNamespaces();
145
		Map nsMap = definition.getNamespaces();
149
	Iterator keyIt = nsMap.keySet().iterator();
146
		Iterator keyIt = nsMap.keySet().iterator();
150
	while(keyIt.hasNext())
147
		while(keyIt.hasNext())
151
	{
148
		{
152
	    Object key = keyIt.next();
149
		    Object key = keyIt.next();
153
	    String namespace = (String) nsMap.get(key);
150
		    String namespace = (String) nsMap.get(key);
154
	    if(namespace.equals(_oldNamespace))
151
		    if(namespace.equals(_oldNamespace))
155
		nsMap.put(key, _newNamespace);
152
			nsMap.put(key, _newNamespace);
156
	}
153
		}
157
    }
154
    }
158
155
159
    private void changeAllOldNSInMetadata()
156
    private void changeAllOldNSInMetadata()
160
    {
157
    {
161
	PropertyMetaDataDescriptor metaDataDescriptor = _capabilityDomain.getMetaDataDescriptor();
158
		MetadataDescriptor metaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
162
	if (metaDataDescriptor == null)
159
		if (metaDataDescriptor == null)
163
	    return;
160
		    return;
164
161
	
165
	changeInAllNamespaces();
162
		changeInAllNamespaces();
166
	changeInAllProperties();
163
		
164
		String capabilityFileName = _capabilityDomain.getCapabilityIFile().getName();
165
		metaDataDescriptor.getMetadataDescriptorType().setWsdlLocation(_newNamespace+" "+capabilityFileName);
167
    }
166
    }
168
167
169
    private void changeInAllNamespaces()
168
    private void changeInAllNamespaces()
170
    {
169
    {
171
	PropertyMetaDataDescriptor metaDataDescriptor = _capabilityDomain.getMetaDataDescriptor();
170
	    MetadataDescriptor metaDataDescriptor = _capabilityDomain.getCapability().getMetadata();
172
	if (metaDataDescriptor.getDocumentRoot().getDefinitions().getTargetNamespace().equals(_oldNamespace))
171
		if (metaDataDescriptor.getDocumentRoot().getDefinitions().getTargetNamespace().equals(_oldNamespace))
173
	    metaDataDescriptor.getDocumentRoot().getDefinitions().setTargetNamespace(_newNamespace);
172
		    metaDataDescriptor.getDocumentRoot().getDefinitions().setTargetNamespace(_newNamespace);
174
173
	
175
	EMap map = metaDataDescriptor.getDocumentRoot().getXMLNSPrefixMap();
174
		EMap map = metaDataDescriptor.getDocumentRoot().getXMLNSPrefixMap();
176
	Iterator keyIt = map.iterator();
175
		Iterator keyIt = map.iterator();
177
	while (keyIt.hasNext())
176
		while (keyIt.hasNext())
178
	{
177
		{
179
	    Object object = keyIt.next();
178
		    Object object = keyIt.next();
180
	    if (object instanceof EStringToStringMapEntryImpl)
179
		    if (object instanceof EStringToStringMapEntryImpl)
181
	    {
180
		    {
182
		EStringToStringMapEntryImpl entry = (EStringToStringMapEntryImpl) object;
181
				EStringToStringMapEntryImpl entry = (EStringToStringMapEntryImpl) object;
183
		if (entry.getValue().equals(_oldNamespace))
182
				if (entry.getValue().equals(_oldNamespace))
184
		    entry.setValue(_newNamespace);
183
				    entry.setValue(_newNamespace);
185
	    }
184
		    }
186
	}
185
		}
187
    }
188
189
    private void changeInAllProperties()
190
    {
191
	PropertyMetaDataDescriptor metaDataDescriptor = _capabilityDomain.getMetaDataDescriptor();
192
	String prefix = metaDataDescriptor.getPrefix(_newNamespace);
193
	List properties = _capabilityDomain.getCapability().getProperties();
194
	for (int i = 0; i < properties.size(); i++)
195
	{
196
	    Property property = (Property) properties.get(i);
197
	    PropertyType metadata = property.getMetaData();
198
	    if(metadata != null)
199
	    {
200
		QName qname = (QName) metadata.getName();
201
		if(qname.getNamespaceURI().equals(_oldNamespace))
202
		{
203
		    qname.setNamespaceURI(_newNamespace);
204
		    qname.setPrefix(prefix);
205
		}		
206
	    }
207
	}
208
    }
186
    }
209
    
187
    
210
    private void changeAllMessagesQName()
188
    private void changeAllMessagesQName()
211
    {
189
    {
212
	Definition definition = _capabilityDomain.getDefinition();
190
		Definition definition = _capabilityDomain.getCapability().getDefinition();
213
	List messages = definition.getEMessages();
191
		List messages = definition.getEMessages();
214
	if(messages == null)
192
		if(messages == null)
215
	    return;
193
		    return;
216
	for(int i=0;i<messages.size();i++)
194
		for(int i=0;i<messages.size();i++)
217
	{
195
		{
218
	    Message message = (Message) messages.get(i);
196
		    Message message = (Message) messages.get(i);
219
	    if(!message.getEnclosingDefinition().equals(definition))
197
		    if(!message.getEnclosingDefinition().equals(definition))
220
		continue;
198
		    	continue;
221
	    String localName = message.getQName().getLocalPart();
199
		    String localName = message.getQName().getLocalPart();
222
	    message.setQName(new javax.xml.namespace.QName(_newNamespace, localName));
200
		    message.setQName(new javax.xml.namespace.QName(_newNamespace, localName));
223
	    changePartsQName(message.getEParts());
201
		    changePartsQName(message.getEParts());
224
	}
202
		}
225
    }
203
    }
226
    
204
    
227
    private void changePartsQName(List parts)
205
    private void changePartsQName(List parts)
228
    {
206
    {
229
	if(parts == null)
207
		if(parts == null)
230
	    return;
208
		    return;
231
	for(int i=0;i<parts.size();i++)
209
		for(int i=0;i<parts.size();i++)
232
	{
210
		{
233
	    Part part = (Part) parts.get(i);
211
		    Part part = (Part) parts.get(i);
234
	    if(part.getElementDeclaration()!=null)
212
		    if(part.getElementDeclaration()!=null)
235
		part.setElementName(new javax.xml.namespace.QName(part.getElementDeclaration().getTargetNamespace(),
213
		    	part.setElementName(new javax.xml.namespace.QName(part.getElementDeclaration().getTargetNamespace(),
236
			part.getElementDeclaration().getName()));
214
				part.getElementDeclaration().getName()));
237
	    if(part.getTypeDefinition()!=null)
215
		    if(part.getTypeDefinition()!=null)
238
		part.setTypeName(new javax.xml.namespace.QName(part.getTypeDefinition().getTargetNamespace(),
216
		    	part.setTypeName(new javax.xml.namespace.QName(part.getTypeDefinition().getTargetNamespace(),
239
			part.getTypeDefinition().getName()));
217
				part.getTypeDefinition().getName()));
240
	}
218
		}
241
    }
219
    }
242
    
220
    
243
}
221
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/topic/internal/NewRootTopicDialog.java (-106 / +106 lines)
Lines 21-145 Link Here
21
import org.eclipse.swt.widgets.Label;
21
import org.eclipse.swt.widgets.Label;
22
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.widgets.Text;
23
import org.eclipse.swt.widgets.Text;
24
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
24
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
25
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
25
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.topic.internal.Messages;
26
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.topic.internal.Messages;
26
import org.eclipse.tptp.wsdm.tooling.util.internal.TopicUtils;
27
27
28
/**
28
/**
29
 * 
29
 * 
30
 * Popup dialog to create new root topic.
30
 * Popup dialog to create new root topic.
31
 *
31
 * 
32
 */
32
 */
33
33
34
public class NewRootTopicDialog extends Dialog
34
public class NewRootTopicDialog extends Dialog
35
{
35
{
36
36
37
    private final String _title;
37
	private final String _title;
38
38
39
    private Text _topicSpaceText;
39
	private Text _topicSpaceText;
40
40
41
    private Text _rootTopicNameText;
41
	private Text _rootTopicNameText;
42
42
43
    private String _topicNamespace;
43
	private String _topicNamespace;
44
44
45
    private Topic _rootTopic;
45
	private Topic _rootTopic;
46
46
47
    /**
47
	/**
48
     * Create a new dialog for root topic.
48
	 * Create a new dialog for root topic.
49
     * 
49
	 * 
50
     * @param parentShell
50
	 * @param parentShell
51
     *        Shell.
51
	 *            Shell.
52
     *        
52
	 * 
53
     * @param dialogTitle
53
	 * @param dialogTitle
54
     *        Title of this dialog.
54
	 *            Title of this dialog.
55
     *        
55
	 * 
56
     * @param topicNamespace
56
	 * @param topicNamespace
57
     *        TopicNamespace to which this root topic will be added.
57
	 *            TopicNamespace to which this root topic will be added.
58
     */
58
	 */
59
    protected NewRootTopicDialog(Shell parentShell, String dialogTitle,
59
	protected NewRootTopicDialog(Shell parentShell, String dialogTitle,
60
	    String topicNamespace)
60
			String topicNamespace)
61
    {
61
	{
62
	super(parentShell);
62
		super(parentShell);
63
	_title = dialogTitle;
63
		_title = dialogTitle;
64
	_topicNamespace = topicNamespace;
64
		_topicNamespace = topicNamespace;
65
    }
65
	}
66
66
67
    protected void configureShell(Shell shell)
67
	protected void configureShell(Shell shell)
68
    {
68
	{
69
	super.configureShell(shell);
69
		super.configureShell(shell);
70
	if (_title != null)
70
		if (_title != null)
71
	    shell.setText(_title);
71
			shell.setText(_title);
72
    }
72
	}
73
73
74
    protected Control createDialogArea(Composite parent)
74
	protected Control createDialogArea(Composite parent)
75
    {
75
	{
76
	Composite composite = (Composite) super.createDialogArea(parent);
76
		Composite composite = (Composite) super.createDialogArea(parent);
77
77
78
	GridLayout layout = new GridLayout(2, true);
78
		GridLayout layout = new GridLayout(2, true);
79
	composite.setLayout(layout);
79
		composite.setLayout(layout);
80
80
81
	Label topicSpaceLabel = new Label(composite, SWT.NONE);
81
		Label topicSpaceLabel = new Label(composite, SWT.NONE);
82
	topicSpaceLabel.setText(Messages.TOPIC_NAMESPACE);
82
		topicSpaceLabel.setText(Messages.TOPIC_NAMESPACE);
83
83
84
	_topicSpaceText = new Text(composite, SWT.SINGLE | SWT.BORDER);
84
		_topicSpaceText = new Text(composite, SWT.SINGLE | SWT.BORDER);
85
	_topicSpaceText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
85
		_topicSpaceText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
86
		| GridData.HORIZONTAL_ALIGN_FILL));
86
				| GridData.HORIZONTAL_ALIGN_FILL));
87
87
88
	Label rootTopicNameLabel = new Label(composite, SWT.NONE);
88
		Label rootTopicNameLabel = new Label(composite, SWT.NONE);
89
	rootTopicNameLabel.setText(Messages.ROOT_TOPIC_NAME);
89
		rootTopicNameLabel.setText(Messages.ROOT_TOPIC_NAME);
90
90
91
	_rootTopicNameText = new Text(composite, SWT.SINGLE | SWT.BORDER);
91
		_rootTopicNameText = new Text(composite, SWT.SINGLE | SWT.BORDER);
92
	_rootTopicNameText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
92
		_rootTopicNameText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
93
		| GridData.HORIZONTAL_ALIGN_FILL));
93
				| GridData.HORIZONTAL_ALIGN_FILL));
94
94
95
	initializeControls();
95
		initializeControls();
96
	hookAllListeners();
96
		hookAllListeners();
97
97
98
	applyDialogFont(composite);
98
		applyDialogFont(composite);
99
99
100
	return composite;
100
		return composite;
101
    }
101
	}
102
102
103
    protected Control createButtonBar(Composite parent)
103
	protected Control createButtonBar(Composite parent)
104
    {
104
	{
105
	Control ret = super.createButtonBar(parent);
105
		Control ret = super.createButtonBar(parent);
106
	return ret;
106
		return ret;
107
    }
107
	}
108
108
109
    private void initializeControls()
109
	private void initializeControls()
110
    {
110
	{
111
	_topicSpaceText.setText(_topicNamespace);
111
		_topicSpaceText.setText(_topicNamespace);
112
	_rootTopicNameText.setText("RootTopic");
112
		_rootTopicNameText.setText("RootTopic");
113
    }
113
	}
114
114
115
    private void hookAllListeners()
115
	private void hookAllListeners()
116
    {
116
	{
117
117
118
    }
118
	}
119
119
120
    protected void okPressed()
120
	protected void okPressed()
121
    {
121
	{
122
	_rootTopic = TopicUtils.createNewTopic();
122
		_rootTopic = CapabilitiesFactory.eINSTANCE.createTopic();
123
	_rootTopic.setName(_rootTopicNameText.getText());
123
		_rootTopic.setName(_rootTopicNameText.getText());
124
	_topicNamespace = _topicSpaceText.getText();
124
		_topicNamespace = _topicSpaceText.getText();
125
	super.okPressed();
125
		super.okPressed();
126
    }
126
	}
127
127
128
    /**
128
	/**
129
     * 
129
	 * 
130
     * @return New root topic.
130
	 * @return New root topic.
131
     */
131
	 */
132
    public Topic getRootTopic()
132
	public Topic getRootTopic()
133
    {
133
	{
134
	return _rootTopic;
134
		return _rootTopic;
135
    }
135
	}
136
136
137
    /**
137
	/**
138
     * 
138
	 * 
139
     * @return Topic namespace.
139
	 * @return Topic namespace.
140
     */
140
	 */
141
    public String getTopicNamespace()
141
	public String getTopicNamespace()
142
    {
142
	{
143
	return _topicNamespace;
143
		return _topicNamespace;
144
    }
144
	}
145
}
145
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/topic/internal/ListSection.java (-369 / +379 lines)
Lines 48-59 Link Here
48
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractPageSection;
48
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractPageSection;
49
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IPageSection;
49
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IPageSection;
50
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
50
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.IUIPage;
51
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
51
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
52
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
52
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
53
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
53
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
54
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
54
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.topic.internal.Messages;
55
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.topic.internal.Messages;
55
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
56
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
56
import org.eclipse.tptp.wsdm.tooling.util.internal.TopicUtils;
57
import org.eclipse.tptp.wsdm.tooling.viewers.internal.IViewerClient;
57
import org.eclipse.tptp.wsdm.tooling.viewers.internal.IViewerClient;
58
import org.eclipse.tptp.wsdm.tooling.viewers.internal.StructuredTreeViewer;
58
import org.eclipse.tptp.wsdm.tooling.viewers.internal.StructuredTreeViewer;
59
import org.eclipse.ui.forms.widgets.FormToolkit;
59
import org.eclipse.ui.forms.widgets.FormToolkit;
Lines 70-461 Link Here
70
public class ListSection extends AbstractPageSection implements IViewerClient
70
public class ListSection extends AbstractPageSection implements IViewerClient
71
{
71
{
72
72
73
    private StructuredTreeViewer _topicViewer;
73
	private StructuredTreeViewer _topicViewer;
74
74
75
    private Button _newRootTopicButton;
75
	private Button _newRootTopicButton;
76
76
77
    private Button _newChildTopicButton;
77
	private Button _newChildTopicButton;
78
78
79
    private Button _removeButton;
79
	private Button _removeButton;
80
80
81
    private Label _errorLabel;
81
	private Label _errorLabel;
82
82
83
    private TopicContentProvider _contentProvider;
83
	private TopicContentProvider _contentProvider;
84
84
85
    private Topic _selectedTopic;
85
	private Topic _selectedTopic;
86
86
87
    private TopicSpace _selectedTopicSpace;
87
	private TopicSpace _selectedTopicSpace;
88
    
88
89
    private Composite _sectionClient;
89
	private Composite _sectionClient;
90
    
90
91
    private Composite _buttonClient;
91
	private Composite _buttonClient;
92
92
93
    /**
93
	/**
94
     * Creates a new object of this class. 
94
	 * Creates a new object of this class.
95
     */
95
	 */
96
    ListSection(CapabilityEditor editor, IUIPage page, ScrolledForm form,
96
	ListSection(CapabilityEditor editor, IUIPage page, ScrolledForm form,
97
	    FormToolkit toolkit)
97
			FormToolkit toolkit)
98
    {
98
	{
99
	super(editor, page, form, toolkit);
99
		super(editor, page, form, toolkit);
100
    }
100
	}
101
101
102
    /**
102
	/**
103
     * Creates the section.
103
	 * Creates the section.
104
     */
104
	 */
105
    public void create()
105
	public void create()
106
    {
106
	{
107
    _sectionClient = createSection(Messages.MNGMNT_EVENTS,
107
		_sectionClient = createSection(Messages.MNGMNT_EVENTS,
108
		Messages.MNSMNT_EVENTS_OF_CAP);
108
				Messages.MNSMNT_EVENTS_OF_CAP);
109
	GridLayout layout = new GridLayout(2, false);
109
		GridLayout layout = new GridLayout(2, false);
110
	layout.marginWidth = LAYOUT_MARGIN_WIDTH;
110
		layout.marginWidth = LAYOUT_MARGIN_WIDTH;
111
	layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
111
		layout.verticalSpacing = LAYOUT_VERTICAL_SPACING;
112
	_sectionClient.setLayout(layout);
112
		_sectionClient.setLayout(layout);
113
	FormToolkit toolkit = getToolkit();
113
		FormToolkit toolkit = getToolkit();
114
114
115
	_topicViewer = new StructuredTreeViewer(_sectionClient, toolkit,
115
		_topicViewer = new StructuredTreeViewer(_sectionClient, toolkit,
116
		SWT.SINGLE, this);
116
				SWT.SINGLE, this);
117
	GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
117
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
118
	gd.heightHint = 300;
118
		gd.heightHint = 300;
119
	gd.widthHint = 50;
119
		gd.widthHint = 50;
120
	_topicViewer.getControl().setLayoutData(gd);
120
		_topicViewer.getControl().setLayoutData(gd);
121
	_topicViewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
121
		_topicViewer.getControl().setData(FormToolkit.KEY_DRAW_BORDER,
122
			FormToolkit.TREE_BORDER);
122
				FormToolkit.TREE_BORDER);
123
123
124
	// Set up a label provider that knows about the capability (so can
124
		// Set up a label provider that knows about the capability (so can
125
	// extract SemanticDecorations from it)
125
		// extract SemanticDecorations from it)
126
	_contentProvider = new TopicContentProvider();
126
		_contentProvider = new TopicContentProvider();
127
	_topicViewer.setContentProvider(_contentProvider);
127
		_topicViewer.setContentProvider(_contentProvider);
128
	_topicViewer.setLabelProvider(_contentProvider
128
		_topicViewer.setLabelProvider(_contentProvider
129
		.createLabelProvider(getForm().getShell()));
129
				.createLabelProvider(getForm().getShell()));
130
	_topicViewer.getControl().setSize(_topicViewer.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT));
130
		_topicViewer.getControl()
131
131
				.setSize(
132
	_buttonClient = toolkit.createComposite(_sectionClient);
132
						_topicViewer.getControl().computeSize(SWT.DEFAULT,
133
	layout = new GridLayout();
133
								SWT.DEFAULT));
134
	layout.marginHeight = 0;
134
135
	_buttonClient.setLayout(layout);
135
		_buttonClient = toolkit.createComposite(_sectionClient);
136
	gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_FILL, false, false);
136
		layout = new GridLayout();
137
	_buttonClient.setLayoutData(gd);
137
		layout.marginHeight = 0;
138
	
138
		_buttonClient.setLayout(layout);
139
	_newRootTopicButton = createPushButton(_buttonClient, toolkit,
139
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING,
140
		Messages.ADD_ROOT_TOPIC, new Listener()
140
				GridData.VERTICAL_ALIGN_FILL, false, false);
141
		{
141
		_buttonClient.setLayoutData(gd);
142
		    public void handleEvent(Event event)
142
143
		    {
143
		_newRootTopicButton = createPushButton(_buttonClient, toolkit,
144
			addRootTopic();
144
				Messages.ADD_ROOT_TOPIC, new Listener() {
145
		    }
145
					public void handleEvent(Event event)
146
		});
146
					{
147
	gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
147
						addRootTopic();
148
	_newRootTopicButton.setLayoutData(gd);
148
					}
149
	gd.widthHint = 85;
149
				});
150
	_newRootTopicButton.setEnabled(!_editor.isReadOnly());
150
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
151
151
		_newRootTopicButton.setLayoutData(gd);
152
	_newChildTopicButton = createPushButton(_buttonClient, toolkit,
152
		gd.widthHint = 85;
153
		Messages.ADD_CHILD_TOPIC, new Listener()
153
		_newRootTopicButton.setEnabled(!_editor.isReadOnly());
154
		{
154
155
		    public void handleEvent(Event event)
155
		_newChildTopicButton = createPushButton(_buttonClient, toolkit,
156
		    {
156
				Messages.ADD_CHILD_TOPIC, new Listener() {
157
			addChildTopic();
157
					public void handleEvent(Event event)
158
		    }
158
					{
159
		});
159
						addChildTopic();
160
	gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
160
					}
161
	gd.widthHint = 85;
161
				});
162
	_newChildTopicButton.setLayoutData(gd);
162
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
163
163
		gd.widthHint = 85;
164
	_removeButton = createPushButton(_buttonClient, toolkit, org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL,
164
		_newChildTopicButton.setLayoutData(gd);
165
		new Listener()
165
166
		{
166
		_removeButton = createPushButton(
167
		    public void handleEvent(Event event)
167
				_buttonClient,
168
		    {
168
				toolkit,
169
			remove();
169
				org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages.REMOVE_BUTTON_LABEL,
170
		    }
170
				new Listener() {
171
					public void handleEvent(Event event)
172
					{
173
						remove();
174
					}
175
				});
176
		gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
177
		gd.widthHint = 85;
178
		_removeButton.setLayoutData(gd);
179
180
		_errorLabel = toolkit.createLabel(_sectionClient, "");
181
		gd = new GridData(GridData.FILL_HORIZONTAL);
182
		gd.horizontalSpan = 2;
183
		gd.grabExcessHorizontalSpace = true;
184
		_errorLabel.setLayoutData(gd);
185
	}
186
187
	private void addRootTopic()
188
	{
189
		String topicNamespace = null;
190
		Capability capability = _editor.getCapabilityDomain().getCapability();
191
		if (_selectedTopicSpace == null)
192
		{
193
			topicNamespace = capability.getNamespace() + "/Topics";
194
			if (capability.getNamespace().endsWith("/"))
195
				topicNamespace = capability.getNamespace() + "Topics";
196
		}
197
		else
198
		{
199
			topicNamespace = _selectedTopicSpace.getNamespace();
200
		}
201
		NewRootTopicDialog dlg = new NewRootTopicDialog(getForm().getShell(),
202
				Messages.NEW_ROOT_TOPIC, topicNamespace);
203
		int choice = dlg.open();
204
		if (choice == Window.OK)
205
		{
206
			Topic rootTopic = dlg.getRootTopic();
207
			String newTopicNamespace = dlg.getTopicNamespace();
208
			AddRootTopicCommand command = new AddRootTopicCommand(_editor
209
					.getCapabilityDomain(), newTopicNamespace, rootTopic);
210
			command.execute();
211
			_page.setDirty();
212
		}
213
	}
214
215
	private void addChildTopic()
216
	{
217
		InputDialog dlg = new InputDialog(getForm().getShell(),
218
				Messages.NEW_CHILD_TOPIC, Messages.TOPIC_NAME,
219
				Messages.CHILD_TOPIC_LABEL, null);
220
		int choice = dlg.open();
221
		if (choice == Window.OK)
222
		{
223
			Topic childTopic = CapabilitiesFactory.eINSTANCE.createTopic();
224
			childTopic.setName(dlg.getValue());
225
			AddChildTopicCommand command = new AddChildTopicCommand(
226
					_selectedTopic, childTopic);
227
			command.execute();
228
			_page.setDirty();
229
		}
230
	}
231
232
	private void remove()
233
	{
234
		if (_selectedTopic != null)
235
		{
236
			RemoveTopicCommand command = new RemoveTopicCommand(
237
					_selectedTopicSpace, _selectedTopic);
238
			command.execute();
239
		}
240
		else
241
		{
242
			RemoveTopicNamespaceCommand command = new RemoveTopicNamespaceCommand(
243
					_editor.getCapabilityDomain(), _selectedTopicSpace);
244
			command.execute();
245
		}
246
		_page.setDirty();
247
	}
248
249
	/**
250
	 * Refreshes the section.
251
	 */
252
	public void refresh()
253
	{
254
		Capability model = _editor.getCapabilityDomain().getCapability();
255
		EList topicSpaceList = model.getTopicSpaces();
256
		_newChildTopicButton.setEnabled(false);
257
		_removeButton.setEnabled(false);
258
		if (topicSpaceList == null || topicSpaceList.size() == 0)
259
		{
260
			_topicViewer.setInput(null);
261
			_page.enableSections(false);
262
			return;
263
		}
264
		_topicViewer.setInput(topicSpaceList);
265
	}
266
267
	public void handleDoubleClick()
268
	{
269
		// TODO Auto-generated method stub
270
	}
271
272
	public void handleSelectionChanged(SelectionChangedEvent event)
273
	{
274
		Object[] objects = _topicViewer.getSelectedObjets();
275
		if (objects != null && objects.length != 0)
276
		{
277
			if (objects[0] instanceof TopicSpace)
278
			{
279
				_selectedTopicSpace = (TopicSpace) objects[0];
280
				_selectedTopic = null;
281
			}
282
			if (objects[0] instanceof Topic)
283
			{
284
				_selectedTopic = (Topic) objects[0];
285
				_selectedTopicSpace = getTopicSpace(_selectedTopic);
286
			}
287
			List sections = _page.getSections();
288
			_page.enableSections(true);
289
			for (int i = 0; i < sections.size(); i++)
290
			{
291
				IPageSection section = (IPageSection) sections.get(i);
292
				section.setSelectedObject(_selectedTopic);
293
				section.selectionChanged(event);
294
			}
295
			return;
296
		}
297
	}
298
299
	/**
300
	 * Initializes control listeners.
301
	 */
302
	public void hookAllListeners()
303
	{
304
		getForm().addControlListener(new ControlAdapter() {
305
			public void controlResized(ControlEvent e)
306
			{
307
				Rectangle formBounds = getForm().getClientArea();
308
				Rectangle sectionClientBounds = _sectionClient.getClientArea();
309
				Rectangle buttonCompositeBounds = _buttonClient.getClientArea();
310
				int width = sectionClientBounds.width
311
						- buttonCompositeBounds.width - 20;
312
				int height = Math.min(formBounds.height,
313
						sectionClientBounds.height) - 100;
314
				Tree tree = (Tree) _topicViewer.getControl();
315
				tree.setSize(width, height);
316
			}
171
		});
317
		});
172
	gd = new GridData(GridData.CENTER, SWT.NONE, false, false);
318
	}
173
	gd.widthHint = 85;
319
174
	_removeButton.setLayoutData(gd);
320
	/**
175
321
	 * Handle viewer selection changed.
176
	_errorLabel = toolkit.createLabel(_sectionClient, "");
322
	 */
177
	gd = new GridData(GridData.FILL_HORIZONTAL);
323
	public void selectionChanged(SelectionChangedEvent event)
178
	gd.horizontalSpan = 2;
324
	{
179
	gd.grabExcessHorizontalSpace = true;
325
		_removeButton.setEnabled(!_editor.isReadOnly());
180
	_errorLabel.setLayoutData(gd);    
326
		Object selectedObject = _topicViewer.getSelectedObjets()[0];
181
    }
327
		_newRootTopicButton.setEnabled(selectedObject instanceof TopicSpace
182
328
				&& !_editor.isReadOnly());
183
    private void addRootTopic()
329
		_newChildTopicButton.setEnabled(selectedObject instanceof Topic
184
    {
330
				&& !_editor.isReadOnly());
185
	String topicNamespace = null;
331
	}
186
	Capability capability = _editor.getCapabilityDomain().getCapability();
332
187
	if (_selectedTopicSpace == null)
333
	/**
188
	{
334
	 * Update its selected object.
189
	    topicNamespace = capability.getNamespace() + "/Topics";
335
	 */
190
	    if (capability.getNamespace().endsWith("/"))
336
	public void setSelectedObject(Object object)
191
		topicNamespace = capability.getNamespace() + "Topics";
337
	{
192
	}
338
	}
193
	else
339
194
	{
340
	private TopicSpace getTopicSpace(Topic topic)
195
	    topicNamespace = _selectedTopicSpace.getNamespace();
341
	{
196
	}
342
		Object parent = _contentProvider.getParent(topic);
197
	NewRootTopicDialog dlg = new NewRootTopicDialog(getForm().getShell(),
343
		while (!(parent instanceof TopicSpace))
198
		Messages.NEW_ROOT_TOPIC, topicNamespace);
344
			parent = _contentProvider.getParent(parent);
199
	int choice = dlg.open();
345
		return (TopicSpace) parent;
200
	if (choice == Window.OK)
346
	}
201
	{
347
202
	    Topic rootTopic = dlg.getRootTopic();
348
	/**
203
	    String newTopicNamespace = dlg.getTopicNamespace();
349
	 * Enable or disable the section based on parameter passed.
204
	    AddRootTopicCommand command = new AddRootTopicCommand(_editor
350
	 */
205
		    .getCapabilityDomain(), newTopicNamespace, rootTopic);
351
	public void enable(boolean enabled)
206
	    command.execute();
352
	{
207
	    _page.setDirty();
353
		// TODO Auto-generated method stub
208
	}
354
	}
209
    }
210
211
    private void addChildTopic()
212
    {
213
	InputDialog dlg = new InputDialog(getForm().getShell(),
214
		Messages.NEW_CHILD_TOPIC, Messages.TOPIC_NAME, Messages.CHILD_TOPIC_LABEL, null);
215
	int choice = dlg.open();
216
	if (choice == Window.OK)
217
	{
218
	    Topic childTopic = TopicUtils.createNewTopic();
219
	    childTopic.setName(dlg.getValue());
220
	    AddChildTopicCommand command = new AddChildTopicCommand(
221
		    _selectedTopic, childTopic);
222
	    command.execute();
223
	    _page.setDirty();
224
	}
225
    }
226
227
    private void remove()
228
    {
229
	if (_selectedTopic != null)
230
	{
231
	    RemoveTopicCommand command = new RemoveTopicCommand(
232
		    _selectedTopicSpace, _selectedTopic);
233
	    command.execute();
234
	}
235
	else
236
	{
237
	    RemoveTopicNamespaceCommand command = new RemoveTopicNamespaceCommand(
238
		    _editor.getCapabilityDomain(), _selectedTopicSpace);
239
	    command.execute();
240
	}
241
	_page.setDirty();
242
    }
243
244
    /**
245
     * Refreshes the section.
246
     */
247
    public void refresh()
248
    {
249
	Capability model = _editor.getCapabilityDomain().getCapability();
250
	EList topicSpaceList = model.getTopicSpaces();
251
	_newChildTopicButton.setEnabled(false);
252
	_removeButton.setEnabled(false);
253
	if (topicSpaceList == null || topicSpaceList.size() == 0)
254
	{
255
	    _topicViewer.setInput(null);
256
	    _page.enableSections(false);
257
	    return;
258
	}
259
	_topicViewer.setInput(topicSpaceList);
260
    }
261
262
    public void handleDoubleClick()
263
    {
264
	// TODO Auto-generated method stub
265
    }
266
267
    public void handleSelectionChanged(SelectionChangedEvent event)
268
    {
269
	Object[] objects = _topicViewer.getSelectedObjets();
270
	if (objects != null && objects.length != 0)
271
	{
272
	    if (objects[0] instanceof TopicSpace)
273
	    {
274
		_selectedTopicSpace = (TopicSpace) objects[0];
275
		_selectedTopic = null;
276
	    }
277
	    if (objects[0] instanceof Topic)
278
	    {
279
		_selectedTopic = (Topic) objects[0];
280
		_selectedTopicSpace = getTopicSpace(_selectedTopic);
281
	    }
282
	    List sections = _page.getSections();
283
	    _page.enableSections(true);
284
	    for (int i = 0; i < sections.size(); i++)
285
	    {
286
		IPageSection section = (IPageSection) sections.get(i);
287
		section.setSelectedObject(_selectedTopic);
288
		section.selectionChanged(event);
289
	    }
290
	    return;
291
	}	
292
    }
293
294
    /**
295
     * Initializes control listeners.
296
     */
297
    public void hookAllListeners()
298
    {
299
    	getForm().addControlListener(new ControlAdapter() {
300
    	    public void controlResized(ControlEvent e) {
301
    	    	Rectangle formBounds = getForm().getClientArea();
302
    	        Rectangle sectionClientBounds = _sectionClient.getClientArea();
303
    	        Rectangle buttonCompositeBounds = _buttonClient.getClientArea();
304
    	        int width = sectionClientBounds.width-buttonCompositeBounds.width-20;
305
    	        int height = Math.min(formBounds.height, sectionClientBounds.height)-100;
306
    	        Tree tree = (Tree) _topicViewer.getControl();
307
    	        tree.setSize(width,height);    	        
308
    	    }
309
    	});
310
    }
311
312
    /**
313
     * Handle viewer selection changed.
314
     */
315
    public void selectionChanged(SelectionChangedEvent event)
316
    {
317
	_removeButton.setEnabled(!_editor.isReadOnly());
318
	Object selectedObject = _topicViewer.getSelectedObjets()[0];
319
	_newRootTopicButton.setEnabled(selectedObject instanceof TopicSpace && !_editor.isReadOnly());
320
	_newChildTopicButton.setEnabled(selectedObject instanceof Topic && !_editor.isReadOnly());
321
    }
322
323
    /**
324
     * Update its selected object.
325
     */
326
    public void setSelectedObject(Object object)
327
    {
328
    }
329
330
    private TopicSpace getTopicSpace(Topic topic)
331
    {
332
	Object parent = _contentProvider.getParent(topic);
333
	while (!(parent instanceof TopicSpace))
334
	    parent = _contentProvider.getParent(parent);
335
	return (TopicSpace) parent;
336
    }
337
338
    /**
339
     * Enable or disable the section based on parameter passed.
340
     */
341
    public void enable(boolean enabled)
342
    {
343
	// TODO Auto-generated method stub
344
    }
345
355
346
}
356
}
347
357
348
class TopicContentProvider implements ITreeContentProvider
358
class TopicContentProvider implements ITreeContentProvider
349
{
359
{
350
360
351
    private final Map _parentMap;
361
	private final Map _parentMap;
352
362
353
    TopicContentProvider()
363
	TopicContentProvider()
354
    {
364
	{
355
	_parentMap = new HashMap();
365
		_parentMap = new HashMap();
356
    }
366
	}
357
367
358
    public Object[] getChildren(Object parentElement)
368
	public Object[] getChildren(Object parentElement)
359
    {
369
	{
360
	if (parentElement instanceof Collection)
370
		if (parentElement instanceof Collection)
361
	{
371
		{
362
	    Collection c = (Collection) parentElement;
372
			Collection c = (Collection) parentElement;
363
	    return c.toArray();
373
			return c.toArray();
364
	}
374
		}
365
	else if (parentElement instanceof TopicSpace)
375
		else if (parentElement instanceof TopicSpace)
366
	{
376
		{
367
	    TopicSpace topicSpace = (TopicSpace) parentElement;
377
			TopicSpace topicSpace = (TopicSpace) parentElement;
368
	    Object[] rootTopics = topicSpace.getRootTopics().toArray();
378
			Object[] rootTopics = topicSpace.getRootTopics().toArray();
369
	    remember(parentElement, rootTopics);
379
			remember(parentElement, rootTopics);
370
	    return rootTopics;
380
			return rootTopics;
371
	}
381
		}
372
	else if (parentElement instanceof Topic)
382
		else if (parentElement instanceof Topic)
373
	{
383
		{
374
	    Topic topic = (Topic) parentElement;
384
			Topic topic = (Topic) parentElement;
375
	    Object[] childrens = topic.getChildren().toArray();
385
			Object[] childrens = topic.getChildren().toArray();
376
	    remember(parentElement, childrens);
386
			remember(parentElement, childrens);
377
	    return childrens;
387
			return childrens;
378
	}
388
		}
379
	return new Object[0];
389
		return new Object[0];
380
    }
390
	}
381
391
382
    public Object getParent(Object element)
392
	public Object getParent(Object element)
383
    {
393
	{
384
	return _parentMap.get(element);
394
		return _parentMap.get(element);
385
    }
395
	}
386
396
387
    public boolean hasChildren(Object element)
397
	public boolean hasChildren(Object element)
388
    {
398
	{
389
	return (getChildren(element).length > 0);
399
		return (getChildren(element).length > 0);
390
    }
400
	}
391
401
392
    public Object[] getElements(Object inputElement)
402
	public Object[] getElements(Object inputElement)
393
    {
403
	{
394
	return getChildren(inputElement);
404
		return getChildren(inputElement);
395
    }
405
	}
396
406
397
    public void dispose()
407
	public void dispose()
398
    {
408
	{
399
	// TODO Auto-generated method stub
409
		// TODO Auto-generated method stub
400
    }
410
	}
401
411
402
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
412
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
403
    {
413
	{
404
	// TODO Auto-generated method stub
414
		// TODO Auto-generated method stub
405
    }
415
	}
406
416
407
    private void remember(Object parent, Object[] childs)
417
	private void remember(Object parent, Object[] childs)
408
    {
418
	{
409
	for (int i = 0; i < childs.length; i++)
419
		for (int i = 0; i < childs.length; i++)
410
	{
420
		{
411
	    _parentMap.put(childs[i], parent);
421
			_parentMap.put(childs[i], parent);
412
	}
422
		}
413
    }
423
	}
414
424
415
    public ILabelProvider createLabelProvider(Shell shell)
425
	public ILabelProvider createLabelProvider(Shell shell)
416
    {
426
	{
417
	return new TopicLabelProvider(shell);
427
		return new TopicLabelProvider(shell);
418
    }
428
	}
419
429
420
}
430
}
421
431
422
class TopicLabelProvider extends LabelProvider implements ILabelProvider
432
class TopicLabelProvider extends LabelProvider implements ILabelProvider
423
{
433
{
424
434
425
    private final static String TOPIC_KEY = "Topic";
435
	private final static String TOPIC_KEY = "Topic";
436
437
	private ImageRegistry _imageRegistry;
438
439
	public TopicLabelProvider(Shell shell)
440
	{
441
		// We ignore the shell. It's here in the constructor in case we
442
		// decide to use graphical icons on the tree later.
426
443
427
    private ImageRegistry _imageRegistry;
444
		_imageRegistry = new ImageRegistry(shell.getDisplay());
445
		Image imgProp = EclipseUtils.loadImage(shell.getDisplay(),
446
				"icons/obj16/rootTopic_obj.gif");
447
		_imageRegistry.put(TOPIC_KEY, imgProp);
448
	}
428
449
429
    public TopicLabelProvider(Shell shell)
450
	public String getText(Object element)
430
    {
451
	{
431
	// We ignore the shell. It's here in the constructor in case we
452
		if (element instanceof TopicSpace)
432
	// decide to use graphical icons on the tree later.
453
		{
433
454
			TopicSpace topicSpace = (TopicSpace) element;
434
	_imageRegistry = new ImageRegistry(shell.getDisplay());
455
			return topicSpace.getNamespace();
435
	Image imgProp = EclipseUtils.loadImage(shell.getDisplay(),
456
		}
436
		"icons/obj16/rootTopic_obj.gif");
457
		else if (element instanceof Topic)
437
	_imageRegistry.put(TOPIC_KEY, imgProp);
458
		{
438
    }
459
			Topic topic = (Topic) element;
439
460
			return topic.getName();
440
    public String getText(Object element)
461
		}
441
    {
462
		return "";
442
	if (element instanceof TopicSpace)
463
	}
443
	{
464
444
	    TopicSpace topicSpace = (TopicSpace) element;
465
	public Image getImage(Object element)
445
	    return topicSpace.getNamespace();
466
	{
446
	}
467
		if (element instanceof Topic)
447
	else if (element instanceof Topic)
468
			return _imageRegistry.get(TOPIC_KEY);
448
	{
469
		return null;
449
	    Topic topic = (Topic) element;
470
	}
450
	    return topic.getName();
451
	}
452
	return "";
453
    }
454
455
    public Image getImage(Object element)
456
    {
457
	if (element instanceof Topic)
458
	    return _imageRegistry.get(TOPIC_KEY);
459
	return null;
460
    }
461
}
471
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/source/internal/XsdSourcePage.java (-76 / +77 lines)
Lines 12-111 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.pages.source.internal;
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.pages.source.internal;
14
14
15
import org.apache.muse.util.xml.XmlUtils;
16
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.Text;
18
import org.eclipse.swt.widgets.Text;
20
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
19
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
21
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractSourcePage;
20
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractSourcePage;
21
import org.eclipse.tptp.wsdm.tooling.util.internal.CapUtils;
22
import org.eclipse.xsd.XSDSchema;
22
import org.eclipse.xsd.XSDSchema;
23
import org.w3c.dom.Document;
23
import org.w3c.dom.Document;
24
24
25
/**
25
/**
26
 * Creates source page to display XSD Source.<br>
26
 * Creates source page to display XSD Source.<br>
27
 * <b>NOTE:</b> It is read-only.
27
 * <b>NOTE:</b> It is read-only.
28
 *
28
 * 
29
 */
29
 */
30
30
31
public class XsdSourcePage extends AbstractSourcePage
31
public class XsdSourcePage extends AbstractSourcePage
32
{
32
{
33
33
34
    private Text _source;
34
	private Text _source;
35
35
36
    private Composite _parent;
36
	private Composite _parent;
37
37
38
    /**
38
	/**
39
     * Creates a new XSD source page.
39
	 * Creates a new XSD source page.
40
     */
40
	 */
41
    public XsdSourcePage(Composite parent, CapabilityEditor editor)
41
	public XsdSourcePage(Composite parent, CapabilityEditor editor)
42
    {
42
	{
43
	super(editor);
43
		super(editor);
44
	_parent = parent;
44
		_parent = parent;
45
	_display = editor.getEditorSite().getShell().getDisplay();
45
		_display = editor.getEditorSite().getShell().getDisplay();
46
    }
46
	}
47
47
48
    /**
48
	/**
49
     * Creates the page.
49
	 * Creates the page.
50
     */
50
	 */
51
    public void create()
51
	public void create()
52
    {
52
	{
53
	_source = new Text(_parent, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL
53
		_source = new Text(_parent, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL
54
		| SWT.READ_ONLY);
54
				| SWT.READ_ONLY);
55
	XSDSchema propSchema = _editor.getCapabilityDomain().getPropertySchema();
55
		XSDSchema propSchema = _editor.getCapabilityDomain()
56
	Document doc = propSchema.getDocument();
56
				.getPropertySchema();
57
	String text = XmlUtils.toString(doc);
57
		Document doc = propSchema.getDocument();
58
	setText(text);
58
		String text = CapUtils.documentToString(doc);
59
    }
59
		setText(text);
60
60
	}
61
    /**
61
62
     * Initializes control listeners.
62
	/**
63
     */
63
	 * Initializes control listeners.
64
    public void hookAllListeners()
64
	 */
65
    {	
65
	public void hookAllListeners()
66
    }
66
	{
67
67
	}
68
    /**
68
69
     * Refreshes the page.
69
	/**
70
     */
70
	 * Refreshes the page.
71
    public void refresh()
71
	 */
72
    {
72
	public void refresh()
73
	// TODO Auto-generated method stub
73
	{
74
74
		// TODO Auto-generated method stub
75
    }
75
76
76
	}
77
    /**
77
78
     * Handle propertyChanged event.
78
	/**
79
     */
79
	 * Handle propertyChanged event.
80
    public void propertyChanged(Object source, int propId)
80
	 */
81
    {
81
	public void propertyChanged(Object source, int propId)
82
	// TODO Auto-generated method stub
82
	{
83
83
		// TODO Auto-generated method stub
84
    }
84
85
85
	}
86
    /**
86
87
     * Returns the control associated with source. 
87
	/**
88
     */
88
	 * Returns the control associated with source.
89
    public Control getControl()
89
	 */
90
    {
90
	public Control getControl()
91
	return _source;
91
	{
92
    }
92
		return _source;
93
93
	}
94
    /**
94
95
     * Set the text to source page.
95
	/**
96
     */
96
	 * Set the text to source page.
97
    public void setText(String newText)
97
	 */
98
    {
98
	public void setText(String newText)
99
	_source.setText(newText);
99
	{
100
    }
100
		_source.setText(newText);
101
101
	}
102
    /**
102
103
     * 
103
	/**
104
     * @return text of source page.
104
	 * 
105
     */
105
	 * @return text of source page.
106
    public String getText()
106
	 */
107
    {
107
	public String getText()
108
	return _source.getText();
108
	{
109
    }
109
		return _source.getText();
110
	}
110
111
111
}
112
}
(-)src/org/eclipse/tptp/wsdm/tooling/editor/capability/pages/source/internal/RmdSourcePage.java (-92 / +82 lines)
Lines 12-125 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.pages.source.internal;
13
package org.eclipse.tptp.wsdm.tooling.editor.capability.pages.source.internal;
14
14
15
import java.io.InputStream;
16
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Text;
18
import org.eclipse.swt.widgets.Text;
22
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
19
import org.eclipse.tptp.wsdm.tooling.editor.capability.internal.CapabilityEditor;
23
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractSourcePage;
20
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.AbstractSourcePage;
24
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
25
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
26
21
27
/**
22
/**
28
 * Creates source page to display RMD Source.<br>
23
 * Creates source page to display RMD Source.<br>
29
 * <b>NOTE:</b> It is read-only.
24
 * <b>NOTE:</b> It is read-only.
30
 *
25
 * 
31
 */
26
 */
32
27
33
public class RmdSourcePage extends AbstractSourcePage
28
public class RmdSourcePage extends AbstractSourcePage
34
{
29
{
35
30
36
    private Text _source;
31
	private Text _source;
32
33
	private Composite _parent;
34
35
	/**
36
	 * Creates a new RMD source page.
37
	 */
38
	public RmdSourcePage(Composite parent, CapabilityEditor editor)
39
	{
40
		super(editor);
41
		_parent = parent;
42
		_display = editor.getEditorSite().getShell().getDisplay();
43
	}
44
45
	/**
46
	 * Creates the page.
47
	 */
48
	public void create()
49
	{
50
		_source = new Text(_parent, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL
51
				| SWT.READ_ONLY);
52
53
		// TODO Set the text from RMD root
54
55
		/*
56
		 * IFile rmdFile = _editor.getCapabilityDomain().getMetaDataDescriptor()
57
		 * .getRMDFile(); try { InputStream is = rmdFile.getContents(); byte[]
58
		 * contents = new byte[is.available()]; is.read(contents); String text =
59
		 * new String(contents); setText(text); } catch (Exception e) {
60
		 * WsdmToolingLog.logError(Messages.FAILED_TO_READ_CONTENTS_OF_MCAP_ERROR_,
61
		 * e); }
62
		 */
63
	}
64
65
	/**
66
	 * Initializes control listeners.
67
	 */
68
	public void hookAllListeners()
69
	{
70
	}
71
72
	/**
73
	 * Refreshes the page.
74
	 */
75
	public void refresh()
76
	{
77
		// TODO Auto-generated method stub
78
79
	}
37
80
38
    private Composite _parent;
81
	/**
82
	 * Handle propertyChanged event.
83
	 */
84
	public void propertyChanged(Object source, int propId)
85
	{
86
		// TODO Auto-generated method stub
39
87
40
    /**
88
	}
41
     * Creates a new RMD source page. 
89
42
     */
90
	/**
43
    public RmdSourcePage(Composite parent, CapabilityEditor editor)
91
	 * Returns the control associated with source.
44
    {
92
	 */
45
	super(editor);
93
	public Control getControl()
46
	_parent = parent;
94
	{
47
	_display = editor.getEditorSite().getShell().getDisplay();
95
		return _source;
48
    }
96
	}
49
97
50
    /**
98
	/**
51
     * Creates the page.
99
	 * Set the text to source page.
52
     */
100
	 */
53
    public void create()
101
	public void setText(String newText)
54
    {
102
	{
55
	_source = new Text(_parent, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL
103
		_source.setText(newText);
56
		| SWT.READ_ONLY);
104
	}
57
	
105
58
	// TODO Set the text from RMD root 
106
	/**
59
	
107
	 * 
60
	/*IFile rmdFile = _editor.getCapabilityDomain().getMetaDataDescriptor()
108
	 * @return text of source page.
61
		.getRMDFile();
109
	 */
62
	try
110
	public String getText()
63
	{
111
	{
64
	    InputStream is = rmdFile.getContents();
112
		return _source.getText();
65
	    byte[] contents = new byte[is.available()];
113
	}
66
	    is.read(contents);
67
	    String text = new String(contents);
68
	    setText(text);
69
	} catch (Exception e)
70
	{
71
	    WsdmToolingLog.logError(Messages.FAILED_TO_READ_CONTENTS_OF_MCAP_ERROR_, e);
72
	}*/
73
    }
74
75
    /**
76
     * Initializes control listeners.
77
     */
78
    public void hookAllListeners()
79
    {	
80
    }
81
82
    /**
83
     * Refreshes the page.
84
     */
85
    public void refresh()
86
    {
87
	// TODO Auto-generated method stub
88
89
    }
90
91
    /**
92
     * Handle propertyChanged event.
93
     */
94
    public void propertyChanged(Object source, int propId)
95
    {
96
	// TODO Auto-generated method stub
97
98
    }
99
100
    /**
101
     * Returns the control associated with source. 
102
     */
103
    public Control getControl()
104
    {
105
	return _source;
106
    }
107
108
    /**
109
     * Set the text to source page.
110
     */
111
    public void setText(String newText)
112
    {
113
	_source.setText(newText);
114
    }
115
116
    /**
117
     * 
118
     * @return text of source page.
119
     */
120
    public String getText()
121
    {
122
	return _source.getText();
123
    }
124
114
125
}
115
}
(-)META-INF/MANIFEST.MF (-1 lines)
Lines 31-34 Link Here
31
 org.eclipse.tptp.wsdm.tooling.viewers.internal,
31
 org.eclipse.tptp.wsdm.tooling.viewers.internal,
32
 org.eclipse.tptp.wsdm.tooling.wizard.capability.internal
32
 org.eclipse.tptp.wsdm.tooling.wizard.capability.internal
33
Bundle-ClassPath: runtime/capability-editor.jar
33
Bundle-ClassPath: runtime/capability-editor.jar
34
Import-Package: org.apache.xml.serialize
(-)src/org/eclipse/tptp/wsdm/tooling/wizard/capability/internal/NewCapabilityWizard.java (-640 / +683 lines)
Lines 15-21 Link Here
15
import java.io.ByteArrayInputStream;
15
import java.io.ByteArrayInputStream;
16
import java.io.ByteArrayOutputStream;
16
import java.io.ByteArrayOutputStream;
17
import java.io.IOException;
17
import java.io.IOException;
18
import java.io.StringWriter;
19
import java.lang.reflect.InvocationTargetException;
18
import java.lang.reflect.InvocationTargetException;
20
import java.util.HashMap;
19
import java.util.HashMap;
21
import java.util.List;
20
import java.util.List;
Lines 23-31 Link Here
23
22
24
import javax.xml.namespace.QName;
23
import javax.xml.namespace.QName;
25
24
26
import org.apache.muse.util.xml.XmlUtils;
27
import org.apache.xml.serialize.OutputFormat;
28
import org.apache.xml.serialize.XMLSerializer;
29
import org.eclipse.core.resources.IContainer;
25
import org.eclipse.core.resources.IContainer;
30
import org.eclipse.core.resources.IFile;
26
import org.eclipse.core.resources.IFile;
31
import org.eclipse.core.resources.IResource;
27
import org.eclipse.core.resources.IResource;
Lines 86-751 Link Here
86
 * Wizard to create new capability.
82
 * Wizard to create new capability.
87
 */
83
 */
88
84
89
public class NewCapabilityWizard extends Wizard implements INewWizard {
85
public class NewCapabilityWizard extends Wizard implements INewWizard
86
{
90
87
91
    private NewCapabilityWizardPage _newCapPage;
88
	private NewCapabilityWizardPage _newCapPage;
92
89
93
    //private CapabilityFileWizardPage _capFilesPage;
90
	// private CapabilityFileWizardPage _capFilesPage;
94
91
95
    private CapabilityModelImporterPage _importerPage;
92
	private CapabilityModelImporterPage _importerPage;
96
93
97
    private ISelection _selection;
94
	private ISelection _selection;
98
95
99
    private Definition _wsdlCapDefinition;
96
	private Definition _wsdlCapDefinition;
100
97
101
    private Map _options = new HashMap();
98
	private Map _options = new HashMap();
102
99
103
    private IFile _capFile;
100
	private IFile _capFile;
104
    
101
105
    private boolean canContinue = true;
102
	private boolean canContinue = true;
106
    
103
107
    private boolean isOverwriteXSD = true;
104
	private boolean isOverwriteXSD = true;
108
    
105
109
    private final static String DEFAULT_DESCRIPTION = "Example capability";
106
	private final static String DEFAULT_DESCRIPTION = "Example capability";
110
107
111
    /**
108
	/**
112
         * Creates new object of this class.
109
	 * Creates new object of this class.
113
         */
110
	 */
114
    public NewCapabilityWizard() {
111
	public NewCapabilityWizard()
115
	super();
112
	{
116
	setNeedsProgressMonitor(true);
113
		super();
117
    }
114
		setNeedsProgressMonitor(true);
118
115
	}
119
    /**
116
120
         * Adding the page to the wizard.
117
	/**
121
         */
118
	 * Adding the page to the wizard.
122
119
	 */
123
    public void addPages() {
120
124
	_newCapPage = new NewCapabilityWizardPage(_selection, this);
121
	public void addPages()
125
	addPage(_newCapPage);
122
	{
126
123
		_newCapPage = new NewCapabilityWizardPage(_selection, this);
127
	//_capFilesPage = new CapabilityFileWizardPage(_selection, this);
124
		addPage(_newCapPage);
128
	//addPage(_capFilesPage);
125
129
126
		// _capFilesPage = new CapabilityFileWizardPage(_selection, this);
130
	_importerPage = new CapabilityModelImporterPage(_selection, this);
127
		// addPage(_capFilesPage);
131
	addPage(_importerPage);
128
132
    }
129
		_importerPage = new CapabilityModelImporterPage(_selection, this);
133
130
		addPage(_importerPage);
134
    /**
131
	}
135
         * Creats a new capability.
132
136
         */
133
	/**
137
    public boolean performFinish() {
134
	 * Creats a new capability.
138
	String containerName = _newCapPage.getContainerName();
135
	 */
139
	String capQName = _newCapPage.getPrefix() + ":"
136
	public boolean performFinish()
140
		+ _newCapPage.getCapabilityName();
137
	{
141
	String capabilityName = CapUtils.getCapabilityNameFromQName(capQName);
138
		String containerName = _newCapPage.getContainerName();
142
	String capPrefix = CapUtils.getCapabilityPrefixFromQName(capQName);
139
		String capQName = _newCapPage.getPrefix() + ":"
143
	if (capPrefix == null)
140
				+ _newCapPage.getCapabilityName();
144
	    capPrefix = "tns";
141
		String capabilityName = CapUtils.getCapabilityNameFromQName(capQName);
145
	String capNS = _newCapPage.getNamespace();
142
		String capPrefix = CapUtils.getCapabilityPrefixFromQName(capQName);
146
	String targetCapFileName = _newCapPage.getTargetFileName();
143
		if (capPrefix == null)
147
	//String xsdFilePath = _capFilesPage.getXSDFilePath();
144
			capPrefix = "tns";
148
	//String xsdFileName = _capFilesPage.getXSDFileName();
145
		String capNS = _newCapPage.getNamespace();
149
	//String rmdFilePath = _capFilesPage.getRMDFilePath();
146
		String targetCapFileName = _newCapPage.getTargetFileName();
150
	//String rmdFileName = _capFilesPage.getRMDFileName();
147
		// String xsdFilePath = _capFilesPage.getXSDFilePath();
151
	String xsdFilePath = containerName+"/"+capabilityName+".xsd";
148
		// String xsdFileName = _capFilesPage.getXSDFileName();
152
	String xsdFileName = capabilityName+".xsd";
149
		// String rmdFilePath = _capFilesPage.getRMDFilePath();
153
	String rmdFilePath = containerName+"/"+capabilityName+".rmd";
150
		// String rmdFileName = _capFilesPage.getRMDFileName();
154
	String rmdFileName = capabilityName+".rmd";
151
		String xsdFilePath = containerName + "/" + capabilityName + ".xsd";
155
152
		String xsdFileName = capabilityName + ".xsd";
156
	String capNamespace = capNS;
153
		String rmdFilePath = containerName + "/" + capabilityName + ".rmd";
157
	String xsdNS = capNS;
154
		String rmdFileName = capabilityName + ".rmd";
158
	String rmdNS = capNS + "metadata";
155
159
156
		String capNamespace = capNS;
160
	String capFilePath = null;
157
		String xsdNS = capNS;
161
	if (!containerName.endsWith("/")) {
158
		String rmdNS = capNS + "metadata";
162
	    capFilePath = containerName + "/" + targetCapFileName;
159
163
	} else {
160
		String capFilePath = null;
164
	    capFilePath = containerName + targetCapFileName;
161
		if (!containerName.endsWith("/"))
165
	}
162
		{
166
163
			capFilePath = containerName + "/" + targetCapFileName;
167
	XSDSchema[] importedXsd = _importerPage.getSchemaToImport();
164
		}
168
	Definition[] importedWsdl = _importerPage.getWsdlToImport();
165
		else
169
166
		{
170
	_options.put(CapabilityWizardKeys.CONTAINER_NAME_KEY, containerName);
167
			capFilePath = containerName + targetCapFileName;
171
	_options.put(CapabilityWizardKeys.CAP_NS_KEY, capNamespace);
168
		}
172
	_options.put(CapabilityWizardKeys.CAP_PREFIX_KEY, capPrefix);
169
173
	_options.put(CapabilityWizardKeys.CAP_NAME_KEY, capabilityName);
170
		XSDSchema[] importedXsd = _importerPage.getSchemaToImport();
174
	_options.put(CapabilityWizardKeys.CAP_FILE_NAME_KEY, targetCapFileName);
171
		Definition[] importedWsdl = _importerPage.getWsdlToImport();
175
	_options.put(CapabilityWizardKeys.CAP_FILE_PATH_KEY, capFilePath);
172
176
173
		_options.put(CapabilityWizardKeys.CONTAINER_NAME_KEY, containerName);
177
	_options.put(CapabilityWizardKeys.XSD_FILE_PATH_KEY, xsdFilePath);
174
		_options.put(CapabilityWizardKeys.CAP_NS_KEY, capNamespace);
178
	_options.put(CapabilityWizardKeys.XSD_FILE_NAME_KEY, xsdFileName);
175
		_options.put(CapabilityWizardKeys.CAP_PREFIX_KEY, capPrefix);
179
	_options.put(CapabilityWizardKeys.XSD_NS_KEY, xsdNS);
176
		_options.put(CapabilityWizardKeys.CAP_NAME_KEY, capabilityName);
180
177
		_options.put(CapabilityWizardKeys.CAP_FILE_NAME_KEY, targetCapFileName);
181
	_options.put(CapabilityWizardKeys.RMD_FILE_PATH_KEY, rmdFilePath);
178
		_options.put(CapabilityWizardKeys.CAP_FILE_PATH_KEY, capFilePath);
182
	_options.put(CapabilityWizardKeys.RMD_FILE_NAME_KEY, rmdFileName);
179
183
	_options.put(CapabilityWizardKeys.RMD_NS_KEY, rmdNS);
180
		_options.put(CapabilityWizardKeys.XSD_FILE_PATH_KEY, xsdFilePath);
184
181
		_options.put(CapabilityWizardKeys.XSD_FILE_NAME_KEY, xsdFileName);
185
	_options.put(CapabilityWizardKeys.IMPORT_XSD_KEY, importedXsd);
182
		_options.put(CapabilityWizardKeys.XSD_NS_KEY, xsdNS);
186
	_options.put(CapabilityWizardKeys.IMPORT_WSDL_KEY, importedWsdl);
183
187
184
		_options.put(CapabilityWizardKeys.RMD_FILE_PATH_KEY, rmdFilePath);
188
	IRunnableWithProgress shouldOverwriteOperation = new IRunnableWithProgress()
185
		_options.put(CapabilityWizardKeys.RMD_FILE_NAME_KEY, rmdFileName);
189
	{
186
		_options.put(CapabilityWizardKeys.RMD_NS_KEY, rmdNS);
190
	    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
187
191
	    {
188
		_options.put(CapabilityWizardKeys.IMPORT_XSD_KEY, importedXsd);
192
		shouldOverWriteXSD();
189
		_options.put(CapabilityWizardKeys.IMPORT_WSDL_KEY, importedWsdl);
193
	    }	    
190
194
	};	
191
		IRunnableWithProgress shouldOverwriteOperation = new IRunnableWithProgress() {
195
	try
192
			public void run(IProgressMonitor monitor)
196
	{
193
					throws InvocationTargetException, InterruptedException
197
	    getContainer().run(false, false, shouldOverwriteOperation);
194
			{
198
	} catch (InvocationTargetException e1)
195
				shouldOverWriteXSD();
199
	{
196
			}
200
		WsdmToolingLog
197
		};
201
	    .logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ",
198
		try
202
		    e1);
199
		{
203
	} catch (InterruptedException e1)
200
			getContainer().run(false, false, shouldOverwriteOperation);
204
	{
201
		} catch (InvocationTargetException e1)
205
		WsdmToolingLog
202
		{
206
	    .logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ",
203
			WsdmToolingLog
207
		    e1);
204
					.logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ", e1);
208
	}
205
		} catch (InterruptedException e1)
209
	
206
		{
210
	IRunnableWithProgress op = new IRunnableWithProgress() {
207
			WsdmToolingLog
211
	    public void run(IProgressMonitor monitor)
208
					.logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ", e1);
212
		    throws InvocationTargetException {
209
		}
213
		try {
210
214
		    doFinish(monitor);
211
		IRunnableWithProgress op = new IRunnableWithProgress() {
215
		} catch (CoreException e) {
212
			public void run(IProgressMonitor monitor)
216
		    WsdmToolingLog
213
					throws InvocationTargetException
217
			    .logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ",
214
			{
218
				    e);
215
				try
219
		} catch (IOException e) {
216
				{
220
		    WsdmToolingLog
217
					doFinish(monitor);
221
			    .logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ",
218
				} catch (CoreException e)
222
				    e);
219
				{
223
		} catch (InterruptedException e)
220
					WsdmToolingLog.logError(Messages.FAILED_CREATE_CAP_ERROR_
224
		{
221
							+ " ", e);
225
		    e.printStackTrace();
222
				} catch (IOException e)
226
		} finally {
223
				{
227
		    monitor.done();
224
					WsdmToolingLog.logError(Messages.FAILED_CREATE_CAP_ERROR_
228
		}
225
							+ " ", e);
229
	    }
226
				} catch (InterruptedException e)
230
	};
227
				{
231
	
228
					e.printStackTrace();
232
	if(canContinue)
229
				} finally
233
	{
230
				{
234
	    try {
231
					monitor.done();
235
		    getContainer().run(true, false, op);
232
				}
236
		} catch (InterruptedException e) {
233
			}
237
		    WsdmToolingLog.logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ", e);
234
		};
238
		    return false;
235
239
		} catch (InvocationTargetException e) {
236
		if (canContinue)
240
		    Throwable realException = e.getTargetException();
237
		{
241
		    MessageDialog.openError(getShell(), "Error", realException
238
			try
242
			    .getMessage());
239
			{
243
		    return false;
240
				getContainer().run(true, false, op);
244
		}
241
			} catch (InterruptedException e)
245
	}
242
			{
246
	return true;
243
				WsdmToolingLog.logError(
247
    }
244
						Messages.FAILED_CREATE_CAP_ERROR_ + " ", e);
248
245
				return false;
249
    private void doFinish(IProgressMonitor monitor) throws CoreException,
246
			} catch (InvocationTargetException e)
250
	    IOException, InvocationTargetException, InterruptedException {
247
			{
251
	verifyContainer();
248
				Throwable realException = e.getTargetException();
252
	if(isOverwriteXSD)
249
				MessageDialog.openError(getShell(), "Error", realException
253
	    doFinishXSD(monitor);
250
						.getMessage());
254
	doFinishRMD(monitor);
251
				return false;
255
	doFinishCapFile(monitor);
252
			}
256
	refreshContainer(monitor);
253
		}
257
	openFile(monitor);
254
		return true;
258
    }
255
	}
259
256
260
    private void verifyContainer() {
257
	private void doFinish(IProgressMonitor monitor) throws CoreException,
261
	// TODO Put the code to verify container
258
			IOException, InvocationTargetException, InterruptedException
262
    }
259
	{
263
    
260
		verifyContainer();
264
    private void shouldOverWriteXSD()
261
		if (isOverwriteXSD)
265
    {
262
			doFinishXSD(monitor);
266
	XSDSchema[] importedXsd = (XSDSchema[]) _options
263
		doFinishRMD(monitor);
267
	.get(CapabilityWizardKeys.IMPORT_XSD_KEY);
264
		doFinishCapFile(monitor);
268
	String xsdFilePath = (String) _options.get(CapabilityWizardKeys.XSD_FILE_PATH_KEY);
265
		refreshContainer(monitor);
269
	if(importedXsd.length != 0)
266
		openFile(monitor);
270
	{
267
	}
271
	    for(int i=0;i<importedXsd.length;i++)
268
272
	    {
269
	private void verifyContainer()
273
		IFile importedXsdFile = null;
270
	{
271
		// TODO Put the code to verify container
272
	}
273
274
	private void shouldOverWriteXSD()
275
	{
276
		XSDSchema[] importedXsd = (XSDSchema[]) _options
277
				.get(CapabilityWizardKeys.IMPORT_XSD_KEY);
278
		String xsdFilePath = (String) _options
279
				.get(CapabilityWizardKeys.XSD_FILE_PATH_KEY);
280
		if (importedXsd.length != 0)
281
		{
282
			for (int i = 0; i < importedXsd.length; i++)
283
			{
284
				IFile importedXsdFile = null;
285
				try
286
				{
287
					importedXsdFile = EclipseUtils.getIFile(importedXsd[i]
288
							.eResource().getURI().toString());
289
				} catch (CoreException e)
290
				{
291
					WsdmToolingLog.logError(e.getLocalizedMessage(), e);
292
				}
293
				if (importedXsdFile.exists()
294
						&& importedXsdFile.getFullPath().toString().equals(
295
								xsdFilePath))
296
				{
297
					isOverwriteXSD = false;
298
					canContinue = true;
299
					return;
300
				}
301
			}
302
		}
303
304
		IFile xsdFile = null;
274
		try
305
		try
275
		{
306
		{
276
		    importedXsdFile = EclipseUtils.getIFile(importedXsd[i].eResource().getURI().toString());
307
			xsdFile = EclipseUtils.getIFile(xsdFilePath);
277
		} catch (CoreException e)
308
		} catch (CoreException e)
278
		{
309
		{
279
		    WsdmToolingLog.logError(e.getLocalizedMessage(), e);
310
			WsdmToolingLog.logError(e.getLocalizedMessage(), e);
280
		}
311
		}
281
		if(importedXsdFile.exists() && importedXsdFile.getFullPath().toString().equals(xsdFilePath))
312
		if (xsdFile.exists())
313
		{
314
			isOverwriteXSD = MessageDialog
315
					.openConfirm(getShell(), Messages.CONFIRM_MESSAGE, Messages
316
							.bind(Messages.OVERWRITE_FILE_MESSAGE, xsdFile
317
									.getName()));
318
			canContinue = isOverwriteXSD;
319
		}
320
	}
321
322
	private void refreshContainer(IProgressMonitor monitor)
323
			throws CoreException
324
	{
325
		String containerName = (String) _options
326
				.get(CapabilityWizardKeys.CONTAINER_NAME_KEY);
327
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
328
		IResource resource = root.findMember(new Path(containerName));
329
		if (!resource.exists() || !(resource instanceof IContainer))
330
		{
331
			throwCoreException(Messages.bind(
332
					Messages.CONTAINER_DOES_NOT_EXISTS_ERROR_, containerName));
333
		}
334
		IContainer container = (IContainer) resource;
335
		container.refreshLocal(IResource.DEPTH_ONE, monitor);
336
	}
337
338
	private void throwCoreException(String message) throws CoreException
339
	{
340
		IStatus status = new Status(IStatus.ERROR, "MrEditor2", IStatus.OK,
341
				message, null);
342
		throw new CoreException(status);
343
	}
344
345
	private void doFinishXSD(IProgressMonitor monitor) throws CoreException
346
	{
347
		String xsdFilePath = (String) _options
348
				.get(CapabilityWizardKeys.XSD_FILE_PATH_KEY);
349
		IFile xsdFile = EclipseUtils.getIFile(xsdFilePath);
350
		monitor.beginTask(Messages.CREATE_XSD_FILE, IProgressMonitor.UNKNOWN);
351
		createXSDFile(xsdFile, monitor);
352
		xsdFile.refreshLocal(IResource.DEPTH_ONE, monitor);
353
	}
354
355
	private void doFinishRMD(IProgressMonitor monitor) throws CoreException
356
	{
357
		String rmdFilePath = (String) _options
358
				.get(CapabilityWizardKeys.RMD_FILE_PATH_KEY);
359
		IFile rmdFile = EclipseUtils.getIFile(rmdFilePath);
360
		monitor.beginTask(Messages.CREATE_RMD_FILE, IProgressMonitor.UNKNOWN);
361
		createRMDFile(rmdFile, monitor);
362
		rmdFile.refreshLocal(IResource.DEPTH_ONE, monitor);
363
	}
364
365
	private void doFinishCapFile(IProgressMonitor monitor) throws CoreException
366
	{
367
		String capFilePath = (String) _options
368
				.get(CapabilityWizardKeys.CAP_FILE_PATH_KEY);
369
		_capFile = EclipseUtils.getIFile(capFilePath);
370
		monitor.beginTask(Messages.CREATE_MCAP_FILE, IProgressMonitor.UNKNOWN);
371
		createCapabilityFile(_capFile, monitor);
372
		_capFile.refreshLocal(IResource.DEPTH_ONE, monitor);
373
	}
374
375
	private void openFile(IProgressMonitor monitor)
376
	{
377
		monitor.beginTask(Messages.OPEN_FILE, IProgressMonitor.UNKNOWN);
378
		getShell().getDisplay().asyncExec(new Runnable() {
379
			public void run()
380
			{
381
				IWorkbenchPage pg = PlatformUI.getWorkbench()
382
						.getActiveWorkbenchWindow().getActivePage();
383
				try
384
				{
385
					IDE.openEditor(pg, _capFile, CapabilityEditor.ID);
386
				} catch (PartInitException e)
387
				{
388
					WsdmToolingLog.logError(Messages.FAILED_TO_OPEN_FILE_ERROR_
389
							+ " ", e);
390
				}
391
			}
392
		});
393
	}
394
395
	private void createXSDFile(IFile schemaFile, IProgressMonitor monitor)
396
	{
397
		String xsdNamespace = (String) _options
398
				.get(CapabilityWizardKeys.XSD_NS_KEY);
399
		XSDSchema schema = XsdUtils.createNewXSDSchema(xsdNamespace);
400
		String xsdURI = schemaFile.getFullPath().toString();
401
		XsdUtils.saveXSDSchema(schema, xsdURI, null, true);
402
	}
403
404
	private void createRMDFile(IFile rmdFile, IProgressMonitor monitor)
405
	{
406
		String capName = (String) _options
407
				.get(CapabilityWizardKeys.CAP_NAME_KEY);
408
		String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
409
		String descriptorName = capName + "Descriptor";
410
		String capabilityPortTypeName = capName + "PortType";
411
		String capabilityFileName = (String) _options
412
				.get(CapabilityWizardKeys.CAP_FILE_NAME_KEY);
413
		DocumentRoot documentRoot = MetaDataUtils.createNewMetadataRoot(capNS,
414
				descriptorName, capabilityPortTypeName, capabilityFileName);
415
		MetaDataUtils.serializeAndFormat(documentRoot, rmdFile, monitor);
416
	}
417
418
	private void createCapabilityFile(IFile capabilityFile,
419
			IProgressMonitor monitor)
420
	{
421
		String location = capabilityFile.getLocation().toString();
422
		String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
423
		String capPrefix = (String) _options
424
				.get(CapabilityWizardKeys.CAP_PREFIX_KEY);
425
		String capName = (String) _options
426
				.get(CapabilityWizardKeys.CAP_NAME_KEY);
427
		_wsdlCapDefinition = WsdlUtils.createNewWSDLDefinition(capNS,
428
				capPrefix, capName, location);
429
430
		_wsdlCapDefinition.addNamespace("wsrmd", WsdmConstants.WSRMD_NS);
431
		_wsdlCapDefinition.addNamespace("wsrp", WsdmConstants.WSRP_NS);
432
433
		createWSDLTypes();
434
		createWSDLPortType();
435
436
		String wsdlURI = capabilityFile.getFullPath().toString();
437
		ByteArrayOutputStream baos = null;
438
		try
439
		{
440
			baos = WsdlUtils.saveWSDLDefinition(_wsdlCapDefinition, wsdlURI,
441
					null);
442
		} catch (IOException e)
282
		{
443
		{
283
		    isOverwriteXSD = false;
444
			WsdmToolingLog.logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ", e);
284
		    canContinue = true;
445
		}
285
		    return;
446
286
		}   
447
		String afterEdit = wsdlEdit(baos.toString());
287
	    }
448
		ByteArrayInputStream baInputStream = new ByteArrayInputStream(afterEdit
288
	}
449
				.getBytes());
289
	
450
290
	IFile xsdFile = null;
451
		try
291
	try
452
		{
292
	{
453
			if (capabilityFile.exists())
293
	    xsdFile = EclipseUtils.getIFile(xsdFilePath);
454
			{
294
	} catch (CoreException e)
455
				capabilityFile.delete(true, null);
295
	{
456
			}
296
		WsdmToolingLog.logError(e.getLocalizedMessage(), e);
457
			capabilityFile.create(baInputStream, true, null);
297
	}		    
458
		} catch (CoreException ce)
298
	if(xsdFile.exists())
459
		{
299
	{
460
			WsdmToolingLog
300
	    isOverwriteXSD = MessageDialog.openConfirm(getShell(), Messages.CONFIRM_MESSAGE, Messages.bind(Messages.OVERWRITE_FILE_MESSAGE, xsdFile.getName()));
461
					.logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ", ce);
301
	    canContinue = isOverwriteXSD;	    	    
462
		}
302
	}	
463
	}
303
    }
464
304
    
465
	private void createWSDLTypes()
305
    private void refreshContainer(IProgressMonitor monitor)
466
	{
306
	    throws CoreException {
467
		Types types = WSDLFactory.eINSTANCE.createTypes();
307
	String containerName = (String) _options
468
		types.setEnclosingDefinition(_wsdlCapDefinition);
308
		.get(CapabilityWizardKeys.CONTAINER_NAME_KEY);
469
		_wsdlCapDefinition.setETypes(types);
309
	IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
470
		createResourcePropertiesSchema();
310
	IResource resource = root.findMember(new Path(containerName));
471
	}
311
	if (!resource.exists() || !(resource instanceof IContainer)) {
472
312
	    throwCoreException(Messages.bind(Messages.CONTAINER_DOES_NOT_EXISTS_ERROR_, containerName));
473
	private void createResourcePropertiesSchema()
313
	}
474
	{
314
	IContainer container = (IContainer) resource;
475
315
	container.refreshLocal(IResource.DEPTH_ONE, monitor);
476
		String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
316
    }
477
		XSDSchema schema = WsdlUtils.createOrFindSchema(_wsdlCapDefinition,
317
478
				capNS);
318
    private void throwCoreException(String message) throws CoreException {
479
		createAnnotation(schema);
319
	IStatus status = new Status(IStatus.ERROR, "MrEditor2", IStatus.OK,
480
		if (isOverwriteXSD)
320
		message, null);
481
			createPropXSDInclude(schema);
321
	throw new CoreException(status);
482
		createResourceProperties(schema);
322
    }
483
	}
323
484
324
    private void doFinishXSD(IProgressMonitor monitor) throws CoreException {
485
	private void createResourceProperties(XSDSchema schema)
325
	String xsdFilePath = (String) _options
486
	{
326
		.get(CapabilityWizardKeys.XSD_FILE_PATH_KEY);
487
		String capName = (String) _options
327
	IFile xsdFile = EclipseUtils.getIFile(xsdFilePath);
488
				.get(CapabilityWizardKeys.CAP_NAME_KEY);
328
	monitor.beginTask(Messages.CREATE_XSD_FILE, IProgressMonitor.UNKNOWN);
489
		XSDElementDeclaration resourcePropertyElement = XSDFactory.eINSTANCE
329
	createXSDFile(xsdFile, monitor);
490
				.createXSDElementDeclaration();
330
	xsdFile.refreshLocal(IResource.DEPTH_ONE, monitor);	
491
		resourcePropertyElement.setName(capName + "Properties");
331
    }
492
		resourcePropertyElement.setTypeDefinition(null);
332
493
		schema.getContents().add(resourcePropertyElement);
333
    private void doFinishRMD(IProgressMonitor monitor) throws CoreException {
494
334
	String rmdFilePath = (String) _options
495
		XSDSchema[] importedXsd = (XSDSchema[]) _options
335
		.get(CapabilityWizardKeys.RMD_FILE_PATH_KEY);
496
				.get(CapabilityWizardKeys.IMPORT_XSD_KEY);
336
	IFile rmdFile = EclipseUtils.getIFile(rmdFilePath);
497
		for (int i = 0; i < importedXsd.length; i++)
337
	monitor.beginTask(Messages.CREATE_RMD_FILE, IProgressMonitor.UNKNOWN);
498
		{
338
	createRMDFile(rmdFile, monitor);
499
			importXSD(resourcePropertyElement, importedXsd[i]);
339
	rmdFile.refreshLocal(IResource.DEPTH_ONE, monitor);
500
		}
340
    }
501
	}
341
502
342
    private void doFinishCapFile(IProgressMonitor monitor) throws CoreException {
503
	private void importXSD(XSDElementDeclaration resourcePropertyElement,
343
	String capFilePath = (String) _options
504
			XSDSchema schema)
344
		.get(CapabilityWizardKeys.CAP_FILE_PATH_KEY);
505
	{
345
	_capFile = EclipseUtils.getIFile(capFilePath);
506
		// Get the location for XSD Schema in drive fromat
346
	monitor.beginTask(Messages.CREATE_MCAP_FILE, IProgressMonitor.UNKNOWN);
507
		String schemaLocation = XsdUtils.getLocalSystemSchemaLocation(schema);
347
	createCapabilityFile(_capFile, monitor);
508
348
	_capFile.refreshLocal(IResource.DEPTH_ONE, monitor);
509
		// Get the location for capability file
349
    }
510
		String capFileLocation = _capFile.getLocation().toString();
350
511
351
    private void openFile(IProgressMonitor monitor) {
512
		// Create xsd:import element
352
	monitor.beginTask(Messages.OPEN_FILE, IProgressMonitor.UNKNOWN);
513
		String importSchemaLocation = EclipseUtils.getRelativePath(
353
	getShell().getDisplay().asyncExec(new Runnable() {
514
				capFileLocation, schemaLocation, '/');
354
	    public void run() {
515
		XsdUtils.createImportStatement(resourcePropertyElement.getSchema(),
355
		IWorkbenchPage pg = PlatformUI.getWorkbench()
516
				schema.getTargetNamespace(), importSchemaLocation);
356
			.getActiveWorkbenchWindow().getActivePage();
517
357
		try {
518
		// Prepare resource property element
358
		    IDE.openEditor(pg, _capFile, CapabilityEditor.ID);
519
		XSDModelGroup modelGroup = null;
359
		} catch (PartInitException e) {
520
		if (resourcePropertyElement.getAnonymousTypeDefinition() == null)
360
		    WsdmToolingLog.logError(Messages.FAILED_TO_OPEN_FILE_ERROR_ + " ",
521
		{
361
			    e);
522
			// Create New XSD Model Group
362
		}
523
			modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
363
	    }
524
			modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
364
	});
525
365
    }
526
			XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
366
527
			xsdParticle.setContent(modelGroup);
367
    private void createXSDFile(IFile schemaFile, IProgressMonitor monitor) {
528
368
	String xsdNamespace = (String) _options
529
			XSDComplexTypeDefinition complexTypeDefiniton = XSDFactory.eINSTANCE
369
		.get(CapabilityWizardKeys.XSD_NS_KEY);
530
					.createXSDComplexTypeDefinition();
370
	XSDSchema schema = XsdUtils.createNewXSDSchema(xsdNamespace);
531
			complexTypeDefiniton.setContent(xsdParticle);
371
	String xsdURI = schemaFile.getFullPath().toString();
532
			resourcePropertyElement
372
	XsdUtils.saveXSDSchema(schema, xsdURI, null, true);
533
					.setAnonymousTypeDefinition(complexTypeDefiniton);
373
    }
534
		}
374
535
		else
375
    private void createRMDFile(IFile rmdFile, IProgressMonitor monitor) {
536
		{
376
	String capName = (String) _options
537
			// Get the XSD Model Group
377
		.get(CapabilityWizardKeys.CAP_NAME_KEY);
538
			XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
378
	String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
539
					.getAnonymousTypeDefinition();
379
	String descriptorName = capName + "Descriptor";
540
			modelGroup = XsdUtils.getXSDModelGroup(typeDef);
380
	DocumentRoot documentRoot = MetaDataUtils.createNewMetadataRoot(capNS,
541
		}
381
		descriptorName);
542
382
	MetaDataUtils.serializeAndFormat(documentRoot, rmdFile, monitor);
543
		List elements = schema.getElementDeclarations();
383
    }
544
		for (int i = 0; i < elements.size(); i++)
384
545
		{
385
    private void createCapabilityFile(IFile capabilityFile,
546
			// Add element to resource properties
386
	    IProgressMonitor monitor) {
547
			XSDElementDeclaration element = (XSDElementDeclaration) elements
387
	String location = capabilityFile.getLocation().toString();
548
					.get(i);
388
	String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
549
389
	String capPrefix = (String) _options
550
			XSDElementDeclaration propertyRef = XSDFactory.eINSTANCE
390
		.get(CapabilityWizardKeys.CAP_PREFIX_KEY);
551
					.createXSDElementDeclaration();
391
	String capName = (String) _options
552
			propertyRef.setResolvedElementDeclaration(element);
392
		.get(CapabilityWizardKeys.CAP_NAME_KEY);
553
			XSDParticle simpleElementParticle = XSDFactory.eINSTANCE
393
	_wsdlCapDefinition = WsdlUtils.createNewWSDLDefinition(capNS,
554
					.createXSDParticle();
394
		capPrefix, capName, location);
555
			simpleElementParticle.setContent(propertyRef);
395
556
			modelGroup.getContents().add(simpleElementParticle);
396
	_wsdlCapDefinition.addNamespace("wsrmd", WsdmConstants.WSRMD_NS);
557
		}
397
	_wsdlCapDefinition.addNamespace("wsrp", WsdmConstants.WSRP_NS);
558
	}
398
559
399
	createWSDLTypes();
560
	private void createAnnotation(XSDSchema schema)
400
	createWSDLPortType();
561
	{
401
562
		XSDAnnotation annotation = XSDFactory.eINSTANCE.createXSDAnnotation();
402
	String wsdlURI = capabilityFile.getFullPath().toString();
563
		schema.getContents().add(annotation);
403
	ByteArrayOutputStream baos = null;
564
		Element documentation = annotation.createUserInformation(null);
404
	try
565
		annotation.getElement().appendChild(documentation);
405
	{
566
		documentation.appendChild(documentation.getOwnerDocument()
406
	    baos = WsdlUtils.saveWSDLDefinition(
567
				.createTextNode(DEFAULT_DESCRIPTION));
407
	    	_wsdlCapDefinition, wsdlURI, null);
568
	}
408
	} catch (IOException e)
569
409
	{
570
	private void createPropXSDInclude(XSDSchema schema)
410
	    WsdmToolingLog.logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ", e);
571
	{
411
	}
572
		String xsdFileName = (String) _options
412
573
				.get(CapabilityWizardKeys.XSD_FILE_NAME_KEY);
413
	String afterEdit = wsdlEdit(baos.toString());
574
		XSDInclude include = XSDFactory.eINSTANCE.createXSDInclude();
414
	ByteArrayInputStream baInputStream = new ByteArrayInputStream(afterEdit
575
		include.setSchemaLocation(xsdFileName);
415
		.getBytes());
576
		schema.getContents().add(include);
416
577
	}
417
	try {
578
418
	    if (capabilityFile.exists()) {
579
	private void createWSDLPortType()
419
		capabilityFile.delete(true, null);
580
	{
420
	    }
581
		PortType pt = WSDLFactory.eINSTANCE.createPortType();
421
	    capabilityFile.create(baInputStream, true, null);
582
		String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
422
	} catch (CoreException ce) {
583
		String capName = (String) _options
423
	    WsdmToolingLog.logError(Messages.FAILED_CREATE_CAP_ERROR_ + " ", ce);
584
				.get(CapabilityWizardKeys.CAP_NAME_KEY);
424
	}
585
		pt.setQName(new QName(capNS, capName + "PortType"));
425
    }
586
		pt.setEnclosingDefinition(_wsdlCapDefinition);
426
587
		_wsdlCapDefinition.addPortType(pt);
427
    private void createWSDLTypes() {
588
428
	Types types = WSDLFactory.eINSTANCE.createTypes();
589
		Definition[] importedWSDL = (Definition[]) _options
429
	types.setEnclosingDefinition(_wsdlCapDefinition);
590
				.get(CapabilityWizardKeys.IMPORT_WSDL_KEY);
430
	_wsdlCapDefinition.setETypes(types);
591
		for (int i = 0; i < importedWSDL.length; i++)
431
	createResourcePropertiesSchema();
592
		{
432
    }
593
			importWSDL(pt, importedWSDL[i]);
433
594
		}
434
    private void createResourcePropertiesSchema() {
595
	}
435
596
436
	String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
597
	private void importWSDL(PortType pt, Definition importedWSDL)
437
	XSDSchema schema = WsdlUtils.createOrFindSchema(_wsdlCapDefinition,
598
	{
438
		capNS);
599
		importWSDLImports(pt, importedWSDL);
439
	createAnnotation(schema);
600
440
	if(isOverwriteXSD)
601
		// Get the location for imported WSDL
441
	    createPropXSDInclude(schema);
602
		String importedWsdlLocation;
442
	createResourceProperties(schema);
603
		try
443
    }
604
		{
444
605
			importedWsdlLocation = WsdlUtils
445
    private void createResourceProperties(XSDSchema schema) {
606
					.getLocalSystemWSDLLocation(importedWSDL);
446
	String capName = (String) _options
607
		} catch (CoreException e)
447
		.get(CapabilityWizardKeys.CAP_NAME_KEY);
608
		{
448
	XSDElementDeclaration resourcePropertyElement = XSDFactory.eINSTANCE
609
			return;
449
		.createXSDElementDeclaration();
610
		}
450
	resourcePropertyElement.setName(capName + "Properties");
611
451
	resourcePropertyElement.setTypeDefinition(null);
612
		// Get the location for capability file
452
	schema.getContents().add(resourcePropertyElement);
613
		String capFileLocation = _capFile.getLocation().toString();
453
614
454
	XSDSchema[] importedXsd = (XSDSchema[]) _options
615
		// Create wsdl:import statement
455
		.get(CapabilityWizardKeys.IMPORT_XSD_KEY);
616
		String relativePath = EclipseUtils.getRelativePath(capFileLocation,
456
	for (int i = 0; i < importedXsd.length; i++) {
617
				importedWsdlLocation, '/');
457
	    importXSD(resourcePropertyElement, importedXsd[i]);
618
		WsdlUtils.createWSDLImport(pt.getEnclosingDefinition(), importedWSDL
458
	}
619
				.getTargetNamespace(), relativePath);
459
    }
620
460
621
		PortType importPortType = WsdlUtils.getPortType(importedWSDL);
461
    private void importXSD(XSDElementDeclaration resourcePropertyElement,
622
		if (importPortType == null)
462
	    XSDSchema schema) {
623
			return;
463
	// Get the location for XSD Schema in drive fromat
624
		List opList = importPortType.getEOperations();
464
	String schemaLocation = XsdUtils.getLocalSystemSchemaLocation(schema);
625
		for (int i = 0; i < opList.size(); i++)
465
626
		{
466
	// Get the location for capability file
627
			Operation importOp = (Operation) opList.get(i);
467
	String capFileLocation = _capFile.getLocation().toString();
628
			Operation newOperation = WSDLFactory.eINSTANCE.createOperation();
468
629
			pt.addOperation(newOperation);
469
	// Create xsd:import element
630
			if (!importOperation(newOperation, importOp))
470
	String importSchemaLocation = EclipseUtils.getRelativePath(
631
				pt.getEOperations().remove(newOperation);
471
		capFileLocation, schemaLocation, '/');
632
		}
472
	XsdUtils.createImportStatement(resourcePropertyElement.getSchema(),
633
473
		schema.getTargetNamespace(), importSchemaLocation);
634
	}
474
635
475
	// Prepare resource property element
636
	private void importWSDLImports(PortType pt, Definition importedWSDL)
476
	XSDModelGroup modelGroup = null;
637
	{
477
	if (resourcePropertyElement.getAnonymousTypeDefinition() == null) {
638
		List imports = importedWSDL.getEImports();
478
	    // Create New XSD Model Group
639
		for (int i = 0; i < imports.size(); i++)
479
	    modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
640
		{
480
	    modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
641
			Import wsdlImport = (Import) imports.get(i);
481
642
			WsdlUtils.createWSDLImport(pt.getEnclosingDefinition(), wsdlImport
482
	    XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
643
					.getNamespaceURI(), wsdlImport.getLocationURI());
483
	    xsdParticle.setContent(modelGroup);
644
		}
484
645
	}
485
	    XSDComplexTypeDefinition complexTypeDefiniton = XSDFactory.eINSTANCE
646
486
		    .createXSDComplexTypeDefinition();
647
	private boolean importOperation(Operation newOperation, Operation importOp)
487
	    complexTypeDefiniton.setContent(xsdParticle);
648
	{
488
	    resourcePropertyElement
649
489
		    .setAnonymousTypeDefinition(complexTypeDefiniton);
650
		if (importOp.getName() == null || importOp.getName().equals(""))
490
	} else {
651
			return false;
491
	    // Get the XSD Model Group
652
492
	    XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
653
		String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
493
		    .getAnonymousTypeDefinition();
654
		if (!capNS.endsWith("/"))
494
	    modelGroup = XsdUtils.getXSDModelGroup(typeDef);
655
			capNS = capNS + "/";
495
	}
656
496
657
		newOperation.setEnclosingDefinition(_wsdlCapDefinition);
497
	List elements = schema.getElementDeclarations();
658
		newOperation.setName(importOp.getName());
498
	for (int i = 0; i < elements.size(); i++) {
659
499
	    // Add element to resource properties
660
		Input importInput = importOp.getEInput();
500
	    XSDElementDeclaration element = (XSDElementDeclaration) elements
661
		Output importOutput = importOp.getEOutput();
501
		    .get(i);
662
		List importFaults = importOp.getEFaults();
502
663
503
	    XSDElementDeclaration propertyRef = XSDFactory.eINSTANCE
664
		if (importInput != null)
504
		    .createXSDElementDeclaration();
665
		{
505
	    propertyRef.setResolvedElementDeclaration(element);
666
			Input newInput = WSDLFactory.eINSTANCE.createInput();
506
	    XSDParticle simpleElementParticle = XSDFactory.eINSTANCE
667
			newInput.setEnclosingDefinition(_wsdlCapDefinition);
507
		    .createXSDParticle();
668
			if (importInput.getName() != null)
508
	    simpleElementParticle.setContent(propertyRef);
669
				newInput.setName(importInput.getName());
509
	    modelGroup.getContents().add(simpleElementParticle);
670
			newInput.setEMessage(importInput.getEMessage());
510
	}
671
			newOperation.setEInput(newInput);
511
    }
672
			WsdlUtils.createOrFindPrefix(_wsdlCapDefinition,
512
673
					WsdmConstants.WSA_URI, WsdmConstants.WSA_PREFIX);
513
    private void createAnnotation(XSDSchema schema) {
674
			String opName = importOp.getName();
514
	XSDAnnotation annotation = XSDFactory.eINSTANCE.createXSDAnnotation();
675
			opName = opName.substring(0, 1).toUpperCase() + opName.substring(1);
515
	schema.getContents().add(annotation);
676
			String action = capNS + opName + "Request";
516
	Element documentation = annotation.createUserInformation(null);
677
			newInput.getElement().setAttributeNS(WsdmConstants.WSA_URI,
517
	annotation.getElement().appendChild(documentation);
678
					WsdmConstants.WSA_ACTION_NAME, action);
518
	documentation.appendChild(documentation.getOwnerDocument()
679
		}
519
		.createTextNode(DEFAULT_DESCRIPTION));
680
520
    }
681
		if (importOutput != null)
521
682
		{
522
    private void createPropXSDInclude(XSDSchema schema) {
683
			Output newOutput = WSDLFactory.eINSTANCE.createOutput();
523
	String xsdFileName = (String) _options
684
			newOutput.setEnclosingDefinition(_wsdlCapDefinition);
524
		.get(CapabilityWizardKeys.XSD_FILE_NAME_KEY);
685
			if (importOutput.getName() != null)
525
	XSDInclude include = XSDFactory.eINSTANCE.createXSDInclude();
686
				newOutput.setName(importOutput.getName());
526
	include.setSchemaLocation(xsdFileName);
687
			newOutput.setEMessage(importOutput.getEMessage());
527
	schema.getContents().add(include);
688
			newOperation.setEOutput(newOutput);
528
    }
689
			WsdlUtils.createOrFindPrefix(_wsdlCapDefinition,
529
690
					WsdmConstants.WSA_URI, WsdmConstants.WSA_PREFIX);
530
    private void createWSDLPortType() {
691
			String opName = importOp.getName();
531
	PortType pt = WSDLFactory.eINSTANCE.createPortType();
692
			opName = opName.substring(0, 1).toUpperCase() + opName.substring(1);
532
	String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
693
			String action = capNS + opName + "Response";
533
	String capName = (String) _options
694
			newOutput.getElement().setAttributeNS(WsdmConstants.WSA_URI,
534
		.get(CapabilityWizardKeys.CAP_NAME_KEY);
695
					WsdmConstants.WSA_ACTION_NAME, action);
535
	pt.setQName(new QName(capNS, capName + "PortType"));
696
		}
536
	pt.setEnclosingDefinition(_wsdlCapDefinition);
697
537
	_wsdlCapDefinition.addPortType(pt);
698
		for (int i = 0; i < importFaults.size(); i++)
538
	
699
		{
539
	Definition[] importedWSDL = (Definition[]) _options
700
			Fault importFault = (Fault) importFaults.get(i);
540
		.get(CapabilityWizardKeys.IMPORT_WSDL_KEY);
701
			Fault newFault = WSDLFactory.eINSTANCE.createFault();
541
	for (int i = 0; i < importedWSDL.length; i++) {
702
			newFault.setName(importFault.getName());
542
	    importWSDL(pt, importedWSDL[i]);
703
			newFault.setEMessage(importFault.getEMessage());
543
	}
704
			newOperation.addFault(newFault);
544
    }
705
		}
545
706
546
    private void importWSDL(PortType pt, Definition importedWSDL) {
707
		return true;
547
	importWSDLImports(pt, importedWSDL);
708
	}
548
709
549
	// Get the location for imported WSDL
710
	private String wsdlEdit(String wsdlString)
550
	String importedWsdlLocation;
711
	{
551
	try
712
		Document doc = null;
552
	{
713
		try
553
	    importedWsdlLocation = WsdlUtils
714
		{
554
	    	.getLocalSystemWSDLLocation(importedWSDL);
715
			doc = CapUtils.createDocument(wsdlString);
555
	} catch (CoreException e)
716
		} catch (Throwable e)
556
	{
717
		{
557
	    return;
718
			WsdmToolingLog.logError(e.getMessage(), e);
558
	}
719
		}
559
720
560
	// Get the location for capability file
721
		NodeList nlD = doc.getElementsByTagNameNS(
561
	String capFileLocation = _capFile.getLocation().toString();
722
				WSDLConstants.WSDL_NAMESPACE_URI, "definitions");
562
723
		Element defs = (Element) nlD.item(0);
563
	// Create wsdl:import statement
724
		defs.setAttribute("xmlns:xsd", XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
564
	String relativePath = EclipseUtils.getRelativePath(capFileLocation,
725
565
		importedWsdlLocation, '/');
726
		NodeList nlpt = doc.getElementsByTagNameNS(
566
	WsdlUtils.createWSDLImport(pt.getEnclosingDefinition(), importedWSDL
727
				WSDLConstants.WSDL_NAMESPACE_URI, "portType");
567
		.getTargetNamespace(), relativePath);
728
		Element pte = (Element) nlpt.item(0);
568
729
		String capName = (String) _options
569
	PortType importPortType = WsdlUtils.getPortType(importedWSDL);
730
				.get(CapabilityWizardKeys.CAP_NAME_KEY);
570
	if (importPortType == null)
731
		String capPrefix = (String) _options
571
	    return;
732
				.get(CapabilityWizardKeys.CAP_PREFIX_KEY);
572
	List opList = importPortType.getEOperations();
733
		String rmdFileName = (String) _options
573
	for (int i = 0; i < opList.size(); i++) {
734
				.get(CapabilityWizardKeys.RMD_FILE_NAME_KEY);
574
	    Operation importOp = (Operation) opList.get(i);
735
		pte.setAttributeNS(WsdmConstants.WSRP_NS, "wsrp:"
575
	    Operation newOperation = WSDLFactory.eINSTANCE.createOperation();	    
736
				+ WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY, capPrefix + ":"
576
	    pt.addOperation(newOperation);
737
				+ capName + "Properties");
577
	    if(!importOperation(newOperation, importOp))
738
		pte.setAttributeNS(WsdmConstants.WSRMD_NS, "wsrmd:"
578
		pt.getEOperations().remove(newOperation);
739
				+ WsdlUtils.METADATA_DESCRIPTOR_KEY, capName + "Descriptor");
579
	}
740
		pte.setAttributeNS(WsdmConstants.WSRMD_NS, "wsrmd:"
580
741
				+ WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY, rmdFileName);
581
    }
742
582
743
		String serialized = CapUtils.documentToString(doc);
583
    private void importWSDLImports(PortType pt, Definition importedWSDL) {
744
		return serialized;
584
	List imports = importedWSDL.getEImports();
745
	}
585
	for (int i = 0; i < imports.size(); i++) {
746
586
	    Import wsdlImport = (Import) imports.get(i);
747
	public void init(IWorkbench workbench, IStructuredSelection selection)
587
	    WsdlUtils.createWSDLImport(pt.getEnclosingDefinition(), wsdlImport
748
	{
588
		    .getNamespaceURI(), wsdlImport.getLocationURI());
749
		_selection = selection;
589
	}
750
		setWindowTitle(Messages.NEW_CAPABILITY);
590
    }
751
	}
591
752
592
    private boolean importOperation(Operation newOperation, Operation importOp) {
753
	public NewCapabilityWizardPage getNewCapabilityWizardPage()
593
	
754
	{
594
	if(importOp.getName()==null || importOp.getName().equals(""))
755
		return _newCapPage;
595
	    return false;
756
	}
596
	
757
597
	String capNS = (String) _options.get(CapabilityWizardKeys.CAP_NS_KEY);
758
	/*
598
	if(!capNS.endsWith("/"))
759
	 * protected CapabilityFileWizardPage getCapabilityFileWizardPage() { return
599
	    capNS = capNS+"/";
760
	 * _capFilesPage; }
600
	
761
	 */
601
	newOperation.setEnclosingDefinition(_wsdlCapDefinition);
602
	newOperation.setName(importOp.getName());
603
604
	Input importInput = importOp.getEInput();
605
	Output importOutput = importOp.getEOutput();
606
	List importFaults = importOp.getEFaults();
607
608
	if (importInput != null) {	    
609
		Input newInput = WSDLFactory.eINSTANCE.createInput();
610
		newInput.setEnclosingDefinition(_wsdlCapDefinition);
611
		if(importInput.getName()!=null)
612
			newInput.setName(importInput.getName());
613
		newInput.setEMessage(importInput.getEMessage());
614
		newOperation.setEInput(newInput);
615
		WsdlUtils.createOrFindPrefix(_wsdlCapDefinition, WsdmConstants.WSA_URI, WsdmConstants.WSA_PREFIX);
616
		String opName = importOp.getName();
617
 	    opName = opName.substring(0, 1).toUpperCase() + opName.substring(1);
618
 	    String action = capNS+opName+"Request";	    
619
 	    newInput.getElement().setAttributeNS(WsdmConstants.WSA_URI, WsdmConstants.WSA_ACTION_NAME, action);
620
	}
621
622
	if (importOutput != null) {
623
		Output newOutput = WSDLFactory.eINSTANCE.createOutput();
624
		newOutput.setEnclosingDefinition(_wsdlCapDefinition);
625
		if(importOutput.getName()!=null)
626
			newOutput.setName(importOutput.getName());
627
		newOutput.setEMessage(importOutput.getEMessage());
628
		newOperation.setEOutput(newOutput);
629
		WsdlUtils.createOrFindPrefix(_wsdlCapDefinition, WsdmConstants.WSA_URI, WsdmConstants.WSA_PREFIX);		
630
	    String opName = importOp.getName();
631
	    opName = opName.substring(0, 1).toUpperCase() + opName.substring(1);
632
	    String action = capNS+opName+"Response";	    
633
	    newOutput.getElement().setAttributeNS(WsdmConstants.WSA_URI, WsdmConstants.WSA_ACTION_NAME, action);	    
634
	}
635
636
	for (int i = 0; i < importFaults.size(); i++) {
637
	    Fault importFault = (Fault) importFaults.get(i);
638
	    Fault newFault = WSDLFactory.eINSTANCE.createFault();
639
	    newFault.setName(importFault.getName());
640
	    newFault.setEMessage(importFault.getEMessage());
641
	    newOperation.addFault(newFault);
642
	}
643
	
644
	return true;
645
    }
646
647
    private String wsdlEdit(String wsdlString) {
648
	Document doc = parseToDOM(wsdlString);
649
650
	NodeList nlD = doc.getElementsByTagNameNS(
651
		WSDLConstants.WSDL_NAMESPACE_URI, "definitions");
652
	Element defs = (Element) nlD.item(0);
653
	defs.setAttribute("xmlns:xsd", XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
654
655
	NodeList nlpt = doc.getElementsByTagNameNS(
656
		WSDLConstants.WSDL_NAMESPACE_URI, "portType");
657
	Element pte = (Element) nlpt.item(0);
658
	String capName = (String) _options
659
		.get(CapabilityWizardKeys.CAP_NAME_KEY);
660
	String capPrefix = (String) _options
661
		.get(CapabilityWizardKeys.CAP_PREFIX_KEY);
662
	String rmdFileName = (String) _options
663
		.get(CapabilityWizardKeys.RMD_FILE_NAME_KEY);
664
	pte.setAttributeNS(WsdmConstants.WSRP_NS, "wsrp:"
665
		+ WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY, capPrefix + ":"
666
		+ capName + "Properties");
667
	pte.setAttributeNS(WsdmConstants.WSRMD_NS, "wsrmd:"
668
		+ WsdlUtils.METADATA_DESCRIPTOR_KEY, capName + "Descriptor");
669
	pte.setAttributeNS(WsdmConstants.WSRMD_NS, "wsrmd:"
670
		+ WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY, rmdFileName);
671
672
	String serialized = prettySerializeDocument(doc);
673
	return serialized;
674
    }
675
676
    private Document parseToDOM(String xmlString) {
677
	Document doc = null;
678
	try {
679
	    doc = XmlUtils.createDocument(xmlString);
680
	} catch (IOException ioe) {
681
	    WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_ + " ", ioe);
682
	    return null;
683
	} catch (SAXException se) {
684
	    WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_ + " ", se);
685
	    return null;
686
	}
687
	doc.normalize();
688
	return doc;
689
    }
690
691
    private static String prettySerializeDocument(Document doc) {
692
	OutputFormat format = new OutputFormat();
693
	format.setPreserveSpace(false);
694
	format.setIndenting(true);
695
	format.setIndent(2);
696
	format.setLineWidth(72); 
697
	format.setLineSeparator(System.getProperty("line.separator"));
698
	StringWriter writer = new StringWriter();
699
	XMLSerializer serializer = new XMLSerializer(writer, format);
700
	try {
701
	    serializer.serialize(doc);
702
	} catch (IOException ioe) {
703
	    WsdmToolingLog.logError(Messages.CANT_SERIALIZE_DOCUMENT_ERROR_ + " ", ioe);
704
	}
705
	return writer.getBuffer().toString();
706
    }
707
708
    public void init(IWorkbench workbench, IStructuredSelection selection) {
709
	_selection = selection;
710
	setWindowTitle(Messages.NEW_CAPABILITY);
711
    }
712
713
    public NewCapabilityWizardPage getNewCapabilityWizardPage() {
714
	return _newCapPage;
715
    }
716
717
    /*protected CapabilityFileWizardPage getCapabilityFileWizardPage() {
718
	return _capFilesPage;
719
    }*/
720
}
762
}
721
763
722
class CapabilityWizardKeys {
764
class CapabilityWizardKeys
765
{
723
766
724
    static final String CONTAINER_NAME_KEY = "CONTAINER_NAME";
767
	static final String CONTAINER_NAME_KEY = "CONTAINER_NAME";
725
768
726
    static final String CAP_NS_KEY = "CAP_NS";
769
	static final String CAP_NS_KEY = "CAP_NS";
727
770
728
    static final String CAP_PREFIX_KEY = "CAP_PREFIX";
771
	static final String CAP_PREFIX_KEY = "CAP_PREFIX";
729
772
730
    static final String CAP_NAME_KEY = "CAP_NAME";
773
	static final String CAP_NAME_KEY = "CAP_NAME";
731
774
732
    static final String CAP_FILE_NAME_KEY = "CAP_FILE_NAME";
775
	static final String CAP_FILE_NAME_KEY = "CAP_FILE_NAME";
733
776
734
    static final String CAP_FILE_PATH_KEY = "CAP_FILE_PATH";
777
	static final String CAP_FILE_PATH_KEY = "CAP_FILE_PATH";
735
778
736
    static final String XSD_FILE_PATH_KEY = "XSD_FILE_PATH";
779
	static final String XSD_FILE_PATH_KEY = "XSD_FILE_PATH";
737
780
738
    static final String XSD_FILE_NAME_KEY = "XSD_FILE_NAME";
781
	static final String XSD_FILE_NAME_KEY = "XSD_FILE_NAME";
739
782
740
    static final String XSD_NS_KEY = "XSD_NS";
783
	static final String XSD_NS_KEY = "XSD_NS";
741
784
742
    static final String RMD_FILE_PATH_KEY = "RMD_FILE_PATH";
785
	static final String RMD_FILE_PATH_KEY = "RMD_FILE_PATH";
743
786
744
    static final String RMD_FILE_NAME_KEY = "RMD_FILE_NAME";
787
	static final String RMD_FILE_NAME_KEY = "RMD_FILE_NAME";
745
788
746
    static final String RMD_NS_KEY = "RMD_NS";
789
	static final String RMD_NS_KEY = "RMD_NS";
747
790
748
    static final String IMPORT_XSD_KEY = "IMPORT_XSD";
791
	static final String IMPORT_XSD_KEY = "IMPORT_XSD";
749
792
750
    static final String IMPORT_WSDL_KEY = "IMPORT_WSDL";
793
	static final String IMPORT_WSDL_KEY = "IMPORT_WSDL";
751
}
794
}
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/MetadataDescriptorType.java (-11 / +9 lines)
Lines 11-18 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor;
12
package org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor;
13
13
14
import java.util.List;
15
16
import org.eclipse.emf.common.util.EList;
14
import org.eclipse.emf.common.util.EList;
17
15
18
import org.eclipse.emf.ecore.util.FeatureMap;
16
import org.eclipse.emf.ecore.util.FeatureMap;
Lines 82-94 Link Here
82
	 * </p>
80
	 * </p>
83
	 * <!-- end-user-doc -->
81
	 * <!-- end-user-doc -->
84
	 * @return the value of the '<em>Interface</em>' attribute.
82
	 * @return the value of the '<em>Interface</em>' attribute.
85
	 * @see #setInterface(Object)
83
	 * @see #setInterface(String)
86
	 * @see org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorPackage#getMetadataDescriptorType_Interface()
84
	 * @see org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorPackage#getMetadataDescriptorType_Interface()
87
	 * @model unique="false" dataType="org.eclipse.emf.ecore.xml.type.QName" required="true"
85
	 * @model unique="false" dataType="org.eclipse.emf.ecore.xml.type.NCName" required="true"
88
	 *        extendedMetaData="kind='attribute' name='interface'"
86
	 *        extendedMetaData="kind='attribute' name='interface'"
89
	 * @generated
87
	 * @generated
90
	 */
88
	 */
91
	Object getInterface();
89
	String getInterface();
92
90
93
	/**
91
	/**
94
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorType#getInterface <em>Interface</em>}' attribute.
92
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorType#getInterface <em>Interface</em>}' attribute.
Lines 98-104 Link Here
98
	 * @see #getInterface()
96
	 * @see #getInterface()
99
	 * @generated
97
	 * @generated
100
	 */
98
	 */
101
	void setInterface(Object value);
99
	void setInterface(String value);
102
100
103
	/**
101
	/**
104
	 * Returns the value of the '<em><b>Name</b></em>' attribute.
102
	 * Returns the value of the '<em><b>Name</b></em>' attribute.
Lines 136-148 Link Here
136
	 * </p>
134
	 * </p>
137
	 * <!-- end-user-doc -->
135
	 * <!-- end-user-doc -->
138
	 * @return the value of the '<em>Wsdl Location</em>' attribute.
136
	 * @return the value of the '<em>Wsdl Location</em>' attribute.
139
	 * @see #setWsdlLocation(List)
137
	 * @see #setWsdlLocation(String)
140
	 * @see org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorPackage#getMetadataDescriptorType_WsdlLocation()
138
	 * @see org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorPackage#getMetadataDescriptorType_WsdlLocation()
141
	 * @model unique="false" dataType="org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PairsOfURIType" many="false"
139
	 * @model unique="false" dataType="org.eclipse.emf.ecore.xml.type.String"
142
	 *        extendedMetaData="kind='attribute' name='wsdlLocation'"
140
	 *        extendedMetaData="kind='attribute' name='wsdlLocation'"
143
	 * @generated
141
	 * @generated
144
	 */
142
	 */
145
	List getWsdlLocation();
143
	String getWsdlLocation();
146
144
147
	/**
145
	/**
148
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorType#getWsdlLocation <em>Wsdl Location</em>}' attribute.
146
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorType#getWsdlLocation <em>Wsdl Location</em>}' attribute.
Lines 152-158 Link Here
152
	 * @see #getWsdlLocation()
150
	 * @see #getWsdlLocation()
153
	 * @generated
151
	 * @generated
154
	 */
152
	 */
155
	void setWsdlLocation(List value);
153
	void setWsdlLocation(String value);
156
154
157
	/**
155
	/**
158
	 * Returns the value of the '<em><b>Any Attribute</b></em>' attribute list.
156
	 * Returns the value of the '<em><b>Any Attribute</b></em>' attribute list.
Lines 171-174 Link Here
171
	 */
169
	 */
172
	FeatureMap getAnyAttribute();
170
	FeatureMap getAnyAttribute();
173
171
174
} // MetadataDescriptorType
172
} // MetadataDescriptorType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/DefinitionsType.java (-1 / +1 lines)
Lines 113-116 Link Here
113
	 */
113
	 */
114
	FeatureMap getAnyAttribute();
114
	FeatureMap getAnyAttribute();
115
115
116
} // DefinitionsType
116
} // DefinitionsType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/DocumentRoot.java (-1 / +1 lines)
Lines 397-400 Link Here
397
	 */
397
	 */
398
	void setDescriptorLocation(String value);
398
	void setDescriptorLocation(String value);
399
399
400
} // DocumentRoot
400
} // DocumentRoot
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/DocumentedType.java (-1 / +1 lines)
Lines 57-60 Link Here
57
	 */
57
	 */
58
	void setDocumentation(DocumentationType value);
58
	void setDocumentation(DocumentationType value);
59
59
60
} // DocumentedType
60
} // DocumentedType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/DocumentationType.java (-1 / +1 lines)
Lines 85-88 Link Here
85
	 */
85
	 */
86
	FeatureMap getAnyAttribute();
86
	FeatureMap getAnyAttribute();
87
87
88
} // DocumentationType
88
} // DocumentationType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/StaticValuesType.java (-1 / +1 lines)
Lines 113-116 Link Here
113
	 */
113
	 */
114
	FeatureMap getAnyAttribute();
114
	FeatureMap getAnyAttribute();
115
115
116
} // StaticValuesType
116
} // StaticValuesType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/MetadataDescriptorReferenceType.java (-1 / +1 lines)
Lines 24-27 Link Here
24
 * @generated
24
 * @generated
25
 */
25
 */
26
public interface MetadataDescriptorReferenceType extends EndpointReferenceType {
26
public interface MetadataDescriptorReferenceType extends EndpointReferenceType {
27
} // MetadataDescriptorReferenceType
27
} // MetadataDescriptorReferenceType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/InitialValuesType.java (-1 / +1 lines)
Lines 113-116 Link Here
113
	 */
113
	 */
114
	FeatureMap getAnyAttribute();
114
	FeatureMap getAnyAttribute();
115
115
116
} // InitialValuesType
116
} // InitialValuesType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/PropertyType.java (-5 / +5 lines)
Lines 289-301 Link Here
289
	 * </p>
289
	 * </p>
290
	 * <!-- end-user-doc -->
290
	 * <!-- end-user-doc -->
291
	 * @return the value of the '<em>Name</em>' attribute.
291
	 * @return the value of the '<em>Name</em>' attribute.
292
	 * @see #setName(Object)
292
	 * @see #setName(String)
293
	 * @see org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorPackage#getPropertyType_Name()
293
	 * @see org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorPackage#getPropertyType_Name()
294
	 * @model unique="false" dataType="org.eclipse.emf.ecore.xml.type.QName" required="true"
294
	 * @model unique="false" dataType="org.eclipse.emf.ecore.xml.type.NCName" required="true"
295
	 *        extendedMetaData="kind='attribute' name='name'"
295
	 *        extendedMetaData="kind='attribute' name='name'"
296
	 * @generated
296
	 * @generated
297
	 */
297
	 */
298
	Object getName();
298
	String getName();
299
299
300
	/**
300
	/**
301
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType#getName <em>Name</em>}' attribute.
301
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType#getName <em>Name</em>}' attribute.
Lines 305-311 Link Here
305
	 * @see #getName()
305
	 * @see #getName()
306
	 * @generated
306
	 * @generated
307
	 */
307
	 */
308
	void setName(Object value);
308
	void setName(String value);
309
309
310
	/**
310
	/**
311
	 * Returns the value of the '<em><b>Subscribability</b></em>' attribute.
311
	 * Returns the value of the '<em><b>Subscribability</b></em>' attribute.
Lines 379-382 Link Here
379
	 */
379
	 */
380
	FeatureMap getAnyAttribute();
380
	FeatureMap getAnyAttribute();
381
381
382
} // PropertyType
382
} // PropertyType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/ValidValueRangeType.java (-1 / +1 lines)
Lines 169-172 Link Here
169
	 */
169
	 */
170
	FeatureMap getAnyAttribute();
170
	FeatureMap getAnyAttribute();
171
171
172
} // ValidValueRangeType
172
} // ValidValueRangeType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/ValidValuesType.java (-1 / +1 lines)
Lines 113-116 Link Here
113
	 */
113
	 */
114
	FeatureMap getAnyAttribute();
114
	FeatureMap getAnyAttribute();
115
115
116
} // ValidValuesType
116
} // ValidValuesType
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/StaticValuesTypeImpl.java (-1 / +1 lines)
Lines 264-267 Link Here
264
		return result.toString();
264
		return result.toString();
265
	}
265
	}
266
266
267
} //StaticValuesTypeImpl
267
} //StaticValuesTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/ValidValuesTypeImpl.java (-1 / +1 lines)
Lines 264-267 Link Here
264
		return result.toString();
264
		return result.toString();
265
	}
265
	}
266
266
267
} //ValidValuesTypeImpl
267
} //ValidValuesTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/DocumentedTypeImpl.java (-1 / +1 lines)
Lines 176-179 Link Here
176
		return super.eIsSet(featureID);
176
		return super.eIsSet(featureID);
177
	}
177
	}
178
178
179
} //DocumentedTypeImpl
179
} //DocumentedTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/DocumentationTypeImpl.java (-1 / +1 lines)
Lines 223-226 Link Here
223
		return result.toString();
223
		return result.toString();
224
	}
224
	}
225
225
226
} //DocumentationTypeImpl
226
} //DocumentationTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/MetadataDescriptorPackageImpl.java (-3 / +3 lines)
Lines 1133-1141 Link Here
1133
		initEClass(metadataDescriptorTypeEClass, MetadataDescriptorType.class, "MetadataDescriptorType", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
1133
		initEClass(metadataDescriptorTypeEClass, MetadataDescriptorType.class, "MetadataDescriptorType", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
1134
		initEReference(getMetadataDescriptorType_Property(), this.getPropertyType(), null, "property", null, 0, -1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1134
		initEReference(getMetadataDescriptorType_Property(), this.getPropertyType(), null, "property", null, 0, -1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1135
		initEAttribute(getMetadataDescriptorType_Any(), ecorePackage.getEFeatureMapEntry(), "any", null, 0, -1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1135
		initEAttribute(getMetadataDescriptorType_Any(), ecorePackage.getEFeatureMapEntry(), "any", null, 0, -1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1136
		initEAttribute(getMetadataDescriptorType_Interface(), theXMLTypePackage.getQName(), "interface", null, 1, 1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1136
		initEAttribute(getMetadataDescriptorType_Interface(), theXMLTypePackage.getNCName(), "interface", null, 1, 1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1137
		initEAttribute(getMetadataDescriptorType_Name(), theXMLTypePackage.getNCName(), "name", null, 1, 1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1137
		initEAttribute(getMetadataDescriptorType_Name(), theXMLTypePackage.getNCName(), "name", null, 1, 1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1138
		initEAttribute(getMetadataDescriptorType_WsdlLocation(), this.getPairsOfURIType(), "wsdlLocation", null, 0, 1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1138
		initEAttribute(getMetadataDescriptorType_WsdlLocation(), theXMLTypePackage.getString(), "wsdlLocation", null, 0, 1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1139
		initEAttribute(getMetadataDescriptorType_AnyAttribute(), ecorePackage.getEFeatureMapEntry(), "anyAttribute", null, 0, -1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1139
		initEAttribute(getMetadataDescriptorType_AnyAttribute(), ecorePackage.getEFeatureMapEntry(), "anyAttribute", null, 0, -1, MetadataDescriptorType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1140
1140
1141
		initEClass(propertyTypeEClass, PropertyType.class, "PropertyType", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
1141
		initEClass(propertyTypeEClass, PropertyType.class, "PropertyType", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
Lines 1146-1152 Link Here
1146
		initEAttribute(getPropertyType_Any(), ecorePackage.getEFeatureMapEntry(), "any", null, 0, -1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1146
		initEAttribute(getPropertyType_Any(), ecorePackage.getEFeatureMapEntry(), "any", null, 0, -1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1147
		initEAttribute(getPropertyType_Modifiability(), this.getModifiabilityType(), "modifiability", "read-only", 0, 1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1147
		initEAttribute(getPropertyType_Modifiability(), this.getModifiabilityType(), "modifiability", "read-only", 0, 1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1148
		initEAttribute(getPropertyType_Mutability(), this.getMutabilityType(), "mutability", "constant", 0, 1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1148
		initEAttribute(getPropertyType_Mutability(), this.getMutabilityType(), "mutability", "constant", 0, 1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1149
		initEAttribute(getPropertyType_Name(), theXMLTypePackage.getQName(), "name", null, 1, 1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1149
		initEAttribute(getPropertyType_Name(), theXMLTypePackage.getNCName(), "name", null, 1, 1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1150
		initEAttribute(getPropertyType_Subscribability(), theXMLTypePackage.getBoolean(), "subscribability", "false", 0, 1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1150
		initEAttribute(getPropertyType_Subscribability(), theXMLTypePackage.getBoolean(), "subscribability", "false", 0, 1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1151
		initEAttribute(getPropertyType_AnyAttribute(), ecorePackage.getEFeatureMapEntry(), "anyAttribute", null, 0, -1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1151
		initEAttribute(getPropertyType_AnyAttribute(), ecorePackage.getEFeatureMapEntry(), "anyAttribute", null, 0, -1, PropertyType.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
1152
1152
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/MetadataDescriptorTypeImpl.java (-14 / +13 lines)
Lines 12-18 Link Here
12
package org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl;
12
package org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl;
13
13
14
import java.util.Collection;
14
import java.util.Collection;
15
import java.util.List;
16
15
17
import org.eclipse.emf.common.notify.Notification;
16
import org.eclipse.emf.common.notify.Notification;
18
import org.eclipse.emf.common.notify.NotificationChain;
17
import org.eclipse.emf.common.notify.NotificationChain;
Lines 80-86 Link Here
80
	 * @generated
79
	 * @generated
81
	 * @ordered
80
	 * @ordered
82
	 */
81
	 */
83
	protected static final Object INTERFACE_EDEFAULT = null;
82
	protected static final String INTERFACE_EDEFAULT = null;
84
83
85
	/**
84
	/**
86
	 * The cached value of the '{@link #getInterface() <em>Interface</em>}' attribute.
85
	 * The cached value of the '{@link #getInterface() <em>Interface</em>}' attribute.
Lines 90-96 Link Here
90
	 * @generated
89
	 * @generated
91
	 * @ordered
90
	 * @ordered
92
	 */
91
	 */
93
	protected Object interface_ = INTERFACE_EDEFAULT;
92
	protected String interface_ = INTERFACE_EDEFAULT;
94
93
95
	/**
94
	/**
96
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
95
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
Lines 120-126 Link Here
120
	 * @generated
119
	 * @generated
121
	 * @ordered
120
	 * @ordered
122
	 */
121
	 */
123
	protected static final List WSDL_LOCATION_EDEFAULT = null;
122
	protected static final String WSDL_LOCATION_EDEFAULT = null;
124
123
125
	/**
124
	/**
126
	 * The cached value of the '{@link #getWsdlLocation() <em>Wsdl Location</em>}' attribute.
125
	 * The cached value of the '{@link #getWsdlLocation() <em>Wsdl Location</em>}' attribute.
Lines 130-136 Link Here
130
	 * @generated
129
	 * @generated
131
	 * @ordered
130
	 * @ordered
132
	 */
131
	 */
133
	protected List wsdlLocation = WSDL_LOCATION_EDEFAULT;
132
	protected String wsdlLocation = WSDL_LOCATION_EDEFAULT;
134
133
135
	/**
134
	/**
136
	 * The cached value of the '{@link #getAnyAttribute() <em>Any Attribute</em>}' attribute list.
135
	 * The cached value of the '{@link #getAnyAttribute() <em>Any Attribute</em>}' attribute list.
Lines 189-195 Link Here
189
	 * <!-- end-user-doc -->
188
	 * <!-- end-user-doc -->
190
	 * @generated
189
	 * @generated
191
	 */
190
	 */
192
	public Object getInterface() {
191
	public String getInterface() {
193
		return interface_;
192
		return interface_;
194
	}
193
	}
195
194
Lines 198-205 Link Here
198
	 * <!-- end-user-doc -->
197
	 * <!-- end-user-doc -->
199
	 * @generated
198
	 * @generated
200
	 */
199
	 */
201
	public void setInterface(Object newInterface) {
200
	public void setInterface(String newInterface) {
202
		Object oldInterface = interface_;
201
		String oldInterface = interface_;
203
		interface_ = newInterface;
202
		interface_ = newInterface;
204
		if (eNotificationRequired())
203
		if (eNotificationRequired())
205
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__INTERFACE, oldInterface, interface_));
204
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__INTERFACE, oldInterface, interface_));
Lines 231-237 Link Here
231
	 * <!-- end-user-doc -->
230
	 * <!-- end-user-doc -->
232
	 * @generated
231
	 * @generated
233
	 */
232
	 */
234
	public List getWsdlLocation() {
233
	public String getWsdlLocation() {
235
		return wsdlLocation;
234
		return wsdlLocation;
236
	}
235
	}
237
236
Lines 240-247 Link Here
240
	 * <!-- end-user-doc -->
239
	 * <!-- end-user-doc -->
241
	 * @generated
240
	 * @generated
242
	 */
241
	 */
243
	public void setWsdlLocation(List newWsdlLocation) {
242
	public void setWsdlLocation(String newWsdlLocation) {
244
		List oldWsdlLocation = wsdlLocation;
243
		String oldWsdlLocation = wsdlLocation;
245
		wsdlLocation = newWsdlLocation;
244
		wsdlLocation = newWsdlLocation;
246
		if (eNotificationRequired())
245
		if (eNotificationRequired())
247
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__WSDL_LOCATION, oldWsdlLocation, wsdlLocation));
246
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__WSDL_LOCATION, oldWsdlLocation, wsdlLocation));
Lines 316-328 Link Here
316
				((FeatureMap.Internal)getAny()).set(newValue);
315
				((FeatureMap.Internal)getAny()).set(newValue);
317
				return;
316
				return;
318
			case MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__INTERFACE:
317
			case MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__INTERFACE:
319
				setInterface((Object)newValue);
318
				setInterface((String)newValue);
320
				return;
319
				return;
321
			case MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__NAME:
320
			case MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__NAME:
322
				setName((String)newValue);
321
				setName((String)newValue);
323
				return;
322
				return;
324
			case MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__WSDL_LOCATION:
323
			case MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__WSDL_LOCATION:
325
				setWsdlLocation((List)newValue);
324
				setWsdlLocation((String)newValue);
326
				return;
325
				return;
327
			case MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__ANY_ATTRIBUTE:
326
			case MetadataDescriptorPackage.METADATA_DESCRIPTOR_TYPE__ANY_ATTRIBUTE:
328
				((FeatureMap.Internal)getAnyAttribute()).set(newValue);
327
				((FeatureMap.Internal)getAnyAttribute()).set(newValue);
Lines 406-409 Link Here
406
		return result.toString();
405
		return result.toString();
407
	}
406
	}
408
407
409
} //MetadataDescriptorTypeImpl
408
} //MetadataDescriptorTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/DocumentRootImpl.java (-1 / +1 lines)
Lines 718-721 Link Here
718
		return result.toString();
718
		return result.toString();
719
	}
719
	}
720
720
721
} //DocumentRootImpl
721
} //DocumentRootImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/ValidValueRangeTypeImpl.java (-1 / +1 lines)
Lines 374-377 Link Here
374
		return result.toString();
374
		return result.toString();
375
	}
375
	}
376
376
377
} //ValidValueRangeTypeImpl
377
} //ValidValueRangeTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/InitialValuesTypeImpl.java (-1 / +1 lines)
Lines 264-267 Link Here
264
		return result.toString();
264
		return result.toString();
265
	}
265
	}
266
266
267
} //InitialValuesTypeImpl
267
} //InitialValuesTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/MetadataDescriptorReferenceTypeImpl.java (-1 / +1 lines)
Lines 46-49 Link Here
46
		return MetadataDescriptorPackage.Literals.METADATA_DESCRIPTOR_REFERENCE_TYPE;
46
		return MetadataDescriptorPackage.Literals.METADATA_DESCRIPTOR_REFERENCE_TYPE;
47
	}
47
	}
48
48
49
} //MetadataDescriptorReferenceTypeImpl
49
} //MetadataDescriptorReferenceTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/PropertyTypeImpl.java (-7 / +7 lines)
Lines 171-177 Link Here
171
	 * @generated
171
	 * @generated
172
	 * @ordered
172
	 * @ordered
173
	 */
173
	 */
174
	protected static final Object NAME_EDEFAULT = null;
174
	protected static final String NAME_EDEFAULT = null;
175
175
176
	/**
176
	/**
177
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
177
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
Lines 181-187 Link Here
181
	 * @generated
181
	 * @generated
182
	 * @ordered
182
	 * @ordered
183
	 */
183
	 */
184
	protected Object name = NAME_EDEFAULT;
184
	protected String name = NAME_EDEFAULT;
185
185
186
	/**
186
	/**
187
	 * The default value of the '{@link #isSubscribability() <em>Subscribability</em>}' attribute.
187
	 * The default value of the '{@link #isSubscribability() <em>Subscribability</em>}' attribute.
Lines 521-527 Link Here
521
	 * <!-- end-user-doc -->
521
	 * <!-- end-user-doc -->
522
	 * @generated
522
	 * @generated
523
	 */
523
	 */
524
	public Object getName() {
524
	public String getName() {
525
		return name;
525
		return name;
526
	}
526
	}
527
527
Lines 530-537 Link Here
530
	 * <!-- end-user-doc -->
530
	 * <!-- end-user-doc -->
531
	 * @generated
531
	 * @generated
532
	 */
532
	 */
533
	public void setName(Object newName) {
533
	public void setName(String newName) {
534
		Object oldName = name;
534
		String oldName = name;
535
		name = newName;
535
		name = newName;
536
		if (eNotificationRequired())
536
		if (eNotificationRequired())
537
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataDescriptorPackage.PROPERTY_TYPE__NAME, oldName, name));
537
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataDescriptorPackage.PROPERTY_TYPE__NAME, oldName, name));
Lines 680-686 Link Here
680
				setMutability((MutabilityType)newValue);
680
				setMutability((MutabilityType)newValue);
681
				return;
681
				return;
682
			case MetadataDescriptorPackage.PROPERTY_TYPE__NAME:
682
			case MetadataDescriptorPackage.PROPERTY_TYPE__NAME:
683
				setName((Object)newValue);
683
				setName((String)newValue);
684
				return;
684
				return;
685
			case MetadataDescriptorPackage.PROPERTY_TYPE__SUBSCRIBABILITY:
685
			case MetadataDescriptorPackage.PROPERTY_TYPE__SUBSCRIBABILITY:
686
				setSubscribability(((Boolean)newValue).booleanValue());
686
				setSubscribability(((Boolean)newValue).booleanValue());
Lines 789-792 Link Here
789
		return result.toString();
789
		return result.toString();
790
	}
790
	}
791
791
792
} //PropertyTypeImpl
792
} //PropertyTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/metadataDescriptor/impl/DefinitionsTypeImpl.java (-1 / +1 lines)
Lines 297-300 Link Here
297
		return result.toString();
297
		return result.toString();
298
	}
298
	}
299
299
300
} //DefinitionsTypeImpl
300
} //DefinitionsTypeImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/util/CapabilitiesAdapterFactory.java (+36 lines)
Lines 20-25 Link Here
20
20
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.*;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.*;
22
22
23
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
24
23
/**
25
/**
24
 * <!-- begin-user-doc -->
26
 * <!-- begin-user-doc -->
25
 * The <b>Adapter Factory</b> for the model.
27
 * The <b>Adapter Factory</b> for the model.
Lines 87-92 Link Here
87
			public Object caseProperty(Property object) {
89
			public Object caseProperty(Property object) {
88
				return createPropertyAdapter();
90
				return createPropertyAdapter();
89
			}
91
			}
92
			public Object caseMetadata(MetadataDescriptor object) {
93
				return createMetadataAdapter();
94
			}
95
			public Object caseMetrics(Metrics object) {
96
				return createMetricsAdapter();
97
			}
90
			public Object defaultCase(EObject object) {
98
			public Object defaultCase(EObject object) {
91
				return createEObjectAdapter();
99
				return createEObjectAdapter();
92
			}
100
			}
Lines 162-167 Link Here
162
	}
170
	}
163
171
164
	/**
172
	/**
173
	 * Creates a new adapter for an object of class '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor <em>Metadata</em>}'.
174
	 * <!-- begin-user-doc -->
175
	 * This default implementation returns null so that we can easily ignore cases;
176
	 * it's useful to ignore a case when inheritance will catch all the cases anyway.
177
	 * <!-- end-user-doc -->
178
	 * @return the new adapter.
179
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor
180
	 * @generated
181
	 */
182
	public Adapter createMetadataAdapter() {
183
		return null;
184
	}
185
186
	/**
187
	 * Creates a new adapter for an object of class '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics <em>Metrics</em>}'.
188
	 * <!-- begin-user-doc -->
189
	 * This default implementation returns null so that we can easily ignore cases;
190
	 * it's useful to ignore a case when inheritance will catch all the cases anyway.
191
	 * <!-- end-user-doc -->
192
	 * @return the new adapter.
193
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics
194
	 * @generated
195
	 */
196
	public Adapter createMetricsAdapter() {
197
		return null;
198
	}
199
200
	/**
165
	 * Creates a new adapter for the default case.
201
	 * Creates a new adapter for the default case.
166
	 * <!-- begin-user-doc -->
202
	 * <!-- begin-user-doc -->
167
	 * This default implementation returns null.
203
	 * This default implementation returns null.
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/util/CapabilitiesSwitch.java (+38 lines)
Lines 18-23 Link Here
18
18
19
import org.eclipse.tptp.wsdm.tooling.model.capabilities.*;
19
import org.eclipse.tptp.wsdm.tooling.model.capabilities.*;
20
20
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
22
21
/**
23
/**
22
 * <!-- begin-user-doc -->
24
 * <!-- begin-user-doc -->
23
 * The <b>Switch</b> for the model's inheritance hierarchy.
25
 * The <b>Switch</b> for the model's inheritance hierarchy.
Lines 116-121 Link Here
116
				if (result == null) result = defaultCase(theEObject);
118
				if (result == null) result = defaultCase(theEObject);
117
				return result;
119
				return result;
118
			}
120
			}
121
			case CapabilitiesPackage.METRICS: {
122
				Metrics metrics = (Metrics)theEObject;
123
				Object result = caseMetrics(metrics);
124
				if (result == null) result = defaultCase(theEObject);
125
				return result;
126
			}
119
			default: return defaultCase(theEObject);
127
			default: return defaultCase(theEObject);
120
		}
128
		}
121
	}
129
	}
Lines 181-186 Link Here
181
	}
189
	}
182
190
183
	/**
191
	/**
192
	 * Returns the result of interpretting the object as an instance of '<em>Metadata</em>'.
193
	 * <!-- begin-user-doc -->
194
	 * This implementation returns null;
195
	 * returning a non-null result will terminate the switch.
196
	 * <!-- end-user-doc -->
197
	 * @param object the target of the switch.
198
	 * @return the result of interpretting the object as an instance of '<em>Metadata</em>'.
199
	 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
200
	 * @generated
201
	 */
202
	public Object caseMetadata(MetadataDescriptor object) {
203
		return null;
204
	}
205
206
	/**
207
	 * Returns the result of interpretting the object as an instance of '<em>Metrics</em>'.
208
	 * <!-- begin-user-doc -->
209
	 * This implementation returns null;
210
	 * returning a non-null result will terminate the switch.
211
	 * <!-- end-user-doc -->
212
	 * @param object the target of the switch.
213
	 * @return the result of interpretting the object as an instance of '<em>Metrics</em>'.
214
	 * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
215
	 * @generated
216
	 */
217
	public Object caseMetrics(Metrics object) {
218
		return null;
219
	}
220
221
	/**
184
	 * Returns the result of interpretting the object as an instance of '<em>EObject</em>'.
222
	 * Returns the result of interpretting the object as an instance of '<em>EObject</em>'.
185
	 * <!-- begin-user-doc -->
223
	 * <!-- begin-user-doc -->
186
	 * This implementation returns null;
224
	 * This implementation returns null;
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/CapabilitiesPackage.java (-3 / +280 lines)
Lines 138-150 Link Here
138
	int CAPABILITY__TOPIC_SPACES = 6;
138
	int CAPABILITY__TOPIC_SPACES = 6;
139
139
140
	/**
140
	/**
141
	 * The feature id for the '<em><b>Definition</b></em>' reference.
142
	 * <!-- begin-user-doc -->
143
	 * <!-- end-user-doc -->
144
	 * @generated
145
	 * @ordered
146
	 */
147
	int CAPABILITY__DEFINITION = 7;
148
149
	/**
150
	 * The feature id for the '<em><b>Metadata</b></em>' reference.
151
	 * <!-- begin-user-doc -->
152
	 * <!-- end-user-doc -->
153
	 * @generated
154
	 * @ordered
155
	 */
156
	int CAPABILITY__METADATA = 8;
157
158
	/**
141
	 * The number of structural features of the '<em>Capability</em>' class.
159
	 * The number of structural features of the '<em>Capability</em>' class.
142
	 * <!-- begin-user-doc -->
160
	 * <!-- begin-user-doc -->
143
	 * <!-- end-user-doc -->
161
	 * <!-- end-user-doc -->
144
	 * @generated
162
	 * @generated
145
	 * @ordered
163
	 * @ordered
146
	 */
164
	 */
147
	int CAPABILITY_FEATURE_COUNT = 7;
165
	int CAPABILITY_FEATURE_COUNT = 9;
148
166
149
	/**
167
	/**
150
	 * The meta object id for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.TopicSpaceImpl <em>Topic Space</em>}' class.
168
	 * The meta object id for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.TopicSpaceImpl <em>Topic Space</em>}' class.
Lines 303-315 Link Here
303
	int PROPERTY__META_DATA = 1;
321
	int PROPERTY__META_DATA = 1;
304
322
305
	/**
323
	/**
324
	 * The feature id for the '<em><b>Metrics</b></em>' reference.
325
	 * <!-- begin-user-doc -->
326
	 * <!-- end-user-doc -->
327
	 * @generated
328
	 * @ordered
329
	 */
330
	int PROPERTY__METRICS = 2;
331
332
	/**
306
	 * The number of structural features of the '<em>Property</em>' class.
333
	 * The number of structural features of the '<em>Property</em>' class.
307
	 * <!-- begin-user-doc -->
334
	 * <!-- begin-user-doc -->
308
	 * <!-- end-user-doc -->
335
	 * <!-- end-user-doc -->
309
	 * @generated
336
	 * @generated
310
	 * @ordered
337
	 * @ordered
311
	 */
338
	 */
312
	int PROPERTY_FEATURE_COUNT = 2;
339
	int PROPERTY_FEATURE_COUNT = 3;
340
341
342
	/**
343
	 * The meta object id for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor <em>Metadata</em>}' class.
344
	 * <!-- begin-user-doc -->
345
	 * <!-- end-user-doc -->
346
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor
347
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilitiesPackageImpl#getMetadata()
348
	 * @generated
349
	 */
350
	int METADATA = 4;
351
352
	/**
353
	 * The number of structural features of the '<em>Metadata</em>' class.
354
	 * <!-- begin-user-doc -->
355
	 * <!-- end-user-doc -->
356
	 * @generated
357
	 * @ordered
358
	 */
359
	int METADATA_FEATURE_COUNT = 0;
360
361
362
	/**
363
	 * The meta object id for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetricsImpl <em>Metrics</em>}' class.
364
	 * <!-- begin-user-doc -->
365
	 * <!-- end-user-doc -->
366
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetricsImpl
367
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilitiesPackageImpl#getMetrics()
368
	 * @generated
369
	 */
370
	int METRICS = 5;
371
372
	/**
373
	 * The feature id for the '<em><b>Change Type</b></em>' attribute.
374
	 * <!-- begin-user-doc -->
375
	 * <!-- end-user-doc -->
376
	 * @generated
377
	 * @ordered
378
	 */
379
	int METRICS__CHANGE_TYPE = 0;
380
381
	/**
382
	 * The feature id for the '<em><b>Time Scope</b></em>' attribute.
383
	 * <!-- begin-user-doc -->
384
	 * <!-- end-user-doc -->
385
	 * @generated
386
	 * @ordered
387
	 */
388
	int METRICS__TIME_SCOPE = 1;
389
390
	/**
391
	 * The feature id for the '<em><b>Gathering Time</b></em>' attribute.
392
	 * <!-- begin-user-doc -->
393
	 * <!-- end-user-doc -->
394
	 * @generated
395
	 * @ordered
396
	 */
397
	int METRICS__GATHERING_TIME = 2;
398
399
	/**
400
	 * The feature id for the '<em><b>Calculation Interval</b></em>' attribute.
401
	 * <!-- begin-user-doc -->
402
	 * <!-- end-user-doc -->
403
	 * @generated
404
	 * @ordered
405
	 */
406
	int METRICS__CALCULATION_INTERVAL = 3;
407
408
	/**
409
	 * The number of structural features of the '<em>Metrics</em>' class.
410
	 * <!-- begin-user-doc -->
411
	 * <!-- end-user-doc -->
412
	 * @generated
413
	 * @ordered
414
	 */
415
	int METRICS_FEATURE_COUNT = 4;
313
416
314
417
315
	/**
418
	/**
Lines 400-405 Link Here
400
	EReference getCapability_TopicSpaces();
503
	EReference getCapability_TopicSpaces();
401
504
402
	/**
505
	/**
506
	 * Returns the meta object for the reference '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getDefinition <em>Definition</em>}'.
507
	 * <!-- begin-user-doc -->
508
	 * <!-- end-user-doc -->
509
	 * @return the meta object for the reference '<em>Definition</em>'.
510
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getDefinition()
511
	 * @see #getCapability()
512
	 * @generated
513
	 */
514
	EReference getCapability_Definition();
515
516
	/**
517
	 * Returns the meta object for the reference '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getMetadata <em>Metadata</em>}'.
518
	 * <!-- begin-user-doc -->
519
	 * <!-- end-user-doc -->
520
	 * @return the meta object for the reference '<em>Metadata</em>'.
521
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getMetadata()
522
	 * @see #getCapability()
523
	 * @generated
524
	 */
525
	EReference getCapability_Metadata();
526
527
	/**
403
	 * Returns the meta object for class '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace <em>Topic Space</em>}'.
528
	 * Returns the meta object for class '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace <em>Topic Space</em>}'.
404
	 * <!-- begin-user-doc -->
529
	 * <!-- begin-user-doc -->
405
	 * <!-- end-user-doc -->
530
	 * <!-- end-user-doc -->
Lines 562-567 Link Here
562
	EReference getProperty_MetaData();
687
	EReference getProperty_MetaData();
563
688
564
	/**
689
	/**
690
	 * Returns the meta object for the reference '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Property#getMetrics <em>Metrics</em>}'.
691
	 * <!-- begin-user-doc -->
692
	 * <!-- end-user-doc -->
693
	 * @return the meta object for the reference '<em>Metrics</em>'.
694
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Property#getMetrics()
695
	 * @see #getProperty()
696
	 * @generated
697
	 */
698
	EReference getProperty_Metrics();
699
700
	/**
701
	 * Returns the meta object for class '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor <em>Metadata</em>}'.
702
	 * <!-- begin-user-doc -->
703
	 * <!-- end-user-doc -->
704
	 * @return the meta object for class '<em>Metadata</em>'.
705
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor
706
	 * @model instanceClass="org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor"
707
	 * @generated
708
	 */
709
	EClass getMetadata();
710
711
	/**
712
	 * Returns the meta object for class '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics <em>Metrics</em>}'.
713
	 * <!-- begin-user-doc -->
714
	 * <!-- end-user-doc -->
715
	 * @return the meta object for class '<em>Metrics</em>'.
716
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics
717
	 * @generated
718
	 */
719
	EClass getMetrics();
720
721
	/**
722
	 * Returns the meta object for the attribute '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getChangeType <em>Change Type</em>}'.
723
	 * <!-- begin-user-doc -->
724
	 * <!-- end-user-doc -->
725
	 * @return the meta object for the attribute '<em>Change Type</em>'.
726
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getChangeType()
727
	 * @see #getMetrics()
728
	 * @generated
729
	 */
730
	EAttribute getMetrics_ChangeType();
731
732
	/**
733
	 * Returns the meta object for the attribute '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getTimeScope <em>Time Scope</em>}'.
734
	 * <!-- begin-user-doc -->
735
	 * <!-- end-user-doc -->
736
	 * @return the meta object for the attribute '<em>Time Scope</em>'.
737
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getTimeScope()
738
	 * @see #getMetrics()
739
	 * @generated
740
	 */
741
	EAttribute getMetrics_TimeScope();
742
743
	/**
744
	 * Returns the meta object for the attribute '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getGatheringTime <em>Gathering Time</em>}'.
745
	 * <!-- begin-user-doc -->
746
	 * <!-- end-user-doc -->
747
	 * @return the meta object for the attribute '<em>Gathering Time</em>'.
748
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getGatheringTime()
749
	 * @see #getMetrics()
750
	 * @generated
751
	 */
752
	EAttribute getMetrics_GatheringTime();
753
754
	/**
755
	 * Returns the meta object for the attribute '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getCalculationInterval <em>Calculation Interval</em>}'.
756
	 * <!-- begin-user-doc -->
757
	 * <!-- end-user-doc -->
758
	 * @return the meta object for the attribute '<em>Calculation Interval</em>'.
759
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getCalculationInterval()
760
	 * @see #getMetrics()
761
	 * @generated
762
	 */
763
	EAttribute getMetrics_CalculationInterval();
764
765
	/**
565
	 * Returns the factory that creates the instances of the model.
766
	 * Returns the factory that creates the instances of the model.
566
	 * <!-- begin-user-doc -->
767
	 * <!-- begin-user-doc -->
567
	 * <!-- end-user-doc -->
768
	 * <!-- end-user-doc -->
Lines 582-588 Link Here
582
	 * <!-- end-user-doc -->
783
	 * <!-- end-user-doc -->
583
	 * @generated
784
	 * @generated
584
	 */
785
	 */
585
	interface Literals {
786
	interface Literals  {
586
		/**
787
		/**
587
		 * The meta object literal for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl <em>Capability</em>}' class.
788
		 * The meta object literal for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl <em>Capability</em>}' class.
588
		 * <!-- begin-user-doc -->
789
		 * <!-- begin-user-doc -->
Lines 650-655 Link Here
650
		EReference CAPABILITY__TOPIC_SPACES = eINSTANCE.getCapability_TopicSpaces();
851
		EReference CAPABILITY__TOPIC_SPACES = eINSTANCE.getCapability_TopicSpaces();
651
852
652
		/**
853
		/**
854
		 * The meta object literal for the '<em><b>Definition</b></em>' reference feature.
855
		 * <!-- begin-user-doc -->
856
		 * <!-- end-user-doc -->
857
		 * @generated
858
		 */
859
		EReference CAPABILITY__DEFINITION = eINSTANCE.getCapability_Definition();
860
861
		/**
862
		 * The meta object literal for the '<em><b>Metadata</b></em>' reference feature.
863
		 * <!-- begin-user-doc -->
864
		 * <!-- end-user-doc -->
865
		 * @generated
866
		 */
867
		EReference CAPABILITY__METADATA = eINSTANCE.getCapability_Metadata();
868
869
		/**
653
		 * The meta object literal for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.TopicSpaceImpl <em>Topic Space</em>}' class.
870
		 * The meta object literal for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.TopicSpaceImpl <em>Topic Space</em>}' class.
654
		 * <!-- begin-user-doc -->
871
		 * <!-- begin-user-doc -->
655
		 * <!-- end-user-doc -->
872
		 * <!-- end-user-doc -->
Lines 775-780 Link Here
775
		 */
992
		 */
776
		EReference PROPERTY__META_DATA = eINSTANCE.getProperty_MetaData();
993
		EReference PROPERTY__META_DATA = eINSTANCE.getProperty_MetaData();
777
994
995
		/**
996
		 * The meta object literal for the '<em><b>Metrics</b></em>' reference feature.
997
		 * <!-- begin-user-doc -->
998
		 * <!-- end-user-doc -->
999
		 * @generated
1000
		 */
1001
		EReference PROPERTY__METRICS = eINSTANCE.getProperty_Metrics();
1002
1003
		/**
1004
		 * The meta object literal for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor <em>Metadata</em>}' class.
1005
		 * <!-- begin-user-doc -->
1006
		 * <!-- end-user-doc -->
1007
		 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor
1008
		 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilitiesPackageImpl#getMetadata()
1009
		 * @generated
1010
		 */
1011
		EClass METADATA = eINSTANCE.getMetadata();
1012
1013
			/**
1014
		 * The meta object literal for the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetricsImpl <em>Metrics</em>}' class.
1015
		 * <!-- begin-user-doc -->
1016
		 * <!-- end-user-doc -->
1017
		 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetricsImpl
1018
		 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilitiesPackageImpl#getMetrics()
1019
		 * @generated
1020
		 */
1021
		EClass METRICS = eINSTANCE.getMetrics();
1022
1023
		/**
1024
		 * The meta object literal for the '<em><b>Change Type</b></em>' attribute feature.
1025
		 * <!-- begin-user-doc -->
1026
		 * <!-- end-user-doc -->
1027
		 * @generated
1028
		 */
1029
		EAttribute METRICS__CHANGE_TYPE = eINSTANCE.getMetrics_ChangeType();
1030
1031
		/**
1032
		 * The meta object literal for the '<em><b>Time Scope</b></em>' attribute feature.
1033
		 * <!-- begin-user-doc -->
1034
		 * <!-- end-user-doc -->
1035
		 * @generated
1036
		 */
1037
		EAttribute METRICS__TIME_SCOPE = eINSTANCE.getMetrics_TimeScope();
1038
1039
		/**
1040
		 * The meta object literal for the '<em><b>Gathering Time</b></em>' attribute feature.
1041
		 * <!-- begin-user-doc -->
1042
		 * <!-- end-user-doc -->
1043
		 * @generated
1044
		 */
1045
		EAttribute METRICS__GATHERING_TIME = eINSTANCE.getMetrics_GatheringTime();
1046
1047
		/**
1048
		 * The meta object literal for the '<em><b>Calculation Interval</b></em>' attribute feature.
1049
		 * <!-- begin-user-doc -->
1050
		 * <!-- end-user-doc -->
1051
		 * @generated
1052
		 */
1053
		EAttribute METRICS__CALCULATION_INTERVAL = eINSTANCE.getMetrics_CalculationInterval();
1054
778
	}
1055
	}
779
1056
780
} //CapabilitiesPackage
1057
} //CapabilitiesPackage
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/Property.java (+27 lines)
Lines 27-32 Link Here
27
 * <ul>
27
 * <ul>
28
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Property#getElement <em>Element</em>}</li>
28
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Property#getElement <em>Element</em>}</li>
29
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Property#getMetaData <em>Meta Data</em>}</li>
29
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Property#getMetaData <em>Meta Data</em>}</li>
30
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Property#getMetrics <em>Metrics</em>}</li>
30
 * </ul>
31
 * </ul>
31
 * </p>
32
 * </p>
32
 *
33
 *
Lines 87-90 Link Here
87
	 */
88
	 */
88
	void setMetaData(PropertyType value);
89
	void setMetaData(PropertyType value);
89
90
91
	/**
92
	 * Returns the value of the '<em><b>Metrics</b></em>' reference.
93
	 * <!-- begin-user-doc -->
94
	 * <p>
95
	 * If the meaning of the '<em>Metrics</em>' reference isn't clear,
96
	 * there really should be more of a description here...
97
	 * </p>
98
	 * <!-- end-user-doc -->
99
	 * @return the value of the '<em>Metrics</em>' reference.
100
	 * @see #setMetrics(Metrics)
101
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage#getProperty_Metrics()
102
	 * @model
103
	 * @generated
104
	 */
105
	Metrics getMetrics();
106
107
	/**
108
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Property#getMetrics <em>Metrics</em>}' reference.
109
	 * <!-- begin-user-doc -->
110
	 * <!-- end-user-doc -->
111
	 * @param value the new value of the '<em>Metrics</em>' reference.
112
	 * @see #getMetrics()
113
	 * @generated
114
	 */
115
	void setMetrics(Metrics value);
116
90
} // Property
117
} // Property
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/CapabilitiesFactory.java (+9 lines)
Lines 67-72 Link Here
67
	Property createProperty();
67
	Property createProperty();
68
68
69
	/**
69
	/**
70
	 * Returns a new object of class '<em>Metrics</em>'.
71
	 * <!-- begin-user-doc -->
72
	 * <!-- end-user-doc -->
73
	 * @return a new object of class '<em>Metrics</em>'.
74
	 * @generated
75
	 */
76
	Metrics createMetrics();
77
78
	/**
70
	 * Returns the package supported by this factory.
79
	 * Returns the package supported by this factory.
71
	 * <!-- begin-user-doc -->
80
	 * <!-- begin-user-doc -->
72
	 * <!-- end-user-doc -->
81
	 * <!-- end-user-doc -->
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/Capability.java (+58 lines)
Lines 15-20 Link Here
15
15
16
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EObject;
17
17
18
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
19
20
import org.eclipse.wst.wsdl.Definition;
21
18
/**
22
/**
19
 * <!-- begin-user-doc -->
23
 * <!-- begin-user-doc -->
20
 * A representation of the model object '<em><b>Capability</b></em>'.
24
 * A representation of the model object '<em><b>Capability</b></em>'.
Lines 30-35 Link Here
30
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getProperties <em>Properties</em>}</li>
34
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getProperties <em>Properties</em>}</li>
31
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getOperations <em>Operations</em>}</li>
35
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getOperations <em>Operations</em>}</li>
32
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getTopicSpaces <em>Topic Spaces</em>}</li>
36
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getTopicSpaces <em>Topic Spaces</em>}</li>
37
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getDefinition <em>Definition</em>}</li>
38
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getMetadata <em>Metadata</em>}</li>
33
 * </ul>
39
 * </ul>
34
 * </p>
40
 * </p>
35
 *
41
 *
Lines 190-193 Link Here
190
	 */
196
	 */
191
	EList getTopicSpaces();
197
	EList getTopicSpaces();
192
198
199
	/**
200
	 * Returns the value of the '<em><b>Definition</b></em>' reference.
201
	 * <!-- begin-user-doc -->
202
	 * <p>
203
	 * If the meaning of the '<em>Definition</em>' reference isn't clear,
204
	 * there really should be more of a description here...
205
	 * </p>
206
	 * <!-- end-user-doc -->
207
	 * @return the value of the '<em>Definition</em>' reference.
208
	 * @see #setDefinition(Definition)
209
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage#getCapability_Definition()
210
	 * @model
211
	 * @generated
212
	 */
213
	Definition getDefinition();
214
215
	/**
216
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getDefinition <em>Definition</em>}' reference.
217
	 * <!-- begin-user-doc -->
218
	 * <!-- end-user-doc -->
219
	 * @param value the new value of the '<em>Definition</em>' reference.
220
	 * @see #getDefinition()
221
	 * @generated
222
	 */
223
	void setDefinition(Definition value);
224
225
	/**
226
	 * Returns the value of the '<em><b>Metadata</b></em>' reference.
227
	 * <!-- begin-user-doc -->
228
	 * <p>
229
	 * If the meaning of the '<em>Metadata</em>' reference isn't clear,
230
	 * there really should be more of a description here...
231
	 * </p>
232
	 * <!-- end-user-doc -->
233
	 * @return the value of the '<em>Metadata</em>' reference.
234
	 * @see #setMetadata(MetadataDescriptor)
235
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage#getCapability_Metadata()
236
	 * @model
237
	 * @generated
238
	 */
239
	MetadataDescriptor getMetadata();
240
241
	/**
242
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability#getMetadata <em>Metadata</em>}' reference.
243
	 * <!-- begin-user-doc -->
244
	 * <!-- end-user-doc -->
245
	 * @param value the new value of the '<em>Metadata</em>' reference.
246
	 * @see #getMetadata()
247
	 * @generated
248
	 */
249
	void setMetadata(MetadataDescriptor value);
250
193
} // Capability
251
} // Capability
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/impl/PropertyImpl.java (+61 lines)
Lines 20-25 Link Here
20
import org.eclipse.emf.ecore.impl.EObjectImpl;
20
import org.eclipse.emf.ecore.impl.EObjectImpl;
21
21
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage;
23
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics;
23
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
24
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
24
25
25
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
26
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
Lines 35-40 Link Here
35
 * <ul>
36
 * <ul>
36
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.PropertyImpl#getElement <em>Element</em>}</li>
37
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.PropertyImpl#getElement <em>Element</em>}</li>
37
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.PropertyImpl#getMetaData <em>Meta Data</em>}</li>
38
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.PropertyImpl#getMetaData <em>Meta Data</em>}</li>
39
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.PropertyImpl#getMetrics <em>Metrics</em>}</li>
38
 * </ul>
40
 * </ul>
39
 * </p>
41
 * </p>
40
 *
42
 *
Lines 62-67 Link Here
62
	protected PropertyType metaData = null;
64
	protected PropertyType metaData = null;
63
65
64
	/**
66
	/**
67
	 * The cached value of the '{@link #getMetrics() <em>Metrics</em>}' reference.
68
	 * <!-- begin-user-doc -->
69
	 * <!-- end-user-doc -->
70
	 * @see #getMetrics()
71
	 * @generated
72
	 * @ordered
73
	 */
74
	protected Metrics metrics = null;
75
76
	/**
65
	 * <!-- begin-user-doc -->
77
	 * <!-- begin-user-doc -->
66
	 * <!-- end-user-doc -->
78
	 * <!-- end-user-doc -->
67
	 * @generated
79
	 * @generated
Lines 160-165 Link Here
160
	 * <!-- end-user-doc -->
172
	 * <!-- end-user-doc -->
161
	 * @generated
173
	 * @generated
162
	 */
174
	 */
175
	public Metrics getMetrics() {
176
		if (metrics != null && metrics.eIsProxy()) {
177
			InternalEObject oldMetrics = (InternalEObject)metrics;
178
			metrics = (Metrics)eResolveProxy(oldMetrics);
179
			if (metrics != oldMetrics) {
180
				if (eNotificationRequired())
181
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CapabilitiesPackage.PROPERTY__METRICS, oldMetrics, metrics));
182
			}
183
		}
184
		return metrics;
185
	}
186
187
	/**
188
	 * <!-- begin-user-doc -->
189
	 * <!-- end-user-doc -->
190
	 * @generated
191
	 */
192
	public Metrics basicGetMetrics() {
193
		return metrics;
194
	}
195
196
	/**
197
	 * <!-- begin-user-doc -->
198
	 * <!-- end-user-doc -->
199
	 * @generated
200
	 */
201
	public void setMetrics(Metrics newMetrics) {
202
		Metrics oldMetrics = metrics;
203
		metrics = newMetrics;
204
		if (eNotificationRequired())
205
			eNotify(new ENotificationImpl(this, Notification.SET, CapabilitiesPackage.PROPERTY__METRICS, oldMetrics, metrics));
206
	}
207
208
	/**
209
	 * <!-- begin-user-doc -->
210
	 * <!-- end-user-doc -->
211
	 * @generated
212
	 */
163
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
213
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
164
		switch (featureID) {
214
		switch (featureID) {
165
			case CapabilitiesPackage.PROPERTY__ELEMENT:
215
			case CapabilitiesPackage.PROPERTY__ELEMENT:
Lines 168-173 Link Here
168
			case CapabilitiesPackage.PROPERTY__META_DATA:
218
			case CapabilitiesPackage.PROPERTY__META_DATA:
169
				if (resolve) return getMetaData();
219
				if (resolve) return getMetaData();
170
				return basicGetMetaData();
220
				return basicGetMetaData();
221
			case CapabilitiesPackage.PROPERTY__METRICS:
222
				if (resolve) return getMetrics();
223
				return basicGetMetrics();
171
		}
224
		}
172
		return super.eGet(featureID, resolve, coreType);
225
		return super.eGet(featureID, resolve, coreType);
173
	}
226
	}
Lines 185-190 Link Here
185
			case CapabilitiesPackage.PROPERTY__META_DATA:
238
			case CapabilitiesPackage.PROPERTY__META_DATA:
186
				setMetaData((PropertyType)newValue);
239
				setMetaData((PropertyType)newValue);
187
				return;
240
				return;
241
			case CapabilitiesPackage.PROPERTY__METRICS:
242
				setMetrics((Metrics)newValue);
243
				return;
188
		}
244
		}
189
		super.eSet(featureID, newValue);
245
		super.eSet(featureID, newValue);
190
	}
246
	}
Lines 202-207 Link Here
202
			case CapabilitiesPackage.PROPERTY__META_DATA:
258
			case CapabilitiesPackage.PROPERTY__META_DATA:
203
				setMetaData((PropertyType)null);
259
				setMetaData((PropertyType)null);
204
				return;
260
				return;
261
			case CapabilitiesPackage.PROPERTY__METRICS:
262
				setMetrics((Metrics)null);
263
				return;
205
		}
264
		}
206
		super.eUnset(featureID);
265
		super.eUnset(featureID);
207
	}
266
	}
Lines 217-222 Link Here
217
				return element != null;
276
				return element != null;
218
			case CapabilitiesPackage.PROPERTY__META_DATA:
277
			case CapabilitiesPackage.PROPERTY__META_DATA:
219
				return metaData != null;
278
				return metaData != null;
279
			case CapabilitiesPackage.PROPERTY__METRICS:
280
				return metrics != null;
220
		}
281
		}
221
		return super.eIsSet(featureID);
282
		return super.eIsSet(featureID);
222
	}
283
	}
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/impl/CapabilityImpl.java (+124 lines)
Lines 19-24 Link Here
19
19
20
import org.eclipse.emf.ecore.EClass;
20
import org.eclipse.emf.ecore.EClass;
21
21
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.emf.ecore.InternalEObject;
24
22
import org.eclipse.emf.ecore.impl.ENotificationImpl;
25
import org.eclipse.emf.ecore.impl.ENotificationImpl;
23
import org.eclipse.emf.ecore.impl.EObjectImpl;
26
import org.eclipse.emf.ecore.impl.EObjectImpl;
24
27
Lines 29-34 Link Here
29
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
32
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
30
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
33
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
31
34
35
import org.eclipse.wst.wsdl.Definition;
32
import org.eclipse.wst.wsdl.Operation;
36
import org.eclipse.wst.wsdl.Operation;
33
37
34
/**
38
/**
Lines 45-50 Link Here
45
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl#getProperties <em>Properties</em>}</li>
49
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl#getProperties <em>Properties</em>}</li>
46
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl#getOperations <em>Operations</em>}</li>
50
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl#getOperations <em>Operations</em>}</li>
47
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl#getTopicSpaces <em>Topic Spaces</em>}</li>
51
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl#getTopicSpaces <em>Topic Spaces</em>}</li>
52
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl#getDefinition <em>Definition</em>}</li>
53
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.CapabilityImpl#getMetadata <em>Metadata</em>}</li>
48
 * </ul>
54
 * </ul>
49
 * </p>
55
 * </p>
50
 *
56
 *
Lines 162-167 Link Here
162
	protected EList topicSpaces = null;
168
	protected EList topicSpaces = null;
163
169
164
	/**
170
	/**
171
	 * The cached value of the '{@link #getDefinition() <em>Definition</em>}' reference.
172
	 * <!-- begin-user-doc -->
173
	 * <!-- end-user-doc -->
174
	 * @see #getDefinition()
175
	 * @generated
176
	 * @ordered
177
	 */
178
	protected Definition definition = null;
179
180
	/**
181
	 * The cached value of the '{@link #getMetadata() <em>Metadata</em>}' reference.
182
	 * <!-- begin-user-doc -->
183
	 * <!-- end-user-doc -->
184
	 * @see #getMetadata()
185
	 * @generated
186
	 * @ordered
187
	 */
188
	protected MetadataDescriptor metadata = null;
189
190
	/**
165
	 * <!-- begin-user-doc -->
191
	 * <!-- begin-user-doc -->
166
	 * <!-- end-user-doc -->
192
	 * <!-- end-user-doc -->
167
	 * @generated
193
	 * @generated
Lines 304-309 Link Here
304
	 * <!-- end-user-doc -->
330
	 * <!-- end-user-doc -->
305
	 * @generated
331
	 * @generated
306
	 */
332
	 */
333
	public Definition getDefinition() {
334
		if (definition != null && definition.eIsProxy()) {
335
			InternalEObject oldDefinition = (InternalEObject)definition;
336
			definition = (Definition)eResolveProxy(oldDefinition);
337
			if (definition != oldDefinition) {
338
				if (eNotificationRequired())
339
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CapabilitiesPackage.CAPABILITY__DEFINITION, oldDefinition, definition));
340
			}
341
		}
342
		return definition;
343
	}
344
345
	/**
346
	 * <!-- begin-user-doc -->
347
	 * <!-- end-user-doc -->
348
	 * @generated
349
	 */
350
	public Definition basicGetDefinition() {
351
		return definition;
352
	}
353
354
	/**
355
	 * <!-- begin-user-doc -->
356
	 * <!-- end-user-doc -->
357
	 * @generated
358
	 */
359
	public void setDefinition(Definition newDefinition) {
360
		Definition oldDefinition = definition;
361
		definition = newDefinition;
362
		if (eNotificationRequired())
363
			eNotify(new ENotificationImpl(this, Notification.SET, CapabilitiesPackage.CAPABILITY__DEFINITION, oldDefinition, definition));
364
	}
365
366
	/**
367
	 * <!-- begin-user-doc -->
368
	 * <!-- end-user-doc -->
369
	 * @generated NOT
370
	 */
371
	public MetadataDescriptor getMetadata() {
372
		/*if (metadata != null && ((EObject)metadata).eIsProxy()) {
373
			InternalEObject oldMetadata = (InternalEObject)metadata;
374
			metadata = (MetadataDescriptor)eResolveProxy(oldMetadata);
375
			if (metadata != oldMetadata) {
376
				if (eNotificationRequired())
377
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CapabilitiesPackage.CAPABILITY__METADATA, oldMetadata, metadata));
378
			}
379
		}*/
380
		return metadata;
381
	}
382
383
	/**
384
	 * <!-- begin-user-doc -->
385
	 * <!-- end-user-doc -->
386
	 * @generated
387
	 */
388
	public MetadataDescriptor basicGetMetadata() {
389
		return metadata;
390
	}
391
392
	/**
393
	 * <!-- begin-user-doc -->
394
	 * <!-- end-user-doc -->
395
	 * @generated
396
	 */
397
	public void setMetadata(MetadataDescriptor newMetadata) {
398
		MetadataDescriptor oldMetadata = metadata;
399
		metadata = newMetadata;
400
		if (eNotificationRequired())
401
			eNotify(new ENotificationImpl(this, Notification.SET, CapabilitiesPackage.CAPABILITY__METADATA, oldMetadata, metadata));
402
	}
403
404
	/**
405
	 * <!-- begin-user-doc -->
406
	 * <!-- end-user-doc -->
407
	 * @generated
408
	 */
307
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
409
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
308
		switch (featureID) {
410
		switch (featureID) {
309
			case CapabilitiesPackage.CAPABILITY__DESCRIPTION:
411
			case CapabilitiesPackage.CAPABILITY__DESCRIPTION:
Lines 320-325 Link Here
320
				return getOperations();
422
				return getOperations();
321
			case CapabilitiesPackage.CAPABILITY__TOPIC_SPACES:
423
			case CapabilitiesPackage.CAPABILITY__TOPIC_SPACES:
322
				return getTopicSpaces();
424
				return getTopicSpaces();
425
			case CapabilitiesPackage.CAPABILITY__DEFINITION:
426
				if (resolve) return getDefinition();
427
				return basicGetDefinition();
428
			case CapabilitiesPackage.CAPABILITY__METADATA:
429
				if (resolve) return getMetadata();
430
				return basicGetMetadata();
323
		}
431
		}
324
		return super.eGet(featureID, resolve, coreType);
432
		return super.eGet(featureID, resolve, coreType);
325
	}
433
	}
Lines 355-360 Link Here
355
				getTopicSpaces().clear();
463
				getTopicSpaces().clear();
356
				getTopicSpaces().addAll((Collection)newValue);
464
				getTopicSpaces().addAll((Collection)newValue);
357
				return;
465
				return;
466
			case CapabilitiesPackage.CAPABILITY__DEFINITION:
467
				setDefinition((Definition)newValue);
468
				return;
469
			case CapabilitiesPackage.CAPABILITY__METADATA:
470
				setMetadata((MetadataDescriptor)newValue);
471
				return;
358
		}
472
		}
359
		super.eSet(featureID, newValue);
473
		super.eSet(featureID, newValue);
360
	}
474
	}
Lines 387-392 Link Here
387
			case CapabilitiesPackage.CAPABILITY__TOPIC_SPACES:
501
			case CapabilitiesPackage.CAPABILITY__TOPIC_SPACES:
388
				getTopicSpaces().clear();
502
				getTopicSpaces().clear();
389
				return;
503
				return;
504
			case CapabilitiesPackage.CAPABILITY__DEFINITION:
505
				setDefinition((Definition)null);
506
				return;
507
			case CapabilitiesPackage.CAPABILITY__METADATA:
508
				setMetadata((MetadataDescriptor)null);
509
				return;
390
		}
510
		}
391
		super.eUnset(featureID);
511
		super.eUnset(featureID);
392
	}
512
	}
Lines 412-417 Link Here
412
				return operations != null && !operations.isEmpty();
532
				return operations != null && !operations.isEmpty();
413
			case CapabilitiesPackage.CAPABILITY__TOPIC_SPACES:
533
			case CapabilitiesPackage.CAPABILITY__TOPIC_SPACES:
414
				return topicSpaces != null && !topicSpaces.isEmpty();
534
				return topicSpaces != null && !topicSpaces.isEmpty();
535
			case CapabilitiesPackage.CAPABILITY__DEFINITION:
536
				return definition != null;
537
			case CapabilitiesPackage.CAPABILITY__METADATA:
538
				return metadata != null;
415
		}
539
		}
416
		return super.eIsSet(featureID);
540
		return super.eIsSet(featureID);
417
	}
541
	}
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/impl/CapabilitiesPackageImpl.java (+118 lines)
Lines 30-35 Link Here
30
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
30
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
31
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage;
31
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage;
32
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
32
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
33
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics;
33
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
34
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
34
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
35
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
35
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
36
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
Lines 90-95 Link Here
90
	private EClass propertyEClass = null;
91
	private EClass propertyEClass = null;
91
92
92
	/**
93
	/**
94
	 * <!-- begin-user-doc -->
95
	 * <!-- end-user-doc -->
96
	 * @generated
97
	 */
98
	private EClass metadataEClass = null;
99
100
	/**
101
	 * <!-- begin-user-doc -->
102
	 * <!-- end-user-doc -->
103
	 * @generated
104
	 */
105
	private EClass metricsEClass = null;
106
107
	/**
93
	 * Creates an instance of the model <b>Package</b>, registered with
108
	 * Creates an instance of the model <b>Package</b>, registered with
94
	 * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package
109
	 * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package
95
	 * package URI value.
110
	 * package URI value.
Lines 259-264 Link Here
259
	 * <!-- end-user-doc -->
274
	 * <!-- end-user-doc -->
260
	 * @generated
275
	 * @generated
261
	 */
276
	 */
277
	public EReference getCapability_Definition() {
278
		return (EReference)capabilityEClass.getEStructuralFeatures().get(7);
279
	}
280
281
	/**
282
	 * <!-- begin-user-doc -->
283
	 * <!-- end-user-doc -->
284
	 * @generated
285
	 */
286
	public EReference getCapability_Metadata() {
287
		return (EReference)capabilityEClass.getEStructuralFeatures().get(8);
288
	}
289
290
	/**
291
	 * <!-- begin-user-doc -->
292
	 * <!-- end-user-doc -->
293
	 * @generated
294
	 */
262
	public EClass getTopicSpace() {
295
	public EClass getTopicSpace() {
263
		return topicSpaceEClass;
296
		return topicSpaceEClass;
264
	}
297
	}
Lines 394-399 Link Here
394
	 * <!-- end-user-doc -->
427
	 * <!-- end-user-doc -->
395
	 * @generated
428
	 * @generated
396
	 */
429
	 */
430
	public EReference getProperty_Metrics() {
431
		return (EReference)propertyEClass.getEStructuralFeatures().get(2);
432
	}
433
434
	/**
435
	 * <!-- begin-user-doc -->
436
	 * <!-- end-user-doc -->
437
	 * @generated
438
	 */
439
	public EClass getMetadata() {
440
		return metadataEClass;
441
	}
442
443
	/**
444
	 * <!-- begin-user-doc -->
445
	 * <!-- end-user-doc -->
446
	 * @generated
447
	 */
448
	public EClass getMetrics() {
449
		return metricsEClass;
450
	}
451
452
	/**
453
	 * <!-- begin-user-doc -->
454
	 * <!-- end-user-doc -->
455
	 * @generated
456
	 */
457
	public EAttribute getMetrics_ChangeType() {
458
		return (EAttribute)metricsEClass.getEStructuralFeatures().get(0);
459
	}
460
461
	/**
462
	 * <!-- begin-user-doc -->
463
	 * <!-- end-user-doc -->
464
	 * @generated
465
	 */
466
	public EAttribute getMetrics_TimeScope() {
467
		return (EAttribute)metricsEClass.getEStructuralFeatures().get(1);
468
	}
469
470
	/**
471
	 * <!-- begin-user-doc -->
472
	 * <!-- end-user-doc -->
473
	 * @generated
474
	 */
475
	public EAttribute getMetrics_GatheringTime() {
476
		return (EAttribute)metricsEClass.getEStructuralFeatures().get(2);
477
	}
478
479
	/**
480
	 * <!-- begin-user-doc -->
481
	 * <!-- end-user-doc -->
482
	 * @generated
483
	 */
484
	public EAttribute getMetrics_CalculationInterval() {
485
		return (EAttribute)metricsEClass.getEStructuralFeatures().get(3);
486
	}
487
488
	/**
489
	 * <!-- begin-user-doc -->
490
	 * <!-- end-user-doc -->
491
	 * @generated
492
	 */
397
	public CapabilitiesFactory getCapabilitiesFactory() {
493
	public CapabilitiesFactory getCapabilitiesFactory() {
398
		return (CapabilitiesFactory)getEFactoryInstance();
494
		return (CapabilitiesFactory)getEFactoryInstance();
399
	}
495
	}
Lines 425-430 Link Here
425
		createEReference(capabilityEClass, CAPABILITY__PROPERTIES);
521
		createEReference(capabilityEClass, CAPABILITY__PROPERTIES);
426
		createEReference(capabilityEClass, CAPABILITY__OPERATIONS);
522
		createEReference(capabilityEClass, CAPABILITY__OPERATIONS);
427
		createEReference(capabilityEClass, CAPABILITY__TOPIC_SPACES);
523
		createEReference(capabilityEClass, CAPABILITY__TOPIC_SPACES);
524
		createEReference(capabilityEClass, CAPABILITY__DEFINITION);
525
		createEReference(capabilityEClass, CAPABILITY__METADATA);
428
526
429
		topicSpaceEClass = createEClass(TOPIC_SPACE);
527
		topicSpaceEClass = createEClass(TOPIC_SPACE);
430
		createEAttribute(topicSpaceEClass, TOPIC_SPACE__NAME);
528
		createEAttribute(topicSpaceEClass, TOPIC_SPACE__NAME);
Lines 443-448 Link Here
443
		propertyEClass = createEClass(PROPERTY);
541
		propertyEClass = createEClass(PROPERTY);
444
		createEReference(propertyEClass, PROPERTY__ELEMENT);
542
		createEReference(propertyEClass, PROPERTY__ELEMENT);
445
		createEReference(propertyEClass, PROPERTY__META_DATA);
543
		createEReference(propertyEClass, PROPERTY__META_DATA);
544
		createEReference(propertyEClass, PROPERTY__METRICS);
545
546
		metadataEClass = createEClass(METADATA);
547
548
		metricsEClass = createEClass(METRICS);
549
		createEAttribute(metricsEClass, METRICS__CHANGE_TYPE);
550
		createEAttribute(metricsEClass, METRICS__TIME_SCOPE);
551
		createEAttribute(metricsEClass, METRICS__GATHERING_TIME);
552
		createEAttribute(metricsEClass, METRICS__CALCULATION_INTERVAL);
446
	}
553
	}
447
554
448
	/**
555
	/**
Lines 484-489 Link Here
484
		initEReference(getCapability_Properties(), this.getProperty(), null, "properties", null, 0, -1, Capability.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
591
		initEReference(getCapability_Properties(), this.getProperty(), null, "properties", null, 0, -1, Capability.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
485
		initEReference(getCapability_Operations(), theWSDLPackage.getOperation(), null, "operations", null, 0, -1, Capability.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
592
		initEReference(getCapability_Operations(), theWSDLPackage.getOperation(), null, "operations", null, 0, -1, Capability.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
486
		initEReference(getCapability_TopicSpaces(), this.getTopicSpace(), null, "topicSpaces", null, 0, -1, Capability.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
593
		initEReference(getCapability_TopicSpaces(), this.getTopicSpace(), null, "topicSpaces", null, 0, -1, Capability.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
594
		initEReference(getCapability_Definition(), theWSDLPackage.getDefinition(), null, "definition", null, 0, 1, Capability.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
595
		initEReference(getCapability_Metadata(), this.getMetadata(), null, "metadata", null, 0, 1, Capability.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
487
596
488
		initEClass(topicSpaceEClass, TopicSpace.class, "TopicSpace", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
597
		initEClass(topicSpaceEClass, TopicSpace.class, "TopicSpace", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
489
		initEAttribute(getTopicSpace_Name(), ecorePackage.getEString(), "name", null, 0, 1, TopicSpace.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
598
		initEAttribute(getTopicSpace_Name(), ecorePackage.getEString(), "name", null, 0, 1, TopicSpace.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
Lines 502-507 Link Here
502
		initEClass(propertyEClass, Property.class, "Property", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
611
		initEClass(propertyEClass, Property.class, "Property", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
503
		initEReference(getProperty_Element(), theXSDPackage.getXSDElementDeclaration(), null, "element", null, 0, 1, Property.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
612
		initEReference(getProperty_Element(), theXSDPackage.getXSDElementDeclaration(), null, "element", null, 0, 1, Property.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
504
		initEReference(getProperty_MetaData(), theMetadataDescriptorPackage.getPropertyType(), null, "metaData", null, 0, 1, Property.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
613
		initEReference(getProperty_MetaData(), theMetadataDescriptorPackage.getPropertyType(), null, "metaData", null, 0, 1, Property.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
614
		initEReference(getProperty_Metrics(), this.getMetrics(), null, "metrics", null, 0, 1, Property.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
615
616
		initEClass(metadataEClass, MetadataDescriptor.class, "Metadata", IS_ABSTRACT, IS_INTERFACE, !IS_GENERATED_INSTANCE_CLASS);
617
618
		initEClass(metricsEClass, Metrics.class, "Metrics", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
619
		initEAttribute(getMetrics_ChangeType(), ecorePackage.getEString(), "changeType", null, 0, 1, Metrics.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
620
		initEAttribute(getMetrics_TimeScope(), ecorePackage.getEString(), "timeScope", null, 0, 1, Metrics.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
621
		initEAttribute(getMetrics_GatheringTime(), ecorePackage.getEString(), "gatheringTime", null, 0, 1, Metrics.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
622
		initEAttribute(getMetrics_CalculationInterval(), ecorePackage.getEString(), "calculationInterval", null, 0, 1, Metrics.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
505
623
506
		// Create resource
624
		// Create resource
507
		createResource(eNS_URI);
625
		createResource(eNS_URI);
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/impl/CapabilitiesFactoryImpl.java (+11 lines)
Lines 68-73 Link Here
68
			case CapabilitiesPackage.TOPIC_SPACE: return createTopicSpace();
68
			case CapabilitiesPackage.TOPIC_SPACE: return createTopicSpace();
69
			case CapabilitiesPackage.TOPIC: return createTopic();
69
			case CapabilitiesPackage.TOPIC: return createTopic();
70
			case CapabilitiesPackage.PROPERTY: return createProperty();
70
			case CapabilitiesPackage.PROPERTY: return createProperty();
71
			case CapabilitiesPackage.METRICS: return createMetrics();
71
			default:
72
			default:
72
				throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
73
				throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
73
		}
74
		}
Lines 118-123 Link Here
118
	 * <!-- end-user-doc -->
119
	 * <!-- end-user-doc -->
119
	 * @generated
120
	 * @generated
120
	 */
121
	 */
122
	public Metrics createMetrics() {
123
		MetricsImpl metrics = new MetricsImpl();
124
		return metrics;
125
	}
126
127
	/**
128
	 * <!-- begin-user-doc -->
129
	 * <!-- end-user-doc -->
130
	 * @generated
131
	 */
121
	public CapabilitiesPackage getCapabilitiesPackage() {
132
	public CapabilitiesPackage getCapabilitiesPackage() {
122
		return (CapabilitiesPackage)getEPackage();
133
		return (CapabilitiesPackage)getEPackage();
123
	}
134
	}
(-)model/capabilities.ecore (+11 lines)
Lines 14-19 Link Here
14
        eType="ecore:EClass wsdl.ecore#//Operation"/>
14
        eType="ecore:EClass wsdl.ecore#//Operation"/>
15
    <eStructuralFeatures xsi:type="ecore:EReference" name="topicSpaces" upperBound="-1"
15
    <eStructuralFeatures xsi:type="ecore:EReference" name="topicSpaces" upperBound="-1"
16
        eType="#//TopicSpace"/>
16
        eType="#//TopicSpace"/>
17
    <eStructuralFeatures xsi:type="ecore:EReference" name="definition" eType="ecore:EClass wsdl.ecore#//Definition"/>
18
    <eStructuralFeatures xsi:type="ecore:EReference" name="metadata" eType="#//Metadata"/>
17
  </eClassifiers>
19
  </eClassifiers>
18
  <eClassifiers xsi:type="ecore:EClass" name="TopicSpace">
20
  <eClassifiers xsi:type="ecore:EClass" name="TopicSpace">
19
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
21
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
Lines 36-40 Link Here
36
  <eClassifiers xsi:type="ecore:EClass" name="Property">
38
  <eClassifiers xsi:type="ecore:EClass" name="Property">
37
    <eStructuralFeatures xsi:type="ecore:EReference" name="element" eType="ecore:EClass ../../../plugin/org.eclipse.xsd/model/XSD.ecore#//XSDElementDeclaration"/>
39
    <eStructuralFeatures xsi:type="ecore:EReference" name="element" eType="ecore:EClass ../../../plugin/org.eclipse.xsd/model/XSD.ecore#//XSDElementDeclaration"/>
38
    <eStructuralFeatures xsi:type="ecore:EReference" name="metaData" eType="ecore:EClass metadataDescriptor.ecore#//PropertyType"/>
40
    <eStructuralFeatures xsi:type="ecore:EReference" name="metaData" eType="ecore:EClass metadataDescriptor.ecore#//PropertyType"/>
41
    <eStructuralFeatures xsi:type="ecore:EReference" name="metrics" eType="#//Metrics"/>
42
  </eClassifiers>
43
  <eClassifiers xsi:type="ecore:EClass" name="Metadata" instanceClassName="org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor"
44
      interface="true"/>
45
  <eClassifiers xsi:type="ecore:EClass" name="Metrics">
46
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="changeType" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
47
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="timeScope" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
48
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="gatheringTime" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
49
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="calculationInterval" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
39
  </eClassifiers>
50
  </eClassifiers>
40
</ecore:EPackage>
51
</ecore:EPackage>
(-)model/metadataDescriptor.ecore (-3 / +6 lines)
Lines 283-289 Link Here
283
      </eAnnotations>
283
      </eAnnotations>
284
    </eStructuralFeatures>
284
    </eStructuralFeatures>
285
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="interface" unique="false"
285
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="interface" unique="false"
286
        lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//QName">
286
        lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//NCName">
287
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
287
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
288
        <details key="kind" value="attribute"/>
288
        <details key="kind" value="attribute"/>
289
        <details key="name" value="interface"/>
289
        <details key="name" value="interface"/>
Lines 297-303 Link Here
297
      </eAnnotations>
297
      </eAnnotations>
298
    </eStructuralFeatures>
298
    </eStructuralFeatures>
299
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="wsdlLocation" unique="false"
299
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="wsdlLocation" unique="false"
300
        eType="#//PairsOfURIType">
300
        eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
301
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
301
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
302
        <details key="kind" value="attribute"/>
302
        <details key="kind" value="attribute"/>
303
        <details key="name" value="wsdlLocation"/>
303
        <details key="name" value="wsdlLocation"/>
Lines 407-413 Link Here
407
      </eAnnotations>
407
      </eAnnotations>
408
    </eStructuralFeatures>
408
    </eStructuralFeatures>
409
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" lowerBound="1"
409
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" lowerBound="1"
410
        eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//QName">
410
        eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//NCName">
411
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
411
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
412
        <details key="kind" value="attribute"/>
412
        <details key="kind" value="attribute"/>
413
        <details key="name" value="name"/>
413
        <details key="name" value="name"/>
Lines 565-568 Link Here
565
      </eAnnotations>
565
      </eAnnotations>
566
    </eStructuralFeatures>
566
    </eStructuralFeatures>
567
  </eClassifiers>
567
  </eClassifiers>
568
  <eClassifiers xsi:type="ecore:EClass" name="Metrics">
569
    <eStructuralFeatures xsi:type="ecore:EReference" name="changeType"/>
570
  </eClassifiers>
568
</ecore:EPackage>
571
</ecore:EPackage>
(-)META-INF/MANIFEST.MF (-2 / +3 lines)
Lines 9-16 Link Here
9
 org.eclipse.emf.ecore;visibility:=reexport,
9
 org.eclipse.emf.ecore;visibility:=reexport,
10
 org.eclipse.emf.ecore.xmi;visibility:=reexport,
10
 org.eclipse.emf.ecore.xmi;visibility:=reexport,
11
 org.eclipse.xsd;visibility:=reexport,
11
 org.eclipse.xsd;visibility:=reexport,
12
 org.eclipse.wst.wsdl;visibility:=reexport,
12
 org.eclipse.core.resources,
13
 org.eclipse.core.resources
13
 org.wsdl4j,
14
 org.eclipse.wst.wsdl;visibility:=reexport
14
Eclipse-LazyStart: true
15
Eclipse-LazyStart: true
15
Export-Package: org.apache.ws.muse.descriptor,
16
Export-Package: org.apache.ws.muse.descriptor,
16
 org.apache.ws.muse.descriptor.impl,
17
 org.apache.ws.muse.descriptor.impl,
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/impl/MetricsImpl.java (+328 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
package org.eclipse.tptp.wsdm.tooling.model.capabilities.impl;
13
14
import org.eclipse.emf.common.notify.Notification;
15
16
import org.eclipse.emf.ecore.EClass;
17
18
import org.eclipse.emf.ecore.impl.ENotificationImpl;
19
import org.eclipse.emf.ecore.impl.EObjectImpl;
20
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics;
23
24
/**
25
 * <!-- begin-user-doc -->
26
 * An implementation of the model object '<em><b>Metrics</b></em>'.
27
 * <!-- end-user-doc -->
28
 * <p>
29
 * The following features are implemented:
30
 * <ul>
31
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetricsImpl#getChangeType <em>Change Type</em>}</li>
32
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetricsImpl#getTimeScope <em>Time Scope</em>}</li>
33
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetricsImpl#getGatheringTime <em>Gathering Time</em>}</li>
34
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetricsImpl#getCalculationInterval <em>Calculation Interval</em>}</li>
35
 * </ul>
36
 * </p>
37
 *
38
 * @generated
39
 */
40
public class MetricsImpl extends EObjectImpl implements Metrics {
41
	/**
42
	 * The default value of the '{@link #getChangeType() <em>Change Type</em>}' attribute.
43
	 * <!-- begin-user-doc -->
44
	 * <!-- end-user-doc -->
45
	 * @see #getChangeType()
46
	 * @generated
47
	 * @ordered
48
	 */
49
	protected static final String CHANGE_TYPE_EDEFAULT = null;
50
51
	/**
52
	 * The cached value of the '{@link #getChangeType() <em>Change Type</em>}' attribute.
53
	 * <!-- begin-user-doc -->
54
	 * <!-- end-user-doc -->
55
	 * @see #getChangeType()
56
	 * @generated
57
	 * @ordered
58
	 */
59
	protected String changeType = CHANGE_TYPE_EDEFAULT;
60
61
	/**
62
	 * The default value of the '{@link #getTimeScope() <em>Time Scope</em>}' attribute.
63
	 * <!-- begin-user-doc -->
64
	 * <!-- end-user-doc -->
65
	 * @see #getTimeScope()
66
	 * @generated
67
	 * @ordered
68
	 */
69
	protected static final String TIME_SCOPE_EDEFAULT = null;
70
71
	/**
72
	 * The cached value of the '{@link #getTimeScope() <em>Time Scope</em>}' attribute.
73
	 * <!-- begin-user-doc -->
74
	 * <!-- end-user-doc -->
75
	 * @see #getTimeScope()
76
	 * @generated
77
	 * @ordered
78
	 */
79
	protected String timeScope = TIME_SCOPE_EDEFAULT;
80
81
	/**
82
	 * The default value of the '{@link #getGatheringTime() <em>Gathering Time</em>}' attribute.
83
	 * <!-- begin-user-doc -->
84
	 * <!-- end-user-doc -->
85
	 * @see #getGatheringTime()
86
	 * @generated
87
	 * @ordered
88
	 */
89
	protected static final String GATHERING_TIME_EDEFAULT = null;
90
91
	/**
92
	 * The cached value of the '{@link #getGatheringTime() <em>Gathering Time</em>}' attribute.
93
	 * <!-- begin-user-doc -->
94
	 * <!-- end-user-doc -->
95
	 * @see #getGatheringTime()
96
	 * @generated
97
	 * @ordered
98
	 */
99
	protected String gatheringTime = GATHERING_TIME_EDEFAULT;
100
101
	/**
102
	 * The default value of the '{@link #getCalculationInterval() <em>Calculation Interval</em>}' attribute.
103
	 * <!-- begin-user-doc -->
104
	 * <!-- end-user-doc -->
105
	 * @see #getCalculationInterval()
106
	 * @generated
107
	 * @ordered
108
	 */
109
	protected static final String CALCULATION_INTERVAL_EDEFAULT = null;
110
111
	/**
112
	 * The cached value of the '{@link #getCalculationInterval() <em>Calculation Interval</em>}' attribute.
113
	 * <!-- begin-user-doc -->
114
	 * <!-- end-user-doc -->
115
	 * @see #getCalculationInterval()
116
	 * @generated
117
	 * @ordered
118
	 */
119
	protected String calculationInterval = CALCULATION_INTERVAL_EDEFAULT;
120
121
	/**
122
	 * <!-- begin-user-doc -->
123
	 * <!-- end-user-doc -->
124
	 * @generated
125
	 */
126
	protected MetricsImpl() {
127
		super();
128
	}
129
130
	/**
131
	 * <!-- begin-user-doc -->
132
	 * <!-- end-user-doc -->
133
	 * @generated
134
	 */
135
	protected EClass eStaticClass() {
136
		return CapabilitiesPackage.Literals.METRICS;
137
	}
138
139
	/**
140
	 * <!-- begin-user-doc -->
141
	 * <!-- end-user-doc -->
142
	 * @generated
143
	 */
144
	public String getChangeType() {
145
		return changeType;
146
	}
147
148
	/**
149
	 * <!-- begin-user-doc -->
150
	 * <!-- end-user-doc -->
151
	 * @generated
152
	 */
153
	public void setChangeType(String newChangeType) {
154
		String oldChangeType = changeType;
155
		changeType = newChangeType;
156
		if (eNotificationRequired())
157
			eNotify(new ENotificationImpl(this, Notification.SET, CapabilitiesPackage.METRICS__CHANGE_TYPE, oldChangeType, changeType));
158
	}
159
160
	/**
161
	 * <!-- begin-user-doc -->
162
	 * <!-- end-user-doc -->
163
	 * @generated
164
	 */
165
	public String getTimeScope() {
166
		return timeScope;
167
	}
168
169
	/**
170
	 * <!-- begin-user-doc -->
171
	 * <!-- end-user-doc -->
172
	 * @generated
173
	 */
174
	public void setTimeScope(String newTimeScope) {
175
		String oldTimeScope = timeScope;
176
		timeScope = newTimeScope;
177
		if (eNotificationRequired())
178
			eNotify(new ENotificationImpl(this, Notification.SET, CapabilitiesPackage.METRICS__TIME_SCOPE, oldTimeScope, timeScope));
179
	}
180
181
	/**
182
	 * <!-- begin-user-doc -->
183
	 * <!-- end-user-doc -->
184
	 * @generated
185
	 */
186
	public String getGatheringTime() {
187
		return gatheringTime;
188
	}
189
190
	/**
191
	 * <!-- begin-user-doc -->
192
	 * <!-- end-user-doc -->
193
	 * @generated
194
	 */
195
	public void setGatheringTime(String newGatheringTime) {
196
		String oldGatheringTime = gatheringTime;
197
		gatheringTime = newGatheringTime;
198
		if (eNotificationRequired())
199
			eNotify(new ENotificationImpl(this, Notification.SET, CapabilitiesPackage.METRICS__GATHERING_TIME, oldGatheringTime, gatheringTime));
200
	}
201
202
	/**
203
	 * <!-- begin-user-doc -->
204
	 * <!-- end-user-doc -->
205
	 * @generated
206
	 */
207
	public String getCalculationInterval() {
208
		return calculationInterval;
209
	}
210
211
	/**
212
	 * <!-- begin-user-doc -->
213
	 * <!-- end-user-doc -->
214
	 * @generated
215
	 */
216
	public void setCalculationInterval(String newCalculationInterval) {
217
		String oldCalculationInterval = calculationInterval;
218
		calculationInterval = newCalculationInterval;
219
		if (eNotificationRequired())
220
			eNotify(new ENotificationImpl(this, Notification.SET, CapabilitiesPackage.METRICS__CALCULATION_INTERVAL, oldCalculationInterval, calculationInterval));
221
	}
222
223
	/**
224
	 * <!-- begin-user-doc -->
225
	 * <!-- end-user-doc -->
226
	 * @generated
227
	 */
228
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
229
		switch (featureID) {
230
			case CapabilitiesPackage.METRICS__CHANGE_TYPE:
231
				return getChangeType();
232
			case CapabilitiesPackage.METRICS__TIME_SCOPE:
233
				return getTimeScope();
234
			case CapabilitiesPackage.METRICS__GATHERING_TIME:
235
				return getGatheringTime();
236
			case CapabilitiesPackage.METRICS__CALCULATION_INTERVAL:
237
				return getCalculationInterval();
238
		}
239
		return super.eGet(featureID, resolve, coreType);
240
	}
241
242
	/**
243
	 * <!-- begin-user-doc -->
244
	 * <!-- end-user-doc -->
245
	 * @generated
246
	 */
247
	public void eSet(int featureID, Object newValue) {
248
		switch (featureID) {
249
			case CapabilitiesPackage.METRICS__CHANGE_TYPE:
250
				setChangeType((String)newValue);
251
				return;
252
			case CapabilitiesPackage.METRICS__TIME_SCOPE:
253
				setTimeScope((String)newValue);
254
				return;
255
			case CapabilitiesPackage.METRICS__GATHERING_TIME:
256
				setGatheringTime((String)newValue);
257
				return;
258
			case CapabilitiesPackage.METRICS__CALCULATION_INTERVAL:
259
				setCalculationInterval((String)newValue);
260
				return;
261
		}
262
		super.eSet(featureID, newValue);
263
	}
264
265
	/**
266
	 * <!-- begin-user-doc -->
267
	 * <!-- end-user-doc -->
268
	 * @generated
269
	 */
270
	public void eUnset(int featureID) {
271
		switch (featureID) {
272
			case CapabilitiesPackage.METRICS__CHANGE_TYPE:
273
				setChangeType(CHANGE_TYPE_EDEFAULT);
274
				return;
275
			case CapabilitiesPackage.METRICS__TIME_SCOPE:
276
				setTimeScope(TIME_SCOPE_EDEFAULT);
277
				return;
278
			case CapabilitiesPackage.METRICS__GATHERING_TIME:
279
				setGatheringTime(GATHERING_TIME_EDEFAULT);
280
				return;
281
			case CapabilitiesPackage.METRICS__CALCULATION_INTERVAL:
282
				setCalculationInterval(CALCULATION_INTERVAL_EDEFAULT);
283
				return;
284
		}
285
		super.eUnset(featureID);
286
	}
287
288
	/**
289
	 * <!-- begin-user-doc -->
290
	 * <!-- end-user-doc -->
291
	 * @generated
292
	 */
293
	public boolean eIsSet(int featureID) {
294
		switch (featureID) {
295
			case CapabilitiesPackage.METRICS__CHANGE_TYPE:
296
				return CHANGE_TYPE_EDEFAULT == null ? changeType != null : !CHANGE_TYPE_EDEFAULT.equals(changeType);
297
			case CapabilitiesPackage.METRICS__TIME_SCOPE:
298
				return TIME_SCOPE_EDEFAULT == null ? timeScope != null : !TIME_SCOPE_EDEFAULT.equals(timeScope);
299
			case CapabilitiesPackage.METRICS__GATHERING_TIME:
300
				return GATHERING_TIME_EDEFAULT == null ? gatheringTime != null : !GATHERING_TIME_EDEFAULT.equals(gatheringTime);
301
			case CapabilitiesPackage.METRICS__CALCULATION_INTERVAL:
302
				return CALCULATION_INTERVAL_EDEFAULT == null ? calculationInterval != null : !CALCULATION_INTERVAL_EDEFAULT.equals(calculationInterval);
303
		}
304
		return super.eIsSet(featureID);
305
	}
306
307
	/**
308
	 * <!-- begin-user-doc -->
309
	 * <!-- end-user-doc -->
310
	 * @generated
311
	 */
312
	public String toString() {
313
		if (eIsProxy()) return super.toString();
314
315
		StringBuffer result = new StringBuffer(super.toString());
316
		result.append(" (changeType: ");
317
		result.append(changeType);
318
		result.append(", timeScope: ");
319
		result.append(timeScope);
320
		result.append(", gatheringTime: ");
321
		result.append(gatheringTime);
322
		result.append(", calculationInterval: ");
323
		result.append(calculationInterval);
324
		result.append(')');
325
		return result.toString();
326
	}
327
328
} //MetricsImpl
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/impl/TopicSpace2MetaDataDescriptor.java (+166 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.model.capabilities.impl;
14
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
import java.util.List;
18
19
import org.eclipse.emf.common.util.EMap;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
22
23
/**
24
 * Generate a topic expression for each topic available in capability.<br>
25
 * So if capability has topics defined as<br>
26
 * <br>
27
 * http://w3.ibm.com/capabilities/WAS (TopicNameSpace)<br>
28
 * |____RootTopic <br>
29
 * |______ChildTopic <br>
30
 * <br>
31
 * 
32
 * Then it will generate the following topic expressions in RMD<br>
33
 * <br>
34
 * 
35
 * xmlns:topics1="http://w3.ibm.com/capabilities/WAS/Topics"<br>
36
 * 
37
 * &lt; wsnt:TopicExpression &gt; topics1:RootTopic &lt; /wsnt:TopicExpression
38
 * &gt;<br>
39
 * &lt; wsnt:TopicExpression &gt; topics1:RootTopic/ChildTopic &lt;
40
 * /wsnt:TopicExpression &gt;<br>
41
 * 
42
 * @see #getTopicExpressions()
43
 * 
44
 */
45
46
public class TopicSpace2MetaDataDescriptor
47
{
48
49
	private List _topicSpaces;
50
51
	private List _generatedTopicExpressions;
52
53
	private EMap _nsMap;
54
55
	/**
56
	 * Creates the instance of this class.
57
	 */
58
	public TopicSpace2MetaDataDescriptor(EMap nsMap, List topicSpaces)
59
	{
60
		_topicSpaces = topicSpaces;
61
		_nsMap = nsMap;
62
		_generatedTopicExpressions = new ArrayList();
63
	}
64
65
	/**
66
	 * 
67
	 * @return Topic expression.
68
	 */
69
	public String[] getTopicExpressions()
70
	{
71
		for (int i = 0; i < _topicSpaces.size(); i++)
72
		{
73
			TopicSpace topicSpace = (TopicSpace) _topicSpaces.get(i);
74
			visitTopicSpace(topicSpace);
75
		}
76
		return (String[]) _generatedTopicExpressions.toArray(new String[0]);
77
	}
78
79
	private void visitTopicSpace(TopicSpace topicSpace)
80
	{
81
		String prefix = getPrefix(topicSpace.getNamespace());
82
		for (int i = 0; i < topicSpace.getRootTopics().size(); i++)
83
		{
84
			visitRootTopic((Topic) topicSpace.getRootTopics().get(i), prefix);
85
		}
86
	}
87
88
	private void visitRootTopic(Topic rootTopic, String prefix)
89
	{
90
		String topicExpression = prepareExpression(prefix, rootTopic);
91
		if (!_generatedTopicExpressions.contains(topicExpression))
92
			_generatedTopicExpressions.add(topicExpression);
93
94
		for (int i = 0; i < rootTopic.getChildren().size(); i++)
95
		{
96
			visitTopic((Topic) rootTopic.getChildren().get(i), prefix);
97
		}
98
	}
99
100
	private void visitTopic(Topic topic, String prefix)
101
	{
102
		String topicExpression = prepareExpression(prefix, topic);
103
		if (!_generatedTopicExpressions.contains(topicExpression))
104
			_generatedTopicExpressions.add(topicExpression);
105
106
		for (int i = 0; i < topic.getChildren().size(); i++)
107
		{
108
			visitTopic((Topic) topic.getChildren().get(i), prefix);
109
		}
110
	}
111
112
	private String prepareExpression(String prefix, Topic topic)
113
	{
114
		StringBuffer buffer = new StringBuffer();
115
		buffer.append(topic.getName());
116
		while (topic.getParent() != null)
117
		{
118
			topic = topic.getParent();
119
			buffer.insert(0, topic.getName() + "/");
120
		}
121
		buffer.insert(0, prefix + ":");
122
		return buffer.toString();
123
	}
124
125
	private String getPrefix(String ns)
126
	{
127
		Iterator keyIt = _nsMap.keySet().iterator();
128
		Iterator valueIt = _nsMap.values().iterator();
129
		while (keyIt.hasNext())
130
		{
131
			String prefix = (String) keyIt.next();
132
			String namespace = (String) valueIt.next();
133
			if (namespace.equals(ns))
134
				return prefix;
135
		}
136
137
		String newPrefix = generateNewPrefix();
138
		_nsMap.put(newPrefix, ns);
139
		return newPrefix;
140
	}
141
142
	private String generateNewPrefix()
143
	{
144
		int counter = 1;
145
		String newPrefix = "topics" + counter;
146
		while (isPrefixExists(newPrefix))
147
		{
148
			counter++;
149
			newPrefix = "topics" + counter;
150
		}
151
		return newPrefix;
152
	}
153
154
	private boolean isPrefixExists(String prefix)
155
	{
156
		Iterator keyIt = _nsMap.keySet().iterator();
157
		while (keyIt.hasNext())
158
		{
159
			String pfx = (String) keyIt.next();
160
			if (pfx.equals(prefix))
161
				return true;
162
		}
163
		return false;
164
	}
165
166
}
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/impl/MetaDataDescriptor2TopicSpace.java (+215 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.model.capabilities.impl;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
import java.util.StringTokenizer;
18
19
import org.eclipse.emf.common.util.EMap;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
23
24
/**
25
 * 
26
 * Populate capability topics from TopicExpression property.<br>
27
 * If RMD file has TopicExpression defined as <br>
28
 * <br>
29
 * 
30
 * xmlns:topics1="http://w3.ibm.com/capabilities/WAS/Topics"<br>
31
 * 
32
 * &lt; wsnt:TopicExpression &gt; topics1:RootTopic &lt; /wsnt:TopicExpression
33
 * &gt;<br>
34
 * &lt; wsnt:TopicExpression &gt; topics1:RootTopic/ChildTopic &lt;
35
 * /wsnt:TopicExpression &gt;<br>
36
 * <br>
37
 * 
38
 * Then it will create in memory model for topics as<br>
39
 * <br>
40
 * 
41
 * http://w3.ibm.com/capabilities/WAS (TopicNameSpace)<br>
42
 * |____RootTopic <br>
43
 * |______ChildTopic <br>
44
 * <br>
45
 * 
46
 * @see #getTopicSpaces()
47
 * 
48
 */
49
50
public class MetaDataDescriptor2TopicSpace
51
{
52
53
	private List _topicSpaces;
54
55
	private EMap _nsMap;
56
57
	/**
58
	 * Creates the object of this class.<br>
59
	 * Parameter passed is the map of the namespaces available in rmd file.
60
	 */
61
	public MetaDataDescriptor2TopicSpace(EMap nsMap)
62
	{
63
		_nsMap = nsMap;
64
		_topicSpaces = new ArrayList();
65
	}
66
67
	/**
68
	 * 
69
	 * @param topicExpression
70
	 *            Topic expression for which new topicSpace to be created.
71
	 */
72
	public void addTopicExpression(String topicExpression)
73
	{
74
		TopicSpace topicSpace = getTopicSpace(topicExpression);
75
		createTopic(topicSpace, topicExpression);
76
	}
77
78
	/**
79
	 * 
80
	 * @return Topicspaces corresponding to topic expression property.
81
	 */
82
	public List getTopicSpaces()
83
	{
84
		return _topicSpaces;
85
	}
86
87
	private TopicSpace getTopicSpace(String topicExpression)
88
	{
89
		String prefix = topicExpression.substring(0, topicExpression
90
				.indexOf(':'));
91
		String namespace = (String) _nsMap.get(prefix);
92
		if (!isTopicSpaceCreated(namespace))
93
		{
94
			TopicSpace topicSpace = CapabilitiesFactory.eINSTANCE
95
					.createTopicSpace();
96
			topicSpace.setName(prefix);
97
			topicSpace.setNamespace(namespace);
98
			_topicSpaces.add(topicSpace);
99
			return topicSpace;
100
		}
101
102
		for (int i = 0; i < _topicSpaces.size(); i++)
103
		{
104
			TopicSpace topicSpace = (TopicSpace) _topicSpaces.get(i);
105
			if (topicSpace.getNamespace().equals(namespace))
106
				return topicSpace;
107
		}
108
109
		return null;
110
	}
111
112
	private boolean isTopicSpaceCreated(String namespace)
113
	{
114
		for (int i = 0; i < _topicSpaces.size(); i++)
115
		{
116
			TopicSpace topicSpace = (TopicSpace) _topicSpaces.get(i);
117
			if (topicSpace.getNamespace().equals(namespace))
118
				return true;
119
		}
120
		return false;
121
	}
122
123
	private void createTopic(TopicSpace topicSpace, String topicExpression)
124
	{
125
		String path = topicExpression
126
				.substring(topicExpression.indexOf(':') + 1);
127
		StringTokenizer tokenizer = new StringTokenizer(path, "/");
128
129
		String rootTopicName = tokenizer.nextToken();
130
		Topic parentTopic = null;
131
		if (!isTopicCreated(topicSpace, rootTopicName))
132
		{
133
			parentTopic = createRootTopic(topicSpace, rootTopicName);
134
		}
135
		else
136
		{
137
			parentTopic = getRootTopic(topicSpace, rootTopicName);
138
		}
139
140
		while (tokenizer.hasMoreTokens())
141
		{
142
			String childTopicName = tokenizer.nextToken();
143
			if (!isTopicCreated(parentTopic, childTopicName))
144
			{
145
				parentTopic = createChildTopic(parentTopic, childTopicName);
146
			}
147
			else
148
			{
149
				parentTopic = getChildTopic(parentTopic, childTopicName);
150
			}
151
		}
152
	}
153
154
	private boolean isTopicCreated(TopicSpace topicSpace, String rootTopicName)
155
	{
156
		for (int i = 0; i < topicSpace.getRootTopics().size(); i++)
157
		{
158
			Topic rootTopic = (Topic) topicSpace.getRootTopics().get(i);
159
			if (rootTopic.getName().equals(rootTopicName))
160
				return true;
161
		}
162
		return false;
163
	}
164
165
	private boolean isTopicCreated(Topic parentTopic, String childTopicName)
166
	{
167
		for (int i = 0; i < parentTopic.getChildren().size(); i++)
168
		{
169
			Topic childTopic = (Topic) parentTopic.getChildren().get(i);
170
			if (childTopic.getName().equals(childTopicName))
171
				return true;
172
		}
173
		return false;
174
	}
175
176
	private Topic createRootTopic(TopicSpace topicSpace, String rootTopicName)
177
	{
178
		Topic rootTopic = CapabilitiesFactory.eINSTANCE.createTopic();
179
		rootTopic.setName(rootTopicName);
180
		rootTopic.setParent(null);
181
		topicSpace.getRootTopics().add(rootTopic);
182
		return rootTopic;
183
	}
184
185
	private Topic getRootTopic(TopicSpace topicSpace, String rootTopicName)
186
	{
187
		for (int i = 0; i < topicSpace.getRootTopics().size(); i++)
188
		{
189
			Topic rootTopic = (Topic) topicSpace.getRootTopics().get(i);
190
			if (rootTopic.getName().equals(rootTopicName))
191
				return rootTopic;
192
		}
193
		return null;
194
	}
195
196
	private Topic createChildTopic(Topic topic, String childTopicName)
197
	{
198
		Topic childTopic = CapabilitiesFactory.eINSTANCE.createTopic();
199
		childTopic.setName(childTopicName);
200
		childTopic.setParent(topic);
201
		topic.getChildren().add(childTopic);
202
		return childTopic;
203
	}
204
205
	private Topic getChildTopic(Topic parentTopic, String childTopicName)
206
	{
207
		for (int i = 0; i < parentTopic.getChildren().size(); i++)
208
		{
209
			Topic childTopic = (Topic) parentTopic.getChildren().get(i);
210
			if (childTopic.getName().equals(childTopicName))
211
				return childTopic;
212
		}
213
		return null;
214
	}
215
}
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/Metrics.java (+141 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.model.capabilities;
14
15
import org.eclipse.emf.ecore.EObject;
16
17
/**
18
 * <!-- begin-user-doc -->
19
 * A representation of the model object '<em><b>Metrics</b></em>'.
20
 * <!-- end-user-doc -->
21
 *
22
 * <p>
23
 * The following features are supported:
24
 * <ul>
25
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getChangeType <em>Change Type</em>}</li>
26
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getTimeScope <em>Time Scope</em>}</li>
27
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getGatheringTime <em>Gathering Time</em>}</li>
28
 *   <li>{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getCalculationInterval <em>Calculation Interval</em>}</li>
29
 * </ul>
30
 * </p>
31
 *
32
 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage#getMetrics()
33
 * @model
34
 * @generated
35
 */
36
public interface Metrics extends EObject {
37
	/**
38
	 * Returns the value of the '<em><b>Change Type</b></em>' attribute.
39
	 * <!-- begin-user-doc -->
40
	 * <p>
41
	 * If the meaning of the '<em>Change Type</em>' attribute isn't clear,
42
	 * there really should be more of a description here...
43
	 * </p>
44
	 * <!-- end-user-doc -->
45
	 * @return the value of the '<em>Change Type</em>' attribute.
46
	 * @see #setChangeType(String)
47
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage#getMetrics_ChangeType()
48
	 * @model
49
	 * @generated
50
	 */
51
	String getChangeType();
52
53
	/**
54
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getChangeType <em>Change Type</em>}' attribute.
55
	 * <!-- begin-user-doc -->
56
	 * <!-- end-user-doc -->
57
	 * @param value the new value of the '<em>Change Type</em>' attribute.
58
	 * @see #getChangeType()
59
	 * @generated
60
	 */
61
	void setChangeType(String value);
62
63
	/**
64
	 * Returns the value of the '<em><b>Time Scope</b></em>' attribute.
65
	 * <!-- begin-user-doc -->
66
	 * <p>
67
	 * If the meaning of the '<em>Time Scope</em>' attribute isn't clear,
68
	 * there really should be more of a description here...
69
	 * </p>
70
	 * <!-- end-user-doc -->
71
	 * @return the value of the '<em>Time Scope</em>' attribute.
72
	 * @see #setTimeScope(String)
73
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage#getMetrics_TimeScope()
74
	 * @model
75
	 * @generated
76
	 */
77
	String getTimeScope();
78
79
	/**
80
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getTimeScope <em>Time Scope</em>}' attribute.
81
	 * <!-- begin-user-doc -->
82
	 * <!-- end-user-doc -->
83
	 * @param value the new value of the '<em>Time Scope</em>' attribute.
84
	 * @see #getTimeScope()
85
	 * @generated
86
	 */
87
	void setTimeScope(String value);
88
89
	/**
90
	 * Returns the value of the '<em><b>Gathering Time</b></em>' attribute.
91
	 * <!-- begin-user-doc -->
92
	 * <p>
93
	 * If the meaning of the '<em>Gathering Time</em>' attribute isn't clear,
94
	 * there really should be more of a description here...
95
	 * </p>
96
	 * <!-- end-user-doc -->
97
	 * @return the value of the '<em>Gathering Time</em>' attribute.
98
	 * @see #setGatheringTime(String)
99
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage#getMetrics_GatheringTime()
100
	 * @model
101
	 * @generated
102
	 */
103
	String getGatheringTime();
104
105
	/**
106
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getGatheringTime <em>Gathering Time</em>}' attribute.
107
	 * <!-- begin-user-doc -->
108
	 * <!-- end-user-doc -->
109
	 * @param value the new value of the '<em>Gathering Time</em>' attribute.
110
	 * @see #getGatheringTime()
111
	 * @generated
112
	 */
113
	void setGatheringTime(String value);
114
115
	/**
116
	 * Returns the value of the '<em><b>Calculation Interval</b></em>' attribute.
117
	 * <!-- begin-user-doc -->
118
	 * <p>
119
	 * If the meaning of the '<em>Calculation Interval</em>' attribute isn't clear,
120
	 * there really should be more of a description here...
121
	 * </p>
122
	 * <!-- end-user-doc -->
123
	 * @return the value of the '<em>Calculation Interval</em>' attribute.
124
	 * @see #setCalculationInterval(String)
125
	 * @see org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesPackage#getMetrics_CalculationInterval()
126
	 * @model
127
	 * @generated
128
	 */
129
	String getCalculationInterval();
130
131
	/**
132
	 * Sets the value of the '{@link org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics#getCalculationInterval <em>Calculation Interval</em>}' attribute.
133
	 * <!-- begin-user-doc -->
134
	 * <!-- end-user-doc -->
135
	 * @param value the new value of the '<em>Calculation Interval</em>' attribute.
136
	 * @see #getCalculationInterval()
137
	 * @generated
138
	 */
139
	void setCalculationInterval(String value);
140
141
} // Metrics
(-)src/org/eclipse/tptp/wsdm/tooling/model/capabilities/impl/MetadataDescriptor.java (+466 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.model.capabilities.impl;
14
15
import java.util.Collections;
16
import java.util.Iterator;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
import org.eclipse.emf.common.util.EMap;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
23
import org.eclipse.emf.ecore.resource.ResourceSet;
24
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
25
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
26
import org.eclipse.emf.ecore.util.ExtendedMetaData;
27
import org.eclipse.emf.ecore.util.FeatureMap;
28
import org.eclipse.emf.ecore.util.FeatureMapUtil;
29
import org.eclipse.emf.ecore.xml.type.AnyType;
30
import org.eclipse.emf.ecore.xml.type.XMLTypeFactory;
31
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
32
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
33
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Metrics;
34
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
35
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
36
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.InitialValuesType;
37
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorFactory;
38
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorType;
39
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.ModifiabilityType;
40
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MutabilityType;
41
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
42
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl;
43
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.ChangeTypeType;
44
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.GatheringTimeType;
45
import org.eclipse.tptp.wsdm.tooling.model.muwsPart2.TimeScopeType;
46
47
public class MetadataDescriptor
48
{
49
	private ExtendedMetaData _extendedMetaData;
50
51
	private DocumentRoot _root;
52
53
	private EStructuralFeature esfWSDM_Capability;
54
55
	private MetadataDescriptorFactory _rmdFactory = new MetadataDescriptorFactoryImpl();
56
57
	private String _metadataDescriptorName;
58
59
	private MetadataDescriptorType _metadataDescriptor;
60
61
	private Capability _capability;
62
63
	// TODO
64
	private String WSNT_NS = "http://docs.oasis-open.org/wsn/b-2";
65
66
	private String MUWS_P2_NS = "http://docs.oasis-open.org/wsdm/muws2-2.xsd";
67
68
	private String METRICS_CAPABILITY = "http://docs.oasis-open.org/wsdm/muws/capabilities/Metrics";
69
70
	public MetadataDescriptor(Capability capability, DocumentRoot root,
71
			String metadataDescriptorName)
72
	{
73
		_capability = capability;
74
		if (_capability != null)
75
			_capability.setMetadata(this);
76
		_root = root;
77
		_metadataDescriptorName = metadataDescriptorName;
78
		_metadataDescriptor = getMetadataDescriptorType();
79
		_extendedMetaData = createExtendedMetaData();
80
		this.esfWSDM_Capability = _extendedMetaData.demandFeature(MUWS_P2_NS,
81
				"Capability", true);
82
	}
83
84
	private ExtendedMetaData createExtendedMetaData()
85
	{
86
		ResourceSet resourceSet = new ResourceSetImpl();
87
		ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(
88
				resourceSet.getPackageRegistry());
89
		return extendedMetaData;
90
	}
91
92
	public MetadataDescriptorType getMetadataDescriptorType()
93
	{
94
		List descriptors = _root.getDefinitions().getMetadataDescriptor();
95
		for (int i = 0; i < descriptors.size(); i++)
96
		{
97
			MetadataDescriptorType mdtVal = (MetadataDescriptorType) descriptors
98
					.get(i);
99
			if (mdtVal.getName().equals(_metadataDescriptorName))
100
				return mdtVal;
101
		}
102
		return null;
103
	}
104
105
	private PropertyType[] getAllPropertyTypes()
106
	{
107
		List capabilityProps = new LinkedList();
108
		List propList = _metadataDescriptor.getProperty();
109
		for (int i = 0; i < propList.size(); i++)
110
		{
111
			PropertyType property = (PropertyType) propList.get(i);
112
			capabilityProps.add(property);
113
		}
114
		return (PropertyType[]) capabilityProps.toArray(new PropertyType[0]);
115
	}
116
117
	public DocumentRoot getDocumentRoot()
118
	{
119
		return _root;
120
	}
121
122
	public String getPrefix(String namespace)
123
	{
124
		if (namespace == null)
125
			return null;
126
		EMap map = _root.getXMLNSPrefixMap();
127
		Iterator keyIt = map.keySet().iterator();
128
		while (keyIt.hasNext())
129
		{
130
			String prefix = (String) keyIt.next();
131
			String ns = (String) map.get(prefix);
132
			if (ns.equals(namespace))
133
				return prefix;
134
		}
135
		return null;
136
	}
137
138
	public String getNamespace(String prefix)
139
	{
140
		if (prefix == null)
141
			return null;
142
		EMap map = _root.getXMLNSPrefixMap();
143
		Iterator keyIt = map.keySet().iterator();
144
		while (keyIt.hasNext())
145
		{
146
			String pfx = (String) keyIt.next();
147
			if (pfx.equals(prefix))
148
				return (String) map.get(pfx);
149
		}
150
		return null;
151
	}
152
153
	public String getOrCreatePrefix(String namespace)
154
	{
155
		String prefix = getPrefix(namespace);
156
		if (prefix != null)
157
			return prefix;
158
		String newPrefix = generateNewPrefix();
159
		_root.getXMLNSPrefixMap().put(newPrefix, namespace);
160
		return newPrefix;
161
	}
162
163
	private String generateNewPrefix()
164
	{
165
		int count = 0;
166
		while (isPrefixExists("pfx" + count))
167
			count++;
168
		return "pfx" + count;
169
	}
170
171
	private boolean isPrefixExists(String prefix)
172
	{
173
		EMap map = _root.getXMLNSPrefixMap();
174
		Iterator keyIt = map.keySet().iterator();
175
		while (keyIt.hasNext())
176
		{
177
			String pfx = (String) keyIt.next();
178
			if (pfx.equals(prefix))
179
				return true;
180
		}
181
		return false;
182
	}
183
184
	public void loadTopicSpaces()
185
	{
186
		PropertyType topicExpProperty = getTopicExpressionProperty();
187
		if (topicExpProperty == null)
188
		{
189
			_capability.getTopicSpaces().addAll(Collections.EMPTY_LIST);
190
			return;
191
		}
192
193
		InitialValuesType intialValues = topicExpProperty.getInitialValues();
194
		if (intialValues == null)
195
		{
196
			_capability.getTopicSpaces().addAll(Collections.EMPTY_LIST);
197
			return;
198
		}
199
200
		FeatureMap map = intialValues.getAny();
201
		Iterator it = map.valueListIterator();
202
		MetaDataDescriptor2TopicSpace metaData2TopicSpace = new MetaDataDescriptor2TopicSpace(
203
				_root.getXMLNSPrefixMap());
204
		while (it.hasNext())
205
		{
206
			Object object = it.next();
207
			if (object instanceof AnyType)
208
			{
209
				AnyType anyType = (AnyType) object;
210
				FeatureMap anyMap = anyType.getAny();
211
				Iterator topicExpIt = anyMap.valueListIterator();
212
				while (topicExpIt.hasNext())
213
				{
214
					String topicExpression = (String) topicExpIt.next();
215
					metaData2TopicSpace.addTopicExpression(topicExpression);
216
				}
217
			}
218
		}
219
		_capability.getTopicSpaces().addAll(
220
				metaData2TopicSpace.getTopicSpaces());
221
	}
222
223
	public PropertyType getTopicExpressionProperty()
224
	{
225
		PropertyType topicExpressionProperty = getPropertyMetadata(
226
				"TopicExpression", WSNT_NS);
227
		return topicExpressionProperty;
228
	}
229
230
	public PropertyType getPropertyMetadata(String name, String namespace)
231
	{
232
		List properties = _metadataDescriptor.getProperty();
233
		for (int i = 0; i < properties.size(); i++)
234
		{
235
			PropertyType property = (PropertyType) properties.get(i);
236
			String propName = property.getName();
237
			String prefix = extractPrefix(propName);
238
			String namespaceURI = getNamespace(prefix);
239
			String localName = extractName(propName);
240
			if (name.equals(localName) && namespace.equals(namespaceURI))
241
				return property;
242
		}
243
		return null;
244
	}
245
246
	private String extractPrefix(String str)
247
	{
248
		if (str == null || str.trim().equals("") || str.indexOf(':') == -1)
249
			return null;
250
		return str.substring(0, str.indexOf(':'));
251
	}
252
253
	private String extractName(String str)
254
	{
255
		if (str == null || str.trim().equals("") || str.indexOf(':') == -1)
256
			return null;
257
		return str.substring(str.indexOf(':') + 1);
258
	}
259
260
	public void saveTopicSpaces(List topicSpaces)
261
	{
262
		PropertyType topicExpressionProperty = getTopicExpressionProperty();
263
		if (topicExpressionProperty != null)
264
		{
265
			InitialValuesType intialValues = _rmdFactory
266
					.createInitialValuesType();
267
			// TODO Check null for InitialValuesType and if null create new
268
			// InitialValuesType
269
			EMap nsMap = _root.getXMLNSPrefixMap();
270
			TopicSpace2MetaDataDescriptor topicSpace2MetaData = new TopicSpace2MetaDataDescriptor(
271
					nsMap, topicSpaces);
272
			String[] topicExpressions = topicSpace2MetaData
273
					.getTopicExpressions();
274
			FeatureMap fm = intialValues.getAny();
275
			for (int i = 0; i < topicExpressions.length; i++)
276
			{
277
				EStructuralFeature esf = _extendedMetaData.demandFeature(
278
						WSNT_NS, "TopicExpression", true);
279
				AnyType atTopicExpression = XMLTypeFactory.eINSTANCE
280
						.createAnyType();
281
				FeatureMapUtil.addText(atTopicExpression.getAny(),
282
						topicExpressions[i]);
283
				fm.add(esf, atTopicExpression);
284
			}
285
			topicExpressionProperty.setInitialValues(intialValues);
286
		}
287
	}
288
289
	public PropertyType[] getPropertyTypes()
290
	{
291
		return getAllPropertyTypes();
292
	}
293
294
	public void setDocumentRoot(DocumentRoot root)
295
	{
296
		_root = root;
297
	}
298
299
	public void setMetadataDescriptorType(
300
			MetadataDescriptorType metadataDescriptor)
301
	{
302
		_metadataDescriptor = metadataDescriptor;
303
	}
304
305
	public void setMetadataDescriptorName(String metadataDescriptorName)
306
	{
307
		_metadataDescriptorName = metadataDescriptorName;
308
		if (_metadataDescriptor != null)
309
			_metadataDescriptor.setName(metadataDescriptorName);
310
	}
311
312
	public PropertyType createNewPropertyType()
313
	{
314
		PropertyType propertyType = _rmdFactory.createPropertyType();
315
		_metadataDescriptor.getProperty().add(propertyType);
316
		return propertyType;
317
	}
318
319
	public PropertyType createTopicExpressionProperty()
320
	{
321
		_root.getXMLNSPrefixMap().put("wsnt", WSNT_NS);
322
		PropertyType topicExp = _rmdFactory.createPropertyType();
323
		topicExp.setModifiability(ModifiabilityType.READ_ONLY_LITERAL);
324
		topicExp.setMutability(MutabilityType.MUTABLE_LITERAL);
325
		topicExp.setName("wsnt:TopicExpression");
326
		InitialValuesType initialValues = _rmdFactory.createInitialValuesType();
327
		topicExp.setInitialValues(initialValues);
328
329
		FeatureMap fm = topicExp.getAny();
330
		AnyType atCapability = XMLTypeFactory.eINSTANCE.createAnyType();
331
		FeatureMapUtil.addText(atCapability.getAny(), WSNT_NS);
332
		fm.add(esfWSDM_Capability, atCapability);
333
334
		_metadataDescriptor.getProperty().add(topicExp);
335
		return topicExp;
336
	}
337
338
	public Metrics getMetrics(PropertyType propertyMetadata)
339
	{
340
		boolean metricsCapabilityFound = false;
341
		String changeType = null;
342
		String timeScope = null;
343
		String gatheringTime = null;
344
		String calculationInterval = null;
345
		FeatureMap fm = propertyMetadata.getAny();
346
		Iterator it = fm.iterator();
347
		while (it.hasNext())
348
		{
349
			Object obj = it.next();
350
			if (obj instanceof EStructuralFeatureImpl.SimpleFeatureMapEntry)
351
			{
352
				EStructuralFeatureImpl.SimpleFeatureMapEntry entry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) obj;
353
				if (entry.getValue() instanceof ChangeTypeType)
354
				{
355
					ChangeTypeType changeTypeType = (ChangeTypeType) entry
356
							.getValue();
357
					changeType = changeTypeType.getLiteral();
358
				}
359
				if (entry.getValue() instanceof TimeScopeType)
360
				{
361
					TimeScopeType timeScopeType = (TimeScopeType) entry
362
							.getValue();
363
					timeScope = timeScopeType.getLiteral();
364
				}
365
				if (entry.getValue() instanceof GatheringTimeType)
366
				{
367
					GatheringTimeType gatheringTimeType = (GatheringTimeType) entry
368
							.getValue();
369
					gatheringTime = gatheringTimeType.getLiteral();
370
				}
371
				if (entry.getEStructuralFeature().getName().equals(
372
						"calculationInterval"))
373
				{
374
					calculationInterval = entry.getValue().toString();
375
				}
376
				if (entry.getEStructuralFeature().getName()
377
						.equals("capability"))
378
				{
379
					if (entry.getValue() instanceof String
380
							&& entry.getValue().equals(METRICS_CAPABILITY))
381
						metricsCapabilityFound = true;
382
				}
383
			}
384
		}
385
386
		if (metricsCapabilityFound)
387
		{
388
			Metrics metrics = CapabilitiesFactory.eINSTANCE.createMetrics();
389
			metrics.setChangeType(changeType);
390
			metrics.setTimeScope(timeScope);
391
			metrics.setGatheringTime(gatheringTime);
392
			metrics.setCalculationInterval(calculationInterval);
393
			return metrics;
394
		}
395
396
		return null;
397
	}
398
399
	public void saveMetrics()
400
	{
401
		List properties = _capability.getProperties();
402
		for (int i = 0; i < properties.size(); i++)
403
		{
404
			Property property = (Property) properties.get(i);
405
			saveMetrics(property);
406
		}
407
	}
408
409
	private void saveMetrics(Property property)
410
	{
411
		Metrics metrics = property.getMetrics();
412
		PropertyType metadata = property.getMetaData();
413
		if (metadata != null)
414
			metadata.getAny().clear();
415
		if (metrics == null)
416
			return;
417
418
		// Create Metrics capability
419
		FeatureMap featureMap = metadata.getAny();
420
		EStructuralFeature esf = _extendedMetaData.demandFeature(MUWS_P2_NS,
421
				"Capability", true);
422
		createExtendedMetadata(featureMap, esf, METRICS_CAPABILITY);
423
424
		// Create Change Type
425
		if (metrics.getChangeType() != null)
426
		{
427
			esf = _extendedMetaData.demandFeature(MUWS_P2_NS, "ChangeType",
428
					true);
429
			createExtendedMetadata(featureMap, esf, metrics.getChangeType());
430
		}
431
432
		// Create Time Scope
433
		if (metrics.getTimeScope() != null)
434
		{
435
			esf = _extendedMetaData
436
					.demandFeature(MUWS_P2_NS, "TimeScope", true);
437
			createExtendedMetadata(featureMap, esf, metrics.getTimeScope());
438
		}
439
440
		// Create Gathering Time
441
		if (metrics.getGatheringTime() != null)
442
		{
443
			esf = _extendedMetaData.demandFeature(MUWS_P2_NS, "GatheringTime",
444
					true);
445
			createExtendedMetadata(featureMap, esf, metrics.getGatheringTime());
446
		}
447
448
		// Create Calculation Interval
449
		if (metrics.getCalculationInterval() != null)
450
		{
451
			esf = _extendedMetaData.demandFeature(MUWS_P2_NS,
452
					"CalculationInterval", true);
453
			createExtendedMetadata(featureMap, esf, metrics
454
					.getCalculationInterval());
455
		}
456
	}
457
458
	private void createExtendedMetadata(FeatureMap featureMap,
459
			EStructuralFeature esf, String value)
460
	{
461
		AnyType anyType = XMLTypeFactory.eINSTANCE.createAnyType();
462
		FeatureMapUtil.addText(anyType.getMixed(), value);
463
		featureMap.add(esf, anyType);
464
	}
465
466
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/WsdlUtils.java (-968 / +973 lines)
Lines 25-31 Link Here
25
25
26
import javax.xml.namespace.QName;
26
import javax.xml.namespace.QName;
27
27
28
import org.apache.muse.util.xml.XmlUtils;
29
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IFile;
30
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IProgressMonitor;
Lines 72-1064 Link Here
72
public class WsdlUtils
71
public class WsdlUtils
73
{
72
{
74
73
75
    public static final String RESOURCE_PROPERTIES_ELEMENT_KEY = "ResourceProperties";
74
	public static final String RESOURCE_PROPERTIES_ELEMENT_KEY = "ResourceProperties";
76
75
77
    public static final String METADATA_DESCRIPTOR_LOCATION_KEY = "metadataDescriptorLocation";
76
	public static final String METADATA_DESCRIPTOR_LOCATION_KEY = "metadataDescriptorLocation";
78
77
79
    public static final String METADATA_DESCRIPTOR_KEY = "metadataDescriptor";
78
	public static final String METADATA_DESCRIPTOR_KEY = "metadataDescriptor";
80
79
81
    /**
80
	/**
82
         * Returns the EMF based object Definition of the given WSDL file.
81
	 * Returns the EMF based object Definition of the given WSDL file.
83
         * 
82
	 * 
84
         * @param wsdlFile
83
	 * @param wsdlFile
85
         *                Any WSDL file available in eclipse workbench
84
	 *            Any WSDL file available in eclipse workbench
86
         * 
85
	 * 
87
         * @return EMF based Definition object
86
	 * @return EMF based Definition object
88
     * @throws Exception 
87
	 * @throws Exception
89
         */
88
	 */
90
    public static Definition getWSDLDefinition(IFile wsdlFile) throws Exception
89
	public static Definition getWSDLDefinition(IFile wsdlFile) throws Exception
91
    {
90
	{
92
	URI wsdlURI = URI.createPlatformResourceURI(wsdlFile.getFullPath()
91
		URI wsdlURI = URI.createPlatformResourceURI(wsdlFile.getFullPath()
93
		.toString());
92
				.toString());
94
	return getWSDLDefinition(wsdlURI);
93
		return getWSDLDefinition(wsdlURI);
95
    }
94
	}
96
95
97
    /**
96
	/**
98
         * Returns the EMF based Definition object of the given URI of any WSDL
97
	 * Returns the EMF based Definition object of the given URI of any WSDL
99
         * file.
98
	 * file.
100
         * 
99
	 * 
101
         * @param wsdlURI
100
	 * @param wsdlURI
102
         *                URI of any WSDL file available in eclipse workbench
101
	 *            URI of any WSDL file available in eclipse workbench
103
         * 
102
	 * 
104
         * @return EMF based Definition object
103
	 * @return EMF based Definition object
105
     * @throws Exception 
104
	 * @throws Exception
106
         */
105
	 */
107
    public static Definition getWSDLDefinition(URI wsdlURI) throws Exception
106
	public static Definition getWSDLDefinition(URI wsdlURI) throws Exception
108
    {
107
	{
109
	ResourceSet resourceSet = new ResourceSetImpl();
108
		ResourceSet resourceSet = new ResourceSetImpl();
110
	resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
109
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
111
		.put("*.wsdl", new CustomWSDLResourceFactoryImpl());
110
				.put("*.wsdl", new CustomWSDLResourceFactoryImpl());
112
	WSDLResourceImpl wsdlMainResource = (WSDLResourceImpl) resourceSet
111
		WSDLResourceImpl wsdlMainResource = (WSDLResourceImpl) resourceSet
113
		.createResource(URI.createURI("*.wsdl"));
112
				.createResource(URI.createURI("*.wsdl"));
114
	wsdlMainResource.setURI(wsdlURI);
113
		wsdlMainResource.setURI(wsdlURI);
115
	java.util.Map map = new Hashtable();
114
		java.util.Map map = new Hashtable();
116
	map.put(WSDLResourceImpl.CONTINUE_ON_LOAD_ERROR, Boolean.valueOf(true));
115
		map.put(WSDLResourceImpl.CONTINUE_ON_LOAD_ERROR, Boolean.valueOf(true));
117
	try
116
		try
118
	{
117
		{
119
	    wsdlMainResource.load(map);
118
			wsdlMainResource.load(map);
120
	} catch (Exception ex)
119
		} catch (Exception ex)
121
	{
120
		{
122
	    WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_, ex);
121
			WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_, ex);
123
	    throw ex;
122
			throw ex;
124
	}
123
		}
125
124
126
	Definition definition = null;
125
		Definition definition = null;
127
	for (Iterator resources = resourceSet.getResources().iterator(); resources
126
		for (Iterator resources = resourceSet.getResources().iterator(); resources
128
		.hasNext();)
127
				.hasNext();)
129
	{
128
		{
130
	    Object resource = resources.next();
129
			Object resource = resources.next();
131
	    if (resource instanceof WSDLResourceImpl)
130
			if (resource instanceof WSDLResourceImpl)
132
	    {
131
			{
133
		WSDLResourceImpl wsdlResource = (WSDLResourceImpl) resource;
132
				WSDLResourceImpl wsdlResource = (WSDLResourceImpl) resource;
134
		definition = wsdlResource.getDefinition();
133
				definition = wsdlResource.getDefinition();
135
		if (definition.getTargetNamespace() == null) // Not a proper
134
				if (definition.getTargetNamespace() == null) // Not a proper
136
		    // WSDL file
135
					// WSDL file
137
		    throw new Exception(Messages.IMPROPER_WSDL_FILE_ERROR_);
136
					throw new Exception(Messages.IMPROPER_WSDL_FILE_ERROR_);
137
				return definition;
138
			}
139
		}
140
141
		return null;
142
	}
143
144
	/**
145
	 * Returns the WSDL Operation defined inside given port type index. If WSDL
146
	 * file does not contain port type then it will return null. If the given
147
	 * port type index is less than 0 then it will return null. If the given
148
	 * port type index is greater than the available port types then it will
149
	 * return null.
150
	 * 
151
	 * @param definition
152
	 *            WSDL Definition object.
153
	 * 
154
	 * @param portTypeIndex
155
	 *            Port type index.
156
	 * 
157
	 * @return Operations available in given port type index.
158
	 */
159
	public static Operation[] getWSDLOperation(Definition definition,
160
			int portTypeIndex)
161
	{
162
		PortType portType = getPortType(definition, portTypeIndex);
163
		if (portType == null)
164
			return null;
165
		return (Operation[]) portType.getOperations().toArray();
166
	}
167
168
	/**
169
	 * Returns the WSDL Operation defined inside first port type.
170
	 * 
171
	 * @param definition
172
	 *            WSDL Definition object.
173
	 * 
174
	 * @return Operations available inside first port type.
175
	 */
176
	public static Operation[] getWSDLOperation(Definition definition)
177
	{
178
		return getWSDLOperation(definition, 0);
179
	}
180
181
	/**
182
	 * Returns the Port Type defined inside given WSDL Definition object. If
183
	 * WSDL file does not contain port type then it will return null. If the
184
	 * given port type index is less than 0 then it will return null. If the
185
	 * given port type index is greater than the available port types then it
186
	 * will return null.
187
	 * 
188
	 * @param definition
189
	 *            WSDL Definition object.
190
	 * 
191
	 * @param portTypeIndex
192
	 *            Port type index.
193
	 * 
194
	 * @return Port Type defined inside given WSDL Definition object.
195
	 */
196
	public static PortType getPortType(Definition definition, int portTypeIndex)
197
	{
198
		if (portTypeIndex < 0)
199
		{
200
			WsdmToolingLog
201
					.logWarning(Messages.PORT_TYPE_INDEX_LESS_THAN_0_ERROR_);
202
			return null;
203
		}
204
		List portTypeList = definition.getEPortTypes();
205
		if (portTypeList == null || portTypeList.size() == 0)
206
		{
207
			// Don't log message in Error log it will go to problems view while
208
			// validating mcap files
209
			// WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_);
210
			return null;
211
		}
212
		if (portTypeIndex > portTypeList.size())
213
		{
214
			WsdmToolingLog.logWarning(NLS.bind(
215
					Messages.PORT_TYPE_INDEX_CANT_MORE_ERROR_, Integer
216
							.toString(portTypeList.size())));
217
			return null;
218
		}
219
		PortType portType = (PortType) portTypeList.get(portTypeIndex);
220
		return portType;
221
	}
222
223
	/**
224
	 * Returns the first Port Type defined inside given WSDL Definition object.
225
	 * 
226
	 * @param definition
227
	 *            WSDL Definition object.
228
	 * 
229
	 * @return First Port Type defined inside given WSDL Definition object.
230
	 */
231
	public static PortType getPortType(Definition definition)
232
	{
233
		return getPortType(definition, 0);
234
	}
235
236
	/**
237
	 * Returns the name of given WSDL Operation object.
238
	 * 
239
	 * @param operation
240
	 *            WSDL Operation object.
241
	 * 
242
	 * @return Name of WSDL Operation object.
243
	 */
244
	public static String getOperationName(Operation operation)
245
	{
246
		return operation.getName();
247
	}
248
249
	/**
250
	 * Create new WSDL Definition object.
251
	 * 
252
	 * @param targetNamespace
253
	 *            TargetNamespace to be used for new WSDL Definition.
254
	 * 
255
	 * @param prefix
256
	 *            TargetNamespace prefix to be used.
257
	 * 
258
	 * @param name
259
	 *            Name for WSDL Definition. It will appear as "name" attribute
260
	 *            inside "deinition" element.
261
	 * 
262
	 * @param location
263
	 *            WSDL File location.
264
	 * 
265
	 * @return new WSDL Definition object.
266
	 */
267
	public static Definition createNewWSDLDefinition(String targetNamespace,
268
			String prefix, String name, String location)
269
	{
270
		Definition definition = WSDLFactory.eINSTANCE.createDefinition();
271
		definition.setTargetNamespace(targetNamespace);
272
		definition.addNamespace("xsd", XsdUtils.XMLSCHEMA_2001_URI);
273
		definition.addNamespace("soap", WsdlConstants.SOAP_NAMESPACE_URI);
274
		definition.addNamespace("wsdl", WsdlConstants.WSDL_NAMESPACE_URI);
275
		definition.setLocation(location);
276
		definition.setEncoding("UTF-8");
277
		definition.setQName(new QName(targetNamespace, name));
278
		if (prefix != null)
279
			definition.addNamespace(prefix, targetNamespace);
280
		else
281
			definition.addNamespace("tns", targetNamespace);
282
		definition.updateElement(true);
138
		return definition;
283
		return definition;
139
	    }
140
	}
284
	}
141
285
142
	return null;
286
	/**
143
    }
287
	 * Saves an WSDL Definition object into ResourceSet and returns the
288
	 * ByteArrayOutputStream of the saved object.
289
	 * 
290
	 * @param definition
291
	 *            WSDL Definition object to be saved.
292
	 * 
293
	 * @param fileURI
294
	 *            URI String of the file to which WSDL Definition object will be
295
	 *            saved.
296
	 * 
297
	 * @param resourceSet
298
	 *            ResourceSet used for saving it, if null ResourceSet specified
299
	 *            then the method will create new ResourceSet.
300
	 * 
301
	 * @return ByteArrayOutputStream representation of the saved object.
302
	 * @throws IOException
303
	 */
304
	public static ByteArrayOutputStream saveWSDLDefinition(
305
			Definition definition, String fileURI, ResourceSet resourceSet)
306
			throws IOException
307
	{
308
		if (resourceSet == null)
309
		{
310
			resourceSet = new ResourceSetImpl();
311
		}
312
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
313
				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
314
						new CustomWSDLResourceFactoryImpl());
315
		URI wsdlFileURI = URI.createPlatformResourceURI(fileURI);
316
		Resource resource = resourceSet.createResource(wsdlFileURI);
317
		resource.getContents().add(definition);
318
		Map options = new HashMap();
319
		ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
320
		try
321
		{
322
			resource.save(baOutputStream, options);
323
		} catch (IOException e)
324
		{
325
			WsdmToolingLog
326
					.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_, e);
327
			throw e;
328
		}
329
		return baOutputStream;
330
	}
144
331
145
    /**
332
	/**
146
         * Returns the WSDL Operation defined inside given port type index. If
333
	 * Saves an WSDL Definition into IFile in formatted representation.
147
         * WSDL file does not contain port type then it will return null. If the
334
	 * 
148
         * given port type index is less than 0 then it will return null. If the
335
	 * @param definition
149
         * given port type index is greater than the available port types then
336
	 *            WSDL Definition object to be saved.
150
         * it will return null.
337
	 * 
151
         * 
338
	 * @param wsdlFile
152
         * @param definition
339
	 *            Eclipse file to which WSDL Definition object will be saved.
153
         *                WSDL Definition object.
340
	 * 
154
         * 
341
	 * @param monitor
155
         * @param portTypeIndex
342
	 *            Progress monitor.
156
         *                Port type index.
343
	 * @throws IOException
157
         * 
344
	 * @throws CoreException
158
         * @return Operations available in given port type index.
345
	 */
159
         */
346
	public static void serializeAndFormatWSDL(Definition definition,
160
    public static Operation[] getWSDLOperation(Definition definition,
347
			IFile wsdlFile, IProgressMonitor monitor) throws IOException,
161
	    int portTypeIndex)
348
			CoreException
162
    {
349
	{
163
	PortType portType = getPortType(definition, portTypeIndex);
350
		String fileURI = wsdlFile.getFullPath().toString();
164
	if (portType == null)
351
		ByteArrayOutputStream baos = saveWSDLDefinition(definition, fileURI,
165
	    return null;
352
				null);
166
	return (Operation[]) portType.getOperations().toArray();
353
		String serializedString = CapUtils.getSerializedDocument(baos
167
    }
354
				.toString());
168
355
		ByteArrayInputStream baInputStream = new ByteArrayInputStream(
169
    /**
356
				serializedString.getBytes());
170
         * Returns the WSDL Operation defined inside first port type.
357
		try
171
         * 
358
		{
172
         * @param definition
359
			if (wsdlFile.exists())
173
         *                WSDL Definition object.
360
				wsdlFile.setContents(baInputStream, IFile.FORCE, monitor);
174
         * 
361
			else
175
         * @return Operations available inside first port type.
362
				wsdlFile.create(baInputStream, IFile.FORCE, monitor);
176
         */
363
		} catch (CoreException e)
177
    public static Operation[] getWSDLOperation(Definition definition)
364
		{
178
    {
365
			WsdmToolingLog
179
	return getWSDLOperation(definition, 0);
366
					.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_, e);
180
    }
367
			throw e;
181
182
    /**
183
         * Returns the Port Type defined inside given WSDL Definition object. If
184
         * WSDL file does not contain port type then it will return null. If the
185
         * given port type index is less than 0 then it will return null. If the
186
         * given port type index is greater than the available port types then
187
         * it will return null.
188
         * 
189
         * @param definition
190
         *                WSDL Definition object.
191
         * 
192
         * @param portTypeIndex
193
         *                Port type index.
194
         * 
195
         * @return Port Type defined inside given WSDL Definition object.
196
         */
197
    public static PortType getPortType(Definition definition, int portTypeIndex)
198
    {
199
	if (portTypeIndex < 0)
200
	{
201
	    WsdmToolingLog
202
		    .logWarning(Messages.PORT_TYPE_INDEX_LESS_THAN_0_ERROR_);
203
	    return null;
204
	}
205
	List portTypeList = definition.getEPortTypes();
206
	if (portTypeList == null || portTypeList.size() == 0)
207
	{
208
	    // Don't log message in Error log it will go to problems view while validating mcap files
209
		//WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_);
210
	    return null;
211
	}
212
	if (portTypeIndex > portTypeList.size())
213
	{
214
	    WsdmToolingLog.logWarning(NLS.bind(
215
		    Messages.PORT_TYPE_INDEX_CANT_MORE_ERROR_, Integer
216
			    .toString(portTypeList.size())));
217
	    return null;
218
	}
219
	PortType portType = (PortType) portTypeList.get(portTypeIndex);
220
	return portType;
221
    }
222
223
    /**
224
         * Returns the first Port Type defined inside given WSDL Definition
225
         * object.
226
         * 
227
         * @param definition
228
         *                WSDL Definition object.
229
         * 
230
         * @return First Port Type defined inside given WSDL Definition object.
231
         */
232
    public static PortType getPortType(Definition definition)
233
    {
234
	return getPortType(definition, 0);
235
    }
236
237
    /**
238
         * Returns the name of given WSDL Operation object.
239
         * 
240
         * @param operation
241
         *                WSDL Operation object.
242
         * 
243
         * @return Name of WSDL Operation object.
244
         */
245
    public static String getOperationName(Operation operation)
246
    {
247
	return operation.getName();
248
    }
249
250
    /**
251
         * Create new WSDL Definition object.
252
         * 
253
         * @param targetNamespace
254
         *                TargetNamespace to be used for new WSDL Definition.
255
         * 
256
         * @param prefix
257
         *                TargetNamespace prefix to be used.
258
         * 
259
         * @param name
260
         *                Name for WSDL Definition. It will appear as "name"
261
         *                attribute inside "deinition" element.
262
         * 
263
         * @param location
264
         *                WSDL File location.
265
         * 
266
         * @return new WSDL Definition object.
267
         */
268
    public static Definition createNewWSDLDefinition(String targetNamespace,
269
	    String prefix, String name, String location)
270
    {
271
	Definition definition = WSDLFactory.eINSTANCE.createDefinition();
272
	definition.setTargetNamespace(targetNamespace);
273
	definition.addNamespace("xsd", XsdUtils.XMLSCHEMA_2001_URI);
274
	definition.addNamespace("soap", WsdlConstants.SOAP_NAMESPACE_URI);
275
	definition.addNamespace("wsdl", WsdlConstants.WSDL_NAMESPACE_URI);
276
	definition.setLocation(location);
277
	definition.setEncoding("UTF-8");
278
	definition.setQName(new QName(targetNamespace, name));
279
	if (prefix != null)
280
	    definition.addNamespace(prefix, targetNamespace);
281
	else
282
	    definition.addNamespace("tns", targetNamespace);
283
	definition.updateElement(true);
284
	return definition;
285
    }
286
287
    /**
288
         * Saves an WSDL Definition object into ResourceSet and returns the
289
         * ByteArrayOutputStream of the saved object.
290
         * 
291
         * @param definition
292
         *                WSDL Definition object to be saved.
293
         * 
294
         * @param fileURI
295
         *                URI String of the file to which WSDL Definition object
296
         *                will be saved.
297
         * 
298
         * @param resourceSet
299
         *                ResourceSet used for saving it, if null ResourceSet
300
         *                specified then the method will create new ResourceSet.
301
         * 
302
         * @return ByteArrayOutputStream representation of the saved object.
303
     * @throws IOException 
304
         */
305
    public static ByteArrayOutputStream saveWSDLDefinition(
306
	    Definition definition, String fileURI, ResourceSet resourceSet) throws IOException
307
    {
308
	if (resourceSet == null)
309
	{
310
	    resourceSet = new ResourceSetImpl();
311
	}
312
	resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
313
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
314
			new CustomWSDLResourceFactoryImpl());
315
	URI wsdlFileURI = URI.createPlatformResourceURI(fileURI);
316
	Resource resource = resourceSet.createResource(wsdlFileURI);
317
	resource.getContents().add(definition);
318
	Map options = new HashMap();
319
	ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
320
	try
321
	{
322
	    resource.save(baOutputStream, options);
323
	} catch (IOException e)
324
	{
325
	    WsdmToolingLog
326
		    .logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_, e);
327
	    throw e;
328
	}
329
	return baOutputStream;
330
    }
331
332
    /**
333
         * Saves an WSDL Definition into IFile in formatted representation.
334
         * 
335
         * @param definition
336
         *                WSDL Definition object to be saved.
337
         * 
338
         * @param wsdlFile
339
         *                Eclipse file to which WSDL Definition object will be
340
         *                saved.
341
         * 
342
         * @param monitor
343
         *                Progress monitor.
344
     * @throws IOException 
345
     * @throws CoreException 
346
         */
347
    public static void serializeAndFormatWSDL(Definition definition,
348
	    IFile wsdlFile, IProgressMonitor monitor) throws IOException, CoreException
349
    {
350
	String fileURI = wsdlFile.getFullPath().toString();
351
	ByteArrayOutputStream baos = saveWSDLDefinition(definition, fileURI,
352
		null);
353
	String serializedString = CapUtils.getSerializedDocument(baos
354
		.toString());
355
	ByteArrayInputStream baInputStream = new ByteArrayInputStream(
356
		serializedString.getBytes());
357
	try
358
	{
359
	    if (wsdlFile.exists())
360
		wsdlFile.setContents(baInputStream, IFile.FORCE, monitor);
361
	    else
362
		wsdlFile.create(baInputStream, IFile.FORCE, monitor);
363
	} catch (CoreException e)
364
	{
365
	    WsdmToolingLog
366
		    .logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_, e);
367
	    throw e;
368
	}
369
    }
370
371
    /**
372
         * It will return the XSD Schema defined inside WSDL Types. If no WSDL
373
         * Types are defined then this method will create new WSDL Types and
374
         * will create new XSDSchema and return it. If WSDL Types are defined
375
         * but no XSDSchema is defined then it will create new XSDSchema and
376
         * return it.
377
         * 
378
         * @param definition
379
         *                WSDL Definition object.
380
         * 
381
         * @param tns
382
         *                XSDSchema targetnamespace to be searched.
383
         * 
384
         * @return XSDSchema object.
385
         */
386
    public static XSDSchema createOrFindSchema(Definition definition, String tns)
387
    {
388
	XSDSchema[] schemas = getXSDSchemas(definition);
389
	if (schemas == null)
390
	{
391
	    // No WSDL Types found
392
	    Types types = WSDLFactory.eINSTANCE.createTypes();
393
	    definition.setETypes(types);
394
	    types.setEnclosingDefinition(definition);
395
	}
396
	else
397
	{
398
	    // Some schemas exists
399
	    for (int i = 0; i < schemas.length; i++)
400
	    {
401
		if (schemas[i].getTargetNamespace().equals(tns))
402
		    return schemas[i];
403
	    }
404
	}
405
	XSDSchema schema = XsdUtils.createNewXSDSchema(tns);
406
	XSDSchemaExtensibilityElement schemaElement = WSDLFactory.eINSTANCE
407
		.createXSDSchemaExtensibilityElement();
408
	schemaElement.setEnclosingDefinition(definition);
409
	schemaElement.setSchema(schema);
410
	definition.getTypes().addExtensibilityElement(schemaElement);
411
	return schema;
412
    }
413
414
    /**
415
         * Returns the XSDSchema of WSDL Definition based on the namespace
416
         * passed.
417
         */
418
    public static XSDSchema getSchema(Definition definition, String tns)
419
    {
420
	XSDSchema[] schemas = getXSDSchemas(definition);
421
	if (schemas == null)
422
	    return null;
423
	for (int i = 0; i < schemas.length; i++)
424
	{
425
	    String schemaTns = schemas[i].getTargetNamespace();
426
	    if (schemaTns != null
427
		    && schemas[i].getTargetNamespace().equals(tns))
428
		return schemas[i];
429
	}
430
431
	// Some of the schemas in WSDL could be defined as
432
	// <xsd:schema>
433
	// <xsd:import namespace="http://docs.oasis-open.org/wsrf/rp-2"
434
        // schemaLocation="WS-ResourceProperties-1_2.xsd" />
435
	// </xsd:schema>
436
	// We have to handle such type of case
437
438
	for (int i = 0; i < schemas.length; i++)
439
	{
440
	    XSDImport[] imports = XsdUtils.getAllXSDImports(schemas[i]);
441
	    for (int j = 0; j < imports.length; j++)
442
	    {
443
		if (imports[j].getNamespace().equals(tns))
444
		    return imports[j].getResolvedSchema();
445
	    }
446
447
	    XSDInclude[] includes = XsdUtils.getAllXSDIncludes(schemas[i]);
448
	    for (int k = 0; k < includes.length; k++)
449
	    {
450
		if (includes[k].getResolvedSchema().getTargetNamespace()
451
			.equals(tns))
452
		    return includes[k].getResolvedSchema();
453
	    }
454
	}
455
	// Don't log message in Error log it will go to problems view while validating mcap files
456
	//WsdmToolingLog.logWarning(NLS.bind(Messages.NO_SCHEMA_FOUND_FOR_NS_WARN_, tns));
457
	return null;
458
    }
459
460
    /**
461
         * Returns the array of XSDSchema defined in WSDL Definition.
462
         */
463
    public static XSDSchema[] getXSDSchemas(Definition def)
464
    {
465
	List schemaList = new ArrayList();
466
	Types types = (Types) def.getTypes();
467
	if (types == null)
468
	{
469
	    WsdmToolingLog.logWarning(Messages.NO_TYPES_FOUND_ERROR_);
470
	    return null;
471
	}
472
	List extList = types.getExtensibilityElements();
473
	XSDSchemaExtensibilityElement schemaElement = null;
474
	Iterator it = extList.iterator();
475
	while (it.hasNext())
476
	{
477
	    Object object = it.next();
478
	    if (object instanceof XSDSchemaExtensibilityElement)
479
	    {
480
		schemaElement = (XSDSchemaExtensibilityElement) object;
481
		XSDSchema schema = schemaElement.getSchema();
482
		schemaList.add(schema);
483
	    }
484
	}
485
	return (XSDSchema[]) schemaList.toArray(new XSDSchema[0]);
486
    }
487
488
    /**
489
         * Returns XSDElementDeclaration for return type of operation.
490
         */
491
    public static XSDElementDeclaration getReturnTypeElement(Operation operation)
492
    {
493
	if (operation.getEOutput() == null)
494
	    return null;
495
	if (operation.getEOutput().getEMessage() == null)
496
	    return null;
497
	List parts = operation.getEOutput().getEMessage().getEParts();
498
	if (parts == null || parts.size() == 0)
499
	    return null;
500
	Part part_0 = (Part) parts.get(0);
501
	return part_0.getElementDeclaration();
502
    }
503
504
    /**
505
         * Returns Message part for return type of operation.
506
         */
507
    public static Part getReturnTypeMessagePart(Operation operation)
508
    {
509
	if (operation.getEOutput() == null)
510
	    return null;
511
	if (operation.getEOutput().getEMessage() == null)
512
	    return null;
513
	List parts = operation.getEOutput().getEMessage().getEParts();
514
	if (parts == null || parts.size() == 0)
515
	    return null;
516
	Part part_0 = (Part) parts.get(0);
517
	return part_0;
518
    }
519
520
    /**
521
         * Returns the operation parameters as XSDElementDeclaration.
522
         */
523
    public static XSDElementDeclaration[] getOperationParams(Operation operation)
524
    {
525
	XSDElementDeclaration[] empty_param = new XSDElementDeclaration[0];
526
	if (operation.getEInput() == null)
527
	    return empty_param;
528
	if (operation.getEInput().getEMessage() == null)
529
	    return empty_param;
530
	List parts = operation.getEInput().getEMessage().getEParts();
531
	if (parts == null || parts.size() == 0)
532
	    return empty_param;
533
534
	Part part_0 = (Part) operation.getEInput().getEMessage().getEParts()
535
		.get(0);
536
	XSDElementDeclaration element = part_0.getElementDeclaration();
537
	XSDTypeDefinition typeDefinition = element.getTypeDefinition();
538
	if (typeDefinition == null)
539
	    return empty_param;
540
	if (typeDefinition instanceof XSDComplexTypeDefinition)
541
	{
542
	    XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) typeDefinition;
543
	    XSDModelGroup modelGroup = XsdUtils
544
		    .getXSDModelGroup(complexTypeDefinition);
545
	    return XsdUtils.getElementDeclarations(modelGroup);
546
	}
547
	return new XSDElementDeclaration[] { element };
548
    }
549
550
    /**
551
         * Returns the namespace of given prefix.
552
         */
553
    public static String getNamespace(Definition definition, String prefix)
554
    {
555
	NamedNodeMap map = definition.getElement().getAttributes();
556
	for (int i = 0; i < map.getLength(); i++)
557
	{
558
	    if (map.item(i) instanceof Attr)
559
	    {
560
		Attr attribute = (Attr) map.item(i);
561
		if (attribute.getNodeName().startsWith("xmlns:"))
562
		{
563
		    String pfx = attribute.getNodeName().substring(
564
			    "xmlns:".length());
565
		    if (pfx.equals(prefix))
566
			return attribute.getNodeValue();
567
		}
568
	    }
569
	}
570
	WsdmToolingLog.logWarning(NLS.bind(
571
		Messages.NO_NS_FOUND_FOR_PREFIX_WARN_, prefix));
572
	return null;
573
    }
574
575
    /**
576
         * Returns the prefix for given namespace in WSDL Definition.
577
         */
578
    public static String getPrefix(Definition definition, String namespace)
579
    {
580
	NamedNodeMap map = definition.getElement().getAttributes();
581
	for (int i = 0; i < map.getLength(); i++)
582
	{
583
	    if (map.item(i) instanceof Attr)
584
	    {
585
		Attr attribute = (Attr) map.item(i);
586
		if (attribute.getNodeValue().equals(namespace))
587
		{
588
		    if (attribute.getNodeName().startsWith("xmlns:"))
589
		    {
590
			String prefix = attribute.getNodeName().substring(
591
				"xmlns:".length());
592
			return prefix;
593
		    }
594
		}
368
		}
595
	    }
596
	}
369
	}
597
	WsdmToolingLog.logWarning(NLS.bind(
370
598
		Messages.NO_PREFIX_FOUND_FOR_NS_WARN_, namespace));
371
	/**
599
	return null;
372
	 * It will return the XSD Schema defined inside WSDL Types. If no WSDL Types
600
    }
373
	 * are defined then this method will create new WSDL Types and will create
601
374
	 * new XSDSchema and return it. If WSDL Types are defined but no XSDSchema
602
    /**
375
	 * is defined then it will create new XSDSchema and return it.
603
         * Returns true if perticular namespace defined inside WSDL definition.
376
	 * 
604
         */
377
	 * @param definition
605
    public static boolean isNamespaceDefined(Definition definition,
378
	 *            WSDL Definition object.
606
	    String namespace)
379
	 * 
607
    {
380
	 * @param tns
608
	if (getPrefix(definition, namespace) == null)
381
	 *            XSDSchema targetnamespace to be searched.
609
	    return false;
382
	 * 
610
	return true;
383
	 * @return XSDSchema object.
611
    }
384
	 */
612
385
	public static XSDSchema createOrFindSchema(Definition definition, String tns)
613
    /**
614
         * Returns the WSDL targetnamespace prefix.
615
         */
616
    public static String getTargetNamespacePrefix(Definition def)
617
    {
618
	return getPrefix(def, def.getTargetNamespace());
619
    }
620
621
    /**
622
         * Returns ResourcePropertyElement from WSDL Definition.
623
         */
624
    public static XSDElementDeclaration getResourcePropertyElement(
625
	    Definition definition, String resourceProperties)
626
    {
627
	String rpNsPrefix = null;
628
	String elementName = resourceProperties;
629
	if (resourceProperties.indexOf(":") != -1)
630
	{
631
	    rpNsPrefix = resourceProperties.substring(0, resourceProperties
632
		    .indexOf(":"));
633
	    elementName = resourceProperties.substring(resourceProperties
634
		    .indexOf(":") + 1);
635
	}
636
	XSDSchema xsdSchema = null;
637
	if (rpNsPrefix == null)
638
	{
639
	    xsdSchema = getSchema(definition, definition.getTargetNamespace());
640
	}
641
	else
642
	{
643
	    String ns = getNamespace(definition, rpNsPrefix);
644
	    xsdSchema = getSchema(definition, ns);
645
	}
646
647
	XSDElementDeclaration resourcePropertyElement = XsdUtils
648
		.getXSDElementDeclarationOfName(xsdSchema, elementName);
649
	if (resourcePropertyElement == null)
650
	    WsdmToolingLog.logMessage(Messages.NO_RP_ELEMENT_ERROR_);
651
	return resourcePropertyElement;
652
    }
653
654
    /**
655
         * Returns the MetadataMap from WSDL port type.<br>
656
         * This map contain values for resource properties, metadatadescriptor
657
         * and metadatadescriptorlocation.
658
     * @throws CoreException 
659
     * @throws IOException 
660
     * @throws SAXException 
661
         */
662
    public static Map getMetadataFromPortType(IFile wsdlFile) throws CoreException, IOException, SAXException
663
    {
664
	Map map = new HashMap();
665
	InputStream is = null;
666
	Document document = null;
667
	try
668
	{
669
	    is = wsdlFile.getContents();
670
	    document = XmlUtils.createDocument(is);
671
	} catch (CoreException e)
672
	{
673
	    WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e);
674
	    throw e;
675
	} catch (IOException e)
676
	{
677
	    WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e);
678
	    throw e;
679
	} catch (SAXException e)
680
	{
681
	    WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e);
682
	    throw e;
683
	}
684
685
	NodeList nlpt = document.getElementsByTagNameNS(
686
		WsdlConstants.WSDL_NAMESPACE_URI, "portType");
687
	Element pte = (Element) nlpt.item(0);
688
	if (pte == null)
689
	    WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_);
690
691
	String metadataDescriptor = pte.getAttributeNS(WsdmConstants.WSRMD_NS,
692
		METADATA_DESCRIPTOR_KEY);
693
	if (metadataDescriptor == null || metadataDescriptor.equals(""))
694
	    WsdmToolingLog.logMessage(Messages.NO_METADESCRIPTOR_WARN_);
695
	else
696
	    map.put(METADATA_DESCRIPTOR_KEY, metadataDescriptor);
697
698
	String metadataDescriptorLocation = pte.getAttributeNS(
699
		WsdmConstants.WSRMD_NS, METADATA_DESCRIPTOR_LOCATION_KEY);
700
	if (metadataDescriptorLocation == null
701
		|| metadataDescriptorLocation.equals(""))
702
	    WsdmToolingLog
703
		    .logMessage(Messages.NO_METADESCRIPTOR_LOCATION_WARN_);
704
	else
705
	    map.put(METADATA_DESCRIPTOR_LOCATION_KEY,
706
		    metadataDescriptorLocation);
707
708
	String resourceProperties = pte.getAttributeNS(WsdmConstants.WSRP_NS,
709
		RESOURCE_PROPERTIES_ELEMENT_KEY);
710
	if (resourceProperties == null || resourceProperties.equals(""))
711
	    WsdmToolingLog.logMessage(Messages.NO_RP_ATTRIBUTE_WARN_);
712
	else
713
	    map.put(RESOURCE_PROPERTIES_ELEMENT_KEY, resourceProperties);
714
715
	return map;
716
    }
717
718
    /**
719
         * Returns the MetadataMap from WSDL port type.<br>
720
         * This map contain values for resource properties, metadatadescriptor
721
         * and metadatadescriptorlocation.
722
         */
723
    public static Map getMetadataFromPortType(Definition wsdlDefinition)
724
    {
725
	Map map = new HashMap();
726
	Element wsdlElement = wsdlDefinition.getElement();
727
728
	NodeList nlpt = wsdlElement.getElementsByTagNameNS(
729
		WsdlConstants.WSDL_NAMESPACE_URI, "portType");
730
	Element pte = (Element) nlpt.item(0);
731
	if (pte == null)
732
	{
733
	    // Don't log message in Error log it will go to problems view while validating mcap files
734
		//WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_);
735
	    return null;
736
	}
737
738
	String metadataDescriptor = pte.getAttributeNS(WsdmConstants.WSRMD_NS,
739
		METADATA_DESCRIPTOR_KEY);
740
	if (metadataDescriptor == null || metadataDescriptor.equals(""))
741
	{
742
	    metadataDescriptor = null;
743
	    // Don't log message in Error log it will go to problems view while validating mcap files
744
	    //WsdmToolingLog.logWarning(Messages.NO_METADESCRIPTOR_WARN_);
745
	}
746
747
	String metadataDescriptorLocation = pte.getAttributeNS(
748
		WsdmConstants.WSRMD_NS, METADATA_DESCRIPTOR_LOCATION_KEY);
749
	if (metadataDescriptorLocation == null
750
		|| metadataDescriptorLocation.equals(""))
751
	{
752
	    metadataDescriptorLocation = null;
753
	    // Don't log message in Error log it will go to problems view while validating mcap files
754
	    //WsdmToolingLog.logWarning(Messages.NO_METADESCRIPTOR_LOCATION_WARN_);
755
	}
756
757
	String resourceProperties = pte.getAttributeNS(WsdmConstants.WSRP_NS,
758
		RESOURCE_PROPERTIES_ELEMENT_KEY);
759
	if (resourceProperties == null || resourceProperties.equals(""))
760
	{
761
	    resourceProperties = null;
762
	    // Don't log message in Error log it will go to problems view while validating mcap files
763
	    //WsdmToolingLog.logWarning(Messages.NO_RP_ATTRIBUTE_WARN_);
764
	}
765
766
	map.put(METADATA_DESCRIPTOR_KEY, metadataDescriptor);
767
	map.put(METADATA_DESCRIPTOR_LOCATION_KEY, metadataDescriptorLocation);
768
	map.put(RESOURCE_PROPERTIES_ELEMENT_KEY, resourceProperties);
769
770
	return map;
771
    }
772
773
    /**
774
         * Returns the WSDLFileLocation from WSDL Definition.
775
         */
776
    public static String getWSDLFileLocation(Definition definition)
777
    {
778
	if (definition.getLocation() != null
779
		&& !definition.getLocation().equals(""))
780
	    return definition.getLocation();
781
	Resource resource = definition.eResource();
782
	if (resource == null)
783
	{
784
	    WsdmToolingLog.logWarning(Messages.IMPROPER_WSDL_FILE_ERROR_);
785
	    return null;
786
	}
787
	URI uri = resource.getURI();
788
	if (uri == null)
789
	{
790
	    WsdmToolingLog.logWarning(Messages.IMPROPER_WSDL_FILE_ERROR_);
791
	    return null;
792
	}
793
	return uri.toString();
794
    }
795
796
    /**
797
         * Creates or return existing prefix. If the passed newPrefix is null,
798
         * the it generates a unique prefix for the namespace.
799
         */
800
    public static String createOrFindPrefix(Definition definition,
801
	    String namespace, String newPrefix)
802
    {
803
	String prefix = getPrefix(definition, namespace);
804
	if (prefix != null)
805
	    return prefix;
806
	if (newPrefix != null)
807
	    definition.addNamespace(newPrefix, namespace);
808
	else
809
	{
810
	    newPrefix = generateNewPrefix(definition);
811
	    definition.addNamespace(newPrefix, namespace);
812
	}
813
	return newPrefix;
814
    }
815
816
    private static String generateNewPrefix(Definition definition)
817
    {
818
	int count = 0;
819
	String prefix = "pfx" + count;
820
	while (isPrefixDefined(definition, prefix))
821
	{
822
	    prefix = "pfx" + count++;
823
	}
824
	return prefix;
825
    }
826
827
    private static boolean isPrefixDefined(Definition definition, String prefix)
828
    {
829
	String[] namespaces = getAllDefinedNamespaces(definition);
830
	for (int i = 0; i < namespaces.length; i++)
831
	{
386
	{
832
	    String pfx = getPrefix(definition, namespaces[i]);
387
		XSDSchema[] schemas = getXSDSchemas(definition);
833
	    if (pfx.equals(prefix))
388
		if (schemas == null)
834
		return true;
389
		{
390
			// No WSDL Types found
391
			Types types = WSDLFactory.eINSTANCE.createTypes();
392
			definition.setETypes(types);
393
			types.setEnclosingDefinition(definition);
394
		}
395
		else
396
		{
397
			// Some schemas exists
398
			for (int i = 0; i < schemas.length; i++)
399
			{
400
				if (schemas[i].getTargetNamespace().equals(tns))
401
					return schemas[i];
402
			}
403
		}
404
		XSDSchema schema = XsdUtils.createNewXSDSchema(tns);
405
		XSDSchemaExtensibilityElement schemaElement = WSDLFactory.eINSTANCE
406
				.createXSDSchemaExtensibilityElement();
407
		schemaElement.setEnclosingDefinition(definition);
408
		schemaElement.setSchema(schema);
409
		definition.getTypes().addExtensibilityElement(schemaElement);
410
		return schema;
411
	}
412
413
	/**
414
	 * Returns the XSDSchema of WSDL Definition based on the namespace passed.
415
	 */
416
	public static XSDSchema getSchema(Definition definition, String tns)
417
	{
418
		XSDSchema[] schemas = getXSDSchemas(definition);
419
		if (schemas == null)
420
			return null;
421
		for (int i = 0; i < schemas.length; i++)
422
		{
423
			String schemaTns = schemas[i].getTargetNamespace();
424
			if (schemaTns != null
425
					&& schemas[i].getTargetNamespace().equals(tns))
426
				return schemas[i];
427
		}
428
429
		// Some of the schemas in WSDL could be defined as
430
		// <xsd:schema>
431
		// <xsd:import namespace="http://docs.oasis-open.org/wsrf/rp-2"
432
		// schemaLocation="WS-ResourceProperties-1_2.xsd" />
433
		// </xsd:schema>
434
		// We have to handle such type of case
435
436
		for (int i = 0; i < schemas.length; i++)
437
		{
438
			XSDImport[] imports = XsdUtils.getAllXSDImports(schemas[i]);
439
			for (int j = 0; j < imports.length; j++)
440
			{
441
				if (imports[j].getNamespace().equals(tns))
442
					return imports[j].getResolvedSchema();
443
			}
444
445
			XSDInclude[] includes = XsdUtils.getAllXSDIncludes(schemas[i]);
446
			for (int k = 0; k < includes.length; k++)
447
			{
448
				if (includes[k].getResolvedSchema().getTargetNamespace()
449
						.equals(tns))
450
					return includes[k].getResolvedSchema();
451
			}
452
		}
453
		// Don't log message in Error log it will go to problems view while
454
		// validating mcap files
455
		// WsdmToolingLog.logWarning(NLS.bind(Messages.NO_SCHEMA_FOUND_FOR_NS_WARN_,
456
		// tns));
457
		return null;
458
	}
459
460
	/**
461
	 * Returns the array of XSDSchema defined in WSDL Definition.
462
	 */
463
	public static XSDSchema[] getXSDSchemas(Definition def)
464
	{
465
		List schemaList = new ArrayList();
466
		Types types = (Types) def.getTypes();
467
		if (types == null)
468
		{
469
			WsdmToolingLog.logWarning(Messages.NO_TYPES_FOUND_ERROR_);
470
			return null;
471
		}
472
		List extList = types.getExtensibilityElements();
473
		XSDSchemaExtensibilityElement schemaElement = null;
474
		Iterator it = extList.iterator();
475
		while (it.hasNext())
476
		{
477
			Object object = it.next();
478
			if (object instanceof XSDSchemaExtensibilityElement)
479
			{
480
				schemaElement = (XSDSchemaExtensibilityElement) object;
481
				XSDSchema schema = schemaElement.getSchema();
482
				schemaList.add(schema);
483
			}
484
		}
485
		return (XSDSchema[]) schemaList.toArray(new XSDSchema[0]);
486
	}
487
488
	/**
489
	 * Returns XSDElementDeclaration for return type of operation.
490
	 */
491
	public static XSDElementDeclaration getReturnTypeElement(Operation operation)
492
	{
493
		if (operation.getEOutput() == null)
494
			return null;
495
		if (operation.getEOutput().getEMessage() == null)
496
			return null;
497
		List parts = operation.getEOutput().getEMessage().getEParts();
498
		if (parts == null || parts.size() == 0)
499
			return null;
500
		Part part_0 = (Part) parts.get(0);
501
		return part_0.getElementDeclaration();
502
	}
503
504
	/**
505
	 * Returns Message part for return type of operation.
506
	 */
507
	public static Part getReturnTypeMessagePart(Operation operation)
508
	{
509
		if (operation.getEOutput() == null)
510
			return null;
511
		if (operation.getEOutput().getEMessage() == null)
512
			return null;
513
		List parts = operation.getEOutput().getEMessage().getEParts();
514
		if (parts == null || parts.size() == 0)
515
			return null;
516
		Part part_0 = (Part) parts.get(0);
517
		return part_0;
518
	}
519
520
	/**
521
	 * Returns the operation parameters as XSDElementDeclaration.
522
	 */
523
	public static XSDElementDeclaration[] getOperationParams(Operation operation)
524
	{
525
		XSDElementDeclaration[] empty_param = new XSDElementDeclaration[0];
526
		if (operation.getEInput() == null)
527
			return empty_param;
528
		if (operation.getEInput().getEMessage() == null)
529
			return empty_param;
530
		List parts = operation.getEInput().getEMessage().getEParts();
531
		if (parts == null || parts.size() == 0)
532
			return empty_param;
533
534
		Part part_0 = (Part) operation.getEInput().getEMessage().getEParts()
535
				.get(0);
536
		XSDElementDeclaration element = part_0.getElementDeclaration();
537
		XSDTypeDefinition typeDefinition = element.getTypeDefinition();
538
		if (typeDefinition == null)
539
			return empty_param;
540
		if (typeDefinition instanceof XSDComplexTypeDefinition)
541
		{
542
			XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) typeDefinition;
543
			XSDModelGroup modelGroup = XsdUtils
544
					.getXSDModelGroup(complexTypeDefinition);
545
			return XsdUtils.getElementDeclarations(modelGroup);
546
		}
547
		return new XSDElementDeclaration[] { element };
548
	}
549
550
	/**
551
	 * Returns the namespace of given prefix.
552
	 */
553
	public static String getNamespace(Definition definition, String prefix)
554
	{
555
		NamedNodeMap map = definition.getElement().getAttributes();
556
		for (int i = 0; i < map.getLength(); i++)
557
		{
558
			if (map.item(i) instanceof Attr)
559
			{
560
				Attr attribute = (Attr) map.item(i);
561
				if (attribute.getNodeName().startsWith("xmlns:"))
562
				{
563
					String pfx = attribute.getNodeName().substring(
564
							"xmlns:".length());
565
					if (pfx.equals(prefix))
566
						return attribute.getNodeValue();
567
				}
568
			}
569
		}
570
		WsdmToolingLog.logWarning(NLS.bind(
571
				Messages.NO_NS_FOUND_FOR_PREFIX_WARN_, prefix));
572
		return null;
573
	}
574
575
	/**
576
	 * Returns the prefix for given namespace in WSDL Definition.
577
	 */
578
	public static String getPrefix(Definition definition, String namespace)
579
	{
580
		NamedNodeMap map = definition.getElement().getAttributes();
581
		for (int i = 0; i < map.getLength(); i++)
582
		{
583
			if (map.item(i) instanceof Attr)
584
			{
585
				Attr attribute = (Attr) map.item(i);
586
				if (attribute.getNodeValue().equals(namespace))
587
				{
588
					if (attribute.getNodeName().startsWith("xmlns:"))
589
					{
590
						String prefix = attribute.getNodeName().substring(
591
								"xmlns:".length());
592
						return prefix;
593
					}
594
				}
595
			}
596
		}
597
		WsdmToolingLog.logWarning(NLS.bind(
598
				Messages.NO_PREFIX_FOUND_FOR_NS_WARN_, namespace));
599
		return null;
835
	}
600
	}
836
	return false;
837
    }
838
601
839
    /**
602
	/**
840
         * Returns all the namespaces defined in the WSDL file.
603
	 * Returns true if perticular namespace defined inside WSDL definition.
841
         */
604
	 */
842
    public static String[] getAllDefinedNamespaces(Definition definition)
605
	public static boolean isNamespaceDefined(Definition definition,
843
    {
606
			String namespace)
844
	List namespaces = new ArrayList();
845
	NamedNodeMap map = definition.getElement().getAttributes();
846
	for (int i = 0; i < map.getLength(); i++)
847
	{
848
	    if (map.item(i) instanceof Attr)
849
	    {
850
		Attr attribute = (Attr) map.item(i);
851
		if (attribute.getNodeName().startsWith("xmlns:"))
852
		{
853
		    String ns = attribute.getNodeValue();
854
		    namespaces.add(ns);
855
		}
856
	    }
857
	}
858
	return (String[]) namespaces.toArray(new String[namespaces.size()]);
859
    }
860
861
    /**
862
         * Returns the fault name of given faultElement.
863
         */
864
    public static String getFaultType(XSDElementDeclaration faultElement)
865
    {
866
	String default_type = faultElement.getName();
867
	XSDTypeDefinition typeDef = faultElement.getTypeDefinition();
868
	if (typeDef == null)
869
	    return default_type;
870
	if (!(typeDef instanceof XSDComplexTypeDefinition))
871
	    return default_type;
872
	XSDComplexTypeDefinition complexTypeDef = (XSDComplexTypeDefinition) typeDef;
873
	XSDDerivationMethod derivationMethod = complexTypeDef
874
		.getDerivationMethod();
875
	if (derivationMethod == null)
876
	    return default_type;
877
	if (!derivationMethod.equals(XSDDerivationMethod.EXTENSION_LITERAL))
878
	    return default_type;
879
	XSDTypeDefinition baseTypeDef = complexTypeDef.getBaseTypeDefinition();
880
	if (baseTypeDef == null)
881
	    return default_type;
882
	if (!(baseTypeDef instanceof XSDSimpleTypeDefinition))
883
	    return default_type;
884
	XSDSimpleTypeDefinition simpleBaseTypeDef = (XSDSimpleTypeDefinition) baseTypeDef;
885
	return simpleBaseTypeDef.getName();
886
    }
887
888
    /**
889
         * Returns the XSD fault elements of given wsdl operation.
890
         */
891
    public static List getOperationFaultElements(Operation operation)
892
    {
893
	List retVal = new ArrayList();
894
	List faults = operation.getEFaults();
895
	for (int i = 0; i < faults.size(); i++)
896
	{
897
	    Fault fault = (Fault) faults.get(i);
898
	    XSDElementDeclaration faultElement = getFaultElement(fault);
899
	    if (faultElement != null)
900
		retVal.add(faultElement);
901
	}
902
	return retVal;
903
    }
904
905
    /**
906
         * Retruns the XSD fault elements of given wsdl fault.
907
         */
908
    public static XSDElementDeclaration getFaultElement(Fault fault)
909
    {
910
	Message msg = fault.getEMessage();
911
	Part part_0 = (Part) msg.getEParts().get(0);
912
	XSDElementDeclaration element = part_0.getElementDeclaration();
913
	return element;
914
    }
915
916
    /**
917
         * Returns the message which contains the given XSDElementDeclaration.
918
         */
919
    public static Message getMessage(Definition definition,
920
	    XSDElementDeclaration element)
921
    {
922
	List msgs = definition.getEMessages();
923
	for (int i = 0; i < msgs.size(); i++)
924
	{
925
	    Message msg = (Message) msgs.get(i);
926
	    Part part = getPart(msg, element);
927
	    if (part != null)
928
		return msg;
929
	}
930
	return null;
931
    }
932
933
    private static Part getPart(Message msg, XSDElementDeclaration element)
934
    {
935
	List parts = msg.getEParts();
936
	for (int i = 0; i < parts.size(); i++)
937
	{
938
	    Part part = (Part) parts.get(i);
939
	    XSDElementDeclaration partElement = part.getElementDeclaration();
940
	    if (element.equals(partElement))
941
		return part;
942
	}
943
	return null;
944
    }
945
946
    /**
947
         * Returns the Fault of given Message.
948
         */
949
    public static Fault getFault(Operation operation, Message message)
950
    {
951
	List faults = operation.getEFaults();
952
	for (int i = 0; i < faults.size(); i++)
953
	{
954
	    Fault fault = (Fault) faults.get(i);
955
	    Message msg = fault.getEMessage();
956
	    if (message.equals(msg))
957
		return fault;
958
	}
959
	return null;
960
    }
961
962
    /**
963
         * Returns the name of WSDL Definition.
964
         */
965
    public static String getName(Definition wsdlDef)
966
    {
967
	return wsdlDef.getQName().getLocalPart();
968
    }
969
970
    /**
971
         * Create a new WSDL Import element inside given Definition. If imported
972
         * namespace or wsdlLocation is null then it does nothing. If imported
973
         * namespace is already imported in one of the WSDL Import element of
974
         * the WSDL then it does nothing.
975
         * 
976
         * @param definition
977
         *                Given WSDL definition inside which this new WSDL
978
         *                Import element will be added.
979
         * 
980
         * @param namespace
981
         *                Namespace to be imported.
982
         * 
983
         * @param wsdlLocation
984
         *                WSDL location to be imported.
985
         */
986
    public static void createWSDLImport(Definition definition,
987
	    String namespace, String wsdlLocation)
988
    {
989
	if (namespace == null || wsdlLocation == null)
990
	    return;
991
	/*
992
         * if (definition.getTargetNamespace().equals(namespace)) return;
993
         */
994
	if (!isImportNSExists(definition, namespace))
995
	{
996
	    Import wsdlImport = WSDLFactory.eINSTANCE.createImport();
997
	    wsdlImport.setEnclosingDefinition(definition);
998
	    wsdlImport.setEDefinition(definition);
999
	    wsdlImport.setLocationURI(wsdlLocation);
1000
	    wsdlImport.setNamespaceURI(namespace);
1001
	    definition.addImport(wsdlImport);
1002
	    createOrFindPrefix(definition, namespace, null);
1003
	}
1004
    }
1005
1006
    /**
1007
         * Check if perticular import already exists in given WSDL definition.
1008
         */
1009
    public static boolean isImportNSExists(Definition definition,
1010
	    String namespace)
1011
    {
1012
	List imports = definition.getEImports();
1013
	for (int i = 0; i < imports.size(); i++)
1014
	{
607
	{
1015
	    Import wsdlImport = (Import) imports.get(i);
608
		if (getPrefix(definition, namespace) == null)
1016
	    if (wsdlImport.getNamespaceURI().equals(namespace))
609
			return false;
1017
		return true;
610
		return true;
1018
	}
611
	}
1019
	return false;
1020
    }
1021
612
1022
    /**
613
	/**
1023
         * Returns the absolute path of given WSDL defintion in the local file
614
	 * Returns the WSDL targetnamespace prefix.
1024
         * system.
615
	 */
1025
     * @throws CoreException 
616
	public static String getTargetNamespacePrefix(Definition def)
1026
         */
617
	{
1027
    public static String getLocalSystemWSDLLocation(Definition definition) throws CoreException
618
		return getPrefix(def, def.getTargetNamespace());
1028
    {
619
	}
1029
	String uriLocation = getWSDLFileLocation(definition);
620
1030
	String wsdlLocation = uriLocation;
621
	/**
1031
	try
622
	 * Returns ResourcePropertyElement from WSDL Definition.
1032
	{
623
	 */
1033
	    IFile wsdlFile = EclipseUtils.getIFile(uriLocation);
624
	public static XSDElementDeclaration getResourcePropertyElement(
1034
	    wsdlLocation = wsdlFile.getLocation().toString();
625
			Definition definition, String resourceProperties)
1035
	    wsdlLocation = EclipseUtils.replaceAll(wsdlLocation, '\\', '/');
626
	{
1036
	} catch (CoreException e)
627
		String rpNsPrefix = null;
1037
	{
628
		String elementName = resourceProperties;
1038
	    WsdmToolingLog
629
		if (resourceProperties.indexOf(":") != -1)
1039
		    .logError(
630
		{
1040
			    NLS
631
			rpNsPrefix = resourceProperties.substring(0, resourceProperties
1041
				    .bind(
632
					.indexOf(":"));
1042
					    org.eclipse.tptp.wsdm.tooling.nls.messages.capability.property.internal.Messages.FAILED_TO_FIND_LOCATION_FOR_XSD_ERROR_,
633
			elementName = resourceProperties.substring(resourceProperties
1043
					    uriLocation), e);
634
					.indexOf(":") + 1);
1044
	    throw e;
635
		}
636
		XSDSchema xsdSchema = null;
637
		if (rpNsPrefix == null)
638
		{
639
			xsdSchema = getSchema(definition, definition.getTargetNamespace());
640
		}
641
		else
642
		{
643
			String ns = getNamespace(definition, rpNsPrefix);
644
			xsdSchema = getSchema(definition, ns);
645
		}
646
647
		XSDElementDeclaration resourcePropertyElement = XsdUtils
648
				.getXSDElementDeclarationOfName(xsdSchema, elementName);
649
		if (resourcePropertyElement == null)
650
			WsdmToolingLog.logMessage(Messages.NO_RP_ELEMENT_ERROR_);
651
		return resourcePropertyElement;
652
	}
653
654
	/**
655
	 * Returns the MetadataMap from WSDL port type.<br>
656
	 * This map contain values for resource properties, metadatadescriptor and
657
	 * metadatadescriptorlocation.
658
	 * 
659
	 * @throws CoreException
660
	 * @throws IOException
661
	 * @throws SAXException
662
	 */
663
	public static Map getMetadataFromPortType(IFile wsdlFile)
664
			throws CoreException, IOException, SAXException
665
	{
666
		Map map = new HashMap();
667
		InputStream is = null;
668
		Document document = null;
669
		try
670
		{
671
			is = wsdlFile.getContents();
672
			document = CapUtils.createDocument(is);
673
		} catch (CoreException e)
674
		{
675
			WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e);
676
			throw e;
677
		} catch (IOException e)
678
		{
679
			WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e);
680
			throw e;
681
		} catch (SAXException e)
682
		{
683
			WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e);
684
			throw e;
685
		}
686
687
		NodeList nlpt = document.getElementsByTagNameNS(
688
				WsdlConstants.WSDL_NAMESPACE_URI, "portType");
689
		Element pte = (Element) nlpt.item(0);
690
		if (pte == null)
691
			WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_);
692
693
		String metadataDescriptor = pte.getAttributeNS(WsdmConstants.WSRMD_NS,
694
				METADATA_DESCRIPTOR_KEY);
695
		if (metadataDescriptor == null || metadataDescriptor.equals(""))
696
			WsdmToolingLog.logMessage(Messages.NO_METADESCRIPTOR_WARN_);
697
		else
698
			map.put(METADATA_DESCRIPTOR_KEY, metadataDescriptor);
699
700
		String metadataDescriptorLocation = pte.getAttributeNS(
701
				WsdmConstants.WSRMD_NS, METADATA_DESCRIPTOR_LOCATION_KEY);
702
		if (metadataDescriptorLocation == null
703
				|| metadataDescriptorLocation.equals(""))
704
			WsdmToolingLog
705
					.logMessage(Messages.NO_METADESCRIPTOR_LOCATION_WARN_);
706
		else
707
			map.put(METADATA_DESCRIPTOR_LOCATION_KEY,
708
					metadataDescriptorLocation);
709
710
		String resourceProperties = pte.getAttributeNS(WsdmConstants.WSRP_NS,
711
				RESOURCE_PROPERTIES_ELEMENT_KEY);
712
		if (resourceProperties == null || resourceProperties.equals(""))
713
			WsdmToolingLog.logMessage(Messages.NO_RP_ATTRIBUTE_WARN_);
714
		else
715
			map.put(RESOURCE_PROPERTIES_ELEMENT_KEY, resourceProperties);
716
717
		return map;
718
	}
719
720
	/**
721
	 * Returns the MetadataMap from WSDL port type.<br>
722
	 * This map contain values for resource properties, metadatadescriptor and
723
	 * metadatadescriptorlocation.
724
	 */
725
	public static Map getMetadataFromPortType(Definition wsdlDefinition)
726
	{
727
		Map map = new HashMap();
728
		Element wsdlElement = wsdlDefinition.getElement();
729
730
		NodeList nlpt = wsdlElement.getElementsByTagNameNS(
731
				WsdlConstants.WSDL_NAMESPACE_URI, "portType");
732
		Element pte = (Element) nlpt.item(0);
733
		if (pte == null)
734
		{
735
			// Don't log message in Error log it will go to problems view while
736
			// validating mcap files
737
			// WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_);
738
			return null;
739
		}
740
741
		String metadataDescriptor = pte.getAttributeNS(WsdmConstants.WSRMD_NS,
742
				METADATA_DESCRIPTOR_KEY);
743
		if (metadataDescriptor == null || metadataDescriptor.equals(""))
744
		{
745
			metadataDescriptor = null;
746
			// Don't log message in Error log it will go to problems view while
747
			// validating mcap files
748
			// WsdmToolingLog.logWarning(Messages.NO_METADESCRIPTOR_WARN_);
749
		}
750
751
		String metadataDescriptorLocation = pte.getAttributeNS(
752
				WsdmConstants.WSRMD_NS, METADATA_DESCRIPTOR_LOCATION_KEY);
753
		if (metadataDescriptorLocation == null
754
				|| metadataDescriptorLocation.equals(""))
755
		{
756
			metadataDescriptorLocation = null;
757
			// Don't log message in Error log it will go to problems view while
758
			// validating mcap files
759
			// WsdmToolingLog.logWarning(Messages.NO_METADESCRIPTOR_LOCATION_WARN_);
760
		}
761
762
		String resourceProperties = pte.getAttributeNS(WsdmConstants.WSRP_NS,
763
				RESOURCE_PROPERTIES_ELEMENT_KEY);
764
		if (resourceProperties == null || resourceProperties.equals(""))
765
		{
766
			resourceProperties = null;
767
			// Don't log message in Error log it will go to problems view while
768
			// validating mcap files
769
			// WsdmToolingLog.logWarning(Messages.NO_RP_ATTRIBUTE_WARN_);
770
		}
771
772
		map.put(METADATA_DESCRIPTOR_KEY, metadataDescriptor);
773
		map.put(METADATA_DESCRIPTOR_LOCATION_KEY, metadataDescriptorLocation);
774
		map.put(RESOURCE_PROPERTIES_ELEMENT_KEY, resourceProperties);
775
776
		return map;
777
	}
778
779
	/**
780
	 * Returns the WSDLFileLocation from WSDL Definition.
781
	 */
782
	public static String getWSDLFileLocation(Definition definition)
783
	{
784
		if (definition.getLocation() != null
785
				&& !definition.getLocation().equals(""))
786
			return definition.getLocation();
787
		Resource resource = definition.eResource();
788
		if (resource == null)
789
		{
790
			WsdmToolingLog.logWarning(Messages.IMPROPER_WSDL_FILE_ERROR_);
791
			return null;
792
		}
793
		URI uri = resource.getURI();
794
		if (uri == null)
795
		{
796
			WsdmToolingLog.logWarning(Messages.IMPROPER_WSDL_FILE_ERROR_);
797
			return null;
798
		}
799
		return uri.toString();
800
	}
801
802
	/**
803
	 * Creates or return existing prefix. If the passed newPrefix is null, the
804
	 * it generates a unique prefix for the namespace.
805
	 */
806
	public static String createOrFindPrefix(Definition definition,
807
			String namespace, String newPrefix)
808
	{
809
		String prefix = getPrefix(definition, namespace);
810
		if (prefix != null)
811
			return prefix;
812
		if (newPrefix != null)
813
			definition.addNamespace(newPrefix, namespace);
814
		else
815
		{
816
			newPrefix = generateNewPrefix(definition);
817
			definition.addNamespace(newPrefix, namespace);
818
		}
819
		return newPrefix;
1045
	}
820
	}
1046
	return wsdlLocation;
1047
    }
1048
}
1049
821
822
	private static String generateNewPrefix(Definition definition)
823
	{
824
		int count = 0;
825
		String prefix = "pfx" + count;
826
		while (isPrefixDefined(definition, prefix))
827
		{
828
			prefix = "pfx" + count++;
829
		}
830
		return prefix;
831
	}
1050
832
1051
class CustomWSDLResourceFactoryImpl extends ResourceFactoryImpl
833
	private static boolean isPrefixDefined(Definition definition, String prefix)
1052
{	
834
	{
1053
	public CustomWSDLResourceFactoryImpl()
835
		String[] namespaces = getAllDefinedNamespaces(definition);
1054
    {
836
		for (int i = 0; i < namespaces.length; i++)
1055
    }
837
		{
838
			String pfx = getPrefix(definition, namespaces[i]);
839
			if (pfx.equals(prefix))
840
				return true;
841
		}
842
		return false;
843
	}
1056
844
1057
    public Resource createResource(URI uri)
845
	/**
1058
    {
846
	 * Returns all the namespaces defined in the WSDL file.
1059
        Resource result = new WSDLResourceImpl(uri);
847
	 */
1060
        return result;
848
	public static String[] getAllDefinedNamespaces(Definition definition)
1061
    }
849
	{
850
		List namespaces = new ArrayList();
851
		NamedNodeMap map = definition.getElement().getAttributes();
852
		for (int i = 0; i < map.getLength(); i++)
853
		{
854
			if (map.item(i) instanceof Attr)
855
			{
856
				Attr attribute = (Attr) map.item(i);
857
				if (attribute.getNodeName().startsWith("xmlns:"))
858
				{
859
					String ns = attribute.getNodeValue();
860
					namespaces.add(ns);
861
				}
862
			}
863
		}
864
		return (String[]) namespaces.toArray(new String[namespaces.size()]);
865
	}
866
867
	/**
868
	 * Returns the fault name of given faultElement.
869
	 */
870
	public static String getFaultType(XSDElementDeclaration faultElement)
871
	{
872
		String default_type = faultElement.getName();
873
		XSDTypeDefinition typeDef = faultElement.getTypeDefinition();
874
		if (typeDef == null)
875
			return default_type;
876
		if (!(typeDef instanceof XSDComplexTypeDefinition))
877
			return default_type;
878
		XSDComplexTypeDefinition complexTypeDef = (XSDComplexTypeDefinition) typeDef;
879
		XSDDerivationMethod derivationMethod = complexTypeDef
880
				.getDerivationMethod();
881
		if (derivationMethod == null)
882
			return default_type;
883
		if (!derivationMethod.equals(XSDDerivationMethod.EXTENSION_LITERAL))
884
			return default_type;
885
		XSDTypeDefinition baseTypeDef = complexTypeDef.getBaseTypeDefinition();
886
		if (baseTypeDef == null)
887
			return default_type;
888
		if (!(baseTypeDef instanceof XSDSimpleTypeDefinition))
889
			return default_type;
890
		XSDSimpleTypeDefinition simpleBaseTypeDef = (XSDSimpleTypeDefinition) baseTypeDef;
891
		return simpleBaseTypeDef.getName();
892
	}
893
894
	/**
895
	 * Returns the XSD fault elements of given wsdl operation.
896
	 */
897
	public static List getOperationFaultElements(Operation operation)
898
	{
899
		List retVal = new ArrayList();
900
		List faults = operation.getEFaults();
901
		for (int i = 0; i < faults.size(); i++)
902
		{
903
			Fault fault = (Fault) faults.get(i);
904
			XSDElementDeclaration faultElement = getFaultElement(fault);
905
			if (faultElement != null)
906
				retVal.add(faultElement);
907
		}
908
		return retVal;
909
	}
910
911
	/**
912
	 * Retruns the XSD fault elements of given wsdl fault.
913
	 */
914
	public static XSDElementDeclaration getFaultElement(Fault fault)
915
	{
916
		Message msg = fault.getEMessage();
917
		Part part_0 = (Part) msg.getEParts().get(0);
918
		XSDElementDeclaration element = part_0.getElementDeclaration();
919
		return element;
920
	}
921
922
	/**
923
	 * Returns the message which contains the given XSDElementDeclaration.
924
	 */
925
	public static Message getMessage(Definition definition,
926
			XSDElementDeclaration element)
927
	{
928
		List msgs = definition.getEMessages();
929
		for (int i = 0; i < msgs.size(); i++)
930
		{
931
			Message msg = (Message) msgs.get(i);
932
			Part part = getPart(msg, element);
933
			if (part != null)
934
				return msg;
935
		}
936
		return null;
937
	}
938
939
	private static Part getPart(Message msg, XSDElementDeclaration element)
940
	{
941
		List parts = msg.getEParts();
942
		for (int i = 0; i < parts.size(); i++)
943
		{
944
			Part part = (Part) parts.get(i);
945
			XSDElementDeclaration partElement = part.getElementDeclaration();
946
			if (element.equals(partElement))
947
				return part;
948
		}
949
		return null;
950
	}
951
952
	/**
953
	 * Returns the Fault of given Message.
954
	 */
955
	public static Fault getFault(Operation operation, Message message)
956
	{
957
		List faults = operation.getEFaults();
958
		for (int i = 0; i < faults.size(); i++)
959
		{
960
			Fault fault = (Fault) faults.get(i);
961
			Message msg = fault.getEMessage();
962
			if (message.equals(msg))
963
				return fault;
964
		}
965
		return null;
966
	}
967
968
	/**
969
	 * Returns the name of WSDL Definition.
970
	 */
971
	public static String getName(Definition wsdlDef)
972
	{
973
		return wsdlDef.getQName().getLocalPart();
974
	}
975
976
	/**
977
	 * Create a new WSDL Import element inside given Definition. If imported
978
	 * namespace or wsdlLocation is null then it does nothing. If imported
979
	 * namespace is already imported in one of the WSDL Import element of the
980
	 * WSDL then it does nothing.
981
	 * 
982
	 * @param definition
983
	 *            Given WSDL definition inside which this new WSDL Import
984
	 *            element will be added.
985
	 * 
986
	 * @param namespace
987
	 *            Namespace to be imported.
988
	 * 
989
	 * @param wsdlLocation
990
	 *            WSDL location to be imported.
991
	 */
992
	public static void createWSDLImport(Definition definition,
993
			String namespace, String wsdlLocation)
994
	{
995
		if (namespace == null || wsdlLocation == null)
996
			return;
997
		/*
998
		 * if (definition.getTargetNamespace().equals(namespace)) return;
999
		 */
1000
		if (!isImportNSExists(definition, namespace))
1001
		{
1002
			Import wsdlImport = WSDLFactory.eINSTANCE.createImport();
1003
			wsdlImport.setEnclosingDefinition(definition);
1004
			wsdlImport.setEDefinition(definition);
1005
			wsdlImport.setLocationURI(wsdlLocation);
1006
			wsdlImport.setNamespaceURI(namespace);
1007
			definition.addImport(wsdlImport);
1008
			createOrFindPrefix(definition, namespace, null);
1009
		}
1010
	}
1011
1012
	/**
1013
	 * Check if perticular import already exists in given WSDL definition.
1014
	 */
1015
	public static boolean isImportNSExists(Definition definition,
1016
			String namespace)
1017
	{
1018
		List imports = definition.getEImports();
1019
		for (int i = 0; i < imports.size(); i++)
1020
		{
1021
			Import wsdlImport = (Import) imports.get(i);
1022
			if (wsdlImport.getNamespaceURI().equals(namespace))
1023
				return true;
1024
		}
1025
		return false;
1026
	}
1027
1028
	/**
1029
	 * Returns the absolute path of given WSDL defintion in the local file
1030
	 * system.
1031
	 * 
1032
	 * @throws CoreException
1033
	 */
1034
	public static String getLocalSystemWSDLLocation(Definition definition)
1035
			throws CoreException
1036
	{
1037
		String uriLocation = getWSDLFileLocation(definition);
1038
		String wsdlLocation = uriLocation;
1039
		try
1040
		{
1041
			IFile wsdlFile = EclipseUtils.getIFile(uriLocation);
1042
			wsdlLocation = wsdlFile.getLocation().toString();
1043
			wsdlLocation = EclipseUtils.replaceAll(wsdlLocation, '\\', '/');
1044
		} catch (CoreException e)
1045
		{
1046
			WsdmToolingLog
1047
					.logError(
1048
							NLS
1049
									.bind(
1050
											org.eclipse.tptp.wsdm.tooling.nls.messages.capability.property.internal.Messages.FAILED_TO_FIND_LOCATION_FOR_XSD_ERROR_,
1051
											uriLocation), e);
1052
			throw e;
1053
		}
1054
		return wsdlLocation;
1055
	}
1062
}
1056
}
1063
1057
1058
class CustomWSDLResourceFactoryImpl extends ResourceFactoryImpl
1059
{
1060
	public CustomWSDLResourceFactoryImpl()
1061
	{
1062
	}
1064
1063
1064
	public Resource createResource(URI uri)
1065
	{
1066
		Resource result = new WSDLResourceImpl(uri);
1067
		return result;
1068
	}
1069
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/PropertyMetaDataDescriptor.java (-319 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.util.internal;
14
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.emf.common.util.EMap;
24
import org.eclipse.emf.ecore.EStructuralFeature;
25
import org.eclipse.emf.ecore.resource.ResourceSet;
26
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
27
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
28
import org.eclipse.emf.ecore.util.BasicFeatureMap;
29
import org.eclipse.emf.ecore.util.ExtendedMetaData;
30
import org.eclipse.emf.ecore.util.FeatureMap;
31
import org.eclipse.emf.ecore.util.FeatureMapUtil;
32
import org.eclipse.emf.ecore.xml.type.AnyType;
33
import org.eclipse.emf.ecore.xml.type.XMLTypeFactory;
34
import org.eclipse.emf.ecore.xml.type.internal.QName;
35
import org.eclipse.osgi.util.NLS;
36
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
37
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
38
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
39
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.InitialValuesType;
40
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorType;
41
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.ModifiabilityType;
42
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MutabilityType;
43
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
44
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorFactory;
45
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl;
46
47
/**
48
 * 
49
 * This class will worked as a wrapper class for the RMD defined for a capability.
50
 *
51
 */
52
53
public class PropertyMetaDataDescriptor
54
{
55
56
    private ExtendedMetaData _extendedMetaData;
57
58
    private DocumentRoot _root;
59
60
    private EStructuralFeature esfWSDM_Capability;
61
62
    private MetadataDescriptorFactory _rmdFactory = new MetadataDescriptorFactoryImpl();
63
64
    private String _metadataDescriptorName;
65
66
    private MetadataDescriptorType _metadataDescriptor;
67
68
    public PropertyMetaDataDescriptor(DocumentRoot root, Capability capability)
69
    {
70
	this(root, capability, capability.getName() + "Descriptor");
71
    }
72
73
    public PropertyMetaDataDescriptor(DocumentRoot root, Capability capability,
74
	    String metadataDescriptorName)
75
    {
76
	_root = root;
77
	if (metadataDescriptorName == null)
78
	    _metadataDescriptorName = capability.getName() + "Descriptor";
79
	_metadataDescriptorName = metadataDescriptorName;
80
	_extendedMetaData = createExtendedMetaData();
81
	if (_root != null)
82
	    _metadataDescriptor = getMetadataDescriptorType();
83
	this.esfWSDM_Capability = _extendedMetaData.demandFeature(
84
		WsdmConstants.MUWS_P2_NS, "Capability", true);
85
    }
86
87
    private ExtendedMetaData createExtendedMetaData()
88
    {
89
	ResourceSet resourceSet = new ResourceSetImpl();
90
	ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(
91
		resourceSet.getPackageRegistry());
92
	return extendedMetaData;
93
    }
94
95
    private PropertyType[] getAllPropertyTypes()
96
    {
97
	List capabilityProps = new LinkedList();
98
	List propList = _metadataDescriptor.getProperty();
99
	for (int i = 0; i < propList.size(); i++)
100
	{
101
	    PropertyType property = (PropertyType) propList.get(i);
102
	    capabilityProps.add(property);	    
103
	}
104
	return (PropertyType[]) capabilityProps.toArray(new PropertyType[0]);
105
    }
106
107
    public MetadataDescriptorType getMetadataDescriptorType()
108
    {
109
	List descriptors = _root.getDefinitions().getMetadataDescriptor();
110
	for (int i = 0; i < descriptors.size(); i++)
111
	{
112
	    MetadataDescriptorType mdtVal = (MetadataDescriptorType) descriptors
113
		    .get(i);
114
	    if (mdtVal.getName().equals(_metadataDescriptorName))
115
		return mdtVal;
116
	}
117
	WsdmToolingLog.logWarning(NLS.bind(Messages.METADESCRIPTOR_TYPE_NOT_FOUND_WARN_,_metadataDescriptorName));
118
	return null;
119
    }
120
121
    public DocumentRoot getDocumentRoot()
122
    {
123
	return _root;
124
    }
125
126
    public String getPrefix(String namespace)
127
    {
128
	if (namespace == null)
129
	    return null;
130
	EMap map = _root.getXMLNSPrefixMap();
131
	Iterator keyIt = map.keySet().iterator();
132
	Iterator valuesIt = map.values().iterator();
133
	while (valuesIt.hasNext())
134
	{
135
	    String ns = (String) valuesIt.next();
136
	    String prefix = (String) keyIt.next();
137
	    if (ns.equals(namespace))
138
		return prefix;
139
	}
140
	return null;
141
    }
142
143
    public String getOrCreatePrefix(String namespace)
144
    {
145
	String prefix = getPrefix(namespace);
146
	if (prefix != null)
147
	    return prefix;
148
	String newPrefix = generateNewPrefix();
149
	_root.getXMLNSPrefixMap().put(newPrefix, namespace);
150
	return newPrefix;
151
    }
152
153
    private String generateNewPrefix()
154
    {
155
	int count = 0;
156
	while (isPrefixExists("pfx" + count))
157
	    count++;
158
	return "pfx" + count;
159
    }
160
161
    private boolean isPrefixExists(String prefix)
162
    {
163
	EMap map = _root.getXMLNSPrefixMap();
164
	Iterator keyIt = map.keySet().iterator();
165
	while (keyIt.hasNext())
166
	{
167
	    String pfx = (String) keyIt.next();
168
	    if (pfx.equals(prefix))
169
		return true;
170
	}
171
	return false;
172
    }
173
174
    public List getTopicSpaces()
175
    {
176
	List topicSpaces = new ArrayList();
177
178
	PropertyType topicExpProperty = getTopicExpressionProperty();
179
	if (topicExpProperty == null)
180
	    return topicSpaces;
181
182
	InitialValuesType intialValues = topicExpProperty.getInitialValues();
183
	if (intialValues == null)
184
	    return topicSpaces;
185
186
	FeatureMap map = intialValues.getAny();
187
	Iterator it = map.valueListIterator();
188
	MetaDataDescriptor2TopicSpace metaData2TopicSpace = new MetaDataDescriptor2TopicSpace(
189
		_root.getXMLNSPrefixMap());
190
	while (it.hasNext())
191
	{
192
	    Object object = it.next();
193
	    if (object instanceof AnyType)
194
	    {
195
		AnyType anyType = (AnyType) object;
196
		FeatureMap anyMap = anyType.getAny();
197
		Iterator topicExpIt = anyMap.valueListIterator();
198
		while (topicExpIt.hasNext())
199
		{
200
		    String topicExpression = (String) topicExpIt.next();
201
		    metaData2TopicSpace.addTopicExpression(topicExpression);
202
		}
203
	    }
204
	}
205
	topicSpaces.addAll(metaData2TopicSpace.getTopicSpaces());
206
	return topicSpaces;
207
    }
208
209
    public PropertyType getTopicExpressionProperty()
210
    {
211
	PropertyType topicExpressionProperty = getPropertyMetadata("TopicExpression",
212
		WsdmConstants.WSNT_NS);
213
	return topicExpressionProperty;
214
    }
215
216
    public PropertyType getPropertyMetadata(String name, String namespace)
217
    {
218
	List properties = _metadataDescriptor.getProperty();
219
	for (int i = 0; i < properties.size(); i++)
220
	{
221
	    PropertyType property = (PropertyType) properties.get(i);
222
	    QName qname = (QName) property.getName();
223
	    if (qname.getLocalPart().equals(name)
224
		    && qname.getNamespaceURI().equals(namespace))
225
		return property;
226
	}
227
	return null;
228
    }
229
230
    public void saveTopicSpaces(List topicSpaces)
231
    {
232
	PropertyType topicExpressionProperty = getTopicExpressionProperty();
233
	if (topicExpressionProperty != null)
234
	{
235
	    InitialValuesType intialValues = _rmdFactory
236
		    .createInitialValuesType();
237
	    // TODO Check null for InitialValuesType and if null create new InitialValuesType
238
	    EMap nsMap = _root.getXMLNSPrefixMap();
239
	    TopicSpace2MetaDataDescriptor topicSpace2MetaData = new TopicSpace2MetaDataDescriptor(
240
		    nsMap, topicSpaces);
241
	    String[] topicExpressions = topicSpace2MetaData
242
		    .getTopicExpressions();
243
	    FeatureMap fm = intialValues.getAny();
244
	    for (int i = 0; i < topicExpressions.length; i++)
245
	    {
246
		EStructuralFeature esf = _extendedMetaData.demandFeature(
247
			WsdmConstants.WSNT_NS, "TopicExpression", true);
248
		AnyType atTopicExpression = XMLTypeFactory.eINSTANCE
249
			.createAnyType();
250
		FeatureMapUtil.addText(atTopicExpression.getAny(),
251
			topicExpressions[i]);
252
		fm.add(esf, atTopicExpression);		
253
	    }
254
	    topicExpressionProperty.setInitialValues(intialValues);
255
	}
256
    }
257
258
    public void save(IProgressMonitor monitor)
259
    {    	
260
    	String rmdFileUri = _root.eResource().getURI().toString();
261
    	IFile rmdFile = null;
262
		try {
263
			rmdFile = EclipseUtils.getIFile(rmdFileUri);
264
		} catch (CoreException e) {
265
			e.printStackTrace();
266
		}    	
267
    	RmdUtils.serializeAndFormat(_root, rmdFile, monitor);  	
268
    }
269
270
    public PropertyType[] getPropertyTypes()
271
    {
272
	return getAllPropertyTypes();
273
    }
274
275
    public void setDocumentRoot(DocumentRoot root)
276
    {
277
	_root = root;
278
    }
279
280
    public void setMetadataDescriptorType(
281
	    MetadataDescriptorType metadataDescriptor)
282
    {
283
	_metadataDescriptor = metadataDescriptor;
284
    }
285
286
    public void setMetadataDescriptorName(String metadataDescriptorName)
287
    {
288
	_metadataDescriptorName = metadataDescriptorName;
289
	if (_metadataDescriptor != null)
290
	    _metadataDescriptor.setName(metadataDescriptorName);
291
    }
292
293
    public PropertyType createNewPropertyType()
294
    {
295
	PropertyType propertyType = _rmdFactory.createPropertyType();
296
	_metadataDescriptor.getProperty().add(propertyType);
297
	return propertyType;
298
    }
299
300
    public PropertyType createTopicExpressionProperty()
301
    {
302
	_root.getXMLNSPrefixMap().put("wsnt", WsdmConstants.WSNT_NS);
303
	PropertyType topicExp = _rmdFactory.createPropertyType();
304
	topicExp.setModifiability(ModifiabilityType.READ_ONLY_LITERAL);
305
	topicExp.setMutability(MutabilityType.MUTABLE_LITERAL);
306
	topicExp.setName(new QName(WsdmConstants.WSNT_NS, "TopicExpression",
307
		"wsnt"));
308
	InitialValuesType initialValues = _rmdFactory.createInitialValuesType();
309
	topicExp.setInitialValues(initialValues);
310
311
	FeatureMap fm = topicExp.getAny();
312
	AnyType atCapability = XMLTypeFactory.eINSTANCE.createAnyType();
313
	FeatureMapUtil.addText(atCapability.getAny(), WsdmConstants.WSNT_NS);
314
	fm.add(esfWSDM_Capability, atCapability);
315
316
	_metadataDescriptor.getProperty().add(topicExp);
317
	return topicExp;
318
    }   
319
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/MetaDataDescriptor2TopicSpace.java (-207 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.util.internal;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
import java.util.StringTokenizer;
18
19
import org.eclipse.emf.common.util.EMap;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
22
23
/**
24
 * 
25
 * Populate capability topics from TopicExpression property.<br>
26
 * If RMD file has TopicExpression defined as <br><br> 
27
 * 
28
 * xmlns:topics1="http://w3.ibm.com/capabilities/WAS/Topics"<br>
29
 * 
30
 * &lt; wsnt:TopicExpression &gt; topics1:RootTopic &lt; /wsnt:TopicExpression &gt;<br>
31
 * &lt; wsnt:TopicExpression &gt; topics1:RootTopic/ChildTopic &lt; /wsnt:TopicExpression &gt;<br><br>
32
 * 
33
 * Then it will create in memory model for topics as<br><br>
34
 * 
35
 *  http://w3.ibm.com/capabilities/WAS (TopicNameSpace)<br>
36
 * 	|____RootTopic <br>
37
 * 	     |______ChildTopic <br><br>
38
 * 
39
 * @see #getTopicSpaces()
40
 * 
41
 */
42
43
public class MetaDataDescriptor2TopicSpace
44
{
45
46
    private List _topicSpaces;
47
48
    private EMap _nsMap;
49
50
    /**
51
     * Creates the object of this class.<br>
52
     * Parameter passed is the map of the namespaces available in rmd file. 
53
     */
54
    public MetaDataDescriptor2TopicSpace(EMap nsMap)
55
    {
56
	_nsMap = nsMap;
57
	_topicSpaces = new ArrayList();
58
    }
59
60
    /**
61
     * 
62
     * @param topicExpression
63
     *        Topic expression for which new topicSpace to be created.
64
     */
65
    public void addTopicExpression(String topicExpression)
66
    {
67
	TopicSpace topicSpace = getTopicSpace(topicExpression);
68
	createTopic(topicSpace, topicExpression);
69
    }
70
71
    /**
72
     * 
73
     * @return Topicspaces corresponding to topic expression property. 
74
     */
75
    public List getTopicSpaces()
76
    {
77
	return _topicSpaces;
78
    }
79
80
    private TopicSpace getTopicSpace(String topicExpression)
81
    {
82
	String prefix = topicExpression.substring(0, topicExpression
83
		.indexOf(':'));
84
	String namespace = (String) _nsMap.get(prefix);
85
	if (!isTopicSpaceCreated(namespace))
86
	{
87
	    TopicSpace topicSpace = TopicUtils.createNewTopicSpace();
88
	    topicSpace.setName(prefix);
89
	    topicSpace.setNamespace(namespace);
90
	    _topicSpaces.add(topicSpace);
91
	    return topicSpace;
92
	}
93
94
	for (int i = 0; i < _topicSpaces.size(); i++)
95
	{
96
	    TopicSpace topicSpace = (TopicSpace) _topicSpaces.get(i);
97
	    if (topicSpace.getNamespace().equals(namespace))
98
		return topicSpace;
99
	}
100
101
	return null;
102
    }
103
104
    private boolean isTopicSpaceCreated(String namespace)
105
    {
106
	for (int i = 0; i < _topicSpaces.size(); i++)
107
	{
108
	    TopicSpace topicSpace = (TopicSpace) _topicSpaces.get(i);
109
	    if (topicSpace.getNamespace().equals(namespace))
110
		return true;
111
	}
112
	return false;
113
    }
114
115
    private void createTopic(TopicSpace topicSpace, String topicExpression)
116
    {
117
	String path = topicExpression
118
		.substring(topicExpression.indexOf(':') + 1);
119
	StringTokenizer tokenizer = new StringTokenizer(path, "/");
120
121
	String rootTopicName = tokenizer.nextToken();
122
	Topic parentTopic = null;
123
	if (!isTopicCreated(topicSpace, rootTopicName))
124
	{
125
	    parentTopic = createRootTopic(topicSpace, rootTopicName);
126
	}
127
	else
128
	{
129
	    parentTopic = getRootTopic(topicSpace, rootTopicName);
130
	}
131
132
	while (tokenizer.hasMoreTokens())
133
	{
134
	    String childTopicName = tokenizer.nextToken();
135
	    if (!isTopicCreated(parentTopic, childTopicName))
136
	    {
137
		parentTopic = createChildTopic(parentTopic, childTopicName);
138
	    }
139
	    else
140
	    {
141
		parentTopic = getChildTopic(parentTopic, childTopicName);
142
	    }
143
	}
144
    }
145
146
    private boolean isTopicCreated(TopicSpace topicSpace, String rootTopicName)
147
    {
148
	for (int i = 0; i < topicSpace.getRootTopics().size(); i++)
149
	{
150
	    Topic rootTopic = (Topic) topicSpace.getRootTopics().get(i);
151
	    if (rootTopic.getName().equals(rootTopicName))
152
		return true;
153
	}
154
	return false;
155
    }
156
157
    private boolean isTopicCreated(Topic parentTopic, String childTopicName)
158
    {
159
	for (int i = 0; i < parentTopic.getChildren().size(); i++)
160
	{
161
	    Topic childTopic = (Topic) parentTopic.getChildren().get(i);
162
	    if (childTopic.getName().equals(childTopicName))
163
		return true;
164
	}
165
	return false;
166
    }
167
168
    private Topic createRootTopic(TopicSpace topicSpace, String rootTopicName)
169
    {
170
	Topic rootTopic = TopicUtils.createNewTopic();
171
	rootTopic.setName(rootTopicName);
172
	rootTopic.setParent(null);
173
	topicSpace.getRootTopics().add(rootTopic);
174
	return rootTopic;
175
    }
176
177
    private Topic getRootTopic(TopicSpace topicSpace, String rootTopicName)
178
    {
179
	for (int i = 0; i < topicSpace.getRootTopics().size(); i++)
180
	{
181
	    Topic rootTopic = (Topic) topicSpace.getRootTopics().get(i);
182
	    if (rootTopic.getName().equals(rootTopicName))
183
		return rootTopic;
184
	}
185
	return null;
186
    }
187
188
    private Topic createChildTopic(Topic topic, String childTopicName)
189
    {
190
	Topic childTopic = TopicUtils.createNewTopic();
191
	childTopic.setName(childTopicName);
192
	childTopic.setParent(topic);
193
	topic.getChildren().add(childTopic);
194
	return childTopic;
195
    }
196
197
    private Topic getChildTopic(Topic parentTopic, String childTopicName)
198
    {
199
	for (int i = 0; i < parentTopic.getChildren().size(); i++)
200
	{
201
	    Topic childTopic = (Topic) parentTopic.getChildren().get(i);
202
	    if (childTopic.getName().equals(childTopicName))
203
		return childTopic;
204
	}
205
	return null;
206
    }
207
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/CapUtils.java (-514 / +585 lines)
Lines 13-18 Link Here
13
package org.eclipse.tptp.wsdm.tooling.util.internal;
13
package org.eclipse.tptp.wsdm.tooling.util.internal;
14
14
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.StringReader;
16
import java.io.StringWriter;
18
import java.io.StringWriter;
17
import java.lang.reflect.Method;
19
import java.lang.reflect.Method;
18
import java.util.ArrayList;
20
import java.util.ArrayList;
Lines 22-28 Link Here
22
import java.util.List;
24
import java.util.List;
23
import java.util.Map;
25
import java.util.Map;
24
26
25
import org.apache.muse.util.xml.XmlUtils;
27
import javax.xml.parsers.DocumentBuilder;
28
import javax.xml.parsers.DocumentBuilderFactory;
29
26
import org.apache.xml.serialize.OutputFormat;
30
import org.apache.xml.serialize.OutputFormat;
27
import org.apache.xml.serialize.XMLSerializer;
31
import org.apache.xml.serialize.XMLSerializer;
28
import org.eclipse.core.resources.IFile;
32
import org.eclipse.core.resources.IFile;
Lines 46-504 Link Here
46
import org.w3c.dom.Document;
50
import org.w3c.dom.Document;
47
import org.w3c.dom.Element;
51
import org.w3c.dom.Element;
48
import org.w3c.dom.Text;
52
import org.w3c.dom.Text;
53
import org.xml.sax.InputSource;
49
import org.xml.sax.SAXException;
54
import org.xml.sax.SAXException;
50
55
51
/**
56
/**
52
 * 
57
 * 
53
 * Utility class to handle different parts of capability.
58
 * Utility class to handle different parts of capability.
54
 *
59
 * 
55
 */
60
 */
56
61
57
public class CapUtils
62
public class CapUtils
58
{
63
{
59
64
60
    /** Includes all Java keywords, plus literals true/false/null */
65
	/** Includes all Java keywords, plus literals true/false/null */
61
    private static final List JAVA_KEYWORDS = Arrays.asList(new String[] {
66
	private static final List JAVA_KEYWORDS = Arrays.asList(new String[] {
62
	    "abstract", "continue", "for", "new", "switch", "assert",
67
			"abstract", "continue", "for", "new", "switch", "assert",
63
	    "default", "goto", "package", "synchronized", "boolean", "do",
68
			"default", "goto", "package", "synchronized", "boolean", "do",
64
	    "if", "private", "this", "break", "double", "implements",
69
			"if", "private", "this", "break", "double", "implements",
65
	    "protected", "throw", "byte", "else", "import", "public", "throws",
70
			"protected", "throw", "byte", "else", "import", "public", "throws",
66
	    "case", "enum", "instanceof", "return", "transient", "catch",
71
			"case", "enum", "instanceof", "return", "transient", "catch",
67
	    "extends", "int", "short", "try", "char", "final", "interface",
72
			"extends", "int", "short", "try", "char", "final", "interface",
68
	    "static", "void", "class", "finally", "long", "strictfp",
73
			"static", "void", "class", "finally", "long", "strictfp",
69
	    "volatile", "const", "float", "native", "super", "while", "true",
74
			"volatile", "const", "float", "native", "super", "while", "true",
70
	    "false", "null" });
75
			"false", "null" });
71
    
76
72
    // This map will contain Capability URI as key and List of Capability WSDL Definition as value  
77
	// This map will contain Capability URI as key and List of Capability WSDL
73
    // all of which have the same capability uri 
78
	// Definition as value
74
    private static Map standardCapabilityMap = null;
79
	// all of which have the same capability uri
75
    
80
	private static Map standardCapabilityMap = null;
76
    // Capability operation name should not be conflicted with their super java implementation classes.
81
77
    private static Method[] abstractCapabilityMethods = new Method[0];
82
	// Capability operation name should not be conflicted with their super java
78
    
83
	// implementation classes.
79
    static{
84
	private static Method[] abstractCapabilityMethods = new Method[0];
80
    	try {
85
81
			Class abstractCapability = Class.forName("org.apache.muse.core.AbstractCapability");
86
	static
82
			abstractCapabilityMethods = abstractCapability.getMethods();			
87
	{
83
		} catch (ClassNotFoundException e) {
88
		try
84
			WsdmToolingLog.logError(e.getMessage(), e);			
89
		{
85
		} catch(SecurityException e) {
90
			Class abstractCapability = Class
91
					.forName("org.apache.muse.core.AbstractCapability");
92
			abstractCapabilityMethods = abstractCapability.getMethods();
93
		} catch (ClassNotFoundException e)
94
		{
95
			WsdmToolingLog.logError(e.getMessage(), e);
96
		} catch (SecurityException e)
97
		{
86
			WsdmToolingLog.logError(e.getMessage(), e);
98
			WsdmToolingLog.logError(e.getMessage(), e);
87
		}
99
		}
88
    }
100
	}
89
101
90
    /**
102
	/**
91
         * This method will retun the root topic , provided any child topic or
103
	 * This method will retun the root topic , provided any child topic or root
92
         * root topic itself. Recursively find the root topic.
104
	 * topic itself. Recursively find the root topic.
93
         */
105
	 */
94
    public static Topic getRootTopic(Topic topic)
106
	public static Topic getRootTopic(Topic topic)
95
    {
107
	{
96
	if (isRootTopic(topic))
108
		if (isRootTopic(topic))
97
	    return topic;
109
			return topic;
98
	Topic rootTopic = getRootTopic(topic.getParent());
110
		Topic rootTopic = getRootTopic(topic.getParent());
99
	return rootTopic;
111
		return rootTopic;
100
    }
112
	}
101
113
102
    /**
114
	/**
103
         * Return true if given topic is a root topic
115
	 * Return true if given topic is a root topic
104
         */
116
	 */
105
    public static boolean isRootTopic(Topic topic)
117
	public static boolean isRootTopic(Topic topic)
106
    {
118
	{
107
	if (topic.getParent() == null)
119
		if (topic.getParent() == null)
108
	    return true;
120
			return true;
109
	return false;
121
		return false;
110
    }
122
	}
111
123
112
    /**
124
	/**
113
     * Returns the capability name form qname. 
125
	 * Returns the capability name form qname.
114
     */
126
	 */
115
    public static String getCapabilityNameFromQName(String qname)
127
	public static String getCapabilityNameFromQName(String qname)
116
    {
128
	{
117
	int index = qname.lastIndexOf(':');
129
		int index = qname.lastIndexOf(':');
118
	if (index != -1)
130
		if (index != -1)
119
	{
131
		{
120
	    return qname.substring(index + 1);
132
			return qname.substring(index + 1);
121
133
122
	}
134
		}
123
	return qname;
135
		return qname;
124
    }
136
	}
125
137
126
    /**
138
	/**
127
     * Returns the capability prefix form qname. 
139
	 * Returns the capability prefix form qname.
128
     */
140
	 */
129
    public static String getCapabilityPrefixFromQName(String qname)
141
	public static String getCapabilityPrefixFromQName(String qname)
130
    {
142
	{
131
	int index = qname.lastIndexOf(':');
143
		int index = qname.lastIndexOf(':');
132
	if (index != -1)
144
		if (index != -1)
133
	{
145
		{
134
	    return qname.substring(0, index);
146
			return qname.substring(0, index);
135
	}
147
		}
136
	return null;
148
		return null;
137
    }
149
	}
138
150
139
    /**
151
	/**
140
     * Returns the namespace of given capability. 
152
	 * Returns the namespace of given capability.
141
     */
153
	 */
142
    public static String getNamespace(Capability cap)
154
	public static String getNamespace(Capability cap)
143
    {
155
	{
144
	String ns = cap.getNamespace();
156
		String ns = cap.getNamespace();
145
	if (ns == null)
157
		if (ns == null)
146
	{
158
		{
147
	    WsdmToolingLog.logWarning(NLS.bind(Messages.CAPABILITY_HAS_NO_NS_WARN_,cap.getName()));
159
			WsdmToolingLog.logWarning(NLS.bind(
148
	    return MrtUtils.createTempNamespace();
160
					Messages.CAPABILITY_HAS_NO_NS_WARN_, cap.getName()));
149
	}
161
			return MrtUtils.createTempNamespace();
150
162
		}
151
	return ns;
163
152
    }
164
		return ns;
153
165
	}
154
    /**
166
155
     * Retruns the list of XSDSchemas that represents the container of properties of capability. 
167
	/**
156
     */
168
	 * Retruns the list of XSDSchemas that represents the container of
157
    public static List getPropertiesSchemas(Definition definition,
169
	 * properties of capability.
158
	    XSDElementDeclaration resourcePropertyElement)
170
	 */
159
    {
171
	public static List getPropertiesSchemas(Definition definition,
160
172
			XSDElementDeclaration resourcePropertyElement)
161
	if (resourcePropertyElement == null)
173
	{
162
	{
174
163
	    WsdmToolingLog.logMessage(Messages.NULL_RESOURCE_PROPERTY_ELEMENT_ERROR_);
175
		if (resourcePropertyElement == null)
164
	    return null;
176
		{
165
	}
177
			WsdmToolingLog
166
178
					.logMessage(Messages.NULL_RESOURCE_PROPERTY_ELEMENT_ERROR_);
167
	List processedSchemas = new LinkedList();
179
			return null;
168
180
		}
169
	if (resourcePropertyElement.getAnonymousTypeDefinition() == null)
181
170
	{
182
		List processedSchemas = new LinkedList();
171
	    XSDSchema[] schemas = WsdlUtils.getXSDSchemas(definition);
183
172
	    if (schemas.length == 0)
184
		if (resourcePropertyElement.getAnonymousTypeDefinition() == null)
173
		WsdmToolingLog.logWarning(Messages.NO_XSD_FOUND_IN_WSDL_INFO_);
185
		{
174
	    XSDSchema rpSchema = WsdlUtils.getSchema(definition,
186
			XSDSchema[] schemas = WsdlUtils.getXSDSchemas(definition);
175
		    resourcePropertyElement.getTargetNamespace());
187
			if (schemas.length == 0)
176
	    if (XsdUtils.hasIncludeXSD(rpSchema))
188
				WsdmToolingLog.logWarning(Messages.NO_XSD_FOUND_IN_WSDL_INFO_);
177
	    {
189
			XSDSchema rpSchema = WsdlUtils.getSchema(definition,
178
		XSDInclude include = XsdUtils.getFirstXSDInclude(rpSchema);
190
					resourcePropertyElement.getTargetNamespace());
179
		processedSchemas.add(include.getResolvedSchema());
191
			if (XsdUtils.hasIncludeXSD(rpSchema))
180
		return processedSchemas;
192
			{
181
	    }
193
				XSDInclude include = XsdUtils.getFirstXSDInclude(rpSchema);
182
	    else
194
				processedSchemas.add(include.getResolvedSchema());
183
	    {
195
				return processedSchemas;
184
		processedSchemas.add(rpSchema);
196
			}
197
			else
198
			{
199
				processedSchemas.add(rpSchema);
200
				return processedSchemas;
201
			}
202
		}
203
204
		XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
205
				.getAnonymousTypeDefinition();
206
		XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
207
		XSDElementDeclaration[] elementRefs = XsdUtils
208
				.getElementDeclarations(modelGroup);
209
		for (int i = 0; i < elementRefs.length; i++)
210
		{
211
			if (XsdUtils.isReferencedElement(elementRefs[i]))
212
			{
213
				WsdlElementResolver resolver = new WsdlElementResolver(
214
						definition, resourcePropertyElement, elementRefs[i]);
215
				XSDElementDeclaration resolvedElement = resolver.resolve();
216
				if (resolvedElement != null)
217
				{
218
					XSDSchema propSchema = resolvedElement.getSchema();
219
					if (!processedSchemas.contains(propSchema))
220
						processedSchemas.add(propSchema);
221
				}
222
			}
223
		}
224
225
		if (processedSchemas.size() != 0)
226
			return processedSchemas;
227
228
		processedSchemas.add(resourcePropertyElement.getSchema());
185
		return processedSchemas;
229
		return processedSchemas;
186
	    }	   
187
	}
230
	}
188
231
189
	XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
232
	/**
190
		.getAnonymousTypeDefinition();
233
	 * Returns the minoccurs of property.
191
	XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
234
	 */
192
	XSDElementDeclaration[] elementRefs = XsdUtils
235
	public static int getMinOccurs(
193
		.getElementDeclarations(modelGroup);
236
			XSDElementDeclaration resourcePropertyElement,
194
	for (int i = 0; i < elementRefs.length; i++)
237
			XSDElementDeclaration property)
195
	{
238
	{
196
	    if (XsdUtils.isReferencedElement(elementRefs[i]))
239
		XSDElementDeclaration propertyRef = getPropertyRef(
197
	    {
240
				resourcePropertyElement, property);
198
		WsdlElementResolver resolver = new WsdlElementResolver(
241
		if (propertyRef == null)
199
			definition, resourcePropertyElement, elementRefs[i]);
242
		{
200
		XSDElementDeclaration resolvedElement = resolver.resolve();
243
			WsdmToolingLog.logWarning(NLS.bind(
201
		if (resolvedElement != null)
244
					Messages.REFERENCE_NOT_FOUND_ERROR_, property.getName()));
202
		{
245
			return 0;
203
		    XSDSchema propSchema = resolvedElement.getSchema();
246
		}
204
		    if (!processedSchemas.contains(propSchema))
247
		if (propertyRef.eContainer() instanceof XSDParticle)
205
			processedSchemas.add(propSchema);
248
		{
206
		}
249
			XSDParticle xsdParticle = (XSDParticle) propertyRef.eContainer();
207
	    }
250
			return xsdParticle.getMinOccurs();
208
	}
251
		}
209
252
		return 0;
210
	if (processedSchemas.size() != 0)
253
	}
211
	    return processedSchemas;
254
212
255
	/**
213
	processedSchemas.add(resourcePropertyElement.getSchema());
256
	 * Returns the maxoccurs of property.
214
	return processedSchemas;
257
	 */
215
    }
258
	public static int getMaxOccurs(
216
259
			XSDElementDeclaration resourcePropertyElement,
217
    /**
260
			XSDElementDeclaration property)
218
     * Returns the minoccurs of property. 
261
	{
219
     */
262
		XSDElementDeclaration propertyRef = getPropertyRef(
220
    public static int getMinOccurs(
263
				resourcePropertyElement, property);
221
	    XSDElementDeclaration resourcePropertyElement,
264
		if (propertyRef == null)
222
	    XSDElementDeclaration property)
265
		{
223
    {
266
			WsdmToolingLog.logWarning(NLS.bind(
224
	XSDElementDeclaration propertyRef = getPropertyRef(
267
					Messages.REFERENCE_NOT_FOUND_ERROR_, property.getName()));
225
		resourcePropertyElement, property);
268
			return 0;
226
	if (propertyRef == null)
269
		}
227
	{
270
		if (propertyRef.eContainer() instanceof XSDParticle)
228
	    WsdmToolingLog.logWarning(NLS.bind(Messages.REFERENCE_NOT_FOUND_ERROR_, property.getName()));
271
		{
229
	    return 0;
272
			XSDParticle xsdParticle = (XSDParticle) propertyRef.eContainer();
230
	}
273
			return xsdParticle.getMaxOccurs();
231
	if (propertyRef.eContainer() instanceof XSDParticle)
274
		}
232
	{
275
		return 0;
233
	    XSDParticle xsdParticle = (XSDParticle) propertyRef.eContainer();
276
	}
234
	    return xsdParticle.getMinOccurs();
277
235
	}
278
	private static XSDElementDeclaration getPropertyRef(
236
	return 0;
279
			XSDElementDeclaration resourcePropertyElement,
237
    }
280
			XSDElementDeclaration property)
238
281
	{
239
    /**
282
		XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
240
     * Returns the maxoccurs of property. 
283
				.getAnonymousTypeDefinition();
241
     */
284
		XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
242
    public static int getMaxOccurs(
285
		XSDElementDeclaration[] elementRefs = XsdUtils
243
	    XSDElementDeclaration resourcePropertyElement,
286
				.getElementDeclarations(modelGroup);
244
	    XSDElementDeclaration property)
287
		for (int i = 0; i < elementRefs.length; i++)
245
    {
288
		{
246
	XSDElementDeclaration propertyRef = getPropertyRef(
289
			if (XsdUtils.isReferencedElement(elementRefs[i]))
247
		resourcePropertyElement, property);
290
			{
248
	if (propertyRef == null)
291
				XSDElementDeclaration element = elementRefs[i]
249
	{
292
						.getResolvedElementDeclaration();
250
	    WsdmToolingLog.logWarning(NLS.bind(Messages.REFERENCE_NOT_FOUND_ERROR_, property.getName()));
293
				if (element.getName().equals(property.getName())
251
	    return 0;
294
						&& element.getTargetNamespace().equals(
252
	}
295
								property.getTargetNamespace()))
253
	if (propertyRef.eContainer() instanceof XSDParticle)
296
					return elementRefs[i];
254
	{
297
			}
255
	    XSDParticle xsdParticle = (XSDParticle) propertyRef.eContainer();
298
		}
256
	    return xsdParticle.getMaxOccurs();
299
		return null;
257
	}
300
	}
258
	return 0;
301
259
    }
302
	/**
260
303
	 * Returns the properties resolved from resourcePropertyElement.
261
    private static XSDElementDeclaration getPropertyRef(
304
	 */
262
	    XSDElementDeclaration resourcePropertyElement,
305
	public static XSDElementDeclaration[] getResolvedProperties(
263
	    XSDElementDeclaration property)
306
			Definition definition, XSDElementDeclaration resourcePropertyElement)
264
    {
307
	{
265
	XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
308
		List properties = new LinkedList();
266
		.getAnonymousTypeDefinition();
309
267
	XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
310
		if (resourcePropertyElement.getAnonymousTypeDefinition() == null)
268
	XSDElementDeclaration[] elementRefs = XsdUtils
311
		{
269
		.getElementDeclarations(modelGroup);
312
			return new XSDElementDeclaration[0];
270
	for (int i = 0; i < elementRefs.length; i++)
313
		}
271
	{
314
272
	    if (XsdUtils.isReferencedElement(elementRefs[i]))
315
		XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
273
	    {
316
				.getAnonymousTypeDefinition();
274
		XSDElementDeclaration element = elementRefs[i]
317
		XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
275
			.getResolvedElementDeclaration();
318
		XSDElementDeclaration[] elementRefs = XsdUtils
276
		if (element.getName().equals(property.getName())
319
				.getElementDeclarations(modelGroup);
277
			&& element.getTargetNamespace().equals(
320
		for (int i = 0; i < elementRefs.length; i++)
278
				property.getTargetNamespace()))
321
		{
279
		    return elementRefs[i];
322
			if (XsdUtils.isReferencedElement(elementRefs[i]))
280
	    }
323
			{
281
	}
324
				WsdlElementResolver resolver = new WsdlElementResolver(
282
	return null;
325
						definition, resourcePropertyElement, elementRefs[i]);
283
    }
326
				XSDElementDeclaration resolvedElement = resolver.resolve();
284
327
				if (resolvedElement != null)
285
    /**
328
					properties.add(resolvedElement);
286
     * Returns the properties resolved from resourcePropertyElement.
329
			}
287
     */
330
		}
288
    public static XSDElementDeclaration[] getResolvedProperties(
331
289
	    Definition definition, XSDElementDeclaration resourcePropertyElement)
332
		return (XSDElementDeclaration[]) properties
290
    {
333
				.toArray(new XSDElementDeclaration[0]);
291
	List properties = new LinkedList();
334
	}
292
335
293
	if (resourcePropertyElement.getAnonymousTypeDefinition() == null)
336
	/**
294
	{
337
	 * Returns string of SerializedDocument.
295
	    return new XSDElementDeclaration[0];
338
	 */
296
	}
339
	public static String getSerializedDocument(String string)
297
340
	{
298
	XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
341
		Document document = parseToDOM(string);
299
		.getAnonymousTypeDefinition();
342
		String serialized = documentToString(document);
300
	XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
343
		return serialized;
301
	XSDElementDeclaration[] elementRefs = XsdUtils
344
	}
302
		.getElementDeclarations(modelGroup);
345
303
	for (int i = 0; i < elementRefs.length; i++)
346
	public static Document parseToDOM(String xmlString)
304
	{
347
	{
305
	    if (XsdUtils.isReferencedElement(elementRefs[i]))
348
		Document document = null;
306
	    {
349
		try
307
		WsdlElementResolver resolver = new WsdlElementResolver(
350
		{
308
			definition, resourcePropertyElement, elementRefs[i]);
351
			document = createDocument(xmlString);
309
		XSDElementDeclaration resolvedElement = resolver.resolve();
352
		} catch (SAXException e)
310
		if (resolvedElement != null)
353
		{
311
		    properties.add(resolvedElement);
354
			WsdmToolingLog.logError(e.getMessage(), e);
312
	    }
355
		} catch (IOException e)
313
	}
356
		{
314
357
			WsdmToolingLog.logError(e.getMessage(), e);
315
	return (XSDElementDeclaration[]) properties
358
		}
316
		.toArray(new XSDElementDeclaration[0]);
359
		if (document != null)
317
    }
360
			document.normalize();
318
361
		return document;
319
    /**
362
	}
320
     * Returns string of SerializedDocument.
363
321
     */
364
	public static Document createDocument(String xmlString)
322
    public static String getSerializedDocument(String string)
365
			throws SAXException, IOException
323
    {
366
	{
324
	Document document = parseToDOM(string);
367
		InputSource source = new InputSource(new StringReader(xmlString));
325
	String serialized = prettySerializeDocument(document);
368
		return createDocument(source);
326
	return serialized;
369
	}
327
    }
370
328
371
	public static Document createDocument(InputSource source)
329
    /**
372
			throws SAXException, IOException
330
     * Parses the given string to DOM document. 
373
	{
331
     */
374
		return createDocumentBuilder().parse(source);
332
    public static Document parseToDOM(String xmlString)
375
	}
333
    {
376
334
	Document document = null;
377
	public static Document createDocument(InputStream stream)
335
	try
378
			throws SAXException, IOException
336
	{
379
	{
337
	    document = XmlUtils.createDocument(xmlString);
380
		return createDocumentBuilder().parse(stream);
338
	} catch (IOException ioe)
381
	}
339
	{
382
340
	    WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, ioe);
383
	private static DocumentBuilder createDocumentBuilder()
341
	    return null;
384
	{
342
	} catch (SAXException se)
385
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
343
	{
386
		factory.setNamespaceAware(true);
344
	    WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, se);
387
		factory.setIgnoringComments(true);
345
	    return null;
388
		try
346
	}
389
		{
347
	document.normalize();
390
			return factory.newDocumentBuilder();
348
	return document;
391
		} catch (Throwable error)
349
    }
392
		{
350
393
			WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, error);
351
    /**
394
		}
352
     * Prepares SerializeDocument.
395
		return null;
353
     */
396
	}
354
    public static String prettySerializeDocument(Document doc)
397
355
    {
398
	public static String documentToString(Document document)
356
	OutputFormat format = new OutputFormat();
399
	{
357
	format.setPreserveSpace(false);
400
		XMLSerializer serializer = new XMLSerializer();
358
	format.setIndenting(true);
401
		serializer.setNamespaces(true);
359
	format.setIndent(2);
402
360
	format.setLineWidth(72);
403
		OutputFormat formatter = new OutputFormat();
361
	format.setLineSeparator(System.getProperty("line.separator"));
404
		formatter.setOmitXMLDeclaration(false);
362
	StringWriter writer = new StringWriter();
405
		formatter.setIndenting(true);
363
	XMLSerializer serializer = new XMLSerializer(writer, format);
406
		serializer.setOutputFormat(formatter);
364
	try
407
365
	{
408
		StringWriter writer = new StringWriter();
366
	    serializer.serialize(doc);
409
		serializer.setOutputCharStream(writer);
367
	} catch (IOException ioe)
410
368
	{
411
		try
369
	    WsdmToolingLog.logError(Messages.CANT_SERIALIZE_DOCUMENT_ERROR_, ioe);
412
		{
370
	}
413
			serializer.serialize(document);
371
	return writer.getBuffer().toString();
414
		} catch (Throwable error)
372
    }
415
		{
373
416
			WsdmToolingLog.logError(Messages.CANT_SERIALIZE_DOCUMENT_ERROR_,
374
    /**
417
					error);
375
     * Returns the instances of property of the given name. 
418
		}
376
     */
419
		return writer.toString();
377
    public static int getInstancesOfProperty(Capability model, String propName)
420
	}
378
    {
421
379
	int counter = 0;
422
	/**
380
	EList propList = model.getProperties();
423
	 * Returns the instances of property of the given name.
381
	for (int i = 0; i < propList.size(); i++)
424
	 */
382
	{
425
	public static int getInstancesOfProperty(Capability model, String propName)
383
	    Property property = (Property) propList.get(i);
426
	{
384
	    String name = XsdUtils.getName(property.getElement());
427
		int counter = 0;
385
	    if (name.equals(propName))
428
		EList propList = model.getProperties();
386
		counter++;
429
		for (int i = 0; i < propList.size(); i++)
387
	}
430
		{
388
	return counter;
431
			Property property = (Property) propList.get(i);
389
    }
432
			String name = XsdUtils.getName(property.getElement());
390
433
			if (name.equals(propName))
391
    /**
434
				counter++;
392
     * Returns the instances of operation of the given name. 
435
		}
393
     */
436
		return counter;
394
    public static int getInstancesOfOperation(Capability model, String opName)
437
	}
395
    {
438
396
	int counter = 0;
439
	/**
397
	EList opList = model.getOperations();
440
	 * Returns the instances of operation of the given name.
398
	for (int i = 0; i < opList.size(); i++)
441
	 */
399
	{
442
	public static int getInstancesOfOperation(Capability model, String opName)
400
	    Operation op = (Operation) opList.get(i);
443
	{
401
	    if (op.getName().equals(opName))
444
		int counter = 0;
402
		counter++;
445
		EList opList = model.getOperations();
403
	}
446
		for (int i = 0; i < opList.size(); i++)
404
	return counter;
447
		{
405
    }
448
			Operation op = (Operation) opList.get(i);
406
449
			if (op.getName().equals(opName))
407
    /**
450
				counter++;
408
     * Returns the instances of parameter of the given name. 
451
		}
409
     */
452
		return counter;
410
    public static int getInstancesOfParameter(Operation operation,
453
	}
411
	    String paramName)
454
412
    {
455
	/**
413
	int counter = 0;
456
	 * Returns the instances of parameter of the given name.
414
	XSDElementDeclaration[] params = WsdlUtils
457
	 */
415
		.getOperationParams(operation);
458
	public static int getInstancesOfParameter(Operation operation,
416
	for (int i = 0; i < params.length; i++)
459
			String paramName)
417
	{
460
	{
418
	    if (params[i].getName().equals(paramName))
461
		int counter = 0;
419
		counter++;
462
		XSDElementDeclaration[] params = WsdlUtils
420
	}
463
				.getOperationParams(operation);
421
	return counter;
464
		for (int i = 0; i < params.length; i++)
422
    }
465
		{
423
    
466
			if (params[i].getName().equals(paramName))
424
    /**
467
				counter++;
425
     * 
468
		}
426
     * Validate whether given string is valid identifier or not
469
		return counter;
427
     * NOTE : Fix for defect [#47609] Validation needed on text fields in editors
470
	}
428
     */
471
429
    public static String validateJavaIdentifier(String name)
472
	/**
430
    {
473
	 * 
431
	// A Java identifier begins with a JavaLetter, followed by 0..n
474
	 * Validate whether given string is valid identifier or not NOTE : Fix for
432
        // JavaLetterOrDigit,
475
	 * defect [#47609] Validation needed on text fields in editors
433
	// but MUST NOT be a Java Keyword, true, false, or null
476
	 */
434
477
	public static String validateJavaIdentifier(String name)
435
	if (name.length() == 0)
478
	{
436
	{
479
		// A Java identifier begins with a JavaLetter, followed by 0..n
437
	    return Messages.EMPTY_NAME_ERROR_;
480
		// JavaLetterOrDigit,
438
	}
481
		// but MUST NOT be a Java Keyword, true, false, or null
439
482
440
	if (!Character.isJavaIdentifierStart(name.charAt(0)))
483
		if (name.length() == 0)
441
	{
484
		{
442
	    return NLS.bind(Messages.INVALID_NAME_ERROR_, name);
485
			return Messages.EMPTY_NAME_ERROR_;
443
	}
486
		}
444
487
445
	for (int i = 1; i < name.length(); i++)
488
		if (!Character.isJavaIdentifierStart(name.charAt(0)))
446
	{
489
		{
447
	    if (!Character.isJavaIdentifierPart(name.charAt(i)))
490
			return NLS.bind(Messages.INVALID_NAME_ERROR_, name);
448
	    {
491
		}
449
		return NLS.bind(Messages.INVALID_NAME_ERROR_, name);
492
450
	    }
493
		for (int i = 1; i < name.length(); i++)
451
	}
494
		{
452
495
			if (!Character.isJavaIdentifierPart(name.charAt(i)))
453
	if (JAVA_KEYWORDS.contains(name))
496
			{
454
	{
497
				return NLS.bind(Messages.INVALID_NAME_ERROR_, name);
455
	    return NLS.bind(Messages.INVALID_NAME_JAVA_KEYWORD_ERROR_, name);
498
			}
456
	}
499
		}
457
	return null;
500
458
    }
501
		if (JAVA_KEYWORDS.contains(name))
459
502
		{
460
    /**
503
			return NLS.bind(Messages.INVALID_NAME_JAVA_KEYWORD_ERROR_, name);
461
     * Returns the property of the given name. 
504
		}
462
     */
505
		return null;
463
    public static Property getProperty(Capability capability,String namespace, String propertyName)
506
	}
464
    {
507
465
	List propList = capability.getProperties();
508
	/**
466
	for (int i = 0; i < propList.size(); i++)
509
	 * Returns the property of the given name.
467
	{
510
	 */
468
	    Property property = (Property) propList.get(i);
511
	public static Property getProperty(Capability capability, String namespace,
469
	    XSDElementDeclaration propElement = property.getElement();
512
			String propertyName)
470
	    String name = XsdUtils.getName(propElement);
513
	{
471
	    if (propElement.getTargetNamespace().equals(namespace) && name.equals(propertyName))
514
		List propList = capability.getProperties();
472
		return property;
515
		for (int i = 0; i < propList.size(); i++)
473
	}
516
		{
474
	return null;
517
			Property property = (Property) propList.get(i);
475
    }
518
			XSDElementDeclaration propElement = property.getElement();
476
519
			String name = XsdUtils.getName(propElement);
477
    /**
520
			if (propElement.getTargetNamespace().equals(namespace)
478
     * Returns the name of the property.
521
					&& name.equals(propertyName))
479
     */
522
				return property;
480
    public static String getName(Property property)
523
		}
481
    {
524
		return null;
482
	return XsdUtils.getName(property.getElement());
525
	}
483
    }
526
484
527
	/**
485
    /**
528
	 * Returns the name of the property.
486
     * Returns the capability DescriptionNode.
529
	 */
487
     */
530
	public static String getName(Property property)
488
    public static Text getDescriptionNode(Definition definition) {
531
	{
532
		return XsdUtils.getName(property.getElement());
533
	}
534
535
	/**
536
	 * Returns the capability DescriptionNode.
537
	 */
538
	public static Text getDescriptionNode(Definition definition)
539
	{
489
		XSDSchema schema = WsdlUtils.getSchema(definition, definition
540
		XSDSchema schema = WsdlUtils.getSchema(definition, definition
490
				.getTargetNamespace());
541
				.getTargetNamespace());
491
		if (schema != null) {
542
		if (schema != null)
543
		{
492
			if (schema.getAnnotations() != null
544
			if (schema.getAnnotations() != null
493
					&& schema.getAnnotations().size() != 0) {
545
					&& schema.getAnnotations().size() != 0)
546
			{
494
				XSDAnnotation annotation = (XSDAnnotation) schema
547
				XSDAnnotation annotation = (XSDAnnotation) schema
495
						.getAnnotations().get(0);
548
						.getAnnotations().get(0);
496
				List userInfo = annotation.getUserInformation();
549
				List userInfo = annotation.getUserInformation();
497
				if (userInfo != null && userInfo.size() != 0) {
550
				if (userInfo != null && userInfo.size() != 0)
551
				{
498
					Element[] elements = getEmptySourceDocumentationElements(userInfo);
552
					Element[] elements = getEmptySourceDocumentationElements(userInfo);
499
					for (int i = 0; i < elements.length; i++) {
553
					for (int i = 0; i < elements.length; i++)
500
						if (elements[i].getChildNodes().getLength() != 0) {
554
					{
501
							if (elements[i].getChildNodes().item(0) instanceof Text) {
555
						if (elements[i].getChildNodes().getLength() != 0)
556
						{
557
							if (elements[i].getChildNodes().item(0) instanceof Text)
558
							{
502
								Text node = (Text) elements[i].getChildNodes()
559
								Text node = (Text) elements[i].getChildNodes()
503
										.item(0);
560
										.item(0);
504
								return node;
561
								return node;
Lines 508-607 Link Here
508
				}
565
				}
509
			}
566
			}
510
		}
567
		}
511
	return null;
568
		return null;
512
    }
569
	}
570
571
	private static Element[] getEmptySourceDocumentationElements(List elements)
572
	{
573
		List result = new ArrayList();
574
		for (int i = 0; i < elements.size(); i++)
575
		{
576
			Element documentation = (Element) elements.get(i);
577
			if (documentation.getAttributes().getLength() == 0)
578
				result.add(documentation);
579
		}
580
		return (Element[]) result.toArray(new Element[result.size()]);
581
	}
513
582
514
    private static Element[] getEmptySourceDocumentationElements(List elements)
583
	/**
515
    {
584
	 * Returns the Map of All capabilites available (Standarad+Workspace). Key
516
	List result = new ArrayList();
585
	 * will be Capability URI and Value will be List of Capability WSDL
517
	for (int i = 0; i < elements.size(); i++)
586
	 * Definition which maps to same Capability URI.
518
	{
587
	 * 
519
	    Element documentation = (Element) elements.get(i);
588
	 * @throws Exception
520
	    if (documentation.getAttributes().getLength() == 0)
589
	 */
521
		result.add(documentation);
590
	public static Map getAllCapabilitiesMap() throws Exception
522
	}
591
	{
523
	return (Element[]) result.toArray(new Element[result.size()]);
592
		if (standardCapabilityMap == null)
524
    }
593
		{
525
    
594
			standardCapabilityMap = new HashMap();
526
    /**
595
			// Get All ManagementCapabilities
527
     * Returns the Map of All capabilites available (Standarad+Workspace).
596
			Definition[] caps = (Definition[]) MrtUtils
528
     * Key will be Capability URI and Value will be List of Capability WSDL Definition 
597
					.getManagementCapabilities().toArray(new Definition[0]);
529
     * which maps to same Capability URI. 
598
			poplulateCapabilityMap(standardCapabilityMap, caps);
530
     * @throws Exception 
599
			// Get All ManagementRelatedCapabilities
531
     */
600
			caps = (Definition[]) MrtUtils.getManagementRelatedCapabilities()
532
    public static Map getAllCapabilitiesMap() throws Exception{
601
					.toArray(new Definition[0]);
533
    	if(standardCapabilityMap == null){
602
			poplulateCapabilityMap(standardCapabilityMap, caps);
534
    		standardCapabilityMap = new HashMap();
603
			// Get All ResourcePropertyCapabilities
535
    		// Get All ManagementCapabilities
604
			caps = (Definition[]) MrtUtils.getResourcePropertyCapabilities()
536
    		Definition[] caps = (Definition[]) MrtUtils.getManagementCapabilities().toArray(new Definition[0]);
605
					.toArray(new Definition[0]);
537
    		poplulateCapabilityMap(standardCapabilityMap, caps);
606
			poplulateCapabilityMap(standardCapabilityMap, caps);
538
    		// Get All ManagementRelatedCapabilities
607
			// Get All ResourceLifetimeCapabilities
539
    		caps = (Definition[]) MrtUtils.getManagementRelatedCapabilities().toArray(new Definition[0]);
608
			caps = (Definition[]) MrtUtils.getResourceLifetimeCapabilities()
540
    		poplulateCapabilityMap(standardCapabilityMap, caps);
609
					.toArray(new Definition[0]);
541
    		// Get All ResourcePropertyCapabilities
610
			poplulateCapabilityMap(standardCapabilityMap, caps);
542
    		caps = (Definition[]) MrtUtils.getResourcePropertyCapabilities().toArray(new Definition[0]);
611
		}
543
    		poplulateCapabilityMap(standardCapabilityMap, caps);
612
		Map allCapabilities = new HashMap();
544
    		// Get All ResourceLifetimeCapabilities
613
		allCapabilities.putAll(standardCapabilityMap);
545
    		caps = (Definition[]) MrtUtils.getResourceLifetimeCapabilities().toArray(new Definition[0]);
614
		// Get All WorkspaceCapabilities
546
    		poplulateCapabilityMap(standardCapabilityMap, caps);
615
		Definition[] workspaceCapabilities = getAllWorkspaceCapabilities();
547
    	}    	
616
		poplulateCapabilityMap(allCapabilities, workspaceCapabilities);
548
    	Map allCapabilities = new HashMap();
617
		return allCapabilities;
549
    	allCapabilities.putAll(standardCapabilityMap);
618
	}
550
    	// Get All WorkspaceCapabilities
619
551
    	Definition[] workspaceCapabilities = getAllWorkspaceCapabilities();
620
	private static void poplulateCapabilityMap(Map map,
552
    	poplulateCapabilityMap(allCapabilities, workspaceCapabilities);
621
			Definition[] capabilities)
553
    	return allCapabilities;
622
	{
554
    }
623
		for (int i = 0; i < capabilities.length; i++)
555
    
624
		{
556
    private static void poplulateCapabilityMap(Map map, Definition[] capabilities){
557
    	for(int i=0;i<capabilities.length;i++){
558
			String key = capabilities[i].getNamespace("capabilityURI");
625
			String key = capabilities[i].getNamespace("capabilityURI");
559
			if(key == null)
626
			if (key == null)
560
				key = capabilities[i].getTargetNamespace();
627
				key = capabilities[i].getTargetNamespace();
561
			Object value = map.get(key);
628
			Object value = map.get(key);
562
			if(value == null){
629
			if (value == null)
630
			{
563
				List list = new LinkedList();
631
				List list = new LinkedList();
564
				list.add(capabilities[i]);
632
				list.add(capabilities[i]);
565
				map.put(key, list);							
633
				map.put(key, list);
566
			}
634
			}
567
			else{
635
			else
636
			{
568
				List list = (List) value;
637
				List list = (List) value;
569
				list.add(capabilities[i]);
638
				list.add(capabilities[i]);
570
			}			
639
			}
571
		}
640
		}
572
    }
641
	}
573
    
642
574
    
643
	/**
575
    /**
644
	 * Returns all the Workspace capabilities.
576
     * Returns all the Workspace capabilities. 
645
	 */
577
     */
646
	public static Definition[] getAllWorkspaceCapabilities() throws Exception
578
    public static Definition[] getAllWorkspaceCapabilities() throws Exception{
647
	{
579
    	IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
648
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
580
    	List allWSDLs = new LinkedList();
649
		List allWSDLs = new LinkedList();
581
    	List wsdls = EclipseUtils.getResourcesOfExtension(root, "mcap");
650
		List wsdls = EclipseUtils.getResourcesOfExtension(root, "mcap");
582
    	for (int i=0;i<wsdls.size();i++) {
651
		for (int i = 0; i < wsdls.size(); i++)
583
			IFile wsdlFile = (IFile)wsdls.get(i);
652
		{
653
			IFile wsdlFile = (IFile) wsdls.get(i);
584
			Definition wsdlDef = WsdlUtils.getWSDLDefinition(wsdlFile);
654
			Definition wsdlDef = WsdlUtils.getWSDLDefinition(wsdlFile);
585
			if(wsdlDef!=null)
655
			if (wsdlDef != null)
586
				allWSDLs.add(wsdlDef);
656
				allWSDLs.add(wsdlDef);
587
		}
657
		}
588
    	return (Definition[]) allWSDLs.toArray(new Definition[allWSDLs.size()]);
658
		return (Definition[]) allWSDLs.toArray(new Definition[allWSDLs.size()]);
589
    }
659
	}
590
    
660
591
    /**
661
	/**
592
     * Returns true if given operation name conflicted with super java capability implementation classes. 
662
	 * Returns true if given operation name conflicted with super java
593
     * Note : Fix for defect 167792 "Operations from abstract capability classes need to be identified"
663
	 * capability implementation classes. Note : Fix for defect 167792
594
     * http://bugs.eclipse.org/bugs/show_bug.cgi?id=167792
664
	 * "Operations from abstract capability classes need to be identified"
595
     */
665
	 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=167792
596
    public static boolean isOperationNameConflicted(String operationName)
666
	 */
597
    {    	
667
	public static boolean isOperationNameConflicted(String operationName)
598
    	if(operationName == null)
668
	{
599
    		return false;
669
		if (operationName == null)
600
    	for(int i=0;i<abstractCapabilityMethods.length;i++)
670
			return false;
601
    	{
671
		for (int i = 0; i < abstractCapabilityMethods.length; i++)
602
    		if(abstractCapabilityMethods[i].getName().equals(operationName))
672
		{
603
    			return true;
673
			if (abstractCapabilityMethods[i].getName().equals(operationName))
604
    	}
674
				return true;
605
    	return false;
675
		}
606
    }
676
		return false;
677
	}
607
}
678
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/TopicSpace2MetaDataDescriptor.java (-161 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.util.internal;
14
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
import java.util.List;
18
19
import org.eclipse.emf.common.util.EMap;
20
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
21
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
22
23
/**
24
 * Generate a topic expression for each topic available in capability.<br>
25
 * So if capability has topics defined as<br><br>
26
 * 	http://w3.ibm.com/capabilities/WAS (TopicNameSpace)<br>
27
 * 	|____RootTopic <br>
28
 * 	     |______ChildTopic <br><br>
29
 * 
30
 * Then it will generate the following topic expressions in RMD<br><br>
31
 * 
32
 * xmlns:topics1="http://w3.ibm.com/capabilities/WAS/Topics"<br>
33
 * 
34
 * &lt; wsnt:TopicExpression &gt; topics1:RootTopic &lt; /wsnt:TopicExpression &gt;<br>
35
 * &lt; wsnt:TopicExpression &gt; topics1:RootTopic/ChildTopic &lt; /wsnt:TopicExpression &gt;<br>	
36
 * 	
37
 * @see #getTopicExpressions()
38
 * 
39
 */
40
41
public class TopicSpace2MetaDataDescriptor
42
{
43
44
    private List _topicSpaces;
45
46
    private List _generatedTopicExpressions;
47
48
    private EMap _nsMap;
49
50
    /**
51
     * Creates the instance of this class.
52
     */
53
    public TopicSpace2MetaDataDescriptor(EMap nsMap, List topicSpaces)
54
    {
55
	_topicSpaces = topicSpaces;
56
	_nsMap = nsMap;
57
	_generatedTopicExpressions = new ArrayList();
58
    }
59
60
    /**
61
     * 
62
     * @return Topic expression.
63
     */
64
    public String[] getTopicExpressions()
65
    {
66
	for (int i = 0; i < _topicSpaces.size(); i++)
67
	{
68
	    TopicSpace topicSpace = (TopicSpace) _topicSpaces.get(i);
69
	    visitTopicSpace(topicSpace);
70
	}
71
	return (String[]) _generatedTopicExpressions.toArray(new String[0]);
72
    }
73
74
    private void visitTopicSpace(TopicSpace topicSpace)
75
    {
76
	String prefix = getPrefix(topicSpace.getNamespace());
77
	for (int i = 0; i < topicSpace.getRootTopics().size(); i++)
78
	{
79
	    visitRootTopic((Topic) topicSpace.getRootTopics().get(i), prefix);
80
	}
81
    }
82
83
    private void visitRootTopic(Topic rootTopic, String prefix)
84
    {
85
	String topicExpression = prepareExpression(prefix, rootTopic);
86
	if (!_generatedTopicExpressions.contains(topicExpression))
87
	    _generatedTopicExpressions.add(topicExpression);
88
89
	for (int i = 0; i < rootTopic.getChildren().size(); i++)
90
	{
91
	    visitTopic((Topic) rootTopic.getChildren().get(i), prefix);
92
	}
93
    }
94
95
    private void visitTopic(Topic topic, String prefix)
96
    {
97
	String topicExpression = prepareExpression(prefix, topic);
98
	if (!_generatedTopicExpressions.contains(topicExpression))
99
	    _generatedTopicExpressions.add(topicExpression);
100
101
	for (int i = 0; i < topic.getChildren().size(); i++)
102
	{
103
	    visitTopic((Topic) topic.getChildren().get(i), prefix);
104
	}
105
    }
106
107
    private String prepareExpression(String prefix, Topic topic)
108
    {
109
	StringBuffer buffer = new StringBuffer();
110
	buffer.append(topic.getName());
111
	while (topic.getParent() != null)
112
	{
113
	    topic = topic.getParent();
114
	    buffer.insert(0, topic.getName() + "/");
115
	}
116
	buffer.insert(0, prefix + ":");
117
	return buffer.toString();
118
    }
119
120
    private String getPrefix(String ns)
121
    {
122
	Iterator keyIt = _nsMap.keySet().iterator();
123
	Iterator valueIt = _nsMap.values().iterator();
124
	while (keyIt.hasNext())
125
	{
126
	    String prefix = (String) keyIt.next();
127
	    String namespace = (String) valueIt.next();
128
	    if (namespace.equals(ns))
129
		return prefix;
130
	}
131
132
	String newPrefix = generateNewPrefix();
133
	_nsMap.put(newPrefix, ns);
134
	return newPrefix;
135
    }
136
137
    private String generateNewPrefix()
138
    {
139
	int counter = 1;
140
	String newPrefix = "topics" + counter;
141
	while (isPrefixExists(newPrefix))
142
	{
143
	    counter++;
144
	    newPrefix = "topics" + counter;
145
	}
146
	return newPrefix;
147
    }
148
149
    private boolean isPrefixExists(String prefix)
150
    {
151
	Iterator keyIt = _nsMap.keySet().iterator();
152
	while (keyIt.hasNext())
153
	{
154
	    String pfx = (String) keyIt.next();
155
	    if (pfx.equals(prefix))
156
		return true;
157
	}
158
	return false;
159
    }
160
161
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/TopicUtils.java (-63 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.util.internal;
14
15
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
16
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Topic;
17
import org.eclipse.tptp.wsdm.tooling.model.capabilities.TopicSpace;
18
19
/**
20
 * 
21
 * Utility class to deal with capability topics.
22
 *
23
 */
24
25
public class TopicUtils
26
{
27
28
    public static final String WS_TOPICS_PREFIX = "wsnt";
29
30
    private static final String TOPICSPACE_ELEMENT = "TopicSpace";
31
32
    private static final String TOPIC_ELEMENT = "Topic";
33
34
    private static final String MESSAGE_PATTERN_ELEMENT = "MessagePattern";
35
36
    private static final String NAME_ATTRIBUTE = "name";
37
38
    private static final String TARGET_NAMESPACE_ATTRIBUTE = "targetNamespace";
39
40
    private static final String MESSAGE_TYPES_ATTRIBUTE = "messageTypes";
41
42
    private static final String FINAL_ATTRIBUTE = "final";
43
44
    /**
45
     * Creates new capability topic.
46
     * 
47
     * @return new capability topic.
48
     */
49
    public static Topic createNewTopic()
50
    {
51
	return CapabilitiesFactory.eINSTANCE.createTopic();
52
    }
53
54
    /**
55
     * Creates new capability topicspace.
56
     * 
57
     * @return new capability topicspace.
58
     */
59
    public static TopicSpace createNewTopicSpace()
60
    {
61
	return CapabilitiesFactory.eINSTANCE.createTopicSpace();
62
    }   
63
}
(-)src/org/eclipse/tptp/wsdm/tooling/util/internal/Definition2Capability.java (-303 / +302 lines)
Lines 18-29 Link Here
18
18
19
import javax.xml.namespace.QName;
19
import javax.xml.namespace.QName;
20
20
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.emf.common.util.URI;
21
import org.eclipse.emf.common.util.URI;
24
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
22
import org.eclipse.tptp.wsdm.tooling.model.capabilities.CapabilitiesFactory;
25
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
23
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
26
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
24
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Property;
25
import org.eclipse.tptp.wsdm.tooling.model.capabilities.impl.MetadataDescriptor;
27
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
26
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.DocumentRoot;
28
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
27
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType;
29
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
28
import org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal.Messages;
Lines 31-37 Link Here
31
import org.eclipse.wst.wsdl.Operation;
30
import org.eclipse.wst.wsdl.Operation;
32
import org.eclipse.wst.wsdl.PortType;
31
import org.eclipse.wst.wsdl.PortType;
33
import org.eclipse.xsd.XSDElementDeclaration;
32
import org.eclipse.xsd.XSDElementDeclaration;
34
import org.eclipse.xsd.XSDSchema;
35
import org.w3c.dom.Text;
33
import org.w3c.dom.Text;
36
34
37
/**
35
/**
Lines 39-362 Link Here
39
 * 
37
 * 
40
 * There are 2 costructors provided to intialize this class.<br>
38
 * There are 2 costructors provided to intialize this class.<br>
41
 * 
39
 * 
42
 * <b>public Definition2Capability(Definition wsdlDefinition, boolean loadProperties, 
40
 * <b>public Definition2Capability(Definition wsdlDefinition, boolean
43
 * boolean loadRMD, boolean loadOperations,boolean loadTopics)</b> <br>
41
 * loadProperties, boolean loadRMD, boolean loadOperations,boolean loadTopics)</b>
42
 * <br>
44
 * 
43
 * 
45
 * Using this constructor one can load perticluar component of a capability.<br>
44
 * Using this constructor one can load perticluar component of a capability.<br>
46
 * 
45
 * 
47
 * Anoter constructor available which will load all the component of a capability.<br>
46
 * Anoter constructor available which will load all the component of a
47
 * capability.<br>
48
 * 
48
 * 
49
 * <b>public Definition2Capability(Definition wsdlDefinition)</b><br>
49
 * <b>public Definition2Capability(Definition wsdlDefinition)</b><br>
50
 * 
50
 * 
51
 * <b>getCapability()</b> method will trigger the conversion and will return the corresponding capability.<br>
51
 * <b>getCapability()</b> method will trigger the conversion and will return
52
 *
52
 * the corresponding capability.<br>
53
 * 
53
 */
54
 */
54
55
55
public class Definition2Capability
56
public class Definition2Capability
56
{
57
{
57
58
58
    protected Capability _capability = null;
59
	protected Capability _capability = null;
59
60
60
    protected boolean _loadProperties;
61
	protected boolean _loadProperties;
61
62
62
    protected boolean _loadRMD;
63
	protected boolean _loadRMD;
63
64
64
    protected boolean _loadOperations;
65
	protected boolean _loadOperations;
65
66
66
    protected boolean _loadTopics;
67
	protected boolean _loadTopics;
67
68
68
    protected List _diagonistics = new LinkedList();
69
	protected List _diagonistics = new LinkedList();
69
70
70
    private Map _metaDataMap;
71
	private Map _metaDataMap;
71
72
72
    protected Definition _wsdlDefinition;
73
	protected Definition _wsdlDefinition;
73
74
74
    private XSDElementDeclaration _resourcePropertyElement;
75
	private XSDElementDeclaration _resourcePropertyElement;
75
76
76
    private PropertyMetaDataDescriptor _metaDataDescriptor;
77
	public static String RMD_FILE_NOT_EXISTS_MESSAGE = Messages.RMD_FILE_DOESNT_EXISTS_ERROR_;
77
78
78
    public static String RMD_FILE_NOT_EXISTS_MESSAGE = Messages.RMD_FILE_DOESNT_EXISTS_ERROR_;
79
	public static String INVALID_WSDL_MESSAGE = Messages.IMPROPER_WSDL_FILE_ERROR_;
79
80
80
    public static String INVALID_WSDL_MESSAGE = Messages.IMPROPER_WSDL_FILE_ERROR_;
81
	public static String WSDL_LOCATION_NOT_RESOLVE = Messages.UNRESOLVED_WSDL_LOCATION_ERROR_;
81
82
82
    public static String WSDL_LOCATION_NOT_RESOLVE = Messages.UNRESOLVED_WSDL_LOCATION_ERROR_;
83
	public static String NO_RP_ATTRIBUTE_MESSAGE = Messages.NO_RP_ATTRIBUTE_WARN_;
83
84
84
    public static String NO_RP_ATTRIBUTE_MESSAGE = Messages.NO_RP_ATTRIBUTE_WARN_;
85
	public static String NO_METADESCRIPTOR_LOCATION_MESSAGE = Messages.NO_METADESCRIPTOR_LOCATION_WARN_;
85
86
86
    public static String NO_METADESCRIPTOR_LOCATION_MESSAGE = Messages.NO_METADESCRIPTOR_LOCATION_WARN_;
87
	public static String NO_METADESCRIPTOR_MESSAGE = Messages.NO_METADESCRIPTOR_WARN_;
87
88
88
    public static String NO_METADESCRIPTOR_MESSAGE = Messages.NO_METADESCRIPTOR_WARN_;
89
	public static String NO_RP_ELEMENT_MESSAGE = Messages.NO_RP_ELEMENT_ERROR_;
89
90
90
    public static String NO_RP_ELEMENT_MESSAGE = Messages.NO_RP_ELEMENT_ERROR_;
91
	public Definition2Capability(Definition wsdlDefinition)
91
92
	{
92
    public Definition2Capability(Definition wsdlDefinition)
93
		this(wsdlDefinition, true, true, true, true);
93
    {
94
	}
94
	this(wsdlDefinition, true, true, true, true);
95
95
    }
96
	public Definition2Capability(Definition wsdlDefinition,
96
97
			boolean loadProperties, boolean loadRMD, boolean loadOperations,
97
    public Definition2Capability(Definition wsdlDefinition,
98
			boolean loadTopics)
98
	    boolean loadProperties, boolean loadRMD, boolean loadOperations,
99
	{
99
	    boolean loadTopics)
100
		_wsdlDefinition = wsdlDefinition;
100
    {
101
		_capability = null;
101
	_wsdlDefinition = wsdlDefinition;
102
		_loadProperties = loadProperties;
102
	_capability = null;
103
		_loadRMD = loadRMD;
103
	_loadProperties = loadProperties;
104
		_loadOperations = loadOperations;
104
	_loadRMD = loadRMD;
105
		_loadTopics = loadTopics;
105
	_loadOperations = loadOperations;
106
	}
106
	_loadTopics = loadTopics;
107
107
    }
108
	/**
108
109
	 * Boolean parameter to load the properties of capability.
109
    /**
110
	 * 
110
     * Boolean parameter to load the properties of capability.
111
	 */
111
     * 
112
	public void setLoadProperties(boolean load)
112
     */
113
	{
113
    public void setLoadProperties(boolean load)
114
		_loadProperties = load;
114
    {
115
	}
115
	_loadProperties = load;
116
116
    }
117
	/**
117
118
	 * Boolean parameter to load the metadata of capability.
118
    /**
119
	 * 
119
     * Boolean parameter to load the metadata of capability.
120
	 */
120
     * 
121
	public void setLoadRMD(boolean load)
121
     */
122
	{
122
    public void setLoadRMD(boolean load)
123
		_loadRMD = load;
123
    {
124
	}
124
	_loadRMD = load;
125
125
    }
126
	/**
126
127
	 * Boolean parameter to load the operations of capability.
127
    /**
128
	 * 
128
     * Boolean parameter to load the operations of capability.
129
	 */
129
     * 
130
	public void setLoadOperations(boolean load)
130
     */
131
	{
131
    public void setLoadOperations(boolean load)
132
		_loadOperations = load;
132
    {
133
	}
133
	_loadOperations = load;
134
134
    }
135
	/**
135
136
	 * Boolean parameter to load the topics of capability.
136
    /**
137
	 * 
137
     * Boolean parameter to load the topics of capability.
138
	 */
138
     * 
139
	public void setLoadTopics(boolean load)
139
     */
140
	{
140
    public void setLoadTopics(boolean load)
141
		_loadTopics = load;
141
    {
142
	}
142
	_loadTopics = load;
143
143
    }
144
	/**
144
145
	 * Returns the diagnostics list.
145
    /**
146
	 */
146
     * Returns the diagnostics list.
147
	public List getDiagonistics()
147
     */
148
	{
148
    public List getDiagonistics()
149
		return _diagonistics;
149
    {
150
	}
150
	return _diagonistics;
151
151
    }
152
	/**
152
153
	 * Returns the capability.
153
    /**
154
	 */
154
     * Returns the capability.
155
	public Capability getCapability()
155
     */
156
	{
156
    public Capability getCapability()
157
		startConversion();
157
    {
158
		return _capability;
158
	startConversion();
159
	}
159
	return _capability;
160
    }
161
162
    /**
163
     * Returns the resource property element.
164
     */
165
    public XSDElementDeclaration getResourcePropertyElement()
166
    {
167
	return _resourcePropertyElement;
168
    }
169
170
    /**
171
     * Returns the wsdl definition.
172
     */
173
    public Definition getWSDLDefinition()
174
    {
175
	return _wsdlDefinition;
176
    }
177
178
    /**
179
     * Returns the PropertyMetaDataDescriptor.
180
     */
181
    public PropertyMetaDataDescriptor getPropertyMetaDataDescriptor()
182
    {
183
	return _metaDataDescriptor;
184
    }
185
186
    private void startConversion()
187
    {
188
	if (!isValidCapability())
189
	    return;
190
	populateCapabilityInfo();
191
192
	if (_metaDataMap != null)
193
	{
194
195
	    String resourceProperties = (String) _metaDataMap
196
		    .get(WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
197
	    String metadataDescriptorLocation = (String) _metaDataMap
198
		    .get(WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
199
	    String metadataDescriptorName = (String) _metaDataMap
200
		    .get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
201
202
	    if (resourceProperties != null)
203
	    {
204
		_resourcePropertyElement = WsdlUtils.getResourcePropertyElement(
205
			_wsdlDefinition, resourceProperties);
206
		if (_loadProperties)
207
		    if (!populateCapabilityProperties())
208
			return;
209
	    }
210
160
211
	    if (metadataDescriptorLocation != null
161
	/**
212
		    && metadataDescriptorName != null)
162
	 * Returns the resource property element.
213
	    {
163
	 */
214
		if (_loadRMD)
164
	public XSDElementDeclaration getResourcePropertyElement()
215
		    if (!populateMetadata())
165
	{
166
		return _resourcePropertyElement;
167
	}
168
169
	/**
170
	 * Returns the wsdl definition.
171
	 */
172
	public Definition getWSDLDefinition()
173
	{
174
		return _wsdlDefinition;
175
	}
176
177
	private void startConversion()
178
	{
179
		if (!isValidCapability())
216
			return;
180
			return;
181
		populateCapabilityInfo();
182
183
		if (_metaDataMap != null)
184
		{
185
186
			String resourceProperties = (String) _metaDataMap
187
					.get(WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
188
			String metadataDescriptorLocation = (String) _metaDataMap
189
					.get(WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
190
			String metadataDescriptorName = (String) _metaDataMap
191
					.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
192
193
			if (resourceProperties != null)
194
			{
195
				_resourcePropertyElement = WsdlUtils
196
						.getResourcePropertyElement(_wsdlDefinition,
197
								resourceProperties);
198
				if (_loadProperties)
199
					if (!populateCapabilityProperties())
200
						return;
201
			}
202
203
			if (metadataDescriptorLocation != null
204
					&& metadataDescriptorName != null)
205
			{
206
				if (_loadRMD)
207
					if (!populateMetadata())
208
						return;
209
				if (_loadTopics)
210
					if (!populateCapabilityTopics())
211
						return;
212
			}
213
		}
214
215
		if (_loadOperations)
216
			if (!populateCapabilityOperations())
217
				return;
218
217
		if (_loadTopics)
219
		if (_loadTopics)
218
		    if (!populateCapabilityTopics())
220
			if (!populateCapabilityTopics())
219
			return;
221
				return;
220
	    }
221
	}
222
222
223
	if (_loadOperations)
224
	    if (!populateCapabilityOperations())
225
		return;
226
	
227
	if(_loadTopics)
228
	    if(!populateCapabilityTopics())
229
		return;
223
		return;
230
	
224
	}
231
	return;
225
232
    }
226
	protected boolean isValidCapability()
233
227
	{
234
    protected boolean isValidCapability()
228
		if (_wsdlDefinition == null)
235
    {
229
		{
236
	if (_wsdlDefinition == null)
230
			prepareErrorDiagnostics(INVALID_WSDL_MESSAGE);
237
	{
231
			return false;
238
	    prepareErrorDiagnostics(INVALID_WSDL_MESSAGE);
232
		}
239
	    return false;
233
240
	}
234
		_metaDataMap = WsdlUtils.getMetadataFromPortType(_wsdlDefinition);
241
235
242
	_metaDataMap = WsdlUtils.getMetadataFromPortType(_wsdlDefinition);
236
		return true;
243
237
	}
244
	return true;
238
245
    }
239
	protected void prepareErrorDiagnostics(String message)
246
240
	{
247
    protected void prepareErrorDiagnostics(String message)
241
		WsdmToolingLog.logWarning(message);
248
    {
242
		_diagonistics.add(message);
249
	WsdmToolingLog.logWarning(message);
243
		_capability = null;
250
	_diagonistics.add(message);
244
	}
251
	_capability = null;
245
252
    }
246
	private void populateCapabilityInfo()
253
247
	{
254
    private void populateCapabilityInfo()
248
		_capability = CapabilitiesFactory.eINSTANCE.createCapability();
255
    {
249
		QName qname = _wsdlDefinition.getQName();
256
	_capability = CapabilitiesFactory.eINSTANCE.createCapability();
250
		String localPart = qname.getLocalPart();
257
	QName qname = _wsdlDefinition.getQName();
251
		String ns = _wsdlDefinition.getTargetNamespace();
258
	String localPart = qname.getLocalPart();
252
		String prefix = _wsdlDefinition.getPrefix(ns);
259
	String ns = _wsdlDefinition.getTargetNamespace();
253
		Text node = CapUtils.getDescriptionNode(_wsdlDefinition);
260
	String prefix = _wsdlDefinition.getPrefix(ns);
254
		String description = "";
261
	Text node = CapUtils.getDescriptionNode(_wsdlDefinition);
255
		if (node != null)
262
	String description = "";
256
			description = node.getData();
263
	if (node != null)
257
		_capability.setNamespace(ns);
264
	    description = node.getData();
258
		_capability.setPrefix(prefix);
265
	_capability.setNamespace(ns);
259
		_capability.setName(localPart);
266
	_capability.setPrefix(prefix);
260
		_capability.setDescription(description);
267
	_capability.setName(localPart);
261
		_capability.setDefinition(_wsdlDefinition);
268
	_capability.setDescription(description);
262
	}
269
    }
263
270
264
	private boolean populateCapabilityProperties()
271
    private boolean populateCapabilityProperties()
265
	{
272
    {
266
		XSDElementDeclaration[] elements = CapUtils.getResolvedProperties(
273
	XSDElementDeclaration[] elements = CapUtils.getResolvedProperties(
267
				_wsdlDefinition, _resourcePropertyElement);
274
		_wsdlDefinition, _resourcePropertyElement);
268
		_capability.getProperties().clear();
275
	_capability.getProperties().clear();
269
		for (int i = 0; i < elements.length; i++)
276
	for (int i = 0; i < elements.length; i++)
270
		{
277
	{
271
			Property property = CapabilitiesFactory.eINSTANCE.createProperty();
278
	    	Property property = CapabilitiesFactory.eINSTANCE.createProperty();
272
			property.setElement(elements[i]);
279
		property.setElement(elements[i]);
273
			_capability.getProperties().add(property);
280
		_capability.getProperties().add(property);	    
274
		}
281
	}
275
		return true;
282
	return true;
276
	}
283
    }
277
284
278
	private boolean populateMetadata()
285
    private boolean populateMetadata()
279
	{
286
    {
280
		String metadataDescriptorLocation = (String) _metaDataMap
287
	String metadataDescriptorLocation = (String) _metaDataMap
281
				.get(WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
288
		.get(WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
282
		String metadataDescriptorName = (String) _metaDataMap
289
	String metadataDescriptorName = (String) _metaDataMap
283
				.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
290
		.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
284
291
285
		String wsdlPath = WsdlUtils.getWSDLFileLocation(_wsdlDefinition);
292
	String wsdlPath = WsdlUtils.getWSDLFileLocation(_wsdlDefinition);
286
		if (wsdlPath == null)
293
	if (wsdlPath == null)
287
		{
294
	{
288
			prepareErrorDiagnostics(WSDL_LOCATION_NOT_RESOLVE);
295
	    prepareErrorDiagnostics(WSDL_LOCATION_NOT_RESOLVE);
289
			return false;
296
	    return false;
290
		}
297
	}
291
		String wsdlContainer = wsdlPath.substring(0, wsdlPath.lastIndexOf("/"));
298
	String wsdlContainer = wsdlPath.substring(0, wsdlPath.lastIndexOf("/"));
292
		String rmdFileLocation = wsdlContainer + "/"
299
	String rmdFileLocation = wsdlContainer + "/"
293
				+ metadataDescriptorLocation;
300
		+ metadataDescriptorLocation;
294
		URI rmdURI = URI.createURI(rmdFileLocation);
301
	URI rmdURI = URI.createURI(rmdFileLocation);
295
		DocumentRoot root = null;
302
	DocumentRoot root = null;
296
		try
303
	try {
297
		{
304
	    root = RmdUtils.getDocumentRoot(rmdURI);
298
			root = RmdUtils.getDocumentRoot(rmdURI);
305
	} catch (Exception e) {
299
		} catch (Exception e)
306
	    // Workaround for relationship rmd, because that rmd have property defined as
300
		{
307
	    // tns:Relationship/Name, and emf fails to load such kind of properties
301
			// Workaround for relationship rmd, because that rmd have property
308
	    // We get the exception as
302
			// defined as
309
	    // org.eclipse.emf.ecore.xmi.IllegalValueException: Value 'tns:Relationship/name' is not legal.
303
			// tns:Relationship/Name, and emf fails to load such kind of
310
	    // and we can't load the rmd for it	    
304
			// properties
311
	    if(e.getCause() instanceof org.eclipse.emf.ecore.xmi.IllegalValueException)
305
			// We get the exception as
312
		return true;	    
306
			// org.eclipse.emf.ecore.xmi.IllegalValueException: Value
313
	    WsdmToolingLog.logError(Messages.FAILED_TO_LOAD_RMD_ERROR_, e);
307
			// 'tns:Relationship/name' is not legal.
314
	}
308
			// and we can't load the rmd for it
315
	if(root == null)
309
			if (e.getCause() instanceof org.eclipse.emf.ecore.xmi.IllegalValueException)
316
	    prepareErrorDiagnostics(RMD_FILE_NOT_EXISTS_MESSAGE);
310
				return true;
317
	
311
			WsdmToolingLog.logError(Messages.FAILED_TO_LOAD_RMD_ERROR_, e);
318
	_metaDataDescriptor = new PropertyMetaDataDescriptor(root, _capability,
312
		}
319
		metadataDescriptorName);
313
		if (root == null)
320
	
314
			prepareErrorDiagnostics(RMD_FILE_NOT_EXISTS_MESSAGE);
321
	List props = _capability.getProperties();
315
322
	if(props == null || props.size() == 0)
316
		MetadataDescriptor _metaDataDescriptor = new MetadataDescriptor(
323
	    return true;
317
				_capability, root, metadataDescriptorName);
324
	
318
325
	for(int i=0;i<props.size();i++)
319
		List props = _capability.getProperties();
326
	{
320
		if (props == null || props.size() == 0)
327
	    Property property = (Property) props.get(i);
321
			return true;
328
	    XSDElementDeclaration element = property.getElement();
322
329
	    String name = XsdUtils.getName(element);
323
		for (int i = 0; i < props.size(); i++)
330
	    PropertyType propertyMetadata = _metaDataDescriptor.getPropertyMetadata(name, element.getTargetNamespace());
324
		{
331
	    if(propertyMetadata!=null)
325
			Property property = (Property) props.get(i);
332
		property.setMetaData(propertyMetadata);
326
			XSDElementDeclaration element = property.getElement();
333
	}
327
			String name = XsdUtils.getName(element);
334
	return true;
328
			PropertyType propertyMetadata = _metaDataDescriptor
335
    }
329
					.getPropertyMetadata(name, element.getTargetNamespace());
336
330
			if (propertyMetadata != null)
337
    private boolean populateCapabilityOperations()
331
				property.setMetaData(propertyMetadata);
338
    {
332
		}
339
	PortType pt = WsdlUtils.getPortType(_wsdlDefinition);
333
		return true;
340
	if(pt == null)
334
	}
341
	    return true;
335
342
	Operation[] operations = WsdlUtils.getWSDLOperation(_wsdlDefinition);
336
	private boolean populateCapabilityOperations()
343
	_capability.getOperations().clear();
337
	{
344
	for (int i = 0; i < operations.length; i++)
338
		PortType pt = WsdlUtils.getPortType(_wsdlDefinition);
345
	{
339
		if (pt == null)
346
	    _capability.getOperations().add(operations[i]);
340
			return true;
347
	}
341
		Operation[] operations = WsdlUtils.getWSDLOperation(_wsdlDefinition);
348
	return true;
342
		_capability.getOperations().clear();
349
    }
343
		for (int i = 0; i < operations.length; i++)
350
344
		{
351
    private boolean populateCapabilityTopics()
345
			_capability.getOperations().add(operations[i]);
352
    {
346
		}
353
	if(_metaDataDescriptor == null)
347
		return true;
354
	    return true;	
348
	}
355
	if(_metaDataDescriptor.getDocumentRoot() == null || _metaDataDescriptor.getMetadataDescriptorType() == null)
349
356
	    return true;
350
	private boolean populateCapabilityTopics()
357
	List topicSpaces = _metaDataDescriptor.getTopicSpaces();
351
	{
358
	_capability.getTopicSpaces().clear();
352
		MetadataDescriptor _metaDataDescriptor = _capability.getMetadata();
359
	_capability.getTopicSpaces().addAll(topicSpaces);
353
		if (_metaDataDescriptor == null)
360
	return true;
354
			return true;
361
    }
355
		if (_metaDataDescriptor.getDocumentRoot() == null
356
				|| _metaDataDescriptor.getMetadataDescriptorType() == null)
357
			return true;
358
		_metaDataDescriptor.loadTopicSpaces();
359
		return true;
360
	}
362
}
361
}
(-)META-INF/MANIFEST.MF (-3 / +2 lines)
Lines 15-22 Link Here
15
 org.eclipse.tptp.wsdm.tooling.model,
15
 org.eclipse.tptp.wsdm.tooling.model,
16
 org.apache.muse.api;visibility:=reexport,
16
 org.apache.muse.api;visibility:=reexport,
17
 org.apache.muse.core,
17
 org.apache.muse.core,
18
 org.apache.muse.utils;visibility:=reexport,
18
 org.apache.muse.tools,
19
 org.apache.muse.tools
19
 org.apache.xerces;visibility:=reexport
20
Eclipse-LazyStart: true
20
Eclipse-LazyStart: true
21
Export-Package: org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal,
21
Export-Package: org.eclipse.tptp.wsdm.tooling.nls.messages.capability.internal,
22
 org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal,
22
 org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal,
Lines 38-41 Link Here
38
 org.eclipse.tptp.wsdm.tooling.validation.wizard.internal
38
 org.eclipse.tptp.wsdm.tooling.validation.wizard.internal
39
Bundle-ClassPath: runtime/validation.jar
39
Bundle-ClassPath: runtime/validation.jar
40
Bundle-Vendor: %plugin.provider
40
Bundle-Vendor: %plugin.provider
41
Import-Package: org.apache.xml.serialize
(-)src/org/eclipse/tptp/wsdm/tooling/validation/capability/internal/CapabilityWSDLValidator.java (-409 / +448 lines)
Lines 20-26 Link Here
20
import javax.wsdl.factory.WSDLFactory;
20
import javax.wsdl.factory.WSDLFactory;
21
import javax.wsdl.xml.WSDLReader;
21
import javax.wsdl.xml.WSDLReader;
22
22
23
import org.apache.muse.util.xml.XmlUtils;
24
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
25
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
Lines 63-481 Link Here
63
public class CapabilityWSDLValidator
62
public class CapabilityWSDLValidator
64
{
63
{
65
64
66
    private IValidationReport _consolidatedReport = new EmptyValidationReport();
65
	private IValidationReport _consolidatedReport = new EmptyValidationReport();
67
66
68
    private static final String INVALID_CAPABILITY_NAME_MESSAGE = Messages.INVALID_CAPABILITY_NAME_MESSAGE;
67
	private static final String INVALID_CAPABILITY_NAME_MESSAGE = Messages.INVALID_CAPABILITY_NAME_MESSAGE;
69
68
70
    private static final String INVALID_CAPABILITY_NAMESPACE_MESSAGE = Messages.INVALID_CAPABILITY_NAMESPACE_MESSAGE;
69
	private static final String INVALID_CAPABILITY_NAMESPACE_MESSAGE = Messages.INVALID_CAPABILITY_NAMESPACE_MESSAGE;
71
70
72
    private static final String NO_PORT_TYPE_MESSAGE = Messages.NO_PORT_TYPE_MESSAGE;
71
	private static final String NO_PORT_TYPE_MESSAGE = Messages.NO_PORT_TYPE_MESSAGE;
73
72
74
    private static final String NO_RP_ELEMENT_MESSAGE = Messages.NO_RP_ELEMENT_MESSAGE;
73
	private static final String NO_RP_ELEMENT_MESSAGE = Messages.NO_RP_ELEMENT_MESSAGE;
75
74
76
    private static final String NO_METADESCRIPTOR_LOCATION_ELEMENT_MESSAGE = Messages.NO_METADESCRIPTOR_LOCATION_ELEMENT_MESSAGE;
75
	private static final String NO_METADESCRIPTOR_LOCATION_ELEMENT_MESSAGE = Messages.NO_METADESCRIPTOR_LOCATION_ELEMENT_MESSAGE;
77
	
76
78
    private static final String NO_METADESCRIPTOR_ELEMENT_MESSAGE = Messages.NO_METADESCRIPTOR_ELEMENT_MESSAGE;
77
	private static final String NO_METADESCRIPTOR_ELEMENT_MESSAGE = Messages.NO_METADESCRIPTOR_ELEMENT_MESSAGE;
79
78
80
    private static final String RP_ELEMENT_NOT_FOUND_MESSAGE = Messages.RP_ELEMENT_NOT_FOUND_MESSAGE;
79
	private static final String RP_ELEMENT_NOT_FOUND_MESSAGE = Messages.RP_ELEMENT_NOT_FOUND_MESSAGE;
81
80
82
    private static final String CONFLICTED_OPERATION = org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages.CONFLICTED_OPERATION_WARN_;
81
	private static final String CONFLICTED_OPERATION = org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages.CONFLICTED_OPERATION_WARN_;
83
    
82
84
    private static final String DUPLICATE_OPERATION_MESSAGE = "Duplicate operation";
83
	private static final String DUPLICATE_OPERATION_MESSAGE = "Duplicate operation";
85
84
86
    private static final String DUPLICATE_PARAM_MESSAGE = "Duplicate parameter";
85
	private static final String DUPLICATE_PARAM_MESSAGE = "Duplicate parameter";
87
86
88
    private static final String INVALID_OPERATION_NAME_MESSAGE = "Invalid operation name";
87
	private static final String INVALID_OPERATION_NAME_MESSAGE = "Invalid operation name";
89
88
90
    private static final String INVALID_PARAM_NAME_MESSAGE = "Invalid parameter name";
89
	private static final String INVALID_PARAM_NAME_MESSAGE = "Invalid parameter name";
91
90
92
    /**
91
	/**
93
     * Creates object of this class. 
92
	 * Creates object of this class.
94
     */
93
	 */
95
    public CapabilityWSDLValidator()
94
	public CapabilityWSDLValidator()
96
    {
95
	{
97
    }
96
	}
98
97
99
    /**
98
	/**
100
     * Perform WSDL validation 
99
	 * Perform WSDL validation
101
     */
100
	 */
102
    public IValidationReport validate(Definition definition)
101
	public IValidationReport validate(Definition definition)
103
    {
102
	{
104
	// Do Validation
103
		// Do Validation
105
	performWSDLValidation(definition);
104
		performWSDLValidation(definition);
106
	performExtraValidation(definition);
105
		performExtraValidation(definition);
107
106
108
	return _consolidatedReport;
107
		return _consolidatedReport;
109
    }
108
	}
110
109
111
    private void performWSDLValidation(Definition definition)
110
	private void performWSDLValidation(Definition definition)
112
    {
111
	{
113
	ByteArrayOutputStream baos;
112
		ByteArrayOutputStream baos;
114
	try
113
		try
115
	{
114
		{
116
	    baos = WsdlUtils.saveWSDLDefinition(definition,
115
			baos = WsdlUtils.saveWSDLDefinition(definition, definition
117
	    	definition.eResource().getURI().toString(), null);
116
					.eResource().getURI().toString(), null);
118
	} catch (IOException e1)
117
		} catch (IOException e1)
119
	{
118
		{
120
	    return;
119
			return;
121
	}
120
		}
122
	String docString = new String(baos.toByteArray());
121
		String docString = new String(baos.toByteArray());
123
	Document document = null;
122
		Document document = null;
124
	
123
125
	try
124
		try
126
	{
125
		{
127
	    document = XmlUtils.createDocument(docString);
126
			document = CapUtils.createDocument(docString);
128
	} catch (IOException exception)
127
		} catch (IOException exception)
129
	{
128
		{
130
	    IValidationMessage message = ValidationUtils
129
			IValidationMessage message = ValidationUtils
131
	    .createNewErrorMessage(exception.getMessage());
130
					.createNewErrorMessage(exception.getMessage());
132
	    _consolidatedReport.addValidationMessage(message);
131
			_consolidatedReport.addValidationMessage(message);
133
	    return;
132
			return;
134
	} catch (SAXException exception)
133
		} catch (SAXException exception)
135
	{
134
		{
136
	    IValidationMessage message = ValidationUtils
135
			IValidationMessage message = ValidationUtils
137
	    .createNewErrorMessage(exception.getMessage());
136
					.createNewErrorMessage(exception.getMessage());
138
	    _consolidatedReport.addValidationMessage(message);
137
			_consolidatedReport.addValidationMessage(message);
139
	    return;
138
			return;
140
	}
139
		}
141
	
140
142
	WSDLFactory factory = new WSDLFactoryImpl();
141
		WSDLFactory factory = new WSDLFactoryImpl();
143
	WSDLReader reader = factory.newWSDLReader();
142
		WSDLReader reader = factory.newWSDLReader();
144
	try
143
		try
145
	{
144
		{
146
	    String baseURI;
145
			String baseURI;
147
	    try
146
			try
148
	    {
147
			{
149
		baseURI = WsdlUtils.getLocalSystemWSDLLocation(definition);
148
				baseURI = WsdlUtils.getLocalSystemWSDLLocation(definition);
150
	    } catch (CoreException e)
149
			} catch (CoreException e)
151
	    {
150
			{
152
		return;
151
				return;
153
	    }
152
			}
154
	    reader.readWSDL(baseURI, document);
153
			reader.readWSDL(baseURI, document);
155
	} 
154
		} catch (WSDLException exception)
156
	catch (WSDLException exception)
155
		{
157
	{
156
			IValidationMessage message = ValidationUtils
158
	    IValidationMessage message = ValidationUtils
157
					.createNewErrorMessage(exception.getMessage());
159
		    .createNewErrorMessage(exception.getMessage());
158
			_consolidatedReport.addValidationMessage(message);
160
	    _consolidatedReport.addValidationMessage(message);
159
		}
161
	}
160
	}
162
    }
161
163
162
	private void performExtraValidation(Definition definition)
164
    private void performExtraValidation(Definition definition)
163
	{
165
    {
164
		String name = definition.getQName().getLocalPart();
166
	String name = definition.getQName().getLocalPart();
165
		String namespace = definition.getTargetNamespace();
167
	String namespace = definition.getTargetNamespace();
166
168
	
167
		// Validate capability name
169
	// Validate capability name
168
		if (name == null || name.equals(""))
170
	if (name == null || name.equals(""))
169
		{
171
	{
170
			IValidationMessage message = ValidationUtils
172
	    IValidationMessage message = ValidationUtils
171
					.createNewErrorMessage(INVALID_CAPABILITY_NAME_MESSAGE);
173
		    .createNewErrorMessage(INVALID_CAPABILITY_NAME_MESSAGE);
172
			_consolidatedReport.addValidationMessage(message);
174
	    _consolidatedReport.addValidationMessage(message);
173
		}
175
	}
174
176
	
175
		// Validate capability namespace
177
	// Validate capability namespace
176
		if (!Validation.isNamespace(namespace))
178
	if (!Validation.isNamespace(namespace))
177
		{
179
	{
178
			IValidationMessage message = ValidationUtils
180
	    IValidationMessage message = ValidationUtils
179
					.createNewErrorMessage(INVALID_CAPABILITY_NAMESPACE_MESSAGE);
181
		    .createNewErrorMessage(INVALID_CAPABILITY_NAMESPACE_MESSAGE);
180
			_consolidatedReport.addValidationMessage(message);
182
	    _consolidatedReport.addValidationMessage(message);
181
		}
183
	}
182
184
	
183
		// Validate Duplicate capability
185
	// Validate Duplicate capability
184
		// NOTE : Fix for Bug 167600 "No validation, When Creating Duplicate
186
	// NOTE : Fix for Bug 167600 "No validation, When Creating Duplicate Capability"
185
		// Capability"
187
	// http://bugs.eclipse.org/bugs/show_bug.cgi?id=167600
186
		// http://bugs.eclipse.org/bugs/show_bug.cgi?id=167600
188
	try {
187
		try
189
		Map capabilitiesMap = CapUtils.getAllCapabilitiesMap();
188
		{
190
		Object value = capabilitiesMap.get(namespace);
189
			Map capabilitiesMap = CapUtils.getAllCapabilitiesMap();
191
		if(value!=null){
190
			Object value = capabilitiesMap.get(namespace);
192
			List list = (List) value;
191
			if (value != null)
193
			if(list.size()>1){
192
			{
193
				List list = (List) value;
194
				if (list.size() > 1)
195
				{
196
					IValidationMessage message = ValidationUtils
197
							.createNewErrorMessage(Messages.bind(
198
									Messages.DUPLICATE_CAPABILITY, name));
199
					_consolidatedReport.addValidationMessage(message);
200
				}
201
			}
202
		} catch (Exception e)
203
		{
204
			IValidationMessage message = ValidationUtils
205
					.createNewErrorMessage(e.getMessage());
206
			_consolidatedReport.addValidationMessage(message);
207
			return;
208
		}
209
210
		// Validate capability port type
211
		PortType pt = WsdlUtils.getPortType(definition);
212
		if (pt == null)
213
		{
214
			IValidationMessage message = ValidationUtils
215
					.createNewErrorMessage(NO_PORT_TYPE_MESSAGE);
216
			_consolidatedReport.addValidationMessage(message);
217
			return;
218
		}
219
220
		Map map = WsdlUtils.getMetadataFromPortType(definition);
221
222
		// Check for Resource property element
223
		String resourceProperties = (String) map
224
				.get(WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
225
		if (resourceProperties == null || resourceProperties.equals(""))
226
		{
227
			IValidationMessage message = ValidationUtils
228
					.createNewWarningMessage(NO_RP_ELEMENT_MESSAGE);
229
			_consolidatedReport.addValidationMessage(message);
230
		}
231
232
		// Check for Metadescriptor element
233
		String metadataDescriptorLocation = (String) map
234
				.get(WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
235
		if (metadataDescriptorLocation == null
236
				|| metadataDescriptorLocation.equals(""))
237
		{
238
			IValidationMessage message = ValidationUtils
239
					.createNewWarningMessage(NO_METADESCRIPTOR_LOCATION_ELEMENT_MESSAGE);
240
			_consolidatedReport.addValidationMessage(message);
241
		}
242
243
		String metadataDescriptor = (String) map
244
				.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
245
		if (metadataDescriptor == null || metadataDescriptor.equals(""))
246
		{
247
			IValidationMessage message = ValidationUtils
248
					.createNewWarningMessage(NO_METADESCRIPTOR_ELEMENT_MESSAGE);
249
			_consolidatedReport.addValidationMessage(message);
250
		}
251
252
		if (resourceProperties != null)
253
		{
254
			XSDElementDeclaration rpElement = WsdlUtils
255
					.getResourcePropertyElement(definition, resourceProperties);
256
			if (rpElement == null)
257
			{
194
				IValidationMessage message = ValidationUtils
258
				IValidationMessage message = ValidationUtils
195
			    .createNewErrorMessage(Messages.bind(Messages.DUPLICATE_CAPABILITY, name));
259
						.createNewErrorMessage(RP_ELEMENT_NOT_FOUND_MESSAGE);
196
				_consolidatedReport.addValidationMessage(message);	    
260
				_consolidatedReport.addValidationMessage(message);
261
			}
262
			else
263
			{
264
				performRPElementValidation(definition, rpElement);
197
			}
265
			}
198
		}
266
		}
199
	} catch (Exception e) {
267
		// TODO Check for RMD exists and Descriptor exists
200
		IValidationMessage message = ValidationUtils
268
		// TODO Check for All in same namespace
201
	    .createNewErrorMessage(e.getMessage());
269
202
		_consolidatedReport.addValidationMessage(message);
270
		performOperationsValidation(definition);
203
		return;
271
204
	}
272
		performWsdlMessagesValidation(definition);
205
	
273
206
	// Validate capability port type
274
		performBindingValidation(definition);
207
	PortType pt = WsdlUtils.getPortType(definition);
275
	}
208
	if (pt == null)
276
209
	{
277
	private void performOperationsValidation(Definition definition)
210
	    IValidationMessage message = ValidationUtils
278
	{
211
		    .createNewErrorMessage(NO_PORT_TYPE_MESSAGE);
279
		Definition2Capability def2Capability = new Definition2Capability(
212
	    _consolidatedReport.addValidationMessage(message);
280
				definition, false, false, true, false);
213
	    return;
281
		Capability capability = def2Capability.getCapability();
214
	}
282
		List operations = capability.getOperations();
215
283
		for (int i = 0; i < operations.size(); i++)
216
	Map map = WsdlUtils.getMetadataFromPortType(definition);
284
		{
217
	
285
			Operation operation = (Operation) operations.get(i);
218
	// Check for Resource property element
286
			validateResolvedOperation(operation);
219
	String resourceProperties = (String) map
287
			String msg = CapUtils.validateJavaIdentifier(operation.getName());
220
		.get(WsdlUtils.RESOURCE_PROPERTIES_ELEMENT_KEY);
288
			if (msg != null)
221
	if (resourceProperties == null || resourceProperties.equals(""))
289
			{
222
	{
290
				IValidationMessage message = ValidationUtils
223
	    IValidationMessage message = ValidationUtils
291
						.createNewErrorMessage(msg);
224
		    .createNewWarningMessage(NO_RP_ELEMENT_MESSAGE);
292
				_consolidatedReport.addValidationMessage(message);
225
	    _consolidatedReport.addValidationMessage(message);
293
			}
226
	}
294
			if (CapUtils.isOperationNameConflicted(operation.getName()))
227
295
			{
228
	// Check for Metadescriptor element
296
				msg = org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages
229
	String metadataDescriptorLocation = (String) map
297
						.bind(CONFLICTED_OPERATION, operation.getName());
230
		.get(WsdlUtils.METADATA_DESCRIPTOR_LOCATION_KEY);
298
				IValidationMessage message = ValidationUtils
231
	if (metadataDescriptorLocation == null
299
						.createNewErrorMessage(msg);
232
		|| metadataDescriptorLocation.equals(""))
300
				_consolidatedReport.addValidationMessage(message);
233
	{
301
			}
234
	    IValidationMessage message = ValidationUtils
302
		}
235
		    .createNewWarningMessage(NO_METADESCRIPTOR_LOCATION_ELEMENT_MESSAGE);
303
		// TODO Check for duplicate param name
236
	    _consolidatedReport.addValidationMessage(message);
304
		// TODO Check for invalid param name
237
	}
305
	}
238
306
239
	String metadataDescriptor = (String) map
307
	private void validateResolvedOperation(Operation operation)
240
		.get(WsdlUtils.METADATA_DESCRIPTOR_KEY);
308
	{
241
	if (metadataDescriptor == null || metadataDescriptor.equals(""))
309
		IValidationMessage unresolvedOperationMessage = ValidationUtils
242
	{
310
				.createNewErrorMessage(Messages.bind(
243
	    IValidationMessage message = ValidationUtils
311
						Messages.UNRESOLVED_OPERATION_MESSAGE, operation
244
		    .createNewWarningMessage(NO_METADESCRIPTOR_ELEMENT_MESSAGE);
312
								.getName()));
245
	    _consolidatedReport.addValidationMessage(message);
313
		if (operation.getEInput() != null)
246
	}
314
		{
247
315
			if (operation.getEInput().getEMessage() == null)
248
	if (resourceProperties != null)
316
				_consolidatedReport
249
	{
317
						.addValidationMessage(unresolvedOperationMessage);
250
	    XSDElementDeclaration rpElement = WsdlUtils
318
251
		    .getResourcePropertyElement(definition, resourceProperties);
319
		}
252
	    if (rpElement == null)
320
		else
253
	    {
321
			_consolidatedReport
254
		IValidationMessage message = ValidationUtils
322
					.addValidationMessage(unresolvedOperationMessage);
255
			.createNewErrorMessage(RP_ELEMENT_NOT_FOUND_MESSAGE);
323
256
		_consolidatedReport.addValidationMessage(message);
324
		if (operation.getEOutput() != null)
257
	    }
325
		{
258
	    else
326
			if (operation.getEOutput().getEMessage() == null)
259
	    {
327
				_consolidatedReport
260
		performRPElementValidation(definition, rpElement);
328
						.addValidationMessage(unresolvedOperationMessage);
261
	    }
329
		}
262
	}
330
		else
263
	// TODO Check for RMD exists and Descriptor exists
331
			_consolidatedReport
264
	// TODO Check for All in same namespace
332
					.addValidationMessage(unresolvedOperationMessage);
265
333
	}
266
	performOperationsValidation(definition);
334
267
	
335
	private void performRPElementValidation(Definition definition,
268
	performWsdlMessagesValidation(definition);
336
			XSDElementDeclaration resourcePropertyElement)
269
	
337
	{
270
	performBindingValidation(definition);
338
		if (resourcePropertyElement.getAnonymousTypeDefinition() == null)
271
    }
339
			return;
272
340
		XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
273
    private void performOperationsValidation(Definition definition)
341
				.getAnonymousTypeDefinition();
274
    {
342
		XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
275
	Definition2Capability def2Capability = new Definition2Capability(
343
		XSDElementDeclaration[] elementRefs = XsdUtils
276
		definition, false, false, true, false);
344
				.getElementDeclarations(modelGroup);
277
	Capability capability = def2Capability.getCapability();
345
		for (int i = 0; i < elementRefs.length; i++)
278
	List operations = capability.getOperations();
346
		{
279
	for (int i = 0; i < operations.size(); i++)
347
			if (XsdUtils.isReferencedElement(elementRefs[i]))
280
	{
348
			{
281
	    Operation operation = (Operation) operations.get(i);
349
				WsdlElementResolver resolver = new WsdlElementResolver(
282
	    validateResolvedOperation(operation);
350
						definition, resourcePropertyElement, elementRefs[i]);
283
	    String msg = CapUtils.validateJavaIdentifier(operation.getName());
351
				XSDElementDeclaration resolvedElement = resolver.resolve();
284
	    if (msg != null)
352
				if (resolvedElement == null)
285
	    {
353
				{
286
		IValidationMessage message = ValidationUtils
354
					String unresolvedElementName = elementRefs[i]
287
			.createNewErrorMessage(msg);
355
							.getResolvedElementDeclaration().getName();
288
		_consolidatedReport.addValidationMessage(message);
356
					IValidationMessage message = ValidationUtils
289
	    }
357
							.createNewErrorMessage(NLS.bind(
290
	    if(CapUtils.isOperationNameConflicted(operation.getName()))
358
									Messages.UNRESOLVED_ELEMENT_MESSAGE,
291
	    {
359
									unresolvedElementName));
292
	    msg = org.eclipse.tptp.wsdm.tooling.nls.messages.capability.operation.internal.Messages.bind(CONFLICTED_OPERATION, operation.getName());
360
					_consolidatedReport.addValidationMessage(message);
293
	    IValidationMessage message = ValidationUtils
361
				}
294
			.createNewErrorMessage(msg);
362
			}
295
		_consolidatedReport.addValidationMessage(message);
363
		}
296
	    }
364
	}
297
	}
365
298
	// TODO Check for duplicate param name
366
	private void performWsdlMessagesValidation(Definition definition)
299
	// TODO Check for invalid param name
367
	{
300
    }
368
		if (definition == null)
301
    
369
			return;
302
    private void validateResolvedOperation(Operation operation)
370
		List messages = definition.getEMessages();
303
    {
371
		if (messages != null)
304
	IValidationMessage unresolvedOperationMessage = ValidationUtils
372
		{
305
	.createNewErrorMessage(Messages.bind(Messages.UNRESOLVED_OPERATION_MESSAGE, operation.getName()));
373
			for (int i = 0; i < messages.size(); i++)
306
	if(operation.getEInput() != null)
374
			{
307
	{
375
				Message message = (Message) messages.get(i);
308
	    if(operation.getEInput().getEMessage() == null)
376
				if (message.getEParts() == null
309
		_consolidatedReport.addValidationMessage(unresolvedOperationMessage);
377
						|| message.getEParts().size() == 0)
310
	
378
				{
311
	}
379
					IValidationMessage valMessage = ValidationUtils
312
	else
380
							.createNewErrorMessage(Messages.bind(
313
	    _consolidatedReport.addValidationMessage(unresolvedOperationMessage);
381
									Messages.WSDL_MESSAGE_ZERO_PART_MESSAGE,
314
    
382
									message.getQName().getLocalPart()));
315
	if(operation.getEOutput() != null)
383
					_consolidatedReport.addValidationMessage(valMessage);
316
	{
384
					continue;
317
	    if(operation.getEOutput().getEMessage() == null)
385
				}
318
	    _consolidatedReport.addValidationMessage(unresolvedOperationMessage);		
386
319
	}
387
				if (message.getEParts().size() > 1)
320
	else
388
				{
321
	_consolidatedReport.addValidationMessage(unresolvedOperationMessage);
389
					IValidationMessage valMessage = ValidationUtils
322
    }
390
							.createNewErrorMessage(Messages
323
    
391
									.bind(
324
    private void performRPElementValidation(Definition definition,
392
											Messages.WSDL_MESSAGE_MORE_THAN_ONE_PART_MESSAGE,
325
	    XSDElementDeclaration resourcePropertyElement)
393
											message.getQName().getLocalPart()));
326
    {
394
					_consolidatedReport.addValidationMessage(valMessage);
327
	if (resourcePropertyElement.getAnonymousTypeDefinition() == null)
395
				}
328
	    return;
396
			}
329
	XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) resourcePropertyElement
397
		}
330
		.getAnonymousTypeDefinition();
398
		List imports = definition.getEImports();
331
	XSDModelGroup modelGroup = XsdUtils.getXSDModelGroup(typeDef);
399
		if (imports != null)
332
	XSDElementDeclaration[] elementRefs = XsdUtils
400
		{
333
		.getElementDeclarations(modelGroup);
401
			for (int i = 0; i < imports.size(); i++)
334
	for (int i = 0; i < elementRefs.length; i++)
402
			{
335
	{
403
				Import theImport = (Import) imports.get(i);
336
	    if (XsdUtils.isReferencedElement(elementRefs[i]))
404
				if (theImport.getLocationURI().endsWith("wsdl"))
337
	    {
405
					performWsdlMessagesValidation(theImport.getEDefinition());
338
		WsdlElementResolver resolver = new WsdlElementResolver(
406
			}
339
			definition, resourcePropertyElement, elementRefs[i]);
407
		}
340
		XSDElementDeclaration resolvedElement = resolver.resolve();
408
	}
341
		if (resolvedElement == null)
409
342
		{
410
	private void performBindingValidation(Definition definition)
343
		    String unresolvedElementName = elementRefs[i].getResolvedElementDeclaration().getName();
411
	{
344
		    IValidationMessage message = ValidationUtils
412
		if (definition == null)
345
			    .createNewErrorMessage(NLS.bind(Messages.UNRESOLVED_ELEMENT_MESSAGE,unresolvedElementName));
413
			return;
346
		    _consolidatedReport.addValidationMessage(message);
414
		List bindings = definition.getEBindings();
347
		}
415
		if (bindings == null)
348
	    }
416
			return;
349
	}
417
		for (int i = 0; i < bindings.size(); i++)
350
    }
418
		{
351
    
419
			Binding binding = (Binding) bindings.get(i);
352
    private void performWsdlMessagesValidation(Definition definition){
420
			validateBinding(binding);
353
    	if(definition == null)
421
		}
354
    		return;
422
		List imports = definition.getEImports();
355
    	List messages = definition.getEMessages();
423
		if (imports != null)
356
    	if(messages!=null)
424
		{
357
    	{
425
			for (int i = 0; i < imports.size(); i++)
358
    		for(int i=0;i<messages.size();i++)
426
			{
359
    		{
427
				Import theImport = (Import) imports.get(i);
360
    			Message message = (Message) messages.get(i);
428
				if (theImport.getLocationURI().endsWith("wsdl"))
361
    			if(message.getEParts() == null || message.getEParts().size() == 0)
429
					performBindingValidation(theImport.getEDefinition());
362
    			{
430
			}
363
    				IValidationMessage valMessage = ValidationUtils.createNewErrorMessage(Messages.bind(Messages.WSDL_MESSAGE_ZERO_PART_MESSAGE, message.getQName().getLocalPart()));
431
		}
364
    				_consolidatedReport.addValidationMessage(valMessage);
432
	}
365
    				continue;
433
366
    			}
434
	private void validateBinding(Binding binding)
367
    			
435
	{
368
    			if(message.getEParts().size()>1)
436
		boolean isDocumentStyle = false;
369
    			{
437
		List extnElems = binding.getEExtensibilityElements();
370
    				IValidationMessage valMessage = ValidationUtils.createNewErrorMessage(Messages.bind(Messages.WSDL_MESSAGE_MORE_THAN_ONE_PART_MESSAGE, message.getQName().getLocalPart()));
438
		if (extnElems == null)
371
    				_consolidatedReport.addValidationMessage(valMessage);
439
			return;
372
    			}	
440
		for (int i = 0; i < extnElems.size(); i++)
373
    		}
441
		{
374
    	}
442
			if (extnElems.get(i) instanceof SOAPBinding)
375
    	List imports = definition.getEImports();
443
			{
376
    	if(imports!=null)
444
				SOAPBinding soapBinding = (SOAPBinding) extnElems.get(i);
377
    	{
445
				isDocumentStyle = soapBinding.getStyle().equals("document");
378
    		for(int i=0;i<imports.size();i++)
446
				break;
379
    		{
447
			}
380
    			Import theImport = (Import) imports.get(i);
448
		}
381
    			if(theImport.getLocationURI().endsWith("wsdl"))
449
382
    				performWsdlMessagesValidation(theImport.getEDefinition());
450
		List operations = binding.getEBindingOperations();
383
    		}
451
		if (operations == null)
384
    	}
452
			return;
385
    }
453
386
    
454
		for (int i = 0; i < operations.size(); i++)
387
    private void performBindingValidation(Definition definition){
455
		{
388
    	if(definition == null)
456
			BindingOperation operation = (BindingOperation) operations.get(i);
389
    		return;
457
			validateBindingOperation(operation, isDocumentStyle);
390
    	List bindings = definition.getEBindings();
458
		}
391
    	if(bindings == null)
459
	}
392
    		return;
460
393
    	for(int i=0;i<bindings.size();i++)
461
	private void validateBindingOperation(BindingOperation operation,
394
    	{
462
			boolean isDocumentStyle)
395
    		Binding binding = (Binding) bindings.get(i);
463
	{
396
    		validateBinding(binding);
464
		if (operation == null)
397
    	}
465
			return;
398
    	List imports = definition.getEImports();
466
		validateBindingInput(operation.getEBindingInput(), isDocumentStyle);
399
    	if(imports!=null)
467
		validateBindingOutput(operation.getEBindingOutput(), isDocumentStyle);
400
    	{
468
	}
401
    		for(int i=0;i<imports.size();i++)
469
402
    		{
470
	private void validateBindingInput(BindingInput bindingInput,
403
    			Import theImport = (Import) imports.get(i);
471
			boolean isDocumentStyle)
404
    			if(theImport.getLocationURI().endsWith("wsdl"))
472
	{
405
    				performBindingValidation(theImport.getEDefinition());
473
		if (bindingInput == null)
406
    		}
474
			return;
407
    	}
475
		List extnElems = bindingInput.getEExtensibilityElements();
408
    }
476
		if (extnElems == null)
409
    
477
			return;
410
    private void validateBinding(Binding binding){
478
		for (int i = 0; i < extnElems.size(); i++)
411
    	boolean isDocumentStyle = false;
479
		{
412
    	List extnElems = binding.getEExtensibilityElements();
480
			if (extnElems.get(i) instanceof SOAPBody)
413
    	if(extnElems == null)
481
			{
414
    		return;
482
				SOAPBody soapBody = (SOAPBody) extnElems.get(i);
415
    	for(int i=0;i<extnElems.size();i++){
483
				boolean isLiteral = soapBody.getUse().equals("literal");
416
    		if(extnElems.get(i) instanceof SOAPBinding)
484
				if (!(isDocumentStyle && isLiteral))
417
    		{
485
				{
418
    			SOAPBinding soapBinding = (SOAPBinding) extnElems.get(i);
486
					IValidationMessage message = ValidationUtils
419
    			isDocumentStyle = soapBinding.getStyle().equals("document");
487
							.createNewErrorMessage(Messages.NOT_DOC_LITERAL_MESSAGE);
420
    			break;
488
					_consolidatedReport.addValidationMessage(message);
421
    		}
489
					return;
422
    	}
490
				}
423
    	
491
			}
424
    	List operations = binding.getEBindingOperations();
492
		}
425
    	if(operations == null)
493
	}
426
    		return;
494
427
    	
495
	private void validateBindingOutput(BindingOutput bindingOutput,
428
    	for(int i=0;i<operations.size();i++){
496
			boolean isDocumentStyle)
429
    		BindingOperation operation = (BindingOperation) operations.get(i);
497
	{
430
    		validateBindingOperation(operation, isDocumentStyle);
498
		if (bindingOutput == null)
431
    	}
499
			return;
432
    }
500
		List extnElems = bindingOutput.getEExtensibilityElements();
433
    
501
		if (extnElems == null)
434
    private void validateBindingOperation(BindingOperation operation, boolean isDocumentStyle){
502
			return;
435
    	if(operation == null)
503
		for (int i = 0; i < extnElems.size(); i++)
436
    		return;
504
		{
437
    	validateBindingInput(operation.getEBindingInput(), isDocumentStyle);
505
			if (extnElems.get(i) instanceof SOAPBody)
438
    	validateBindingOutput(operation.getEBindingOutput(), isDocumentStyle);
506
			{
439
    }
507
				SOAPBody soapBody = (SOAPBody) extnElems.get(i);
440
    
508
				boolean isLiteral = soapBody.getUse().equals("literal");
441
    private void validateBindingInput(BindingInput bindingInput, boolean isDocumentStyle){
509
				if (!(isDocumentStyle && isLiteral))
442
    	if(bindingInput == null)
510
				{
443
    		return;
511
					IValidationMessage message = ValidationUtils
444
    	List extnElems = bindingInput.getEExtensibilityElements();
512
							.createNewErrorMessage(Messages.NOT_DOC_LITERAL_MESSAGE);
445
    	if(extnElems == null)
513
					_consolidatedReport.addValidationMessage(message);
446
    		return;
514
					return;
447
    	for(int i=0;i<extnElems.size();i++){
515
				}
448
    		if(extnElems.get(i) instanceof SOAPBody)
516
			}
449
    		{
517
		}
450
    			SOAPBody soapBody = (SOAPBody) extnElems.get(i);
518
	}
451
    			boolean isLiteral = soapBody.getUse().equals("literal");
519
452
    			if(!(isDocumentStyle && isLiteral)){
453
    				IValidationMessage message = ValidationUtils.createNewErrorMessage(Messages.NOT_DOC_LITERAL_MESSAGE);
454
    				_consolidatedReport.addValidationMessage(message);
455
    				return;
456
    			}	
457
    		}
458
    	}
459
    }
460
    
461
    private void validateBindingOutput(BindingOutput bindingOutput, boolean isDocumentStyle){
462
    	if(bindingOutput == null)
463
    		return;
464
    	List extnElems = bindingOutput.getEExtensibilityElements();
465
    	if(extnElems == null)
466
    		return;
467
    	for(int i=0;i<extnElems.size();i++){
468
    		if(extnElems.get(i) instanceof SOAPBody)
469
    		{
470
    			SOAPBody soapBody = (SOAPBody) extnElems.get(i);
471
    			boolean isLiteral = soapBody.getUse().equals("literal");
472
    			if(!(isDocumentStyle && isLiteral)){
473
    				IValidationMessage message = ValidationUtils.createNewErrorMessage(Messages.NOT_DOC_LITERAL_MESSAGE);
474
    				_consolidatedReport.addValidationMessage(message);
475
    				return;
476
    			}	
477
    		}
478
    	}
479
    }
480
    
481
}
520
}

Return to bug 161932