4.4.2.3. Class

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

Usage

Listing 4.29 <class/> example
 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
<code_instruction>
        ...

        <class>
            name=""
            visibility=""
            abstract="true|false"
            final="true|false"
            enum="true|false"
            code instruction base

            <generic></generic>
            <apicomment></apicomment>
            <developercomment></developercomment>
            <import></import>
            <annotation></annotation>
            <implements>
                condition=""
            </implements>
            <inherits>
                condition=""
                foreach="package|object|attribute"
                package=""
            </inherits>
            <enum_constants></enum_constants>
            <field></field>
            <method></method>
        </class>

        ...
</code_instruction>

Attributes

Table 4.24 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 4.25 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