1 56 57 package org.jdom.adapters; 58 59 import java.io.*; 60 import java.lang.reflect.*; 61 62 import org.jdom.*; 63 import org.w3c.dom.Document ; 64 import org.xml.sax.*; 65 66 73 public class OracleV2DOMAdapter extends AbstractDOMAdapter { 74 75 private static final String CVS_ID = 76 "@(#) $RCSfile: OracleV2DOMAdapter.java,v $ $Revision: 1.18 $ $Date: 2004/02/06 09:28:31 $ $Name: $"; 77 78 89 public Document getDocument(InputStream in, boolean validate) 90 throws IOException, JDOMException { 91 92 try { 93 Class parserClass = Class.forName("oracle.xml.parser.v2.DOMParser"); 95 Object parser = parserClass.newInstance(); 96 97 Method parse = 99 parserClass.getMethod("parse", 100 new Class [] {org.xml.sax.InputSource .class}); 101 parse.invoke(parser, new Object [] {new InputSource(in)}); 102 103 Method getDocument = parserClass.getMethod("getDocument", null); 105 Document doc = (Document )getDocument.invoke(parser, null); 106 107 return doc; 108 } catch (InvocationTargetException e) { 109 Throwable targetException = e.getTargetException(); 110 if (targetException instanceof org.xml.sax.SAXParseException ) { 111 SAXParseException parseException = (SAXParseException)targetException; 112 throw new JDOMException("Error on line " + parseException.getLineNumber() + 113 " of XML document: " + parseException.getMessage(), parseException); 114 } else if (targetException instanceof IOException) { 115 IOException ioException = (IOException) targetException; 116 throw ioException; 117 } else { 118 throw new JDOMException(targetException.getMessage(), targetException); 119 } 120 } catch (Exception e) { 121 throw new JDOMException(e.getClass().getName() + ": " + 122 e.getMessage(), e); 123 } 124 } 125 126 133 public Document createDocument() throws JDOMException { 134 try { 135 return 136 (Document )Class.forName( 137 "oracle.xml.parser.v2.XMLDocument") 138 .newInstance(); 139 140 } catch (Exception e) { 141 throw new JDOMException(e.getClass().getName() + ": " + 142 e.getMessage() + " when creating document", e); 143 } 144 } 145 } 146 | Popular Tags |