5

I'm writing a program in java language which takes the java source code as an input and the output is xmi file which contains the class diagram of the source code.

I have researched for xmi structure but I was not able to find an adequate resource which explain the structure and order of tags.

First question is how can I found out what is the order of the tags and definition of each tag? for instance, what is the meaning of "isActive = false" etc?

Secondly, is there any suggestion of libraries or anything in java language which can help me to finish this project?

Bernard
  • 4,240
  • 18
  • 55
  • 88
  • you can define xml structure as per you need. – Alpesh Gediya May 11 '13 at 04:29
  • It would be better if you first go through some basic XML tutorial to learn about XML basic such as tags, attributes, namespace... – Alpesh Gediya May 11 '13 at 04:32
  • http://www.vogella.com/articles/JAXB/article.html – Kanagavelu Sugumar May 11 '13 at 05:17
  • Am I the only one who thinks some of the commenters on this question have got confused between `XMI` and `XML`? – Luke Woodward May 11 '13 at 11:56
  • I have studied the XML language. I'm writing a program which generate the class digram of any source code(in java language). Just like starUML or AgroUML which create the XMI file which is the graphical description of class diagrams. Now how the structure of xmi file should be? – Bernard May 11 '13 at 15:37

1 Answers1

3

I think the tag order doesn't matter in XMI. In general, XMI just defines how to map MOF to XML. So basically you build the M2 model (=UML) from Java and and then map this to XML with XMI if I understand this correctly (and I think the double indirection is why you don't find good resources for the mapping from UML to XMI directly).

For many people, examples may be more accessible than the chain of transformation rules defined by the various OMG standards. So I'd just draw a minimal UML example diagram in my favorite UML tool for the export aspect I am interested in and look at the exported XMI. Then add features as needed...

P.S.: You may want to use the Java reflection classes (package java.lang.reflect) instead of parsing the the Java source yourself to generate XMI (if you don't need to preserve method argument names).

Stefan Haustein
  • 18,427
  • 3
  • 36
  • 51
  • 2
    Using reflection throws away the parameter names of methods. This _might_ be a concern or not - YMMV. – A.H. May 11 '13 at 09:20
  • @Stefan Haustein, I appreciate your respond but I didn't understand you clearly. I am exactly parse the java code to generate XMI file. I have seen the example created by StarUML on windows or ArgoUML on mac. I find relationship between classes and also their content and generate UMLClass Diagram. I'm impressed with java reflection but can I use it for my program to determine class diagram of any source. (The input of program is any source code) – Bernard May 11 '13 at 15:35
  • @Bernard You need to compile the target program in order to use reflection. You can do so from within Java using javax.tools.JavaCompiler. As A.H. points out, this works only if you don't need to preserve method parameter names. It may still be a simple way to get started without needing to create your own Java source parser first.... – Stefan Haustein May 11 '13 at 20:38