Use the /atg/dynamo/nucleus/ParameterConstructorInstanceFactory
component to instantiate components that are based on classes that have constructors that take arguments. See Parameterized Constructors.
To use ParameterConstructorInstanceFactory
:
Include the
$class
property in your component configuration file. This is the class that requires constructor arguments.Include the
$instanceFactory
property and set its value to/atg/dynamo/nucleus/ParameterConstructorInstanceFactory
.Set the value of each constructor argument. Include one or more
$constructor.param[
n
].value
properties. Replace n with the zero-based index number of the argument. For example, to set the value of the first constructor argument:$constructor.param[0].value=Hello
Set the Java data type of each constructor argument. Include one or more
$constructor.param[
n
].type properties
. Replace n with the zero-based index number of the argument. For example, to set the type of the first constructor argument:$constructor.param[0].type=String
Note: You do not need to supply the Java data types of the constructor arguments if they are not ambiguous (there is only one constructor that takes the number of arguments you supply). However, if you supply any $constructor.param[
n
].type
properties, you must supply them for all of the constructor arguments. Whenever possible, provide type properties for all arguments.
The following example class and configuration files show how to use ParameterConstructorInstanceFactory
. The class requires constructor arguments.
package mycompany; public class MyClass { private String mystring; private int mynumber; // The constructor requires two arguments. public MyClass (String pMyString, int pMyNumber) { mystring = pMyString; mynumber = pMyNumber; } public String getmMyString() { return mystring; } public int getmMyNumber() { return mynumber; } }
The configuration file supplies values for each of the arguments.
$class=mycompany.MyClass $instanceFactory=/atg/dynamo/nucleus/ParameterConstructorInstanceFactory $constructor.param[0].value=Hello $constructor.param[0].type=String $constructor.param[1].value=321 $constructor.param[1].type=int # Set any further properties using standard syntax