View Javadoc

1   /*
2    * Copyright (c) 2001-2005,
3    * RedVerst Group, ISP RAS http://www.ispras.ru
4    * All rights reserved.
5    *
6    * Redistribution and use in source and binary forms, with or without
7    * modification, are permitted provided that the following conditions are met:
8    *
9    * 1. Redistributions of source code must retain the above copyright notice, this
10   *    list of conditions and the following disclaimer.
11   *
12   * 2. Redistributions in binary form must reproduce the above copyright notice,
13   *    this list of conditions and the following disclaimer in the documentation
14   *    and/or other materials provided with the distribution.
15   *
16   * 3. The names "ATP", "TreeDL", "RedVerst", "ISP RAS"
17   *    may not be used to endorse or promote products derived from this software
18   *    without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24   * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27   * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   */
31  
32  package com.unitesk.atp.tree;
33  
34  /***
35   * A node of an attributed tree (AT).
36   * Each node except <code>root</code> node has <code>parent</code> node.
37   * {@link com.unitesk.atp.dynattrs.Accessor Accessor} can be used to work with node attributes.
38   * <code>Child</code> of node is an attribute's value or an element
39   * of an indexed attribute that implement this interface and have this node
40   * as parent.
41   * <P>Implementations of this interface should provide read-only attribute
42   * <code>"this"</code> whose value is object itself.
43   *
44   * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
45   * @version $Id: Node.java,v 1.9 2005/09/07 14:40:56 all-x Exp $
46   */
47  public interface Node extends Keyed
48  {
49      /***
50       * Gets the parent of this node.
51       *
52       * @return         The parent of this node.
53       *                 Can be <code>null</code> only for root node.
54       */
55      Node getParent();
56  
57      /***
58       * Sets the parent of this node.
59       *
60       * @param  parent  The node to become parent of this node.
61       * @throws NullPointerException
62       *                 If <code>parent</code> is <code>null</code>.
63       * @throws IllegalArgumentException
64       *                 If parent was already set.
65       * @see #resetParent()
66       */
67      void setParent( Node parent );
68      
69      /***
70       * Reset parent of this node.
71       * 
72       * @see #setParent(Node)
73       * @since 3.6
74       */
75      void resetParent();
76  
77      /***
78       * Makes a value of the specified attribute a child of this node.
79       * If this attribute is indexed makes each element of its value
80       * a child of this node.
81       * <code>null</code> an attribute value or an element are allowed.
82       *
83       * @param  name    The name of an attribute of this node.
84       * @throws IllegalArgumentException
85       *                 If the specified name is not a name of an attribute
86       *                 of this node.
87       * @throws ClassCastException
88       *                 If a value of an attribute or an element
89       *                 of indexed attribute does not implement
90       *                 {@link Node} interface.
91       */
92      void makeChild( String name );
93  
94      /***
95       * Accepts the specified visitor.
96       * This is an implementation of <code>Visitor</code> design pattern.
97       * Each inherited node type <code>NodeType</code> must override this method
98       * to call <code>void visit<I>NodeType</I>( NodeType node )</code>
99       * visitor's method.
100      *
101      * @param  visitor The visitor to accept.
102      */
103     void accept( Visitor visitor );
104 }