Generate XML file from UML Model in Java - java

I want to make a java application that take UML Model and it's output is a XML File.
I want to know what is the library/API can i use in Java ? - and i want to know if there is any application that do this job ?

Most (if not all) UML tools will export to XMI, you can learn more at
Wikipedia MOF. If you are really interested in code generation (rather than just parsing XML) there are eclipse related projects such as eclipse emf. Good luck w/your journey.

Related

Java programming with uml

I'm a java developer new with uml modeling. I wanna create a complete web application (backend+db+jms+security +ui) deployable to an application server by using only UML. Despite I didn't understand what really is meta-modeling I started using Umbrello, visual paradigm and eclipse emf.
I've read just a little about omg's xmi standard.
So supponing to have an xmi file I didn't understand how to generate java code. Eclipse emf for example would generate "strange" java code.
Do I need to
write my own xmi parser?
Do I need to write my own xmi parser?
No.
Eclipse EMF generator generates code for saving and loading your model, so there is no need to write your own parser or serializer.
EMF allows you to generate a maximum of four different plugins for a defined model:
Model: The model contains all entities, packages and factories to create instances of the model.
Edit: The edit plugin contains providers to display a model in a UI. For example, the providers offer a label for every model element, which can be used to display an entity showing an icon and a name.
Editor: The editor plugin is a generated example editor to create and modify instances of a model.
Test: The test plugin contains templates to write tests for a model.
This is a good article if you need any help with EMF:
What every Eclipse developer should know about EMF.
http://eclipsesource.com/blogs/tutorials/emf-tutorial/

AST for UML Activity diagram

I am currently doing a project to convert uml diagrams to java code,in one of the step I have to create an ast for general activity diagram and write a java code for the ast. The problem is I am not sure how to represent it in java code to accept any activity diagram as an input. Please need some help.
This is the meta-model of a general activity diagram, I want to represent this diagram as a java code to accept inputs.
Activity Diagram Metamodel
The first diagram on the second page of the pdf
What tool are you using to create your activity diagrams? Most will provide an API to query models and/or an XMI export*. In either case you don't get an AST as such, more an Object structure of your model. But it's still pretty easy to iterate that structure and generate code.
One option worth considering is the Eclipse Modeling Framework (EMF). There are tools available for both creating diagrams (e.g. Papyrus) and a multitude of options for generating code from models (e.g. Acceleo) - have a look at the 'Model to Text' (M2T) sub-project.
Even if you decide to use another tool for diagram creation, it's possible to use Eclipse M2T for code generation; most tools will export XMI in the eclipse dialect.
hth.
--
*XMI is the 'standard' for UML model interchange. It was plagued with inconsistency in interpretation originally, and there are still some problems among tools today. However: it is an XML dialect so even if tool B can't directly import XMI from tool A, it's usually possible to convert between the two.

Class diagram generation from java/groovy code and exporting

I'm in the need of a eclipse plugin / or tool which can generate
class diagrams from my java/groovy code and vice versa. Actually it is a
groovy/grails project. The actual requirements are:
I should be able to draw class diagram and generate code and generate class diagram
from existing code
(Important) I have to export the generated class diagram in some format to share it
with my teammates, so they can generate code from it.
Please suggest me a good solution.
Thanks in advance.
You can use visual paradigm for uml. Using Visual Paradign you generate UML diagrams of your and generate code, using UML diagrams
You can create diagrams, share it on CVS or by email but it is only possible with the java code. I don't think it exist for both groovy and java.
You have two options today which is to use a live code and model synchronization tool which is more integration level or a model driven tool which will generate all the code once the model has been completed.
I personally prefer the first live synchronization option because if the code is updated then my model will also be. It is painful to produce diagrams and then realize that at the implementation stage the development team has changed the code and that my diagrams are not anymore relevant !!

Where in the NetBeans 6.9.1 source code is the code for scanning Java files and finding all the methods, variables, imports etc

I'm looking for a sample or possibly even code I can use which scans Java files and tells me key pieces of information about each class, which i can then use much like the NetBeans refactoring and go to source features do.
Instead of reusing the Netbeans sources, you should probably just find a good library.
tells me key pieces of information about each class
Depending on your definition of "key pieces", I would recommend QDox:
http://qdox.codehaus.org/
QDox is a high speed, small footprint
parser for extracting
class/interface/method definitions
from source files complete with
JavaDoc #tags.
If you are looking for reusing Netbeans code which parses Java file, I don't know.
If you are looking for how to parse a Java file, you can try ANTLR. ANTLR is a parser generator. There exists Java grammar which you can use right away. Once, you generate a Java parser, you can use the parser to parse your Java file. You will have to learn how to use ANTLR.
I don't understand very well your question.
If you want to navigate inside source java code with netbeans, push CTRL and with your mouse go over the word you want to explore ; netbeans highligth the word, and if you clic you go to the source.

Code / template generator for Java

For C#, I have often used CodeSmith and lately the T4 generator which is part of Visual Studio.
I'm looking for something similar for Java, in particular an Eclipse add-in since I do all my Java development using the Eclipse IDE.
I've found that freemarker does a pretty good job for generating any type of code. From the website:
FreeMarker is a "template engine"; a generic tool to generate text output (anything from HTML to autogenerated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.
It is used by struts2 a lot. The website has a long list of other products that use freemarker.
I have worked with both Velocity and StringTemplate. Velocity is a bit more conventional (think JSP/ASP concepts), while StringTemplate seems a bit cleaner. in a sense described in this Artima interview. Both are pure templating engines, and will require you to write some code around them, if you want to do full-blown code generation from a model.
StringTemplate is used internally by ANTLR, which may be useful to your effort.
As an alternative approach, you could go with Eclipse, using EMF and JET.
You should try Telosys Tools, an Eclipse plugin for code generation working from an existing database with customizable Velocity templates
See: http://www.telosys.org/
Eclipse Marketplace : http://marketplace.eclipse.org/content/telosys-tools
The tutorials are here : https://sites.google.com/site/telosystutorial/
See this other question about CodeSmith : Is there any freeware tool available which is like Codesmith?
I use JavaForger to generate code from templates. It parses existing classes so that you can use that class-data inside your templates. It can both create new classes or insert code into existing classes. You can determine where generated code will be inserted based on a string conversion rule (e.g. myProject/dao/ProductDao.java => myProject/service/ProductService.java).
JavaForger is open source and uses FreeMarker as template engine and JavaParser as parser.
This is an old question but the only thing that comes close (for Java) to do what CodeSmith Generator does is Spring Roo.
The reason is that Java does not have Partial Classes like C# does. Spring Roo gets around this by using AspectJ ITDs.
My answer is to use StringTemplate, but there is a bit more to it than just what tool to use.
Is it the issue to generate java code? Or is it to use java tools? Programmers would be normally very comfortable writing code. Therefore, it would not be a leap to write some java classes and write a walk that would generate code using StringTemplate. I personally think it is a good exercise to create example models, generate your java code from the models. And depending on your use case you could end up writing JSON models by hand and never having to write any java code to produce the java code. Or you could end up writing Java classes that produce equivalent models.
You could use the StringTemplate based STST, which reads JSON. STST is command line based, and I am sure you could hook it to both eclipse and/or Visual Studio.
I personally think about portability, JSON is an extremely simple language. And almost every language has libraries that support it.
I'm not a C# man so I don't know what the equivalents would be, however I've found xdoclet to be very good in the past. I don't think it integrates with eclipse as such but you can run it from an ant script. Does things like generating Hibernate mapping files from annotated Java classes. Useful if that's what you're looking for :)
eclipse has a built-in template system.
look in window -> preferences -> java -> code style -> code templates
You might look at my plugin : http://fast-code.sourceforge.net/. It allows one to select multiple fields and generate code using user specified velocity templates.
Take a look at my project https://github.com/karajdaar/templator and see if that helps.
I wrote a simple web based application for my use.
its available at https://github.com/harish2704/templates
and a demo is available at http://templates-harish2704.rhcloud.com/
Its language independent tool. GUI supports several languages ( highlighting, snippet completion ect )

Categories