Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem in Java mapping

Hi,

I have developed java mapping. I am able to generate the target xml file properly in external tool, where as when I tried to use same thing in XI IR. It is throwing an exception.

Please help me to find out whats wrong in the below code:

While loading into XI i removed the main method.

/*

  • Created on May 26, 2006

*

  • To change the template for this generated file go to

  • Window - Preferences - Java - Code Generation - Code and Comments

*/

package JavaMapTest;

import java.io.InputStream;

import java.io.OutputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.util.Hashtable;

import java.util.Map;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

import org.w3c.dom.Text;

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

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

/**

  • @author yaseenm

*

  • To change the template for this generated type comment go to

  • Window - Preferences - Java - Code Generation - Code and Comments

*/

public class TransformXML implements StreamTransformation{

private Map map;

private Document sourceDocument = null;

private Document docOut = null;

private Element root;

private String field1 = "";

public void setParameter(Map param) {

map = param;

}

public void execute(InputStream in, OutputStream out)

throws StreamTransformationException {

Element elm ;

Text tagValue;

DOMSource domS = null;

DocumentBuilder documentBuilder = null;

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setValidating(true);

factory.setNamespaceAware(true);

try {

documentBuilder = factory.newDocumentBuilder();

documentBuilder.setErrorHandler(null);

} catch (ParserConfigurationException e) {

e.printStackTrace();

}

try {

// write XML

TransformerFactory transformerFactory = TransformerFactory.newInstance();

Transformer transformer = transformerFactory.newTransformer();

// System.out.println("b4 parsing");

sourceDocument = documentBuilder.parse(in);

// System.out.println("b4 document builder");

docOut = documentBuilder.newDocument();

NodeList nodeList = sourceDocument

.getElementsByTagName("Source_MT");

root = docOut.createElement("Target_MI");

docOut.appendChild(root);

Element temp = (Element) nodeList.item(0);

NodeList N1 = temp.getElementsByTagName("field1");

field1 = N1.item(0).getFirstChild().getNodeValue();

elm = docOut.createElement("Tarfield1");

docOut.createDocumentFragment();

root.appendChild(elm);

tagValue = docOut.createTextNode(field1);

elm.appendChild(tagValue);

domS = new DOMSource(docOut);

transformer.transform(domS, new StreamResult(out));

}catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

System.out.println("Start Of Application1");

TransformXML convertIDOC = new TransformXML();

convertIDOC.setParameter(new Hashtable());

try {

convertIDOC.execute(new FileInputStream("C:/anilx.xml"),new FileOutputStream("C:/output123.xml"));

}catch (FileNotFoundException e) {

e.printStackTrace();

} catch (StreamTransformationException e) {

e.printStackTrace();

}

System.out.println("Done");

}

}

Thanks In Advance.

Yaseen

Not what you were looking for? View more on this topic or Ask a question