Skip to Content
2
Former Member
Jul 11, 2007 at 11:03 AM

Java Mapping

35 Views

Hi all,

I have written a java mapping program which wil take the input value as CSV and convert that into XML of the target structure.

The structure is like

Source

<Root>

<Number>1</Number>

</Root>

<Root>

<Number>2</Number>

</Root>

<Root> <Number>3</Number>

</Root>

The Source is a CSV with delimiter as ";" source file 1;2;3

The Target Structure is

<Node>

<Value>1</Value>

<Value>2</Value>

<Value>3</Value>

</Node>

The program i have written is as follows:

public class TMapping implements StreamTransformation {

private Map map;

public void setParameter (Map param){

map = param;

}

public void execute(InputStream in, OutputStream out) throws StreamTransformationException {

try {

out.write("<?xml version ='1.0' encoding='UTF-8'?>".getBytes());

out.write(" ".getBytes" target="_blank"> ".getBytes" target="_blank">http://www.infosys.com/sap/xi/projects/rt/n2">".getBytes());

out.write("<Node>".getBytes());

String line = null;

BufferedReader bin = new BufferedReader(new InputStreamReader(in));

while((line = bin.readLine())!= null) {

String value = null;

char[] str = new char[100];

str = line.toCharArray();

int s1 = 0;

int s2 = 0;

String[] Data = new String[10];

for(int i=0;i<line.length();i++)

{

if(str<i>==';')

{

Data[s1] = line.substring(s2,i);

s1=s1+1;

s2=i+1;

}

if(i== line.length()-1)

{

Data[s1] = line.substring(s2,i+1);

for(int j=0; j<3; j++) {

String data = Data[j];

out.write(("<Value>"data"</Value>").getBytes());

}

}

}

}

out.write("</Node>".getBytes());

out.write("</ns0:MT_MappingTest_Target>".getBytes());

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

I have excluded the imports:

I tried it using the main method and it gives a perfect out.xml file

i imported the same into XI and the error which is its showing is

"does not implement the required interface com.sap.aii.mapping.api.StreamTransformation"

when i have implemented the StreamTransformation interface

Can any one tell me how to implement the same

Rgds

Aditya