A custom function extension is a method for a software engineer to make new functions available on a per-project basis.
In this example a function is required to capitalize a name entered by a user. For example, if a user enters the name “fred jones”, the rulebase needs to present this as “Fred Jones”. Since no built-in function exists to do this and there is no way to combine existing functions to do this, it is a good candidate for a custom function.
The new function is called “Capitalize” and it accepts one text value and returns another text value. This is defined in an extension.xml file (see Reference:Custom Function Extensions for the schema).
The function also needs a Java or .NET class in which the function is implemented. In this example both a Java and a .NET handler are provided, however either one of these could be left out. In practice a .NET implementation is always highly recommended so the rulebase can be used in the debugger, but it is not required if the rulebase will only be executed in a Java environment.
<extension>
<functions>
<function name="Capitalize" return-type="text">
<arg name="entered-name" type="text"/>
<handler platform="java"
class="com.oracle.determinations.examples.CapitalizeFunction"/>
<handler platform="dotnet"
class="Oracle.Determinations.Examples.CapitalizeFunction"/>
</function>
</functions>
</extension>
The above extension.xml file should be saved inside a new subfolder of the project’s “Extensions” folder. This “Extensions” folder may also have to be manually created.
Note that the extension.xml file is now located in Extensions\Example\extensions.xml , which is two levels away from the project folder (the folder containing the xprj file). This allows several extension folders to be copied into the extensions folder and they will all be active at once, for example in the above screenshot there is a second extension called “OtherExample” in the extensions folder.
In addition to the extension.xml file, a “lib” folder should be created to store the compiled code that implements the custom function. This folder will contain compiled assembly DLLs (for .NET) and JAR files (for Java).
With this in place, it is possible to compile a rule document that uses the custom function.
Attempting to build and debug this rulebase will result in an error because the class named in the extension.xml file is not available. The extension’s lib folder must be populated with the code that implements the custom function.
The above code should be compiled into a Java JAR or .NET assembly DLL and copied into the extension’s lib folder. The rulebase can then be built and debugged, either without screens (if a .NET assembly DLL is provided) or with screens (if a Java JAR is provided).
Write a Custom Function Extension
Custom Function Extensions
Example: Create a Custom Function Extension To Default A Value