View Javadoc
1 /* 2 Copyright (C) 2003 Together 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 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 /*** 27 * Class implements the JDBC Driver interface for the XmlJdbc driver. 28 * 29 * @author Zoran Milakovic 30 */ 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 /* If set to true, driver will log into xmldriver.log file, in working directory */ 43 private static boolean ENABLE_LOG = false; 44 45 46 /*** 47 *Gets the propertyInfo attribute of the XmlDriver object 48 * 49 * @param url Description of Parameter 50 * @param info Description of Parameter 51 * @return The propertyInfo value 52 * @exception SQLException Description of Exception 53 * @since 54 */ 55 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) 56 throws SQLException 57 { 58 return new DriverPropertyInfo[0]; 59 } 60 61 62 /*** 63 *Gets the majorVersion attribute of the XmlDriver object 64 * 65 * @return The majorVersion value 66 * @since 67 */ 68 public int getMajorVersion() 69 { 70 return 1; 71 } 72 73 74 /*** 75 *Gets the minorVersion attribute of the XmlDriver object 76 * 77 * @return The minorVersion value 78 * @since 79 */ 80 public int getMinorVersion() 81 { 82 return 0; 83 } 84 85 86 /*** 87 *Description of the Method 88 * 89 * @param url Description of Parameter 90 * @param info Description of Parameter 91 * @return Description of the Returned Value 92 * @exception SQLException Description of Exception 93 * @since 94 */ 95 public Connection connect(String url, Properties info) throws SQLException 96 { 97 DriverManager.println("XmlJdbc - XmlDriver:connect() - url=" + url); 98 // check for correct url 99 if (!url.startsWith(URL_PREFIX)) 100 { 101 return null; 102 } 103 // get filepath from url 104 this.filePath = url.substring(URL_PREFIX.length()); 105 //if file do not ends with .xml,add one 106 if( !filePath.endsWith(".xml") ) { 107 this.filePath += this.DEFAULT_EXTENSION; 108 } 109 DriverManager.println("XmlJdbc - XmlDriver:connect() - filePath=" + filePath); 110 // check if filepath is a correct path. 111 // File checkPath; 112 // checkPath = new File(filePath); 113 // 114 // if (!checkPath.exists()) 115 // { 116 // this.createDatabase(); 117 // } 118 return new XmlConnection(filePath, info); 119 } 120 121 122 /*** 123 *Description of the Method 124 * 125 * @param url Description of Parameter 126 * @return Description of the Returned Value 127 * @exception SQLException Description of Exception 128 * @since 129 */ 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 /*** 138 *Description of the Method 139 * 140 * @return Description of the Returned Value 141 * @since 142 */ 143 public boolean jdbcCompliant() 144 { 145 return false; 146 } 147 // This static block inits the driver when the class is loaded by the JVM. 148 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

This page was automatically generated by Maven