Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

In my earlier blog "[XSLT: Runtime Value Mapping from Integration Directory using XIVMService.class | https://weblogs.sdn.sap.com/cs/junior/view/wlg/15427]" , I tried to explain concept to call value mapping at runtime from Integration Directory using XSLT Mapping. Same procedure can be applied to Java Mapping also to access ValueMapping at run time.

I will make use of same data type, message type and interface mapping created earlier. Here is our data type.

Java Code to call value mapping at runtime;

<p align="left">import com.sap.aii.mapping.api.StreamTransformation;</p>

import java.io.;</p></strong>

import java.util.Map;

*<p align="left">import javax.xml.parsers.;</p>*<p align="left">import org.xml.sax.;</p>*<p align="left">import org.xml.sax.helpers.;</p>*import com.sap.aii.mapping.value.api.XIVMService;

*

public class ValMapping extends DefaultHandler implements StreamTransformation{ </p>*<p align="left">private Map map;private* OutputStream out;

**

private boolean a1 = false;

**

private boolean b1 = false;

**

private boolean c1 = false;

**

private int a;

**

private int b;</p>*private int c;

String lineEnd = System.getProperty("line.separator");

*

public void setParameter (Map param) {

map = param;

}

public void execute (InputStream in, OutputStream out)throws com.sap.aii.mapping.api.StreamTransformationException {

DefaultHandler handler = this;

SAXParserFactory factory = SAXParserFactory.newInstance();</p>try {

SAXParser saxParser = factory.newSAXParser();

this.out = out;

saxParser.parse(in, handler);

}

catch (Throwable t){

t.printStackTrace();

}}

<p align="left">private <strong>void write (String s) throws SAXException{ </p>*<p align="left">try{ </p>

out.write(s.getBytes());

out.flush(); }catch (IOException e){throw new SAXException("I/O error", e);

}}

public void startDocument () throws SAXException{ public void endDocument () throws SAXException {

write("");write(

lineEnd);

write("");

try { out.flush();

}

<p align="left">catch (IOException e) {</p>throw new SAXException("I/O error", e);

}}

public void startElement (String namespaceURI, String sName,String qName, Attributes attrs) throws SAXException {

String eName = sName;

<p align="left">if ("".equals(eName)) eName = qName; </p>

if(eName.equals("a")) a1 = true;</p></strong>if(eName.equals("b")) b1 = true;if(eName.equals("c")) c1 = true;

}

public void endElement (String namespaceURI, String sName, String qName) throws SAXException {

String eName = sName;

<p align="left">if ("".equals(eName)) eName = qName; </p>

if(eName.equals("a")) a1 = false;</p></strong>if(eName.equals("b")) b1 = false;if(eName.equals("c")) c1 = false;

}

public void characters(char[] chars,int startIndex, int endIndex) throws SAXException {

String dataString =

new String(chars, startIndex, endIndex).trim(); </p>+// CALL VALUE MAPPING TABLES FROM INTEGRATION DIRECTORY +

+String ValMappfromID = +

XIVMService.executeMapping("Sender", "SenderType",dataString,"Receiver","ReceiverType");

+if (a1) { +

+write("" + ValMappfromID +""); </strong><p align="left">*write(lineEnd);} </p><p align="left">if (b1) { </p><p align="left">write("" + ValMappfromID "</b>");write(</p>+lineEnd); <p align="left">}</p>if (c1) { write("");write(lineEnd); <p align="left">}}}+*

Value Mapping Maintained in ID:

!https://weblogs.sdn.sap.com/weblogs/images/251765799/ValMap.jpg|height=203|alt=image|width=492|src=h...

Result in SXMB_MONI: Both Input and Ouput are shown.

!https://weblogs.sdn.sap.com/weblogs/images/251765799/Result.jpg|height=405|alt=image|width=662|src=h...!</body>

1 Comment