This section describes how to use Java classes as source or target types in transformations.
To Use a Java Class in Transformations
For instructions on creating a new business process project and application, see Creating a Business Process Application.
To open an existing application that contains the query:
Note: Java interfaces and abstract Java classes are supported as source or target types for transformations but cannot be executed in Test View. However, a transformation with a Java interfaces and/or abstract Java classes as source or target types can be invoked from a business process (JPD) without error.
For the example shown in this procedure, create a Java file called Book.java in a subfolder named processes in the project folder:
The New File dialog box appears.
public String title; // Will convert to xsd type public Author[] authors; // Will convert to xsd type private int copiesPrinted; // Private member with no get/set methods; will not convert to xsd type private int copiesSold; // Private member with get/set methods will convert to xsd public int getCopiesSold(){ return copiesSold; } public void setCopiesSold(int in){ copiesSold = in; } public HashMap stores; // Will not convert to xsd type, HashMap not supported
Errors will be reported in the Source View. You will fix those errors in the following steps.
To learn more about which fields are supported in Java classes, see Java Class Conversion.
Note: If you use the Java class variable in a business process, you may enable process variable instance monitoring for the variable by implementing a toString() method in the custom class.
import java.util.HashMap;
In Application tab, expand the your application folder. (If the Application tab is not visible in WebLogic Workshop, from the menu bar choose View —> Application.)
Expand the myprojectWeb project folder, where myproject represents the name of your project folder.
If required, expand the folder(s) that contain the Book.java file.
Right-click the Book.java file and in the drop-down menu select Save.
You also need to create a Java file called Author.java in the processes subfolder:
The New File dialog box appears.
public String lastname; // Will convert to xsd type public String firstname; // Will convert to xsd type
In Application tab, expand the your application folder. (If the Application tab is not visible in WebLogic Workshop, from the menu bar choose View —> Application.)
Expand the myprojectWeb project folder, where myproject represents the name of your project folder.
If required, expand the folder(s) that contain the Author.java file.
Right-click the Author.java file and in the drop-down menu select Save.
For the example in this procedure, import the Book.xsd file. For example, if you installed WebLogic Platform in the c:\bea directory, import the Book.xsd file from the C:\bea\weblogic81\workshop\help\doc\en\integration\reffiles\transform\javaClass directory.
The XML Schema in the Book.xsd file is the target type for this example transformation.
Importing schemas files triggers a build of the current Schemas project folder. Wait until the Schemas project folder is built before proceeding to the next step. (The representations of the schemas will not be available in Available Source Types and Available Target Type panes until build is complete.)
For instructions on creating a new Transformation file, see Creating a Transformation File and a Transformation Method.
For instructions on creating a new method in a Transformation file, see To Add a Transformation Method to Transformation File.
To open an existing method which contains the query:
The Configure XQuery Transformation Method dialog box is displayed.
For this example, in the Available Source Types pane, select the XML option, select Typed/Book.xsd/Book element as the target parameter, and click Add.
For this example, in the Available Target Types pane, select the Java option, enter: processes.Book in the Type field, and click Add.
A graphical representation of the Java class and XML Schema is displayed in the Design View.
Note: Not all the fields in the Book.java class are displayed. Only supported public members or private members with JavaBean style get and set methods are displayed. In this example, the private member: copiesSold is displayed because the associated JavaBeans set and get methods for this member are provided. However, the class member stores is not displayed because it is of type: java.util.HashMap which is not a supported type. To learn more about which fields of a Java class are supported in transformations, see Java Class Conversion.
A link represented by a line between the two nodes is displayed.
Repeat this step as necessary to create additional links.
For this example, in the Source pane select the $BookDoc/Title node and drag it to the Book/title node in the Target pane.
For this example, in the Source pane select the $BookDoc/Author node and drag it to the Book/authors node in the Target pane. These nodes are both repeating nodes. A repeating node means more than one instances of this node can be specified. In the Source pane, repeating nodes are represented with a + symbol to the right of the node. A dashed line linking the two repeating nodes is displayed.
For this example, in the Source pane select the $BookDoc/Author/LastName node and drag it to the Book/authors/Author/lastname node in the Target pane. A solid line linking the two nodes is displayed.
In the Source pane select the $BookDoc/Author/FirstName node and drag it to the Book/authors/firstname node in the Target pane. A solid line linking the two nodes is displayed.
In the Source pane select the $BookDoc/CopiesSold node and drag it to the Book/copiesSold node in the Target pane. A solid line linking the two nodes is displayed.
![]() |
![]() |