Java Integration

Creating an extension with Java

Layout of this Document:

Sample – Building the Java Component

Calling the extension from TransactXML Server

Calling the extension from the XSLT engine

=======  Sample – Building the Java Component =======

  1. Install the JDK (Java Development Kit)

Download from: http://www.oracle.com/technetwork/indexes/downloads/index.html

2. Save the following text to HelloJava.java

public class HelloJava {

public static String SayHello(String strInput)    {

String strRet = “[“;

strRet += strInput;

strRet += “]:Hello Java”;

return strRet;

}

}

3. Create the class file by compiling HelloJava.java like this:

c:\jdk\bin\javac HelloJava.java

4. Set the [Java] section in TXML.TXT like this

[Java]
Path=C:\MyJavaObjects

5.  Move the class file from step 3 into the location configured in step 4

Copy HelloJava.class c:\MyJavaObjects

Now your custom java extension is ready to be used from TransactXML Server or the XSLT engine. Both examples are shown.

===  Calling the extension from TXML Server ===

1.      From DesignerXML, double click an element to get the following dialog:

Java-E1Change the “Element Value Source” to “Custom extension” and the following dialog box will popup. The Dialog will be empty by default. You should set the following values to call the example built above:

Java-E2This causes the Element “MyElement” to get it’s value from the external Java function.  Double click the parameter to set it’s value.

===  Calling the extension from XSLT Engine ===

XSLT Engine Syntax:           functoid:LANGUAGE%COMPONENT%INTERFACE%METHOD()

To call the example above use the following syntax:

functoid:Java%HelloJava.class%HelloJava%SayHello()

Here’s a complete example to transform this XML:

<customers at=’yes’>

<name>Chris</name>

<name>Sean</name>

<name>Brian</name>

<name>Lad</name>

</customers>

to this HTML table:

Java-E3

 by processing this XSL:

<xsl:stylesheet version=’1.0’xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”xmlns:functoid=”functoid”&gt;

<xsl:template match=”customers”>

<table width=”20%” border=”1″>

<tbody>

<xsl:for-each select=”name”>

<!–Sort the table by customer name–>

<xsl:sort/>

<tr>

<th>

<xsl:value-of select= “functoid:Java%HelloJava.class%HelloJava%SayHello(.)”/>

</th>

</tr>

</xsl:for-each>

</tbody>

</table>

</xsl:template>

</xsl:stylesheet>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s