There are several possibilities to fine-tune the appearance of the generated Java source code. Among them are the creation of accessor methods for attributes, the types for collection attributes, and the list of import statements in the files.
Accessor methods
From Poseidon 1.4 on, you can create accessor methods for attributes automatically. This way, you can fine-tune the code so that some attributes have accessors, some not. In previous versions of Poseidon, you could only have setters/getters for all attributes, or for none.
In
, there is a check box called 'Generate accessor methods for attributes'. Check this box to have accessor methods created for every attribute that is created. If the attribute has a multiplicity of 1..1 or 0..1, two simple getAttribute() and setAttribute() methods are created. For attributes with a finite multiplicity, an array is generated, and the accessor methods include addAttribute() and setAttribute(). For an unbounded multiplicity, a Collection is generated, and the appropriate access methods like addAttribute() and removeAttribute() are produced.You can fill the bodies of these access methods according to your business logic. Also, you can hide the display of accessors by setting the check box 'Hide accessor methods' in
.Additionally, you can generate the standard accessor methods for your attributes at code generation time. These will be visible only in the generated code, not in your Poseidon project.
Collection types
Poseidon up to version 1.3.1 used the type Vector whenever an association had a multiplicity of ..*.
From version 1.4 on, the rules are:
Create an attribute of the element's type if the multiplicity is 0..1 or 1..1.
Create a Collection type attribute if the multiplicity has an upper bound of *.
Create an array of the element's type if the multiplicity has an upper bound that is not 1 and not * (that is, it is a number).
In Code Generation—Settings, you can define what type of collection should be used for Collection types. The default is ArrayList, but you can enter any type (e.g., Vector ) that implements Collection. Accessor methods are programmed against Collection.
Future versions of Poseidon, you will be able to distinguish between ordered, unordered and sorted attributes, and you will be able to give different kinds of implementation types such as TreeSet for unordered, ArrayList for ordered and Vector for sorted attributes.
Import statements
Import statements can be added to classes in two ways: By drawing dependencies or by entering tagged values.
The graphical way is to draw a dependency from the class to the class or package that you want to import. An appropriate import statement will be generated: Either import package.* or import package.Class.
The second way (that does not clutter up your diagrams) is to add a Tagged Value called JavaImportStatement to the class. Then enter a number of imports, separated with colons. Qualified names can be given in Java syntax. For example, import java.lang.reflect.* and java.io.IOException by setting the tagged value JavaImportStatement to java.lang.reflect.*:java.io.IOException.
Modifying templates (Developer and Professional Editions)
More advanced customizaton of the generated code is possible if you are using one of the Premium Editions. Modification of the templates that are used for code generation is possible with these editions. We cover this topic briefly in a separate chapter and more deeply in a separate document that is distributed with these editions and online under http://www.gentleware.com/support/developer.
Javadoc Tags
You may not want certain operations to be reverse engineered. Any operations with the Javadoc tag '@poseidon-generated' will be excluded from the reverse engineering process.