Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsDynamic extension of EMF model and getEAllStructuralFeatures
https://www.eclipse.org/forums/index.php/mv/msg/214770/686800/#msg_686800
EMF 2.6.1). We generate Java code from Ecore and then have config files
that dynamically add properties to EClasses at runtime.
What I am seeing is that new dynamic properties show up on the EClasses
but are not visible on derived classes (using getEAllStructureFeatures).
======
MyClass
secondClass
Name
owner
======
======
Derived
secondClass
Name
======
Anyone have any ideas?
Thanks,
Dan]]>Daniel Selman2011-05-19T12:32:34-00:00Re: Dynamic extension of EMF model and getEAllStructuralFeatures
https://www.eclipse.org/forums/index.php/mv/msg/214770/686976/#msg_686976
custom Jet templates and our own class derived from EClassImpl to manage
this. If there are easier ways of achieving this I'd be interested to
hear of them.
Dan
On 5/19/11 2:32 PM, 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.
>
> What I am seeing is that new dynamic properties show up on the EClasses
> but are not visible on derived classes (using getEAllStructureFeatures).
>
> 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?
>
> Thanks,
> Dan]]>Daniel Selman2011-05-19T13:41:12-00:00Re: Dynamic extension of EMF model and getEAllStructuralFeatures
https://www.eclipse.org/forums/index.php/mv/msg/214770/686801/#msg_686801
custom Jet templates and our own class derived from EClassImpl to manage
this. If there are easier ways of achieving this I'd be interested to
hear of them.
Dan
On 5/19/11 2:32 PM, 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.
>
> What I am seeing is that new dynamic properties show up on the EClasses
> but are not visible on derived classes (using getEAllStructureFeatures).
>
> 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?
>
> Thanks,
> Dan]]>Daniel Selman2011-05-19T13:41:12-00:00Re: Dynamic extension of EMF model and getEAllStructuralFeatures
https://www.eclipse.org/forums/index.php/mv/msg/214770/686987/#msg_686987
Originally posted by: Rich Kulp
Hi,
Was the derived class generated as frozen? By default the
ePackageImpl.init() method for your EMF package freezes the classes
generated. This means that once the package is initialized the structure
is frozen. It doesn't listen for changes from parent classes.
Rich Kulp]]>2011-05-19T17:44:34-00:00Re: Dynamic extension of EMF model and getEAllStructuralFeatures
https://www.eclipse.org/forums/index.php/mv/msg/214770/686811/#msg_686811
Originally posted by: Rich Kulp
Hi,
Was the derived class generated as frozen? By default the
ePackageImpl.init() method for your EMF package freezes the classes
generated. This means that once the package is initialized the structure
is frozen. It doesn't listen for changes from parent classes.
Rich Kulp]]>2011-05-19T17:44:34-00:00Re: Dynamic extension of EMF model and getEAllStructuralFeatures
https://www.eclipse.org/forums/index.php/mv/msg/214770/686988/#msg_686988
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 Merks2011-05-19T17:45:53-00:00Re: Dynamic extension of EMF model and getEAllStructuralFeatures
https://www.eclipse.org/forums/index.php/mv/msg/214770/686812/#msg_686812
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 Merks2011-05-19T17:45:53-00:00