|
|
|
|
Re: genmodel for state machine diagram [message #478635 is a reply to message #478634] |
Fri, 24 July 2009 15:17 |
Tas Frangoullides Messages: 195 Registered: July 2009 |
Senior Member |
|
|
Eban,
UML2 is implemented as instance of an ecore model, so you can instanciate
and manipulate it using the UML2 API. It's API is not as easy to understand
and EMF but that's just the way the UMl2 Spec is. You mgiht find the OMG
specification useful as the UML2 API is pretty much a mirror of it plus some
convenience methods.
You can do soemting allong the lines of
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
.....
Model model = UMLFactory.eINSTANCE.createModel();
Class personClass = model.createOwnedClass("Person", false);
Class addressClass = model.createOwnedClass("Address", false);
personClass.createOwnedAttribute("address", addressClass);
for (NamedElement namedElement: model.getOwnedMembers()) {
if (UMLPackage.Literals.CLASS.equals(namedElement.eClass())) {
Class umlClass = (Class) namedElement;
System.out.println(umlClass.getName());
}
}
In terms of going from a UML Statemachine I would approach it in a number of
steps which make it easier to build and test your generators
1. Using EMF define a simple StateMachine meta-model that describes the
semantics you are really interested in.
2. Develop a generators for generating code from instances of this simple
meta-model
3. Develop a transformation from UML2 StateMachine to your own StateMachine
To achieve step 2 you may find transforming to an ecore model and
customising the emf code generation tamplates helpful
The pure "modeling" approach to the transformations would be to use a proper
model transformation language but I have also found SwithUtil classes
pragmatic and easy to test.
Hope that helps,
Tas
"Eban Escott" <eban.escott@uqconnect.edu.au> wrote in message
news:1db3d97061ef7dcbb69e6494d701ad4a$1@www.eclipse.org...
> Hey Tas, thanks for the heads up. I am trying to do some reflective
> programming on a ecore model, or as it turns out now on a uml2 model? So,
> i have been reading the EMF, 2nd edition book and I have got this working
> on an ecore model fine:
>
> InputCPackage inputCPackage = InputCPackage.eINSTANCE;
> System.out.println(inputCPackage);
> classifiers = inputCPackage.getEClassifiers();
> for(EClassifier classifier: classifiers) {
> System.out.println(classifier);
> }
> And from here I can reflectively traverse a meta-model combine that with
> JET and out pops some code ... sweet. Having a guess, is this how
> generators work?
>
> Now, I want to do something similar again but on a state machine not a
> class diagram. I have tried converting to ecore as you know but ran into
> problems. How can I use reflection on a UML2 model?
>
> Thanks, Eban
>
|
|
|
Re: genmodel for state machine diagram [message #478643 is a reply to message #478635] |
Mon, 27 July 2009 03:08 |
Eban Escott Messages: 61 Registered: July 2009 |
Member |
|
|
Hi Tas, I got the example code going that you included and I intend to
look at model transformational languages soon, thanks heaps for the tips!
For the moment, I am still trying to de-serialise the uml model as per:
http://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_lo ad_a_UML_.28.uml.29_resource_from_a_standalone_application.3 F
I am getting an empty set and I have double checked the .uml file has in
it a statemachine and other elements. The code I have written is:
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE); resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
File file = new File("InputC.uml");
if(!file.exists()) {
System.out.println("Cannot find file.");
} else {
System.out.println("Found " + file.getCanonicalPath());
}
//URI uri = URI.createFileURI(file.getCanonicalPath());
//Resource resource = resourceSet.createResource(uri);
//System.out.println(resource.getContents().get(0));
Map uriMap = resourceSet.getURIConverter().getURIMap();
URI uri = URI.createFileURI(file.getCanonicalPath());
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uri.appendSegment("profiles").appendSegment(""));
Resource resource = resourceSet.createResource(uri);
System.out.println(resource.getContents());
I know I am close but can't seem to get it loading. Any ideas? Thanks, Eban
|
|
|
|
|
|
|
Re: genmodel for state machine diagram [message #627814 is a reply to message #478634] |
Fri, 24 July 2009 15:17 |
Tas Frangoullides Messages: 195 Registered: July 2009 |
Senior Member |
|
|
Eban,
UML2 is implemented as instance of an ecore model, so you can instanciate
and manipulate it using the UML2 API. It's API is not as easy to understand
and EMF but that's just the way the UMl2 Spec is. You mgiht find the OMG
specification useful as the UML2 API is pretty much a mirror of it plus some
convenience methods.
You can do soemting allong the lines of
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
.....
Model model = UMLFactory.eINSTANCE.createModel();
Class personClass = model.createOwnedClass("Person", false);
Class addressClass = model.createOwnedClass("Address", false);
personClass.createOwnedAttribute("address", addressClass);
for (NamedElement namedElement: model.getOwnedMembers()) {
if (UMLPackage.Literals.CLASS.equals(namedElement.eClass())) {
Class umlClass = (Class) namedElement;
System.out.println(umlClass.getName());
}
}
In terms of going from a UML Statemachine I would approach it in a number of
steps which make it easier to build and test your generators
1. Using EMF define a simple StateMachine meta-model that describes the
semantics you are really interested in.
2. Develop a generators for generating code from instances of this simple
meta-model
3. Develop a transformation from UML2 StateMachine to your own StateMachine
To achieve step 2 you may find transforming to an ecore model and
customising the emf code generation tamplates helpful
The pure "modeling" approach to the transformations would be to use a proper
model transformation language but I have also found SwithUtil classes
pragmatic and easy to test.
Hope that helps,
Tas
"Eban Escott" <eban.escott@uqconnect.edu.au> wrote in message
news:1db3d97061ef7dcbb69e6494d701ad4a$1@www.eclipse.org...
> Hey Tas, thanks for the heads up. I am trying to do some reflective
> programming on a ecore model, or as it turns out now on a uml2 model? So,
> i have been reading the EMF, 2nd edition book and I have got this working
> on an ecore model fine:
>
> InputCPackage inputCPackage = InputCPackage.eINSTANCE;
> System.out.println(inputCPackage);
> classifiers = inputCPackage.getEClassifiers();
> for(EClassifier classifier: classifiers) {
> System.out.println(classifier);
> }
> And from here I can reflectively traverse a meta-model combine that with
> JET and out pops some code ... sweet. Having a guess, is this how
> generators work?
>
> Now, I want to do something similar again but on a state machine not a
> class diagram. I have tried converting to ecore as you know but ran into
> problems. How can I use reflection on a UML2 model?
>
> Thanks, Eban
>
|
|
|
Re: genmodel for state machine diagram [message #627822 is a reply to message #478635] |
Mon, 27 July 2009 03:08 |
Eban Escott Messages: 61 Registered: July 2009 |
Member |
|
|
Hi Tas, I got the example code going that you included and I intend to
look at model transformational languages soon, thanks heaps for the tips!
For the moment, I am still trying to de-serialise the uml model as per:
http://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_lo ad_a_UML_.28.uml.29_resource_from_a_standalone_application.3 F
I am getting an empty set and I have double checked the .uml file has in
it a statemachine and other elements. The code I have written is:
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE); resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
File file = new File("InputC.uml");
if(!file.exists()) {
System.out.println("Cannot find file.");
} else {
System.out.println("Found " + file.getCanonicalPath());
}
//URI uri = URI.createFileURI(file.getCanonicalPath());
//Resource resource = resourceSet.createResource(uri);
//System.out.println(resource.getContents().get(0));
Map uriMap = resourceSet.getURIConverter().getURIMap();
URI uri = URI.createFileURI(file.getCanonicalPath());
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uri.appendSegment("profiles").appendSegment(""));
Resource resource = resourceSet.createResource(uri);
System.out.println(resource.getContents());
I know I am close but can't seem to get it loading. Any ideas? Thanks, Eban
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04379 seconds