Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Get real Instance of DynamicEObjectImpl
Get real Instance of DynamicEObjectImpl [message #488609] Tue, 29 September 2009 12:51 Go to next message
Patrick Schmitt is currently offline Patrick SchmittFriend
Messages: 87
Registered: July 2009
Member
Hello,
I am working with EMF and oAW Code Generation.
When putting my EMF Element from oAW into Java code I get a DynamicEObjectImpl object instead of real Class instance.
I tried following w/o success:
		if(param instanceof DynamicEObjectImpl)
		{
			DynamicEObjectImpl test = (DynamicEObjectImpl)param;
			Object element=DdfFactory.eINSTANCE.create(test.eClass());
			System.out.println(element);
			
			if(element instanceof SectionNode)
			{
				SectionNode secNode = (SectionNode)element;
                                ......

			}
		
		}


Maybe anybody has a hint how to get the class instance of my DynamicEObjectImpl.

Sincerly
Patrick
Re: Get real Instance of DynamicEObjectImpl [message #488611 is a reply to message #488609] Tue, 29 September 2009 13:07 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 31
Registered: September 2009
Member
Hi Patrick,


I'm not quite familiar with oAW code generation. But I think the following excerpt (taken from "Using Dynamic EMF" at http:// www.openarchitectureware.org/pub/documentation/4.3.1/html/co ntents/emf_tutorial.html) might give you a hint:
Quote:

Note that openArchitectureWare can work completely with dynamic models, there is no reason to generate code. However, if you want to programmatically work with the model, the generated metaclasses (not the editors!) are really helpful. Please also keep in mind: in subsequent parts of the tutorial, you will specify the metaModelPackage in various component configurations in the workflow file, like this:

<metaModel id="mm"
class="org.openarchitectureware.type.emf.EmfMetaModel">
<metaModelPackage value="data.DataPackage"/>
</metaModel>
In case of dynamic EMF, there has no metamodel package been generated. So, you have to specify the metamodel file instead, that is, the .ecore file you just created. Note that the .ecore file has to be in the classpath to make this work.

<metaModel id="mm"
class="org.openarchitectureware.type.emf.EmfMetaModel">
<metaModelFile value="data.ecore"/>
</metaModel>




Best regards,

sas
Re: Get real Instance of DynamicEObjectImpl [message #488625 is a reply to message #488611] Tue, 29 September 2009 13:58 Go to previous messageGo to next message
Patrick Schmitt is currently offline Patrick SchmittFriend
Messages: 87
Registered: July 2009
Member
Thats not the point, in this its just the description how to use ecore models in oAW.... Thanks anyway

News.sascha.gessler.googl wrote on Tue, 29 September 2009 09:07
Hi Patrick,


I'm not quite familiar with oAW code generation. But I think the following excerpt (taken from "Using Dynamic EMF" at http:// www.openarchitectureware.org/pub/documentation/4.3.1/html/co ntents/emf_tutorial.html) might give you a hint:
Quote:

Note that openArchitectureWare can work completely with dynamic models, there is no reason to generate code. However, if you want to programmatically work with the model, the generated metaclasses (not the editors!) are really helpful. Please also keep in mind: in subsequent parts of the tutorial, you will specify the metaModelPackage in various component configurations in the workflow file, like this:

<metaModel id="mm"
class="org.openarchitectureware.type.emf.EmfMetaModel">
<metaModelPackage value="data.DataPackage"/>
</metaModel>
In case of dynamic EMF, there has no metamodel package been generated. So, you have to specify the metamodel file instead, that is, the .ecore file you just created. Note that the .ecore file has to be in the classpath to make this work.

<metaModel id="mm"
class="org.openarchitectureware.type.emf.EmfMetaModel">
<metaModelFile value="data.ecore"/>
</metaModel>




Best regards,

sas

Re: Get real Instance of DynamicEObjectImpl [message #488626 is a reply to message #488609] Tue, 29 September 2009 13:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Hi,

Unless things have changed drastically since I last worked on EMF, you
only get a DynamicEObjectImpl in the cases where the dynamic class (i.e.
comes from any package that is only a .ecore file and no code is
generated for the package) does NOT inherit from any code generated
class. In other words none of the eClass' supertypes, all of the way up
to the root, are generated classes. If any of the primary supertypes is
a generated class, then the first eclass that is generated then the
instance class for that eClass will be the instance for the dynamic object.

So if one of your dynamic eclasses inherits from SectionNode, then the
instance at runtime will not be a DynamicEObjectImpl but instead will be
directly a SectionNode instead.

So basically you should never cast directly to DynamicEObjectImpl. That
is an implementation class and not a class interface.


Patrick Schmitt wrote:
> Hello,
> I am working with EMF and oAW Code Generation.
> When putting my EMF Element from oAW into Java code I get a
> DynamicEObjectImpl object instead of real Class instance.
> I tried following w/o success:
>
> if(param instanceof DynamicEObjectImpl)
> {
> DynamicEObjectImpl test = (DynamicEObjectImpl)param;
> Object element=DdfFactory.eINSTANCE.create(test.eClass());
> System.out.println(element);
>
> if(element instanceof SectionNode)
> {
> SectionNode secNode = (SectionNode)element;
> ......
>
> }
>
> }
>
>
> Maybe anybody has a hint how to get the class instance of my
> DynamicEObjectImpl.
>
> Sincerly
> Patrick
>

--
Thanks,
Rich Kulp
Re: Get real Instance of DynamicEObjectImpl [message #488629 is a reply to message #488626] Tue, 29 September 2009 14:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Hi,

One more point, the only reason I can think that SectionNode would be a
generated class, but you still get a DynamicEObjectImpl for a
SectionNode would be that the EPackage that SectionNode is defined in is
not correctly registered as a code generated package. Instead its ecore
file is registered. In that way the SectionNode eClass would also be
considered dynamic and not generated.

--
Thanks,
Rich Kulp
Re: Get real Instance of DynamicEObjectImpl [message #488759 is a reply to message #488609] Wed, 30 September 2009 07:37 Go to previous messageGo to next message
Patrick Schmitt is currently offline Patrick SchmittFriend
Messages: 87
Registered: July 2009
Member
What does that mean, is there a way to get a real class instance ??
Re: Get real Instance of DynamicEObjectImpl [message #488765 is a reply to message #488759] Wed, 30 September 2009 08:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Patrick,

Part of the problem here is that you've provided next to zero
information to indicate what you're actually doing to end up with
dynamic instances nor why you would expect to have instance of your
generated model instead. This lack of information will result in very
general answers that don't appear to help you. Perhaps you'll consider
elaborating on your question.


Patrick Schmitt wrote:
> What does that mean, is there a way to get a real class instance ??


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Get real Instance of DynamicEObjectImpl [message #488770 is a reply to message #488765] Wed, 30 September 2009 08:28 Go to previous messageGo to next message
Patrick Schmitt is currently offline Patrick SchmittFriend
Messages: 87
Registered: July 2009
Member
Okey, so i will describe it better...

- I created a ecore model and from that a genmodel...
- Then I generated the model code, edit code and editor code, started the editor and build a model based on my ecore.
- After that i created a mwe workflow using the xmi reader and xpand2 generator to create code of my model.

In my Xpand file i tried to put the the Section Node instance to my java code:
«DEFINE menuNodeStruct FOR SectionNode»
static node DDF_MENUNODE _node«setMenuNodeID(this)»«this.nodeID»
«EXPAND menuNodeStruct FOREACH this.menuNode»
«ENDDEFINE»


Xtend:
import ddf;
Void setMenuNodeID(ddf::SectionNode item): JAVA ddf.core.helper.setMenuNodeID(ddf.SectionNode)


Problem is that the SectionNode i give as parameter to the java function is no real object, its just a DynamicEObjectImpl instance.

I dont know how to get the real instance of my SectionNode...

Hope now you better understand my intention,

Kind Regards
Patrick
Re: Get real Instance of DynamicEObjectImpl [message #488785 is a reply to message #488770] Wed, 30 September 2009 08:47 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Patrick Schmitt wrote:
> Okey, so i will describe it better...
>
> - I created a ecore model and from that a genmodel... - Then I
> generated the model code, edit code and editor code, started the
> editor and build a model based on my ecore.
> - After that i created a mwe workflow using the xmi reader and xpand2
> generator to create code of my model.
>
> In my Xpand file i tried to put the the Section Node instance to my
> java code:
>
> «DEFINE menuNodeStruct FOR SectionNode»
> static node DDF_MENUNODE _node«setMenuNodeID(this)»«this.nodeID»
> «EXPAND menuNodeStruct FOREACH this.menuNode»
> «ENDDEFINE»
>
>
> Xtend:
>
> import ddf;
> Void setMenuNodeID(ddf::SectionNode item): JAVA
> ddf.core.helper.setMenuNodeID(ddf.SectionNode)
>
>
> Problem is that the SectionNode i give as parameter to the java
> function is no real object, its just a DynamicEObjectImpl instance.
>
> I dont know how to get the real instance of my SectionNode...
I'm not sure under the covers how the instance is being read by oAW.
What EMF itself does is look at the XML namespace of the root element
and it tried to use
EPackage.Registry.INSTANCE.getEPackage(<namespace>). Whatever that
returns is used to resolve names in that namespace and ultimate the
factory of that package is used to create all the instances.
Therefore, your generated package needs to be registered. I'm not sure
how to ensure that this happens in your oAW environment. In an OSGi
application, the plugin.xml registry normally ensure this is done.
>
> Hope now you better understand my intention,
>
> Kind Regards
> Patrick


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Multiple instances of an application
Next Topic:custom emf output to a special format
Goto Forum:
  


Current Time: Wed Sep 25 18:42:41 GMT 2024

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

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

Back to the top