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