Motivation
One useful, widely known and very "eye-catching" fashion to
represent the design of a software project is the UML class
diagram. In fact, there is a variety of CASE tools allowing
to build and manipulate such diagrams as well as to produce
code skeletons for programs based on the specifications the
author visualised in his diagram.
However, one might want to perform the reverse step: to
gain design information from a program, possibly because
the original information has been lost or in order to
check if what he developed corresponds to the actual
design.
Although it might seem straightforward (classes map
to class boxes, subclasses to generalisation relationships
etc.), it is a difficult issue when treating associations.
In a programmer's terms, an association between class
A and B occurs if A has a field where it stores Bs.
However, associations have cardinalities which tell,
again in a programmer's terms, how many B-objects
A could reference in his field during the execution
of the program.
This is generally impossible to tell, but might be
analysed for some cases, and this is the point where
class2uml enters with its idea.
What does class2uml do?
The program builds a class diagram recursively
parting from one given class. The depth of the
recursion can (and should) be limited by the user
in order to produce a diagram that is still
comprehensible...
The UML elements it displays are:
- classes and interfaces
- generalisations
- dependencies and
- associations (and compositions, which are a
special case of associations)
For associations, an analysis is performed in order
to allow an estimation of how many objects there
could be actually referenced in the object field
the association corresponds to. The goal is to be
able to tell the programmer in a safe way a little
more than the always-correct 0..*, but to base it on
intuitive analyses, so that he will be able to
understand where the result came from.
Additionally, class2uml analyses methods
for the query property - query methods are
said to be those that do not affect the system state.
It then layouts the class diagram using dot
from the Graphviz package and draws
it in a crude JAVA Swing window. It also exports
the diagram into a .dia file, which
can be opened with the free diagram editor
Dia. By default, this will be the
file export.dia.
The latter program allows you to edit the generated
class diagram on an UML level, to export it into
other formats, to print it and more.
Finally, as its newest feature, it writes its data into
XMI (XML Metadata Interchange) file which offers flexible
and tool independent treatment of the UML diagram that has been
produced. By default, this will be the file export.xmi.
The XMI flavour it uses is the one of the well-known
Open Source modelling tool ArgoUML.
Screenshots
Here you can get a more practical impression of the
program.
Example 1
Source of class2uml.Test:
package class2uml;
public class Test {
public String s = "Hello World!";
public void helloWorld() {
System.out.println(s);
}
}
Results of "java class2uml.ClassDiagram class2uml.Test":
(default: no recursive analysis of referenced classes)
 Swing window |
 Dia screenshot of the exported diagram |
 ArgoUML screenshot (diagram imported via XMI) |
|