1 7 package org.jboss.cache.pojo.test; 8 9 import java.util.HashMap ; 10 import java.util.List ; 11 import java.util.Map ; 12 13 14 24 @org.jboss.cache.pojo.annotation.Replicable 26 public class NodeManager 27 { 28 private TestNode rootNode_; 29 30 private Map nodeMap_ = new HashMap (); 31 32 public NodeManager() 33 { 34 } 35 36 public void setRootNode(String rdn) 37 { 38 this.rootNode_ = new TestNode(); 39 rootNode_.setNodeFDN(rdn); 40 rootNode_.setNodeRDN(rdn); 41 42 registMap(rootNode_); 43 } 44 45 public void addNode(String parentFdn, String rdn) 46 { 47 TestNode parent = findNode(parentFdn); 48 if (parent != null) 49 { 50 TestNode node = new TestNode(); 51 node.setNodeFDN(parentFdn + "." + rdn); 52 node.setNodeRDN(rdn); 53 54 node.setParentNode(parent); 55 parent.addChildNode(node); 56 57 registMap(node); 58 } 59 } 60 61 public TestNode findNode(String fdn) 62 { 63 return (TestNode) nodeMap_.get(fdn); 64 } 65 66 private void registMap(TestNode node) 67 { 68 this.nodeMap_.put(node.getNodeFDN(), node); 69 } 70 71 public void printNodes() 72 { 73 printNode(rootNode_, ""); 74 } 75 76 private void printNode(TestNode node, String prefix) 77 { 78 System.out.println(prefix + node.getNodeRDN()); 79 80 String childPrefix = prefix + " + "; 81 List children = node.getChildren(); 82 int size = children.size(); 83 for (int idx = 0; idx < size; idx++) 84 { 85 TestNode child = (TestNode) children.get(idx); 86 printNode(child, childPrefix); 87 } 88 } 89 90 } 91 | Popular Tags |