KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > pojo > test > NodeManager


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.pojo.test;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.Map JavaDoc;
12
13
14 /**
15  * Test class for PojoCache for circular references.
16  * Link is a POJO that will be instrumentet with CacheFieldInterceptor
17  *
18  * @version $Revision: 1.4 $
19  * <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
20  * conjunction with a special jboss-aop.xml (supplied by JBossCache). In addition, this is JDK1.4 style,
21  * so a annoc Ant build target is needed to pre-compile it.</p>
22  * <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
23  */

24 // We are using JDK1.5 annotation.
25
@org.jboss.cache.pojo.annotation.Replicable
26 public class NodeManager
27 {
28    private TestNode rootNode_;
29
30    private Map JavaDoc nodeMap_ = new HashMap JavaDoc();
31
32    public NodeManager()
33    {
34    }
35
36    public void setRootNode(String JavaDoc 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 JavaDoc parentFdn, String JavaDoc 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 JavaDoc 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 JavaDoc prefix)
77    {
78       System.out.println(prefix + node.getNodeRDN());
79
80       String JavaDoc childPrefix = prefix + " + ";
81       List JavaDoc 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