Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 59630 Details for
Bug 167588
UCD: Code Generation Wizard: Add option for persisting generated artifacts when generating from MRT
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch for this bug
PersistArtifactsPatch.txt (text/plain), 58.53 KB, created by
Saurabh Dravid
on 2007-02-23 02:32:09 EST
(
hide
)
Description:
Patch for this bug
Filename:
MIME Type:
Creator:
Saurabh Dravid
Created:
2007-02-23 02:32:09 EST
Size:
58.53 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.tptp.wsdm.editor >Index: src/org/eclipse/tptp/wsdm/tooling/wizard/mrt/internal/NewMrtWizard.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/wizard/mrt/internal/NewMrtWizard.java,v >retrieving revision 1.3 >diff -u -r1.3 NewMrtWizard.java >--- src/org/eclipse/tptp/wsdm/tooling/wizard/mrt/internal/NewMrtWizard.java 19 Feb 2007 19:39:13 -0000 1.3 >+++ src/org/eclipse/tptp/wsdm/tooling/wizard/mrt/internal/NewMrtWizard.java 23 Feb 2007 07:26:47 -0000 >@@ -315,13 +315,9 @@ > * Throws exception while getting WSDL files and also while > * merging them > */ >- public static Document createMergedWSDL(IPath mrtFile, String address) >+ public static Document createMergedWSDL(ManageableResourceType mrt, String address) > throws Exception > { >- // Get the MRT file and load it into memory >- URI uri = URI.createFileURI(mrtFile.toString()); >- ManageableResourceType mrt = MrtUtils.loadMRT(uri); >- > checkReadersWriters(); > > List wsdlFiles = null; >Index: src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/Messages.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/Messages.java,v >retrieving revision 1.3 >diff -u -r1.3 Messages.java >--- src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/Messages.java 20 Feb 2007 12:51:06 -0000 1.3 >+++ src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/Messages.java 23 Feb 2007 07:26:47 -0000 >@@ -47,6 +47,7 @@ > public static String HOOKUP_WIZARD_ERROR_1; > public static String HOOKUP_WIZARD_ERROR_2; > public static String HOOKUP_WIZARD_ERROR_3; >+ public static String HOOKUP_WIZARD_PERSIST; > public static String HOOKUP_WIZARD_ERROR_4; > public static String HOOKUP_WIZARD_ERROR_5; > public static String HOOKUP_WIZARD_ERROR_6; >@@ -131,6 +132,7 @@ > public static String CODE_GEN_STEP1; > public static String CODE_GEN_STEP2; > public static String CODE_GEN_STEP3; >+ public static String CODE_GEN_STEP4; > public static String CODE_GEN_FAILED_ERROR; > public static String CODE_GEN_SUBTASK1; > public static String CODE_GEN_SUBTASK2; >Index: src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/messages.properties >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/messages.properties,v >retrieving revision 1.3 >diff -u -r1.3 messages.properties >--- src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/messages.properties 20 Feb 2007 12:51:06 -0000 1.3 >+++ src/org/eclipse/tptp/wsdm/tooling/nls/messages/mrt/internal/messages.properties 23 Feb 2007 07:26:47 -0000 >@@ -33,6 +33,7 @@ > HOOKUP_WIZARD_TXT1 = Deployment target and generation options > HOOKUP_WIZARD_TXT2 = This wizard creates code for touchpoint > HOOKUP_WIZARD_TXT3 = Overwrite files if necessary >+HOOKUP_WIZARD_PERSIST = Persist extra artifacts > HOOKUP_WIZARD_TXT4 = Output project > HOOKUP_WIZARD_TXT5 = Browse... > HOOKUP_WIZARD_TXT6 = Location >@@ -126,6 +127,7 @@ > CODE_GEN_STEP1 = Initializing Code Generation > CODE_GEN_STEP2 = Merging WSDL > CODE_GEN_STEP3 = Creating project >+CODE_GEN_STEP4 = Persisting artifacts > CODE_GEN_FAILED_ERROR = Code generation failed, see Error Log > CODE_GEN_SUBTASK1 = Running Analyzer > CODE_GEN_SUBTASK2 = Running Synthesizer >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MRTCodeGenerationDelegate.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MRTCodeGenerationDelegate.java,v >retrieving revision 1.2 >diff -u -r1.2 MRTCodeGenerationDelegate.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MRTCodeGenerationDelegate.java 20 Feb 2007 12:51:06 -0000 1.2 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MRTCodeGenerationDelegate.java 23 Feb 2007 07:26:46 -0000 >@@ -12,37 +12,26 @@ > > package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional; > >-import java.util.ArrayList; >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.IOException; > import java.util.HashMap; >-import java.util.List; > import java.util.Map; > >-import org.apache.ws.muse.descriptor.AdditionalJarsType; > import org.apache.ws.muse.descriptor.DescriptorFactory; > import org.apache.ws.muse.descriptor.DocumentRoot; >-import org.apache.ws.muse.descriptor.InitialInstancesType; >-import org.apache.ws.muse.descriptor.LogLevelType; >-import org.apache.ws.muse.descriptor.LoggingType; >-import org.apache.ws.muse.descriptor.MuseType; >-import org.apache.ws.muse.descriptor.PersistenceType; > import org.apache.ws.muse.descriptor.ResourceTypeType; >-import org.apache.ws.muse.descriptor.RootType; >-import org.apache.ws.muse.descriptor.RouterType; > import org.apache.ws.muse.descriptor.WsdlType; > import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.SubProgressMonitor; > import org.eclipse.emf.common.util.URI; >-import org.eclipse.emf.ecore.EObject; > import org.eclipse.emf.ecore.resource.Resource; > import org.eclipse.emf.ecore.resource.ResourceSet; > import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; > import org.eclipse.emf.ecore.xmi.XMLResource; >-import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability; > import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType; > import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages; >-import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils; > import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils; > import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl; > import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog; >@@ -54,11 +43,12 @@ > */ > public class MRTCodeGenerationDelegate implements CodeGenerationDelegate > { >- >+ private ManageableResourceType _mrt; >+ private MrtPreProcessor _mrtPreProcessor; > private String _ddFilePath; > private IFile _mrtFile; >- private DocumentRoot _root; >- >+ private DocumentRoot _ddRoot; >+ > /** > * Constructor of the class > * @param mrtFile >@@ -66,18 +56,17 @@ > public MRTCodeGenerationDelegate(IFile mrtFile) > { > _mrtFile = mrtFile; >- _generatedResourceTypes = new ArrayList(); >- _initialInstancesList = new ArrayList(); >- _contributedInspectors = new ArrayList(); > URI mrtURI = URI.createPlatformResourceURI(mrtFile.getFullPath() > .toString()); > _mrt = MrtUtils.loadMRT(mrtURI); >+ _mrtPreProcessor = new MrtPreProcessor(_mrt); > } > > /** > * Creates the DD file. > * The method returns a DescriptorHelper which > * aggregates all of the work that was done. >+ * > * @param progressMonitor A progress monitor to > * show the progress done during this > * task. >@@ -86,11 +75,71 @@ > public DescriptorHelper run(SubProgressMonitor progressMonitor) > throws Exception > { >- IFile ddFile = createDDFile(); >- return new DescriptorHelper(ddFile); >+ byte[] serializedDD = createDD(); >+ Map mrtObjectMap = _mrtPreProcessor.getMrtObjectMap(); >+ return new DescriptorHelper(new ByteArrayInputStream(serializedDD), mrtObjectMap); >+ } >+ >+ private byte[] createDD() >+ { >+ _mrtPreProcessor.preProcess(); >+ _ddRoot = _mrtPreProcessor.getDDDocumentRoot(); >+ ResourceSet resourceSet = new ResourceSetImpl(); >+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() >+ .put(Resource.Factory.Registry.DEFAULT_EXTENSION, >+ new MyDescriptorResourceFactoryImpl()); >+ URI uri = URI.createURI("dummy.xml"); >+ Resource resource = resourceSet.createResource(uri); >+ resource.getContents().add(_ddRoot); >+ Map map = new HashMap(); >+ ByteArrayOutputStream baos = new ByteArrayOutputStream(); >+ try >+ { >+ resource.save(baos, map); >+ } >+ catch (IOException e) >+ { >+ e.printStackTrace(); >+ } >+ return baos.toByteArray(); >+ } >+ >+ private String createDDFilePath() >+ { >+ IPath ddIPath = _mrtFile.getFullPath().removeFileExtension() >+ .addFileExtension("dd"); >+ return ddIPath.toString(); > } > >- private IFile createDDFile() >+ /** >+ * Create and return a new instance of given ResourceTypeType. Only >+ * ContextPath, JavaIdFactoryClass, JavaResourceClass and WsdlType fields >+ * have been copied. >+ */ >+ public static ResourceTypeType cloneResourceType(ResourceTypeType rt) >+ { >+ ResourceTypeType clone = DescriptorFactory.eINSTANCE >+ .createResourceTypeType(); >+ clone.setContextPath(rt.getContextPath()); >+ clone.setJavaIdFactoryClass(rt.getJavaIdFactoryClass()); >+ clone.setJavaResourceClass(rt.getJavaResourceClass()); >+ WsdlType wClone = DescriptorFactory.eINSTANCE.createWsdlType(); >+ wClone.setWsdlFile(rt.getWsdl().getWsdlFile()); >+ wClone.setWsdlPortType(rt.getWsdl().getWsdlPortType()); >+ clone.setWsdl(wClone); >+ return clone; >+ } >+ >+ /** >+ * This method will persist the extra artifacts generated at codegen time. >+ */ >+ public void persistArtifacts() >+ { >+ _mrtPreProcessor.persistArtifacts(); >+ persistDDFile(); >+ } >+ >+ private void persistDDFile() > { > _ddFilePath = createDDFilePath(); > >@@ -115,10 +164,9 @@ > // > // Add the initial model object to the contents. > // >- EObject rootObject = createInitialModel(); >- if (rootObject != null) >+ if (_ddRoot != null) > { >- resource.getContents().add(rootObject); >+ resource.getContents().add(_ddRoot); > } > > // >@@ -128,12 +176,7 @@ > options.put(XMLResource.OPTION_ENCODING, "UTF-8"); > try > { >- resource.save(options); >- >- IFile file = EclipseUtils.getIFile(ResourcesPlugin.getWorkspace() >- .getRoot(), fileURI.toString()); >- //return file.getLocation().toFile(); >- return file; >+ resource.save(options); > } > catch (Exception exception) > { >@@ -142,145 +185,5 @@ > Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_, > exception); > } >- >- return null; >- } >- >- private String createDDFilePath() >- { >- IPath ddIPath = _mrtFile.getFullPath().removeFileExtension() >- .addFileExtension("dd"); >- return ddIPath.toString(); >- } >- >- protected EObject createInitialModel() >- { >- _root = DescriptorFactory.eINSTANCE.createDocumentRoot(); >- RootType _rootType = DescriptorFactory.eINSTANCE.createRootType(); >- MuseType _muse = DescriptorFactory.eINSTANCE.createMuseType(); >- AdditionalJarsType jars = DescriptorFactory.eINSTANCE >- .createAdditionalJarsType(); >- _rootType.setMuse(_muse); >- _rootType.setAdditionalJars(jars); >- _root.setRoot(_rootType); >- >- // Add the router to muse descriptor >- RouterType router = createRouterType(); >- _muse.setRouter(router); >- >- ResourceTypeType[] resourceTypes = process(); >- for (int i = 0; i < resourceTypes.length; i++) >- _muse.getResourceType().add(resourceTypes[i]); >- >- // Create initial instances >- InitialInstancesType[] instances = getInitialInstances(); >- for (int i = 0; i < instances.length; i++) >- _rootType.getInitialInstances().add(instances[i]); >- >- return _root; >- } >- >- private RouterType createRouterType() >- { >- RouterType router = DescriptorFactory.eINSTANCE.createRouterType(); >- router >- .setJavaRouterClass("org.apache.muse.core.routing.SimpleResourceRouter"); >- LoggingType logging = DescriptorFactory.eINSTANCE.createLoggingType(); >- logging.setLogFile("/log/muse.log"); >- logging.setLogLevel(LogLevelType.OFF_LITERAL); >- router.setLogging(logging); >- PersistenceType persistence = DescriptorFactory.eINSTANCE >- .createPersistenceType(); >- persistence >- .setJavaPersistenceClass("org.apache.muse.core.routing.RouterFilePersistence"); >- persistence.setPersistenceLocation("router-entries"); >- router.setPersistence(persistence); >- return router; >- } >- >- private ManageableResourceType _mrt; >- >- private List _generatedResourceTypes; >- >- private List _initialInstancesList; >- >- private List _contributedInspectors; >- >- /** >- * This method processes the given manageable resource type to check whether >- * we need any extra resource type in muse descriptor file such as >- * Subscription manager etc. It will returns all the proper ResourceTypeType >- * objects. So it will return atleast one ResourceTypeType object that >- * represents the given manageable resource type. >- */ >- public ResourceTypeType[] process() >- { >- Capability[] mrtCapabilities = new Capability[0]; >- try >- { >- mrtCapabilities = MrtUtils.getCapabilities(_mrt); >- } >- catch (Exception e) >- { >- } >- // Analyze the given manageable resource type for Subscription manager >- // etc. >- // If needed add the extra resource type for Subscription manager >- List inspectors = getAllMrtInspectors(); >- for (int i = 0; i < inspectors.size(); i++) >- { >- MrtInspector inspector = (MrtInspector) inspectors.get(i); >- inspector.setMrtParentDirectory(_mrtFile.getParent().getFullPath() >- .toString()); >- ResourceTypeType resourceType = inspector.inspect(mrtCapabilities); >- if (resourceType != null) >- { >- _generatedResourceTypes.add(resourceType); >- InitialInstancesType[] instances = inspector >- .getInitialInstances(); >- for (int j = 0; j < instances.length; j++) >- _initialInstancesList.add(instances[j]); >- _contributedInspectors.add(inspector); >- } >- } >- return (ResourceTypeType[]) _generatedResourceTypes >- .toArray(new ResourceTypeType[_generatedResourceTypes.size()]); >- } >- >- private List getAllMrtInspectors() >- { >- List inspectors = new ArrayList(); >- inspectors.add(new BasicMrtInspector(_mrtFile, _mrt, _root)); >- inspectors.add(new SubscriptionManagerInspector(_root)); >- return inspectors; >- } >- >- /** >- * Create and return a new instance of given ResourceTypeType. Only >- * ContextPath, JavaIdFactoryClass, JavaResourceClass and WsdlType fields >- * have been copied. >- */ >- public static ResourceTypeType cloneResourceType(ResourceTypeType rt) >- { >- ResourceTypeType clone = DescriptorFactory.eINSTANCE >- .createResourceTypeType(); >- clone.setContextPath(rt.getContextPath()); >- clone.setJavaIdFactoryClass(rt.getJavaIdFactoryClass()); >- clone.setJavaResourceClass(rt.getJavaResourceClass()); >- WsdlType wClone = DescriptorFactory.eINSTANCE.createWsdlType(); >- wClone.setWsdlFile(rt.getWsdl().getWsdlFile()); >- wClone.setWsdlPortType(rt.getWsdl().getWsdlPortType()); >- clone.setWsdl(wClone); >- return clone; >- } >- >- /** >- * Returns the initial instances >- * @return IntialInstancesType[] >- */ >- public InitialInstancesType[] getInitialInstances() >- { >- return (InitialInstancesType[]) _initialInstancesList >- .toArray(new InitialInstancesType[_initialInstancesList.size()]); > } > } >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/SubscriptionManagerInspector.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/SubscriptionManagerInspector.java,v >retrieving revision 1.1 >diff -u -r1.1 SubscriptionManagerInspector.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/SubscriptionManagerInspector.java 19 Feb 2007 19:39:12 -0000 1.1 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/SubscriptionManagerInspector.java 23 Feb 2007 07:26:47 -0000 >@@ -13,15 +13,11 @@ > package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional; > > import java.io.ByteArrayInputStream; >-import java.io.File; > import java.io.IOException; > import java.io.InputStream; > > import javax.wsdl.Operation; >-import javax.xml.namespace.QName; > >-import org.apache.muse.tools.Activator; >-import org.apache.muse.util.xml.XmlUtils; > import org.apache.ws.muse.descriptor.CapabilityType; > import org.apache.ws.muse.descriptor.DescriptorFactory; > import org.apache.ws.muse.descriptor.DocumentRoot; >@@ -33,7 +29,6 @@ > import org.eclipse.core.resources.IFile; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.NullProgressMonitor; >-import org.eclipse.core.runtime.Path; > import org.eclipse.emf.common.util.URI; > import org.eclipse.emf.ecore.resource.ResourceSet; > import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; >@@ -43,11 +38,6 @@ > import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils; > import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils; > import org.eclipse.tptp.wsdm.tooling.util.internal.WsdlUtils; >-import org.osgi.framework.Bundle; >-import org.w3c.dom.Attr; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.xml.sax.SAXException; > > /** > * This class analyzes the given manageable resource type and provide an extra >@@ -61,9 +51,9 @@ > > private DocumentRoot _root; > >- private static String WSDL_FILE_PATH = "artifacts/resourceTypes/SubscriptionManager.wsdl"; >- > private ResourceTypeType _subManagerResourceType; >+ >+ private ManageableResourceType _subManagerMRT; > /** > * Constructor of the class > * @param root >@@ -73,15 +63,6 @@ > _root = root; > } > >- private String getModelSmashedWSDLLocation() >- { >- Bundle modelPlugin = Activator.getDefault().getBundle(); >- Path wsdlFilePath = new Path(WSDL_FILE_PATH); >- String filePath = EclipseUtils.getResolvedPath(modelPlugin, >- wsdlFilePath); >- return filePath; >- } >- > /** > * Analyzes the given manageable resource type for NotificationProducer > * capability, and if the capability available then returns the muse >@@ -100,96 +81,54 @@ > private ResourceTypeType createSubscriptionManagerResourceType() > { > createSubManagerMrt(); >- >- /* >- * try { copySubManagerMergedWSDL(); } catch (IOException e) { // TODO >- * Log e.printStackTrace(); } >- */ >- > _subManagerResourceType = createSubManagerMuseResourceType(); > return _subManagerResourceType; > } > > private void createSubManagerMrt() > { >- ManageableResourceType mrt = ManageableResourceTypeFactory.eINSTANCE >+ _subManagerMRT = ManageableResourceTypeFactory.eINSTANCE > .createManageableResourceType(); >- mrt.setIdentifier("SubscriptionManager"); >- mrt >+ _subManagerMRT.setIdentifier("SubscriptionManager"); >+ _subManagerMRT > .setNamespace("http://docs.oasis-open.org/wsn/b-2/SubscriptionManager"); >- mrt >+ _subManagerMRT > .getImplements() > .add( > "platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/Identity.wsdl"); >- mrt >+ _subManagerMRT > .getImplements() > .add( > "platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/ManageabilityCharacteristics.wsdl"); >- mrt >+ _subManagerMRT > .getImplements() > .add( > "platform:/plugin/org.apache.muse.tools/artifacts/managementCapabilities/MetadataExchange.wsdl"); >- mrt >+ _subManagerMRT > .getImplements() > .add( > "platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/GetProperty.wsdl"); >- mrt >+ _subManagerMRT > .getImplements() > .add( > "platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/SetProperty.wsdl"); >- mrt >+ _subManagerMRT > .getImplements() > .add( > "platform:/plugin/org.apache.muse.tools/artifacts/resourcePropertyCapabilities/QueryProperty.wsdl"); >- mrt >+ _subManagerMRT > .getImplements() > .add( > "platform:/plugin/org.apache.muse.tools/artifacts/resourceLifetimeCapabilities/ImmediateResourceTermination.wsdl"); >- mrt >+ _subManagerMRT > .getImplements() > .add( > "platform:/plugin/org.apache.muse.tools/artifacts/resourceLifetimeCapabilities/ScheduledResourceTermination.wsdl"); > >- mrt >+ _subManagerMRT > .getImplements() > .add( >- "platform:/plugin/org.apache.muse.tools/artifacts/resourceTypes/SubscriptionManagerCapability.wsdl"); >- >- ResourceSet rs = new ResourceSetImpl(); >- byte[] rawNewMRT = MrtUtils.serializeMRT(mrt, rs, URI >- .createURI("dummy.xml"), true); >- InputStream stream = new ByteArrayInputStream(rawNewMRT); >- >- try >- { >- String subManagerMrt = _mrtParentDirName + "/" >- + "SubscriptionManager.mrt"; >- IFile subManagerMrtFile = EclipseUtils.getIFile(subManagerMrt); >- if (subManagerMrtFile.exists()) >- { >- subManagerMrtFile.setContents(stream, true, true, >- new NullProgressMonitor()); >- } >- else >- { >- subManagerMrtFile.create(stream, true, >- new NullProgressMonitor()); >- } >- try >- { >- stream.close(); >- } >- catch (IOException e) >- { >- // TODO Log >- e.printStackTrace(); >- } >- } >- catch (CoreException e) >- { >- // TODO Log >- e.printStackTrace(); >- } >+ "platform:/plugin/org.apache.muse.tools/artifacts/resourceTypes/SubscriptionManagerCapability.wsdl"); > } > > private ResourceTypeType createSubManagerMuseResourceType() >@@ -303,57 +242,6 @@ > } > > /** >- * Returns the merged wsdl file document for SubscriptionManager. >- */ >- public Document[] getWsdlDocuments(String baseAddress) >- { >- String mergedSubManagerWsdl = getModelSmashedWSDLLocation(); >- >- Document document = null; >- try >- { >- // document = XmlUtils.createDocument(new >- // File(_mergedWsdlFilePath)); >- document = XmlUtils.createDocument(new File(mergedSubManagerWsdl)); >- makeServiceAddress(document, baseAddress); >- } >- catch (IOException e) >- { >- e.printStackTrace(); >- } >- catch (SAXException e) >- { >- e.printStackTrace(); >- } >- return new Document[] { document }; >- } >- >- private void makeServiceAddress(Document mergedWsdl, String basePath) >- { >- Element serviceElement = XmlUtils.findFirstInSubTree(mergedWsdl >- .getDocumentElement(), new QName(WSDL_NAMESPACE, "service")); >- if (serviceElement == null) // Can't find the service element in smashed >- // wsdl >- return; >- Element portInServiceElement = XmlUtils.findFirstInSubTree( >- serviceElement, new QName(WSDL_NAMESPACE, "port")); >- if (portInServiceElement == null) // Can't find the port element >- // inside service element >- return; >- Element addressElement = XmlUtils.findFirstInSubTree( >- portInServiceElement, new QName( >- "http://schemas.xmlsoap.org/wsdl/soap/", "address")); >- if (addressElement == null) // Can't find address element inside port >- // element >- return; >- Attr locationAttr = addressElement.getAttributeNode("location"); >- if (locationAttr == null || locationAttr.getNodeValue().equals("")) >- return; >- int beginIndex = locationAttr.getNodeValue().lastIndexOf('/') + 1; >- String serviceName = locationAttr.getNodeValue().substring(beginIndex); >- locationAttr.setNodeValue(basePath + "/" + serviceName); >- } >- /** > * Sets the parent directory > * @param mrtParentDir > */ >@@ -377,4 +265,62 @@ > instance.setReferenceParameters(refParam); > return new InitialInstancesType[] { instance }; > } >+ >+ /** >+ * This method will persist the extra artifacts generated at codegen time (SubscriptionManager.mrt file). >+ */ >+ public void persistArtifacts() >+ { >+ ResourceSet rs = new ResourceSetImpl(); >+ byte[] rawNewMRT = MrtUtils.serializeMRT(_subManagerMRT, rs, URI >+ .createURI("dummy.xml"), true); >+ InputStream stream = new ByteArrayInputStream(rawNewMRT); >+ >+ try >+ { >+ String subManagerMrt = _mrtParentDirName + "/" >+ + "SubscriptionManager.mrt"; >+ IFile subManagerMrtFile = EclipseUtils.getIFile(subManagerMrt); >+ if (subManagerMrtFile.exists()) >+ { >+ subManagerMrtFile.setContents(stream, true, true, >+ new NullProgressMonitor()); >+ } >+ else >+ { >+ subManagerMrtFile.create(stream, true, >+ new NullProgressMonitor()); >+ } >+ try >+ { >+ stream.close(); >+ } >+ catch (IOException e) >+ { >+ // TODO Log >+ e.printStackTrace(); >+ } >+ } >+ catch (CoreException e) >+ { >+ // TODO Log >+ e.printStackTrace(); >+ } >+ } >+ >+ /** >+ * This method will returns the extra generated ManageableResourceType object equivalent to SubscriptionManager. >+ */ >+ public ManageableResourceType getExtraGeneratedMrt() >+ { >+ return _subManagerMRT; >+ } >+ >+ /** >+ * This method should return the persistance location for extra generated ManageableResourceType object equivalent to SubscriptionManager. >+ */ >+ public String getExtraGeneratedMrtPersistanceLocation() >+ { >+ return _mrtParentDirName+"/SubscriptionManager.mrt"; >+ } > } >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/DescriptorHelper.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/DescriptorHelper.java,v >retrieving revision 1.2 >diff -u -r1.2 DescriptorHelper.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/DescriptorHelper.java 20 Feb 2007 12:51:06 -0000 1.2 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/DescriptorHelper.java 23 Feb 2007 07:26:46 -0000 >@@ -13,28 +13,26 @@ > package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional; > > import java.io.File; >-import java.io.IOException; >-import java.util.Collections; >+import java.io.FileInputStream; >+import java.io.InputStream; >+import java.util.Arrays; >+import java.util.HashMap; >+import java.util.LinkedList; >+import java.util.List; >+import java.util.Map; >+ > import javax.xml.namespace.QName; > > import org.apache.muse.core.descriptor.DescriptorConstants; > import org.apache.muse.util.xml.XmlUtils; >-import org.apache.ws.muse.descriptor.AdditionalJarsType; >-import org.apache.ws.muse.descriptor.DescriptorPackage; >-import org.apache.ws.muse.descriptor.DocumentRoot; >-import org.apache.ws.muse.descriptor.RootType; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IWorkspace; > import org.eclipse.core.resources.IWorkspaceRoot; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.IPath; > import org.eclipse.emf.common.util.URI; >-import org.eclipse.emf.ecore.resource.Resource; >-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; >-import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil; >-import org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages; >-import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl; >-import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog; >+import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType; >+import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils; > import org.eclipse.tptp.wsdm.tooling.wizard.mrt.internal.NewMrtWizard; > import org.w3c.dom.Document; > import org.w3c.dom.Element; >@@ -101,6 +99,14 @@ > private Object[][] _instances; > > private IFile ddIFile; >+ >+ /** >+ * Descriptor file stores the MRT file reference in Wsdl-File element. >+ * When we do the codegeneration we generate some extra MRTs such as SubscriptionManager, >+ * so we pass the map of these MRTs to this class. >+ * Key will be the persisted location of MRT and value will be the ManageableREsourceType object. >+ */ >+ private Map _mrtObjectMap = new HashMap(); > > /** > * A do-something constructor. Take a file, if that file is null, then load >@@ -130,7 +136,26 @@ > */ > public DescriptorHelper(File file) throws Exception > { >- Document rootDocument = XmlUtils.createDocument(file); >+ this(new FileInputStream(file), null); >+ } >+ >+ /** >+ * A do-something constructor. Take a inputstream, if that inputstream is null, then load >+ * up a default template. Otherwise load up the inputstream and pull out the >+ * instances, descriptor and additional jars. For the null inputstream case, there >+ * will be no instances of additional-jars, hence the constants defined >+ * above. >+ * >+ * @param inputstream - The inputstream to analyze, can be null. >+ * @param mrtObjectMap - The map of MRTLocation-MRTObject pair, can be null. >+ * @throws Exception - If anything goes wrong. >+ */ >+ public DescriptorHelper(InputStream inputStream, Map mrtObjectMap) throws Exception >+ { >+ if(mrtObjectMap!=null) >+ _mrtObjectMap = mrtObjectMap; >+ >+ Document rootDocument = XmlUtils.createDocument(inputStream); > > _descriptorDocument = extractDescriptorDocument(rootDocument); > _instances = extractInstances(rootDocument); >@@ -303,6 +328,8 @@ > * find all of the MRT files referenced therein. For each MRT file use > * <code>WsdlMerge</code> to merge the MRT's WSDL into a consolidate WSDL. > * Return the Muse Descriptor document-order list of the WSDL files. >+ * The passed map will contain the MRT file location as key and MRT object as value. >+ * So first search the map for MRT if not found then load the MRT from location. > * > * @return A list of merged WSDL files as gathered from the deployment > * descriptor >@@ -322,18 +349,28 @@ > resourceTypes[i], DescriptorConstants.WSDL_FILE_QNAME); > > String wsdlPath = XmlUtils.extractText(wsdlFileElement); >- >- IWorkspace workspace = ResourcesPlugin.getWorkspace(); >- IWorkspaceRoot root = workspace.getRoot(); >- IPath mrtFilePath = root.findMember( >- getMRTPathFromWSDLPath(wsdlPath)).getFullPath(); >- >- if (mrtFilePath != null) >+ String mrtPath = getMRTPathFromWSDLPath(wsdlPath); >+ ManageableResourceType mrt = null; >+ String serviceAddress = null; >+ if(_mrtObjectMap!=null && _mrtObjectMap.containsKey(mrtPath)) >+ { >+ mrt = (ManageableResourceType) _mrtObjectMap.get(mrtPath); >+ serviceAddress = baseAddress+"/"+mrt.getIdentifier(); >+ } >+ else >+ { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IWorkspaceRoot root = workspace.getRoot(); >+ IPath mrtFilePath = root.findMember(mrtPath).getFullPath(); >+ URI uri = URI.createFileURI(mrtFilePath.toString()); >+ mrt = MrtUtils.loadMRT(uri); >+ serviceAddress = makeServiceAddress(baseAddress, mrtFilePath); >+ } >+ if(mrt!=null) > { > try > { >- mergedWSDLs[i] = NewMrtWizard.createMergedWSDL(mrtFilePath, >- makeServiceAddress(baseAddress, mrtFilePath)); >+ mergedWSDLs[i] = NewMrtWizard.createMergedWSDL(mrt, serviceAddress); > } > catch (Exception e) > { >@@ -347,7 +384,6 @@ > throw new RuntimeException(); > } > } >- > return mergedWSDLs; > } > >@@ -384,45 +420,11 @@ > */ > public void addAdditionalJars(String serverLocation, String[] axis2files) > { >- DocumentRoot root = DdeUtil.getDocRoot(ddIFile); >- RootType rootType = root.getRoot(); >- AdditionalJarsType additionalJars = rootType.getAdditionalJars(); >+ List additionalJarFiles = new LinkedList(); >+ if(_jarFiles!=null) >+ additionalJarFiles.addAll(Arrays.asList(_jarFiles)); > for(int i = 0 ; i < axis2files.length ; i++ ) >- additionalJars.getJarPath().add(serverLocation + File.separator + axis2files[i]); >- rootType.setAdditionalJars(additionalJars); >- root.setRoot(rootType); >- save(root); >- } >- >- private void save(DocumentRoot root) >- { >- ensureMusePackagePresent(); >- URI ddFileURI = URI.createPlatformResourceURI(ddIFile.getFullPath().toString()); >- ResourceSetImpl rsImpl = new ResourceSetImpl(); >- rsImpl.getResourceFactoryRegistry().getExtensionToFactoryMap() >- .put(Resource.Factory.Registry.DEFAULT_EXTENSION, >- new MyDescriptorResourceFactoryImpl()); >- rsImpl.getPackageRegistry().put(DescriptorPackage.eNS_URI, >- DescriptorPackage.eINSTANCE); >- Resource ddRes = rsImpl.getResource(ddFileURI, true); >- ddRes.getContents().remove(0); >- ddRes.getContents().add(root); >- try >- { >- ddRes.save(Collections.EMPTY_MAP); >- } >- catch (IOException e) >- { >- e.printStackTrace(); >- } >- } >- >- private void ensureMusePackagePresent() >- { >- // Ensure EMF knows about Muse descriptor >- if (DescriptorPackage.eINSTANCE == null) >- { >- WsdmToolingLog.logError(Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_, new Throwable()); >- } >+ additionalJarFiles.add(new File(serverLocation + File.separator + axis2files[i])); >+ _jarFiles = (File[]) additionalJarFiles.toArray(new File[additionalJarFiles.size()]); > } > } >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/GenerationOptionsPage.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/GenerationOptionsPage.java,v >retrieving revision 1.3 >diff -u -r1.3 GenerationOptionsPage.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/GenerationOptionsPage.java 21 Feb 2007 13:46:51 -0000 1.3 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/GenerationOptionsPage.java 23 Feb 2007 07:26:46 -0000 >@@ -112,6 +112,8 @@ > > private boolean axis2Project; > >+ private Button _persistExtraArtifactsButton; >+ > /** > * For cheatsheet purpose only This constructor will be used in cheatsheet > * only >@@ -174,6 +176,8 @@ > > _buttonOverwrite = makeButton(column, Messages.HOOKUP_WIZARD_TXT3, > SWT.CHECK); >+ >+ _persistExtraArtifactsButton = makeButton(column, Messages.HOOKUP_WIZARD_PERSIST, SWT.CHECK); > } > > private Group createProjectizerGroup(Composite parent) >@@ -659,6 +663,11 @@ > { > return _buttonOverwrite.getSelection(); > } >+ >+ public boolean shouldPersistArtifacts() >+ { >+ return _persistExtraArtifactsButton.getSelection(); >+ } > > /** > * Return the value of the output project >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/NewProjectWizard.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/NewProjectWizard.java,v >retrieving revision 1.2 >diff -u -r1.2 NewProjectWizard.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/NewProjectWizard.java 20 Feb 2007 12:51:06 -0000 1.2 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/NewProjectWizard.java 23 Feb 2007 07:26:47 -0000 >@@ -63,6 +63,8 @@ > private String _projectName; > > private boolean _overwrite; >+ >+ private boolean _shouldPersistArtifacts; > > private Projectizer _projectizer; > >@@ -118,7 +120,7 @@ > { > try > { >- monitor.beginTask(Messages.CODE_GEN_START, 6); >+ monitor.beginTask(Messages.CODE_GEN_START, 7); > > if(_isAxis2Project) > { >@@ -179,6 +181,11 @@ > throw new InvocationTargetException(new Exception( > Messages.CODE_GEN_FAILED_ERROR, e)); > } >+ >+ monitor.subTask(Messages.CODE_GEN_STEP4); >+ if(_shouldPersistArtifacts) >+ _codeGenerationDelegate.persistArtifacts(); >+ monitor.worked(1); > } > finally > { >@@ -197,6 +204,7 @@ > _synthesizer = _generationOptionsPage.getSynthesizer(); > _analyzer = _generationOptionsPage.getAnalyzer(); > _overwrite = _generationOptionsPage.isOverwrite(); >+ _shouldPersistArtifacts = _generationOptionsPage.shouldPersistArtifacts(); > _projectName = _generationOptionsPage.getProjectName(); > _baseAddress = _generationOptionsPage.getBaseAddress(); > _isAxis2Project = _generationOptionsPage.isAxis2Project(); >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtInspector.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtInspector.java,v >retrieving revision 1.1 >diff -u -r1.1 MrtInspector.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtInspector.java 19 Feb 2007 19:39:12 -0000 1.1 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtInspector.java 23 Feb 2007 07:26:46 -0000 >@@ -15,6 +15,7 @@ > import org.apache.ws.muse.descriptor.InitialInstancesType; > import org.apache.ws.muse.descriptor.ResourceTypeType; > import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability; >+import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType; > > /** > * This interface is created for some cases where we expect some extra resource >@@ -28,9 +29,34 @@ > { > public static String WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/"; > >+ /** >+ * Analyzes the given manageable resource type capabilities and then returns the muse >+ * resource type for some extra generated artifact else returns the null. >+ */ > ResourceTypeType inspect(Capability[] mrtCapabilities); > >+ /** >+ * This method should set the parent directory for extra generated artifact. >+ */ > void setMrtParentDirectory(String mrtParentDir); > >+ /** >+ * Returns initial instances for extra generated artifact. >+ */ > InitialInstancesType[] getInitialInstances(); >+ >+ /** >+ * This method will persist the extra artifacts generated at codegen time. >+ */ >+ void persistArtifacts(); >+ >+ /** >+ * This method will returns the extra ManageableResourceType object generated at codegen time. >+ */ >+ ManageableResourceType getExtraGeneratedMrt(); >+ >+ /** >+ * This method should return the persistance location for extra generated ManageableResourceType object. >+ */ >+ String getExtraGeneratedMrtPersistanceLocation(); > } >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/CodeGenerationDelegate.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/CodeGenerationDelegate.java,v >retrieving revision 1.1 >diff -u -r1.1 CodeGenerationDelegate.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/CodeGenerationDelegate.java 19 Feb 2007 19:39:12 -0000 1.1 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/CodeGenerationDelegate.java 23 Feb 2007 07:26:46 -0000 >@@ -35,4 +35,9 @@ > * @throws Exception > */ > DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception; >+ >+ /** >+ * Persist the extra artifacts generated during codegeneration such as SubscriptionManager.mrt etc. >+ */ >+ void persistArtifacts(); > } >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/BasicMrtInspector.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/BasicMrtInspector.java,v >retrieving revision 1.2 >diff -u -r1.2 BasicMrtInspector.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/BasicMrtInspector.java 22 Feb 2007 05:47:24 -0000 1.2 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/BasicMrtInspector.java 23 Feb 2007 07:26:46 -0000 >@@ -101,6 +101,20 @@ > public void setMrtParentDirectory(String mrtParentDir) > { > } >+ >+ public void persistArtifacts() >+ { >+ } >+ >+ public ManageableResourceType getExtraGeneratedMrt() >+ { >+ return null; >+ } >+ >+ public String getExtraGeneratedMrtPersistanceLocation() >+ { >+ return null; >+ } > } > > class Mrt2DescriptorResourceType >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/DDCodeGenerationDelegate.java >=================================================================== >RCS file: /cvsroot/ganges/org.eclipse.tptp.wsdm.editor/src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/DDCodeGenerationDelegate.java,v >retrieving revision 1.2 >diff -u -r1.2 DDCodeGenerationDelegate.java >--- src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/DDCodeGenerationDelegate.java 19 Feb 2007 19:39:13 -0000 1.2 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/dd/internal/DDCodeGenerationDelegate.java 23 Feb 2007 07:26:46 -0000 >@@ -12,30 +12,31 @@ > > package org.eclipse.tptp.wsdm.tooling.codegen.dd.internal; > >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; > import java.io.IOException; >-import java.util.ArrayList; >-import java.util.Collections; >+import java.util.HashMap; >+import java.util.LinkedList; > import java.util.List; >+import java.util.Map; > >-import org.apache.ws.muse.descriptor.CapabilityType; >-import org.apache.ws.muse.descriptor.DescriptorPackage; > import org.apache.ws.muse.descriptor.DocumentRoot; > import org.apache.ws.muse.descriptor.MuseType; > import org.apache.ws.muse.descriptor.ResourceTypeType; >-import org.apache.ws.muse.descriptor.RootType; > import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; > import org.eclipse.core.runtime.SubProgressMonitor; > import org.eclipse.emf.common.util.URI; > import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.ResourceSet; > import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; >+import org.eclipse.emf.ecore.xmi.XMLResource; > import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.CodeGenerationDelegate; > import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.DescriptorHelper; >-import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.SubscriptionManagerInspector; >+import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.MrtPreProcessor; > import org.eclipse.tptp.wsdm.tooling.editor.dde.util.internal.DdeUtil; >-import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability; > import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType; > import org.eclipse.tptp.wsdm.tooling.nls.messages.dde.internal.Messages; >-import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils; > import org.eclipse.tptp.wsdm.tooling.util.internal.MyDescriptorResourceFactoryImpl; > import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog; > >@@ -44,143 +45,144 @@ > * Descriptor and find all of the MCap files and resolve them and merge them > * into WSDL documents. > */ >-public class DDCodeGenerationDelegate implements CodeGenerationDelegate { >+public class DDCodeGenerationDelegate implements CodeGenerationDelegate >+{ > > /** > * The IFile of the unparsed descriptor file > */ > private IFile _descriptorFile; >+ private DocumentRoot _ddRoot; >+ private List _mrtPreProcessors = new LinkedList(); > >- public DDCodeGenerationDelegate(IFile descriptorFile) { >+ public DDCodeGenerationDelegate(IFile descriptorFile) >+ { > _descriptorFile = descriptorFile; > } > >- public DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception { >- inspectForSubscriptionManager(); >- return new DescriptorHelper(_descriptorFile); >+ public DescriptorHelper run(SubProgressMonitor progressMonitor) throws Exception >+ { >+ _ddRoot = DdeUtil.getDocRoot(_descriptorFile); >+ ManageableResourceType[] mrts = getMrtsFromDD(); >+ Map mrtObjectMap = new HashMap(); >+ for(int i=0;i<mrts.length;i++) >+ { >+ MrtPreProcessor mrtPreProcessor = new MrtPreProcessor(mrts[i], _ddRoot); >+ mrtPreProcessor.preProcess(); >+ _mrtPreProcessors.add(mrtPreProcessor); >+ mrtObjectMap.putAll(mrtPreProcessor.getMrtObjectMap()); >+ } >+ byte[] serializedDD = serializeDD(); >+ return new DescriptorHelper(new ByteArrayInputStream(serializedDD), mrtObjectMap); > } > >- private void inspectForSubscriptionManager() >+ private ManageableResourceType[] getMrtsFromDD() > { >- DocumentRoot docRoot = DdeUtil.getDocRoot(_descriptorFile); >- SubscriptionManagerInspector inspector = new SubscriptionManagerInspector(docRoot); >- inspector.setMrtParentDirectory(_descriptorFile.getParent().getFullPath() >- .toString()); >- RootType root = docRoot.getRoot(); >- MuseType mt = root.getMuse(); >- List rts = mt.getResourceType(); >- if(rts == null || rts.size() == 0) >- { >- return; >- } >- List mrts = subManagerAdded(rts);// This method returns a list of mrts if subscriptionmanager is not already added. else null >- if(mrts == null || mrts.size() == 0) >- { >- return; >- } >- for(int i = 0; i < mrts.size(); i++) >- { >- ManageableResourceType mrt = (ManageableResourceType) mrts.get(i); >- Capability[] capDefs = getMrtCapabilities(mrt); >- ResourceTypeType subMgr = inspector.inspect(capDefs); >- if(subMgr == null) >- { >- continue; >- } >- else >+ List mrts = new LinkedList(); >+ if(_ddRoot.getRoot()!=null) >+ { >+ if(_ddRoot.getRoot().getMuse()!=null) > { >- mt.getResourceType().add(subMgr); >- root.setMuse(mt); >- docRoot.setRoot(root); >- save(docRoot); >- break; >+ MuseType muse = _ddRoot.getRoot().getMuse(); >+ if(muse.getResourceType()!=null) >+ { >+ List resourceTypes = muse.getResourceType(); >+ for(int i=0;i<resourceTypes.size();i++) >+ { >+ ResourceTypeType resourceType = (ResourceTypeType) resourceTypes.get(i); >+ IResource mrtFile = DdeUtil.getIFileFromName(DdeUtil >+ .getMrtFileName(resourceType.getWsdl().getWsdlFile()), >+ "mrt"); >+ if(mrtFile!=null) >+ { >+ ManageableResourceType mrt = DdeUtil.loadMrtFile((IFile)mrtFile); >+ mrts.add(mrt); >+ } >+ } >+ } > } > } >+ return (ManageableResourceType[]) mrts.toArray(new ManageableResourceType[mrts.size()]); > } > >- private Capability[] getMrtCapabilities(ManageableResourceType mrt) { >- Capability[] capList = null; >- try { >- capList = MrtUtils.getCapabilities(mrt); >- } catch (Exception e) { >- WsdmToolingLog >- .logError( >- org.eclipse.tptp.wsdm.tooling.nls.messages.mrt.internal.Messages.MRT_ERROR_CANNOT_TRACE_CAPS, >- e); >- } >- >- if (capList != null) >- return capList; >- return new Capability[0]; >- } >- >- private void save(DocumentRoot root) >+ private byte[] serializeDD() > { >- ensureMusePackagePresent(); >- URI ddFileURI = URI.createPlatformResourceURI(_descriptorFile.getFullPath().toString()); >- ResourceSetImpl rsImpl = new ResourceSetImpl(); >- rsImpl.getResourceFactoryRegistry().getExtensionToFactoryMap() >+ ResourceSet resourceSet = new ResourceSetImpl(); >+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() > .put(Resource.Factory.Registry.DEFAULT_EXTENSION, > new MyDescriptorResourceFactoryImpl()); >- rsImpl.getPackageRegistry().put(DescriptorPackage.eNS_URI, >- DescriptorPackage.eINSTANCE); >- Resource ddRes = rsImpl.getResource(ddFileURI, true); >- ddRes.getContents().remove(0); >- ddRes.getContents().add(root); >- try { >- ddRes.save(Collections.EMPTY_MAP); >- } catch (IOException e) { >+ URI uri = URI.createURI("dummy.xml"); >+ Resource resource = resourceSet.createResource(uri); >+ resource.getContents().add(_ddRoot); >+ Map map = new HashMap(); >+ ByteArrayOutputStream baos = new ByteArrayOutputStream(); >+ try >+ { >+ resource.save(baos, map); >+ } >+ catch (IOException e) >+ { > e.printStackTrace(); > } >+ return baos.toByteArray(); > } > >- private void ensureMusePackagePresent() >+ /** >+ * This method will persist the extra artifacts generated at codegen time. >+ */ >+ public void persistArtifacts() > { >- // Ensure EMF knows about Muse descriptor >- if (DescriptorPackage.eINSTANCE == null) >+ for(int i=0;i<_mrtPreProcessors.size();i++) > { >- WsdmToolingLog.logError(Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_, new Throwable()); >+ MrtPreProcessor mrtPreProcessor = (MrtPreProcessor) _mrtPreProcessors.get(i); >+ mrtPreProcessor.persistArtifacts(); > } >+ persistDDFile(); > } > >- /** >- * This method takes alist of resourceTypes and checks whether subscriptionmanager is already present.<br> >- * if so returns null. else converts the resourcetypes into mrts and returns the list. >- * @param rts >- * @return >- */ >- private List subManagerAdded(List rts) >+ private void persistDDFile() > { >- List mrts = new ArrayList(); >- if(rts == null || rts.size() == 0) >+ // >+ // Create a resource set >+ // >+ ResourceSet resourceSet = new ResourceSetImpl(); >+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() >+ .put(Resource.Factory.Registry.DEFAULT_EXTENSION, >+ new MyDescriptorResourceFactoryImpl()); >+ >+ // >+ // Get the URI of the model file. >+ // >+ URI fileURI = URI.createPlatformResourceURI(_descriptorFile.getFullPath().toString()); >+ >+ // >+ // Create a resource for this file. >+ // >+ Resource resource = resourceSet.createResource(fileURI); >+ >+ // >+ // Add the initial model object to the contents. >+ // >+ if (_ddRoot != null) > { >- return null; >+ resource.getContents().add(_ddRoot); > } >- for(int i = 0; i < rts.size(); i++) >- { >- ResourceTypeType rt = (ResourceTypeType) rts.get(i); >- IFile mrtFile = DdeUtil.getIFileFromName(DdeUtil >- .getMrtFileName(rt.getWsdl().getWsdlFile()), "mrt"); >- if(mrtFile == null) >- { >- continue; >- } >- ManageableResourceType mrt = DdeUtil.loadMrtFile(mrtFile); >- mrts.add(mrt); >- List capList = DdeUtil.getCapabilitiesFromMRT(mrt); >- if(capList == null || capList.size() == 0) >- { >- continue; >- } >- for(int j = 0; j < capList.size(); j++) >- { >- CapabilityType ctype = (CapabilityType) capList.get(j); >- if(ctype.getCapabilityUri().equals("http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager")) >- { >- return null; >- } >- } >+ >+ // >+ // Save the contents of the resource to the file system. >+ // >+ Map options = new HashMap(); >+ options.put(XMLResource.OPTION_ENCODING, "UTF-8"); >+ try >+ { >+ resource.save(options); >+ } >+ catch (Exception exception) >+ { >+ exception.printStackTrace(); >+ WsdmToolingLog.logError( >+ Messages.FAILED_TO_INITIALIZE_MUSE_DESCRIPTOR_ERROR_, >+ exception); > } >- return mrts; > } > } >Index: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtPreProcessor.java >=================================================================== >RCS file: src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtPreProcessor.java >diff -N src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtPreProcessor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/tptp/wsdm/tooling/codegen/mrt/provisional/MrtPreProcessor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,269 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Andrew Eberbach (aeberbac@us.ibm.com) >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional; >+ >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.LinkedList; >+import java.util.List; >+import java.util.Map; >+ >+import org.apache.ws.muse.descriptor.AdditionalJarsType; >+import org.apache.ws.muse.descriptor.DescriptorFactory; >+import org.apache.ws.muse.descriptor.DocumentRoot; >+import org.apache.ws.muse.descriptor.InitialInstancesType; >+import org.apache.ws.muse.descriptor.LogLevelType; >+import org.apache.ws.muse.descriptor.LoggingType; >+import org.apache.ws.muse.descriptor.MuseType; >+import org.apache.ws.muse.descriptor.PersistenceType; >+import org.apache.ws.muse.descriptor.ResourceTypeType; >+import org.apache.ws.muse.descriptor.RootType; >+import org.apache.ws.muse.descriptor.RouterType; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability; >+import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType; >+import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils; >+import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils; >+ >+/** >+ * This class analyzes the given ManageableResourceType object and check whether it needs >+ * any other extra ManageableResourceType object such as SubscriptionManager based on the capabilities >+ * available in given ManagableResourceType. >+ */ >+ >+public class MrtPreProcessor >+{ >+ private ManageableResourceType _mrt; >+ private DocumentRoot _ddRoot; >+ private IFile _mrtFile; >+ private List _generatedResourceTypes = new LinkedList(); >+ private List _initialInstancesList = new LinkedList(); >+ private List _contributedInspectors = new LinkedList(); >+ private Map _mrtObjectMap = new HashMap(); >+ >+ /** >+ * Creates instance of this class. >+ * >+ * @param mrt >+ * Given MRT to analyze. >+ * >+ * @param ddRoot >+ * Given Descriptor file document root, can be null. >+ */ >+ public MrtPreProcessor(ManageableResourceType mrt, DocumentRoot ddRoot) >+ { >+ _mrt = mrt; >+ if(ddRoot == null) >+ ddRoot = createDDModel(); >+ _ddRoot = ddRoot; >+ String mrtLocation = _mrt.eResource().getURI().toString(); >+ try >+ { >+ _mrtFile = EclipseUtils.getIFile(mrtLocation); >+ } >+ catch (CoreException e) >+ { >+ e.printStackTrace(); >+ } >+ } >+ >+ /** >+ * Creates instance of this class. >+ * >+ * @param mrt >+ * Given MRT to analyze. >+ */ >+ public MrtPreProcessor(ManageableResourceType mrt) >+ { >+ this(mrt,null); >+ } >+ >+ private DocumentRoot createDDModel() >+ { >+ DocumentRoot root = DescriptorFactory.eINSTANCE.createDocumentRoot(); >+ RootType _rootType = DescriptorFactory.eINSTANCE.createRootType(); >+ MuseType _muse = DescriptorFactory.eINSTANCE.createMuseType(); >+ AdditionalJarsType jars = DescriptorFactory.eINSTANCE >+ .createAdditionalJarsType(); >+ _rootType.setMuse(_muse); >+ _rootType.setAdditionalJars(jars); >+ root.setRoot(_rootType); >+ >+ RouterType router = createRouterType(); >+ _muse.setRouter(router); >+ >+ return root; >+ } >+ >+ private RouterType createRouterType() >+ { >+ RouterType router = DescriptorFactory.eINSTANCE.createRouterType(); >+ router >+ .setJavaRouterClass("org.apache.muse.core.routing.SimpleResourceRouter"); >+ LoggingType logging = DescriptorFactory.eINSTANCE.createLoggingType(); >+ logging.setLogFile("/log/muse.log"); >+ logging.setLogLevel(LogLevelType.OFF_LITERAL); >+ router.setLogging(logging); >+ PersistenceType persistence = DescriptorFactory.eINSTANCE >+ .createPersistenceType(); >+ persistence >+ .setJavaPersistenceClass("org.apache.muse.core.routing.RouterFilePersistence"); >+ persistence.setPersistenceLocation("router-entries"); >+ router.setPersistence(persistence); >+ return router; >+ } >+ >+ /** >+ * Returns the modified Descriptor document root. >+ */ >+ public DocumentRoot getDDDocumentRoot() >+ { >+ return _ddRoot; >+ } >+ >+ /** >+ * Analyzes the given MRT file for extra required artifacts. >+ */ >+ public void preProcess() >+ { >+ if(_ddRoot!=null) >+ { >+ RootType root = _ddRoot.getRoot(); >+ MuseType muse = root.getMuse(); >+ ResourceTypeType[] resourceTypes = process(); >+ for (int i = 0; i < resourceTypes.length; i++) >+ muse.getResourceType().add(resourceTypes[i]); >+ >+ // Create initial instances >+ >+ InitialInstancesType[] instances = getInitialInstances(); >+ for (int i = 0; i < instances.length; i++) >+ root.getInitialInstances().add(instances[i]); >+ } >+ } >+ >+ private boolean hasResourceTypeInDD(ResourceTypeType givenResourceType) >+ { >+ if(_ddRoot!=null) >+ { >+ if(_ddRoot.getRoot()!=null) >+ { >+ if(_ddRoot.getRoot().getMuse()!=null) >+ { >+ MuseType muse = _ddRoot.getRoot().getMuse(); >+ List resourceTypes = muse.getResourceType(); >+ if(resourceTypes!=null) >+ { >+ for(int i=0;i<resourceTypes.size();i++) >+ { >+ ResourceTypeType resourceType = (ResourceTypeType)resourceTypes.get(i); >+ boolean equalContextPath = givenResourceType.getContextPath().equals(resourceType.getContextPath()); >+ boolean equalWsdlFile = givenResourceType.getWsdl().getWsdlFile().equals(resourceType.getWsdl().getWsdlFile()); >+ boolean equalWsdlPortType = givenResourceType.getWsdl().getWsdlPortType().equals(resourceType.getWsdl().getWsdlPortType()); >+ if(equalContextPath && equalWsdlFile && equalWsdlPortType) >+ return true; >+ } >+ } >+ } >+ } >+ } >+ return false; >+ } >+ >+ /** >+ * This method processes the given manageable resource type to check whether >+ * we need any extra resource type in muse descriptor file such as >+ * Subscription manager etc. It will returns all the proper ResourceTypeType >+ * objects. So it will return atleast one ResourceTypeType object that >+ * represents the given manageable resource type. >+ */ >+ private ResourceTypeType[] process() >+ { >+ Capability[] mrtCapabilities = new Capability[0]; >+ try >+ { >+ mrtCapabilities = MrtUtils.getCapabilities(_mrt); >+ } >+ catch (Exception e) >+ { >+ } >+ // Analyze the given manageable resource type for Subscription manager >+ // etc. >+ // If needed add the extra resource type for Subscription manager >+ List inspectors = getAllMrtInspectors(); >+ for (int i = 0; i < inspectors.size(); i++) >+ { >+ MrtInspector inspector = (MrtInspector) inspectors.get(i); >+ inspector.setMrtParentDirectory(_mrtFile.getParent().getFullPath() >+ .toString()); >+ ResourceTypeType resourceType = inspector.inspect(mrtCapabilities); >+ if (resourceType != null) >+ { >+ if(!hasResourceTypeInDD(resourceType)) >+ { >+ _generatedResourceTypes.add(resourceType); >+ InitialInstancesType[] instances = inspector >+ .getInitialInstances(); >+ for (int j = 0; j < instances.length; j++) >+ _initialInstancesList.add(instances[j]); >+ if(inspector.getExtraGeneratedMrt()!=null) >+ _mrtObjectMap.put(inspector.getExtraGeneratedMrtPersistanceLocation(), inspector.getExtraGeneratedMrt()); >+ _contributedInspectors.add(inspector); >+ } >+ } >+ } >+ return (ResourceTypeType[]) _generatedResourceTypes >+ .toArray(new ResourceTypeType[_generatedResourceTypes.size()]); >+ } >+ >+ private List getAllMrtInspectors() >+ { >+ List inspectors = new ArrayList(); >+ inspectors.add(new BasicMrtInspector(_mrtFile, _mrt, _ddRoot)); >+ inspectors.add(new SubscriptionManagerInspector(_ddRoot)); >+ return inspectors; >+ } >+ >+ /** >+ * Returns the initial instances >+ * @return IntialInstancesType[] >+ */ >+ private InitialInstancesType[] getInitialInstances() >+ { >+ return (InitialInstancesType[]) _initialInstancesList >+ .toArray(new InitialInstancesType[_initialInstancesList.size()]); >+ } >+ >+ /** >+ * Returns the map. >+ * Key will be the persisted location of MRT and >+ * value will be the ManageableREsourceType object. >+ */ >+ public Map getMrtObjectMap() >+ { >+ return _mrtObjectMap; >+ } >+ >+ /** >+ * This method will persist the extra artifacts generated at codegen time. >+ */ >+ public void persistArtifacts() >+ { >+ for(int i=0;i<_contributedInspectors.size();i++) >+ { >+ MrtInspector inspector = (MrtInspector)_contributedInspectors.get(i); >+ inspector.persistArtifacts(); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 167588
: 59630