|
|
|
Re: Dynamic EMF [message #400493 is a reply to message #400492] |
Fri, 21 April 2006 12:37 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
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)
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Dynamic EMF [message #1692309 is a reply to message #1692277] |
Wed, 15 April 2015 04:19 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
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.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03474 seconds