Home » Archived » M2M (model-to-model transformation) » [ATL] How to inject XML?
|
Re: [ATL] How to inject XML? [message #105327 is a reply to message #105157] |
Tue, 19 May 2009 15:53 |
Hugo Bruneliere Messages: 674 Registered: July 2009 |
Senior Member |
|
|
Hi Lucas,
Lucas a écrit :
> Hi everybody!
>
> I've read quite a lot around this topic so far, but I was unable to find
> any helpful answer to my question...
>
> My question is about the creation of an injector for XML-files. I'm
> planning to do a transformation following these steps:
> 1. XML-File (.xml) to XML.ecore-Model (injection)
> 2. XML.ecore-Model to Source.ecore-Model
> 3. Source.ecore-Model to Target.ecore-Model
> 4. Target.ecore-Model to XML.ecore-Model
> 5. XML.ecore-Model to XML-File (extraction)
>
> By now, steps 2-5 are working - all I need is some way to inject an
> XML-File to my XML.ecore-Model. For the extraction I'm using a ATL-query
> - maybe there is some existing query for the injection of XML? Or any
> other approach?
By following the instructions from
http://wiki.eclipse.org/AM3/How_Install_AM3_From_SVN, you will install
additional plugins which provide XML injection/extraction facilities:
** From an XML file (.xml file), you will be able to right-click on it
an select "Inject XML file to XML model (Ecore based)" in order to get
the corresponding XML model.
** From an XML model (.xmi file conforming to the XML metamodel), you
will be able to right-click on it an select "Extract XML model to XML
file" in order to get the corresponding XML model.
Note that the XML metamodel is available from the "resources" folder of
the "org.eclipse.am3.core" plugin (file named XML.ecore).
Best regards,
Hugo
>
> Any hints would be appreciated...
>
> Lucas
>
--
-------------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (INRIA & EMN) - Room B206
École des Mines de Nantes
4, rue Alfred Kastler
44307 Nantes Cedex 3 - France
EMail: hugo.bruneliere@inria.fr
-------------------------------------------------
--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
|
|
|
Re: [ATL] How to inject XML? [message #105382 is a reply to message #105327] |
Wed, 20 May 2009 09:51 |
Lucas Messages: 9 Registered: July 2009 |
Junior Member |
|
|
Hi Hugo,
thanks for your reply. I finally got it working now :-) Thank you! I tried
using the new AM3-version but there were some build errors which made it
impossible to run the application. I didn't know that I have to use the
old version instead...
I wonder why you don't offer the download of AM3 as Eclipse Plugins,
because the way now (via SVN) requires more effort than necessary...?
Regards,
Lucas
Hugo Bruneliere wrote:
> Hi Lucas,
> Lucas a écrit :
>> Hi everybody!
>>
>> I've read quite a lot around this topic so far, but I was unable to find
>> any helpful answer to my question...
>>
>> My question is about the creation of an injector for XML-files. I'm
>> planning to do a transformation following these steps:
>> 1. XML-File (.xml) to XML.ecore-Model (injection)
>> 2. XML.ecore-Model to Source.ecore-Model
>> 3. Source.ecore-Model to Target.ecore-Model
>> 4. Target.ecore-Model to XML.ecore-Model
>> 5. XML.ecore-Model to XML-File (extraction)
>>
>> By now, steps 2-5 are working - all I need is some way to inject an
>> XML-File to my XML.ecore-Model. For the extraction I'm using a ATL-query
>> - maybe there is some existing query for the injection of XML? Or any
>> other approach?
> By following the instructions from
> http://wiki.eclipse.org/AM3/How_Install_AM3_From_SVN, you will install
> additional plugins which provide XML injection/extraction facilities:
> ** From an XML file (.xml file), you will be able to right-click on it
> an select "Inject XML file to XML model (Ecore based)" in order to get
> the corresponding XML model.
> ** From an XML model (.xmi file conforming to the XML metamodel), you
> will be able to right-click on it an select "Extract XML model to XML
> file" in order to get the corresponding XML model.
> Note that the XML metamodel is available from the "resources" folder of
> the "org.eclipse.am3.core" plugin (file named XML.ecore).
> Best regards,
> Hugo
>>
>> Any hints would be appreciated...
>>
>> Lucas
>>
|
|
|
Re: [ATL] How to inject XML? [message #665424 is a reply to message #105157] |
Thu, 14 April 2011 15:08 |
Emwedish Endargachew Messages: 27 Registered: April 2011 |
Junior Member |
|
|
Hi Lucas,
I know it has been a long time since you posted this questions and i believe u have solved the problem. I am currently facing the same problem, would you be kind and share the idea with me. If u want to send me an email: it is "emwedishberhanu@yahoo.com"
Explaining the working steps would be helpful.
I am currently using different approach, which is creating the metamodel through EMF project and then registering the meta-model and using it as a meta model in ATL transformation. But still it is giving me package with URI is not found which is same as urs.
I appreciate your help
[Updated on: Thu, 14 April 2011 15:09] Report message to a moderator
|
|
|
Re: [ATL] How to inject XML? [message #665505 is a reply to message #105157] |
Thu, 14 April 2011 20:34 |
Thanasis Naskos Messages: 22 Registered: March 2011 |
Junior Member |
|
|
Hi Edwedish,
I've write a plugin (changing the "Hello World" plugin) for a project of mine, running atl transformation programmatically using XML parameters..
Although it's adapted to my project's needs (modisco transformation) it may help you..
I've attached the code below!
package trasform2singleton.actions;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.m2m.atl.core.ATLCoreException;
import org.eclipse.m2m.atl.core.IExtractor;
import org.eclipse.m2m.atl.core.IInjector;
import org.eclipse.m2m.atl.core.IModel;
import org.eclipse.m2m.atl.core.IReferenceModel;
import org.eclipse.m2m.atl.core.ModelFactory;
import org.eclipse.m2m.atl.core.launch.ILauncher;
import org.eclipse.m2m.atl.core.service.CoreService;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
/**
* Our sample action implements workbench action delegate.
* The action proxy will be created by the workbench and
* shown in the UI. When the user tries to use the action,
* this delegate will be created and execution will be
* delegated to it.
* @see IWorkbenchWindowActionDelegate
*/
public class SingletonTransformation implements IWorkbenchWindowActionDelegate {
private static IInjector injector;
private static IExtractor extractor;
private static IReferenceModel sourceTargetMetamodel;
private static IReferenceModel XMLMetamodel;
private static String transformationFilepath = "/home/thanasis/Desktop/data/transformation/modiscoJavaModelSingleton.asm";
private static String libraryFilepath = "/home/thanasis/Desktop/data/transformation/XMLHelpers.asm";
private static String dataSourceFilepath = "file:///home/thanasis/Desktop/data/toSingleton.javaxmi";
private static String dataSourceXMLFilepath = "file:///home/thanasis/Desktop/data/parameters.xml";
private static String dataTargetfilepath = "file:///home/thanasis/Desktop/data/newModel.javaxmi";
static {
// ATL public2private transformation
try {
injector = CoreService.getInjector("EMF"); //$NON-NLS-1$
extractor = CoreService.getExtractor("EMF"); //$NON-NLS-1$
} catch (ATLCoreException e) {
e.printStackTrace();
}
}
/**
* The constructor.
*/
public SingletonTransformation() {
}
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {
// parameters.xml creation
try{
// Create file
FileWriter fstream = new FileWriter("/home/thanasis/Desktop/data/parameters.xml");
BufferedWriter out = new BufferedWriter(fstream);
out.write("<parameters>\n <param name=\"singletonClass\" value=\"Singleton\"/>\n</parameters>");
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
ModelFactory factory = null;
try {
factory = CoreService.getModelFactory("EMF");
//launch options
Map<String, Object> options = new HashMap<String, Object>();
options.put("allowInterModelReferences", Boolean.TRUE);
// Metamodels
sourceTargetMetamodel = factory.newReferenceModel();
XMLMetamodel = factory.newReferenceModel();
injector.inject(XMLMetamodel, "http://www.eclipse.org/MoDisco/Xml/0.1.incubation/XML");
injector.inject(sourceTargetMetamodel, "http://www.eclipse.org/MoDisco/Java/0.2.incubation/java");
// Getting launcher
ILauncher launcher = null;
launcher = CoreService.getLauncher("EMF-specific VM"); //$NON-NLS-1$
launcher.initialize(Collections.<String, Object> emptyMap());
// Creating models
IModel sourceModel = factory.newModel(sourceTargetMetamodel);
IModel XMLModel = factory.newModel(XMLMetamodel);
IModel targetModel = factory.newModel(sourceTargetMetamodel);
// Loading existing model
injector.inject(sourceModel, dataSourceFilepath);
injector.inject(XMLModel, dataSourceXMLFilepath);
// Launching
launcher.addInModel(sourceModel, "IN", "MODISCOJAVA");
launcher.addOutModel(targetModel, "OUT", "MODISCOJAVA");
launcher.addInModel(XMLModel, "parameters", "XML");
URL asmFile1 = new File(transformationFilepath).toURI().toURL();
URL asmFile2 = new File(libraryFilepath).toURI().toURL();
InputStream asmInputStream1 = (InputStream) asmFile1.openStream();
InputStream asmInputStream2 = (InputStream) asmFile2.openStream();
InputStream[] modules = new InputStream[2];
modules[0] = asmInputStream1;
modules[1] = asmInputStream2;
//Object loadedModule = launcher.loadModule(asmFile.openStream());
launcher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), options, (Object[])modules);
// Saving model
extractor.extract(targetModel, dataTargetfilepath); //the name of the generated model
} catch (ATLCoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //$NON-NLS-1$
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Transformation Complete");
}
/**
* Selection in the workbench has been changed. We
* can change the state of the 'real' action here
* if we want, but this can only happen after
* the delegate has been created.
* @see IWorkbenchWindowActionDelegate#selectionChanged
*/
public void selectionChanged(IAction action, ISelection selection) {
}
/**
* We can use this method to dispose of any system
* resources we previously allocated.
* @see IWorkbenchWindowActionDelegate#dispose
*/
public void dispose() {
}
/**
* We will cache window object in order to
* be able to provide parent shell for the message dialog.
* @see IWorkbenchWindowActionDelegate#init
*/
public void init(IWorkbenchWindow window) {
}
}
|
|
| | |
Re: [ATL] How to inject XML? [message #665975 is a reply to message #105157] |
Mon, 18 April 2011 12:36 |
Thanasis Naskos Messages: 22 Registered: March 2011 |
Junior Member |
|
|
Hi Emwedish,
I think you are mistaken... I've posted the code above "Thanasis Naskos", so I think you are asking me about all this stuff...
.javaxmi -> This has nothing to do with what you want to do. It a model "Modisco Java Model" that I'm using in my transformation
.asm -> Every .atl file, automatically, produces an .asm file that holds the same information in a difference form. You need this file, not the .atl, when you run your transformation programmatically.
the code posted above -> It's a plugin based on "Hello World plugin" which runs transformations programmatically. I've posted the code to help you understand how to inject and extract metamodels and models programmatically, like in these lines
injector.inject(XMLMetamodel, "http://www.eclipse.org/MoDisco/Xml/0.1.incubation/XML");
injector.inject(sourceTargetMetamodel, "http://www.eclipse.org/MoDisco/Java/0.2.incubation/java");
...where I'm injection the metamodels, my transformation needs!
But as I understand I've confused you more, since you don't want to run your transformation programmatically. But it's good to know that there is also this way to do it.
How to inject a metamodel not programmatically -> First you should add the name that is conforms to, in the header of the atl file
module something;
create OUT : XML from IN : MyMetamodel
Then if you right click on the atl file from the Project Explorer and go to "Run As" -> "Run Configurations" it should automatically prompts you to select the appropriate metamodels for every metamodel name of the "create" section..
If this is not helping you don't hesitate to ask anything else...
|
|
| |
Goto Forum:
Current Time: Thu Mar 28 16:46:04 GMT 2024
Powered by FUDForum. Page generated in 0.04550 seconds
|