Project

General

Profile

« Previous | Next » 

Revision 129

Added by Matt Jones over 24 years ago

renamed BasicElement to BasicNode

View differences:

src/edu/ucsb/nceas/metacat/BasicElement.java
1
/**
2
 *        Name: BasicElement.java
3
 *     Purpose: A Class that represents an XML element 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
 *
8
 *     Version: '$Id$'
9
 */
10

  
11
package edu.ucsb.nceas.metacat;
12

  
13
import java.io.IOException;
14
import java.util.Hashtable;
15
import java.util.Enumeration;
16
import java.util.Vector;
17

  
18
/** A Class that represents an XML element and its contents */
19
public class BasicElement {
20

  
21
    private long		element_id;
22
    private String		tagname;
23
    //private StringBuffer	content;
24
    private long		parent_id;
25
    private Hashtable	attributes;
26
    private int         childNum;
27
    private int         nodeIndex;
28
    private String      nodeType;
29
    private Vector	children;
30

  
31
    /** Construct a Basic Element */
32
    public BasicElement () {
33
      //content = new StringBuffer();
34
      children = new Vector();
35
      attributes = new Hashtable(); 
36
      this.childNum = 0;
37
    }
38

  
39
    /** Construct a Basic Element 
40
     *
41
     * @param tagname the name of the element
42
     * @param parent_id the id number of the parent element
43
     * @param nodeIndex - order of node among siblings in parent node
44
     *                    Every element initializes childNum to 0 when 
45
     *                    created and has interface incChildNum
46
     *                    when new child is created
47
     */
48
    public BasicElement (String tagname, long parent_id, int nodeIndex) {
49
      this();
50
      this.tagname = tagname;
51
      this.parent_id = parent_id;
52
      this.nodeIndex = nodeIndex;
53
    }
54
    
55
    /** Construct a Basic Element 
56
     *
57
     * @param element_id the id number of the element
58
     * @param tagname the name of the element
59
     * @param parent_id the id number of the parent element
60
     */
61
    public BasicElement (long element_id, String tagname, long parent_id, 
62
                         int nodeIndex) {
63
      this(tagname,parent_id,nodeIndex);
64
      this.element_id = element_id;
65
    }
66

  
67
    /** convert the element to a string representation for display */
68
/*
69
    public String toString ()
70
    {
71
	StringBuffer value = new StringBuffer();
72
	value.append('<');
73
	value.append(getTagName());
74
	value.append(getAttributes().toString());
75
	value.append('>');
76
	return value.toString();
77
    }
78
*/
79

  
80
    /** Get the id of this element */
81
    public long getElementID() 
82
    { 
83
      return element_id; 
84
    }
85

  
86
    /** Set the id of this element */
87
    public void setElementID(long element_id) 
88
    { 
89
      this.element_id = element_id; 
90
    }
91

  
92
    /** Get the parent id of this element */
93
    public long getParentID() 
94
    { 
95
      return parent_id; 
96
    }
97

  
98
    /** Set the parent id of this element */
99
    public void setParentID(long parent_id) 
100
    { 
101
      this.parent_id = parent_id; 
102
    }
103

  
104
    /** Get the name of this element */
105
    public String getTagName() 
106
    { 
107
      return tagname; 
108
    }
109

  
110
    /** Set the tagname of this element */
111
    public void setTagName(String tagname) 
112
    { 
113
      this.tagname = tagname; 
114
    }
115

  
116
    /** Get the attributes as a string */
117
    public String getAttributes() {
118
      StringBuffer buf = new StringBuffer();
119
      String attName = null;
120
      String attValue = null;
121

  
122
      Enumeration attList = attributes.keys();
123
      while (attList.hasMoreElements()) {
124
        attName = (String)attList.nextElement();
125
        attValue = (String)attributes.get(attName);
126
        buf.append(" ").append(attName).append("=\"");
127
        buf.append(attValue).append("\"");        
128
      }
129
      return buf.toString();      
130
    }
131

  
132
    /** Add a new attribute to this element, or set its value */
133
    public void setAttribute(String attName, String attValue) {
134
      if (attName != null) {
135
        // Enter the attribute in the hash table
136
        attributes.put(attName, attValue);
137
 
138
      } else {
139
        System.err.println("Attribute name must not be null!");
140
      }
141
    }
142

  
143
    /** Get an attribute value by name */
144
    public String getAttribute(String attName) {
145
      return (String)attributes.get(attName);
146
    }
147

  
148
    /** Append to the content of the element */
149
/*
150
    public void appendContent(char[] cbuf, int start, int len) {
151
      this.content.append( cbuf, start, len );
152
    }
153
*/
154
    /** Append to the content of the element */
155
/*
156
    public void appendContent(String new_content) {
157
      this.content.append( new_content );
158
    }
159
*/
160
    /** Get the content of the element */
161
/*
162
    public String getContent() {
163
      return this.content.toString();
164
    }
165
*/
166

  
167
    /** Get nodeIndex of the node element */
168
    public int getNodeIndex() {
169
      return this.nodeIndex;
170
    }
171

  
172
    /** Set the node index of this node */
173
    public void setNodeIndex(int nodeIndex) { 
174
      this.nodeIndex = nodeIndex; 
175
    }
176

  
177
    /** Get the type of this node */
178
    public String getNodeType() { 
179
      return nodeType; 
180
    }
181

  
182
    /** Set the type of this node */
183
    public void setNodeType(String type) { 
184
      this.nodeType = type; 
185
    }
186

  
187
    /** Add a child node to this node */
188
    public void addChildNode(BasicElement child) { 
189
      this.children.add(child);
190
    }
191

  
192
    /** Get the an enumeration of the children of this node */
193
    public Enumeration getChildren() { 
194
      return children.elements(); 
195
    }
196

  
197
    /** increase childNum when new child for the element is created */
198
    public int incChildNum() {
199
      return ++this.childNum;    
200
    }    
201

  
202
}
203 0

  
src/edu/ucsb/nceas/metacat/ElementNode.java
20 20
 * A Class that represents an XML element and its contents,
21 21
 * and can build itself from a database connection
22 22
 */
23
public class ReaderElement extends BasicElement {
23
public class ReaderElement extends BasicNode {
24 24

  
25 25
    private Connection	conn;
26 26

  
......
216 216
        } 
217 217

  
218 218
        // Process children recursively here
219
        BasicElement child = null;
219
        BasicNode child = null;
220 220
        Enumeration e = getChildren();
221 221
        while (e.hasMoreElements()) {
222
          child = (BasicElement)e.nextElement(); 
222
          child = (BasicNode)e.nextElement(); 
223 223
          value.append(child);
224 224
        }
225 225

  
src/edu/ucsb/nceas/metacat/DBSAXNode.java
19 19
 * A Class that represents an XML element and its contents and
20 20
 * can write its own representation to a database connection
21 21
 */
22
public class DBSAXElement extends BasicElement {
22
public class DBSAXElement extends BasicNode {
23 23

  
24 24
    private Connection		conn;
25 25

  
src/edu/ucsb/nceas/metacat/DBSAXElement.java
19 19
 * A Class that represents an XML element and its contents and
20 20
 * can write its own representation to a database connection
21 21
 */
22
public class DBSAXElement extends BasicElement {
22
public class DBSAXElement extends BasicNode {
23 23

  
24 24
    private Connection		conn;
25 25

  
src/edu/ucsb/nceas/metacat/ReaderElement.java
20 20
 * A Class that represents an XML element and its contents,
21 21
 * and can build itself from a database connection
22 22
 */
23
public class ReaderElement extends BasicElement {
23
public class ReaderElement extends BasicNode {
24 24

  
25 25
    private Connection	conn;
26 26

  
......
216 216
        } 
217 217

  
218 218
        // Process children recursively here
219
        BasicElement child = null;
219
        BasicNode child = null;
220 220
        Enumeration e = getChildren();
221 221
        while (e.hasMoreElements()) {
222
          child = (BasicElement)e.nextElement(); 
222
          child = (BasicNode)e.nextElement(); 
223 223
          value.append(child);
224 224
        }
225 225

  
src/edu/ucsb/nceas/metacat/BasicNode.java
1 1
/**
2
 *        Name: BasicElement.java
2
 *        Name: BasicNode.java
3 3
 *     Purpose: A Class that represents an XML element and its contents
4 4
 *   Copyright: 2000 Regents of the University of California and the
5 5
 *              National Center for Ecological Analysis and Synthesis
......
16 16
import java.util.Vector;
17 17

  
18 18
/** A Class that represents an XML element and its contents */
19
public class BasicElement {
19
public class BasicNode {
20 20

  
21 21
    private long		element_id;
22 22
    private String		tagname;
......
29 29
    private Vector	children;
30 30

  
31 31
    /** Construct a Basic Element */
32
    public BasicElement () {
33
      //content = new StringBuffer();
32
    public BasicNode () {
34 33
      children = new Vector();
35 34
      attributes = new Hashtable(); 
36 35
      this.childNum = 0;
......
45 44
     *                    created and has interface incChildNum
46 45
     *                    when new child is created
47 46
     */
48
    public BasicElement (String tagname, long parent_id, int nodeIndex) {
47
    public BasicNode (String tagname, long parent_id, int nodeIndex) {
49 48
      this();
50 49
      this.tagname = tagname;
51 50
      this.parent_id = parent_id;
......
58 57
     * @param tagname the name of the element
59 58
     * @param parent_id the id number of the parent element
60 59
     */
61
    public BasicElement (long element_id, String tagname, long parent_id, 
60
    public BasicNode (long element_id, String tagname, long parent_id, 
62 61
                         int nodeIndex) {
63 62
      this(tagname,parent_id,nodeIndex);
64 63
      this.element_id = element_id;
65 64
    }
66 65

  
67 66
    /** convert the element to a string representation for display */
68
/*
67
/*  MAKE THIS AN ABSTRACT METHOD??????
69 68
    public String toString ()
70 69
    {
71 70
	StringBuffer value = new StringBuffer();
......
145 144
      return (String)attributes.get(attName);
146 145
    }
147 146

  
148
    /** Append to the content of the element */
149
/*
150
    public void appendContent(char[] cbuf, int start, int len) {
151
      this.content.append( cbuf, start, len );
152
    }
153
*/
154
    /** Append to the content of the element */
155
/*
156
    public void appendContent(String new_content) {
157
      this.content.append( new_content );
158
    }
159
*/
160
    /** Get the content of the element */
161
/*
162
    public String getContent() {
163
      return this.content.toString();
164
    }
165
*/
166

  
167 147
    /** Get nodeIndex of the node element */
168 148
    public int getNodeIndex() {
169 149
      return this.nodeIndex;
......
185 165
    }
186 166

  
187 167
    /** Add a child node to this node */
188
    public void addChildNode(BasicElement child) { 
168
    public void addChildNode(BasicNode child) { 
189 169
      this.children.add(child);
190 170
    }
191 171

  
src/edu/ucsb/nceas/metacat/TextNode.java
17 17
 * A Class that represents an XML element and its contents,
18 18
 * and can build itself from a database connection
19 19
 */
20
public class TextNode extends BasicElement {
20
public class TextNode extends BasicNode {
21 21

  
22 22
    private Connection	conn;
23 23
    private String      nodeData = null;

Also available in: Unified diff