When you develop a program, you have an UML model and source
code. The purpouse of the model is to visualize structural
relationships, interesting interactions and so on. The source code
contains the implementation in a specific programming language and
contains all the details required to execute the program. Neither
of these are the master store of information, from which the other
can be derived, but are two equally important components with
different focus. The model and the source code share a lot of
information that needs to be in sync, but it is both error prone
and boring to have to update the same information in two places by
hand. This problem is solved by JavaRE.
When you have modelled enough to start the implementation, you run
UML2Java to generate the source skeleton. When working with the
implementation, you probably add operations, classses and
attributes. When finished, you run Java2UML to update the model
with the new information and can go back and model some more. Run
UML2Java again to update the source code with new things added to
the model. Repeat the iteration until the program is finished.
Java2UML
Java2UML updates or generates an UML XMI model from Java source
code.
Setup the CLASSPATH to point at java2uml, nsuml.jar, xml4j.jar,
antlr.jar, the classes that you want to model and any libraries
used by them. Then run
java java2uml.Java2UML <model> <sourcepath>
<model> is the XMI file you want to create or update.
<sourcepath> is the file or directory with files you want to
model.
To find out if an unknown class (not yet in the UML model) is an
interface or a class, reflection is used. Therefore, all classes
and interfaces that is used by the source must be incuded in the
classpath. When the classes and interfaces have been included in
the model once, they no longer need to be in the classpath.
UML2Java
UML2Java updates or generates Java source code from an UML XMI
model.
Setup the CLASSPATH to point at uml2java, nsuml.jar, xml4j.jar and
antlr.jar. Then run
java uml2java.UML2Java <model> <sourcepath> {<class> | <package.*>}
<model> is the XMI model. <sourcepath> is the root
directory for the source. <class> is the class to generate
code for. <package.*> is the package to generate code for.
Scope
JavaRE handles
- Packages
- Classes
- Interfaces
- Generalizations
- Abstractions<<Realize>>
- Operations
- Attributes
- Javadoc
JavaRE leaves all other information in the source and in the model
untouched, including
- Method implementations
- Attribute initialization code
- Associations
- Import statements
- Exceptions
- Comments, excluding javadoc
Limitations
-
JavaRE works best if only one class is defined in a source
file. Inner classes are allowed.
-
JavaRE works best if only one attribute is declared in a
single statement.
-
Operations with the same name have to be in the same order in
the model and in the source code. (No parameter signatures are
checked.)
-
Only inner classes and interfaces are automatically removed
from the model and the source.
|