|
Re: Get real Instance of DynamicEObjectImpl [message #488611 is a reply to message #488609] |
Tue, 29 September 2009 13:07 |
No real name 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 |
Patrick Schmitt 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 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 #488785 is a reply to message #488770] |
Wed, 30 September 2009 08:47 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.03852 seconds