4.4.2.4. Attribute

<attribute> is a child element of <class> or <interface> and defines the generation of a mapped Java type property, such as int, Integer, String, date etc.

Each attribute is a Java property of a Class or Interface.

Usage

A java attribute (field of an interface or class) is defined by an attribute element.

The name attribute is mandatory and indicates the name of the attribute.

Listing 4.28 Syntax
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<pattern>
        ...
        <attribute name=""
                   visibility=""
                   access=""
                   static=""
                   final=""
                   transient=""
                   volatile=""
                   foreach="package|object|attribute|reference|
                            object.reference|object.attribute|
                            currentModelObject.property"
                   condition=""
                   package=""
                   var0=""
                   var1=""
                   var2=""
                   var3=""
                   var4=""
                   var5="">
            <library></library>
            <datatype></datatype>
            <apicomment></apicomment>
            <developercomment></developercomment>
            <annotation></annotation>
            <annotation.getter></annotation.getter>
            <annotation.setter></annotation.setter>
            <body></body>
            <getterBody></getterBody>
            <setterBody></setterBody>
        </attribute>
        ...
</pattern>

Attributes

Table 4.25 attributes of <attribute/>

Name

Details

name

The name of the java attribute that is made (also called the field or property).

visibility

Visibility of this attribute. Possible values are public, protected en private.

access

The access attribute determines whether getters and setters should be created. Possible values are ro, rw and wo. With ro (readonly) only the getter is generated. With rw (readwrite) both getter and setter are generated. With wo (writeonly) only the setter is generated. If the access attribute is omitted, then neither getter nor setter is generated.

static

true or false. Indicates whether or not the attribute should be defined static.

final

true or false. Indicates whether or not the attribute should be defined final.

transient

true or false. Indicates whether or not the attribute should be defined as transient.

volatile

true or false. Indicates whether or not the attribute should be defined volatile.

foreach

Indicates whether the interface must be created for each element in model (value of foreach determines what model element). Possible values: package, object, attribute, reference.

condition

An expression that evaluates to true or false. Generation of the current file wil precede if true and otherwise not.

Example:

condition="${object.name}=Person"

In this case, the attribute is made only if the current model object has the name: Person. This works only if all model objects are iterated (foreach=”object”).

package

The name of the package in the model (model.xml) that must be used to apply the foreach attribute.

object

The name of the object in the model (model.xml) that must be used to apply the foreach attribute.

var0

Value that you wish to store in the pre-defined variable with the name var0. Reference to this value can be made later by means of: ${var0}. This can be used in both the pattern and in a snippet (freemarker or velocity template).

var1

Value that you wish to store in the pre-defined variable with the name var1. Reference to this value can be made later by means of: ${var1}. This can be used in both the pattern and in a snippet (freemarker or velocity template).

var2

Value that you wish to store in the pre-defined variable with the name var2. Reference to this value can be made later by means of: ${var2}. This can be used in both the pattern and in a snippet (freemarker or velocity template).

var3

Value that you wish to store in the pre-defined variable with the name var3. Reference to this value can be made later by means of: ${var3}. This can be used in both the pattern and in a snippet (freemarker or velocity template).

var4

Value that you wish to store in the pre-defined variable with the name var4. Reference to this value can be made later by means of: ${var4}. This can be used in both the pattern and in a snippet (freemarker or velocity template).

var5

Value that you wish to store in the pre-defined variable with the name var5. Reference to this value can be made later by means of: ${var5}. This can be used in both the pattern and in a snippet (freemarker or velocity template). * -

Sub elements

Table 4.26 sub elements of <operation/>

Name

Details

Number

library

The value of library is attached as an import statement to the class or interface in which this attribute is defined.

0 or 1

apicomment

Javadoc that is attached to this method.

0 or 1

developercomment

Commentary that is attached to this attribute.

0 or 1

annotation

Annotation defined for the attribute.

0 or more

parameter

Parameter of this method. The parameter with the name return is reserved for specifying the return parameter.

0 or more

exception

Exception thrown by this method.

0 or more

body

The contents of the method.

0 or 1