Anonymous Extensions
There are several facilities in place that enable extensibility using Anonymous extensions. They are in the Math processing of a transaction rule, via the ExternalProcess business rule and through the FileReceived Web Service. Each mechanism is explained in detail below. Anonymous Extensions are not included in a configuration file. Their invocation is governed by configuration of OIPA rules.
Math Type Process
Some tasks may require interaction with custom Java code during the math processing of rules. OIPA has a dedicated math variable type for this purpose, which can be added to any XML math section that contains the <MathVariable> element. The math variable type is PROCESS. This has the advantage of allowing for business rule logic to dictate which extension should execute and which parameters should be passed. Refer to the OIPA XML Configuration Guide for further detail about the math variable type.
Example XML Configuration
This example illustrates the PROCESS type <MathVariable> and the available attributes and parameter passing.
<MathVariable NAME="VariableName" TYPE="PROCESS" NAMESPACE="com.example.package" OBJECT="ClassName" ISARRAY="YES|NO" DATATYPE="DataType*"> <Parameters> <Parameter NAME="InputVar" TYPE="INPUT">Literal|VariableName</Parameter> <Parameter NAME="OutputVar" TYPE="OUTPUT">VariableName</Parameter> </Parameters> </MathVariable> |
Note: Data type can be one of the following: TEXT, INTEGER, DECIMAL, BOOLEAN, DATE.
Java Implementation Details
The above example requires that a class, com.example.package.ClassName, implement the interface IProcessableObject. This class must be present on the class path of the application's class loader. The IProcessableObject interface is defined as follows:
public interface IProcessableObject { public Object execute( Map<String, Object> inputParameterMap, Map<String, Object> outputParameterMap ) throws Exception; } |
The implementation will receive two java.util.Map instances. The first, inputParameterMap, contains all of the values defined as input parameters in the Math XML, keyed on the parameter name. Similarly, the outputParamaterMap contains all of the values defined as output parameters in the Math XML, keyed on the parameter name. Output parameters will be copied back to the original variable name specified as the value of the parameter. In other words, the value of the output variables will be passed into the extension. Any changes to that value will be applied to the variable that is provided by the parameter definition. In essence, the variable is "passed by reference" to the extension.
By supporting output parameters, the extension can return any number of values. By default, the extension returns a single value, which is stored in the variable given by the VARIABLENAME attribute from the XML Configuration example above.
Example Use of Math Extension
Assume there is a service available in the enterprise that will validate that a postal code provided by the user matches the city also provided by the user. The extension will return a Boolean value indicating whether or not the postal code/city pair matches. It will also return the valid city name for the given postal code in the event that the city and postal code do not match.
Example XML Configuration
<MathVariable NAME="PostalCodeMV" TYPE="FIELD" DATATYPE="TEXT">Policy:IssuePostalCode</MathVariable> <MathVariable NAME="CityMV" TYPE="FIELD" DATATYPE="TEXT">Policy:IssueCity</MathVariable> <MathVariable NAME="CorrectCityMV" TYPE="VALUE" DATATYPE="TEXT"></MathVariable> <MathVariable NAME="PostalCodeAndCityMatch" TYPE="PROCESS" NAMESPACE="com.example.package" OBJECT="VerifyPostalCode" ISARRAY="NO" DATATYPE="BOOLEAN"> <Parameters> <Parameter NAME="PostalCode" TYPE="INPUT">PostalCodeMV</Parameter> <Parameter NAME="City" TYPE="INPUT">CityMV</Parameter> <Parameter NAME="CorrectedCity" TYPE="OUTPUT">CorrectCityMV</Parameter> </Parameters> </MathVariable> Extension Pseudo-Code class VerifyPostalCode implements IProcessableObject { public Object execute( Map <String, Object> inputVariableMap, Map <String, Object> outputVariableMap ) throws Exception { String postalCode = ( String )inputVariableMap.get( "PostalCode" ); String city = ( String )inputVariableMap.get( "City" ); VerificationResult result = ExternalService.verifyPostalCode( postalCode, city ); if( result.isValid() ) { return true; } else { outputVariableMap.put( "CorrectedCity", result.getCorrectedCity() ); return false; } } } |