Node createChild(String child_name, String fqn, Node parent, HashMap<String,Object> data) { Node child=null; if(child_name == null) return null; if(children == null) children=new TreeMap<>(); child=children.get(child_name); if(child != null) child.setData(data); else { child=new Node(child_name, fqn, parent, data); children.put(child_name, child); } return child; }
public void getState(OutputStream ostream) throws Exception { Util.objectToStream(root.clone(), new DataOutputStream(ostream)); }
name=tok.nextToken(); sb.append(SEPARATOR).append(name); node=curr.getChild(name); if(node == null && create_if_not_exists) node=curr.createChild(name, sb.toString(), null, null); if(node == null) return null;
name=tok.nextToken(); sb.append(SEPARATOR).append(name); node=curr.getChild(name); if(node == null && create_if_not_exists) node=curr.createChild(name, sb.toString(), null, null); if(node == null) return null;
name=tok.nextToken(); sb.append(SEPARATOR).append(name); node=curr.getChild(name); if(node == null && create_if_not_exists) node=curr.createChild(name, sb.toString(), null, null); if(node == null) return null;
public void _put(String fqn, String key, Object value) { Node n; StringHolder child_name=new StringHolder(); boolean child_exists=false; if(fqn == null || key == null || value == null) return; n=findParentNode(fqn, child_name, true); if(child_name.getValue() != null) { child_exists=n.childExists(child_name.getValue()); n.createChild(child_name.getValue(), fqn, n, key, value); } else { child_exists=true; n.setData(key, value); } if(child_exists) notifyNodeModified(fqn); else notifyNodeAdded(fqn); }
public void _put(String fqn, String key, Object value) { Node n; StringHolder child_name=new StringHolder(); boolean child_exists=false; if(fqn == null || key == null || value == null) return; n=findParentNode(fqn, child_name, true); if(child_name.getValue() != null) { child_exists=n.childExists(child_name.getValue()); n.createChild(child_name.getValue(), fqn, n, key, value); } else { child_exists=true; n.setData(key, value); } if(child_exists) notifyNodeModified(fqn); else notifyNodeAdded(fqn); }
public void _put(String fqn, HashMap data) { Node n; StringHolder child_name=new StringHolder(); boolean child_exists=false; if(fqn == null) return; n=findParentNode(fqn, child_name, true); // create all nodes if they don't exist if(child_name.getValue() != null) { child_exists=n.childExists(child_name.getValue()); n.createChild(child_name.getValue(), fqn, n, data); } else { child_exists=true; n.setData(data); } if(child_exists) notifyNodeModified(fqn); else notifyNodeAdded(fqn); }
public void _put(String fqn, HashMap data) { Node n; StringHolder child_name=new StringHolder(); boolean child_exists=false; if(fqn == null) return; n=findParentNode(fqn, child_name, true); // create all nodes if they don't exist if(child_name.getValue() != null) { child_exists=n.childExists(child_name.getValue()); n.createChild(child_name.getValue(), fqn, n, data); } else { child_exists=true; n.setData(data); } if(child_exists) notifyNodeModified(fqn); else notifyNodeAdded(fqn); }
/** * Returns the node at fqn. This method should not be used by clients (therefore it is package-private): * it is only used internally (for navigation). C++ 'friend' would come in handy here... * @param fqn The fully qualified name of the node * @return Node The node at fqn */ Node findNode(String fqn) { StringHolder sh=new StringHolder(); Node n=findParentNode(fqn, sh, false); String child_name=sh.getValue(); if(fqn == null || fqn.equals(SEPARATOR) || fqn != null && fqn.isEmpty()) return root; if(n == null || child_name == null) return null; else return n.getChild(child_name); }
/** Set the cache (tree) to this value */ public void setState(byte[] new_state) { Node new_root=null; Object obj; if(new_state == null) { if(log.isInfoEnabled()) log.info("new cache is null"); return; } try { obj=Util.objectFromByteBuffer(new_state); new_root=(Node)((Node)obj).clone(); root=new_root; notifyAllNodesCreated(root); } catch(Throwable ex) { if(log.isErrorEnabled()) log.error("could not set cache: " + ex); } }
/** * Returns the node at fqn. This method should not be used by clients (therefore it is package-private): * it is only used internally (for navigation). C++ 'friend' would come in handy here... * @param fqn The fully qualified name of the node * @return Node The node at fqn */ Node findNode(String fqn) { StringHolder sh=new StringHolder(); Node n=findParentNode(fqn, sh, false); String child_name=sh.getValue(); if(fqn == null || fqn.equals(SEPARATOR) || "".equals(fqn)) return root; if(n == null || child_name == null) return null; else return n.getChild(child_name); }
public String toString() { StringBuffer sb=new StringBuffer(); int indent=0; Map children; children=root.getChildren(); if(children != null && children.size() > 0) { Collection nodes=children.values(); for(Iterator it=nodes.iterator(); it.hasNext();) { ((Node)it.next()).print(sb, indent); sb.append('\n'); } } else sb.append(SEPARATOR); return sb.toString(); }
public String toString() { StringBuilder sb=new StringBuilder(); int indent=0; Map children; children=root.getChildren(); if(children != null && !children.isEmpty()) { Collection nodes=children.values(); for(Iterator it=nodes.iterator(); it.hasNext();) { ((Node)it.next()).print(sb, indent); sb.append('\n'); } } else sb.append(SEPARATOR); return sb.toString(); }
/** * Returns all children of a given node * @param fqn The fully qualified name of the node * @return Set A list of child names (as Strings) */ public Set getChildrenNames(String fqn) { Node n=findNode(fqn); Map m; if(n == null) return null; m=n.getChildren(); if(m != null) return m.keySet(); else return null; }
/** * Returns all children of a given node * @param fqn The fully qualified name of the node * @return Set A list of child names (as Strings) */ public Set getChildrenNames(String fqn) { Node n=findNode(fqn); Map m; if(n == null) return null; m=n.getChildren(); if(m != null) return m.keySet(); else return null; }
/** * Gets the keys of the <code>data</code> map. Returns all keys as Strings. Returns null if node * does not exist. * @param fqn The fully qualified name of the node * @return Set A set of keys (as Strings) */ public Set getKeys(String fqn) { Node n=findNode(fqn); Map data; if(n == null) return null; data=n.getData(); if(data == null) return null; return data.keySet(); }
public void getState(OutputStream ostream) throws Exception { Util.objectToStream(root.clone(), new DataOutputStream(ostream)); }
/** Generates NodeAdded notifications for all nodes of the tree. This is called whenever the tree is initially retrieved (state transfer) */ void notifyAllNodesCreated(Node curr) { Node n; Map children; if(curr == null) return; notifyNodeAdded(curr.fqn); if((children=curr.getChildren()) != null) { for(Iterator it=children.values().iterator(); it.hasNext();) { n=(Node)it.next(); notifyAllNodesCreated(n); } } }
public void _remove(String fqn) { Node n; StringHolder child_name=new StringHolder(); if(fqn == null) return; if(fqn.equals(SEPARATOR)) { root.removeAll(); notifyNodeRemoved(fqn); return; } n=findParentNode(fqn, child_name, false); if(n == null) return; n.removeChild(child_name.getValue(), fqn); notifyNodeRemoved(fqn); }