Java Mapping Secrets Revealed - SAP Blogs
Java Mapping Secrets Revealed - SAP Blogs
Community
Former Member
July 27, 2008
| 5 minute read
Follow
Like When I decided to learn java mapping, I searched SDN for blogs on java mapping and found lot of blogs. Some of them are too
technical and some of them given only coding and nothing else. As a developer, who did not have java background ,I found it very
difficult to follow those blogs. So, I have decided to come up with this blog for beginners, which will give a basic understanding of how
RSS Feed to do write a java mapping program.
*What is parsing?*
The literal meaning of parsing is “taking apart” or breaking down” something into smaller segments. Technically when we say
parsing of an XML document, we are breaking the XML file into individual elements and reading the data contained in the elements (
body of the individual element)
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 1/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
A typical java mapping program takes the incoming XML message and transfers the data into target XML message structure. To do
this the java program first needs to read what is there in the incoming XML message. This is done by parsing or breaking down the
XML document into individual elements.
Apart from the above two we can use JDOM and JAXP methods also.
The subject of this blog is SAX so I am going to concentrate more on SAX parser.
SAX parser is nothing but simple API for XML. In crude words set of classes used for reading the XML document
The five methods shown below are used when parsing the XML documents
— Called when the Parser starts parsing the Current XML File.
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 2/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
–Called when the Parser Completes parsing the Current XML File.
Called when the starting of the Element is reached. For Example if we have Tag
Encountered while parsing the Current XML File. The AttributeList Parameter has
the list of all Attributes declared for the Current Element in the XML File.
public void startElement (String name, AttributeList attrs) throws SAXException<br />{<br />……<br />}
Called when the Ending of the current Element is reached. For example in the
public void endElement (String name) throws SAXException<br />{<br />……<br />}
While Parsing the XML file, if extra characters like space or enter Character
are encountered then this method is called. If you don’t want to do anything
special with these characters, then you can normally leave this method blank.So this method can be used to read the values or
body of the elements.
public void characters (char buf [], int offset, int len) throws SAXException<br />{<br />……<br />}<br /><br />Lets take a simple
example and understand how this methods work. The incoming message has below format * <strong>Understand the java Mapping
program:</strong> </p><p style=”margin: 0in 0in 0pt” class=”MsoNormal”>package jmapsax;</p><p style=”margin: 0in 0in
0pt” class=”MsoNormal”> </p><p style=”margin: 0in 0in 0pt” class=”MsoNormal”>import java.io.FileInputStream;</p><p
style=”margin: 0in 0in 0pt” class=”MsoNormal”>import java.io.FileOutputStream;</p><p style=”margin: 0in 0in 0pt”
class=”MsoNormal”>import com.sap.aii.mapping.api.StreamTransformation;</p><p style=”margin: 0in 0in 0pt”
class=”MsoNormal”>import java.io.;
import java.util.Map;
import org.xml.sax.helpers.*;
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 3/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
//IMPORT statement imports the specified classes and its methods into the program
//Every java mapping program must implement the interface StreamTransformation and its methods execute() and setParameter()
and extend the class DefaultHandler.
//Below is the declaration for all the variables we are going to use in the subsequent methods.
//setParamater() method is used to store the mapping object in the variable “map”
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 4/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
{
}
{
try {
}
t.printStackTrace();
}
}
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 5/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
//As seen above execute() method has two parameters “in” of type InputStream and “out” 0f type OutputStream. First we get a new
instance of *SAXParserFactory *and from this one we create a new Instance of SAXParser. To the Parse Method of SaxParser, we
pass two parameters, inputstream “in” and the class variable “handler”.Method “write” is a user defined method, which is used to
write the string “s” to the outpurstream “out”.
Alert Moderator
Assigned Tags
Related Questions
about mappings Java Mapping
By
Former Member Nov 06, 2008 By
Former Member Aug 22, 2008
java mapping
By
Former Member May 29, 2009
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 6/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
Coffee Corner
Join the new Coffee Corner Discussion Group.
12 Comments
Nice explaination!!
U have mentioned that In java, parsing can be done using DOM and SAX. Just to make it clear, u may add that the usage of JDOM and JAXP are possible too.
Regards,
Prateek
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 7/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
Like 0 | Share
Hi Prateek,
I will take your suggestion and update the same. Thanks for your feedback
thanks
sankar
Like 0 | Share
Former Member
July 28, 2008 at 3:58 am
Hi friend,
Apart from the above two we can use JDOM and JAXP methods also
Like 0 | Share
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 8/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
Former Member
July 28, 2008 at 4:02 am
Hi Prateek,
I misunderstood ur sentence.
Regards
Praveen
Like 0 | Share
Former Member
July 30, 2008 at 4:43 am
Please ref:
Using JAXP to both parse and emit XML in XI Java mapping programs
Like 0 | Share
Hi Prasad,
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 9/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
Yes you are right. There are several blogs in SDN on java mapping. My blog is intended for beginners who does not have knowledge in java mapping
using SAX parser.
thanks
sanakr
Like 0 | Share
Former Member
August 7, 2008 at 6:19 am
I have read some webblogs regarding the java mapping but this is very clear and good for guys not having java back ground.
I really appreciate your effort and expecting more blogs from you. keep it up.
Thanks,
Srini
Like 0 | Share
Hi Srinivas,
Thanks for your comments. It is really encouraging to see people appreciating the work.I will definetely come up with more blogs on XI in future.
thanks,
sankar
Like 0 | Share
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 10/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
Former Member
September 22, 2008 at 7:48 pm
Somu.
Like 0 | Share
Former Member
January 8, 2009 at 5:48 am
Hi,
This is one of the blogs, I will rate the best in terms of the sincerity to make the subject comprehensible for all.No jargons and all the steps are clearly
described.
It will be appreciable, if you can write the version2 for a complecated structure.
Regards,
Subhendu
Like 0 | Share
Former Member
January 20, 2009 at 2:13 am
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 11/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
But can u just clarify one doubt. here you said that we need to add bin folder path at environment variable, and for classpath need to give lib folder path..
navneet
Like 0 | Share
Former Member | Blog Post Author
January 20, 2009 at 5:16 am
hi navneet,
right click on "My computer" icon on ur desktop and go to properties. in the properties select "advanced" tab, in that at the bottom u will find
"environment variables". if u click that u can see CLASSPATH entry. select that entry and click on Edit button. now u should be able to add an entry
there.
thanks
sankar
Like 0 | Share
Find us on
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 12/13
2/19/22, 12:11 PM Java Mapping secrets revealed | SAP Blogs
Newsletter Support
https://blogs.sap.com/2008/07/27/java-mapping-secrets-revealed/ 13/13