Use the /atg/dynamo/nucleus/MethodInstanceFactory component to create Nucleus components based on objects returned by factory methods. Factory methods are one way to create components with parameterized constructors. See Parameterized Constructors.

To use MethodInstanceFactory:

  1. Include the $instanceFactory property in the component properties file. Set its value to /atg/dynamo/nucleus/MethodInstanceFactory.

  2. Specify the Java class or Nucleus component that contains the factory method.

    To use a static factory method in a Java class, specify the class name with the $factory.class property as shown below.

    $factory.class=mycompany.MyStaticFactoryClass

    To use a non-static factory method in another Nucleus component, specify the Nucleus path of that component with the $factory.instance property as shown below.

    $factory.instance=/mycompany/MyFactoryComponent

  3. Include the $factory.methodName property. Set its value to the name of the method that will return the component object.

  4. Set the value of each factory method argument. Include one or more $factory.param[n].value properties. Replace n with the zero-based index number of the argument. For example, to set the value of the first factory method argument:

    $factory.param[0].value=Hello

  5. Set the Java data type of each factory method argument. Include one or more $factory.param[n].type properties. Replace n with the zero-based index number of the argument. For example, to set the type of the first factory method argument:

    $factory.param[0].type=String

Note: You do not need to supply the Java types of the factory method arguments if they are not ambiguous (there is only one factory method of that name that takes the number of arguments you supply). However, if you supply any $factory.param[n].type properties, you must supply them for all of the factory method arguments. Whenever possible, provide type properties for all arguments.

The following sections show examples of the Java classes and configuration files that use static and non-static factory methods.

Example Configuration Using a Static Factory Method

The following example class and configuration files show how to use MethodInstanceFactory with a static factory method.

This Java class includes a static factory method that returns the object that the new component is based on.

package mycompany;
public class MyStaticFactoryMethodClass {

    /* This static factory method returns the object that the
       new component is based on. */
    public static MyComponentObject makeComponentObject 
    (String pMyString, int pMyNumber) {
        return new MyComponentObject(pMyString, pMyNumber);
    }
}

This is the configuration file for the component that is based on the object returned by the factory method.

$instanceFactory=/atg/dynamo/nucleus/MethodInstanceFactory
$factory.class=mycompany.MyStaticFactoryMethodClass
$factory.methodName=makeComponentObject
$factory.param[0].value=Hello
$factory.param[0].type=String
$factory.param[1].value=321
$factory.param[1].type=int
# Set any further properties using standard syntax
Example Configuration Using a Non-Static Component Method

The following example class and configuration files show how to use MethodInstanceFactory with a non-static factory method in another component.

This Java class includes a factory method that returns the object that the new component is based on. An existing Nucleus component is based on this class.

package mycompany;
public class MyFactoryComponent {

    /* This non-static factory method returns the object that the
    new component is based on. */
    public MyComponentObject makeComponentObject 
    (String pMyString, int pMyNumber) {
    return new MyComponentObject(pMyString, pMyNumber);
    }
}

This is the configuration file for the component that is based on the object returned by the factory method.

$instanceFactory=/atg/dynamo/nucleus/MethodInstanceFactory

# The component named in the following property is based on
# the class shown in the example Java class above.
$factory.instance=/mycompany/MyFactoryComponent
$factory.methodName=makeComponentObject
$factory.param[0].value=Hello
$factory.param[0].type=String
$factory.param[1].value=321
$factory.param[1].type=int
# Set any further properties using standard syntax

Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved.

Legal Notices