cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically create mapping for non singleton nodes

Former Member
0 Kudos

Hi,

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) iter.next();
			dst_ni.addMappedAttribute(attrInfo.getName(), attrInfo.getName());
		}

		// Copy child nodes
		for (Iterator iter = src_ni.iterateChildren(); iter.hasNext();) {
			IWDNodeInfo srcNodeInfo = (IWDNodeInfo) iter.next();
			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 =
			dstNodeInfo.addMappedChild(
				srcNodeInfo.getName(),
				null,
				srcNodeInfo.isSingleton(),
				srcNodeInfo.isMandatorySelection(),
				srcNodeInfo.isMultipleSelection(),
				null,
				true,
				true);

		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?

Thx,

Bjoern

View Entire Topic
Former Member
0 Kudos

Bjoern,

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>

NO!!!!!!!

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

http://www.NetWeaverTeam.com

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

Former Member
0 Kudos

Valery,

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.

Thanks!