cancel
Showing results for 
Search instead for 
Did you mean: 

java mapping

Former Member
0 Kudos

Hi XI gurus,

Objective : To Delete nodes & attributes from Source XML file before mapping. And i dont want target message to generate, I just want to execute Java Code for Source File and wanting to remove nodes and attributes from source xml before graphical mapping.

Approach I took : I have created java program using DOM in netbeans and deleted nodes and attributes of incoming file and output it in proper way when executed in netBean, but when I am using same code in Interface mapping, I get error Java Mapping failed. can you please suggest me how should I generate my code ?

my code goes like this :

public class LcMapp implements StreamTransformation

{

//private Map myParam;

public void setParameter (java.util.Map param)

{

// myParam = param;

}

public void execute (InputStream in,OutputStream out)

throws StreamTransformationException {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

Document documentIn = null;

DocumentBuilder builder = null;

try {

builder = factory.newDocumentBuilder();

}

catch (ParserConfigurationException e1)

{

e1.printStackTrace();

}

try{

documentIn = builder.parse(in);

Element root = documentIn.getDocumentElement();

//// Root Node List

NodeList rootlist = root.getChildNodes();

Node xp = rootlist.item(1);

// String st1 = root.getNodeName();

Node xa = xp.getFirstChild();

// String st2 = xa.getNodeName();

Node data = xa.getFirstChild();

// String st3 = data.getNodeName();

NodeList dataNL = data.getChildNodes();

Node zlcquote = dataNL.item(0);

Node remlc = data.removeChild(zlcquote);

Element HeaderAttr = (Element)dataNL.item(0);

HeaderAttr.removeAttribute("xfa:dataNode");

Element InputAttr = (Element)dataNL.item(1);

InputAttr.removeAttribute("xfa:dataNode");

Node execEvent = rootlist.item(3);

// String strEvent = execEvent.getNodeName();

Node rem_execEvent = root.removeChild(execEvent);

TransformerFactory tf = TransformerFactory.newInstance();

Transformer transform = tf.newTransformer();

transform.setOutputProperty(OutputKeys.INDENT, "yes");

// create source and result wrappers and perform transformation

DOMSource source = new DOMSource(documentIn);

StreamResult result = new StreamResult(out);

transform.transform(source, result);

}

catch (SAXException e2)

{

e2.printStackTrace();

}

catch (IOException e2)

{

e2.printStackTrace();

}

catch (Throwable t)

{ throw new StreamTransformationException("Mapping failed", t);

}

}

}

Thanks In advance

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Chandrkant,

One way to test ur java mapping before entering it as an imported archive and using it ur interface mapping is the main method..

just try to add a main method as follows

public static void main (String[] args) {

try {

InputStream in = new FileInputStream(new File("in.xml"));

OutputStream out = new FileOutputStream(new File("out.xml"));

YourClass change = new YourClass ();

change.execute(in, out);

} catch (Exception e) {

System.out.println(e.getMessage());

e.printStackTrace();

}

}

where u have to place the input file in the java working directory,and then run the program as a java application.See the content of output file out.xml to check the output.

u can obtain the user directory using

system.get property("user.dir')

Should help u out

moorthy
Active Contributor
0 Kudos

Hi,

If you want to get the required xml without any attributes etc before mapping, then one of best approach will be use of Adapter Modules. so that, before the mapping calls, you have cleaned data ..

and what is the exact error ? You can test this mapping independently in your netbean using similar xml which you have tested for the interface mapping..

Regards, Moorthy

Former Member
0 Kudos

Thanks for your prompt reply....

Can you please tell me how should I test my Mapping in NetBeans without Interface Mapping.....?

Thanks in advance...