5.4.2.3. Class

<class> is a child element of <package> and defines the generation of a Java Class.

Usage

Listing 5.30 <class/> example
 1<code_instruction>
 2        ...
 3
 4        <class>
 5            name=""
 6            visibility=""
 7            abstract="true|false"
 8            final="true|false"
 9            enum="true|false"
10            code instruction base
11
12            <generic></generic>
13            <apicomment></apicomment>
14            <developercomment></developercomment>
15            <import></import>
16            <annotation></annotation>
17            <implements>
18                condition=""
19            </implements>
20            <inherits>
21                condition=""
22                foreach="package|object|attribute"
23                package=""
24            </inherits>
25            <enum_constants></enum_constants>
26            <field></field>
27            <method></method>
28        </class>
29
30        ...
31</code_instruction>

Attributes

Table 5.34 attributes of <class/>

Name

Details

name

The name of the java class to be generated.

visibility

Visibility of the class. Possible values are public, protected and private

abstract

true or false. Indicates whether or not the generated class should be abstract.

final

true or false. Indicates whether or not the generated class should be final.

enum

true or false. Indicates whether or not the generated class should be an enum. Default is false. If true, the childelement enumConstants must be defined.

Example:

...
        <class>
            name="Color"
            visibility="public"
            enum="true"
            <enum_constants>WHITE, BLACK, RED, YELLOW, BLUE</enum_constants>
        </class>
...

This code_instruction class creates the java enum:

public enum Color {
        WHITE, BLACK, RED, YELLOW, BLUE;
}

In practice, enum classes (as wel as normal classes) are created from model object elements. By setting metadata for each model object, you can specify whether an enum or normal java class should be generated:

<class>
    name="${code_instruction.property.model.implementation.class}"
    visibility="public"
    enum="${model.property.object.enum}"
    foreach="object"

    <import></import>
    <enum_constants>
        condition="${model.property.object.enum}==true"
        ${fmsnippet.java.pojo.enum.enum_constants}
    </enum_constants>
</class>

Model.xml contains an object (RelationType) with metadata enum=true and metadata for enum_constants:

<model>

    <package name="domain_model">
        ...
        <object name="RelationType">
            <metadata>
                <enum>true</enum>
                <enum.constants>Private,Business</enum.constants>
                <serialVersionUID>1</serialVersionUID>
            </metadata>
        </object>
        ...
    </package>
</model>

code instruction base

Loupe S Code instruction base.

Sub elements

Table 5.35 sub elements of <class/>

Name

Details

Number

generic

Makes the class generic (java 1.5 or higher).

0 or 1

apicommentline

Javadoc that is attached to this class.

0 or more

devcommentline

Commentary that is attached to this class.

0 or more

import

All library elements under import are translated in the class as import statements.

0 or more

annotation

Annotation defined for the class.

0 or more

implements

The interface that is implemented by this class.

0 or more

inherits

The class from which this class is derived.

0 or more (java supports only 1)

enum_constants

Enum values (eg. Private, Business)

0 or 1

field

Those fields contained in this class. The field element defines both the field and possibly also the related getters and setters (dependent on the access attribute (rw|ro|wo). The getter_body and setter_body child element of field can be used for custom code of a getter of setter.

0 or more

method

Methods included in this class.

0 or more