Showing results for 
Search instead for 
Did you mean: 

Dynamically create mapping for non singleton nodes

Former Member
0 Kudos


Following situation:

Controller SRC
     +-- Node_A
             +--- attrib_A1
             +--- attrib_An
             +--- Node NS (NonSingleton)
                        +--- attrib_NS1
                        +--- attrib_NSn

Controller DST

I want to write a method which creates a mapped copy of Node_A in Controller DST with all of its children and attributes.

This is what I tried:

	public static void copyContextMappings(
		IWDNodeInfo src_ni,
		IWDNodeInfo dst_ni) {		
		// Copy the attribute information
		for (Iterator iter = src_ni.iterateAttributes(); iter.hasNext();) {
			IWDAttributeInfo attrInfo = (IWDAttributeInfo);
			dst_ni.addMappedAttribute(attrInfo.getName(), attrInfo.getName());

		// Copy child nodes
		for (Iterator iter = src_ni.iterateChildren(); iter.hasNext();) {
			IWDNodeInfo srcNodeInfo = (IWDNodeInfo);
			IWDNodeInfo newChildNodeInfo =
				addMappedChildNode(srcNodeInfo, dst_ni);

			// Now copy all attributes and children nodes for child node 
			copyContextMappings(srcNodeInfo, newChildNodeInfo);

	public static IWDNodeInfo addMappedChildNode(
		IWDNodeInfo srcNodeInfo,
		IWDNodeInfo dstNodeInfo) {

		IWDNodeInfo newChildNodeInfo;

		newChildNodeInfo =

		newChildNodeInfo.setMapping(srcNodeInfo, true);

		return newChildNodeInfo;

To make it short: This only works for the root-arguments and for singleton children nodes but not for non singleton nodes.

As I read, for a non singleton node, like Node_NS, WD creates a seperate childnode for each element of Node_A. The question is now, how can I set the mapping to Node_NS? Do I have to iterate over all elements and set the mapping for each element childnode? If yes, how can I do this with only Framework classes like IWDNode or IWDNodeInfo, without using generated classes (cause I want to reuse this methods)? What happens if for example an element is added to Node_A?



Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos


Your first variant should work, at least for value nodes of any depth. If you are using model nodes and/or nodes with structure binding there are could be errors.

However, it depends how you invoke this code.

<i>This only works for the root-arguments and for singleton children nodes but not for non singleton nodes.</i>

Did you test? Did you get any errors?

There are should be none....

<i>As I read, for a non singleton node, like Node_NS, WD creates a seperate childnode for each element of Node_A.</i>


Do not confuse data (node / node-element) with metadata (node-info). When do mapping create node-info in target per node-info in source.

Valery Silaev

EPAM Systems

P.S. In effect, your first loop in copyContextMappings is same as single call dst_ni.addAttributesFromDataNode().

Former Member
0 Kudos


thanks for your answer. You are completly right, the code is working... so I have to search in the rest of my project where the error really is.


Answers (1)

Answers (1)

Former Member
0 Kudos

Tried a littlebit further, but no luck at all

I wrote an additional method:

	public static void addNonSingletonMappings(
		IWDNode src_node,
		IWDNode dst_node) {

		IWDNodeInfo src_nodeInfo = src_node.getNodeInfo();
		IWDNodeInfo dst_nodeInfo = dst_node.getNodeInfo();

		for (Iterator iter = src_nodeInfo.iterateChildren(); iter.hasNext();) {
			IWDNodeInfo ni = (IWDNodeInfo);
			if (!ni.isSingleton()) {
				for (int i = 0; i < src_node.size(); i++) {
					IWDNode node = src_node.getChildNode(ni.getName(), i);
					IWDNode dnode = dst_node.getChildNode(ni.getName(), i);

					dnode.getNodeInfo().setMapping(node.getNodeInfo(), true);					

and changed line in method addMappedChildNode to only set mapping if source node is a singleton node. After call to addMappedChildNode I simply call addNonSingletonMappings which shall do exactly what I want (Iterate through elements and set mappings to each "elementnode"). For the first element (index to start from does not matter) this works fine, but for second I get following exception: Node(SimpleTable.SimpleTableDataSource.1.Kundentypnummer): illegal mapping, because it does not match the parent's mapping

So the first call to setMapping seems to set the mapping for all node elements...

Has anybody an idea how to solve this?