Glossary
| Acronym | Definition |
|---|---|
| SPO | Software Production Operation |
| BL | Behavior Layer |
| ML | Middleware Layer |
| BSM | Behavior Specific Middleware |
| TSM | Target Specific Middleware |
Glossary
Referenced Documents
Document History
Goal of the documentThis document describes the detailed requirements of the UML Class code generator involved in the java code generation for a UML Class. Audience of the documentPeople who need to understand principles of the code generation for UML Class. General ConceptsUML & SysML to Java code generator is an operation generating Java code from UML and SysML design. See [2] for more information. This specification document is more focused on the Java code generation from UML class diagram. Supported ElementsHere is an exhaustive list of elements used by the code generator to produce the Code with a summary of the purpose and impact.
Validation Constraints N/A
Code Generator Specification
This section is divided in 2 parts:
Files Specifications
Code generator generates one java file for each element which can be a UML class, a UML interface or a UML enumeration:
General requirements related to file content are described in [1]. <ObjectName>.java<ClassName>.java, <InterfaceName>.java and <EnumerationName>.java are described in the same way. For the following chapter: ClassName, InterfaceName and EnumerationName are replaced by ObjectName which points to the name of the Class or the Interface or the Enumeration. <ObjectName>.java file describes the content of a class entity. This file declares and implements the elements associated to a class. File <ObjectName>.java is generated for the each UML class / UML interface / UML Enumeration element involved in the code generation. The file name <ObjectName>.java matches the name of the element. File is generated in a folder reflecting the structure of package of the UML project. ![]() The package in which the file is generated is declared on top of file after the header. package root.myPachage; Example: package declaration Import of other classes, Interfaces, enumerations on which the current class depends depending on relations - inheritance, composition, aggregation, usage - are generated if any. import root.otherpackage.LockableElement; Example: Imports declaration See chapter Semantic Code Specifications for more details. The class is described using the regular java declaration mechanism. The interface is described using the regular java declaration mechanism. The enumeration is described using the regular java declaration mechanism. See the dedicated section in chapter Semantic Code Specifications.
/**
* @generated_from <class uiid>
*/
public class LockManager {
<MEMBERS DECLARATION – See chapter Semantic Code Specifications>
}
Example: Class declaration
/**
* @generated_from <interface uiid>
*/
public interface MyInterface {
<MEMBERS DECLARATION – See chapter Semantic Code Specifications>
}
Example: Interface declaration
/**
* @generated_from <enumeration uiid>
*/
public enumeration MyEnum {
<MEMBERS DECLARATION – See chapter Semantic Code Specifications>
}
Example: Enumeration declaration Semantic Code Specifications
This section describes the behavior of the code generator depending on the UML element. PackageIn Java, a package is a logical grouping of classes, interfaces, and enumerations that are related to each other. The concept of "visibility of a package" does not exist in Java. ![]() When ObjectName is created within a hierarchy of packages, This hierarchy is declared on the top of the file using the package statement.
package package_name.sub_package_1.sub_package_2;
/**
* @generated_from <class uuid>
*/
class A {
}
Example: Declaration of a package hierarchy Class
If generalization relation is created from a class to another one, then this inheritance relation is reproduced in class declaration. ![]()
/** @generated from: <class uuid> */
public class A extends B {
}
Abstract classA java class is abstract when it contains at least one abstract method. Abstract classes cannot be instantiated directly; they serve as blueprints for subclasses to inherit and provide implementations for their abstract methods. If the isAbstract attribute of the class is set to true, then the class is generated as an abstract class by adding the keyword abstract to the class declaration.
/** @generated from: <class uuid> */
public abstract class A {
/**Abstract method*/
public abstract method ();
}
Example: Abstract class Final classA final class is a class that cannot be subclassed or extended. If the isLeaf or isFinalSpecialization attribute of the class is set to true, then the class is generated as a final class by adding the keyword final to the class declaration.
/**
* @generated_from <class uuid>
*/
public final class A {
}
Example: Final class Composition relation (black diamond)![]() ![]() [MEMBERS DECLARATION] If a composition relation is created from a class to another one as directional or not directional, a variable is created in the source class of relation to point to target class. If a composition relation is created from a class to another one as not directional, a variable is created in the target class of relation to point to the source class.
class A {
/**
* @brief Attribute for composition relation to B:b
* @generated_from <property uuid>
*/
private B b;
}
Example: Variable in source class for directional and not directional relation
class B {
/**
* @brief Attribute for aggregation relation to A:a
* @generated_from <property uuid>
*/
private A a;
}
Example: Variable in target class for not directional relation Aggregation relation (white diamond)![]() [MEMBERS DECLARATION] If an aggregation relation is created from a class to another one as directional or not directional, a variable is created in the source class of relation to point to target class. If an aggregation relation is created from a class to another one as not directional, a variable is created in the target class of relation to point to the source class.
class A {
/**
* @brief Attribute for association relation to B:b
* @generated from <property uuid>
*/
public B b;
}
Example: Variable in source class
class B {
/**
* @brief Attribute for aggregation relation to A:a
* @generated from <property uuid>
*/
public A a;
}
Example: Variable in target class for not directional relation Association relation![]() [MEMBERS DECLARATION] If an association relation is created between 2 classes, a variable is created in each class to point to the other class.
class A {
/**
* @brief Attribute for association relation to B:b
* @generated from <property uuid>
*/
public B a;
}
class B {
/**
* @brief Attribute for association relation to A:a
* @generated from <property uuid>
*/
public A a;
}
Example: Association between 2 classes Realization relation![]() If realization relation is created from a class to one or multiple interfaces, then this implementation relation is reproduced in class declaration.
/** @generated from: <class uuid> */
public class A implements B,C {
}
Example: Class declaration with realization Interface Realization relationInterface Realization relation to a specific method is not supported by java. This element is not supported by java code generator. Substitution relationSubstitution relation is not supported. Dependency relationAbout Dependency relation Interface[MEMBERS DECLARATION] Interface methods are generated without any body. In Java, interface methods are public and abstract.
/**
* interface ContactOperations
* @generated_from <interface uuid>
*/
public interface ContactOperations{
/**
* add method
* @generated_from <operation uuid>
*/
Contact add(Contact /*in*/ contact);
}
Example: Interface methods declaration Datatype EnumerationEnumeration is a special data type that allows a variable to be a set of predefined constants. ![]() [MEMBERS DECLARATION] Enumeration is generated via the standard Java mechanism to generate enums.
/**
* @generated_from <enumeration uuid>
*/
private enum Group {
/**
* @generated_from <litteral uuid>
*/
FAMILY,
/**
* @generated_from <litteral uuid>
*/
FRIEND,
/**
* @generated_from <litteral uuid>
*/
COLLEAGUE,
/**
* @generated_from <litteral uuid>
*/
UNKNOWN;
}
Example: Enumeration declaration Property
[MEMBERS DECLARATION] Each property declared in a UML Class is replicated in the generated code. A brief description is generated for any property describing type and name of the variable. Additional documentation is generated if the documentation section is field in the model. Type of the property is used as declared in the model. Visibility of the property is used as declared in the model. Default value is set as declared in the model. /** * This is my documentation for attribute * @brief Attribute for String:attribute * @generated_from <property uuid> */ private String attribute = “attr”; Example: Property Final declarationIf the isReadOnly attribute of the property is set to true, the property is marked as final, and it must be initialized. /** * @brief Attribute for String:attribute * @generated_from <property uuid> */ private final String attribute = “attr”; Static declarationIf the isStatic attribute of the property is set to true, the property is marked as static, it belongs to the class itself, rather than to any specific instance of the class, it can be accessed directly using the class name. /** * @brief Attribute for String:attribute * @generated_from <property uuid> */ private static String attribute; Array declaration![]() If the multiplicity corresponds to a finite number or an interval of finite numbers, an array is created with a length equal to the upper value. /** * @generated_from <property uuid> */ public int[] number = new int [10]; Example: Array declaration List declaration![]() If the multiplicity is equal to "*", isOrdered and isUnique attributes are not set or set to false, a collection List is created. If the multiplicity is equal to "*" if isOrdered is set to true and isOrdered is set to false or not set, a collection List is created.
If a List is used according to above rules, import of
/** * @generated_from <property uuid> */ public List<Integer> number; Example: List declaration Set declarationIf the multiplicity is equal to "*", isOrdered is set to false or not set and isUnique is set to true, a collection Set is created.
If a Set is used according to above rules, import of
/** * @generated_from <property uuid> */ public Set<Integer> number; Example: Set declaration Sorted Set declarationN/A
Operation
[MEMBERS DECLARATION] ![]() Each operation declared in a UML Class or UML Interface is generated within their body. A brief description is generated for any property describing type and name of the variable. Additional documentation is generated if the documentation section is field in the model. Visibility of the operation is used as declared in the model. In the context of an UML Class, user code section is inserted in operation to let the user fills his behavior. If any, a default return code is inserted in the user code section.
/**
* @generated_from <operation uuid>
*/
public boolean lockDoors(){
/* BEG_USER_CODE<operation uuid>) do not remove */
// Add your code here
return true;
/* END_USER_CODE(<operation uuid>) do not remove */
}
Example: Operation ConstructorConstructor methods are only generated when explicitly declared in UML Class or UML Interface. If an operation has the same name as the class, it is considered a constructor of the class. If operation parameters have the same name as the class attributes, the assignement of the value is done automatically.
class Door{
private String attr;
/**
* @brief Constructor of Door class
* @generated from <operation uuid>
*/
public Door (String attr) {
this.attr=attr;
/* BEG_USER_CODE(<operation uuid>) do not remove */
// Add your code here
/* END_USER_CODE(<operation uuid>) do not remove */
}
}
Example: Constructor If the constructor contains parameters that are not among the attributes of the class, the user can implement their own logic inside it.
public class Door{
private String attr;
/**
* @brief Constructor
* @generated_from < operation uuid>
*/
public Door (int a) {
/* BEG_USER_CODE(<operation uuid>) do not remove */
/* Add your code here */
/* END_USER_CODE(<operation uuid>) do not remove */
}
}
Example: Constructor with different parameters Getter & SetterIn Java it is recommended to write getters and setters for all attributes, regardless of their visibility levels (private, protected, or public) for Encapsulation, compatibility, flexibility and Maintenance. Getter and setter operations are generated for each attribute independently of their visibility except for attributes having isLeaf set to true. Only Getter operation is generated for attributes with isLeaf set to true independently of their visibility except for final attributes.
public class Door {
private String attr;
/**
* Getter for attribute attr
* @generated_from <property uuid>
*/
public String getAttr (){
return attr;
}
/**
* Setter for attribute attr
* @generated_from <property uuid>
*/
public void setAttr(String attr){
this.attr = attr;
}
}
Example: Getter and Setter Static declarationIf the isStatic attribute is set to true for an operation, then the method is generated as a static method.
/**
* @generated_from <operation uuid>
*/
static void function() {
/* BEG_USER_CODE(<operation uuid>) do not remove */
/* Add your code here */
/* END_USER_CODE(<operation uuid>) do not remove */
}
Example: Static declaration Final declarationIf the isLeaf attribute is set to true for a method, then the method is generated as a final function.
/**
* @generated_from <operation uuid>
*/
final void function() {
/* BEG_USER_CODE(<operation uuid>) do not remove */
/* Add your code here */
/* END_USER_CODE(<operation uuid>) do not remove */
}
Example: Final declaration Abstract declarationAn abstract method is a method declared without any implementation. If the isAbstract attribute of the operation is set to true, method is generated as abstract by adding the keyword abstract to the class declaration. /** * @generated_from <operation uuid> */ abstract void function(); Example: Abstract method ExceptionException not yet supported. Add a validation rule. Operation behaviorIf an operation has an Opaque behavior assigned to it, then this opaque behavior is replicated in the operation body. Not yet supported
void OperationWithBeh(){
/* BEG_USER_CODE(<operation uuid>) do not remove */
MyClass c;
c.privateOp();
/* END_USER_CODE(<operation uuid>) do not remove */
}
Example: Operation with behavior Parameter
Type of parameter of operation with direction set as "return" is used as return type of the operation. Type of the parameter is used as declared in the model. The parameter of operation with the direction set as "in", "out", or "inout" is used as a parameter of the operation. Direction "in" or "out" or "inout" of parameter is used for documentation purpose. Note that parameters direction do not have any meaning in Java. Note that parameters do not support Visibility.
/**
* @generated_from <operation uuid>
*/
public boolean setWindowPosition(ControlEnum /*in*/ windowPosition){
}
Example: Parameters Array declaration![]() If the multiplicity corresponds to a finite number or an interval of finite numbers, an array is created.
/**
* @generated_from <operation uuid>
*/
public double calculate(int[] /*in*/ values ){}
Example: Array declaration List declaration![]() If the multiplicity is equal to "*", isOrdered and isUnique attributes are not set or set to false, a collection List is created. If the multiplicity is equal to "*" if isOrdered is set to true and isOrdered is set to false or not set, a collection List is created.
If a List is used according to above rules, import of
/**
* @generated_from <operation uuid>
*/
public double calculate(List<Integer> /*in*/ a){}
Example: List declaration Set declarationIf the multiplicity is equal to "*", isOrdered is set to false or not set and isUnique is set to true, a collection Set is created. If a Set is used according to above rules, import of java.util.Set is added in import section. /** * @generated_from <operation uuid> */ Set<HistoryEntry> getHistoryRange(int /*in*/ from, int /*in*/ to); Example: Parameter as set | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||