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

Accepted Solutions (1)

Accepted Solutions (1)

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!

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) iter.next();
			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:


com.sap.tc.webdynpro.progmodel.context.ContextException: Node(SimpleTable.SimpleTableDataSource.1.Kundentypnummer): illegal mapping, because it does not match the parent's mapping
	at com.sap.tc.webdynpro.progmodel.context.Node.initMapping(Node.java:341)
	at com.sap.tc.webdynpro.progmodel.context.Node.<init>(Node.java:284)
	at com.sap.tc.webdynpro.progmodel.context.Node.<init>(Node.java:297)
	at com.sap.tc.webdynpro.progmodel.context.Node.createNode(Node.java:1294)
	at com.sap.tc.webdynpro.progmodel.context.Node.createNode(Node.java:1305)

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

Has anybody an idea how to solve this?