Skip to Content

Introduction

As mentioned in “help.sap.com” mapping programs can refer other mappings (imported archives: Java, xslt).They should be in the same software component versions or dependent software component versions.

  • Java mapping can use (cross reference) other Java class of an archive.

  • XSLT mapping can use (cross reference) other java class of an archive.

  • XSLT mapping can use (cross reference) other xslt mapping with help of “import”.

Part1:Here we are going to see first two topics,means how to trigger java class from message mapping,Java mapping.

Part2  (References between Mapping Programs-Part2):covers last two topics,means how to trigger java class from xslt mapping and how to trigger xslt mapping from other xslt mapping.</p>h4. *                                                                  Part1*

Description of the Example:

Simple example is taken for demonstration of mapping program references*.

*

 *In target message type there is a field called “Grade” which will be calculated based on average of marks of source message type. There is archive java class  to calculate the “Grade”. </p><p>So the agenda here is to trigger the Grade method (of Java archive) from Message mapping and Java Mapping. </p><p>SourceMessage:**!https://weblogs.sdn.sap.com/weblogs/images/47240/sat_source1.JPG|height=400|alt=|width=700|src=https://weblogs.sdn.sap.com/weblogs/images/47240/sat_source1.JPG! * 

* ________________* 

* TargetMessage:*TargetMessage:

* _____________</p><p> ** *Input xml file(Source xml): ImportArchive(Java class)

*______________ </p><p>Java archive (class) which is referred by udf in message mapping </p><p> package prasad.map;</p><p> @author Prasad Babu Nemalikanti </p><p><p><p> Created on Apr 11, 2011

  • Company:Mahindra Satyam

/ </p></p><p>public class XSLTTesting { </p><p>public static String grade (String a, String b,String c) </p><p><p>{ </p></p><p>   int  e = Integer.parseInt(a); </p><p>   int f = Integer.parseInt(b); </p><p>   int g = Integer.parseInt(c); </p><p>   float average = (efg)/3 </p><p>   if(average>=90) </p><p>      return “Grade A”; </p><p>   else if(average>=80) </p><p>      return “Grade B”; </p><p>   else if(average>=70) </p><p>       return”Grade C”; </p><p>    else if(average>=60) </p><p>      return”First Class”; </p><p>    else if(average>=50) </p><p>    return”Pass”; </p><p>    else </p><p>   return”fail”; </p><p>   } </p><p>} </p></p><p>UDF in Message mapping:</p><p><p>Public String Grade(String a, String b,String c,Container container) throws StreamTransformationException { </p></p><p>String result =XSLTTesting.grade(a,b,c); // calling java method of java archive</p><p><p>return result; </p><p>} </p></p><p>Message mapping:*

* ______________</p><p>Mapping with import and archives options:*

*________________ </p><p> *Testing message mapping with UDF:

 

________________

2. Java mapping can use (cross reference) other Java class of an archive.

Java mapping can refer (call) other java mapping or other archived java class of the same software component or underlying software component. So here to calculate grade, java mapping calls other java method “grade” (java class “XSLTTesting”)

Steps:

a) Creating java class which calculates “grade” ,and deploy that into xi(Import archive) (class Name”XSLTTesting”)

b) Creating java mapping that calls the other java class or other java mapping ,deploy java mapping into xi(Import archive) .Class Name;”MaprefJavamapping” 

Java class that calculates “grade”, this class is called in Java mapping

/*

@author Prasad Babu Nemalikanti

  • Created on Apr 11, 2011

  • Company:Mahindra Satyam

/ </p></p></p><p> public class XSLTTesting {</p><p>public static String grade(String a,String b,String c) </p><p> { </p><p>         int e = Integer.parseInt(a);   </p><p>          int f = Integer.parseInt(b); </p><p>          int g = Integer.parseInt(c); </p><p>          float average = (efg)/3; </p><p>          if(average>=90) </p><p>         return “Grade A”; </p><p>         else if(average>=80) </p><p>         return “Grade B”; </p><p>         else if(average>=70) </p><p>         return “Grade C”; </p><p>         else if(average>=60) </p><p>         return “First Class”; </p><p>        else if(average>=50) </p><p>        return “Pass”; </p><p>       else </p><p>        return “fail”; </p><p><p>    } </p></p><p><p>} </p><p>Java Mapping that calls above mentioned java method:- </strong></p></p><p dir=”ltr”>package nemali.javamap;</p><p dir=”ltr”> /</p><p dir=”ltr”> @author Prasad Babu Nemalikanti

 

  • Created on Apr 18, 2011

 

  • Company : Mahindra Satyam

/</p><div>import  prasad.map.; import  java.io.InputStream;*

</strong></p><p>import  java.io.OutputStream; </p><p>import  java.io.FileInputStream; </p><p>import  java.io.File; </p><p>import  java.io.FileOutputStream; </p><p>import  javax.xml.parsers.DocumentBuilder; </p><p>import  javax.xml.parsers.DocumentBuilderFactory; </p><p>import  org.w3c.dom.Document; </p><p>import  org.w3c.dom.Node; </p><p>import  org.w3c.dom.NodeList; </p><p>import  java.util.;

import  com.sap.aii.mapping.api.StreamTransformation;

public class MaprefJavamapping implements StreamTransformation {

  private Map par;

   String result=null;

*

     </strong>int flag=0;</p><p>   String mt=null; </p><p>    String ph=null; </p><p>    String ln=null; </p><p>public void setParameter(Map param)</p><p>{ </p><p>   par = param; </p><p>    if(par==null) </p><p>    for(int i=0;i<childern.getLength();i+) </p><p>     Node child=childern.item(i);</p><p>     short childType=child.getNodeType(); </p><p>     if(childType==Node.ELEMENT_NODE) </p><p>     { </p><p>      String targetNodeName=null; </p><p><p><p>      String nodeName=child.getNodeName(); </p></p></p><p>       if(nodeName.equals(“Students”))</p><p>        targetNodeName=”Students”; </p><p>         if(nodeName.equals(“Records”)) </p><p>         targetNodeName=”Rows”; </p><p>          if(nodeName.equals(“StudentID”))</p><p>           targetNodeName=”StudentID”; </p><p>            if(nodeName.equals(“FirstName”))</p><p>            targetNodeName=”StudentName”; </p><p>             if(nodeName.equals(“DOJ”)) </p><p>             targetNodeName=”DOJ”; </p><p>            if(nodeName.equals(“Subjects”))</p><p>            targetNodeName=”Marks”; </p><p>            if(nodeName.equals(“Maths”)) </p><p>            { </p><p>                  targetNodeName=”Maths”; </p><p>                  flag=1; </p><p>             } </p><p>          if(nodeName.equals(“Sceince”)) </p><p>          { </p><p>             targetNodeName=”Physics”; </p><p>              flag=2;       </p><p>            } </p><p>         if(nodeName.equals(“Language”)) </p><p>         { </p><p>            targetNodeName=”English”; </p><p>            flag=3; </p><p>          } </p><p>         if(targetNodeName!=null) </p><p>          result=result.concat(“<“targetNodeName“>”); </p><p>          traversingXML(child); </p><p>          if(targetNodeName!=null) </p><p>           if(flag!=3) </p><p>            result=result.concat(“</”targetNodeName“>”); </p><p>           else </p><p>           flag=0; </p><p>          } </p><p>   else if(childType==Node.TEXT_NODE) </p><p>   {</p><p>      String nodeValue=child.getNodeValue(); </p><p>       result=result.concat(nodeValue); </p><p>   // If Blocks to find the grade </p><p>     if(flag==1) </p><p>      { </p><p>          mt=child.getNodeValue(); </p><p>          flag=0; </p><p>      } </p><p>     if(flag==2)</p><p>      { </p><p>          ph=child.getNodeValue(); </p><p>           flag=0; </p><p>       } </p><p>     if(flag==3)  // Calling other java class to calculate “grade” </p><p>      { </p><p>         ln=child.getNodeValue(); </p><p>          String grade=XSLTTesting.grade(mt,ph,ln); </p><p>          result=result.concat(“</English>”); </p><p>           result=result.concat(“<Grade>”grade+””);

          } // End of If block to find grade

       }

    }

  }

 }

*Import archive of java class that calculates “grade” *

</p><p>__________________________</p><p>Import archive of java mapping *

_________________

*Operational Mapping *

____________________

*Testing of java mapping *

 

!https://weblogs.sdn.sap.com/weblogs/images/47240/sat_tst11.JPG|height=269|alt=|width=700|src=https://weblogs.sdn.sap.com/weblogs/images/47240/sat_tst11.JPG!</body>

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply