Skip to main content



      Home
Home » Modeling » EMF » Reflective access to generated classes
Reflective access to generated classes [message #1691632] Wed, 08 April 2015 12:06 Go to next message
Eclipse UserFriend
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 12:09] by Moderator

Re: Reflective acces to generated classes [message #1691634 is a reply to message #1691632] Wed, 08 April 2015 12:17 Go to previous messageGo to next message
Eclipse UserFriend
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 12:34 Go to previous messageGo to next message
Eclipse UserFriend
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 12:43] by Moderator

Re: Reflective acces to generated classes [message #1691683 is a reply to message #1691638] Thu, 09 April 2015 00:22 Go to previous message
Eclipse UserFriend
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: Sun Jul 27 02:09:39 EDT 2025

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

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

Back to the top