In theory, an UML association consists of at least two association ends. eUML2 Modeler supports only the associations with two ends. All UML association data are stored in each association end, which corresponds a property. A property as an association end must is tagged by @uml.associationEnd. The other tags @uml.associationand @uml. associationStereotype are optional.
Here is an example of an association between Company and Employee:
The association has an UML stereotype of type Realization.
public class Employee
{
@UML.Property("company")
@UML.AssociationEnd(inverse = "employees:database.Company") @UML.Association(inverse = "employment", stereotypes = @Stereotype("Intermediate::Realization")) private Company company; ... } public class Company
{
@UML.Property("employees")
@UML.AssociationEnd(inverse = "company:database.Employee", multiplicity="(0 -1)") @UML.Association(inverse = "employment", stereotypes = @Stereotype("Intermediate::Realization")) private Collection employees; ... }
Let’s consider a complicate example: the n-ary qualified association. If all employees are classified by their positions, we have the following design.
public class Company
{
@UML.Property("employees")
@UML.AssociationEnd(inverse = "company:database.Employee", qualifier = "position:java.lang.String model.Employee", multiplicity = "(0 -1)") @UML.Association(inverse = "employment", stereotypes = @Stereotype("Intermediate::Realization")) private Map employeesMap; @UML.Property("employees") public Collection getEmployees(String key){ return (Collection) this.employeesMap.get(key); } ... }
public class Employee
{
@UML.Property("company")
@UML.AssociationEnd(inverse = "employees:database.Company") @UML.Association(inverse = "employment", stereotypes = @Stereotype("Intermediate::Realization")) private Company company; ... }
package com.soyatec.uml.annotations; public @interface UML { { ... /** * Association end annotation definition */ @Target({ElementType. METHOD, ElementType. FIELD}) public @interface AssociationEnd { Multiplicity multiplicity() default @Multiplicity(); int dimension() default 0; boolean readOnly() default false; boolean ordering() default false; Aggregation aggregation() default Aggregation.NONE; Class container() default Collection.class; String elementType() default""; String inverse() default""; Qualifier qualifier() default @Qualifier( key=@com.soyatec.uml.annotations.Property(), value=@com.soyatec.uml.annotations.Property()); com.soyatec.uml.annotations.Stereotype[] stereotypes() default {}; } /** * Association annotation definition */ @Target({ElementType. METHOD, ElementType. FIELD}) public @interface Association { String value(); // name com.soyatec.uml.annotations.Stereotype[] stereotypes() default {}; } ... }
@UML.Association (0…1)
Name |
Value Type |
Cardinality |
Default value |
Description |
value |
String |
(0…1) |
“” |
The association name. |
stereotypes |
@Stereotype[] |
(0…*) |
{} |
|
@UML.AssociationEnd (1)
Name |
Value Type |
Cardinality |
Default value |
Description |
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 N-ary multiplicity. |
aggregation |
String |
(0…1) |
none |
The possible values are:
|
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. In case of a qualified association with n-ary multiplicity, this attribute is used to specify the collection type. |
ordering |
String |
(0…1) |
false |
If the property is a collection, this attribute indicates whether the element is ordered. |
inverse |
String |
(0…1) |
“” |
This value indicates the inverse property. The value is composed of : <property name>:<qualified class name>. |
elementType |
String |
(0…1) |
“” |
This attribute is used to indicate the element type in collection. It is used only in unidirectional association. |
qualifier |
String |
(0…1) |
“” |
This attribute contains the qualifier definition if the association is qualified. It is composed of: <key name>:<qualified key type> <qualified value type> |
stereotypes |
@Stereotype[] |
(0…*) |
{} |
|