In this recipe, we will illustrate how to define the custom functions in Java and how to import them into JDeveloper for the XSLT mapper.
The following text will cover the steps needed to define the custom functions and import them into JDeveloper:
ValueWithUnit.java
) that is used as a placeholder for the function logic. What we do is concatenate the value of the field with its corresponding unit as follows:public class ValueWithUnit { public static String formatValueWithUnit(String value, String unit) { return value + " " + unit; } }
xml
in the project and prepare the XML file named ext-mapper-xpath-functions-config.xml
.<?xml version = "1.0" encoding = "utf-8" ?> <soa-xpath-functions xmlns = "http://xmlns.oracle.com/soa/config/xpath" xmlns:ud = "http://www.oracle.com/XSL/Transform/java/org.packt.user.defined.ValueWithUnit"> <function name = "ud:formatValueWithUnit"> <className>org.packt.user.defined.ValueWithUnit</className> <return type = "string"/> <params> <param name = "value" type = "string"/> <param name = "unit" type = "string"/> </params> <desc/> <detail> <![CDATA[Function concatenates the value and unit.]]> </detail> </function> </soa-xpath-functions>
UserDefinedFunction
as the name of the deployment profile and click on the OK button.xml
part from the Files tab as shown in the following screenshot:config
. We define the packaging type of the file group. To configure the file group, we perform the following actions on the following tabs:META-INF
xml
directoryNow we are ready to build the package and deploy it for usage in JDeveloper. At the project root, we right-click and select Deploy and UserDefined Functions…. The deployment action wizard appears and we confirm the dialog by clicking on Finish. We find the created JAR file in the deploy directory of the project.
We install the extension to JDeveloper by selecting the Tools menu and then selecting Preferences.
Under the SOA tab, we select the generated JAR file and click on the OK button as shown in the following screenshot:
The user-defined functions are composed of the Java class and the XML configuration file. The composition packed into the JAR file can be used as an extension function in JDeveloper and Oracle SOA Suite.
Depending on where we want to use the user-defined functions, we define the XML configuration file. The structure of the XML configuration is the same; however, the names differ depending on the area we want to use the functions in as follows:
Purpose of usage |
XML configuration file name |
---|---|
Oracle BPEL engine |
|
Oracle Mediator |
|
XSLT Mapper |
|
Human workflow |
|
All of above |
|
The configuration file we used in this recipe is highlighted in the preceding table.
After the restart, we can see that our user-defined function appears in JDeveloper. It can be picked up from the Component Palette and User Defined Extension Functions tab.
Next, we will show you how to use the user-defined function in JDeveloper:
<client:milleage> <xsl:value-of select = "ud:formatValueWithUnit(/ns0:TempElement/ns0:pieces[3], /ns0:TempElement/ns0:pieces[4])"/> </client:milleage>
Oracle SOA Suite provides a placeholder where we put the extensions. We can put the extension in place by executing the following steps:
<Oracle_SOA_home>Oracle_SOA1soamodulesoracle.soa.ext_11.1.1
and copy the extension JAR file into this directory.C:ProgramsOracleMiddlewareOracle_SOA1soamodulesoracle.soa.ext_11.1.1>ant Buildfile: build.xml create-manifest-jar: [echo] Creating oracle.soa.ext at C:ProgramsOracleMiddlewareOracle_SOA1soamodulesoracle.soa.ext_11.1.1/oracle.soa.ext.jar; C:ProgramsOracleMiddlewareOracle_SOA1soamodulesoracle.soa.ext_11.1.1UserDefinedFunctions.jar; C:ProgramsOracleMiddlewareOracle_SOA1soamodulesoracle.soa.ext_11.1.1classes [jar] Updating jar; C:ProgramsOracleMiddlewareOracle_SOA1soamodulesoracle.soa.ext_11.1.1oracle.soa.ext.jar BUILD SUCCESSFUL Total time: 0 seconds C:ProgramsOracleMiddlewareOracle_SOA1soamodulesoracle.soa.ext_11.1.1>