KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > impl > tree > NodeImpl


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.impl.tree;
10
11 import org.jboss.portal.common.FQN;
12 import org.jboss.portal.common.tree.Node;
13 import org.jboss.cache.Fqn;
14
15 import java.util.Map JavaDoc;
16 import java.util.HashMap JavaDoc;
17
18 /**
19  * The node implementation.
20  *
21  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
22  * @version $Revision: 1.1 $
23  */

24 public class NodeImpl
25    implements Node
26 {
27
28    /** Each property has an associated synthetic id. */
29    final Map JavaDoc ids;
30
31    /** The model it is attached to. */
32    final TreeImpl model;
33
34    /** The id in the tree. */
35    final FQN id;
36
37    /** The id in the cache. */
38    final Fqn fqn;
39
40    NodeImpl(TreeImpl model, Fqn fqn)
41    {
42       this.ids = new HashMap JavaDoc();
43       this.model = model;
44       this.id = TreeImpl.toFQN(fqn);
45       this.fqn = fqn;
46    }
47
48    public FQN getID()
49    {
50       return id;
51    }
52
53    public String JavaDoc getName()
54    {
55       return id.getName(id.size() - 1);
56    }
57
58    public Object JavaDoc getProperty(String JavaDoc name)
59    {
60       return model.getProperty(this, name);
61    }
62
63    public Node getChild(String JavaDoc key)
64    {
65       return model.getChild(this, key);
66    }
67
68    public Map JavaDoc getChildren()
69    {
70       return model.getChildren(this);
71    }
72
73    public boolean equals(Object JavaDoc obj)
74    {
75       if (obj == this)
76       {
77          return true;
78       }
79       if (obj instanceof NodeImpl)
80       {
81          NodeImpl other = (NodeImpl)obj;
82          return fqn.equals(other.fqn);
83       }
84       return false;
85    }
86
87    public int hashCode()
88    {
89       return fqn.hashCode();
90    }
91
92    public String JavaDoc toString()
93    {
94       return "Node[" + fqn.toString() + "]";
95    }
96 }
97
Popular Tags