How to create uml class diagram and notations by programming? - uml

Package model = UMLFactory.eINSTANCE.createPackage();
model.setName("MyPackage");
Class cls = model.createOwnedClass("MyClass", false);
I created some uml2 models by code above, now I want to create a class diagram and some notations for package/class etc. How can I do this by programming? (We can initialize class diagram for .uml by uml2tools in eclipse, but what's the API for it?)
Thanks a lot.

The uml2 model provides you with the entities needed to create uml models. UML diagrams are views of these models and are not part of the mode definition. So you can't create a diagram :-(

Related

unable to create a Class Diagram in Rational Rhapsody SysML Project

I created a Rational Rhapsody project with Project Type set to SysML. After creating the project I added HarmonySE profile into the project. I also created a Block Definition Diagram and a Requirement Diagram in the project. But I can't find a way to create a Class Diagram in my project. If I click on Tools menu -> Diagrams, Class Diagram is not in the list of diagrams:
Can someone please suggest how to include Class Diagram in a Project?
There is no Class Diagram in SysML, thus Rhapsody prohibts its usage in a project having the SysML profile. If you want to use class diagrams (i.e., UML in general) for your SW domain, you can add an UML project to your workspace, via File->Add new project. This project can use a different profile, and thus you can create your classical UML diagrams there.
In simple terms, a UML class is a block in SysML. What you are looking for is a Block Definition Diagram. There is no Class Diagram in SysML.

Relation between a Object Diagram and a Class Digram in MOF Layer terms

I want to express the relationship between object diagrams and class diagrams in terms of the MOF Layer Model.
As an Object Diagram (OD) is an instance of a Class Diagram (CD), I conclude that an OD must be on a Layer below a CD (e.g. OD in M0 and CD in M1).
What confuses me is that both, Object Diagrams and Class Diagrams seem to be in the M1 layer as they're both instances of the UML-metamodel which is in the M2-layer.
What am I missing here?
AFAIK for the purpose of diagram interchange in a MOF container the diagram relationships are not defined (nor needed) and thus do not impose any layer constraints.
This is where I drew my conclusion from:
1.
uml-diagrams.org: Class and Object Diagrams Overview says:
...Object diagram could be considered as instance level class diagram which shows instance specifications of classes and interfaces (objects), slots with value specifications, and links (instances of association)...
2.
uml-diagrams.org: Object Diagram says:
Object diagram was defined in now obsolete UML 1.4.2 Specification as...
UML 2.4 specification simply provides no definition of object diagram...
Note, that UML 2.5 standard hierarchy of diagrams (see UML 2.5 diagrams overview), shows class diagrams and object diagrams as completely unrelated...
...I really have a headache with all this mess-up… OMG please fix it!
3.
omg.org: Diagram Definition, Version 1.0, July 2012 says:
Figure 7.2 - Example of Diagram Definition Architecture For UML
9.3.1 Diagram Interchange → Classifier Descriptions → Diagram [Class]
Diagram is an abstract container of a graph of diagram elements...
...It can also be owned by elements of the abstract syntax model, or by no element at all...
...a diagram may reference a model element from an abstract syntax model, in which case the whole diagram is considered a depiction of that element (e.g., an activity diagram is a depiction of a UML activity).
Alternatively, a diagram without such a reference is simply a layout container for its diagram elements (e.g., a class diagram is a container for UML class shapes and edges)

Generate UML from a conceptual data model

I have an conceptual data model (Relational model) created using powerAMC for my database but i wanted to generate DAO from it using acceleo and for that i need it in UML , is there a way to generate UML from a conceptual data model model ?
Acceleo can generate code from any models defined with any EMF based metamodel. The UML project of the Eclipse Foundation defines an UML metamodel based on EMF so that users can create UML models based on EMF and Acceleo can thus generate code from those models.
If you want to use another metamodel, you can do it, so if you want to create a metamodel that matches more closely your data structure, feel free to do so. As an example, you can see here a metamodel that I have created of the Scala language and my generator uses models defined from this metamodel to generate the code. You can find an example of a generator using this metamodel here. You can see in this example that the Acceleo generator is defined on my scala metamodel "http://github.com/sbegaudeau/acceleo/scalametamodel/2011/01" (contrary to an Acceleo generator that would be defined on UML that would be using the standard UML metamodel "http://www.eclipse.org/uml2/3.0.0/UML") and I can manipulate in Acceleo some concepts from this metamodel directly like traits (if you are familiar with Scala).
So you can:
create a metamodel that matches your concepts
create a small converter in java to create an EMF model (instance of your metamodel defining the concepts of your database) and then transform the data in your database to an EMF model that you just have to save.
use Acceleo with your models :)
Regards,
Stephane Begaudeau
Disclaimer: I am the leader of Acceleo.
PowerAMC has a data model which is not object like UML. It is therefore impossible to transform it to UML.
If you have directly the generated database then you can create the UML model from the code but not from database modeler.

Can I use Eclipse-EMF's internal data structure?

In EMF, a user can draw UML diagram and that UML model can be transformed into Java code. As far as I know EMF has its own internal data structure to capture the UML model user draws. And what I want to do is to make UML model by coding, not by drawing, i.e., by using EMF's internal data structure representing UML metamodel(Class, Package, Attribute, etc). Like,
UmlClass myClass = new UmlClass();
UmlAttribute myAttr = new UmlAttribute();
myClass.addAttribute(myAttr);
Is this possible(not even by EMF)? Anyway, I want to use a robust data structure that exactly reflects OMG's standard UML specification.
Thanks in advance.
EMF is a modelling framework designed to support modelling in general, not just UML.
If it is UML in particular you're after, there is indeed such an implementation built on top of EMF. Check out UML2.
There are no classes exactly reflecting the OMG specification, but EMF ECore is a meta model for models. Therefore you can do what you want using EMF ECore. There is lots of doc at http://www.eclipse.org/modeling/emf/docs/#overviews and an excellent book. The link has a picture and link to the book.
An example:
EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
EClass myClass = ecoreFactory.createEClass();
myClass.setName("MyClass");
EAttribute myAttr = ECoreFactory.createEAttribute();
myAttr.setName("myAttr");
myAttr.setEType(EcorePackage.Literals.ESTRING);
myClass.getEStructuralFeatures().add(myAttr);

What kind of UML diagram is this?

What kind of UML diagram is this?
(source: tripod.com)
This is a class diagram, with added stereotypes
This is Class Diagram in a very abstract or initial form because all relationship are shown as Association.
Usually we start with such class diagram and then keep on refining by converting association (arrow as shown above) into more stronger relationship like generalization,composition,implementation etc.
Association is considered as weaker form of relationship between classes. So final class diagram should have fewer associations.
What is the emphasis or goal of this diagram? If it's the classes and relationships, then it's a class diagram. If it's the mapping between the classes and layers of function or responsiblity in the system, then it looks like a layer diagram. Those columns look like layers: presentation, business logic, data...
Ok now I see the problem after a good sleep :-)
It seems it is a powerpoint and not a class diagram because you can not have straight line in a class diagram. I mean you can not have 3 separators like Presentation/ objectos .......etc
This powerpoint tried to use class diagram and have added titles in order to separate 3 layers. The problem is that the class diagram is incorrect and it is not because you present it with 3 layer that it would become correct !! This is a bad understanding of what means JPA stereotypes inside a class diagram.
It looks like a Class Diagram that uses "swimlanes" on the background to facilitate some kind of MVC.
This class diagram is not correct because there is confusion between Java EE stereotypes and class names!
What are the << class module>> , << module>> stereotypes and Session, Session persistence names should be Java EE stereotypes. If it persists in the database then it is an entity! Persistence etc...can be written on attributes.
This diagram doesn't make sense!
The main advantage of scheme in this diagram is that if you use a code generator such as AndroMDA, MIA software or Blue Age, then you can then generate your database directly from the model. These tools look at stereotypes during code generation.
If you don't want to generate code from a model but prefer to let hibernate mapping do the job, then the "entity" stereotype can be written as an annotation in your java code. Then thanks to live code and model synchronization, hibernate can take the annotation and produce a mapping.
This is why stereotyping is really very important and using the wrong stereotype can be a very serious mistake!

Resources