Skip to Content
0
Former Member
Mar 28, 2006 at 09:24 AM

Dynamically create mapping for non singleton nodes

28 Views

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