Is it possible to generate real Java code with Dresden OCL Toolkit? - ocl

I tried using Dresden OCL to describe constraints for an UML class diagram. It looks like it can generate AspectJ code fine but I could not find a way to generate the Java code representing the modeled classes (and their attributes and methods). The examples provided with Dresden OCL Toolkit also show how to generate AspectJ code once the Java code is already present (OCL22Java tutorial).
Is it possible to generate the Java (not AspectJ) code with constraints embedded inside? And if it is, then how is it done?

It is not possible to do that with Dresden OCL Toolkit, therefore some other tool must be used for that. I used Uml2Java for Acceleo.

The standalone engine of DresdenOCL (StandaloneFacade) includes a function called generateJavaCode. I'm not sure though if this function is actually "complete" and generates correct Java Code for all possible OCL constraints. You also cannot find any info about that function on Google, it's just used in the standalone example.
Edit: As an example what Java code it generates:
For this OCL expression (on some simple UML model that I created)
context person
inv: self.age >= 0
you get this piece of Java code
(aClass.age >= new Integer(0))
And for this OCL expression
context person::havingBirthday()
post: self.age = self.age#pre+1
you get this:
((Object) aClass.age).equals((atPreValue1 + new Integer(1)))
So the generated Java code is not that usable atm, you need to modify it (or your Java functions) a bit to actually use it.

Eclipse OCL provides support for enriching the Java generated from Ecore models with complete inline Java code for OCL embedded within Ecore. Eclipse UML2 provides support for converting UML with embedded OCL to Ecore with embedded OCL. This now provides all that you ask for. It has been available for a couple of years. See the Code Generator tutorial in the Eclipse OCL documentation for an example and further information.

Related

Get the source code of FP Growth algorithm used in WEKA to see how it is implemented

I am currently working on a project that involves FP-Growth and I have no idea how to implement it. Is the source code of FP-Growth used in WEKA available anywhere so i can study the working?
Weka is indeed Open Source Software (OSS), and their source code is freely available via SVN hosted by the University of Weikato: http://www.cs.waikato.ac.nz/ml/weka/svn.html
To find a specific implementation, I would search the Weka Java Docs on SourceForge to identify the class: http://weka.sourceforge.net/doc.stable/. (Here is FP-Growth). Note the class hierarchy beneath the class name:
Take that class hierarchy and locate it in SVN by traversing the package names in the version that you want:
Click on the link in SVN to open or download the source code. Here is the link for FP-Growth: https://svn.cms.waikato.ac.nz/svn/weka/tags/weka-stable-3.6.13/src/main/java/weka/associations/FPGrowth.java (for Weka 3.6.13).
You could have a look at the version of FP-Growth implemented in the SPMF data mining library (I'm the founder), which is specialized in pattern mining and offers FPGrowth, and many other algorithms. It is implemented in Java, and it is very easy to reuse it, it is optimized, and unlike some other implementations it has no dependencies to other libraries.

Domain model in EMF - can I produce POJOs using Acceleo?

I have a domain model that is created using ecore EMF.
And I would like to generate POJOs. I would like to be able customize the POJOs, so I am looking at using Acceleo.
However, I can only see creating POJOs in Acceleo from UML. When using EMF it produces EObjects, Estrings etc.
Is it possible to just produce POJOs?
With Acceleo, you can generate anything you want. If you want to generate just POJOs from an UML model, you can use or fork the UML to Java generator available on Github. If you do, make sure to use the version matching the version of UML that you are using (master branch for UML2 v4.0.0, R1_1_maintenance branch for UML2 v3.x.x).
If you are using UML2 v3.x.x, you can simply install it by using the Eclipse Marketplace. The 2.0.0 release of the generator fo UML2 v4.0.0 will be released soon.
See the following link for generating POJOs with EMF:
http://eclipseo.blogspot.be/2007/10/creating-pojos-using-emf.html
If you want to customize this even more, you could also use other methods:
XPand
XText
Acceleo ECore generation templates
etc

Can i add ocl to ecore with java code?

I want to add ocl to my .ecore metamodel with java code. But i cant find any example or tutorial.
So i want to ask is tihs possible or where can i find sample codes?
Did you check OCLinEcore? It allows embed OCL in your ecore model and edit it like a text which may be edited with the aid of syntax and semantic validation and completion suggestions.
This is exerpt from the link:
OCL can be embedded in Ecore using annotations. Maintenance of these
annotations is performed automatically by the OCLinEcore editor ...
The embedded OCL becomes active when the appropriate delegate
functionality is specified.
There are three type of delegate functionality:
Setting Delegate
Invocation Delegate
Validation Delegate
Also there are invariants constraints.
I see two alternatives:
Use EVL (Epsilon Validation Language), it is included in EMF (Eclipse Modeling Framework). In that way, you just right click .ecore model and create a new EVL Validation (under Epsilon options). EVL syntax is well documented on Epsilon book https://www.eclipse.org/epsilon/doc/book/.
Use OCL directly. For this purpose yo need to install OCL component on EMF. So, if you are using Eclipse, Help > Install Modeling Components > Find: OCL. Check the obtained result. Now this tutorial could help you http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FCompleteOCLTutorial.html.
I wish this could help.

C++ code to class diagram

Is there is a way I can generate a hierachial class diagram from C++ code. My code is spread over 5 to 6 .cpp files.
I would like to know if there is any free tool for the same.
Regards,
AJ
There's e.g. doxygen
http://www.doxygen.nl/manual/features.html says:
Uses the dot tool of the Graphviz tool kit to generate include dependency graphs, collaboration diagrams, call graphs, directory structure graphs, and graphical class hierarchy graphs.
It creates graphs like
(from http://www.vtk.org/doc/nightly/html/structvtkKdTree_1_1__cellList.html, an example listed on the doxygen site)
Since the question was about class diagrams you might also be interested in the UML_LOOK flag that makes the ouput a bit more uml-like.
Class diagrams are networks, not hierarchies. There a re quite a few tools that can generate them - my favourite is Enterprise Architect, but it isn't free (there is a trial).
Umberello is the Linux application that generate diagram from code.
Doxygen can create class-diagrams. However, I believe these diagrams are only to show the network of classes, they do not list methods and members and such.

Create class diagram from c++ source?

Is there any free tools available for generating class diagram from c++ source files and if possible for mfc source files too.
We use doxygen with graphviz support
You could try SourceNavigator. I'm not sure what the current state of the project is, but here's a place to start.
I've had some success with Umbrello (a KDE-based app). It allows you to import code to create a model, that can then be used to generate UML diagrams.
Umbrello is probably fine for projects with a limited number of classes, and certainly requires manual intervention for tuning. I imagine doxygen/graphviz is more suitable for larger projects.