Property annotation

A property may be abstract or concrete. A concrete property is generated into two kinds of elements in Java: a field to hold the data and its associated getters/setters. However an abstract one has only the abstract accessors.

There are two categories of property tags:

When you delete a property from class diagram, all methods marked by Member tags for this property will be deleted as well.

The property tags will be stored in the corresponding Java Field if the property is concrete. Others accessors will be marked as members of the property by the member tags, which has only the name attribute. For example, we have a property “ age” with “ persistence” stereotype in a class Person,

The generated codes are following:


public class Person
{
/** * @uml.property name="age" * @uml.stereotype uml_id="database::persistance" */
private int age; /** * @uml.property name="age" */ public int getAge() { return age; } /** * @uml.property name="age" */ public void setAge(int age) { this.age = age; } }

The bold black tags are Property tags and the bold blue UML tags are Member tags.

If the property is abstract, the Property tags will be stored in the getter and all accessors are abstract methods. Using the same example above, the abstract property “age” will be generated as following:


public abstract class Person
{
/** * @uml.property name="age" * @uml.stereotype uml_id="database::persistance" */
public abstract int getAge(); /** * @uml.property name="age" */
public abstract void setAge(int age); }

Once the accessors are generated, it is possible that users want to change them. To prevent the overriding by the forward code generation, users can use the directive tags by inserting the attribute bodyGenerated = false. For example, if users want add the change notification notify(“age”)in the setter setAge(), the complete code will be:

/**
 * @uml.property name = "age"
 * @uml bodyGenerated = "false"
 */
public void setAge(int age) { this.age = age notify(“age”); }

The comment of the property is retrieved from and stored in its primary member. Only the user comments and annotations in the primary member of the property are preserved during the property edition.

@uml.property (1)

 

Name

Value Type

Cardinality

Default value

Description

Name

String

(1…1)

 

This attribute contains a qualified name of the supplier.

readOnly

Boolean

(0…1)

“false”

The value “true” indicates that the property can be read only.

multiplicity

String

(0…1)

“{0 1}”.

The value contains two integer values enclosed by the brackets. The first is lower bound and the second is upper bound.

dimension

Integer

(0…1)

“0”

This is an array dimension of Java field. It is another way to implement Nary multiplicity.

ordering

String

(0…1)

“false”

If the property is a collection, this attribute indicates whether the element is ordered. Two values of UML 1.x ca be used as well: “ordered” and “unordered”

container

String

(0…1)

java.util.Collection

 

This attribute indicates the Java field type. It is necessary if the property is abstract and has n-ary multiplicity..

The old name “ javaType” still works.

default

String

(0…1)

“”

The default value of the property. This attribute is used only when the property is abstract.