1 18 19 package org.webdocwf.util.xml; 20 21 import java.sql.*; 22 import java.util.Properties ; 23 import java.io.File ; 24 import java.io.RandomAccessFile ; 25 26 31 32 public class XmlDriver implements Driver 33 { 34 35 public static final String DEFAULT_EXTENSION = ".xml"; 36 public static final String FILE_EXTENSION="fileExtension"; 37 private final static String URL_PREFIX = "jdbc:webdocwf:xml:"; 38 private Properties info = null; 39 private String filePath; 40 41 42 43 private static boolean ENABLE_LOG = false; 44 45 46 55 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) 56 throws SQLException 57 { 58 return new DriverPropertyInfo[0]; 59 } 60 61 62 68 public int getMajorVersion() 69 { 70 return 1; 71 } 72 73 74 80 public int getMinorVersion() 81 { 82 return 0; 83 } 84 85 86 95 public Connection connect(String url, Properties info) throws SQLException 96 { 97 DriverManager.println("XmlJdbc - XmlDriver:connect() - url=" + url); 98 if (!url.startsWith(URL_PREFIX)) 100 { 101 return null; 102 } 103 this.filePath = url.substring(URL_PREFIX.length()); 105 if( !filePath.endsWith(".xml") ) { 107 this.filePath += this.DEFAULT_EXTENSION; 108 } 109 DriverManager.println("XmlJdbc - XmlDriver:connect() - filePath=" + filePath); 110 return new XmlConnection(filePath, info); 119 } 120 121 122 130 public boolean acceptsURL(String url) throws SQLException 131 { 132 DriverManager.println("XmlJdbc - XmlDriver:accept() - url=" + url); 133 return url.startsWith(URL_PREFIX); 134 } 135 136 137 143 public boolean jdbcCompliant() 144 { 145 return false; 146 } 147 static 149 { 150 try 151 { 152 java.sql.DriverManager.registerDriver(new XmlDriver()); 153 } 154 catch (SQLException e) 155 { 156 throw new RuntimeException ( 157 "FATAL ERROR: Could not initialise Xml driver ! Message was: " 158 + e.getMessage()); 159 } 160 } 161 162 public static void log( String message) { 163 if ( XmlDriver.ENABLE_LOG ) { 164 try { 165 File file = new File ("xmldriver.log"); 166 if (!file.exists()) 167 file.createNewFile(); 168 java.io.RandomAccessFile fileLogr = new java.io.RandomAccessFile (file, 169 "rw"); 170 fileLogr.seek(fileLogr.length()); 171 fileLogr.writeBytes("XmlJdbc, "+message + "\r\n"); 172 fileLogr.close(); 173 } 174 catch (Exception ex) { 175 ex.printStackTrace(); 176 } 177 } 178 } 179 180 } 181 182 | Popular Tags |