Project

General

Profile

« Previous | Next » 

Revision 204

Fixed bugs associated with the new UPDATE and DELETE functions of
DBWriter. There were problematic interactions between some static
variables used in DBEntityResolver and the way in which the
Servlet objects are re-used across multiple client invocations.

Generally cleaned up error reporting. Now all errors and success
results are reported as XML documents from MetaCatServlet. Need
to make the command line tools do the same.

View differences:

DBSAXHandler.java
19 19

  
20 20
import org.xml.sax.Attributes;
21 21
import org.xml.sax.SAXException;
22
import org.xml.sax.SAXParseException;
22 23
import org.xml.sax.ext.DeclHandler;
23 24
import org.xml.sax.ext.LexicalHandler;
24 25
import org.xml.sax.helpers.DefaultHandler;
......
30 31
public class DBSAXHandler extends DefaultHandler 
31 32
                          implements LexicalHandler, DeclHandler {
32 33

  
33
   static  int 		elementNo = 0;
34
   static  String 	docname = null;
34
   private boolean	atFirstElement;
35
   private String 	docname = null;
35 36
   private String 	doctype;
36 37
   private String 	systemid;
37 38
   private boolean 	stackCreated = false;
......
48 49
    */
49 50
   public DBSAXHandler(Connection conn) {
50 51
     this.conn = conn;
52
     this.atFirstElement = true;
51 53

  
52 54
     // Create the stack for keeping track of node context
53 55
     // if it doesn't already exist
......
73 75

  
74 76
     // Create the document node representation as root
75 77
     rootNode = new DBSAXNode(conn, docname);
78
     MetaCatUtil.debugMessage("PRINTING DOCNAME FROM ROOTNODE: " + 
79
                               rootNode.getTagName());
76 80
     // Add the node to the stack, so that any text data can be 
77 81
     // added as it is encountered
78 82
     nodeStack.push(rootNode);
......
84 88
     MetaCatUtil.debugMessage("end Document");
85 89
     if ((docid != null) && (!docid.equals(currentDocument.getDocID()))) {
86 90
       throw (new SAXException("New document ID generated:",
87
              new AccessionNumberException(currentDocument.getDocID())));
91
           new AccessionNumberGeneratedException(currentDocument.getDocID())));
88 92
     } else {
89 93
       throw (new SAXException("New document ID generated:",
90
              new AccessionNumberException(currentDocument.getDocID())));
94
           new AccessionNumberGeneratedException(currentDocument.getDocID())));
91 95
     }
92 96
   }
93 97

  
......
100 104
     DBSAXNode parentNode = null;
101 105
     DBSAXNode currentNode = null;
102 106

  
103
     elementNo++;
104 107
     // Get a reference to the parent node for the id
105 108
     try {
106 109
       parentNode = (DBSAXNode)nodeStack.peek();
......
108 111
     }
109 112

  
110 113
     // Document representation that points to the root document node
111
     if (elementNo == 1) {
114
     if (atFirstElement) {
115
       atFirstElement = false;
112 116
       // If no DOCTYPE declaration: docname = root element name 
113 117
       if (docname == null) {
114 118
         docname = localName;
115
         MetaCatUtil.debugMessage("DOCNAME: " + docname);
119
         doctype = docname;
120
         MetaCatUtil.debugMessage("DOCNAME-a: " + docname);
121
         MetaCatUtil.debugMessage("DOCTYPE-a: " + doctype);
116 122
       } else if (doctype == null) {
117
         doctype = DBEntityResolver.doctype;
118
         MetaCatUtil.debugMessage("DOCTYPE: " + doctype);
123
         doctype = docname;
124
         //doctype = DBEntityResolver.doctype;
125
         MetaCatUtil.debugMessage("DOCTYPE-b: " + doctype);
119 126
       }
120 127
       rootNode.writeNodename(docname);
121 128
       rootNode.writeRootNodeID(rootNode.getNodeID());
......
123 130
         currentDocument = new DBSAXDocument(conn, rootNode.getNodeID(), 
124 131
                                           docname, doctype, docid, action);
125 132
         } catch (AccessionNumberException ane) {
126
           throw (new SAXException("Error with" + action, ane));
133
           throw (new SAXException("Error with " + action, ane));
127 134
         }
128 135
       rootNode.writeDocID(currentDocument.getDocID());
129 136
     }      
......
161 168
   }
162 169

  
163 170
   /** 
164
    * SAX Handler called once for each comment found: 
165
    * node that comment may occur before or after the root element.
166
    */
167
/*
168
   public void comment(String data) throws SAXException {
169
     MetaCatUtil.debugMessage("COMMENT");
170
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
171
     currentNode.writeChildNodeToDB("COMMENT", null, data);
172
   }
173
*/
174
   /** 
175 171
    * SAX Handler called once for each processing instruction found: 
176 172
    * node that PI may occur before or after the root element.
177 173
    */
......
202 198
     doctype = publicId;
203 199
     systemid = systemId;
204 200

  
205
     MetaCatUtil.debugMessage("Start DOCTYPE");
201
     MetaCatUtil.debugMessage("Start DTD");
206 202
     MetaCatUtil.debugMessage("DOCNAME: " + docname);
207 203
     MetaCatUtil.debugMessage("DOCTYPE: " + doctype);
208 204
     MetaCatUtil.debugMessage("  SYSID: " + systemid);
......
212 208
    * SAX Handler that receives notification of end of DTD 
213 209
    */
214 210
   public void endDTD() throws SAXException {
215
     MetaCatUtil.debugMessage("end DOCTYPE");
211
     MetaCatUtil.debugMessage("end DTD");
216 212
   }
217 213

  
218 214
   /** 
......
286 282
     MetaCatUtil.debugMessage("EXTERNENTITYDECL");
287 283
   }
288 284

  
285
   //
286
   // the next section implements the ErrorHandler interface
287
   //
289 288

  
289
   /** 
290
    * SAX Handler that receives notification of fatal parsing errors
291
    */
292
   public void fatalError(SAXParseException exception) throws SAXException {
293
     MetaCatUtil.debugMessage("FATALERROR");
294
     throw (new SAXException("Fatal processing error.", exception));
295
   }
296

  
297
   /** 
298
    * SAX Handler that receives notification of recoverable parsing errors
299
    */
300
   public void error(SAXParseException exception) throws SAXException {
301
     MetaCatUtil.debugMessage("ERROR");
302
   }
303

  
304
   /** 
305
    * SAX Handler that receives notification of warnings
306
    */
307
   public void warning(SAXParseException exception) throws SAXException {
308
     MetaCatUtil.debugMessage("FATALERROR");
309
   }
310

  
311
   // 
312
   // Helper, getter and setter methods
313
   //
314
   
315
   /**
316
    * get the document name
317
    */
318
   public String getDocname() {
319
     return docname;
320
   }
321

  
322
   /**
323
    * get the document processing state
324
    */
325
   public boolean atFirstElement() {
326
     return atFirstElement;
327
   }
290 328
}
291 329

  
292 330
/**
293 331
 * '$Log$
332
 * 'Revision 1.28  2000/06/26 10:35:05  jones
333
 * 'Merged in substantial changes to DBWriter and associated classes and to
334
 * 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE
335
 * 'functions.  The command line tools and the parameters for the
336
 * 'servlet have changed substantially.
337
 * '
294 338
 * 'Revision 1.27.2.6  2000/06/26 02:02:20  jones
295 339
 * 'Continued fixing problems with exception handling that deals
296 340
 * 'with INSERT and UPDATE actions and the docid passed to DBWriter

Also available in: Unified diff