5.4.2.5.1. Parameter
<parameter> is a child element of <method> and defines a single parameter of a method. It is also used to define the return type.
Usage
A method (method in code_instruction) has 0 or more parameters (arguments). These parameters can be created with the <parameter> child elements of method.
1<method>
2 name=""
3 ...
4 <parameter>
5 name=""
6 final=""
7 code instruction base
8
9 <apicommentline></apicommentline>
10 <devcommentline></devcommentline>
11 <import></import>
12 <annotation></annotation>
13 <datatype></datatype>
14 </parameter>
15 ...
16</method>
The name attribute is mandatory and indicates the name of the method.
Attributes
Name |
Details |
---|---|
name |
The name of the parameter made. “return” is reserved for return parameter. |
final |
true or false. Indicates whether or not the parameter should be defined final. Parameters are final by default. |
code instruction base |
Sub elements
Name |
Details |
Number |
---|---|---|
apicommentline |
Javadoc that is attached to this field. |
0 or 1 |
devcommentline |
Commentary that is attached to this attribute. |
0 or 1 |
import |
The value of this field is attached as an import statement to the class or interface in which this attribute is defined. |
0 or 1 |
annotation |
Annotation defined for the attribute. |
0 or more |
datatype |
0 or 1 |
Examples
1<method>
2 name="constructor"
3 visibility="${fmsnippet.field.visibility_of_constructor}"
4 foreach="currentModelObject.property.createConstructor"
5 var0="${forEachPropertyValue}"
6
7 <parameter>
8 name="${field.name}"
9 foreach="field.property.useInConstructor"
10 condition="${forEachPropertyValue}=${var0}"
11
12 <datatype>${field.type}</datatype>
13 </parameter>
14
15 <parameter>
16 name="${reference.name}"
17 foreach="reference.property.useInConstructor"
18 condition="${forEachPropertyValue}=${var0}"
19
20 <datatype>${reference.type}</datatype>
21 </parameter>
22
23 <body>${fmsnippet.java.model.method.constructorUsingFields} </body>
24</method>
This method is used to create constructors. The constructor is generated only if the model object has metadata named createConstructor defined. The value of the createConstructor property is stored in var0 and is used to read the right arguments for this constructor from the modelObject metadata. The properties are saved in var0 with the expression: useInConstructor=${var0}.
The following xml from <model> creates a 3 argument constructor (firstName, middlename and lastName) for the Person object by using this mechanism:
1<model>
2 <package>
3 name="domain_model"
4 <object>
5 name="Person"
6 <metadata>
7 <createConstructor>FirstConstructor</createConstructor>
8 </metadata>
9
10 <field>
11 name="firstName" type="String" notnull="true" length="40"
12 <metadata>
13 <useInConstructor>FirstConstructor</useInConstructor>
14 </metadata>
15 </field>
16
17 <field>
18 name="middleName" type="String" notnull="false" length="10"
19 <metadata></metadata>
20 </field>
21
22 <field>
23 name="lastName" type="String" notnull="true" length="60">
24 <metadata>
25 <useInConstructor>FirstConstructor</useInConstructor>
26 </metadata>
27 </field>
28 </object>
29 </package>
30</model>