cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping doubt

Former Member
0 Kudos

Dear SDN,

I am trying to create a message mapping but I'm having problems. The source is of the form:

Source(1..1)

Line (1..unbounded)

Key (1..1)

Val (1..1)

And target is of the form:

Target(1..1)

Id (1..1)

Name (1..1)

Age (1..1)

An example of source could be

<Source>

<Line>

<Key>Name</Key>

<Val>Angie</Val>

</Line>

<Line>

<Key>Id</Key>

<Val>1002</Val>

</Line>

<Line>

<Key>Age</Key>

<Val>25</Val>

</Line>

</Source>

Target result should be

<Target>

<Id>1002</Id>

<Name>Angie</Name>

<Age>25</Age>

</Target>

Note that the mapping is from an 1..unbounded node to an 1:1 node, also note that tuples Key,Val are not sorted just like Target needed.

Any Ideas?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Create user defined function with three inputs. Inside it use global object of type HashMap (package java.util.*).

inputs:

1) input key

2) input value

3) what to put into target

Regards,

Wojciech

Former Member
0 Kudos

Hi,

Tnks for your reply.

If I undestood, such function shoud be something like this:

GlobalContainer globalContainer;

globalContainer = container.getGlobalContainer();

HashMap hm = (HashMap) globalContainer.getParameter("hm");

hm.put(key[0], value[0]);

Two questions:

When could I create the Global HashMap? (Is there some init section?)

When could I get the values to fill target? (Could I read first whole source message before fill target?)

Former Member
0 Kudos

Hi,

You can do it either in init section. Header section of the mapping or inside this function. Just check if it's null or not. You can get this values in the same function. First create hash map if it's not created afterwards use it. Remember that it should be queue function (whole queue).

Regards,

Wojciech

Former Member
0 Kudos

Thank you, I got it.

But I am still not sure when I have to read the HashMap in order to fill corresponding target elements.

Former Member
0 Kudos

Hi,

Look at this

if{hash==null){

//here fill map

}

//here select from hash map, 3rd input should be a constant corresponding to which element you are mapping

Regards,

Wojciech

Answers (1)

Answers (1)

Former Member
0 Kudos

THis is an XSLT scenario. Java code can get complex whereas with XSLT and right tools, it is quite easy and maintainable