Project

General

Profile

1 21 jones
/**
2 203 jones
 *  '$RCSfile$'
3
 *    Purpose: A Class that represents an XML node and its contents
4
 *  Copyright: 2000 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Matt Jones
7 21 jones
 *
8 203 jones
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11 21 jones
 */
12
13 74 jones
package edu.ucsb.nceas.metacat;
14 21 jones
15
import java.io.IOException;
16
import java.util.Hashtable;
17
import java.util.Enumeration;
18 126 jones
import java.util.Vector;
19 21 jones
20 134 jones
/** A Class that represents an XML node and its contents */
21 129 jones
public class BasicNode {
22 21 jones
23 133 jones
    private long	node_id;
24
    private String	tagname;
25
    private long	parent_id;
26 149 bojilova
    private long    rootnode_id;
27 162 bojilova
    private String  doc_id;
28 72 bojilova
    private Hashtable	attributes;
29
    private int         childNum;
30
    private int         nodeIndex;
31 122 jones
    private String      nodeType;
32 162 bojilova
    private Vector  	children;
33 21 jones
34 135 jones
    /** Construct a Basic Node */
35 129 jones
    public BasicNode () {
36 126 jones
      children = new Vector();
37 23 jones
      attributes = new Hashtable();
38 126 jones
      this.childNum = 0;
39 23 jones
    }
40
41 135 jones
    /**
42
     * Construct a Basic Node
43 31 jones
     *
44 134 jones
     * @param tagname the name of the node
45 135 jones
     */
46
    public BasicNode (String tagname) {
47
      this();
48
      this.tagname = tagname;
49
    }
50
51
    /**
52
     * Construct a Basic Node
53
     *
54
     * @param tagname the name of the node
55 134 jones
     * @param parent_id the id number of the parent node
56 135 jones
     * @param nodeIndex - index of node among siblings in parent node
57 134 jones
     *                    Every node initializes childNum to 0 when
58 122 jones
     *                    created and has interface incChildNum
59
     *                    when new child is created
60 31 jones
     */
61 129 jones
    public BasicNode (String tagname, long parent_id, int nodeIndex) {
62 23 jones
      this();
63 21 jones
      this.tagname = tagname;
64
      this.parent_id = parent_id;
65 72 bojilova
      this.nodeIndex = nodeIndex;
66 21 jones
    }
67
68 135 jones
    /** Construct a Basic Node
69 31 jones
     *
70 133 jones
     * @param node_id the id number of the node
71
     * @param tagname the name of the node
72
     * @param parent_id the id number of the parent node
73 31 jones
     */
74 133 jones
    public BasicNode (long node_id, String tagname, long parent_id,
75 122 jones
                         int nodeIndex) {
76 72 bojilova
      this(tagname,parent_id,nodeIndex);
77 133 jones
      this.node_id = node_id;
78 21 jones
    }
79
80 134 jones
    /** convert the node to a string representation for display */
81 129 jones
/*  MAKE THIS AN ABSTRACT METHOD??????
82 21 jones
    public String toString ()
83
    {
84 24 jones
	StringBuffer value = new StringBuffer();
85
	value.append('<');
86
	value.append(getTagName());
87
	value.append(getAttributes().toString());
88
	value.append('>');
89
	return value.toString();
90 21 jones
    }
91 126 jones
*/
92 21 jones
93 134 jones
    /** Get the id of this node */
94 133 jones
    public long getNodeID()
95 23 jones
    {
96 133 jones
      return node_id;
97 23 jones
    }
98 21 jones
99 134 jones
    /** Set the id of this node */
100 133 jones
    public void setNodeID(long node_id)
101 23 jones
    {
102 133 jones
      this.node_id = node_id;
103 23 jones
    }
104
105 134 jones
    /** Get the parent id of this node */
106 23 jones
    public long getParentID()
107
    {
108
      return parent_id;
109
    }
110
111 134 jones
    /** Set the parent id of this node */
112 23 jones
    public void setParentID(long parent_id)
113
    {
114
      this.parent_id = parent_id;
115
    }
116
117 149 bojilova
    /** Get the root node id of this node */
118
    public long getRootNodeID()
119
    {
120
      return rootnode_id;
121
    }
122
123
    /** Set the root node id of this node */
124
    public void setRootNodeID(long rootnode_id)
125
    {
126
      this.rootnode_id = rootnode_id;
127
    }
128
129
    /** Get the doc id of this node */
130 162 bojilova
    public String getDocID()
131 149 bojilova
    {
132
      return doc_id;
133
    }
134
135
    /** Set the doc id of this node */
136 162 bojilova
    public void setDocID(String doc_id)
137 149 bojilova
    {
138
      this.doc_id = doc_id;
139
    }
140
141 134 jones
    /** Get the name of this node */
142 23 jones
    public String getTagName()
143
    {
144
      return tagname;
145
    }
146 21 jones
147 134 jones
    /** Set the name of this node */
148 23 jones
    public void setTagName(String tagname)
149
    {
150
      this.tagname = tagname;
151
    }
152
153 21 jones
    /** Get the attributes as a string */
154
    public String getAttributes() {
155
      StringBuffer buf = new StringBuffer();
156
      String attName = null;
157
      String attValue = null;
158
159
      Enumeration attList = attributes.keys();
160
      while (attList.hasMoreElements()) {
161
        attName = (String)attList.nextElement();
162
        attValue = (String)attributes.get(attName);
163 122 jones
        buf.append(" ").append(attName).append("=\"");
164
        buf.append(attValue).append("\"");
165 21 jones
      }
166
      return buf.toString();
167
    }
168
169 134 jones
    /** Add a new attribute to this node, or set its value */
170 21 jones
    public void setAttribute(String attName, String attValue) {
171
      if (attName != null) {
172
        // Enter the attribute in the hash table
173
        attributes.put(attName, attValue);
174
175
      } else {
176
        System.err.println("Attribute name must not be null!");
177
      }
178
    }
179
180
    /** Get an attribute value by name */
181
    public String getAttribute(String attName) {
182
      return (String)attributes.get(attName);
183
    }
184
185 134 jones
    /** Get nodeIndex of the node */
186 72 bojilova
    public int getNodeIndex() {
187
      return this.nodeIndex;
188
    }
189
190 126 jones
    /** Set the node index of this node */
191
    public void setNodeIndex(int nodeIndex) {
192
      this.nodeIndex = nodeIndex;
193
    }
194 122 jones
195
    /** Get the type of this node */
196 126 jones
    public String getNodeType() {
197 122 jones
      return nodeType;
198
    }
199
200
    /** Set the type of this node */
201 126 jones
    public void setNodeType(String type) {
202 122 jones
      this.nodeType = type;
203
    }
204 126 jones
205 127 jones
    /** Add a child node to this node */
206 129 jones
    public void addChildNode(BasicNode child) {
207 127 jones
      this.children.add(child);
208
    }
209
210
    /** Get the an enumeration of the children of this node */
211
    public Enumeration getChildren() {
212
      return children.elements();
213
    }
214
215 134 jones
    /** increase childNum when new child for the node is created */
216 126 jones
    public int incChildNum() {
217
      return ++this.childNum;
218
    }
219
220 21 jones
}
221 203 jones
222
/**
223
 * '$Log$
224
 * 'Revision 1.19.2.2  2000/06/25 23:38:16  jones
225
 * 'Added RCSfile keyword
226
 * '
227
 * 'Revision 1.19.2.1  2000/06/25 23:34:17  jones
228
 * 'Changed documentation formatting, added log entries at bottom of source files
229
 * ''
230
 */