PeopleCode Translation Example
Although XSLT is the recommended language for using the codeset repository to translate message data, you can use PeopleCode for this purpose as well. Because XSLT works only with XML DOM-compliant message data, you must use PeopleCode if the message you’re translating contains non-XML data, including formats like comma separated values (CSV).
Once you’ve defined the match name/match value permutations for a codeset with respect to a given target codeset group and defined the return values for those permutations, you can write a PeopleCode translation program that invokes that codeset and applies the return values.
FindCodeSetValues Built-in Function
To implement data translation capability, Integration Broker provides a PeopleCode built-in function called FindCodeSetValues, which takes four parameters and returns a two dimensional array.
The following example of PeopleCode data translation presents an example input message, the PeopleCode translation program, and the resulting output message.
Input Message
This is the input to the PeopleCode translation:
<?xml version="1.0"?>
<Header>
<LANGUAGE_CODE>en_us</LANGUAGE_CODE>
<STATUS_CODE>0</STATUS_CODE>
</Header>
PeopleCode Data Translation Program
This translation program processes the input message in this example, and generates the output message that follows. The statement shown emphasized demonstrates the use of the FindCodeSetValues function:
/* Get the data from the AE Runtime */
Local TransformData &incomingData = %TransformData;
/* Set a temp object to contain the incoming document */
Local XmlDoc &tempDoc = &incomingData.XmlDoc;
/* Find the Language and status codes value*/
Local string &langCode = &tempDoc.DocumentElement.FindNode("LANGUAGE_CODE").
Node Value;
Local string &statusCode = &tempDoc.DocumentElement.FindNode("STATUS_CODE").
Node Value;
/* Create an array to hold the name value pairs */
Local array of array of string &inNameValuePairsAry;
/* Load the array with some values */
&inNameValuePairsAry = CreateArray(CreateArray("LANG", &langCode),
CreateArray("STATUS", &statusCode));
/* Find the codeset values */
&outAry = FindCodeSetValues("STATUS_CHANGE", &inNameValuePairsAry,
&incomingData.SourceNode, &incomingData.DestNode);
/* Create the new output doc */
If &tempDoc.ParseXmlString("<?xml version=""1.0""?><NewHeader/>") Then
/* Make sure something was returned */
If &outAry.Len > 0 Then
/* Create the new Status Code Node */
Local XmlNode &statusNode = &tempDoc.DocumentElement.AddElement("STATUS");
/* Since this is a 2D array, get the Return Value*/
&statusNode.NodeValue = &outAry [1][2];
End-If;
End-If;
Output Message
This is the result of applying the PeopleCode translation:
<?xml version="1.0"?>
<NewHeader>
<STATUS>Open</STATUS>
</NewHeader>
Related Topics