Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Reflective access to generated classes
Reflective access to generated classes [message #1691632] Wed, 08 April 2015 16:06 Go to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
Hi,

I am struggling with reflective access to the fields of my generated classes.
So this works for me in one model but not in the other:

ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(EPackage.Registry.INSTANCE);
List<EStructuralFeature> allContent = extendedMetaData.getAllElements(testObject.eClass())


I am not able to track the difference between the model which works and the one
which does not. Does anyone know how to enable this reflective access?

Thank you!

[Updated on: Wed, 08 April 2015 16:09]

Report message to a moderator

Re: Reflective acces to generated classes [message #1691634 is a reply to message #1691632] Wed, 08 April 2015 16:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
Registered: July 2009
Senior Member
Alexander,

What's returned will depend on the extended metadata annotations on the
model. If it has none, the list will be empty. Most models will not
have such annotations...


On 08/04/2015 6:06 PM, Alexander Klatt wrote:
> Hi,
>
> I am struggling with reflective access to the fields of my generated
> classes.
> So this works for me in one model but not in the other:
>
>
> ExtendedMetaData extendedMetaData = new
> BasicExtendedMetaData(EPackage.Registry.INSTANCE);
> List<EStructuralFeature> allContent =
> extendedMetaData.getAllElements(testObject.eClass())
>
>
> I am not able to track the difference between the model which works
> and the one which does not. Does anyone know how to enable this
> reflective access?
>
> Thank you!
Re: Reflective acces to generated classes [message #1691638 is a reply to message #1691634] Wed, 08 April 2015 16:34 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
Okay thanks, this makes sense. I was only looking at the property view...
The model which worked, was created from an xsd schema. So the annotations were created automatically.

So I guess the standard approach for reflective access is as follows?

List<EStructuralFeature> allContent = testObject.eClass().getEAllStructuralFeatures()

[Updated on: Wed, 08 April 2015 16:43]

Report message to a moderator

Re: Reflective acces to generated classes [message #1691683 is a reply to message #1691638] Thu, 09 April 2015 04:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
Registered: July 2009
Senior Member
Alexander,

You can manually create extended metadata annotations for an Ecore
model. But I'm not sure your goal. Why not use
testObject.eClass().getEAllStructuralFeatures()? What are you hoping to
achieve knowing about elements versus attributes in the XML
serialization? You might use
ExtendedMetaData.getFeatureKind(EStructuralFeature) to determine for
your goal, but without knowing what you're trying to achieve, it's hard
to give advice. For example, a cross reference might be serialized as
attribute or as an element, depending on what options are passed to the
resource implementation, e.g.,
org.eclipse.emf.ecore.xmi.XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, so
just looking at the model seems unhelpful...


On 08/04/2015 6:34 PM, Alexander Klatt wrote:
> Okay thanks, this makes sense. I was only looking at the property view...
> The model which worked, was created from an xsd schema. So the
> annotations were created automatically.
>
> Is there any other way to get reflective access for manually created
> ecore models?
Previous Topic:Using CDOModificationTrackingAdapter
Next Topic:[EMF] ResourceSetImpl.getResource does not behave in the same way calling it twice
Goto Forum:
  


Current Time: Fri Aug 23 22:51:41 GMT 2019

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

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

Back to the top