Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » inter-model references - java code
inter-model references - java code [message #62411] Tue, 25 September 2007 18:40 Go to next message
Eclipse UserFriend
Originally posted by: heggly.gmx.net

Hi everyone,

Im using inter-model references in my metamodel. After enabling inter-model
references in the launch configuration
everything works fine. I only get problems when trying to invoke the
transformation with java:

Im trying to load a model conforming to ecore with the following java code:

AtlEMFModelHandler amh =
(AtlEMFModelHandler)AtlModelHandler.getDefault(AtlModelHandl er.AMH_EMF);
ASMModel model = amh.loadModel("IN", amh.getMof(), modelURI);

which gives me the exception:
org.eclipse.m2m.atl.drivers.emf4atl.ASMEMFModel addReferencedExtentsFor
WARNUNG: Resource for org.eclipse.emf.ecore.impl.EClassImpl@10bbf9e
(eProxyURI:
http://.../language/componentmodel.ecore#//AbstractFragmentT ype) is null;
cannot be referenced

Are inter-model references not supported at all or is there any way to do
this?

Best regards,
Felix F
Re: [ATL] inter-model references - java code [message #62435 is a reply to message #62411] Tue, 25 September 2007 19:28 Go to previous messageGo to next message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hi,

Could you please remember to use the appropriate prefix in the subject
of your posts? (see http://wiki.eclipse.org/M2M)


Is your transformation taking an Ecore metamodel as source:

create OUT : TargetMM from IN : Ecore;

?


Regards,

Frédéric Jouault


Felix Förster wrote:
> Hi everyone,
>
> Im using inter-model references in my metamodel. After enabling inter-model
> references in the launch configuration
> everything works fine. I only get problems when trying to invoke the
> transformation with java:
>
> Im trying to load a model conforming to ecore with the following java code:
>
> AtlEMFModelHandler amh =
> (AtlEMFModelHandler)AtlModelHandler.getDefault(AtlModelHandl er.AMH_EMF);
> ASMModel model = amh.loadModel("IN", amh.getMof(), modelURI);
>
> which gives me the exception:
> org.eclipse.m2m.atl.drivers.emf4atl.ASMEMFModel addReferencedExtentsFor
> WARNUNG: Resource for org.eclipse.emf.ecore.impl.EClassImpl@10bbf9e
> (eProxyURI:
> http://.../language/componentmodel.ecore#//AbstractFragmentT ype) is null;
> cannot be referenced
>
> Are inter-model references not supported at all or is there any way to do
> this?
>
> Best regards,
> Felix Förster.
>
>
Re: [ATL] inter-model references - java code [message #62483 is a reply to message #62435] Wed, 26 September 2007 07:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: heggly.gmx.net

Hi,

actually it does not matter. I didn't even launch the transformation yet.
All I do is trying to load the ASMModel which is stored in my workspace and
contains some references.

e.g.
<eClassifiers xsi:type="ecore:EClass" name="ReuseAbstraction">
<eStructuralFeatures xsi:type="ecore:EReference" name="reuselanguage"
lowerBound="1"
eType="ecore:EClass
http://www-st.inf.tu-dresden.de/reuseware/language/component model.ecore#//AbstractFragmentType"
containment="true"/>
....

2)
Is it possible to transform an ASMModel (output) to a List of EObjects or
one EObject which is the root element of the model tree?
I tried using
amh.saveModel(asmModel, outputstream);
InputStream inputstream = new
ByteArrayInputStream(outputstream.toByteArray());
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(cwd);
try {
resource.load(inputstream, Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
EObject root = resource.getContents().get(0);

throws:
Exception in thread "main" java.lang.IllegalStateException: Workspace is
closed.
at
org.eclipse.core.resources.ResourcesPlugin.getWorkspace(Reso urcesPlugin.java:326)
at
org.eclipse.m2m.atl.engine.AtlEMFModelHandler.saveModel(AtlE MFModelHandler.java:144)
at
org.eclipse.m2m.atl.engine.AtlEMFModelHandler.saveModel(AtlE MFModelHandler.java:65)

> Hi,
>
> Could you please remember to use the appropriate prefix in the subject of
> your posts? (see http://wiki.eclipse.org/M2M)
>
>
> Is your transformation taking an Ecore metamodel as source:
>
> create OUT : TargetMM from IN : Ecore;
>
> ?
>
>
> Regards,
>
> Fr
Re: [ATL] inter-model references - java code [message #62543 is a reply to message #62411] Wed, 26 September 2007 08:35 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 147
Registered: July 2009
Senior Member
Felix Förster schreef:
> Hi everyone,
>

Hi Felix,


> Im using inter-model references in my metamodel. After enabling inter-model
> references in the launch configuration
> everything works fine. I only get problems when trying to invoke the
> transformation with java:
>
> Im trying to load a model conforming to ecore with the following java code:
>
> AtlEMFModelHandler amh =
> (AtlEMFModelHandler)AtlModelHandler.getDefault(AtlModelHandl er.AMH_EMF);
> ASMModel model = amh.loadModel("IN", amh.getMof(), modelURI);
>
> which gives me the exception:
> org.eclipse.m2m.atl.drivers.emf4atl.ASMEMFModel addReferencedExtentsFor
> WARNUNG: Resource for org.eclipse.emf.ecore.impl.EClassImpl@10bbf9e
> (eProxyURI:
> http://.../language/componentmodel.ecore#//AbstractFragmentT ype) is null;
> cannot be referenced
>
> Are inter-model references not supported at all or is there any way to do
> this?

The error you get happens when the meta-model is not found/loaded. If
you're using an Ecore meta-model by URI, ATL waits for Eclipse to load
and register the meta-model. As soon as you load your model, its Ecore
meta-model should be available. Apparently, this did not happen in your
case.

Outside Eclipse, you must load and register Ecore meta-models yourself:
http://wiki.eclipse.org/index.php/EMF-FAQ#I_get_a_PackageNot FoundException:_e.g..2C_.22Package_with_uri_.27http:.2F.2Fco m.example.company.ecore.27_not_found..22_What_do_I_need_to_d o.3F

>
> Best regards,
> Felix Förster.
>
>

Hope this helps..
Dennis
Re: [ATL] inter-model references - java code [message #62570 is a reply to message #62483] Wed, 26 September 2007 08:51 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 147
Registered: July 2009
Senior Member
Felix Förster schreef:
> Hi,
>
> actually it does not matter. I didn't even launch the transformation yet.
> All I do is trying to load the ASMModel which is stored in my workspace and
> contains some references.

ok, so you're accessing your workspace...?

>
> e.g.
> <eClassifiers xsi:type="ecore:EClass" name="ReuseAbstraction">
> <eStructuralFeatures xsi:type="ecore:EReference" name="reuselanguage"
> lowerBound="1"
> eType="ecore:EClass
> http://www-st.inf.tu-dresden.de/reuseware/language/component model.ecore#//AbstractFragmentType"
> containment="true"/>
> ...
>
> 2)
> Is it possible to transform an ASMModel (output) to a List of EObjects or
> one EObject which is the root element of the model tree?
> I tried using
> amh.saveModel(asmModel, outputstream);
> InputStream inputstream = new
> ByteArrayInputStream(outputstream.toByteArray());
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet.createResource(cwd);
> try {
> resource.load(inputstream, Collections.EMPTY_MAP);
> } catch (IOException e) {
> e.printStackTrace();
> }
> EObject root = resource.getContents().get(0);
>
> throws:
> Exception in thread "main" java.lang.IllegalStateException: Workspace is
> closed.
> at
> org.eclipse.core.resources.ResourcesPlugin.getWorkspace(Reso urcesPlugin.java:326)
> at
> org.eclipse.m2m.atl.engine.AtlEMFModelHandler.saveModel(AtlE MFModelHandler.java:144)
> at
> org.eclipse.m2m.atl.engine.AtlEMFModelHandler.saveModel(AtlE MFModelHandler.java:65)
>
*snip*

There we are: workspace closed. Your workspace is only accessible from
within Eclipse, i.e. Eclipse plugins and Ant tasks run within the same
Java VM. You cannot access the workspace from normal Java applications.
Java applications are typically run standalone in their own VM, even
when launched from within Eclipse.

In case you were not trying to access the workspace: there's a known bug
in saveModel():
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202069

This bug is fixed in CVS.

Dennis
Re: [ATL] inter-model references - java code [message #62691 is a reply to message #62570] Wed, 26 September 2007 17:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: heggly.gmx.net

Hi,

thanks for your help. I was able to solve most of the problems by using a
plugin istead of a stand-alone application.
I have got one problem left though:

ATL looks like this:

module Test;
create OUT : Persons from IN1 : MOF, IN2 : MOF2;

i.e. I want to use two input models with internal names "MOF" and "MOF2"
conforming to the EMF metamodel. In the launch configuration I can simply
select the checkbox "is metamodel" (handler is EMF) for both MOF and MOF2
and then specify the input files IN1 and IN2. Works fine.
With java code I try to use "handler.getMOF()" to get the metamodel. This
only works fine for the first input model since its default name "MOF"
corresponds to the internal name used in the module.
If I try that with the second model I get the error "message: cannot find
model MOF2". How can I solve this?
I somehow need to change the name of the "handler.getMOF()" returned object
to "MOF2".
Is that possible? How? If not, can I load a new model with name "MOF2" which
is the EMF metamodel? How would I do that?
I hope this was comprehendible.

Best regards,
Felix.

"Dennis Wagelaar" <dennis.wagelaar@vub.ac.be> schrieb im Newsbeitrag
news:fdd6il$i3i$1@build.eclipse.org...
> Felix F
Re: [ATL] inter-model references - java code [message #62737 is a reply to message #62691] Wed, 26 September 2007 20:24 Go to previous messageGo to next message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hi,

> I have got one problem left though:
>
> ATL looks like this:
>
> module Test;
> create OUT : Persons from IN1 : MOF, IN2 : MOF2;
>
> i.e. I want to use two input models with internal names "MOF" and "MOF2"
> conforming to the EMF metamodel. In the launch configuration I can
simply
> select the checkbox "is metamodel" (handler is EMF) for both MOF and
MOF2
> and then specify the input files IN1 and IN2. Works fine.
> With java code I try to use "handler.getMOF()" to get the metamodel.
This
> only works fine for the first input model since its default name "MOF"
> corresponds to the internal name used in the module.
> If I try that with the second model I get the error "message: cannot
find
> model MOF2". How can I solve this?
> I somehow need to change the name of the "handler.getMOF()" returned
object
> to "MOF2".
> Is that possible? How? If not, can I load a new model with name
"MOF2" which
> is the EMF metamodel? How would I do that?

The name of the metamodel in the ATL program (e.g., MOF, MOF2) should be
used as the key when you build the map of models.
For instance:

Map models = new HashMap();
models.put("MOF", handler.getMOF());
models.put("MOF2", handler.getMOF());


May I ask why you use two different names instead of just one?


> I hope this was comprehendible.

Hopefully, this message answers your question ;-).


Regards,

Frédéric Jouault
Re: [ATL] inter-model references - java code [message #62801 is a reply to message #62737] Thu, 27 September 2007 12:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: heggly.gmx.net

Hey,

> Hi,
>
>
> The name of the metamodel in the ATL program (e.g., MOF, MOF2)
> should be used as the key when you build the map of models.
> For instance:
>
> Map models = new HashMap();
> models.put("MOF", handler.getMOF());
> models.put("MOF2", handler.getMOF());
>

OK. I thought the name of the metamodel (returned by
"model.getName()") should be the name of the metamodel in the ATL
program.

>
> May I ask why you use two different names instead of just one?
>

Well, I simply want to have to different matching rules for two
different input models.
e.g.
--matches Eclasses from inputModel IN
from
class: MOF!EClass
to ....

and
--matches EClasses from inputModel IN2
from
class : MOF2!EClass
to...

Am I doing something too complicated? But it works now!

2)
I use
handler.saveModel(model, uri);
to save back the ecore file.
The file is saved to the right place but I still get a
ResourceException whether the file exists or not. Does anyone know
where that comes from?
(see below)

Thanks, regards,
Felix.


Resource
'/Dokumente%20und%20Einstellungen/ich/workspace/ATLInvocatio n/models/test.ecore'
does not exist.
org.eclipse.core.internal.resources.ResourceException: Resource
'/Dokumente%20und%20Einstellungen/ich/workspace/ATLInvocatio n/models/test.ecore'
does not exist.
at
org.eclipse.core.internal.resources.Resource.checkExists(Res ource.java:310)
at
org.eclipse.core.internal.resources.Resource.checkAccessible (Resource.java:193)
at
org.eclipse.core.internal.resources.Resource.setDerived(Reso urce.java:1478)
at
org.eclipse.m2m.atl.engine.AtlEMFModelHandler.saveModel(AtlE MFModelHandler.java:145)
at
org.eclipse.m2m.atl.engine.AtlEMFModelHandler.saveModel(AtlE MFModelHandler.java:61)
at atlinvocation.main.ATLInvocation.saveModel(ATLInvocation.jav a:108)
at
atlinvocation.actions.SampleAction.testComogen(SampleAction. java:113)
at atlinvocation.actions.SampleAction.run(SampleAction.java:46)
at
org.eclipse.ui.internal.PluginAction.runWithEvent(PluginActi on.java:256)
at
org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPl uginAction.java:229)
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:545)
at
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:490)
at
org.eclipse.jface.action.ActionContributionItem$6.handleEven t(ActionContributionItem.java:443)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 19)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:289)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:461)
at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:106)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Re: [ATL] inter-model references - java code [message #62817 is a reply to message #62801] Thu, 27 September 2007 13:24 Go to previous messageGo to next message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hi,

>> The name of the metamodel in the ATL program (e.g., MOF, MOF2)
>> should be used as the key when you build the map of models.
>> For instance:
>>
>> Map models = new HashMap();
>> models.put("MOF", handler.getMOF());
>> models.put("MOF2", handler.getMOF());
>>
>
> OK. I thought the name of the metamodel (returned by
> "model.getName()") should be the name of the metamodel in the ATL
> program.
>

This was originally the case. However, ATL now supports complex
transformation chaining (e.g., using ant scripts), which makes this
inappropriate.


>> May I ask why you use two different names instead of just one?
>>
>
> Well, I simply want to have to different matching rules for two
> different input models.
> e.g.
> --matches Eclasses from inputModel IN
> from
> class: MOF!EClass
> to ....
>
> and
> --matches EClasses from inputModel IN2
> from
> class : MOF2!EClass
> to...
>
> Am I doing something too complicated? But it works now!

Well, if you are using ATL 2006, then you could do something like:

--matches Eclasses from inputModel IN
from
class: MOF!EClass in IN1
to ....

and
--matches EClasses from inputModel IN2
from
class : MOF!EClass in IN2
to...


> 2)
> I use
> handler.saveModel(model, uri);
> to save back the ecore file.
> The file is saved to the right place but I still get a
> ResourceException whether the file exists or not. Does anyone know
> where that comes from?
> (see below)

You may need to update to a more recent version (e.g., CVS HEAD).


Regards,

Frédéric Jouault
Re: [ATL] inter-model references - java code [message #62874 is a reply to message #62817] Thu, 27 September 2007 23:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: heggly.gmx.net

Hi,

> >
> > Well, I simply want to have to different matching rules for two
> > different input models.
> > e.g.
> > --matches Eclasses from inputModel IN
> > from
> > class: MOF!EClass
> > to ....
> >
> > and
> > --matches EClasses from inputModel IN2
> > from
> > class : MOF2!EClass
> > to...
> >
> > Am I doing something too complicated? But it works now!
>
> Well, if you are using ATL 2006, then you could do something like:
>
> --matches Eclasses from inputModel IN
> from
> class: MOF!EClass in IN1
> to ....
>
> and
> --matches EClasses from inputModel IN2
> from
> class : MOF!EClass in IN2
> to...
>

Actually I have two helpers that traverse MOF and MOF2 respectively
searching for EClasses with a certain name:

let coll : Sequence(MOF!EClass) =
MOF!EClass.allInstances()->asSequence()->select(...
and
let coll : Sequence(MOF2!EClass) =
MOF2!EClass.allInstances()->asSequence()->select(...

I tried (MOF!EClass in IN2).allInstances()->asSequence()->select(...
that does not work.

Can I still use just one name for the model and use the helpers?

Kind regards,
Felix.
Re: [ATL] inter-model references - java code [message #63142 is a reply to message #62874] Fri, 28 September 2007 19:11 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hi,

> Actually I have two helpers that traverse MOF and MOF2 respectively
> searching for EClasses with a certain name:
>
> let coll : Sequence(MOF!EClass) =
> MOF!EClass.allInstances()->asSequence()->select(...
> and
> let coll : Sequence(MOF2!EClass) =
> MOF2!EClass.allInstances()->asSequence()->select(...
>
> I tried (MOF!EClass in IN2).allInstances()->asSequence()->select(...
> that does not work.
>
> Can I still use just one name for the model and use the helpers?

I would suggest using allInstancesFrom:


let coll : Sequence(MOF!EClass) =
MOF!EClass.allInstancesFrom('IN1')->asSequence()->select(...
and
let coll : Sequence(MOF2!EClass) =
MOF2!EClass.allInstancesFrom('IN2')->asSequence()->select(...


Regards,

Frédéric Jouault
Previous Topic:[ATL] UML profiles, enumerations, same literals in in and out
Next Topic:[ATL] Compiling outside eclipse (part II)
Goto Forum:
  


Current Time: Sat Nov 09 03:35:40 GMT 2024

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

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

Back to the top