Powered By

Free XML Skins for Blogger

Powered by Blogger

Friday, January 16, 2009

SAP XSLT Mapping with Java Enhancement

Use

The XSLT specification proposes an enhancement mechanism that enables the system to call external routines from XSLT for transforming XML structures. Java is a programming language that is supported by some Java XSLT processors as an enhancement language.

Using the XSLT mapping with Java enhancement, you can implement mappings quicker and more flexibly.

Caution

The working draft of the specification for XSL Transformations (XSLT) version 2.0 (version from December 20, 2001), does not define the features of the enhancement mechanism of the XSL transformation. There are also no accompanying standards that standardize the enhancement mechanism with Java. For this reason, XSLT processors available on the open market vary considerably in this respect.

Below is a description of one of the ways that the SAP J2EE Engine supports the XML Toolkit 2.0.

Activities

To implement an XSLT mapping with Java enhancement, proceed as follows:

...

1. Implement a Java class that contains the static methods of transforming XML documents or structures. Within this Java class you can also write messages to a trace that is visible in the message monitoring using the MappingTrace object.

Note

The PCK does not support the MappingTrace object.

2. Include the method calls in the XSLT mapping program (see below).

3. Import the XSLT mapping program and the Java class as an archive to the Integration Repository. You can also use two different archives. The archive with the Java class must be in the same or an underlying software component version of the XSLT mapping program (see also: XSLT and Java Mapping).

The following example illustrates the procedure using a simple XSLT mapping for a message.

Example

The following table shows the message instance that you want to transfer to the target message, using an XSLT mapping program with Java enhancement.

Source Instance

Target Instance

Robert
White

Robert White

You must link the and <last-name> elements using a concat() Java method. You also want to write a message to the mapping trace in this method. Carry out the following steps in the XSLT mapping program in which you want to call this Java method:

...

1. Declare the Java class with a namespace definition as an attribute of the element. The namespace name can be any string you want; in the example it is called javamap (see below). The name of the namespace comprises the string java: as the prefix, and the complete name of the class. The complete name of a Java class comprises the name of the package and the class name. In the example this is com.company.group.MappingClass.

2. Use to define the parameters that you want to transfer in the method calls. In the example below, three parameters of the concat() method signature are defined correspondingly:

The first parameter takes the value of the element.

The last parameter takes the value of the element.

The parameter name inputparam is defined and enables you to transfer the constants of the StreamTransformationConstants class to the Java program.

Note

In a Java mapping you have to implement the setParameter() method to enable the Integration Server to set the constants at runtime. For XSLT mappings with a Java enhancement it is sufficient to transfer the constants using the inputparam parameter. The mapping runtime sets the parameter. (see also: Java Mapping).

3. The method is called with the element . Specify the method with the corresponding parameters using the attribute select. The name for the namespace javamapreplaces the complete class name as a prefix.

Note

SAP advises you to check the availability of methods before you call them. Test the XSL element using the attribute test, for example.

The XSLT program looks like this:



xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:javamap="java:com.company.group.MappingClass">






The concat() class method of the Java class com.company.group.MappingClass groups the values of the and elements of the source instance together in a string that represents the value of the element of the target instance. The method also has the inputparam parameter of the Map type for writing information to the trace. You use this to first fetch a MappingTrace object and then use its methods addInfo()or AddWarning() to transfer messages to the trace:

package com.company.group;

import java.util.Map;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.StreamTransformationConstants;

public class MappingClass {

private static AbstractTrace trace = null;

public static String concat(String first,
String last,
Map inputparam)
{
// write trace information
trace = (AbstractTrace)inputparam.get(
StreamTransformationConstants.MAPPING_TRACE );

trace.addInfo(“concat():
\nfirst-name = “ + first +
“\nlast-name = “ + last );

// return concatentation

return first + ' ' + last;
}

//...

}

No comments:

Archives