Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Henshin] Loading a model from an Xtext resource
[Henshin] Loading a model from an Xtext resource [message #651794] Tue, 01 February 2011 16:00 Go to next message
Domenik P. is currently offline Domenik P.Friend
Messages: 3
Registered: February 2011
Junior Member
Hi,

I'm trying to process a model, that I've created in an Xtext editor.

My problem is, that my Henshin rule doesn't match, if I load the model from an Xtex resource. See the following code:

URI javaURI = URI.createFileURI(new File("model/Java.ecore").getAbsolutePath());
Resource jResource = resourceSet.getResource(javaURI, true);
Resource resource = resourceSet.createResource(URI.createURI("dummy:/mode /JavaProgram.java"));
InputStream in = new ByteArrayInputStream("type foo type bar".getBytes());
try {
   resource.load(in, resourceSet.getLoadOptions());
} catch (IOException e1) {
   // TODO Auto-generated catch block
   e1.printStackTrace();
}
EObject javaProg = resource.getContents().get(0);


If I load the model from a dynamic instance (XMI file) in a reflective way, then the Henshin rules finds a match and executes the transformation. The code below shows how I load the model from the xmi file:

URI javaURI = URI.createFileURI(new File("model/Java.ecore") .getAbsolutePath());
Resource jResource = resourceSet.getResource(javaURI, true);
EObject javaProg = resourceSet.getResource(URI.createFileURI(new File("model/JavaProgram2.xmi").getAbsolutePath()), true).getContents().get(0);


Does Henshin currently only support the processing of dynamic instances?


Regards
Domenik
Re: [Henshin] Loading a model from an Xtext resource [message #654338 is a reply to message #651794] Tue, 15 February 2011 09:17 Go to previous message
Stefan Jurack is currently offline Stefan JurackFriend
Messages: 24
Registered: February 2010
Junior Member
Hi Domenik,

first of all: sorry for the late reply. If hope this response helps anyway.

Generally, to Henshin is does not matter if which way an instance model
has been created. The important thing is, that the types of the instance
model and the types used in a Henshin transformation system are to be
the *same*. E.g., in a transformation system you may import an ecore
file (and use its types) by (relative/absolute) path or alternatively by
its namespace URI. If you do one or the other, your instance model has
to be typed over the same way. Otherwise, the types are not the *same*
in memory. Consequently no match can be found.

I guess this may be the problem. You probably created the dynamic XMI
instance using a relative path to the ecore model, while loading your
dummy ByteArray instance (probably?) leads to an instance model typed
using the namespace URI of the metamodel. (Find out by saving it and
have a look at its xml content.)

The final question is, in which manner the Java ecore model has been
imported in your Henshin transformtion system. For this you may have a
look inside the .henshin file with a text editor. I assume you use a
path equal to your XMI instance only.

Cheers,
Stefan


Am 01.02.2011 17:00, schrieb Domenik P.:
> Hi,
>
> I'm trying to process a model, that I've created in an Xtext editor.
>
> My problem is, that my Henshin rule doesn't match, if I load the model
> from an Xtex resource. See the following code:
>
>
> URI javaURI = URI.createFileURI(new
> File("model/Java.ecore").getAbsolutePath());
> Resource jResource = resourceSet.getResource(javaURI, true);
> Resource resource =
> resourceSet.createResource(URI.createURI("dummy:/mode /JavaProgram.java"));
> InputStream in = new ByteArrayInputStream("type foo type bar".getBytes());
> try {
> resource.load(in, resourceSet.getLoadOptions());
> } catch (IOException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
> EObject javaProg = resource.getContents().get(0);
>
>
> If I load the model from a dynamic instance (XMI file) in a reflective
> way, then the Henshin rules finds a match and executes the
> transformation. The code below shows how I load the model from the xmi
> file:
>
>
> URI javaURI = URI.createFileURI(new File("model/Java.ecore")
> .getAbsolutePath());
> Resource jResource = resourceSet.getResource(javaURI, true);
> EObject javaProg = resourceSet.getResource(URI.createFileURI(new
> File("model/JavaProgram2.xmi").getAbsolutePath()),
> true).getContents().get(0);
>
>
> Does Henshin currently only support the processing of dynamic instances?
>
>
> Regards
> Domenik
Previous Topic:Find referenced Objects
Next Topic:EEF liveEditingDomain issue
Goto Forum:
  


Current Time: Sun Nov 01 02:23:44 GMT 2020

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

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

Back to the top