0 / 0
Using user-defined properties (Java Integration stage)

Using user-defined properties (Java Integration stage)

You can use your Java™ code to define custom properties and use these property values in your Java code.

At job design time, the Java Integration stage editor calls thegetUserPropertyDefinitions() method in your Processor class to get a list of user-defined property definitions and then show the properties in the editor panel to allow the users to specify the string value for each property.

The following example shows the sample implementation of the getUserPropertyDefinitions() method.
public List<propertyDefinition> getUserPropertyDefinitions()
{
    List<PropertyDefinition> list = new ArrayList<PropertyDefinition>();
    propList.add(new PropertyDefinition
		("NumOfRecords",                                          
		"10", 
    "Number of Records", 
    "Specifies the number of record to be generated.",
    PropertyDefinition.Scope.STAGE)); 

    propList.add(new PropertyDefinition
		("WaveCount",
      "5", 
      "Wave Count", 
  			"Specifies the number of record to be processed 
			before writing end-of-wave marker.",
      PropertyDefinition.Scope.OUTPUT_LINK_ONLY));    
    return list;
 }

The getUserProperties() method of the Configuration interface returns a set of user-defined properties which forms as key=value pair. The getUserProperties() method of the Link interface returns a set of user-defined link properties which forms as key=value pair.

The following code gets the value of the NumOfRecords property which is set as stage properties, and the WaveCount property which is set as link properties.
public boolean validateConfiguration(
  Configuration configuration, boolean isRuntime) throws Exception
{
  // Specify current link configurations.
  m_outputLink = configuration.getOutputLink(0);

  Properties userStageProperties = configuration.getUserProperties();
  String propValue;
  // Fetch the value of "NumOfRecords" user property.
  // If it is not specified, use default value 10.
  // The minimum number of NumOfRecords is 0.
  // The maximum number of NumOfRecords is 100.
  // If specified value is out of range, return error.
  propValue = userStageProperties.getProperty("NumOfRecords");
  if (propValue != null)
  {
    m_numOfRecords = Integer.valueOf(propValue);
  }
  if (m_numOfRecords < 0 || m_numOfRecords > 100)
  {
    m_errors.add("Please set the NumOfRecords value between 1 to 100.");
  }

  // Fetch the value of "WaveCount" user property.
  // If it is not specified, use default value 5.
  // The minimum number of WaveCount is 0.
  // The maximum number of WaveCount is 100.
  // If specified value is out of range, return error.
  Properties userLinkProperties = m_outputLink.getUserProperties();
  propValue = userLinkProperties.getProperty("WaveCount");
  if (propValue != null)
  {
    m_waveCount = Integer.valueOf(propValue);
  }
  if (m_waveCount < 0 || m_waveCount > 100)
  {
    m_errors.add("Please set the waveCount value between 1 to 100.");
  }
Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more