Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » UML2 to Java Literals
UML2 to Java Literals [message #859116] Fri, 27 April 2012 13:16 Go to next message
Rogério Costa is currently offline Rogério CostaFriend
Messages: 5
Registered: April 2012
Junior Member
I am developing a model-based tool, PIM -> PSM -> Code, and I am using EMF ATL to accomplish the M2M transformations. My problem is simple: My ATL mapping works betwen UML2 and Java metamodels, except in Primitive Types (Literal types).

If some with more experience could look to my files and take a shot, it will help me a lot!

UML metamodel: By URI, but you could use that as reference: UML.ecore;
Java metamodel: Java-20040316.ecore; (To be built gradually);
ATL mapping: UML2JAVA.atl;

My (UML) input Model: exampleUMLModel_PIM.xmi;

My (Java) output Model: out.j2se5; ==> At line 18 it is supposed to have a Primitive Type, right?

tanks in advance
Re: UML2 to Java Literals [message #873162 is a reply to message #859116] Thu, 17 May 2012 16:05 Go to previous messageGo to next message
Rogério Costa is currently offline Rogério CostaFriend
Messages: 5
Registered: April 2012
Junior Member
This is my Atl configuration, hope this help a little more ... Should I need to register something more?


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

public class UML2_2_JAVA extends AbstractPIMPSM_Factory
{
    private IInjector injector;
    private IExtractor extractor;
    private IReferenceModel sourceMetamodel;
    private IReferenceModel targetMetamodel;
    
    private String transformationFilepath = null;
    private String sourceMetaModelFilepath = null;
    private String targetMetaModelFilepath = null;
    private String sourceDataFilepath = null;
    private String targetDataFilepath = null;
    
    
    private IModel targetModel;
    private IModel sourceModel;
    private ModelFactory factory;
    private ILauncher launcher;
            
    public UML2_2_JAVA()
    {
        super();
    }

    
    public IModel getTargetModel()
    {
        return this.targetModel;
    }
    
           
    /// From now on, there are the functions
    public void doCore() throws ATLCoreException
    {
        CoreService.registerLauncher("EMF-specific VM", EMFVMLauncher.class);
        CoreService.registerFactory("EMF", EMFModelFactory.class); 
        CoreService.registerExtractor("EMF", EMFExtractor.class);
        CoreService.registerInjector("EMF", EMFInjector.class);
        injector = CoreService.getInjector("EMF"); 
        extractor = CoreService.getExtractor("EMF"); 			
            
        // Defaults
        this.factory = CoreService.getModelFactory("EMF");
        
        /*Resource specification*/
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi",  UMLResource.Factory.INSTANCE);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
        
             
        /*Type specification*/
        EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
        EPackage.Registry.INSTANCE.put("ecore", EcorePackage.eINSTANCE);
        EPackage.Registry.INSTANCE.put("h**p://www.omg.org/spec/UML/20110701", UMLPackage.eINSTANCE);
        EPackage.Registry.INSTANCE.put("h**p://www.omg.org/spec/XMI/20110701", UMLPackage.eINSTANCE);
        
               
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("j2se5", new EcoreResourceFactoryImpl());
    }
    
    @Override
    public void doMetaModels(String sourceTargetMMPath) throws ATLCoreException
    { this.doMetaModels(sourceTargetMMPath, null); }
    
    
    
    @Override
    public void doMetaModels(String sourceMMPath, String targetMMPath) throws ATLCoreException
    {           
        // Metamodels
        this.sourceMetaModelFilepath = sourceMMPath;
        sourceMetamodel = factory.newReferenceModel();
        injector.inject(sourceMetamodel, UMLPackage.eNS_URI);
        

        if(targetMMPath != null) //This means, the metamodel is the same for both models (InputModel & OutputModel)
        {
            this.targetMetaModelFilepath =  targetMMPath;
            targetMetamodel = factory.newReferenceModel();                                              
            injector.inject(targetMetamodel, URI.createFileURI(targetMetaModelFilepath).toString());
        }
    }
    
     
    @Override
    public void doModels(String sourceDM) throws ATLCoreException
    {
         /// Creating models
        sourceModel = factory.newModel(sourceMetamodel);
       
        if(this.targetMetamodel == null)
        { targetModel = factory.newModel(this.sourceMetamodel);}
        else
        { targetModel = factory.newModel(this.targetMetamodel); }
        
        // Loading existing model
        this.sourceDataFilepath = sourceDM;
        injector.inject(sourceModel, URI.createFileURI(sourceDM).toString());         
    }
    
       
    
    public void doTrans(String transformationPath) throws ATLCoreException, MalformedURLException, IOException
    {
        // Getting launcher
        launcher = (EMFVMLauncher)CoreService.getLauncher("EMF-specific VM"); 
        launcher.initialize(Collections.<String, Object> emptyMap());

        // Launching //TODO: REVER ISTO
        launcher.addInModel(sourceModel,"IN", "UML");
        launcher.addOutModel(targetModel, "OUT", "JAVA");
        
        // the loadModule function requires an absolute path to the ASM file
        this.transformationFilepath = transformationPath;
        URL asmFile = new File(transformationPath).toURI().toURL();
        Object loadedModule = launcher.loadModule(asmFile.openStream());

        //launcher.addLibrary("libName", new File("path").toURI().toURL().openStream());
        
        Map <String, Object> optionsTransf = new  TreeMap <String, Object>();
        optionsTransf.put("showSummary", "true");
        optionsTransf.put("printExecutionTime", "true");
        optionsTransf.put("continueAfterError", "true");
        optionsTransf.put("allowInterModelReferences", "true");
        //optionsTransf.put("step", "true"); 
        launcher.launch(ILauncher.DEBUG_MODE, new NullProgressMonitor(), optionsTransf, loadedModule);           
    }
    
    
    /**
    * Saving model
    */
    public void doSave(String dataTargetfp) throws ATLCoreException
    {
        this.targetMetaModelFilepath = dataTargetfp;
        //extractor.extract(targetModel, System.out, null);
        extractor.extract(targetModel, URI.createFileURI(dataTargetfp).toString());
    }
}


Re: UML2 to Java Literals [message #873228 is a reply to message #873162] Thu, 17 May 2012 18:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your original message seems to have fallen foul of the forum/newsgroup
synchronisation bug and not been sent to the newsgroups that are usually
the more reliable and consequently are the outlet monitored by committers.

An ATL query is more likely to get a response on the ATL than UML
newsgroups.

Regards

Ed Willink

On 17/05/2012 17:05, Rogério Costa wrote:
> This is my Atl configuration, hope this help a little more ... Should
> I need to register something more?
>
>
>
> /*
> * To change this template, choose Tools | Templates
> * and open the template in the editor.
> */
>
> public class UML2_2_JAVA extends AbstractPIMPSM_Factory
> {
> private IInjector injector;
> private IExtractor extractor;
> private IReferenceModel sourceMetamodel;
> private IReferenceModel targetMetamodel;
> private String transformationFilepath = null;
> private String sourceMetaModelFilepath = null;
> private String targetMetaModelFilepath = null;
> private String sourceDataFilepath = null;
> private String targetDataFilepath = null;
> private IModel targetModel;
> private IModel sourceModel;
> private ModelFactory factory;
> private ILauncher launcher;
> public UML2_2_JAVA()
> {
> super();
> }
>
> public IModel getTargetModel()
> {
> return this.targetModel;
> }
> /// From now on, there are the functions
> public void doCore() throws ATLCoreException
> {
> CoreService.registerLauncher("EMF-specific VM",
> EMFVMLauncher.class);
> CoreService.registerFactory("EMF", EMFModelFactory.class);
> CoreService.registerExtractor("EMF", EMFExtractor.class);
> CoreService.registerInjector("EMF", EMFInjector.class);
> injector = CoreService.getInjector("EMF"); extractor =
> CoreService.getExtractor("EMF");
> // Defaults
> this.factory = CoreService.getModelFactory("EMF");
> /*Resource specification*/
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
> new EcoreResourceFactoryImpl());
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi",
> UMLResource.Factory.INSTANCE);
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> /*Type specification*/
> EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
> EPackage.Registry.INSTANCE.put("ecore", EcorePackage.eINSTANCE);
>
> EPackage.Registry.INSTANCE.put("h**p://www.omg.org/spec/UML/20110701",
> UMLPackage.eINSTANCE);
>
> EPackage.Registry.INSTANCE.put("h**p://www.omg.org/spec/XMI/20110701",
> UMLPackage.eINSTANCE);
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("j2se5",
> new EcoreResourceFactoryImpl());
> }
> @Override
> public void doMetaModels(String sourceTargetMMPath) throws
> ATLCoreException
> { this.doMetaModels(sourceTargetMMPath, null); }
> @Override
> public void doMetaModels(String sourceMMPath, String targetMMPath)
> throws ATLCoreException
> { // Metamodels
> this.sourceMetaModelFilepath = sourceMMPath;
> sourceMetamodel = factory.newReferenceModel();
> injector.inject(sourceMetamodel, UMLPackage.eNS_URI);
>
> if(targetMMPath != null) //This means, the metamodel is the
> same for both models (InputModel & OutputModel)
> {
> this.targetMetaModelFilepath = targetMMPath;
> targetMetamodel =
> factory.newReferenceModel();
> injector.inject(targetMetamodel,
> URI.createFileURI(targetMetaModelFilepath).toString());
> }
> }
> @Override
> public void doModels(String sourceDM) throws ATLCoreException
> {
> /// Creating models
> sourceModel = factory.newModel(sourceMetamodel);
> if(this.targetMetamodel == null)
> { targetModel = factory.newModel(this.sourceMetamodel);}
> else
> { targetModel = factory.newModel(this.targetMetamodel); }
> // Loading existing model
> this.sourceDataFilepath = sourceDM;
> injector.inject(sourceModel,
> URI.createFileURI(sourceDM).toString()); }
> public void doTrans(String transformationPath) throws
> ATLCoreException, MalformedURLException, IOException
> {
> // Getting launcher
> launcher = (EMFVMLauncher)CoreService.getLauncher("EMF-specific
> VM"); launcher.initialize(Collections.<String, Object>
> emptyMap());
>
> // Launching //TODO: REVER ISTO
> launcher.addInModel(sourceModel,"IN", "UML");
> launcher.addOutModel(targetModel, "OUT", "JAVA");
> // the loadModule function requires an absolute path to
> the ASM file
> this.transformationFilepath = transformationPath;
> URL asmFile = new File(transformationPath).toURI().toURL();
> Object loadedModule = launcher.loadModule(asmFile.openStream());
>
> //launcher.addLibrary("libName", new
> File("path").toURI().toURL().openStream());
> Map <String, Object> optionsTransf = new TreeMap
> <String, Object>();
> optionsTransf.put("showSummary", "true");
> optionsTransf.put("printExecutionTime", "true");
> optionsTransf.put("continueAfterError", "true");
> optionsTransf.put("allowInterModelReferences", "true");
> //optionsTransf.put("step", "true");
> launcher.launch(ILauncher.DEBUG_MODE, new NullProgressMonitor(),
> optionsTransf, loadedModule); }
> /**
> * Saving model
> */
> public void doSave(String dataTargetfp) throws ATLCoreException
> {
> this.targetMetaModelFilepath = dataTargetfp;
> //extractor.extract(targetModel, System.out, null);
> extractor.extract(targetModel,
> URI.createFileURI(dataTargetfp).toString());
> }
> }
>
>
>
Re: UML2 to Java Literals [message #876601 is a reply to message #873228] Thu, 24 May 2012 23:26 Go to previous message
Rogério Costa is currently offline Rogério CostaFriend
Messages: 5
Registered: April 2012
Junior Member
Thank you
Previous Topic:Make UML profile plug-in visible
Next Topic:UML Component creation
Goto Forum:
  


Current Time: Fri Apr 19 20:58:18 GMT 2024

Powered by FUDForum. Page generated in 0.02895 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top