Java nodes can be made to be generic and reusable by defining node properties, and accessing them from within the node code.
There are two mechanisms for accessing properties within a Java node:
Using run time property names
For example, in the JavaCode property, you define the following method propertyBase
:
public String propertyBase() {
return "ls.brain.node.sumExample";
}
This means that all properties will have the following run time property name format, where <runtime-property-name-extension>
is the suffix of the run time property name:
propertyBase().<runtime-property-name-extension>
For example, for the OutputFieldName property the propertyBase part of the run time property name is ls.brain.node.sumExample
and the suffix is outputFieldName
:
ls.brain.node.sumExample.outputFieldName
Variables are defined within the JavaCode class to store these properties, as follows:
Then, within the setup
method of the node these properties are loaded into the variables, as follows:
Consider the first property from the above code example. This code obtains the Properties object via the properties() accessor defined on the Node interface (see the "laeJavaApi" in the following location: <Data360Analyze installation directory>/docs/lae
). The code then attempts to access the boolean property called:
propertyBase() + ".outputFloat"
From the propertyBase() method, this corresponds to the Run Time Property Name:
ls.brain.node.sumExample.outputFloat
This Run Time Property Name is used by the OutputAsFloat property.
With all of this put together, the following line states "obtain the Boolean property OutputAsFloat and store it in the variable m_outputAsFloat
":
m_outputAsFloat = properties().getBoolean( propertyBase() + ".outputFloat");
Textual substitution of properties
You can use textual substitution to access properties within the Java code, using the {{^propertyname^}}
syntax, see Explicit property reference.
The following example shows textual substitution of the name of the class and the name of the package within which it lies. In general, the Java code needs to be declared within a package with the same name as the value of the JavaPackage property. Similarly, the code needs to be defined within a class with the same name as the value of the JavaClass property:
package {{^JavaPackage^}};…public class {{^JavaClass^}} extends SimplifiedNode
In these cases, it would not be possible to read in the value of the JavaPackage or JavaClass property into a variable to then be used as the package or class name, therefore the textual substitution approach is used.