Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Referenced model(Get referenced model element's generated factory)
Referenced model [message #1704153] Fri, 07 August 2015 17:32 Go to next message
Adam Lengyel is currently offline Adam LengyelFriend
Messages: 8
Registered: October 2014
Junior Member
Hello,

I have some problem with referenced models. I have two metamodel:

/* The first one */
Configuration {
configDescriptors : ConfigurationDescriptor [0..*]
}

ConfigurationDescriptor {
elementType : EClass [1..1]
}
/* End of first metamodel */

/* The second one */
Foo {
fooAs : FooA [0..*]
fooBs : FooB [0..*]
fooCs : FooC [0..*]
}
FooA {...}
FooB {...}
FooC {...}
/* End of second metamodel */

When I create an instance model (lets name it sample.configuration) from the Configuration, I create a new ConfigurationDescriptor element, and set the elementType reference to FooA from the second metamodel. For this, I load the resource using the "Browse Registered Packages" option in the editor. Until this point, everything is fine.

In the Runtime Eclipse I try to load the created resource (sample.configuration) like this:

String uri = "/foo.project/model/sample.configuration";

ResourceSet rset = new ResourceSetImpl();
Resource res = rset.getResource(URI.createPlatformResourceURI(uri, true), true);

Configuration root = (Configuration) res.getContents().get(0);
ConfigurationDescriptor configDescriptor = root.getConfigDescriptors().get(0);

EClass elementType = configDescriptor.getElementType();
//Until this point, it's OK

/* The problematic part */
EcoreUtil.create(elementType); //<= the result of this operation is a DynamicEObjectImpl-type element instead of FooA



If I do it like below, everything is fine:
EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(elementType.getEPackage().getNsURI());
ePackage.getEFactoryInstance().create(elementType); //<=this creates a FooA-type element


I don't really understand why it is not working, because I thought that if I call elementType.getEPackage().getEFactoryInstance() I get the generated EFactory which belongs to the EClass. But instead of this, I get an other implementation, which creates that DynamicEObject...

My question is that is it possible to create element with the given type using the EcoreUtil.create() method like above? What is the reason, why I can't get the generated factory using this referenced EClass element?

Thanks,
Adam
Re: Referenced model [message #1704183 is a reply to message #1704153] Sat, 08 August 2015 07:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Adam,

Comments below.


On 07/08/2015 7:32 PM, Adam Lengyel wrote:
> Hello,
>
> I have some problem with referenced models. I have two metamodel:
>
> /* The first one */
> Configuration {
> configDescriptors : ConfigurationDescriptor [0..*]
> }
>
> ConfigurationDescriptor {
> elementType : EClass [1..1]
> }
> /* End of first metamodel */
>
Which notation is this?
> /* The second one */
> Foo {
> fooAs : FooA [0..*]
> fooBs : FooB [0..*]
> fooCs : FooC [0..*]
> }
> FooA {...}
> FooB {...}
> FooC {...}
> /* End of second metamodel */
>
> When I create an instance model (lets name it sample.configuration)
> from the Configuration, I create a new ConfigurationDescriptor
> element, and set the elementType reference to FooA from the second
> metamodel.
Have you generated the model and are doing this via generated code?

And for FooA, where did this EClass instance come from? From loading
"second metamodel".ecore, or using SecondMetaModel.Literals.FOO_A?
> For this, I load the resource using the "Browse Registered Packages"
> option in the editor. Until this point, everything is fine.

Did you pick Development time version or Runtime version?
>
> In the Runtime Eclipse I try to load the created resource
> (sample.configuration) like this:
>
> String uri = "/foo.project/model/sample.configuration";
>
> ResourceSet rset = new ResourceSetImpl();
> Resource res = rset.getResource(URI.createPlatformResourceURI(uri,
> true), true);
>
> Configuration root = (Configuration) res.getContents().get(0);
> ConfigurationDescriptor configDescriptor =
> root.getConfigDescriptors().get(0);
>
> EClass elementType = configDescriptor.getElementType();
> //Until this point, it's OK
>
> /* The problematic part */
> EcoreUtil.create(elementType); //<= the result of this operation
> is a DynamicEObjectImpl-type element instead of FooA
So it sounds like you're referencing the development time version, not
the generated runtime version.
>
>
>
> If I do it like below, everything is fine:
> EPackage ePackage =
> EPackage.Registry.INSTANCE.getEPackage(elementType.getEPackage().getNsURI());
> ePackage.getEFactoryInstance().create(elementType); //<=this
> creates a FooA-type element
Yes, that's the runtime version of the model.
>
>
> I don't really understand why it is not working, because I thought
> that if I call elementType.getEPackage().getEFactoryInstance() I get
> the generated EFactory which belongs to the EClass. But instead of
> this, I get an other implementation, which creates that DynamicEObject...
If you have a dynamically loaded Ecore model, such as the development
time version used along with the GenModel to generated the code, then
you'll end up with dynamic instances. If you use the runtime (generally
generated) version of the model, you'll of course get the usual behavior
of creating the generated instances.
>
> My question is that is it possible to create element with the given
> type using the EcoreUtil.create() method like above? What is the
> reason, why I can't get the generated factory using this referenced
> EClass element?
Because you're not using the generated model. So be sure to choose the
Runtime version in the dialog when you load the resource. And have a
close look at the difference in serialization between the Development
time version and the Runtime version, i.e., the former refers to the
*.ecore in the model folder of the bundle, that later refers to the
model via its nsURI.
>
> Thanks,
> Adam


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Referenced model [message #1704235 is a reply to message #1704183] Sun, 09 August 2015 16:20 Go to previous messageGo to next message
Adam Lengyel is currently offline Adam LengyelFriend
Messages: 8
Registered: October 2014
Junior Member
I generated the model code for both metamodels (Configuration and Foo). In the Runtime-Eclipse I created the sample.configuration model, opened it with Sample Ecore Model Editor, and there I used the Load resource...=>Browse Registered Packages option. Here, I selected the Development Time Version of the model (I got an URI like this: platform:/plugin/foo.project/model/foo.ecore). After that, I set the ConfigurationDescriptor element's elementType reference to FooA (from the foo.ecore model).

Based on your suggestions, I tried to select the runtime version of the model, but after that I got the following message:
Runtime packages are not displayed in the editor
Reason:
Runtime packages are registered in the package registry and are not loaded as resources so while the package contents will be available for setting properties, they will not be displayed directly. Click details to see the list of successfully loaded runtime packages


I checked the details, and it showed my model was successfully loaded. If I understand this message correctly, now I should be able to "use" the content of the loaded package; in my case I should be able to set the ConfigurationDescriptor element's elementType reference to FooA from the loaded package, but unfortunately I can't "see" the content of the loaded package when I try to set the reference. Am I doing something wrong? How should I do this?

Thank you for your help!

Adam
Re: Referenced model [message #1704271 is a reply to message #1704235] Mon, 10 August 2015 05:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Adam,

Comments below.

On 09/08/2015 6:20 PM, Adam Lengyel wrote:
> I generated the model code for both metamodels (Configuration and
> Foo). In the Runtime-Eclipse I created the sample.configuration model,
> opened it with Sample Ecore Model Editor, and there I used the Load
> resource...=>Browse Registered Packages option. Here, I selected the
> Development Time Version of the model (I got an URI like this:
> platform:/plugin/foo.project/model/foo.ecore). After that, I set the
> ConfigurationDescriptor element's elementType reference to FooA (from
> the foo.ecore model).
>
> Based on your suggestions, I tried to select the runtime version of
> the model, but after that I got the following message:
> Runtime packages are not displayed in the editor
> Reason:
> Runtime packages are registered in the package registry and are not
> loaded as resources so while the package contents will be available
> for setting properties, they will not be displayed directly. Click
> details to see the list of successfully loaded runtime packages
Yes, that's normal.
>
> I checked the details, and it showed my model was successfully loaded.
> If I understand this message correctly, now I should be able to "use"
> the content of the loaded package; in my case I should be able to set
> the ConfigurationDescriptor element's elementType reference to FooA
> from the loaded package, but unfortunately I can't "see" the content
> of the loaded package when I try to set the reference.
I.e., it's not in the drop-down combo choices...
> Am I doing something wrong? How should I do this?
In the Ecore model, all the property descriptors inherit from
org.eclipse.emf.ecore.provider.EModelElementItemProvider.ItemPropertyDescriptorWithUniqueChoiceOfValueLabels.getChoiceOfValues(Object)
which visits the packages in the resource set's local package registry
(and the load resource action registers the runtime package to that
registry). You'll need to do something similar.
>
> Thank you for your help!
>
> Adam


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Referenced model [message #1704911 is a reply to message #1704271] Mon, 10 August 2015 14:59 Go to previous messageGo to next message
Adam Lengyel is currently offline Adam LengyelFriend
Messages: 8
Registered: October 2014
Junior Member
I checked the source code of the class you mentioned, the source code of the Sample Ecore Model Editor and the source code of my generated editor (for Configuration metamodel) too.
As far as I understand the operation of these editors (Sample Ecore Model Editor and my generated editor), they will only list those appropriate objects e.g. in a drop-down combo, which belong to the used ResourceSet. When I load a resource with a packageNS, the loaded resource won't be added to the used ResourceSet, and because of this I won't see the appropriate elements in the drop-down combo (for example in my case FooA, FooB, ...).

So if I want to use the runtime version of my model in the editor, I should modify e.g. the generated editor to operate similarly like this org.eclipse.emf.ecore.provider.EModelElementItemProvider.ItemPropertyDescriptorWithUniqueChoiceOfValueLabels? Is it right, or did I misunderstand something?

Adam
Re: Referenced model [message #1704951 is a reply to message #1704911] Tue, 11 August 2015 06:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Adam,

Comments below.

On 10/08/2015 4:59 PM, Adam Lengyel wrote:
> I checked the source code of the class you mentioned, the source code
> of the Sample Ecore Model Editor and the source code of my generated
> editor (for Configuration metamodel) too.
> As far as I understand the operation of these editors (Sample Ecore
> Model Editor and my generated editor), they will only list those
> appropriate objects e.g. in a drop-down combo, which belong to the
> used ResourceSet. When I load a resource with a packageNS, the loaded
> resource won't be added to the used ResourceSet, and because of this I
> won't see the appropriate elements in the drop-down combo (for example
> in my case FooA, FooB, ...).
>
> So if I want to use the runtime version of my model in the editor, I
> should modify e.g. the generated editor to operate similarly like this
> org.eclipse.emf.ecore.provider.EModelElementItemProvider.ItemPropertyDescriptorWithUniqueChoiceOfValueLabels?
> Is it right, or did I misunderstand something?
Yes, that's right.
>
> Adam


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Referenced model [message #1705001 is a reply to message #1704951] Tue, 11 August 2015 11:15 Go to previous message
Adam Lengyel is currently offline Adam LengyelFriend
Messages: 8
Registered: October 2014
Junior Member
Ed,

Thank you very much!
Previous Topic:[EMFStore] Redo capability
Next Topic:Problem installing EMF updates with Juno For Java Developers!! Help Please!
Goto Forum:
  


Current Time: Sat Apr 20 03:25:04 GMT 2024

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

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

Back to the top