Dynamic EMF [message #400487] |
Fri, 21 April 2006 06:24  |
Eclipse User |
|
|
|
Hello,
I am just playing around with Dynamic EMF. I try to add an attribute to
the UML2 message class.
The Syso statement returns the added attribute, but calling eSet(...)
raises an exception. Why?
EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute();
attr.setName("testAttribute");
attr.setEType(EcorePackage.eINSTANCE.getEString());
EClass messageClass = UML2Package.eINSTANCE.getMessage();
messageClass.getEStructuralFeatures().add(attr);
Message m = UML2Factory.eINSTANCE.createMessage();
System.out.println(m.eClass().getEStructuralFeature("testAttribute "));
m.eSet(attr,"foo");
Exception in thread "main" java.lang.NullPointerException
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDerivedStructur alFeatureID(BasicEObjectImpl.java:780)
at org.eclipse.uml2.impl.MessageImpl.eGet(MessageImpl.java:614)
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:483)
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenSet(BasicEO bjectImpl.java:549)
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDynamicSet(Basi cEObjectImpl.java:532)
at org.eclipse.uml2.impl.MessageImpl.eSet(MessageImpl.java:720)
|
|
|
|
|
Re: Dynamic EMF [message #400493 is a reply to message #400492] |
Fri, 21 April 2006 08:37   |
Eclipse User |
|
|
|
Jens,
I guess you interpreted my "you can't do that" answer as "it's
impossible to do that" when what I meant is "it's a really bad thing
that you should never do because you've just corrupted the one shared
instance of the meta data for the UML2 model that the whole JVM is using
and it won't really do all the things you are expecting."
Jens wrote:
> ok, but then I am wondering why
> m.eClass().getEStructuralFeature("testAttribute") returns the
> attribute of my extension.
>
> Jens
>
> Ed Merks wrote:
>> Jens,
>>
>> Ouch. You can't directly modify a generated class. You can extend
>> any class with a new class, add attributes to that new class, and
>> then create instances of that. (And once you've created an instance
>> of a class, you can no longer modify that class either.)
>>
>>
>> Jens wrote:
>>> Hello,
>>>
>>> I am just playing around with Dynamic EMF. I try to add an attribute
>>> to the UML2 message class.
>>>
>>> The Syso statement returns the added attribute, but calling
>>> eSet(...) raises an exception. Why?
>>>
>>> EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute();
>>> attr.setName("testAttribute");
>>> attr.setEType(EcorePackage.eINSTANCE.getEString());
>>> EClass messageClass = UML2Package.eINSTANCE.getMessage();
>>> messageClass.getEStructuralFeatures().add(attr);
>>> Message m = UML2Factory.eINSTANCE.createMessage();
>>>
>>> System.out.println(m.eClass().getEStructuralFeature("testAttribute "));
>>> m.eSet(attr,"foo");
>>>
>>>
>>> Exception in thread "main" java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDerivedStructur alFeatureID(BasicEObjectImpl.java:780)
>>>
>>> at org.eclipse.uml2.impl.MessageImpl.eGet(MessageImpl.java:614)
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:483)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenSet(BasicEO bjectImpl.java:549)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDynamicSet(Basi cEObjectImpl.java:532)
>>>
>>> at org.eclipse.uml2.impl.MessageImpl.eSet(MessageImpl.java:720)
|
|
|
|
Re: Dynamic EMF [message #1692309 is a reply to message #1692277] |
Wed, 15 April 2015 00:19  |
Eclipse User |
|
|
|
Edoaurd,
Comments below.
On 14/04/2015 6:59 PM, Edoaurd Batot wrote:
> Hi Ed,
>
> what if we want to do it anyway ?
It doesn't work.
>
> Suppose I'm not playing with the UML2 blahblah but with a personnal
> Metamodel I want to evolve during an execution....
Use a dynamic model all the time.
> How to get rid of that null pointer ?
>
Java supports things like hot replace when debugging, but even there,
you can't add a field to a Java class and still hot replace it. You can
want to do it, but that desire itself doesn't make it possible in practice.
|
|
|
Powered by
FUDForum. Page generated in 0.47706 seconds