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 167588
Collapse All | Expand All

(-)src/org/eclipse/tptp/wsdm/tooling/wizard/mrt/internal/NewMrtWizard.java (-5 / +1 lines)
Lines 315-327 Link Here
315
	 *             Throws exception while getting WSDL files and also while
315
	 *             Throws exception while getting WSDL files and also while
316
	 *             merging them
316
	 *             merging them
317
	 */
317
	 */
318
	public static Document createMergedWSDL(IPath mrtFile, String address)
318
	public static Document createMergedWSDL(ManageableResourceType mrt, String address)
319
			throws Exception
319
			throws Exception
320
	{
320
	{
321
		// Get the MRT file and load it into memory
322
		URI uri = URI.createFileURI(mrtFile.toString());
323
		ManageableResourceType mrt = MrtUtils.loadMRT(uri);
324
325
		checkReadersWriters();
321
		checkReadersWriters();
326
322
327
		List wsdlFiles = null;
323
		List wsdlFiles = null;
(-)src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/Messages.java (+2 lines)
Lines 47-52 Link Here
47
	public static String HOOKUP_WIZARD_ERROR_1;
47
	public static String HOOKUP_WIZARD_ERROR_1;
48
	public static String HOOKUP_WIZARD_ERROR_2;
48
	public static String HOOKUP_WIZARD_ERROR_2;
49
	public static String HOOKUP_WIZARD_ERROR_3;
49
	public static String HOOKUP_WIZARD_ERROR_3;
50
	public static String HOOKUP_WIZARD_PERSIST;
50
	public static String HOOKUP_WIZARD_ERROR_4;
51
	public static String HOOKUP_WIZARD_ERROR_4;
51
	public static String HOOKUP_WIZARD_ERROR_5;
52
	public static String HOOKUP_WIZARD_ERROR_5;
52
	public static String HOOKUP_WIZARD_ERROR_6;
53
	public static String HOOKUP_WIZARD_ERROR_6;
Lines 131-136 Link Here
131
	public static String CODE_GEN_STEP1;
132
	public static String CODE_GEN_STEP1;
132
	public static String CODE_GEN_STEP2;
133
	public static String CODE_GEN_STEP2;
133
	public static String CODE_GEN_STEP3;
134
	public static String CODE_GEN_STEP3;
135
	public static String CODE_GEN_STEP4;
134
	public static String CODE_GEN_FAILED_ERROR;
136
	public static String CODE_GEN_FAILED_ERROR;
135
	public static String CODE_GEN_SUBTASK1;
137
	public static String CODE_GEN_SUBTASK1;
136
	public static String CODE_GEN_SUBTASK2;
138
	public static String CODE_GEN_SUBTASK2;
(-)src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/messages.properties (+2 lines)
Lines 33-38 Link Here
33
HOOKUP_WIZARD_TXT1 = Deployment target and generation options
33
HOOKUP_WIZARD_TXT1 = Deployment target and generation options
34
HOOKUP_WIZARD_TXT2 = This wizard creates code for touchpoint
34
HOOKUP_WIZARD_TXT2 = This wizard creates code for touchpoint
35
HOOKUP_WIZARD_TXT3 = Overwrite files if necessary
35
HOOKUP_WIZARD_TXT3 = Overwrite files if necessary
36
HOOKUP_WIZARD_PERSIST = Persist extra artifacts
36
HOOKUP_WIZARD_TXT4 = Output project
37
HOOKUP_WIZARD_TXT4 = Output project
37
HOOKUP_WIZARD_TXT5 = Browse...
38
HOOKUP_WIZARD_TXT5 = Browse...
38
HOOKUP_WIZARD_TXT6 = Location
39
HOOKUP_WIZARD_TXT6 = Location
Lines 126-131 Link Here
126
CODE_GEN_STEP1 = Initializing Code Generation
127
CODE_GEN_STEP1 = Initializing Code Generation
127
CODE_GEN_STEP2 = Merging WSDL
128
CODE_GEN_STEP2 = Merging WSDL
128
CODE_GEN_STEP3 = Creating project
129
CODE_GEN_STEP3 = Creating project
130
CODE_GEN_STEP4 = Persisting artifacts
129
CODE_GEN_FAILED_ERROR = Code generation failed, see Error Log
131
CODE_GEN_FAILED_ERROR = Code generation failed, see Error Log
130
CODE_GEN_SUBTASK1 = Running Analyzer
132
CODE_GEN_SUBTASK1 = Running Analyzer
131
CODE_GEN_SUBTASK2 = Running Synthesizer
133
CODE_GEN_SUBTASK2 = Running Synthesizer
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MRTCodeGenerationDelegate.java (-172 / +75 lines)
Lines 12-48 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
14
15
import java.util.ArrayList;
15
import java.io.ByteArrayInputStream;
16
import java.io.ByteArrayOutputStream;
17
import java.io.IOException;
16
import java.util.HashMap;
18
import java.util.HashMap;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Map;
19
20
20
import org.apache.ws.muse.descriptor.AdditionalJarsType;
21
import org.apache.ws.muse.descriptor.DescriptorFactory;
21
import org.apache.ws.muse.descriptor.DescriptorFactory;
22
import org.apache.ws.muse.descriptor.DocumentRoot;
22
import org.apache.ws.muse.descriptor.DocumentRoot;
23
import org.apache.ws.muse.descriptor.InitialInstancesType;
24
import org.apache.ws.muse.descriptor.LogLevelType;
25
import org.apache.ws.muse.descriptor.LoggingType;
26
import org.apache.ws.muse.descriptor.MuseType;
27
import org.apache.ws.muse.descriptor.PersistenceType;
28
import org.apache.ws.muse.descriptor.ResourceTypeType;
23
import org.apache.ws.muse.descriptor.ResourceTypeType;
29
import org.apache.ws.muse.descriptor.RootType;
30
import org.apache.ws.muse.descriptor.RouterType;
31
import org.apache.ws.muse.descriptor.WsdlType;
24
import org.apache.ws.muse.descriptor.WsdlType;
32
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IFile;
33
import org.eclipse.core.resources.ResourcesPlugin;
34
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IPath;
35
import org.eclipse.core.runtime.SubProgressMonitor;
27
import org.eclipse.core.runtime.SubProgressMonitor;
36
import org.eclipse.emf.common.util.URI;
28
import org.eclipse.emf.common.util.URI;
37
import org.eclipse.emf.ecore.EObject;
38
import org.eclipse.emf.ecore.resource.Resource;
29
import org.eclipse.emf.ecore.resource.Resource;
39
import org.eclipse.emf.ecore.resource.ResourceSet;
30
import org.eclipse.emf.ecore.resource.ResourceSet;
40
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
31
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
41
import org.eclipse.emf.ecore.xmi.XMLResource;
32
import org.eclipse.emf.ecore.xmi.XMLResource;
42
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
43
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
33
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
44
import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages;
34
import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages;
45
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
46
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
35
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
47
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
36
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
48
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
37
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
Lines 54-64 Link Here
54
 */
43
 */
55
public class MRTCodeGenerationDelegate implements CodeGenerationDelegate
44
public class MRTCodeGenerationDelegate implements CodeGenerationDelegate
56
{
45
{
57
46
	private ManageableResourceType _mrt;
47
	private MrtPreProcessor _mrtPreProcessor;
58
	private String _ddFilePath;
48
	private String _ddFilePath;
59
	private IFile _mrtFile;
49
	private IFile _mrtFile;
60
	private DocumentRoot _root;
50
	private DocumentRoot _ddRoot;
61
51
	
62
	/**
52
	/**
63
	 * Constructor of the class
53
	 * Constructor of the class
64
	 * @param mrtFile
54
	 * @param mrtFile
Lines 66-83 Link Here
66
	public MRTCodeGenerationDelegate(IFile mrtFile)
56
	public MRTCodeGenerationDelegate(IFile mrtFile)
67
	{
57
	{
68
		_mrtFile = mrtFile;
58
		_mrtFile = mrtFile;
69
		_generatedResourceTypes = new ArrayList();
70
		_initialInstancesList = new ArrayList();
71
		_contributedInspectors = new ArrayList();
72
		URI mrtURI = URI.createPlatformResourceURI(mrtFile.getFullPath()
59
		URI mrtURI = URI.createPlatformResourceURI(mrtFile.getFullPath()
73
				.toString());
60
				.toString());
74
		_mrt = MrtUtils.loadMRT(mrtURI);
61
		_mrt = MrtUtils.loadMRT(mrtURI);
62
		_mrtPreProcessor = new MrtPreProcessor(_mrt);
75
	}
63
	}
76
64
77
	/**
65
	/**
78
	 * Creates the DD file. 
66
	 * Creates the DD file. 
79
	 * The method returns a DescriptorHelper which
67
	 * The method returns a DescriptorHelper which
80
	 * aggregates all of the work that was done.
68
	 * aggregates all of the work that was done.
69
	 * 
81
	 * @param progressMonitor 	A progress monitor to 
70
	 * @param progressMonitor 	A progress monitor to 
82
	 * 							show the progress done during this 
71
	 * 							show the progress done during this 
83
	 * 							task. 
72
	 * 							task. 
Lines 86-96 Link Here
86
	public DescriptorHelper run(SubProgressMonitor progressMonitor)
75
	public DescriptorHelper run(SubProgressMonitor progressMonitor)
87
			throws Exception
76
			throws Exception
88
	{
77
	{
89
		IFile ddFile = createDDFile();
78
		byte[] serializedDD = createDD();
90
		return new DescriptorHelper(ddFile);
79
		Map mrtObjectMap = _mrtPreProcessor.getMrtObjectMap();
80
		return new DescriptorHelper(new ByteArrayInputStream(serializedDD), mrtObjectMap);
81
	}
82
	
83
	private byte[] createDD()
84
	{
85
		_mrtPreProcessor.preProcess();
86
		_ddRoot = _mrtPreProcessor.getDDDocumentRoot();
87
		ResourceSet resourceSet = new ResourceSetImpl();
88
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
89
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
90
				new MyDescriptorResourceFactoryImpl());
91
		URI uri = URI.createURI("dummy.xml");
92
		Resource resource = resourceSet.createResource(uri);
93
		resource.getContents().add(_ddRoot);
94
		Map map = new HashMap();
95
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
96
		try 
97
		{
98
			resource.save(baos, map);
99
		} 
100
		catch (IOException e) 
101
		{
102
			e.printStackTrace();
103
		}
104
		return baos.toByteArray();
105
	}
106
	
107
	private String createDDFilePath()
108
	{
109
		IPath ddIPath = _mrtFile.getFullPath().removeFileExtension()
110
				.addFileExtension("dd");
111
		return ddIPath.toString();
91
	}
112
	}
92
113
93
	private IFile createDDFile()
114
	/**
115
	 * Create and return a new instance of given ResourceTypeType. Only
116
	 * ContextPath, JavaIdFactoryClass, JavaResourceClass and WsdlType fields
117
	 * have been copied.
118
	 */
119
	public static ResourceTypeType cloneResourceType(ResourceTypeType rt)
120
	{
121
		ResourceTypeType clone = DescriptorFactory.eINSTANCE
122
				.createResourceTypeType();
123
		clone.setContextPath(rt.getContextPath());
124
		clone.setJavaIdFactoryClass(rt.getJavaIdFactoryClass());
125
		clone.setJavaResourceClass(rt.getJavaResourceClass());
126
		WsdlType wClone = DescriptorFactory.eINSTANCE.createWsdlType();
127
		wClone.setWsdlFile(rt.getWsdl().getWsdlFile());
128
		wClone.setWsdlPortType(rt.getWsdl().getWsdlPortType());
129
		clone.setWsdl(wClone);
130
		return clone;
131
	}
132
133
	/**
134
	 * This method will persist the extra artifacts generated at codegen time.
135
	 */
136
	public void persistArtifacts() 
137
	{
138
		_mrtPreProcessor.persistArtifacts();
139
		persistDDFile();		
140
	}
141
	
142
	private void persistDDFile()
94
	{
143
	{
95
		_ddFilePath = createDDFilePath();
144
		_ddFilePath = createDDFilePath();
96
145
Lines 115-124 Link Here
115
		//
164
		//
116
		// Add the initial model object to the contents.
165
		// Add the initial model object to the contents.
117
		//
166
		//
118
		EObject rootObject = createInitialModel();
167
		if (_ddRoot != null)
119
		if (rootObject != null)
120
		{
168
		{
121
			resource.getContents().add(rootObject);
169
			resource.getContents().add(_ddRoot);
122
		}
170
		}
123
171
124
		//
172
		//
Lines 128-139 Link Here
128
		options.put(XMLResource.OPTION_ENCODING, "UTF-8");
176
		options.put(XMLResource.OPTION_ENCODING, "UTF-8");
129
		try
177
		try
130
		{
178
		{
131
			resource.save(options);
179
			resource.save(options);		
132
133
			IFile file = EclipseUtils.getIFile(ResourcesPlugin.getWorkspace()
134
					.getRoot(), fileURI.toString());
135
			//return file.getLocation().toFile();
136
			return file;
137
		}
180
		}
138
		catch (Exception exception)
181
		catch (Exception exception)
139
		{
182
		{
Lines 142-286 Link Here
142
					Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_,
185
					Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_,
143
					exception);
186
					exception);
144
		}
187
		}
145
146
		return null;
147
	}
148
149
	private String createDDFilePath()
150
	{
151
		IPath ddIPath = _mrtFile.getFullPath().removeFileExtension()
152
				.addFileExtension("dd");
153
		return ddIPath.toString();
154
	}
155
156
	protected EObject createInitialModel()
157
	{
158
		_root = DescriptorFactory.eINSTANCE.createDocumentRoot();
159
		RootType _rootType = DescriptorFactory.eINSTANCE.createRootType();
160
		MuseType _muse = DescriptorFactory.eINSTANCE.createMuseType();
161
		AdditionalJarsType jars = DescriptorFactory.eINSTANCE
162
				.createAdditionalJarsType();
163
		_rootType.setMuse(_muse);
164
		_rootType.setAdditionalJars(jars);
165
		_root.setRoot(_rootType);
166
167
		// Add the router to muse descriptor
168
		RouterType router = createRouterType();
169
		_muse.setRouter(router);
170
171
		ResourceTypeType[] resourceTypes = process();
172
		for (int i = 0; i < resourceTypes.length; i++)
173
			_muse.getResourceType().add(resourceTypes[i]);
174
175
		// Create initial instances
176
		InitialInstancesType[] instances = getInitialInstances();
177
		for (int i = 0; i < instances.length; i++)
178
			_rootType.getInitialInstances().add(instances[i]);
179
180
		return _root;
181
	}
182
183
	private RouterType createRouterType()
184
	{
185
		RouterType router = DescriptorFactory.eINSTANCE.createRouterType();
186
		router
187
				.setJavaRouterClass("org.apache.muse.core.routing.SimpleResourceRouter");
188
		LoggingType logging = DescriptorFactory.eINSTANCE.createLoggingType();
189
		logging.setLogFile("/log/muse.log");
190
		logging.setLogLevel(LogLevelType.OFF_LITERAL);
191
		router.setLogging(logging);
192
		PersistenceType persistence = DescriptorFactory.eINSTANCE
193
				.createPersistenceType();
194
		persistence
195
				.setJavaPersistenceClass("org.apache.muse.core.routing.RouterFilePersistence");
196
		persistence.setPersistenceLocation("router-entries");
197
		router.setPersistence(persistence);
198
		return router;
199
	}
200
201
	private ManageableResourceType _mrt;
202
203
	private List _generatedResourceTypes;
204
205
	private List _initialInstancesList;
206
207
	private List _contributedInspectors;
208
209
	/**
210
	 * This method processes the given manageable resource type to check whether
211
	 * we need any extra resource type in muse descriptor file such as
212
	 * Subscription manager etc. It will returns all the proper ResourceTypeType
213
	 * objects. So it will return atleast one ResourceTypeType object that
214
	 * represents the given manageable resource type.
215
	 */
216
	public ResourceTypeType[] process()
217
	{
218
		Capability[] mrtCapabilities = new Capability[0];
219
		try
220
		{
221
			mrtCapabilities = MrtUtils.getCapabilities(_mrt);
222
		}
223
		catch (Exception e)
224
		{
225
		}
226
		// Analyze the given manageable resource type for Subscription manager
227
		// etc.
228
		// If needed add the extra resource type for Subscription manager
229
		List inspectors = getAllMrtInspectors();
230
		for (int i = 0; i < inspectors.size(); i++)
231
		{
232
			MrtInspector inspector = (MrtInspector) inspectors.get(i);
233
			inspector.setMrtParentDirectory(_mrtFile.getParent().getFullPath()
234
					.toString());
235
			ResourceTypeType resourceType = inspector.inspect(mrtCapabilities);
236
			if (resourceType != null)
237
			{
238
				_generatedResourceTypes.add(resourceType);
239
				InitialInstancesType[] instances = inspector
240
						.getInitialInstances();
241
				for (int j = 0; j < instances.length; j++)
242
					_initialInstancesList.add(instances[j]);
243
				_contributedInspectors.add(inspector);
244
			}
245
		}
246
		return (ResourceTypeType[]) _generatedResourceTypes
247
				.toArray(new ResourceTypeType[_generatedResourceTypes.size()]);
248
	}
249
250
	private List getAllMrtInspectors()
251
	{
252
		List inspectors = new ArrayList();
253
		inspectors.add(new BasicMrtInspector(_mrtFile, _mrt, _root));
254
		inspectors.add(new SubscriptionManagerInspector(_root));
255
		return inspectors;
256
	}
257
258
	/**
259
	 * Create and return a new instance of given ResourceTypeType. Only
260
	 * ContextPath, JavaIdFactoryClass, JavaResourceClass and WsdlType fields
261
	 * have been copied.
262
	 */
263
	public static ResourceTypeType cloneResourceType(ResourceTypeType rt)
264
	{
265
		ResourceTypeType clone = DescriptorFactory.eINSTANCE
266
				.createResourceTypeType();
267
		clone.setContextPath(rt.getContextPath());
268
		clone.setJavaIdFactoryClass(rt.getJavaIdFactoryClass());
269
		clone.setJavaResourceClass(rt.getJavaResourceClass());
270
		WsdlType wClone = DescriptorFactory.eINSTANCE.createWsdlType();
271
		wClone.setWsdlFile(rt.getWsdl().getWsdlFile());
272
		wClone.setWsdlPortType(rt.getWsdl().getWsdlPortType());
273
		clone.setWsdl(wClone);
274
		return clone;
275
	}
276
277
	/**
278
	 * Returns the initial instances
279
	 * @return IntialInstancesType[]
280
	 */
281
	public InitialInstancesType[] getInitialInstances()
282
	{
283
		return (InitialInstancesType[]) _initialInstancesList
284
				.toArray(new InitialInstancesType[_initialInstancesList.size()]);
285
	}
188
	}
286
}
189
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/SubscriptionManagerInspector.java (-127 / +73 lines)
Lines 13-27 Link Here
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
14
15
import java.io.ByteArrayInputStream;
15
import java.io.ByteArrayInputStream;
16
import java.io.File;
17
import java.io.IOException;
16
import java.io.IOException;
18
import java.io.InputStream;
17
import java.io.InputStream;
19
18
20
import javax.wsdl.Operation;
19
import javax.wsdl.Operation;
21
import javax.xml.namespace.QName;
22
20
23
import org.apache.muse.tools.Activator;
24
import org.apache.muse.util.xml.XmlUtils;
25
import org.apache.ws.muse.descriptor.CapabilityType;
21
import org.apache.ws.muse.descriptor.CapabilityType;
26
import org.apache.ws.muse.descriptor.DescriptorFactory;
22
import org.apache.ws.muse.descriptor.DescriptorFactory;
27
import org.apache.ws.muse.descriptor.DocumentRoot;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
Lines 33-39 Link Here
33
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.resources.IFile;
34
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.NullProgressMonitor;
31
import org.eclipse.core.runtime.NullProgressMonitor;
36
import org.eclipse.core.runtime.Path;
37
import org.eclipse.emf.common.util.URI;
32
import org.eclipse.emf.common.util.URI;
38
import org.eclipse.emf.ecore.resource.ResourceSet;
33
import org.eclipse.emf.ecore.resource.ResourceSet;
39
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
34
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
Lines 43-53 Link Here
43
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
38
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
44
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
45
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
40
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils;
46
import org.osgi.framework.Bundle;
47
import org.w3c.dom.Attr;
48
import org.w3c.dom.Document;
49
import org.w3c.dom.Element;
50
import org.xml.sax.SAXException;
51
41
52
/**
42
/**
53
 * This class analyzes the given manageable resource type and provide an extra
43
 * This class analyzes the given manageable resource type and provide an extra
Lines 61-69 Link Here
61
51
62
	private DocumentRoot _root;
52
	private DocumentRoot _root;
63
53
64
	private static String WSDL_FILE_PATH = "artifacts/resourceTypes/SubscriptionManager.wsdl";
65
66
	private ResourceTypeType _subManagerResourceType;
54
	private ResourceTypeType _subManagerResourceType;
55
	
56
	private ManageableResourceType _subManagerMRT;
67
	/**
57
	/**
68
	 * Constructor of the class
58
	 * Constructor of the class
69
	 * @param root
59
	 * @param root
Lines 73-87 Link Here
73
		_root = root;
63
		_root = root;
74
	}
64
	}
75
65
76
	private String getModelSmashedWSDLLocation()
77
	{
78
		Bundle modelPlugin = Activator.getDefault().getBundle();
79
		Path wsdlFilePath = new Path(WSDL_FILE_PATH);
80
		String filePath = EclipseUtils.getResolvedPath(modelPlugin,
81
				wsdlFilePath);
82
		return filePath;
83
	}
84
85
	/**
66
	/**
86
	 * Analyzes the given manageable resource type for NotificationProducer
67
	 * Analyzes the given manageable resource type for NotificationProducer
87
	 * capability, and if the capability available then returns the muse
68
	 * capability, and if the capability available then returns the muse
Lines 100-195 Link Here
100
	private ResourceTypeType createSubscriptionManagerResourceType()
81
	private ResourceTypeType createSubscriptionManagerResourceType()
101
	{
82
	{
102
		createSubManagerMrt();
83
		createSubManagerMrt();
103
104
		/*
105
		 * try { copySubManagerMergedWSDL(); } catch (IOException e) { // TODO
106
		 * Log e.printStackTrace(); }
107
		 */
108
109
		_subManagerResourceType = createSubManagerMuseResourceType();
84
		_subManagerResourceType = createSubManagerMuseResourceType();
110
		return _subManagerResourceType;
85
		return _subManagerResourceType;
111
	}
86
	}
112
87
113
	private void createSubManagerMrt()
88
	private void createSubManagerMrt()
114
	{
89
	{
115
		ManageableResourceType mrt = ManageableResourceTypeFactory.eINSTANCE
90
		_subManagerMRT = ManageableResourceTypeFactory.eINSTANCE
116
				.createManageableResourceType();
91
				.createManageableResourceType();
117
		mrt.setIdentifier("SubscriptionManager");
92
		_subManagerMRT.setIdentifier("SubscriptionManager");
118
		mrt
93
		_subManagerMRT
119
				.setNamespace("http://docs.oasis-open.org/wsn/b-2/SubscriptionManager");
94
				.setNamespace("http://docs.oasis-open.org/wsn/b-2/SubscriptionManager");
120
		mrt
95
		_subManagerMRT
121
				.getImplements()
96
				.getImplements()
122
				.add(
97
				.add(
123
						"platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/Identity.wsdl");
98
						"platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/Identity.wsdl");
124
		mrt
99
		_subManagerMRT
125
				.getImplements()
100
				.getImplements()
126
				.add(
101
				.add(
127
						"platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/ManageabilityCharacteristics.wsdl");
102
						"platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/ManageabilityCharacteristics.wsdl");
128
		mrt
103
		_subManagerMRT
129
				.getImplements()
104
				.getImplements()
130
				.add(
105
				.add(
131
						"platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/MetadataExchange.wsdl");
106
						"platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/MetadataExchange.wsdl");
132
		mrt
107
		_subManagerMRT
133
				.getImplements()
108
				.getImplements()
134
				.add(
109
				.add(
135
						"platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/GetProperty.wsdl");
110
						"platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/GetProperty.wsdl");
136
		mrt
111
		_subManagerMRT
137
				.getImplements()
112
				.getImplements()
138
				.add(
113
				.add(
139
						"platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/SetProperty.wsdl");
114
						"platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/SetProperty.wsdl");
140
		mrt
115
		_subManagerMRT
141
				.getImplements()
116
				.getImplements()
142
				.add(
117
				.add(
143
						"platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/QueryProperty.wsdl");
118
						"platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/QueryProperty.wsdl");
144
		mrt
119
		_subManagerMRT
145
				.getImplements()
120
				.getImplements()
146
				.add(
121
				.add(
147
						"platform:/plugin/org.apache.muse.tools/artifacts/resourceLifetimeCapabilities/ImmediateResourceTermination.wsdl");
122
						"platform:/plugin/org.apache.muse.tools/artifacts/resourceLifetimeCapabilities/ImmediateResourceTermination.wsdl");
148
		mrt
123
		_subManagerMRT
149
				.getImplements()
124
				.getImplements()
150
				.add(
125
				.add(
151
						"platform:/plugin/org.apache.muse.tools/artifacts/resourceLifetimeCapabilities/ScheduledResourceTermination.wsdl");
126
						"platform:/plugin/org.apache.muse.tools/artifacts/resourceLifetimeCapabilities/ScheduledResourceTermination.wsdl");
152
127
153
		mrt
128
		_subManagerMRT
154
				.getImplements()
129
				.getImplements()
155
				.add(
130
				.add(
156
						"platform:/plugin/org.apache.muse.tools/artifacts/resourceTypes/SubscriptionManagerCapability.wsdl");
131
						"platform:/plugin/org.apache.muse.tools/artifacts/resourceTypes/SubscriptionManagerCapability.wsdl");		
157
158
		ResourceSet rs = new ResourceSetImpl();
159
		byte[] rawNewMRT = MrtUtils.serializeMRT(mrt, rs, URI
160
				.createURI("dummy.xml"), true);
161
		InputStream stream = new ByteArrayInputStream(rawNewMRT);
162
163
		try
164
		{
165
			String subManagerMrt = _mrtParentDirName + "/"
166
					+ "SubscriptionManager.mrt";
167
			IFile subManagerMrtFile = EclipseUtils.getIFile(subManagerMrt);
168
			if (subManagerMrtFile.exists())
169
			{
170
				subManagerMrtFile.setContents(stream, true, true,
171
						new NullProgressMonitor());
172
			}
173
			else
174
			{
175
				subManagerMrtFile.create(stream, true,
176
						new NullProgressMonitor());
177
			}
178
			try
179
			{
180
				stream.close();
181
			}
182
			catch (IOException e)
183
			{
184
				// TODO Log
185
				e.printStackTrace();
186
			}
187
		}
188
		catch (CoreException e)
189
		{
190
			// TODO Log
191
			e.printStackTrace();
192
		}
193
	}
132
	}
194
133
195
	private ResourceTypeType createSubManagerMuseResourceType()
134
	private ResourceTypeType createSubManagerMuseResourceType()
Lines 303-359 Link Here
303
	}
242
	}
304
243
305
	/**
244
	/**
306
	 * Returns the merged wsdl file document for SubscriptionManager.
307
	 */
308
	public Document[] getWsdlDocuments(String baseAddress)
309
	{
310
		String mergedSubManagerWsdl = getModelSmashedWSDLLocation();
311
312
		Document document = null;
313
		try
314
		{
315
			// document = XmlUtils.createDocument(new
316
			// File(_mergedWsdlFilePath));
317
			document = XmlUtils.createDocument(new File(mergedSubManagerWsdl));
318
			makeServiceAddress(document, baseAddress);
319
		}
320
		catch (IOException e)
321
		{
322
			e.printStackTrace();
323
		}
324
		catch (SAXException e)
325
		{
326
			e.printStackTrace();
327
		}
328
		return new Document[] { document };
329
	}
330
331
	private void makeServiceAddress(Document mergedWsdl, String basePath)
332
	{
333
		Element serviceElement = XmlUtils.findFirstInSubTree(mergedWsdl
334
				.getDocumentElement(), new QName(WSDL_NAMESPACE, "service"));
335
		if (serviceElement == null) // Can't find the service element in smashed
336
			// wsdl
337
			return;
338
		Element portInServiceElement = XmlUtils.findFirstInSubTree(
339
				serviceElement, new QName(WSDL_NAMESPACE, "port"));
340
		if (portInServiceElement == null) // Can't find the port element
341
			// inside service element
342
			return;
343
		Element addressElement = XmlUtils.findFirstInSubTree(
344
				portInServiceElement, new QName(
345
						"http://schemas.xmlsoap.org/wsdl/soap/", "address"));
346
		if (addressElement == null) // Can't find address element inside port
347
			// element
348
			return;
349
		Attr locationAttr = addressElement.getAttributeNode("location");
350
		if (locationAttr == null || locationAttr.getNodeValue().equals(""))
351
			return;
352
		int beginIndex = locationAttr.getNodeValue().lastIndexOf('/') + 1;
353
		String serviceName = locationAttr.getNodeValue().substring(beginIndex);
354
		locationAttr.setNodeValue(basePath + "/" + serviceName);
355
	}
356
	/**
357
	 * Sets the parent directory 
245
	 * Sets the parent directory 
358
	 * @param mrtParentDir
246
	 * @param mrtParentDir
359
	 */
247
	 */
Lines 377-380 Link Here
377
		instance.setReferenceParameters(refParam);
265
		instance.setReferenceParameters(refParam);
378
		return new InitialInstancesType[] { instance };
266
		return new InitialInstancesType[] { instance };
379
	}
267
	}
268
269
	/**
270
	 * This method will persist the extra artifacts generated at codegen time (SubscriptionManager.mrt file).
271
	 */
272
	public void persistArtifacts()
273
	{
274
		ResourceSet rs = new ResourceSetImpl();
275
		byte[] rawNewMRT = MrtUtils.serializeMRT(_subManagerMRT, rs, URI
276
				.createURI("dummy.xml"), true);
277
		InputStream stream = new ByteArrayInputStream(rawNewMRT);
278
279
		try
280
		{
281
			String subManagerMrt = _mrtParentDirName + "/"
282
					+ "SubscriptionManager.mrt";
283
			IFile subManagerMrtFile = EclipseUtils.getIFile(subManagerMrt);
284
			if (subManagerMrtFile.exists())
285
			{
286
				subManagerMrtFile.setContents(stream, true, true,
287
						new NullProgressMonitor());
288
			}
289
			else
290
			{
291
				subManagerMrtFile.create(stream, true,
292
						new NullProgressMonitor());
293
			}
294
			try
295
			{
296
				stream.close();
297
			}
298
			catch (IOException e)
299
			{
300
				// TODO Log
301
				e.printStackTrace();
302
			}
303
		}
304
		catch (CoreException e)
305
		{
306
			// TODO Log
307
			e.printStackTrace();
308
		}
309
	}
310
311
	/**
312
	 * This method will returns the extra generated ManageableResourceType object equivalent to SubscriptionManager.
313
	 */
314
	public ManageableResourceType getExtraGeneratedMrt() 
315
	{
316
		return _subManagerMRT;
317
	}
318
319
	/**
320
	 * This method should return the persistance location for extra generated ManageableResourceType object equivalent to SubscriptionManager.
321
	 */
322
	public String getExtraGeneratedMrtPersistanceLocation() 
323
	{
324
		return _mrtParentDirName+"/SubscriptionManager.mrt";
325
	}
380
}
326
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/DescriptorHelper.java (-62 / +64 lines)
Lines 13-40 Link Here
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
14
15
import java.io.File;
15
import java.io.File;
16
import java.io.IOException;
16
import java.io.FileInputStream;
17
import java.util.Collections;
17
import java.io.InputStream;
18
import java.util.Arrays;
19
import java.util.HashMap;
20
import java.util.LinkedList;
21
import java.util.List;
22
import java.util.Map;
23
18
import javax.xml.namespace.QName;
24
import javax.xml.namespace.QName;
19
25
20
import org.apache.muse.core.descriptor.DescriptorConstants;
26
import org.apache.muse.core.descriptor.DescriptorConstants;
21
import org.apache.muse.util.xml.XmlUtils;
27
import org.apache.muse.util.xml.XmlUtils;
22
import org.apache.ws.muse.descriptor.AdditionalJarsType;
23
import org.apache.ws.muse.descriptor.DescriptorPackage;
24
import org.apache.ws.muse.descriptor.DocumentRoot;
25
import org.apache.ws.muse.descriptor.RootType;
26
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IWorkspace;
29
import org.eclipse.core.resources.IWorkspace;
28
import org.eclipse.core.resources.IWorkspaceRoot;
30
import org.eclipse.core.resources.IWorkspaceRoot;
29
import org.eclipse.core.resources.ResourcesPlugin;
31
import org.eclipse.core.resources.ResourcesPlugin;
30
import org.eclipse.core.runtime.IPath;
32
import org.eclipse.core.runtime.IPath;
31
import org.eclipse.emf.common.util.URI;
33
import org.eclipse.emf.common.util.URI;
32
import org.eclipse.emf.ecore.resource.Resource;
34
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
33
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
35
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
34
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
35
import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages;
36
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
37
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
38
import org.eclipse.tptp.wsdm.tooling.wizard.mrt.internal.NewMrtWizard;
36
import org.eclipse.tptp.wsdm.tooling.wizard.mrt.internal.NewMrtWizard;
39
import org.w3c.dom.Document;
37
import org.w3c.dom.Document;
40
import org.w3c.dom.Element;
38
import org.w3c.dom.Element;
Lines 101-106 Link Here
101
	private Object[][] _instances;
99
	private Object[][] _instances;
102
	
100
	
103
	private IFile ddIFile;
101
	private IFile ddIFile;
102
	
103
	/**
104
	 * Descriptor file stores the MRT file reference in Wsdl-File element.
105
	 * When we do the codegeneration we generate some extra MRTs such as SubscriptionManager,
106
	 * so we pass the map of these MRTs to this class.
107
	 * Key will be the persisted location of MRT and value will be the ManageableREsourceType object.
108
	 */
109
	private Map _mrtObjectMap = new HashMap();
104
110
105
	/**
111
	/**
106
	 * A do-something constructor. Take a file, if that file is null, then load
112
	 * A do-something constructor. Take a file, if that file is null, then load
Lines 130-136 Link Here
130
	 */
136
	 */
131
	public DescriptorHelper(File file) throws Exception
137
	public DescriptorHelper(File file) throws Exception
132
	{
138
	{
133
		Document rootDocument = XmlUtils.createDocument(file);
139
		this(new FileInputStream(file), null);
140
	}
141
	
142
	/**
143
	 * A do-something constructor. Take a inputstream, if that inputstream is null, then load
144
	 * up a default template. Otherwise load up the inputstream and pull out the
145
	 * instances, descriptor and additional jars. For the null inputstream case, there
146
	 * will be no instances of additional-jars, hence the constants defined
147
	 * above.
148
	 * 
149
	 * @param inputstream - The inputstream to analyze, can be null.
150
	 * @param mrtObjectMap - The map of MRTLocation-MRTObject pair, can be null.
151
	 * @throws Exception - If anything goes wrong.
152
	 */
153
	public DescriptorHelper(InputStream inputStream, Map mrtObjectMap) throws Exception
154
	{
155
		if(mrtObjectMap!=null)
156
			_mrtObjectMap = mrtObjectMap;
157
		
158
		Document rootDocument = XmlUtils.createDocument(inputStream);
134
159
135
		_descriptorDocument = extractDescriptorDocument(rootDocument);
160
		_descriptorDocument = extractDescriptorDocument(rootDocument);
136
		_instances = extractInstances(rootDocument);
161
		_instances = extractInstances(rootDocument);
Lines 303-308 Link Here
303
	 * find all of the MRT files referenced therein. For each MRT file use
328
	 * find all of the MRT files referenced therein. For each MRT file use
304
	 * <code>WsdlMerge</code> to merge the MRT's WSDL into a consolidate WSDL.
329
	 * <code>WsdlMerge</code> to merge the MRT's WSDL into a consolidate WSDL.
305
	 * Return the Muse Descriptor document-order list of the WSDL files.
330
	 * Return the Muse Descriptor document-order list of the WSDL files.
331
	 * The passed map will contain the MRT file location as key and MRT object as value.
332
	 * So first search the map for MRT if not found then load the MRT from location.
306
	 * 
333
	 * 
307
	 * @return A list of merged WSDL files as gathered from the deployment
334
	 * @return A list of merged WSDL files as gathered from the deployment
308
	 *         descriptor
335
	 *         descriptor
Lines 322-339 Link Here
322
					resourceTypes[i], DescriptorConstants.WSDL_FILE_QNAME);
349
					resourceTypes[i], DescriptorConstants.WSDL_FILE_QNAME);
323
350
324
			String wsdlPath = XmlUtils.extractText(wsdlFileElement);
351
			String wsdlPath = XmlUtils.extractText(wsdlFileElement);
325
352
			String mrtPath = getMRTPathFromWSDLPath(wsdlPath);
326
			IWorkspace workspace = ResourcesPlugin.getWorkspace();
353
			ManageableResourceType mrt = null;
327
			IWorkspaceRoot root = workspace.getRoot();
354
			String serviceAddress = null;
328
			IPath mrtFilePath = root.findMember(
355
			if(_mrtObjectMap!=null && _mrtObjectMap.containsKey(mrtPath))
329
					getMRTPathFromWSDLPath(wsdlPath)).getFullPath();
356
			{
330
357
				mrt = (ManageableResourceType) _mrtObjectMap.get(mrtPath);
331
			if (mrtFilePath != null)
358
				serviceAddress = baseAddress+"/"+mrt.getIdentifier();
359
			}
360
			else
361
			{
362
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
363
				IWorkspaceRoot root = workspace.getRoot();
364
				IPath mrtFilePath = root.findMember(mrtPath).getFullPath();
365
				URI uri = URI.createFileURI(mrtFilePath.toString());
366
				mrt = MrtUtils.loadMRT(uri);
367
				serviceAddress = makeServiceAddress(baseAddress, mrtFilePath);
368
			}
369
			if(mrt!=null)
332
			{
370
			{
333
				try
371
				try
334
				{
372
				{
335
					mergedWSDLs[i] = NewMrtWizard.createMergedWSDL(mrtFilePath,
373
					mergedWSDLs[i] = NewMrtWizard.createMergedWSDL(mrt, serviceAddress);
336
							makeServiceAddress(baseAddress, mrtFilePath));
337
				}
374
				}
338
				catch (Exception e)
375
				catch (Exception e)
339
				{
376
				{
Lines 347-353 Link Here
347
				throw new RuntimeException();
384
				throw new RuntimeException();
348
			}
385
			}
349
		}
386
		}
350
351
		return mergedWSDLs;
387
		return mergedWSDLs;
352
	}
388
	}
353
389
Lines 384-428 Link Here
384
	 */
420
	 */
385
	public void addAdditionalJars(String serverLocation, String[] axis2files)
421
	public void addAdditionalJars(String serverLocation, String[] axis2files)
386
	{
422
	{
387
		DocumentRoot root = DdeUtil.getDocRoot(ddIFile);
423
		List additionalJarFiles = new LinkedList();
388
		RootType rootType = root.getRoot();
424
		if(_jarFiles!=null)
389
		AdditionalJarsType additionalJars = rootType.getAdditionalJars();
425
			additionalJarFiles.addAll(Arrays.asList(_jarFiles));
390
		for(int i = 0 ; i < axis2files.length ; i++ )
426
		for(int i = 0 ; i < axis2files.length ; i++ )
391
			additionalJars.getJarPath().add(serverLocation + File.separator + axis2files[i]);
427
			additionalJarFiles.add(new File(serverLocation + File.separator + axis2files[i]));
392
		rootType.setAdditionalJars(additionalJars);
428
		_jarFiles = (File[]) additionalJarFiles.toArray(new File[additionalJarFiles.size()]);
393
		root.setRoot(rootType);
394
		save(root);
395
	}
396
	
397
	private void save(DocumentRoot root)
398
	{
399
		ensureMusePackagePresent();
400
		URI ddFileURI = URI.createPlatformResourceURI(ddIFile.getFullPath().toString());
401
		ResourceSetImpl rsImpl = new ResourceSetImpl();
402
		rsImpl.getResourceFactoryRegistry().getExtensionToFactoryMap()
403
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
404
				new MyDescriptorResourceFactoryImpl());
405
		rsImpl.getPackageRegistry().put(DescriptorPackage.eNS_URI,
406
		DescriptorPackage.eINSTANCE);
407
		Resource ddRes = rsImpl.getResource(ddFileURI, true);
408
		ddRes.getContents().remove(0);
409
		ddRes.getContents().add(root);
410
		try 
411
		{
412
			ddRes.save(Collections.EMPTY_MAP);
413
		} 
414
		catch (IOException e) 
415
		{
416
			e.printStackTrace();
417
		}
418
	}
419
	
420
	private void ensureMusePackagePresent()
421
	{
422
		// Ensure EMF knows about Muse descriptor
423
		if (DescriptorPackage.eINSTANCE == null)
424
		{
425
			WsdmToolingLog.logError(Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_, new Throwable());
426
		}
427
	} 	
429
	} 	
428
}
430
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/GenerationOptionsPage.java (+9 lines)
Lines 112-117 Link Here
112
112
113
	private boolean axis2Project;
113
	private boolean axis2Project;
114
	
114
	
115
	private Button _persistExtraArtifactsButton;
116
	
115
	/**
117
	/**
116
	 * For cheatsheet purpose only This constructor will be used in cheatsheet
118
	 * For cheatsheet purpose only This constructor will be used in cheatsheet
117
	 * only
119
	 * only
Lines 174-179 Link Here
174
176
175
		_buttonOverwrite = makeButton(column, Messages.HOOKUP_WIZARD_TXT3,
177
		_buttonOverwrite = makeButton(column, Messages.HOOKUP_WIZARD_TXT3,
176
				SWT.CHECK);
178
				SWT.CHECK);
179
		
180
		_persistExtraArtifactsButton = makeButton(column, Messages.HOOKUP_WIZARD_PERSIST, SWT.CHECK);
177
	}
181
	}
178
182
179
	private Group createProjectizerGroup(Composite parent)
183
	private Group createProjectizerGroup(Composite parent)
Lines 659-664 Link Here
659
	{
663
	{
660
		return _buttonOverwrite.getSelection();
664
		return _buttonOverwrite.getSelection();
661
	}
665
	}
666
	
667
	public boolean shouldPersistArtifacts()
668
	{
669
		return _persistExtraArtifactsButton.getSelection();
670
	}
662
671
663
	/**
672
	/**
664
	 * Return the value of the output project
673
	 * Return the value of the output project
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/NewProjectWizard.java (-1 / +9 lines)
Lines 63-68 Link Here
63
	private String _projectName;
63
	private String _projectName;
64
64
65
	private boolean _overwrite;
65
	private boolean _overwrite;
66
	
67
	private boolean _shouldPersistArtifacts;
66
68
67
	private Projectizer _projectizer;
69
	private Projectizer _projectizer;
68
70
Lines 118-124 Link Here
118
	{
120
	{
119
		try
121
		try
120
		{
122
		{
121
			monitor.beginTask(Messages.CODE_GEN_START, 6);
123
			monitor.beginTask(Messages.CODE_GEN_START, 7);
122
					
124
					
123
			if(_isAxis2Project)
125
			if(_isAxis2Project)
124
			{
126
			{
Lines 179-184 Link Here
179
				throw new InvocationTargetException(new Exception(
181
				throw new InvocationTargetException(new Exception(
180
						Messages.CODE_GEN_FAILED_ERROR, e));
182
						Messages.CODE_GEN_FAILED_ERROR, e));
181
			}
183
			}
184
			
185
			monitor.subTask(Messages.CODE_GEN_STEP4);
186
			if(_shouldPersistArtifacts)
187
				_codeGenerationDelegate.persistArtifacts();
188
			monitor.worked(1);
182
		}
189
		}
183
		finally
190
		finally
184
		{
191
		{
Lines 197-202 Link Here
197
		_synthesizer = _generationOptionsPage.getSynthesizer();
204
		_synthesizer = _generationOptionsPage.getSynthesizer();
198
		_analyzer = _generationOptionsPage.getAnalyzer();
205
		_analyzer = _generationOptionsPage.getAnalyzer();
199
		_overwrite = _generationOptionsPage.isOverwrite();
206
		_overwrite = _generationOptionsPage.isOverwrite();
207
		_shouldPersistArtifacts = _generationOptionsPage.shouldPersistArtifacts();
200
		_projectName = _generationOptionsPage.getProjectName();
208
		_projectName = _generationOptionsPage.getProjectName();
201
		_baseAddress = _generationOptionsPage.getBaseAddress();
209
		_baseAddress = _generationOptionsPage.getBaseAddress();
202
		_isAxis2Project = _generationOptionsPage.isAxis2Project();
210
		_isAxis2Project = _generationOptionsPage.isAxis2Project();
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtInspector.java (+26 lines)
Lines 15-20 Link Here
15
import org.apache.ws.muse.descriptor.InitialInstancesType;
15
import org.apache.ws.muse.descriptor.InitialInstancesType;
16
import org.apache.ws.muse.descriptor.ResourceTypeType;
16
import org.apache.ws.muse.descriptor.ResourceTypeType;
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.manageableResourceType.ManageableResourceType;
18
19
19
/**
20
/**
20
 * This interface is created for some cases where we expect some extra resource
21
 * This interface is created for some cases where we expect some extra resource
Lines 28-36 Link Here
28
{
29
{
29
	public static String WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";
30
	public static String WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";
30
31
32
	/**
33
	 * Analyzes the given manageable resource type capabilities and then returns the muse
34
	 * resource type for some extra generated artifact else returns the null.
35
	 */
31
	ResourceTypeType inspect(Capability[] mrtCapabilities);
36
	ResourceTypeType inspect(Capability[] mrtCapabilities);
32
37
38
	/**
39
	 * This method should set the parent directory for extra generated artifact. 
40
	 */
33
	void setMrtParentDirectory(String mrtParentDir);
41
	void setMrtParentDirectory(String mrtParentDir);
34
42
43
	/**
44
	 * Returns initial instances for extra generated artifact. 
45
	 */
35
	InitialInstancesType[] getInitialInstances();
46
	InitialInstancesType[] getInitialInstances();
47
	
48
	/**
49
	 * This method will persist the extra artifacts generated at codegen time.
50
	 */
51
	void persistArtifacts();
52
	
53
	/**
54
	 * This method will returns the extra ManageableResourceType object generated at codegen time.
55
	 */
56
	ManageableResourceType getExtraGeneratedMrt();
57
	
58
	/**
59
	 * This method should return the persistance location for extra generated ManageableResourceType object.
60
	 */
61
	String getExtraGeneratedMrtPersistanceLocation();
36
}
62
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/CodeGenerationDelegate.java (+5 lines)
Lines 35-38 Link Here
35
	 * @throws Exception
35
	 * @throws Exception
36
	 */
36
	 */
37
	DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception;
37
	DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception;
38
	
39
	/**
40
	 * Persist the extra artifacts generated during codegeneration such as SubscriptionManager.mrt etc.
41
	 */
42
	void persistArtifacts();
38
}
43
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/BasicMrtInspector.java (+14 lines)
Lines 101-106 Link Here
101
	public void setMrtParentDirectory(String mrtParentDir)
101
	public void setMrtParentDirectory(String mrtParentDir)
102
	{
102
	{
103
	}
103
	}
104
105
	public void persistArtifacts()
106
	{
107
	}
108
109
	public ManageableResourceType getExtraGeneratedMrt() 
110
	{
111
		return null;
112
	}
113
114
	public String getExtraGeneratedMrtPersistanceLocation() 
115
	{
116
		return null;
117
	}
104
}
118
}
105
119
106
class Mrt2DescriptorResourceType
120
class Mrt2DescriptorResourceType
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/DDCodeGenerationDelegate.java (-113 / +115 lines)
Lines 12-41 Link Here
12
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.dd.internal;
13
package org.eclipse.tptp.wsdm.tooling.codegen.dd.internal;
14
14
15
import java.io.ByteArrayInputStream;
16
import java.io.ByteArrayOutputStream;
15
import java.io.IOException;
17
import java.io.IOException;
16
import java.util.ArrayList;
18
import java.util.HashMap;
17
import java.util.Collections;
19
import java.util.LinkedList;
18
import java.util.List;
20
import java.util.List;
21
import java.util.Map;
19
22
20
import org.apache.ws.muse.descriptor.CapabilityType;
21
import org.apache.ws.muse.descriptor.DescriptorPackage;
22
import org.apache.ws.muse.descriptor.DocumentRoot;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
23
import org.apache.ws.muse.descriptor.MuseType;
24
import org.apache.ws.muse.descriptor.MuseType;
24
import org.apache.ws.muse.descriptor.ResourceTypeType;
25
import org.apache.ws.muse.descriptor.ResourceTypeType;
25
import org.apache.ws.muse.descriptor.RootType;
26
import org.eclipse.core.resources.IFile;
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IResource;
27
import org.eclipse.core.runtime.SubProgressMonitor;
28
import org.eclipse.core.runtime.SubProgressMonitor;
28
import org.eclipse.emf.common.util.URI;
29
import org.eclipse.emf.common.util.URI;
29
import org.eclipse.emf.ecore.resource.Resource;
30
import org.eclipse.emf.ecore.resource.Resource;
31
import org.eclipse.emf.ecore.resource.ResourceSet;
30
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
32
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
33
import org.eclipse.emf.ecore.xmi.XMLResource;
31
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.CodeGenerationDelegate;
34
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.CodeGenerationDelegate;
32
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.DescriptorHelper;
35
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.DescriptorHelper;
33
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.SubscriptionManagerInspector;
36
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.MrtPreProcessor;
34
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
37
import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil;
35
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
36
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
38
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
37
import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages;
39
import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages;
38
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
39
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
40
import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl;
40
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
41
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog;
41
42
Lines 44-186 Link Here
44
 * Descriptor and find all of the MCap files and resolve them and merge them
45
 * Descriptor and find all of the MCap files and resolve them and merge them
45
 * into WSDL documents.
46
 * into WSDL documents.
46
 */
47
 */
47
public class DDCodeGenerationDelegate implements CodeGenerationDelegate {
48
public class DDCodeGenerationDelegate implements CodeGenerationDelegate
49
{
48
	
50
	
49
	/**
51
	/**
50
	 * The IFile of the unparsed descriptor file
52
	 * The IFile of the unparsed descriptor file
51
	 */
53
	 */
52
	private IFile _descriptorFile;
54
	private IFile _descriptorFile;
55
	private DocumentRoot _ddRoot;
56
	private List _mrtPreProcessors = new LinkedList();
53
57
54
	public DDCodeGenerationDelegate(IFile descriptorFile) {
58
	public DDCodeGenerationDelegate(IFile descriptorFile) 
59
	{
55
		_descriptorFile = descriptorFile;
60
		_descriptorFile = descriptorFile;
56
	}
61
	}
57
	
62
	
58
	public DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception {		
63
	public DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception 
59
		inspectForSubscriptionManager();
64
	{		
60
		return new DescriptorHelper(_descriptorFile);
65
		_ddRoot = DdeUtil.getDocRoot(_descriptorFile);
66
		ManageableResourceType[] mrts = getMrtsFromDD();
67
		Map mrtObjectMap = new HashMap();
68
		for(int i=0;i<mrts.length;i++)
69
		{
70
			MrtPreProcessor mrtPreProcessor = new MrtPreProcessor(mrts[i], _ddRoot);
71
			mrtPreProcessor.preProcess();
72
			_mrtPreProcessors.add(mrtPreProcessor);
73
			mrtObjectMap.putAll(mrtPreProcessor.getMrtObjectMap());
74
		}
75
		byte[] serializedDD = serializeDD();
76
		return new DescriptorHelper(new ByteArrayInputStream(serializedDD), mrtObjectMap);
61
	}
77
	}
62
	
78
	
63
	private void inspectForSubscriptionManager()
79
	private ManageableResourceType[] getMrtsFromDD()
64
	{
80
	{
65
		DocumentRoot docRoot = DdeUtil.getDocRoot(_descriptorFile);
81
		List mrts = new LinkedList();
66
		SubscriptionManagerInspector inspector = new SubscriptionManagerInspector(docRoot);
82
		if(_ddRoot.getRoot()!=null)
67
		inspector.setMrtParentDirectory(_descriptorFile.getParent().getFullPath()
83
		{
68
				.toString());
84
			if(_ddRoot.getRoot().getMuse()!=null)
69
		RootType root = docRoot.getRoot();
70
		MuseType mt = root.getMuse();
71
		List rts = mt.getResourceType();
72
		if(rts == null || rts.size() == 0)
73
		{
74
			return;
75
		}
76
		List mrts = subManagerAdded(rts);// This method returns a list of mrts if subscriptionmanager is not already added. else null
77
		if(mrts == null || mrts.size() == 0) 
78
		{
79
			return;
80
		}
81
		for(int i = 0; i < mrts.size(); i++)
82
		{
83
			ManageableResourceType mrt = (ManageableResourceType) mrts.get(i);
84
			Capability[] capDefs = getMrtCapabilities(mrt);
85
			ResourceTypeType subMgr = inspector.inspect(capDefs);
86
			if(subMgr == null)
87
			{
88
				continue;
89
			}
90
			else
91
			{
85
			{
92
				mt.getResourceType().add(subMgr);
86
				MuseType muse = _ddRoot.getRoot().getMuse();
93
				root.setMuse(mt);
87
				if(muse.getResourceType()!=null)
94
				docRoot.setRoot(root);
88
				{
95
				save(docRoot);
89
					List resourceTypes = muse.getResourceType();
96
				break;
90
					for(int i=0;i<resourceTypes.size();i++)
91
					{
92
						ResourceTypeType resourceType = (ResourceTypeType) resourceTypes.get(i);
93
						IResource mrtFile = DdeUtil.getIFileFromName(DdeUtil
94
								.getMrtFileName(resourceType.getWsdl().getWsdlFile()),
95
								"mrt");
96
						if(mrtFile!=null)
97
						{
98
							ManageableResourceType mrt = DdeUtil.loadMrtFile((IFile)mrtFile);
99
							mrts.add(mrt);
100
						}						
101
					}
102
				}
97
			}
103
			}
98
		}
104
		}
105
		return (ManageableResourceType[]) mrts.toArray(new ManageableResourceType[mrts.size()]);
99
	}
106
	}
100
	
107
	
101
	private Capability[] getMrtCapabilities(ManageableResourceType mrt) {
108
	private byte[] serializeDD()
102
		Capability[] capList = null;
103
		try {
104
			capList = MrtUtils.getCapabilities(mrt);
105
		} catch (Exception e) {
106
			WsdmToolingLog
107
					.logError(
108
							org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages.MRT_ERROR_CANNOT_TRACE_CAPS,
109
							e);
110
		}
111
112
		if (capList != null)
113
			return capList;
114
		return new Capability[0];
115
	}
116
	
117
	private void save(DocumentRoot root)
118
	{
109
	{
119
		ensureMusePackagePresent();
110
		ResourceSet resourceSet = new ResourceSetImpl();
120
		URI ddFileURI = URI.createPlatformResourceURI(_descriptorFile.getFullPath().toString());
111
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
121
		ResourceSetImpl rsImpl = new ResourceSetImpl();
122
		rsImpl.getResourceFactoryRegistry().getExtensionToFactoryMap()
123
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
112
		.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
124
				new MyDescriptorResourceFactoryImpl());
113
				new MyDescriptorResourceFactoryImpl());
125
		rsImpl.getPackageRegistry().put(DescriptorPackage.eNS_URI,
114
		URI uri = URI.createURI("dummy.xml");
126
		DescriptorPackage.eINSTANCE);
115
		Resource resource = resourceSet.createResource(uri);
127
		Resource ddRes = rsImpl.getResource(ddFileURI, true);
116
		resource.getContents().add(_ddRoot);
128
		ddRes.getContents().remove(0);
117
		Map map = new HashMap();
129
		ddRes.getContents().add(root);
118
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
130
		try {
119
		try 
131
			ddRes.save(Collections.EMPTY_MAP);
120
		{
132
		} catch (IOException e) {
121
			resource.save(baos, map);
122
		} 
123
		catch (IOException e) 
124
		{
133
			e.printStackTrace();
125
			e.printStackTrace();
134
		}
126
		}
127
		return baos.toByteArray();
135
	}
128
	}
136
	
129
	
137
	private void ensureMusePackagePresent()
130
	/**
131
	 * This method will persist the extra artifacts generated at codegen time.
132
	 */
133
	public void persistArtifacts() 
138
	{
134
	{
139
		// Ensure EMF knows about Muse descriptor
135
		for(int i=0;i<_mrtPreProcessors.size();i++)
140
		if (DescriptorPackage.eINSTANCE == null)
141
		{
136
		{
142
			WsdmToolingLog.logError(Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_, new Throwable());
137
			MrtPreProcessor mrtPreProcessor = (MrtPreProcessor) _mrtPreProcessors.get(i);
138
			mrtPreProcessor.persistArtifacts();
143
		}
139
		}
140
		persistDDFile();		
144
	}
141
	}
145
	
142
	
146
	/**
143
	private void persistDDFile()
147
	 * This method takes alist of resourceTypes and checks whether subscriptionmanager is already present.<br>
148
	 * if so returns null. else converts the resourcetypes into mrts and returns the list.
149
	 * @param rts
150
	 * @return
151
	 */
152
	private List subManagerAdded(List rts)
153
	{
144
	{
154
		List mrts = new ArrayList();
145
		//
155
		if(rts == null || rts.size() == 0)
146
		// Create a resource set
147
		//
148
		ResourceSet resourceSet = new ResourceSetImpl();
149
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
150
				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
151
						new MyDescriptorResourceFactoryImpl());
152
153
		//
154
		// Get the URI of the model file.
155
		//
156
		URI fileURI = URI.createPlatformResourceURI(_descriptorFile.getFullPath().toString());
157
158
		//
159
		// Create a resource for this file.
160
		//
161
		Resource resource = resourceSet.createResource(fileURI);
162
163
		//
164
		// Add the initial model object to the contents.
165
		//
166
		if (_ddRoot != null)
156
		{
167
		{
157
			return null;
168
			resource.getContents().add(_ddRoot);
158
		}
169
		}
159
		for(int i = 0; i < rts.size(); i++)
170
160
		{
171
		//
161
			ResourceTypeType rt = (ResourceTypeType) rts.get(i);
172
		// Save the contents of the resource to the file system.
162
			IFile mrtFile = DdeUtil.getIFileFromName(DdeUtil
173
		//
163
					.getMrtFileName(rt.getWsdl().getWsdlFile()), "mrt"); 
174
		Map options = new HashMap();
164
			if(mrtFile == null)
175
		options.put(XMLResource.OPTION_ENCODING, "UTF-8");
165
			{
176
		try
166
				continue;
177
		{
167
			}
178
			resource.save(options);		
168
			ManageableResourceType mrt = DdeUtil.loadMrtFile(mrtFile);
179
		}
169
			mrts.add(mrt);
180
		catch (Exception exception)
170
			List capList = DdeUtil.getCapabilitiesFromMRT(mrt);
181
		{
171
			if(capList == null || capList.size() == 0)
182
			exception.printStackTrace();
172
			{
183
			WsdmToolingLog.logError(
173
				continue;
184
					Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_,
174
			}
185
					exception);
175
			for(int j = 0; j < capList.size(); j++)
176
			{
177
				CapabilityType ctype = (CapabilityType) capList.get(j);
178
				if(ctype.getCapabilityUri().equals("http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager"))
179
				{
180
					return null;
181
				}
182
			}
183
		}
186
		}
184
		return mrts;
185
	}
187
	}
186
}
188
}
(-)src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtPreProcessor.java (+269 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
 * 	Andrew Eberbach (aeberbac@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional;
14
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.LinkedList;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.apache.ws.muse.descriptor.AdditionalJarsType;
22
import org.apache.ws.muse.descriptor.DescriptorFactory;
23
import org.apache.ws.muse.descriptor.DocumentRoot;
24
import org.apache.ws.muse.descriptor.InitialInstancesType;
25
import org.apache.ws.muse.descriptor.LogLevelType;
26
import org.apache.ws.muse.descriptor.LoggingType;
27
import org.apache.ws.muse.descriptor.MuseType;
28
import org.apache.ws.muse.descriptor.PersistenceType;
29
import org.apache.ws.muse.descriptor.ResourceTypeType;
30
import org.apache.ws.muse.descriptor.RootType;
31
import org.apache.ws.muse.descriptor.RouterType;
32
import org.eclipse.core.resources.IFile;
33
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability;
35
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType;
36
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils;
37
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils;
38
39
/**
40
 * This class analyzes the given ManageableResourceType object and check whether it needs
41
 * any other extra ManageableResourceType object such as SubscriptionManager based on the capabilities 
42
 * available in given ManagableResourceType.   
43
 */
44
45
public class MrtPreProcessor 
46
{
47
	private ManageableResourceType _mrt;
48
	private DocumentRoot _ddRoot;
49
	private IFile _mrtFile;
50
	private List _generatedResourceTypes = new LinkedList();
51
	private List _initialInstancesList = new LinkedList();
52
	private List _contributedInspectors = new LinkedList();
53
	private Map _mrtObjectMap = new HashMap();
54
	
55
	/**
56
	 * Creates instance of this class.
57
	 * 
58
	 * @param mrt
59
	 * 			Given MRT to analyze.
60
	 * 
61
	 * @param ddRoot
62
	 * 			Given Descriptor file document root, can be null.
63
	 */
64
	public MrtPreProcessor(ManageableResourceType mrt, DocumentRoot ddRoot)
65
	{
66
		_mrt = mrt;
67
		if(ddRoot == null)
68
			ddRoot = createDDModel();
69
		_ddRoot = ddRoot;
70
		String mrtLocation = _mrt.eResource().getURI().toString();
71
		try 
72
		{
73
			_mrtFile = EclipseUtils.getIFile(mrtLocation);
74
		} 
75
		catch (CoreException e) 
76
		{
77
			e.printStackTrace();
78
		}
79
	}
80
	
81
	/**
82
	 * Creates instance of this class.
83
	 * 
84
	 * @param mrt
85
	 * 			Given MRT to analyze.
86
	 */
87
	public MrtPreProcessor(ManageableResourceType mrt)
88
	{
89
		this(mrt,null);
90
	}
91
	
92
	private DocumentRoot createDDModel()
93
	{
94
		DocumentRoot root = DescriptorFactory.eINSTANCE.createDocumentRoot();
95
		RootType _rootType = DescriptorFactory.eINSTANCE.createRootType();
96
		MuseType _muse = DescriptorFactory.eINSTANCE.createMuseType();
97
		AdditionalJarsType jars = DescriptorFactory.eINSTANCE
98
				.createAdditionalJarsType();
99
		_rootType.setMuse(_muse);
100
		_rootType.setAdditionalJars(jars);
101
		root.setRoot(_rootType);
102
		
103
		RouterType router = createRouterType();
104
		_muse.setRouter(router);
105
		
106
		return root;
107
	}
108
	
109
	private RouterType createRouterType()
110
	{
111
		RouterType router = DescriptorFactory.eINSTANCE.createRouterType();
112
		router
113
				.setJavaRouterClass("org.apache.muse.core.routing.SimpleResourceRouter");
114
		LoggingType logging = DescriptorFactory.eINSTANCE.createLoggingType();
115
		logging.setLogFile("/log/muse.log");
116
		logging.setLogLevel(LogLevelType.OFF_LITERAL);
117
		router.setLogging(logging);
118
		PersistenceType persistence = DescriptorFactory.eINSTANCE
119
				.createPersistenceType();
120
		persistence
121
				.setJavaPersistenceClass("org.apache.muse.core.routing.RouterFilePersistence");
122
		persistence.setPersistenceLocation("router-entries");
123
		router.setPersistence(persistence);
124
		return router;
125
	}
126
	
127
	/**
128
	 * Returns the modified Descriptor document root. 
129
	 */
130
	public DocumentRoot getDDDocumentRoot()
131
	{
132
		return _ddRoot;
133
	}
134
	
135
	/**
136
	 * Analyzes the given MRT file for extra required artifacts. 
137
	 */
138
	public void preProcess()
139
	{
140
		if(_ddRoot!=null)
141
		{
142
			RootType root = _ddRoot.getRoot();
143
			MuseType muse = root.getMuse();		
144
			ResourceTypeType[] resourceTypes = process();
145
			for (int i = 0; i < resourceTypes.length; i++)
146
				muse.getResourceType().add(resourceTypes[i]);
147
			
148
			// Create initial instances
149
			
150
			InitialInstancesType[] instances = getInitialInstances();
151
			for (int i = 0; i < instances.length; i++)
152
				root.getInitialInstances().add(instances[i]);
153
		}
154
	}
155
	
156
	private boolean hasResourceTypeInDD(ResourceTypeType givenResourceType)
157
	{
158
		if(_ddRoot!=null)
159
		{
160
			if(_ddRoot.getRoot()!=null)
161
			{
162
				if(_ddRoot.getRoot().getMuse()!=null)
163
				{
164
					MuseType muse = _ddRoot.getRoot().getMuse();
165
					List resourceTypes = muse.getResourceType();
166
					if(resourceTypes!=null)
167
					{
168
						for(int i=0;i<resourceTypes.size();i++)
169
						{
170
							ResourceTypeType resourceType = (ResourceTypeType)resourceTypes.get(i);
171
							boolean equalContextPath = givenResourceType.getContextPath().equals(resourceType.getContextPath());
172
							boolean equalWsdlFile = givenResourceType.getWsdl().getWsdlFile().equals(resourceType.getWsdl().getWsdlFile());
173
							boolean equalWsdlPortType = givenResourceType.getWsdl().getWsdlPortType().equals(resourceType.getWsdl().getWsdlPortType());
174
							if(equalContextPath && equalWsdlFile && equalWsdlPortType)
175
								return true;
176
						}
177
					}
178
				}
179
			}
180
		}
181
		return false;
182
	}
183
	
184
	/**
185
	 * This method processes the given manageable resource type to check whether
186
	 * we need any extra resource type in muse descriptor file such as
187
	 * Subscription manager etc. It will returns all the proper ResourceTypeType
188
	 * objects. So it will return atleast one ResourceTypeType object that
189
	 * represents the given manageable resource type.
190
	 */
191
	private ResourceTypeType[] process()
192
	{
193
		Capability[] mrtCapabilities = new Capability[0];
194
		try
195
		{
196
			mrtCapabilities = MrtUtils.getCapabilities(_mrt);
197
		}
198
		catch (Exception e)
199
		{
200
		}
201
		// Analyze the given manageable resource type for Subscription manager
202
		// etc.
203
		// If needed add the extra resource type for Subscription manager
204
		List inspectors = getAllMrtInspectors();
205
		for (int i = 0; i < inspectors.size(); i++)
206
		{
207
			MrtInspector inspector = (MrtInspector) inspectors.get(i);
208
			inspector.setMrtParentDirectory(_mrtFile.getParent().getFullPath()
209
					.toString());
210
			ResourceTypeType resourceType = inspector.inspect(mrtCapabilities);
211
			if (resourceType != null)
212
			{
213
				if(!hasResourceTypeInDD(resourceType))
214
				{
215
					_generatedResourceTypes.add(resourceType);
216
					InitialInstancesType[] instances = inspector
217
							.getInitialInstances();
218
					for (int j = 0; j < instances.length; j++)
219
						_initialInstancesList.add(instances[j]);
220
					if(inspector.getExtraGeneratedMrt()!=null)
221
						_mrtObjectMap.put(inspector.getExtraGeneratedMrtPersistanceLocation(), inspector.getExtraGeneratedMrt());
222
					_contributedInspectors.add(inspector);
223
				}
224
			}
225
		}
226
		return (ResourceTypeType[]) _generatedResourceTypes
227
				.toArray(new ResourceTypeType[_generatedResourceTypes.size()]);
228
	}
229
230
	private List getAllMrtInspectors()
231
	{
232
		List inspectors = new ArrayList();
233
		inspectors.add(new BasicMrtInspector(_mrtFile, _mrt, _ddRoot));
234
		inspectors.add(new SubscriptionManagerInspector(_ddRoot));
235
		return inspectors;
236
	}
237
	
238
	/**
239
	 * Returns the initial instances
240
	 * @return IntialInstancesType[]
241
	 */
242
	private InitialInstancesType[] getInitialInstances()
243
	{
244
		return (InitialInstancesType[]) _initialInstancesList
245
				.toArray(new InitialInstancesType[_initialInstancesList.size()]);
246
	}
247
248
	/**
249
	 * Returns the map.
250
	 * Key will be the persisted location of MRT and 
251
	 * value will be the ManageableREsourceType object. 
252
	 */
253
	public Map getMrtObjectMap() 
254
	{
255
		return _mrtObjectMap;
256
	}
257
	
258
	/**
259
	 * This method will persist the extra artifacts generated at codegen time.
260
	 */
261
	public void persistArtifacts()
262
	{
263
		for(int i=0;i<_contributedInspectors.size();i++)
264
		{
265
			MrtInspector inspector = (MrtInspector)_contributedInspectors.get(i);
266
			inspector.persistArtifacts();
267
		}		
268
	}
269
}

Return to bug 167588