Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* BindingNode.java
  
  {{IS_NOTE
  	Purpose:
  		
  	Description:
  		
  	History:
  		Thu Feb  1 16:16:54     2007, Created by Henri
 }}IS_NOTE
 
 Copyright (C) 2006 Potix Corporation. All Rights Reserved.
 
 {{IS_RIGHT
 }}IS_RIGHT
 */
 package org.zkoss.zkplus.databind;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
BindingNode that forms a databinding bean path dependant tree.

Author(s):
Henri
 
 /*package*/ class BindingNode implements java.io.Serializable {
 	private static final long serialVersionUID = 200808191424L;
 
 	private LinkedHashSet _bindingSet = new LinkedHashSet(); //(Binding set of this expression BindingNode)
 	private Map _kids = new LinkedHashMap(7); //(nodeid, BindingNode)
 	private String _path//path of this BindingNode
 	private Set _sameNodes = new HashSet(); //BindingNode Set that refer to the same object
 	private boolean _var//a var node
 	private String _nodeId//node id of this BindingNode
 	private boolean _root//whether root node of a path
 	private boolean _innerCollectionNode//whether a collection in collection item node
 	
Constructor.

Parameters:
path the path of this node in the expression dependant tree.
var whether a _var variable binding node.
 
 	public BindingNode(String pathboolean varString idboolean root) {
 		 = path;
 		.add(this);
 		 = var;
 		 = id;
 		 = root;
 	}
 	
 	public LinkedHashSet getBindings() {
 		return ;
 	}

Get all Bindings below the given nodes (deepth first traverse).
 
 		Set walkedNodes = new HashSet(23);
 		LinkedHashSet all = new LinkedHashSet(23*2);
 		myGetAllBindings(allwalkedNodes);
 		
 		return all;
 	}
 	
 	private void myGetAllBindings(LinkedHashSet allSet walkedNodes) {
 		if (walkedNodes.contains(this)) {
 			return//already walked, skip
 		}
 		
 		//mark as walked already
 		walkedNodes.add(this);
 		
 		for(final Iterator it = .values().iterator(); it.hasNext();) {
 			((BindingNodeit.next()).myGetAllBindings(allwalkedNodes); //recursive
 		}
 		
 		for(final Iterator it = .iterator(); it.hasNext();) {
 			final Object obj = it.next();
 			if (obj instanceof BindingNode) {
 				((BindingNodeobj).myGetAllBindings(allwalkedNodes); //recursive
 			}
 		}
 		
 	}
 		
 	public String getPath() {
 		return ;
 	}
 	
 	public String getNodeId() {
		return ;
	}
	public boolean isVar() {
		return ;
	}
	public boolean isRoot() {
		return ;
	}

Add a binding in the BindingNode of the specified path.

Parameters:
path the path of the specified BindingNode in the tree.
binding the binding to be added to the specified BindingNode.
varnameSet set with all _var names
	public void addBinding(String pathBinding bindingSet varnameSet) {
		final List nodeids = DataBinder.parseExpression(path".");
		if (nodeids.size() <= 0) {
			throw new UiException("Incorrect bean expression: "+path);
		}
		boolean var = varnameSet.contains(nodeids.get(0));
		BindingNode currentNode = this;
		for(final Iterator it = nodeids.iterator(); it.hasNext();) {
			final String nodeid = (Stringit.next();
			if (nodeid == null) {
				throw new UiException("Incorrect bean expression: "+path);
			}
			BindingNode kidNode = (BindingNodecurrentNode.getKidNode(nodeid);
			if (kidNode == null) { //if not found, then add one
				if ("/".equals(currentNode._path)) {
					kidNode = new BindingNode(nodeidvarnodeidtrue);
else {
					kidNode = new BindingNode(currentNode._path + "." + nodeidvarnodeidfalse);
				}
				currentNode.addKidNode(nodeidkidNode);
else {
				var = var || kidNode._var;
			}
			currentNode = kidNode;
		}
		if (currentNode == this) {
			throw new UiException("Incorrect bean expression: "+path);
		}
		currentNode.addBinding(binding);
		if ("_var".equals(binding.getAttr())) {
			currentNode._innerCollectionNode =  DataBinder.hasTemplateOwner(binding.getComponent());
		}
	}
	public boolean isInnerCollectionNode() {
	}

Add a binding to this BindingNode.

Parameters:
binding the binding to be added to this node.
	public void addBinding(Binding binding) {
		.add(binding);
	}

Locate the BindingNode of the specified path.

Parameters:
path the path of the specified BindingNode in the tree.
	public BindingNode locate(String path) {
		BindingNode currentNode = this;
		final List nodeids = DataBinder.parseExpression(path".");
		for(final Iterator it = nodeids.iterator(); it.hasNext(); ) {
			final String nodeid = (Stringit.next();
			if (nodeid == null) {
				throw new UiException("Incorrect format of bean expression: "+path);
			}
			currentNode = (BindingNodecurrentNode.getKidNode(nodeid);
			if (currentNode == null) {
				return null
			}
		}
		return currentNode == this ? null : currentNode;
	}

Get root node of this node.
	public BindingNode getRootNode(BindingNode superNode) {
		if (isRoot()) {
			return this;
		}
		final int j = getPath().indexOf(".");
		final String path = (j < 0) ? getPath() : getPath().substring(0, j);
		return superNode.locate(path);
	}

get the sameNodes of this BindingNode.
	public Set getSameNodes() {
		return ;
	}

merge and set the given other sameNodes as sameNodes of this BindingNode.
	public void mergeAndSetSameNodes(Set other) {
		if (other == ) { //same set, no need to merge
			return;
		}
		if ( != null) {
		}
		 = other;
	}
	public String toString() {
		return ;
	}
	// Get kid nodes
	/*package*/ Collection getKidNodes() {
		return .values();
	}
	// Get kid nodes of the specified nodeid.
	/*package*/ BindingNode getKidNode(String nodeid) {
		return (BindingNode.get(nodeid);
	}
	private void addKidNode(String nodeidBindingNode kid) {
		.put(nodeidkid);
	}
New to GrepCode? Check out our FAQ X