Integrations (PTC products, 3rd party products and code) > Code integration (Ada, ARINC 653, C, C#, C++, IDL, Java, SQL and VB) > Java code > Reverse engineering legacy Java code > Mapping information > Mapping information (excluding state diagrams) > Association and role mapping for Java (Java code)
  
Association and role mapping for Java (Java code)
ACS generates Roles applied by Associations as attributes of a class or interface.
Reverser Notes: When reverse engineering a class' attributes, the Reverser will reverse engineer an attribute as a Role if all of the following statements are true:
The Java attribute's data type can be identified as a class in the code being reverse engineered.
The Java class that is used as a data type is being reverse engineered.
The Reverser cannot match the Java attribute to an Attribute in the Model.
The generation of an attribute from an Association and Role is derived from the properties of the Association and Role, and the tagged values set for the Tag Definitions applied to the Role by the «Java Role» stereotype.
Association Properties:
The Association Type property determines the Java file in which the attributes are created:
Start-end - attributes generated in the file created for the Start item.
End-start - attributes generated in the file created for the End item.
Bi-directional - attributes generated in the files created for both the Start item and End item.
None - no attributes are generated.
Aggregations are treated the same as Associations.
The Composite property is used only in the generation of Ports. For more information, see the Port property that follows.
If the tagged value of the Java Array Spec tag definition has been set, the Multiplicity property is ignored. If the tagged value of the Java Array Spec tag definition has not been set, the Multiplicity property is generated as follows:
For 'only one', ACS generates the attribute as having a single value.
Example code:
public class Class1
{
// Roles

private Class2 rClass2;

}
For any other value, ACS generates an array.
Example code:
public class Class3
{
// Roles

private Class4[] rClass4;
}
Role Properties:
Unnamed Roles are generated with an 'r' prefix, and named Roles are generated without an 'r' prefix. Prefixing and suffixing of named and unnamed Roles is controlled through the [role] and [unnamed role] sections of the mangle.ini file. If you want all Roles to be generated with an 'r' prefix, ensure that the Role sections of the mangle.ini file are as follows:
[role]
AddPrefix=r
AddSuffix=

[unnamed role]
AddPrefix=r
AddSuffix=
If the Visibility property is set to Public, Protected or Private, ACS generates the attribute with Public, Protected or Private access, unless the Java Default Access tag definition is set to TRUE.
Example code:
public class foo
{
public bar myBar;
protected thing myThang;
}
If Visibility property is set to Package or the Java Default Access tag definition is set to TRUE, the Access property is ignored and ACS generates the attribute with no access specifier.
The Behavior property is used with the Port property - for more information, see the Port property entry.
If the Default property is set, ACS generates the Role as an attribute with an initial value in the Java file.
Example code:
public class foo
{
bar myBar = null
}
The Name property is generated as the name of the attribute in the code.
Example code:
class foo
{
bar myBar;
}
* 
If a Role is unnamed, the name of the generated attribute is that of the associated item prefixed with an 'r'.
Example code:
public class Class1
{
// Roles

private Class2 rClass2; // Unnamed Role
private Class2 NamedRole // Named Role
}
ACS may modify the role name that is added to the code to make it valid for Java. You can specify the exact role name to add to the code through the CODE_GENERATION_NAME property of a Role. Tell me more...
If the Port property is set to true (Port check box selected on Property Pages) and the Behavior property is set to true (Behavior check box selected on Property Pages) the attribute is initialized to the 'this' reference as long as the following properties apply:
Example code:
For the following example:
public class Class1
implements Interface1
{
// Roles
// following class generated to delegate messages sent to rPort1
class _RtS_rPort1_Interface1 implements Interface1
{
}
_RtS_rPort1_Interface1 rPort1;
}
Composite property is set to false.
Storage property is set to On Instance.
Multiplicity property is set to 'zero or one' or 'only one'.
The Port has no navigable associations to any Class, Part or Port.
The Data Type is an Interface that is implemented by the Class.
If the Port property is set to true (Port check box selected on Property Pages) and the Behavior property is set to false (Behavior check box cleared on Property Pages), ACS generates a local class to implement the interface data type as long as the following properties apply:
Example code:
For the following example:
public class Class1
{
// Roles

// following class generated to delegate messages sent to rPort1
class _RtS_rPort1_Interface1 implements Interface1
{
// Operations

public void Operation1()
{

rXYZ.Operation1();

}

private Class3 rXYZ;

}

_RtS_rPort1_Interface1 rPort1;

}
Composite property is set to true.
The Data Type is an Interface..
The generated class derives from the data type and implements each function by delegation to all navigable Roles that support the Operation.
If the Read Only property is set to TRUE (Read Only check box selected on Property Pages), the attribute is generated as final.
Example code:
public class foo
{
final bar myBar; // Read only = true
}
If the Storage property is set to On Class, the attribute is marked as static.
Example code:
protected static foo myFoo;
The Unique property is ignored.
Role Tag Definitions:
The following Tag Definitions are applied to a Role by the «Java Role» stereotype:
If the tagged value of the Java Actual Arguments tag definition has been set and the Role is using a Java Generic as its data type, ACS generates the value as the arguments that are passed to the generic type.
If the tagged value of the Java Array Spec tag definition has been set, ACS generates the value after the attribute's data type. Note the tagged value should be one or more pairs of empty brackets.
Example code:
class foo
{
bar [] someBars;
bar [][] moreBars;
}
If the tagged value of the Java Data Type tag definition is set, the Role represents a Java Generic Collection class and the tagged value specifies the Generic Class that is used to hold that collection. ACS generates the value as demonstrated in the following example.
In this example, the role is linked to the Class 'Bar' and the Java Data Type tag definition is linked to the generic Class 'List'. ACS generates the following code:
public class Foo
{
List<Bar> m_TheBars = new List<Bar>;
}
Reverser Notes: Use the [Collection Classes] section of the JavaGen.ini file to specify template collection classes you are reverse engineering. For more information see the JavaGen.ini file.
If the tagged value of the Java Default Access tag definition is set to TRUE, ACS generates the attribute with no access specifier, irrespective of how the Visibility property is set.
If the tagged value of the Java Field Modifier tag definition is set to volatile, transient or volatile transient, ACS generates the selected keyword in front of the attribute's data type.
Example code:
public class foo
{
public transient volatile bar myBar;
}
If the tagged value of the Java Generic Name tag definition is set, the Role represents a Java Generic Collection class and the tagged value specifies the Generic Class that is used to hold that collection. ACS generates the value as demonstrated in the following example.
In this example, the role is linked to the Class 'Bar' and the Java Generic Name tag definition is set to 'List', ACS generates the following code:
public class Foo
{
List<Bar> m_TheBars = new List<Bar>;
}
Note that if a value is set for the Java Data Type tag definition, ACS ignores the Java Generic Name tag definition.
Reverser Notes: Use the [Collection Classes] section of the JavaGen.ini file to specify template collection classes you are reverse engineering. For more information see the JavaGen.ini file.
If the tagged value of the Java Needs Qualified Type tag definition is set to TRUE, ACS generates the attribute's data type with a qualified name.