KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > xmlimporter > TransactionsParser


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.applications.xmlimporter;
11
12 import java.io.*;
13 import java.util.HashMap JavaDoc;
14
15 import javax.xml.parsers.*;
16
17 import org.mmbase.module.*;
18 import org.mmbase.module.core.*;
19 import org.mmbase.util.logging.*;
20 import org.xml.sax.*;
21 import org.xml.sax.helpers.DefaultHandler JavaDoc;
22
23 /**
24  * This class parses the xml file with TML code and calls the appropriate methods
25  * in TransactionManager TemporarayNodeManager org.mmabse.module.core
26  * Furthermore is does some nameserving.
27  *
28  * @author John Balder: 3MPS
29  * @author Rob Vermeulen: VPRO
30  * @author Rob van Maris: Finnalist IT Group
31  * @author Erik Visser: Finnalist IT Group
32  * @since MMBase-1.5
33  * @version $Id: TransactionsParser.java,v 1.8 2006/06/30 09:01:09 andre Exp $
34  */

35
36 public class TransactionsParser extends DefaultHandler JavaDoc {
37
38     /** The element and attribute names. */
39     private final static String JavaDoc ELEMENT_TRANSACTIONS = "transactions";
40     private final static String JavaDoc ATTRIBUTE_EXCEPTION_PAGE = "exceptionPage";
41     private final static String JavaDoc ATTRIBUTE_REPORT_FILE = "reportFile";
42     private final static String JavaDoc ATTRIBUTE_KEY = "key";
43     private final static String JavaDoc ELEMENT_CREATE = "create";
44     private final static String JavaDoc ATTRIBUTE_ID = "id";
45     private final static String JavaDoc ATTRIBUTE_COMMIT_ON_CLOSE = "commit";
46     private final static String JavaDoc ATTRIBUTE_TIME_OUT = "timeOut";
47     private final static String JavaDoc ELEMENT_OPEN = "open";
48     private final static String JavaDoc ELEMENT_COMMIT = "commit";
49     private final static String JavaDoc ELEMENT_DELETE = "delete";
50     private final static String JavaDoc ELEMENT_CREATE_OBJECT = "createObject";
51     private final static String JavaDoc ATTRIBUTE_TYPE = "type";
52     private final static String JavaDoc ATTRIBUTE_DISPOSE = "disposeWhenNotReferenced";
53     private final static String JavaDoc ELEMENT_OPEN_OBJECT = "openObject";
54     private final static String JavaDoc ELEMENT_DELETE_OBJECT = "deleteObject";
55     private final static String JavaDoc ELEMENT_ACCESS_OBJECT = "accessObject";
56     private final static String JavaDoc ATTRIBUTE_MMBASE_ID = "mmbaseId";
57     private final static String JavaDoc ELEMENT_MARK_OBJECT_DELETE = "markObjectDelete";
58     private final static String JavaDoc ATTRIBUTE_NAME = "name";
59     private final static String JavaDoc ELEMENT_CREATE_RELATION = "createRelation";
60     private final static String JavaDoc ATTRIBUTE_SOURCE = "source";
61     private final static String JavaDoc ATTRIBUTE_DESTINATION = "destination";
62     private final static String JavaDoc ATTRIBUTE_DELETE_RELATIONS = "deleteRelations";
63     private final static String JavaDoc ELEMENT_MERGE_OBJECTS = "mergeObjects";
64     private final static String JavaDoc ELEMENT_OBJECT_MERGER = "objectMerger";
65     private final static String JavaDoc ELEMENT_OBJECT_MATCHER = "objectMatcher";
66     private final static String JavaDoc ATTRIBUTE_CLASS = "class";
67     private final static String JavaDoc ELEMENT_PARAM = "param";
68     private final static String JavaDoc ATTRIBUTE_VALUE = "value";
69     private final static String JavaDoc ELEMENT_SET_FIELD = "setField";
70     private final static String JavaDoc ATTRIBUTE_URL = "url";
71
72     /**
73      * The character encoding used for the reporfile: ISO-8859-1.
74      */

75     public final static String JavaDoc ENCODING = "ISO-8859-1";
76
77     /**
78      * The XML header used for the reportfile.
79      */

80     public final String JavaDoc xmlHeader =
81         "<?xml version='1.0' encoding='"
82             + ENCODING
83             + "'?>\n"
84             + "<!DOCTYPE transactions "
85             + "PUBLIC '-//MMBase/DTD transactions config 1.0//EN' "
86             + "'http://www.mmbase.org/dtd/transactions_1_0.dtd'>\n";
87
88     /** Logger instance. */
89     private static Logger log = Logging.getLoggerInstance(TransactionsParser.class.getName());
90
91     /** MMBase module. */
92     private static MMBase mmbase = null;
93
94     /** TransactionHandler module. */
95     private static TransactionHandler transactionHandler = null;
96
97     /** Upload module. */
98     // private static Upload upload = null;
99

100     /** TransactionManager module. */
101     private TransactionManagerInterface transactionManager;
102
103     /** TemporaryNodeManager module. */
104     private TemporaryNodeManagerInterface tmpObjectManager;
105
106     /** Path of the MMBase dtd directory. */
107     private String JavaDoc dtdDirectory;
108
109     /** Path of the MMBase report directory. */
110     private String JavaDoc reportDirectory;
111
112     /** Transaction information for current user. */
113     private UserTransactionInfo uti;
114
115     /** Transaction information for current user. */
116     private Consultant consultant;
117
118     /** The error page. */
119     private String JavaDoc exceptionPage;
120
121     /** The report file, used to report merging problems to. */
122     private File reportFile;
123
124     /** The current transaction context. */
125     private Transaction transaction;
126
127     /** The current object context. */
128     private TmpObject tmpObject;
129
130     /** The value of the fieldName attribute when parsing a setField element. */
131     private String JavaDoc fieldName;
132
133     /** The value of the element value when parsing a setField element. */
134     private StringBuffer JavaDoc fieldValue;
135
136     /** The value of the url attribute when parsing a setField element. */
137     private String JavaDoc url;
138
139     /** The name of the type attribute when parsing a mergeObjects element. */
140     private String JavaDoc type;
141
142     /** The objectMerger, when parsing a mergeObjects element. */
143     private ObjectMerger objectMerger;
144
145     /** The SimilarObjectFinder, when parsing a mergeObjects element. */
146     private SimilarObjectFinder objectFinder;
147
148     /** The name of the class attribute when parsing an objectMerger element. */
149     private String JavaDoc className;
150
151     /** The name/value attributes of param elements, when parsing
152      * an objectMerger element. */

153     private HashMap JavaDoc params;
154
155     /**
156      * Creates new TransactionParser object.
157      * @param consultant The intermediate import object. Used to set and get status from and set and get objects to and from.
158      * @param uti - UserTransactionInfo object which contains a collection in
159      * which all transactions for a user are listed.
160      */

161     public TransactionsParser(UserTransactionInfo uti, Consultant consultant) {
162         this(uti);
163         this.consultant = consultant;
164     }
165
166     /**
167      * Creates new TransactionParser object.
168      * @param uti - UserTransactionInfo object which contains a collection in
169      * which all transactions for a user are listed.
170      */

171     public TransactionsParser(UserTransactionInfo uti) {
172         this.uti = uti;
173         mmbase = (MMBase)Module.getModule("MMBASEROOT");
174         transactionHandler = (TransactionHandler)TransactionHandler.getModule("transactionhandler");
175         //upload = (Upload)Module.getModule("upload");
176
dtdDirectory = MMBaseContext.getConfigPath() + File.separator + "dtd" + File.separator;
177         reportDirectory = MMBaseContext.getConfigPath() + File.separator + "import" + File.separator + "report" + File.separator;
178         tmpObjectManager = new TemporaryNodeManager(mmbase);
179         transactionManager = new TransactionManager(mmbase, tmpObjectManager);
180     }
181
182     /**
183      * Overrides a method of org.xml.sax.helpers.DefaultHandler.
184      * For further info see javadoc of org.xml.sax.ContentHandler.
185      *
186      * @param nameSpaceURI - see org.xml.sax.ContentHandler
187      * @param localName - see org.xml.sax.ContentHandler
188      * @param name - The element type name.
189      * @param attributes - The specified or defaulted attributes.
190      * @throws SAXException - Any SAX exception, possibly wrapping another
191      * exception.
192      */

193     public void startElement(String JavaDoc nameSpaceURI, String JavaDoc localName, String JavaDoc name, Attributes attributes) throws SAXException {
194
195         // Reconstruct the parsed line.
196
StringBuffer JavaDoc sb = new StringBuffer JavaDoc("<" + name);
197         for (int i = 0; i < attributes.getLength(); i++) {
198             sb.append(" " + attributes.getQName(i) + "=\"" + attributes.getValue(i) + "\"");
199         }
200         sb.append(">");
201         String JavaDoc parsedLine = sb.toString();
202
203         // Log element read when debugging.
204
if (log.isDebugEnabled()) {
205             log.debug(parsedLine);
206         }
207
208         try {
209             if (name.equals(ELEMENT_TRANSACTIONS)) { // transactions
210
// Get attributes.
211
String JavaDoc attrExceptionPage = attributes.getValue(ATTRIBUTE_EXCEPTION_PAGE);
212                 String JavaDoc attrReportFile = attributes.getValue(ATTRIBUTE_REPORT_FILE);
213                 String JavaDoc attrKey = attributes.getValue(ATTRIBUTE_KEY);
214
215                 // Check attrKey.
216
transactionHandler.checkKey(attrKey);
217                 // Set exception page.
218
if (attrExceptionPage != null) {
219                     exceptionPage = attrExceptionPage;
220                 }
221
222                 // Create new reportFile.
223
try {
224                     if (attrReportFile != null) {
225                         reportFile = new File(reportDirectory, attrReportFile);
226
227                         // Delete old file if present.
228
if (reportFile.exists()) {
229                             reportFile.delete();
230                         } else {
231                             // Create parent directory if it does not exist already.
232
reportFile.getParentFile().mkdirs();
233                         }
234
235                         appendReportFile(xmlHeader + parsedLine + "\n");
236                     }
237
238                 } catch (Exception JavaDoc e) {
239                     throw new SAXException("Failed to create reportFile " + reportFile + ": " + e);
240                 }
241
242             } else if (name.equals(ELEMENT_CREATE)) { // create
243
// Get attributes.
244
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID); // id
245
boolean commit = Boolean.valueOf(//commit
246
attributes.getValue(ATTRIBUTE_COMMIT_ON_CLOSE)).booleanValue();
247                     long timeOut = Long.parseLong(// timeout
248
attributes.getValue(ATTRIBUTE_TIME_OUT));
249
250                 // Create new transaction.
251
transaction = Transaction.createTransaction(uti, id, commit, timeOut, reportFile, consultant);
252             } else if (name.equals(ELEMENT_OPEN)) { // open
253
// Get attributes.
254
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID); // id
255
boolean commit = Boolean.valueOf(// commit
256
attributes.getValue(ATTRIBUTE_COMMIT_ON_CLOSE)).booleanValue();
257
258                 // Open transaction.
259
transaction = Transaction.openTransaction(uti, id, commit);
260
261             } else if (name.equals(ELEMENT_COMMIT)) { // commit
262
// Get attributes.
263
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID); // id
264

265                 // Commit transaction.
266
transaction = Transaction.openTransaction(uti, id, false);
267                 transaction.commit();
268
269             } else if (name.equals(ELEMENT_DELETE)) { // delete
270
// Get attributes.
271
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID);
272
273                 // Delete transaction.
274
transaction = Transaction.openTransaction(uti, id, false);
275                 transaction.delete();
276
277             } else if (name.equals(ELEMENT_CREATE_OBJECT)) { // createObject
278
// Get attributes.
279
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID);
280                 String JavaDoc type = attributes.getValue(ATTRIBUTE_TYPE);
281                 boolean dispose // disposeWhenNotReferenced
282
= Boolean.valueOf(attributes.getValue(ATTRIBUTE_DISPOSE)).booleanValue();
283
284                 // Create new object.
285
tmpObject = transaction.createObject(id, type, dispose);
286
287             } else if (name.equals(ELEMENT_CREATE_RELATION)) { // createRelation
288
// Get attributes.
289
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID);
290                 String JavaDoc type = attributes.getValue(ATTRIBUTE_TYPE);
291                 String JavaDoc source = attributes.getValue(ATTRIBUTE_SOURCE);
292                 String JavaDoc destination = attributes.getValue(ATTRIBUTE_DESTINATION);
293
294                 // Create relation.
295
tmpObject = transaction.createRelation(id, type, source, destination);
296
297             } else if (name.equals(ELEMENT_OPEN_OBJECT)) { // openObject
298
// Get attributes.
299
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID); // id
300

301                 // Open object.
302
tmpObject = transaction.openObject(id);
303
304             } else if (name.equals(ELEMENT_ACCESS_OBJECT)) { // accessObject
305
// Get attributes.
306
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID); // id
307
try {
308                     int mmbaseId = Integer.parseInt(attributes.getValue(ATTRIBUTE_MMBASE_ID)); // mmbaseId
309

310                     // Access object.
311
tmpObject = transaction.accessObject(id, mmbaseId);
312                 } catch (NumberFormatException JavaDoc e) {
313                     throw new SAXException("invalid attribute mmbasid=\"" + attributes.getValue(ATTRIBUTE_MMBASE_ID) + "\"");
314                 }
315
316             } else if (name.equals(ELEMENT_DELETE_OBJECT)) { // deleteObject
317
// Get attributes.
318
String JavaDoc id = attributes.getValue(ATTRIBUTE_ID); // id
319

320                 // Delete object.
321
tmpObject = transaction.openObject(id);
322                 transaction.deleteObject(tmpObject);
323
324             } else if (name.equals(ELEMENT_MARK_OBJECT_DELETE)) { // markObjectDelete
325
// Get attributes.
326
try {
327                     int mmbaseId = Integer.parseInt(attributes.getValue(ATTRIBUTE_MMBASE_ID)); // mmbaseId
328
boolean deleteRelations = Boolean.valueOf(// deleteRelations
329
attributes.getValue(ATTRIBUTE_DELETE_RELATIONS)).booleanValue();
330
331                     // Mark object for delete.
332
tmpObject = transaction.accessObject(null, mmbaseId);
333                     transaction.markDeleteObject(tmpObject, deleteRelations);
334                 } catch (NumberFormatException JavaDoc e) {
335                     throw new SAXException("invalid attribute mmbasid=\"" + attributes.getValue(ATTRIBUTE_MMBASE_ID) + "\"");
336                 }
337
338             } else if (name.equals(ELEMENT_MERGE_OBJECTS)) { // mergeObjects
339
// Get attributes.
340
type = attributes.getValue(ATTRIBUTE_TYPE);
341
342             } else if (name.equals(ELEMENT_OBJECT_MATCHER)) { // objectMatcher
343
// Get attributes.
344
className = attributes.getValue(ATTRIBUTE_CLASS);
345
346                 // Initialize parameters.
347
params = new HashMap JavaDoc();
348
349             } else if (name.equals(ELEMENT_OBJECT_MERGER)) { // objectMerger
350
// Get attributes.
351
className = attributes.getValue(ATTRIBUTE_CLASS);
352
353                 // Initialize parameters.
354
params = new HashMap JavaDoc();
355
356             } else if (name.equals(ELEMENT_PARAM)) { // param
357
// Get attributes.
358
String JavaDoc paramName = attributes.getValue(ATTRIBUTE_NAME);
359                 String JavaDoc value = attributes.getValue(ATTRIBUTE_VALUE);
360
361                 // Add to parameters.
362
params.put(paramName, value);
363
364             } else if (name.equals(ELEMENT_SET_FIELD)) {
365                 // Get attributes.
366
fieldName = attributes.getValue(ATTRIBUTE_NAME); // name
367
url = attributes.getValue(ATTRIBUTE_URL); // url
368

369                 // Url specified, then set value from file.
370
/*
371                 if (url != null) {
372                     Object value = upload.getFile(url);
373                     tmpObject.setField(fieldName, value);
374                 }
375                 */

376
377             } else {
378                 throw new TransactionHandlerException("transaction operator \"" + name + "\" doesn't exist");
379             }
380
381         } catch (TransactionHandlerException e) {
382             throw new SAXException(e);
383         } finally {
384             // Add parsed line of xml to transactions history.
385
if (transaction != null) {
386                 transaction.appendReportBuffer("\n" + parsedLine);
387             }
388         }
389     }
390
391     /**
392      * Overrides a method of org.xml.sax.helpers.DefaultHandler.
393      * For further info see javadoc of org.xml.sax.ContentHandler.
394      *
395      * @param nameSpaceURI - see org.xml.sax.ContentHandler
396      * @param localName - see org.xml.sax.ContentHandler
397      * @param name - The element type name.
398      *
399      * @throws SAXException - Any SAX exception, possibly wrapping another exception.
400      */

401     public void endElement(String JavaDoc nameSpaceURI, String JavaDoc localName, String JavaDoc name) throws org.xml.sax.SAXException JavaDoc {
402
403         // Log this when debugging.
404
if (log.isDebugEnabled()) {
405             log.debug("</" + name + ">");
406         }
407
408         // Add parsed line of xml to transactions history.
409
if (transaction != null) {
410             transaction.appendReportBuffer("</" + name + ">\n");
411         }
412
413         try {
414             if (name.equals(ELEMENT_TRANSACTIONS)) { // transactions
415
// finish reportFile.
416
try {
417                     appendReportFile("</" + ELEMENT_TRANSACTIONS + ">");
418                 } catch (Exception JavaDoc e) {
419                     throw new SAXException("Failed to write to reportFile " + reportFile + ": " + e);
420                 }
421
422                 exceptionPage = null;
423                 reportFile = null;
424
425             } else if (name.equals(ELEMENT_CREATE)) { // create
426
transaction.leave();
427                 transaction = null;
428
429             } else if (name.equals(ELEMENT_OPEN)) { // open
430
transaction.leave();
431                 transaction = null;
432
433             } else if (name.equals(ELEMENT_COMMIT)) { // commit
434
transaction = null;
435
436             } else if (name.equals(ELEMENT_DELETE)) { // delete
437
transaction = null;
438
439             } else if (name.equals(ELEMENT_CREATE_OBJECT)) { // createObject
440
tmpObject = null;
441
442             } else if (name.equals(ELEMENT_CREATE_RELATION)) { // createRelation
443
tmpObject = null;
444
445             } else if (name.equals(ELEMENT_OPEN_OBJECT)) { // openObject
446
tmpObject = null;
447
448             } else if (name.equals(ELEMENT_ACCESS_OBJECT)) { // accessObject
449
tmpObject = null;
450
451             } else if (name.equals(ELEMENT_DELETE_OBJECT)) { // deleteObject
452
tmpObject = null;
453
454             } else if (name.equals(ELEMENT_MARK_OBJECT_DELETE)) { // markObjectDelete
455
tmpObject = null;
456
457             } else if (name.equals(ELEMENT_MERGE_OBJECTS)) { // mergeObjects
458
transaction.mergeObjects(type, objectFinder, objectMerger);
459
460                 type = null;
461                 objectFinder = null;
462                 objectMerger = null;
463
464             } else if (name.equals(ELEMENT_OBJECT_MATCHER)) { // objectFinder
465
// Create and initialize object finder instance.
466
try {
467                     objectFinder = (SimilarObjectFinder)Class.forName(className).newInstance();
468                     objectFinder.init(params);
469                 } catch (Exception JavaDoc e) {
470                     throw new SAXException(e);
471                 }
472
473                 params = null;
474                 className = null;
475
476             } else if (name.equals(ELEMENT_OBJECT_MERGER)) { // objectMerger
477
// Create object merger instance.
478
try {
479                     objectMerger = (ObjectMerger)Class.forName(className).newInstance();
480                     objectMerger.init(params);
481                 } catch (Exception JavaDoc e) {
482                     throw new SAXException(e);
483                 }
484
485                 params = null;
486                 className = null;
487
488             } else if (name.equals(ELEMENT_SET_FIELD)) {
489                 if (fieldValue != null) {
490                     tmpObject.setField(fieldName, fieldValue.toString());
491                 }
492                 fieldName = null;
493                 fieldValue = null;
494                 if (url != null) {
495                     //upload.deleteFile(url);
496
url = null;
497                 }
498             }
499
500         } catch (TransactionHandlerException e) {
501             throw new SAXException(e);
502         }
503
504     }
505
506     /**
507      * Overrides a method of org.xml.sax.helpers.DefaultHandler.
508      * The Parser will call this method to report each chunk of character data.
509      * For further info see javadoc of org.xml.sax.ContentHandler.
510      * @param ch - The characters from the XML document.
511      * @param start - The start position in the array.
512      * @param length - The number of characters to read from the array.
513      * @throws SAXException - Any SAX exception, possibly wrapping another
514      * exception.
515      */

516     public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException JavaDoc {
517
518         // Log characters read when debugging.
519
String JavaDoc characters = new String JavaDoc(ch, start, length);
520         if (log.isDebugEnabled()) {
521             log.debug("\"" + characters + "\"");
522         }
523
524         // Add parsed xml to transactions history.
525
if (transaction != null) {
526             transaction.appendReportBuffer(characters);
527         }
528
529         // We are only interested in the text contained in setField elements.
530
if (fieldName != null) {
531             // Check value not already set by url attribute.
532
if (url != null) {
533                 throw new SAXException("Can not set field value from both url and element value.");
534             }
535             if (fieldValue == null) {
536                 fieldValue = new StringBuffer JavaDoc();
537             }
538             fieldValue.append(characters);
539         }
540     }
541
542     /**
543      * Overrides a method of org.xml.sax.helpers.DefaultHandler.
544      * The default implementation (org.xml.sax.ContentHandler) does nothing.
545      * This implementation throws a SaxException.
546      *
547      * @param e c
548      * @throws SAXException - Any SAX exception, possibly wrapping another exception.
549      */

550     public void error(SAXParseException e) throws SAXException {
551         throw e;
552     }
553
554     /**
555      * Overrides a method of org.xml.sax.helpers.DefaultHandler.
556      * The default implementation (org.xml.sax.ContentHandler) does nothing.
557      * This implementation throws a SaxException.
558      * @param e - Any SAX exception, possibly wrapping another exception.
559      * @throws SAXException - Any SAX exception, possibly wrapping another exception.
560      */

561     public void warning(SAXParseException e) throws SAXException {
562         throw e;
563     }
564
565     /**
566      * Parse xml and execute transactions accordingly.
567      * @param input The input source.
568      * @throws TransactionHandlerException Except for IO exceptions every exception is wrapped in a TransactionException.
569      * @throws IOException If an IO problem occurs while reading the XML data.
570      */

571     public synchronized void parse(java.io.Reader JavaDoc input) throws IOException, TransactionHandlerException {
572
573         InputSource in = null;
574         SAXParser saxParser = null;
575         SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
576         try {
577             saxParser = saxParserFactory.newSAXParser();
578         } catch (ParserConfigurationException ex) {
579             log.warn(Logging.stackTrace(ex));
580         } catch (SAXException ex2) {
581             log.warn(Logging.stackTrace(ex2));
582         }
583
584         // Create input source.
585
in = new InputSource(input);
586         // set base directory (only works as reader is not made in this method)
587
in.setSystemId(dtdDirectory);
588         log.service("Sax parser system id set to \"" + dtdDirectory + "\"");
589
590         // Parse.
591
try {
592
593             saxParserFactory.setValidating(true);
594
595             XMLReader reader = saxParser.getXMLReader();
596             reader.setContentHandler(this);
597
598             reader.setDTDHandler(this);
599             reader.setEntityResolver(this);
600             reader.setErrorHandler(this);
601             reader.parse(in);
602         } catch (SAXException e2) {
603             // If a transaction is in progress, delete it.
604
if (transaction != null) {
605                 if (log.isDebugEnabled()) {
606                     log.debug("About to roll back transaction " + transaction.getKey() + " because an error occurred.");
607                 }
608                 try {
609                     transaction.delete();
610                 } catch (Exception JavaDoc e4) {
611                     log.debug("Failed to roll back transaction " + transaction.getKey() + " after an error occurred.");
612                 }
613             }
614
615             // Convert SAXException to TransactionHandlerException.
616
Exception JavaDoc e3 = e2.getException();
617             if (e3 != null && e3 instanceof TransactionHandlerException) {
618                 // Use embedded TransactionHandlerException.
619
throw (TransactionHandlerException)e3;
620             } else {
621                 // Wrap SAXException in TransactionHandlerException.
622
throw new TransactionHandlerException("Parse failed: \n" + e2);
623             }
624         }
625     }
626
627     /**
628      * Accessor for exceptionPage.
629      * @return value of exceptionPage field.
630      */

631     String JavaDoc getExceptionPage() {
632         return exceptionPage;
633     }
634
635     /**
636      * Appends text to reportFile (only if reportfile is specified).
637      * The file is opened and closed every time this method is called.
638      * @param text The text to append.
639      * @throws IOException If an IO failure occurred.
640      */

641     private void appendReportFile(String JavaDoc text) throws IOException {
642         Writer out = null;
643         if (reportFile != null) {
644             try {
645                 out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(reportFile.getPath(), true), ENCODING));
646                 out.write(text);
647             } finally {
648                 if (out != null) {
649                     out.close();
650                 }
651             }
652         }
653     }
654 }
655
Popular Tags