cancel
Showing results for 
Search instead for 
Did you mean: 

Java mapping code for looping through a node. Kindlty help!

gopalkrishna_baliga
Participant
0 Kudos

Hi Experts,

I have source message:

<ProductlineItem>

<ProductIdentification>

<ClassificationCode>Reseller</ClassificationCode>

<ProductIdentifier>MM001</ProductIdentifier>

</ProductIdentification>

<ProductIdentification>

<ClassificationCode>Manufacturer</ClassificationCode>

<ProductIdentifier>MM002</ProductIdentifier>

</ProductIdentification>

<ProductIdentification>

<ClassificationCode>Sender</ClassificationCode>

<ProductIdentifier>MM003</ProductIdentifier>

</ProductIdentification>

</ProductlineItem>

<ProductlineItem>

<ProductIdentification>

<ClassificationCode>Sender</ClassificationCode>

<ProductIdentifier>KK001</ProductIdentifier>

</ProductIdentification>

<ProductIdentification>

<ClassificationCode>Manufacturer</ClassificationCode>

<ProductIdentifier>KK002</ProductIdentifier>

</ProductIdentification>

<ProductIdentification>

<ClassificationCode>Reseller</ClassificationCode>

<ProductIdentifier>KK003</ProductIdentifier>

</ProductIdentification>

</ProductlineItem>

As shown above each product can have multiple indentification. For each product item I have to map the <ProductIdentifier> value to <MM> of target message where <ClassificationCode> is Manufacturer. Similarly map the <ProductIdentifier> value to <CPN> of target message where <ClassificationCode> is Sender.

I want to generate the output(target) message as below:

<ITAB_PRODUCT>

<Item>

<MM>MM002</MM>

<CPN>MM003</CPN>

</Item>

<Item>

<MM>KK002</MM>

<CPN>KK001</CPN>

</Item>

<ITAB_PRODUCT>

How can I get the target message? I beleive I have to use Java user defined function where I have to do some looping. kIndly help me with some sample java code for the same to get the target message.

Kindly help!

Thanks

Gopal

Accepted Solutions (0)

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

Gopal,

Its very easy. Please follow the below code. But let me clarify something , I made some assumptions and did the UDF.

Assumption 1: Sub-element of <ProductIdentification>.......</ProductIdentification> will have only one Manufacturer and only one sender.

Assumption 2 :Sub-element of <ProductIdentification>.......</ProductIdentification> will have both Manufacturer and Sender [I mean both must be present inside ProductIdentification, it should not be the case that the ProductIdentification will have only Manufacturer and not Sender or the other way around].

Gopal if the above assumptions are correct, kindly follow the below steps.

Mapping logic:

ProductlineItem <b>---></b> Item

<u>Two Parameters for UDF1</u>

ClassificationCode[Change Context to ProductlineItem]<b> &</b>

ProductIdentifier[Change Context to ProductlineItem] -


>UDF1 -


>MM

<u>Two Parameters for UDF2</u>

ClassificationCode[Change Context to ProductlineItem]<b> &</b>

ProductIdentifier[Change Context to ProductlineItem] -


>UDF1 -


>CPN

<b>UDF1 -Code:</b> [Paramter :CCode,Pidentifier &Cache :Queue]

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

{

if(CCode<i>.equals("Manufacturer"))

{

result.addValue(""Pidentifier<i>"");

result.addContextChange();

}

}

<b>UDF2 -Code:</b> [Paramter :CCode,Pidentifier &Cache :Queue]

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

{

if(CCode<i>.equals("Sender"))

{

result.addValue(""Pidentifier<i>"");

result.addContextChange();

}

}

I executed the same,I got the same output as u needed. If it doesn't suits ur reqmt, kindly let me know.

Hope it helps..

Best regards,

raj.