1
|
/**
|
2
|
* Name: ReaderElement.java
|
3
|
* Purpose: A Class that represents an XML element and its contents,
|
4
|
* and can build itself from a database connection
|
5
|
* Institution: National Center for Ecological Analysis and Synthesis
|
6
|
* Copyright: 2000
|
7
|
* Authors: Matt Jones
|
8
|
*
|
9
|
* Version: '$Id: ReaderElement.java 23 2000-04-11 20:56:55Z jones $'
|
10
|
*/
|
11
|
|
12
|
//package project;
|
13
|
|
14
|
import java.sql.*;
|
15
|
import java.io.IOException;
|
16
|
import java.util.Vector;
|
17
|
import java.util.Enumeration;
|
18
|
|
19
|
public class ReaderElement extends BasicElement {
|
20
|
|
21
|
private Connection conn;
|
22
|
private Vector children;
|
23
|
|
24
|
public ReaderElement (Connection conn, long nodeid) {
|
25
|
|
26
|
this.conn = conn;
|
27
|
|
28
|
//Lookup data for self
|
29
|
getElementInfo(nodeid);
|
30
|
|
31
|
//Lookup list of child nodes
|
32
|
//foreach childnode (childid,childtype)
|
33
|
// if (type.equals("ATTRIBUTE")) {
|
34
|
// add the att to attribute hash
|
35
|
// else (type.equals("ELEMENT")) {
|
36
|
// ReaderElement child = new ReaderElement(childid);
|
37
|
// add child to vector of children
|
38
|
// }
|
39
|
//}
|
40
|
|
41
|
}
|
42
|
|
43
|
private void getElementInfo(long nodeid) {
|
44
|
long element_id=0;
|
45
|
long parentnodeid=0;
|
46
|
String nodetype=null;
|
47
|
String nodename=null;
|
48
|
String nodedata=null;
|
49
|
|
50
|
PreparedStatement pstmt;
|
51
|
try {
|
52
|
pstmt =
|
53
|
conn.prepareStatement("SELECT nodeid,parentnodeid,nodetype, " +
|
54
|
"nodename,nodedata FROM xml_nodes WHERE nodeid = ?");
|
55
|
// Bind the values to the query
|
56
|
pstmt.setLong(1, nodeid);
|
57
|
|
58
|
pstmt.execute();
|
59
|
try {
|
60
|
ResultSet rs = pstmt.getResultSet();
|
61
|
try {
|
62
|
boolean tableHasRows = rs.next();
|
63
|
if (tableHasRows) {
|
64
|
try {
|
65
|
element_id = rs.getLong(1);
|
66
|
parentnodeid = rs.getLong(2);
|
67
|
nodetype = rs.getString(3);
|
68
|
nodename = rs.getString(4);
|
69
|
nodedata = rs.getString(5);
|
70
|
} catch (SQLException e) {
|
71
|
System.out.println("Error with getInt: " + e.getMessage());
|
72
|
}
|
73
|
}
|
74
|
} catch (SQLException e) {
|
75
|
System.out.println("Error with next: " + e.getMessage());
|
76
|
}
|
77
|
} catch (SQLException e) {
|
78
|
System.out.println("Error with getrset: " + e.getMessage());
|
79
|
}
|
80
|
pstmt.close();
|
81
|
} catch (SQLException e) {
|
82
|
System.out.println("Error getting id: " + e.getMessage());
|
83
|
}
|
84
|
|
85
|
if (nodetype.equals("ELEMENT")) {
|
86
|
setElementID(element_id);
|
87
|
setParentID(parentnodeid);
|
88
|
setTagName(nodename);
|
89
|
content.append(nodedata);
|
90
|
}
|
91
|
}
|
92
|
}
|