Home » Modeling » UML2 » Dynamic UML
Dynamic UML [message #547720] |
Mon, 19 July 2010 13:11 |
Eclipse User |
|
|
|
Originally posted by: ML1984.gmx.de
Hi there,
is there something like 'Dynamic UML' (similar to Dynamic EMF)? The
following tutorial gives a brief overview of the features of Dynamic EMF.
http://www.ibm.com/developerworks/library/os-eclipse-dynamic emf/
My precise question is, whether it is possible to create an dynamic
instance of a UML class? I tried to rewrite the code of the above
example using the UML API, but stucked at Listing 4: getEFactoryInstance().
There is no such method in class org.eclipse.uml2.uml.Package. Is there
another way of doing this?
Cheers,
Mark
|
|
| |
Re: Dynamic UML [message #547794 is a reply to message #547789] |
Mon, 19 July 2010 15:51 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi Mark
The generalisation of OCL support to treat Ecore and UML uniformly may
in due course provide this, but certainly not soon.
Regards
Ed Willink
On 19/07/2010 16:32, Ed Merks wrote:
> Mark,
>
> As far as I know, nothing at Eclipse provides such a thing, i.e., direct
> instantiation of UML2 models. You could map UML2 to Ecore and then use
> dynamic EMF...
>
>
> Mark L. wrote:
>> Hi there,
>>
>> is there something like 'Dynamic UML' (similar to Dynamic EMF)? The
>> following tutorial gives a brief overview of the features of Dynamic EMF.
>>
>> http://www.ibm.com/developerworks/library/os-eclipse-dynamic emf/
>>
>> My precise question is, whether it is possible to create an dynamic
>> instance of a UML class? I tried to rewrite the code of the above
>> example using the UML API, but stucked at Listing 4:
>> getEFactoryInstance().
>>
>> There is no such method in class org.eclipse.uml2.uml.Package. Is
>> there another way of doing this?
>>
>> Cheers,
>> Mark
|
|
|
Re: Dynamic UML [message #547882 is a reply to message #547720] |
Tue, 20 July 2010 05:06 |
Rafael Chaves Messages: 161 Registered: July 2009 |
Senior Member |
|
|
Mark, is this what you are looking for?
package foo.tests;
import junit.framework.TestCase;
import org.eclipse.emf.common.util.*;
import org.eclipse.emf.ecore.*;
import org.eclipse.uml2.uml.NamedElement;
public class ReflectiveUMLTest extends TestCase{
public void testFoo() {
String umlNamespaceURI = "http://www.eclipse.org/uml2/3.0.0/UML";
EPackage umlPackage = EPackage.Registry.INSTANCE.getEPackage(umlNamespaceURI);
EFactory umlFactory = EPackage.Registry.INSTANCE.getEFactory(umlNamespaceURI);
EClass namedElementMetaClass = (EClass) umlPackage.getEClassifier("NamedElement");
EStructuralFeature namedElementName = namedElementMetaClass.getEStructuralFeature("name");
EClass packageMetaClass = (EClass) umlPackage.getEClassifier("Package");
EClass classMetaClass = (EClass) umlPackage.getEClassifier("Class");
EObject bookstorePackage = umlFactory.create(packageMetaClass);
bookstorePackage.eSet(namedElementName, "BookstorePackage");
EObject bookClass = umlFactory.create(classMetaClass);
bookClass.eSet(namedElementName, "Book");
EReference packagedElement = (EReference) packageMetaClass.getEStructuralFeature("packagedElement");
((EList<EObject>) bookstorePackage.eGet(packagedElement)).add(bookClass);
EObject subPackage = umlFactory.create(packageMetaClass);
subPackage.eSet(namedElementName, "SubPackage");
((EList) bookstorePackage.eGet(packagedElement)).add(subPackage);
EReference namespace = (EReference) namedElementMetaClass.getEStructuralFeature("namespace");
assertSame(bookstorePackage, bookClass.eGet(namespace));
// use the static API to show it worked
assertEquals("BookstorePackage::Book", ((NamedElement)bookClass).getQualifiedName());
assertEquals("BookstorePackage::SubPackage", ((NamedElement)subPackage).getQualifiedName());
// derived/subset collections work normally
EReference packageOwnedTypes = (EReference) packageMetaClass.getEStructuralFeature("ownedType");
assertTrue(((EList) bookstorePackage.eGet(packageOwnedTypes)).contains(bookClass));
assertFalse(((EList) bookstorePackage.eGet(packageOwnedTypes)).contains(subPackage));
EReference packageNestedPackages = (EReference) packageMetaClass.getEStructuralFeature("nestedPackage");
assertFalse(((EList) bookstorePackage.eGet(packageNestedPackages)).contains(bookClass));
assertTrue(((EList) bookstorePackage.eGet(packageNestedPackages)).contains(subPackage));
}
}
You still get EMF's management of relationships, and type-safe collections. But this is a really painful way to go about doing things. Not to mention you lose access to the behavioral aspects of the UML metamodel implementation, such as implementation of OCL queries.
Rafael Chaves
http://abstratt.com/blog
|
|
|
Re: Dynamic UML [message #547993 is a reply to message #547882] |
Tue, 20 July 2010 10:56 |
Eclipse User |
|
|
|
Originally posted by: ML1984.gmx.de
Thanks for the quick replies!
> Mark, is this what you are looking for?
No, it is not. The most important thing is missing: creating dynamic
objects, but Ed Merks already gave a statement about this. I think the
situation is clear.
Cheers,
Mark
|
|
| | |
Re: Dynamic UML [message #628545 is a reply to message #547720] |
Mon, 19 July 2010 15:32 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Mark,
As far as I know, nothing at Eclipse provides such a thing, i.e., direct
instantiation of UML2 models. You could map UML2 to Ecore and then use
dynamic EMF...
Mark L. wrote:
> Hi there,
>
> is there something like 'Dynamic UML' (similar to Dynamic EMF)? The
> following tutorial gives a brief overview of the features of Dynamic EMF.
>
> http://www.ibm.com/developerworks/library/os-eclipse-dynamic emf/
>
> My precise question is, whether it is possible to create an dynamic
> instance of a UML class? I tried to rewrite the code of the above
> example using the UML API, but stucked at Listing 4:
> getEFactoryInstance().
>
> There is no such method in class org.eclipse.uml2.uml.Package. Is
> there another way of doing this?
>
> Cheers,
> Mark
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Dynamic UML [message #628546 is a reply to message #547789] |
Mon, 19 July 2010 15:51 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi Mark
The generalisation of OCL support to treat Ecore and UML uniformly may
in due course provide this, but certainly not soon.
Regards
Ed Willink
On 19/07/2010 16:32, Ed Merks wrote:
> Mark,
>
> As far as I know, nothing at Eclipse provides such a thing, i.e., direct
> instantiation of UML2 models. You could map UML2 to Ecore and then use
> dynamic EMF...
>
>
> Mark L. wrote:
>> Hi there,
>>
>> is there something like 'Dynamic UML' (similar to Dynamic EMF)? The
>> following tutorial gives a brief overview of the features of Dynamic EMF.
>>
>> http://www.ibm.com/developerworks/library/os-eclipse-dynamic emf/
>>
>> My precise question is, whether it is possible to create an dynamic
>> instance of a UML class? I tried to rewrite the code of the above
>> example using the UML API, but stucked at Listing 4:
>> getEFactoryInstance().
>>
>> There is no such method in class org.eclipse.uml2.uml.Package. Is
>> there another way of doing this?
>>
>> Cheers,
>> Mark
|
|
|
Re: Dynamic UML [message #628548 is a reply to message #547720] |
Tue, 20 July 2010 05:07 |
Rafael Chaves Messages: 161 Registered: July 2009 |
Senior Member |
|
|
Mark, is this what you are looking for?
package foo.tests;
import junit.framework.TestCase;
import org.eclipse.emf.common.util.*;
import org.eclipse.emf.ecore.*;
import org.eclipse.uml2.uml.NamedElement;
public class ReflectiveUMLTest extends TestCase{
public void testFoo() {
String umlNamespaceURI = "http://www.eclipse.org/uml2/3.0.0/UML";
EPackage umlPackage = EPackage.Registry.INSTANCE.getEPackage(umlNamespaceURI);
EFactory umlFactory = EPackage.Registry.INSTANCE.getEFactory(umlNamespaceURI);
EClass namedElementMetaClass = (EClass) umlPackage.getEClassifier("NamedElement");
EStructuralFeature namedElementName = namedElementMetaClass.getEStructuralFeature("name");
EClass packageMetaClass = (EClass) umlPackage.getEClassifier("Package");
EClass classMetaClass = (EClass) umlPackage.getEClassifier("Class");
EObject bookstorePackage = umlFactory.create(packageMetaClass);
bookstorePackage.eSet(namedElementName, "BookstorePackage");
EObject bookClass = umlFactory.create(classMetaClass);
bookClass.eSet(namedElementName, "Book");
EReference packagedElement = (EReference) packageMetaClass.getEStructuralFeature("packagedElement");
((EList<EObject>) bookstorePackage.eGet(packagedElement)).add(bookClass);
EObject subPackage = umlFactory.create(packageMetaClass);
subPackage.eSet(namedElementName, "SubPackage");
((EList) bookstorePackage.eGet(packagedElement)).add(subPackage);
EReference namespace = (EReference) namedElementMetaClass.getEStructuralFeature("namespace");
assertSame(bookstorePackage, bookClass.eGet(namespace));
// use the static API to show it worked
assertEquals("BookstorePackage::Book", ((NamedElement)bookClass).getQualifiedName());
assertEquals("BookstorePackage::SubPackage", ((NamedElement)subPackage).getQualifiedName());
// derived/subset collections work normally
EReference packageOwnedTypes = (EReference) packageMetaClass.getEStructuralFeature("ownedType");
assertTrue(((EList) bookstorePackage.eGet(packageOwnedTypes)).contains(bookClass ));
assertFalse(((EList) bookstorePackage.eGet(packageOwnedTypes)).contains(subPackag e));
EReference packageNestedPackages = (EReference) packageMetaClass.getEStructuralFeature("nestedPackage");
assertFalse(((EList) bookstorePackage.eGet(packageNestedPackages)).contains(bookC lass));
assertTrue(((EList) bookstorePackage.eGet(packageNestedPackages)).contains(subPa ckage));
}
}
You still get EMF's management of relationships, and type-safe collections. But this is a really painful way to go about doing things. Not to mention you lose access to the behavioral aspects of the UML metamodel implementation, such as implementation of OCL queries.
Rafael Chaves
http://abstratt.com/blog
|
|
|
Re: Dynamic UML [message #628549 is a reply to message #628548] |
Tue, 20 July 2010 10:56 |
Eclipse User |
|
|
|
Originally posted by: ML1984.gmx.de
Thanks for the quick replies!
> Mark, is this what you are looking for?
No, it is not. The most important thing is missing: creating dynamic
objects, but Ed Merks already gave a statement about this. I think the
situation is clear.
Cheers,
Mark
|
|
| | |
Goto Forum:
Current Time: Fri Apr 19 11:46:29 GMT 2024
Powered by FUDForum. Page generated in 0.02540 seconds
|