Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/aendvari/common/model/ModelNode.java


1   /*
2    * ModelNode.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.common.model;
11  
12  import java.util.Map;
13  import java.util.List;
14  
15  
16  /**
17   * <p>The ModelNode interface represents a specific node in the XML or OSM implementation.
18   * Typically the implementation would include a reference to the OsmNode or Node (XML) object.</p>
19   *
20   * @author  Scott Milne
21   *
22   */
23  
24  public interface ModelNode
25  {
26    /**
27     * Returns the instance of ModelTree from which the ModelNode is within.
28     *
29     * @return                  The {@link ModelTree} instance this node is within.
30     *
31     */
32  
33    public ModelTree getOwnerModelTree();
34  
35  
36    /* Accessors. */
37  
38    /**
39     * Returns the value of the node.
40     *
41     * @return                  A string value of the node.
42     *
43     */
44  
45    public String getNodeValue();
46  
47    /**
48     * Sets the value of the node.
49     *
50     * @param                  A string value for the node.
51     *
52     */
53  
54    public void setNodeValue( String value );
55  
56    /**
57     * Returns the name of this node.
58     *
59     * @return                  The name of this node.
60     *
61     */
62  
63    public String getNodeName();
64  
65    /**
66     * Returns a string representation of the node's position in the hierarchy.
67     *
68     * @return                  The position of this node in the hierarchy.
69     *
70     */
71  
72    public String getNodePath();
73  
74    /**
75     * Returns the attributes of this node.
76     *
77     * @return                  A <code>Map</code> of all attibutes.
78     *
79     */
80  
81    public Map getAttributes();
82  
83    /**
84     * Returns the string value of the attribute.
85     *
86     * @return                  The string of the attribute.
87     *
88     */
89  
90    public String getAttribute( String name );
91  
92    /**
93     * Sets the string value of the attribute.
94     *
95     * @param    name            The name of the attibute.
96     * @param    value            The value of the attribute.
97     *
98     */
99  
100   public void setAttribute( String name, String value );
101 
102 
103   /* Node access. */
104 
105 
106   /**
107    * The parent of this node. All nodes, except the root ({@link ModelNode})
108    * node may have a parent. If a node has just been created and not yet added to the tree, or if
109    * it has been removed from the tree, this is null.
110    *
111    * @return                  The parent of this node.
112    *
113    */
114 
115   public ModelNode getParentNode();
116 
117   /**
118    * The first child of this node. If there is no such node, this returns null.
119    *
120    * @return                  The first child node.
121    *
122    */
123 
124   public ModelNode getFirstChild();
125 
126   /**
127    * The last child of this node. If there is no such node, this returns null.
128    *
129    * @return                  The last child node.
130    *
131    */
132 
133   public ModelNode getLastChild();
134 
135   /**
136    * The node immediately preceding this node. If there is no such node,
137    * this returns null.
138    *
139    * @return                  The preceding sibling node.
140    *
141    */
142 
143   public ModelNode getPreviousSibling();
144 
145   /**
146    * The node immediately following this node. If there is no such node,
147    * this returns null.
148    *
149    * @return                  The following sibling node.
150    *
151    */
152 
153   public ModelNode getNextSibling();
154 
155   /**
156    * Returns a <code>List<code> of {@link ModelNode}'s using the path provided.
157    *
158    * @return                  A <code>List</code> of this nodes' children as {@link ModelNode}'s.
159    *
160    */
161 
162   public List getChildNodes();
163 
164   /**
165    * Returns whether this node has any children.
166    *
167    * @return                  True if this node has children, false otherwise.
168    *
169    */
170 
171   public boolean hasChildNodes();
172 
173 
174   /* Node manipulation. */
175 
176 
177   /**
178    * Adds the node <code>newChild</code> to the end of the list of children of this node.
179    * If the <code>newChild</code> is already in the tree, it is first removed.
180    *
181    * @param    newChild          The node to add.
182    *
183    * @return                  The node added.
184    *
185    */
186 
187   public ModelNode appendChild(ModelNode newChild);
188 
189   /**
190    * Inserts the node <code>newChild</code> before the existing child node <code>refChild</code>.
191    * If <code>refChild</code> is null, <code>newChild</code> is inserted at the end of the list
192    * of children. If the <code>newChild</code> is already in the tree, it is first removed.
193    *
194    * @param    newChild          The node to insert.
195    * @param    refChild          The reference node.
196    *
197    * @return                  The node inserted.
198    *
199    */
200 
201   public ModelNode insertBefore(ModelNode newChild, ModelNode refChild);
202 
203   /**
204    * Replaces the child node <code>oldChild</code> with <code>newChild</code>, and returns
205    * the <code>oldChild</code> node. If the <code>newChild</code> is already in the tree,
206    * it is first removed.
207    *
208    * @param    newChild          The node to replace.
209    * @param    oldChild          The node being replaced.
210    *
211    * @return                  The node replaced.
212    *
213    */
214 
215   public ModelNode replaceChild(ModelNode newChild, ModelNode oldChild);
216 
217   /**
218    * Removes the child node indicated by <code>oldChild</code> from the list of children,
219    * and returns it.
220    *
221    * @param    oldChild          The node to remove.
222    *
223    * @return                  The removed node.
224    *
225    */
226 
227   public ModelNode removeChild(ModelNode oldChild);
228 }
229