Project

General

Profile

1
/**
2
 *  '$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
 *    Release: @release@
8
 *
9
 *   '$Author: jones $'
10
 *     '$Date: 2000-08-14 13:53:34 -0700 (Mon, 14 Aug 2000) $'
11
 * '$Revision: 349 $'
12
 */
13

    
14
package edu.ucsb.nceas.metacat;
15

    
16
import java.io.IOException;
17
import java.util.Hashtable;
18
import java.util.Enumeration;
19
import java.util.Vector;
20

    
21
/** A Class that represents an XML node and its contents */
22
public class BasicNode {
23

    
24
    private long	node_id;
25
    private String	tagname;
26
    private long	parent_id;
27
    private long    rootnode_id;
28
    private String  doc_id;
29
    private Hashtable	attributes;
30
    private int         childNum;
31
    private int         nodeIndex;
32
    private String      nodeType;
33
    private Vector  	children;
34

    
35
    /** Construct a Basic Node */
36
    public BasicNode () {
37
      children = new Vector();
38
      attributes = new Hashtable(); 
39
      this.childNum = 0;
40
    }
41

    
42
    /** 
43
     * Construct a Basic Node 
44
     *
45
     * @param tagname the name of the node
46
     */
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
     * @param parent_id the id number of the parent node
57
     * @param nodeIndex - index of node among siblings in parent node
58
     *                    Every node initializes childNum to 0 when 
59
     *                    created and has interface incChildNum
60
     *                    when new child is created
61
     */
62
    public BasicNode (String tagname, long parent_id, int nodeIndex) {
63
      this();
64
      this.tagname = tagname;
65
      this.parent_id = parent_id;
66
      this.nodeIndex = nodeIndex;
67
    }
68
    
69
    /** Construct a Basic Node 
70
     *
71
     * @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
     */
75
    public BasicNode (long node_id, String tagname, long parent_id, 
76
                         int nodeIndex) {
77
      this(tagname,parent_id,nodeIndex);
78
      this.node_id = node_id;
79
    }
80

    
81
    /** convert the node to a string representation for display */
82
/*  MAKE THIS AN ABSTRACT METHOD??????
83
    public String toString ()
84
    {
85
	StringBuffer value = new StringBuffer();
86
	value.append('<');
87
	value.append(getTagName());
88
	value.append(getAttributes().toString());
89
	value.append('>');
90
	return value.toString();
91
    }
92
*/
93

    
94
    /** Get the id of this node */
95
    public long getNodeID() 
96
    { 
97
      return node_id; 
98
    }
99

    
100
    /** Set the id of this node */
101
    public void setNodeID(long node_id) 
102
    { 
103
      this.node_id = node_id; 
104
    }
105

    
106
    /** Get the parent id of this node */
107
    public long getParentID() 
108
    { 
109
      return parent_id; 
110
    }
111

    
112
    /** Set the parent id of this node */
113
    public void setParentID(long parent_id) 
114
    { 
115
      this.parent_id = parent_id; 
116
    }
117

    
118
    /** 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
    public String getDocID() 
132
    { 
133
      return doc_id; 
134
    }
135

    
136
    /** Set the doc id of this node */
137
    public void setDocID(String doc_id) 
138
    { 
139
      this.doc_id = doc_id; 
140
    }
141

    
142
    /** Get the name of this node */
143
    public String getTagName() 
144
    { 
145
      return tagname; 
146
    }
147

    
148
    /** Set the name of this node */
149
    public void setTagName(String tagname) 
150
    { 
151
      this.tagname = tagname; 
152
    }
153

    
154
    /** 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
        buf.append(" ").append(attName).append("=\"");
165
        buf.append(attValue).append("\"");        
166
      }
167
      return buf.toString();      
168
    }
169

    
170
    /** Add a new attribute to this node, or set its value */
171
    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
    /** Get nodeIndex of the node */
187
    public int getNodeIndex() {
188
      return this.nodeIndex;
189
    }
190

    
191
    /** Set the node index of this node */
192
    public void setNodeIndex(int nodeIndex) { 
193
      this.nodeIndex = nodeIndex; 
194
    }
195

    
196
    /** Get the type of this node */
197
    public String getNodeType() { 
198
      return nodeType; 
199
    }
200

    
201
    /** Set the type of this node */
202
    public void setNodeType(String type) { 
203
      this.nodeType = type; 
204
    }
205

    
206
    /** Add a child node to this node */
207
    public void addChildNode(BasicNode child) { 
208
      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
    /** increase childNum when new child for the node is created */
217
    public int incChildNum() {
218
      return ++this.childNum;    
219
    }    
220

    
221
}
222

    
223
/**
224
 * '$Log$
225
 * '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
 * '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
 */
(4-4/27)