|
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 |
} |