|
|
|
Re: Dynamic extension of EMF model and getEAllStructuralFeatures [message #686812 is a reply to message #686800] |
Thu, 19 May 2011 17:45 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Daniel,
Comments below.
Daniel Selman wrote:
> I am trying to debug an issue I am seeing with our application (based
> on EMF 2.6.1). We generate Java code from Ecore and then have config
> files that dynamically add properties to EClasses at runtime.
Changing the generated model in any way isn't supported. Things like
feature IDs would just end up being wrong...
>
> What I am seeing is that new dynamic properties show up on the
> EClasses but are not visible on derived classes (using
> getEAllStructureFeatures).
Because that's assumed to be static for a generated model (after freeze
is called during initialization).
>
> E.g. Derived -> MyClass
>
> package mypackage;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.ecore.EAttribute;
> import org.eclipse.emf.ecore.EClass;
> import org.eclipse.emf.ecore.EStructuralFeature;
> import org.eclipse.emf.ecore.EcoreFactory;
> import org.eclipse.emf.ecore.EcorePackage;
>
> public class Main {
> public static void main( String[] args ) {
>
> IlrMypackagePackage pkg = IlrMypackagePackage.eINSTANCE;
> EClass clazz = pkg.getMyClass();
>
> EcorePackage theCorePackage = EcorePackage.eINSTANCE;
> EcoreFactory theCoreFactory = EcoreFactory.eINSTANCE;
>
> EAttribute bookStoreOwner = theCoreFactory.createEAttribute();
> bookStoreOwner.setName("owner");
> bookStoreOwner.setEType(theCorePackage.getEString());
>
> clazz.getEStructuralFeatures().add(bookStoreOwner);
> dumpEClass(clazz);
>
> EClass derivedClazz = pkg.getDerived();
> dumpEClass(derivedClazz);
> }
>
> private static void dumpEClass( EClass clazz ) {
> System.out.println( "======" );
> System.out.println( clazz.getName() );
> EList<EStructuralFeature> list =
> clazz.getEAllStructuralFeatures();
> for (EStructuralFeature eStructuralFeature : list) {
> System.out.println( " " + eStructuralFeature.getName()
> );
> }
> System.out.println( "======" );
> }
> }
>
> private static void dumpEClass( EClass clazz ) {
> System.out.println( "======" );
> System.out.println( clazz.getName() );
> EList<EStructuralFeature> list =
> clazz.getEAllStructuralFeatures();
> for (EStructuralFeature eStructuralFeature : list) {
> System.out.println( " " + eStructuralFeature.getName()
> );
> }
> System.out.println( "======" );
> }
>
> Output:
>
> ======
> MyClass
> secondClass
> Name
> owner
> ======
> ======
> Derived
> secondClass
> Name
> ======
>
> Anyone have any ideas?
If anything, you should be using a dynamic model that extends the
generated model, rather than modifying the generated model directly
(much like you'd extend a Java class, rather than go in and try to munge
the byte code dynamically at runtime).
>
> Thanks,
> Dan
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
Re: Dynamic extension of EMF model and getEAllStructuralFeatures [message #686988 is a reply to message #686800] |
Thu, 19 May 2011 17:45 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Daniel,
Comments below.
Daniel Selman wrote:
> I am trying to debug an issue I am seeing with our application (based
> on EMF 2.6.1). We generate Java code from Ecore and then have config
> files that dynamically add properties to EClasses at runtime.
Changing the generated model in any way isn't supported. Things like
feature IDs would just end up being wrong...
>
> What I am seeing is that new dynamic properties show up on the
> EClasses but are not visible on derived classes (using
> getEAllStructureFeatures).
Because that's assumed to be static for a generated model (after freeze
is called during initialization).
>
> E.g. Derived -> MyClass
>
> package mypackage;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.ecore.EAttribute;
> import org.eclipse.emf.ecore.EClass;
> import org.eclipse.emf.ecore.EStructuralFeature;
> import org.eclipse.emf.ecore.EcoreFactory;
> import org.eclipse.emf.ecore.EcorePackage;
>
> public class Main {
> public static void main( String[] args ) {
>
> IlrMypackagePackage pkg = IlrMypackagePackage.eINSTANCE;
> EClass clazz = pkg.getMyClass();
>
> EcorePackage theCorePackage = EcorePackage.eINSTANCE;
> EcoreFactory theCoreFactory = EcoreFactory.eINSTANCE;
>
> EAttribute bookStoreOwner = theCoreFactory.createEAttribute();
> bookStoreOwner.setName("owner");
> bookStoreOwner.setEType(theCorePackage.getEString());
>
> clazz.getEStructuralFeatures().add(bookStoreOwner);
> dumpEClass(clazz);
>
> EClass derivedClazz = pkg.getDerived();
> dumpEClass(derivedClazz);
> }
>
> private static void dumpEClass( EClass clazz ) {
> System.out.println( "======" );
> System.out.println( clazz.getName() );
> EList<EStructuralFeature> list =
> clazz.getEAllStructuralFeatures();
> for (EStructuralFeature eStructuralFeature : list) {
> System.out.println( " " + eStructuralFeature.getName()
> );
> }
> System.out.println( "======" );
> }
> }
>
> private static void dumpEClass( EClass clazz ) {
> System.out.println( "======" );
> System.out.println( clazz.getName() );
> EList<EStructuralFeature> list =
> clazz.getEAllStructuralFeatures();
> for (EStructuralFeature eStructuralFeature : list) {
> System.out.println( " " + eStructuralFeature.getName()
> );
> }
> System.out.println( "======" );
> }
>
> Output:
>
> ======
> MyClass
> secondClass
> Name
> owner
> ======
> ======
> Derived
> secondClass
> Name
> ======
>
> Anyone have any ideas?
If anything, you should be using a dynamic model that extends the
generated model, rather than modifying the generated model directly
(much like you'd extend a Java class, rather than go in and try to munge
the byte code dynamically at runtime).
>
> Thanks,
> Dan
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04479 seconds