[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.mdt.uml2] Re: genmodel for state machine diagram

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@xxxxxxxxxxxxxxxx> wrote in message news:1db3d97061ef7dcbb69e6494d701ad4a$1@xxxxxxxxxxxxxxxxxx
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