Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » ecore2ecore mapping
ecore2ecore mapping [message #509705] Mon, 25 January 2010 03:32 Go to next message
smilee  is currently offline smilee Friend
Messages: 6
Registered: January 2010
Junior Member
Hell moderator,

I am having two ecore files and i want to do ecore2ecore transformation. May I know how to execute the file. Also, is there any necessary to write the java file..?

[Updated on: Mon, 25 January 2010 03:33]

Report message to a moderator

Re: ecore2ecore mapping [message #509755 is a reply to message #509705] Mon, 25 January 2010 10:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
A *.ecore2ecore resource just describes a mapping between Ecore
instances. It's not an executable thing and can't be used directly to
do a transformation. You could write a transformation as Java code just
like you'd transform any Java instance to some other Java instance or
use one of the Model to Model technologies: http://www.eclipse.org/m2m/

smilee wrote:
> Hell moderator,
>
> I am having two ecore files and i want to do ecore2ecore
> transformation. May I know how to execute the file. Also, is there any
> necessary to write the java file..?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ecore2ecore mapping [message #509988 is a reply to message #509755] Tue, 26 January 2010 01:16 Go to previous messageGo to next message
smilee  is currently offline smilee Friend
Messages: 6
Registered: January 2010
Junior Member
Hello Ed,

Thank you for giving the reply.

What exactly I need to do is am having two ecore files. Student.ecore and University.ecore.

If i give Student.ecore as input, i have to get University.ecore as the output.

So for that, I am following the procedure ecore2ecore mapping.

Is that the right way to get the model or do I need to do follow any other way..

Can you suggest me the procedure to follow that..
Re: ecore2ecore mapping [message #510007 is a reply to message #509988] Tue, 26 January 2010 02:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
You have to produce a GenModel for each *.ecore and generate the model
code from that. Using those APIs you could implement a mapping of
instance in Java. Nothing will generate a transformation for you.

smilee wrote:
> Hello Ed,
>
> Thank you for giving the reply.
> What exactly I need to do is am having two ecore files. Student.ecore
> and University.ecore.
>
> If i give Student.ecore as input, i have to get University.ecore as
> the output.
> So for that, I am following the procedure ecore2ecore mapping.
>
> Is that the right way to get the model or do I need to do follow any
> other way..
>
> Can you suggest me the procedure to follow that..
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ecore2ecore mapping [message #511447 is a reply to message #510007] Mon, 01 February 2010 15:59 Go to previous message
smilee  is currently offline smilee Friend
Messages: 6
Registered: January 2010
Junior Member
Hi Ed,

I am trying to solve the example from previous posts. I'm providing the link here: http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 9636.html



public static void saveResourceWithMapping() throws IOException{
// Create package registry
EPackage.Registry ePackageRegistry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
EPackage sourcePackage = (EPackage)EPackage.Registry.INSTANCE.getEPackage("http://Met1");
EPackage targetPackage = (EPackage)EPackage.Registry.INSTANCE.getEPackage("http://Met2");




// Map between source namespace and target model location with the target package
//ePackageRegistry.put(sourcePackage.getNsURI(), targetPackage);
ePackageRegistry.put("platform:/resource/Met1/model/Met2.ecore ", targetPackage);


//han
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put
("*", //<--- your file extension
new XMIResourceFactoryImpl() //<--- the class to resource factory
{
public Resource createResource(URI uri)
{
XMIResource xmiResource = new XMIResourceImpl(uri);
return xmiResource;
}
});


// Create new resource set
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.setPackageRegistry(ePackageRegistry);

// Create the input model resource
XMLResource resource = (XMLResource)resourceSet.createResource(URI.createURI("platform:/resource/Met1/src/Mod1.met1 "));

//File

// Create the input mapping resource
//Resource mappingResource = resourceSet.getResource(URI.createURI("platform:/resource/Met1/model/Met1_2_Met2.ecore2xml "), true);

Resource mappingResource = null;
File f = new File("resource/Met1/model/Met1_2_Met2.ecore2xml");
System.out.println(f.exists());
if(f.exists()) {
System.out.println(f.getAbsolutePath());

URI uri;
uri = URI.createFileURI(f.getAbsolutePath());
System.out.println(uri);

mappingResource = resourceSet.getResource(URI.createFileURI(f.getAbsolutePath( )), true);


}


Resource ecoreResource = resourceSet.getResource(URI.createURI("platform:/resource/Met1/model/Met2.ecore "), true);

// Create new mapping registry
Ecore2XMLRegistry ecore2xmlRegistry = new Ecore2XMLRegistryImpl(Ecore2XMLRegistry.INSTANCE);

// Get the mapping information from the input mapping resource
XMLMap myXMLMapping = (XMLMap)EcoreUtil.getObjectByType(mappingResource.getContent s(), Ecore2XMLPackage.eINSTANCE.getXMLMap());

// Map between source namespace and the input mapping information
ecore2xmlRegistry.put(sourcePackage.getNsURI(), myXMLMapping);

// Create new mapping ExtendedMetaData information
ExtendedMetaData extendedMetaData = new Ecore2XMLExtendedMetaData(ePackageRegistry, ecore2xmlRegistry);

// Map save/load option of an XMLResource with the ExtendedMetaData information
Map myMap = new HashMap();
myMap.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
myMap.put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);

// Load and save with the mapping
resource.load(myMap);
resource.setURI(URI.createURI("platform:/resource/Met1/src/Mod1.met2 "));
resource.save(null);
}

public static void main(String[] args) {


/*

File f = new File("resource/Met1/model/Met1_2_Met2.ecore2xml");
System.out.println(f.exists());
if(f.exists()) {
System.out.println(f.getAbsolutePath());

URI uri;
uri = URI.createFileURI(f.getAbsolutePath());
System.out.println(uri);


}
*/

try {
M2MConverter.saveResourceWithMapping();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


We are not getting any output for this and some exceptions are coming. Could you explain me why this happens, also, if possible, can you provide an example for ecore2ecore transformation so that we can understand easily.
Re: ecore2ecore mapping [message #511489 is a reply to message #511447] Mon, 01 February 2010 12:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040807050108090201020105
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

You could have a look at the EMF recipes:

5.1 Recipe: Data Migration
<http://wiki.eclipse.org/EMF/Recipes#Recipe:_Data_Migration>


smilee wrote:
> Hi Ed,
>
> I am trying to solve the example from previous posts. I'm providing
> the link here:
> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 9636.html
>
>
>
> public static void saveResourceWithMapping() throws IOException{
> // Create package registry
> EPackage.Registry ePackageRegistry = new
> EPackageRegistryImpl(EPackage.Registry.INSTANCE);
> EPackage sourcePackage =
> (EPackage)EPackage.Registry.INSTANCE.getEPackage("http://Met1");
> EPackage targetPackage =
> (EPackage)EPackage.Registry.INSTANCE.getEPackage("http://Met2");
>
>
>
>
> // Map between source namespace and target model location with
> the target package
> //ePackageRegistry.put(sourcePackage.getNsURI(), targetPackage);
> ePackageRegistry.put("platform:/resource/Met1/model/Met2.ecore
> ", targetPackage);
>
>
> //han
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(
> ).put
> ("*", //<--- your file extension
> new XMIResourceFactoryImpl() //<--- the class to resource
> factory
> {
> public Resource createResource(URI uri)
> {
> XMIResource xmiResource = new XMIResourceImpl(uri);
> return xmiResource;
> }
> });
>
>
> // Create new resource set
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.setPackageRegistry(ePackageRegistry);
I wonder why you had to replace the registry with your own?
>
> // Create the input model resource
> XMLResource resource =
> (XMLResource)resourceSet.createResource(URI.createURI("platform:/resource/Met1/src/Mod1.met1
> "));
>
> //File
>
> // Create the input mapping resource
> //Resource mappingResource =
> resourceSet.getResource(URI.createURI("platform:/resource/Met1/model/Met1_2_Met2.ecore2xml
> "), true);
>
> Resource mappingResource = null;
> File f = new File("resource/Met1/model/Met1_2_Met2.ecore2xml");
Direct file system access?
> System.out.println(f.exists());
> if(f.exists()) {
> System.out.println(f.getAbsolutePath());
> URI uri;
> uri = URI.createFileURI(f.getAbsolutePath());
> System.out.println(uri);
> mappingResource =
> resourceSet.getResource(URI.createFileURI(f.getAbsolutePath( )), true);
> }
>
>
> Resource ecoreResource =
> resourceSet.getResource(URI.createURI("platform:/resource/Met1/model/Met2.ecore
> "), true);
>
> // Create new mapping registry
> Ecore2XMLRegistry ecore2xmlRegistry = new
> Ecore2XMLRegistryImpl(Ecore2XMLRegistry.INSTANCE);
>
> // Get the mapping information from the input mapping resource
> XMLMap myXMLMapping =
> (XMLMap)EcoreUtil.getObjectByType(mappingResource.getContent s(),
> Ecore2XMLPackage.eINSTANCE.getXMLMap());
> // Map between source namespace and the input mapping information
> ecore2xmlRegistry.put(sourcePackage.getNsURI(), myXMLMapping);
>
> // Create new mapping ExtendedMetaData information
> ExtendedMetaData extendedMetaData = new
> Ecore2XMLExtendedMetaData(ePackageRegistry, ecore2xmlRegistry);
>
> // Map save/load option of an XMLResource with the
> ExtendedMetaData information Map myMap = new HashMap();
> myMap.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,
> Boolean.TRUE);
> myMap.put(XMLResource.OPTION_EXTENDED_META_DATA,
> extendedMetaData);
>
> // Load and save with the mapping
> resource.load(myMap);
>
> resource.setURI(URI.createURI("platform:/resource/Met1/src/Mod1.met2 "));
> resource.save(null);
> }
>
> public static void main(String[] args) {
>
>
> /*
>
> File f = new File("resource/Met1/model/Met1_2_Met2.ecore2xml");
> System.out.println(f.exists());
> if(f.exists()) {
> System.out.println(f.getAbsolutePath());
> URI uri;
> uri = URI.createFileURI(f.getAbsolutePath());
> System.out.println(uri);
> }
> */
>
> try {
> M2MConverter.saveResourceWithMapping();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
>
> We are not getting any output for this and some exceptions are coming.
> Could you explain me why this happens, also, if possible, can you
> provide an example for ecore2ecore transformation so that we can
> understand easily.
It's not as if I can run your example so best to use the debugger rather
than me for your answers.

--------------040807050108090201020105
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
You could have a look at the EMF recipes:<br>
<blockquote><a
href="http://wiki.eclipse.org/EMF/Recipes#Recipe:_Data_Migration"><span
class="tocnumber">5.1</span> <span class="toctext">Recipe: Data
Migration</span></a><br>
</blockquote>
<br>
smilee wrote:
<blockquote cite="mid:hk6tob$han$1@build.eclipse.org" type="cite">Hi
Ed,
<br>
<br>
I am trying to solve the example from previous posts. I'm providing the
link here:
<a class="moz-txt-link-freetext" href=" http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 9636.html"> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 9636.html</a>
<br>
<br>
<br>
<br>
    public static void saveResourceWithMapping() throws IOException{
<br>
        // Create package registry
<br>
        EPackage.Registry ePackageRegistry = new
EPackageRegistryImpl(EPackage.Registry.INSTANCE);
<br>
        EPackage sourcePackage =
(EPackage)EPackage.Registry.INSTANCE.getEPackage(<a class="moz-txt-link-rfc2396E" href="http://Met1">"http://Met1"</a>);
<br>
        EPackage targetPackage =
(EPackage)EPackage.Registry.INSTANCE.getEPackage(<a class="moz-txt-link-rfc2396E" href="http://Met2">"http://Met2"</a>);
<br>
<br>
        <br>
        <br>
<br>
        // Map between source namespace and target model location with
the target package
<br>
        //ePackageRegistry.put(sourcePackage.getNsURI(),
targetPackage);
<br>
        ePackageRegistry.put("platform:/resource/Met1/model/Met2.ecore
", targetPackage);
<br>
<br>
        <br>
        //han
<br>
         Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(
).put
<br>
           ("*", //&lt;--- your file extension
<br>
            new XMIResourceFactoryImpl() //&lt;--- the class to
resource factory
<br>
            {
<br>
              public Resource createResource(URI uri)
<br>
              {
<br>
                XMIResource xmiResource = new XMIResourceImpl(uri);
<br>
                return xmiResource;
<br>
              }
<br>
            });
<br>
<br>
        <br>
        // Create new resource set
<br>
        ResourceSet resourceSet = new ResourceSetImpl();
<br>
        resourceSet.setPackageRegistry(ePackageRegistry);
<br>
</blockquote>
I wonder why you had to replace the registry with your own?<br>
<blockquote cite="mid:hk6tob$han$1@build.eclipse.org" type="cite"><br>
        // Create the input model resource
<br>
        XMLResource resource =
(XMLResource)resourceSet.createResource(URI.createURI("platform:/resource/Met1/src/Mod1.met1
"));
<br>
<br>
        //File
<br>
        <br>
        // Create the input mapping resource
<br>
        //Resource mappingResource =
resourceSet.getResource(URI.createURI("platform:/resource/Met1/model/Met1_2_Met2.ecore2xml
"), true);
<br>
        <br>
        Resource mappingResource = null;
<br>
        File f = new File("resource/Met1/model/Met1_2_Met2.ecore2xml");
<br>
</blockquote>
Direct file system access?<br>
<blockquote cite="mid:hk6tob$han$1@build.eclipse.org" type="cite">        
System.out.println(f.exists());
<br>
         if(f.exists()) {
<br>
             System.out.println(f.getAbsolutePath());
<br>
                          URI uri;
<br>
             uri = URI.createFileURI(f.getAbsolutePath());
<br>
             System.out.println(uri);
<br>
                          mappingResource = 
resourceSet.getResource(URI.createFileURI(f.getAbsolutePath( )), true);
<br>
                                   }
<br>
<br>
        <br>
        Resource ecoreResource =
resourceSet.getResource(URI.createURI("platform:/resource/Met1/model/Met2.ecore
"), true);
<br>
<br>
        // Create new mapping registry
<br>
        Ecore2XMLRegistry ecore2xmlRegistry = new
Ecore2XMLRegistryImpl(Ecore2XMLRegistry.INSTANCE);
<br>
<br>
        // Get the mapping information from the input mapping resource
<br>
        XMLMap myXMLMapping = 
(XMLMap)EcoreUtil.getObjectByType(mappingResource.getContent s(),
Ecore2XMLPackage.eINSTANCE.getXMLMap()); <br>
        // Map between source namespace and the input mapping
information
<br>
        ecore2xmlRegistry.put(sourcePackage.getNsURI(), myXMLMapping);
<br>
<br>
        // Create new mapping ExtendedMetaData information
<br>
        ExtendedMetaData extendedMetaData = new
Ecore2XMLExtendedMetaData(ePackageRegistry, ecore2xmlRegistry);
<br>
<br>
        // Map save/load option of an XMLResource with the
ExtendedMetaData information         Map myMap = new HashMap();
<br>
        myMap.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,
Boolean.TRUE);
<br>
        myMap.put(XMLResource.OPTION_EXTENDED_META_DATA,
extendedMetaData);
<br>
<br>
        // Load and save with the mapping
<br>
        resource.load(myMap);
<br>
       
resource.setURI(URI.createURI("platform:/resource/Met1/src/Mod1.met2
"));
<br>
        resource.save(null);
<br>
    }
<br>
    
<br>
    public static void main(String[] args) {
<br>
        <br>
        <br>
        /*
<br>
        <br>
         File f = new
File("resource/Met1/model/Met1_2_Met2.ecore2xml");
<br>
         System.out.println(f.exists());
<br>
         if(f.exists()) {
<br>
             System.out.println(f.getAbsolutePath());
<br>
                          URI uri;
<br>
             uri = URI.createFileURI(f.getAbsolutePath());
<br>
             System.out.println(uri);
<br>
                                   }
<br>
        */
<br>
        <br>
        try {
<br>
            M2MConverter.saveResourceWithMapping();
<br>
        } catch (IOException e) {
<br>
            // TODO Auto-generated catch block
<br>
            e.printStackTrace();
<br>
        }
<br>
    }
<br>
<br>
<br>
We are not getting any output for this and some exceptions are coming.
Could you explain me why this happens, also, if possible, can you
provide an example for ecore2ecore transformation so that we can
understand easily.
<br>
</blockquote>
It's not as if I can run your example so best to use the debugger
rather than me for your answers.<br>
</body>
</html>

--------------040807050108090201020105--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Any truly good books
Next Topic:Moving from MyEclipse to Eclipse
Goto Forum:
  


Current Time: Fri Apr 26 10:56:22 GMT 2024

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

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

Back to the top