UML to Java mapping

The following stereotypes of UML classes and data types are mapped to J2SE objects as below:


UMLOGC PurposeJava mapping
<<DataType>> A descriptor of a set of values that lack identity (independent existence and the possibility of side effects). A DataType is a class with no operations whose primary purpose is to hold the information. Interface
<<CodeList>> A flexible enumeration that uses string values for expressing a list of potential values. CodeList extends java.lang.Enum*
<<Union>> Contains a list of attributes where only one of those attributes can be present at any time. none
<<Abstract>> A polymorphic object class that cannot be instantiated. Interface
Constructor Cast an object into an object of an other type. A createFoo() method in a Factory interface.
Set<DataType> A finite set. Each object is considered to be in the set only once. java.util.Set
Sequence<DataType> A sequence type of collection, which contains an ordered finite list of values (possibly with repeated values) of the specified data type. Small array, or java.util.List if the sequence is likely to be big.
CharacterString A sequence of characters. java.lang.String in the general case, or java.net.URL for reference to a file.
Integer An integer number. int
Double A double precision floating point number. double
Boolean A value specifying TRUE or FALSE. boolean
Sign Sign + or -. int with value +1 ou -1
DateTime A character string as specified by ISO 19108, which comprises year, month, day and time of the day to the appropriate level of precision. java.util.Date
Scale A floating point number associated with a dimensionless unit. double
Length A floating point number associated with a linear unit. double with some getUnit() method (e.g. getAxisUnit()).
Angle A floating point number associated with an angular unit. double with some getUnit() method (e.g. getAngularUnit()).
Measure A floating point number associated with an arbitrary unit. double with a getUnit() method.

* For platform earlier than J2SE 1.5, the CodeList class will defines the same attributes than Enum but will not extends Enum.

 

Custom Javadoc tags

OpenGIS's Mandatory, Conditional and Optional attributes are marked using custom @UML mandatory, @UML conditional and @UML optional javadoc tags respectively. Additional javadoc tags include @UML association and @UML datatype. All the above-cited tags imply some renaming rules in order to comply with Java naming conventions.

Javadoc tag Usage and renaming rule
@UML datatype

Interfaces marked with this tag are "datatype" (as opposed to "abstract") in UML diagrams.

@UML mandatory

The Java method maps to a mandatory attribute in the UML diagram. The Java method name is prefixed by "get". For example, the mandatory "code" UML attribute maps to a getCode() Java method.

@UML conditional

The Java method maps to a conditional attribute in the UML diagram. The Java method name is prefixed by "get".

@UML optional

The Java method maps to an optional attribute in the UML diagram. The Java method name is prefixed by "get". For example, the optional "remarks" UML attribute maps to a getRemarks() Java method.

@UML association

The Java method maps to an association in the UML diagram. The UML's "uses" or "includes" prefix are omitted and the Java method name is prefixed by "get". For example, the CoordinateSystem class has a "usesAxis" association. In Java, associations map to ordinary methods. Consequently, the usesAxis association is mapped into a plain getAxis() method.

@rename <reason>

Some other name change has been applied in order to match more closely Java usage. A description of the change and its rational shall follow the @rename tag. There is two reasons for renaming:

  • In some occasions, abbreviations are expanded. For example a getCS() method returning a CoordinateSystem object is renamed getCoordinateSystem().

  • In some occasions, supplementary prefix are omitted. For example, some UML attribute names are prefixed by some abbreviation of the enclosing class name (e.g. "csName" is CoordinateSystem and "srsName" in ReferenceSystem). For Java interfaces, the above-cited attributes map to a plain getName() method. The same apply to "ID".

  • Methods returning an array are renamed to their plural form (e.g. getElement() to getElements()).

@unitof <quantity>

The method returns a double value which should be expressed in unit of Scale, Length or Angle. Some getUnit() method must be provided in addition to this method.

@revisit <comment>

Somme open issue to revisit.