Revision 461
Added by bojilova almost 24 years ago
src/edu/ucsb/nceas/metacat/DBSAXNode.java | ||
---|---|---|
18 | 18 |
import java.util.Hashtable; |
19 | 19 |
import java.util.Enumeration; |
20 | 20 |
import oracle.jdbc.driver.*; |
21 |
import org.xml.sax.SAXException; |
|
21 | 22 |
|
22 | 23 |
/** |
23 | 24 |
* A Class that represents an XML node and its contents and |
... | ... | |
33 | 34 |
* |
34 | 35 |
* @param conn the JDBC Connection to which all information is written |
35 | 36 |
*/ |
36 |
public DBSAXNode (Connection conn, String docid) { |
|
37 |
public DBSAXNode (Connection conn, String docid) throws SAXException {
|
|
37 | 38 |
super(); |
38 | 39 |
this.conn = conn; |
39 | 40 |
this.parentNode = null; |
... | ... | |
48 | 49 |
* @param parentNode the parent node for this node being created |
49 | 50 |
*/ |
50 | 51 |
public DBSAXNode (Connection conn, String tagname, DBSAXNode parentNode, |
51 |
long rootnodeid, String docid, String doctype) { |
|
52 |
long rootnodeid, String docid, String doctype) |
|
53 |
throws SAXException { |
|
52 | 54 |
|
53 | 55 |
super(tagname); |
54 | 56 |
setParentID(parentNode.getNodeID()); |
... | ... | |
63 | 65 |
|
64 | 66 |
/** creates SQL code and inserts new node into DB connection */ |
65 | 67 |
public void writeChildNodeToDB(String nodetype, String nodename, |
66 |
String data, String docid) { |
|
68 |
String data, String docid) |
|
69 |
throws SAXException { |
|
67 | 70 |
try { |
68 | 71 |
PreparedStatement pstmt; |
69 | 72 |
if (nodetype == "DOCUMENT") { |
... | ... | |
129 | 132 |
nodename + ", " + |
130 | 133 |
data + ")" ); |
131 | 134 |
System.err.println(e.getMessage()); |
135 |
throw new SAXException(e.getMessage()); |
|
132 | 136 |
} |
133 | 137 |
} |
134 | 138 |
|
... | ... | |
136 | 140 |
* creates SQL code to put nodename for the document node |
137 | 141 |
* into DB connection |
138 | 142 |
*/ |
139 |
public void writeNodename(String nodename) { |
|
143 |
public void writeNodename(String nodename) throws SAXException {
|
|
140 | 144 |
try { |
141 | 145 |
PreparedStatement pstmt; |
142 | 146 |
pstmt = conn.prepareStatement( |
... | ... | |
151 | 155 |
pstmt.close(); |
152 | 156 |
} catch (SQLException e) { |
153 | 157 |
System.out.println(e.getMessage()); |
158 |
throw new SAXException(e.getMessage()); |
|
154 | 159 |
} |
155 | 160 |
} |
156 | 161 |
|
... | ... | |
158 | 163 |
* creates SQL code to put doc ID for the document node and for |
159 | 164 |
* comment/PI nodes under document node into DB connection |
160 | 165 |
*/ |
166 |
/* |
|
161 | 167 |
public void writeDocID(String doc_id) { |
162 | 168 |
try { |
163 | 169 |
PreparedStatement pstmt; |
... | ... | |
186 | 192 |
System.out.println(e.getMessage()); |
187 | 193 |
} |
188 | 194 |
} |
189 |
|
|
195 |
*/ |
|
190 | 196 |
/** get next node id from DB connection */ |
191 |
private long generateNodeID() { |
|
197 |
private long generateNodeID() throws SAXException {
|
|
192 | 198 |
long nid=0; |
193 | 199 |
Statement stmt; |
194 | 200 |
try { |
... | ... | |
202 | 208 |
stmt.close(); |
203 | 209 |
} catch (SQLException e) { |
204 | 210 |
System.out.println("Error getting id: " + e.getMessage()); |
211 |
throw new SAXException(e.getMessage()); |
|
205 | 212 |
} |
206 | 213 |
|
207 | 214 |
return nid; |
208 | 215 |
} |
209 | 216 |
|
210 | 217 |
/** Add a new attribute to this node, or set its value */ |
211 |
public void setAttribute(String attName, String attValue, String docid) { |
|
218 |
public void setAttribute(String attName, String attValue, String docid) |
|
219 |
throws SAXException { |
|
212 | 220 |
if (attName != null) { |
213 | 221 |
// Enter the attribute in the hash table |
214 | 222 |
super.setAttribute(attName, attValue); |
... | ... | |
217 | 225 |
writeChildNodeToDB("ATTRIBUTE", attName, attValue, docid); |
218 | 226 |
} else { |
219 | 227 |
System.err.println("Attribute name must not be null!"); |
228 |
throw new SAXException("Attribute name must not be null!"); |
|
220 | 229 |
} |
221 | 230 |
} |
222 | 231 |
|
... | ... | |
225 | 234 |
* test strings that represent all of the relative and absolute |
226 | 235 |
* paths through the XML tree from document root to this node |
227 | 236 |
*/ |
228 |
private void updateNodeIndex(String docid, String doctype) { |
|
237 |
private void updateNodeIndex(String docid, String doctype) |
|
238 |
throws SAXException |
|
239 |
{ |
|
229 | 240 |
Hashtable pathlist = new Hashtable(); |
230 | 241 |
boolean atStartingNode = true; |
231 | 242 |
boolean atRootDocumentNode = false; |
... | ... | |
290 | 301 |
} catch (SQLException sqe) { |
291 | 302 |
System.err.println("SQL Exception while inserting path to index."); |
292 | 303 |
System.err.println(sqe.getMessage()); |
304 |
throw new SAXException(sqe.getMessage()); |
|
293 | 305 |
} |
294 | 306 |
} |
295 | 307 |
|
Also available in: Unified diff
writeDocID() not needed any more
throw SAXException from everywhere