⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmldriver.java

📁 数据仓库工具
💻 JAVA
字号:
/*
    Copyright (C) 2003  Together

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package org.webdocwf.util.xml;

import java.sql.*;
import java.util.Properties;
import java.io.File;
import java.io.RandomAccessFile;

/**
 * Class implements the JDBC Driver interface for the XmlJdbc driver.
 *
 * @author     Zoran Milakovic
 */

public class XmlDriver implements Driver
{

  public static final String DEFAULT_EXTENSION = ".xml";
  public static final String FILE_EXTENSION="fileExtension";
  private final static String URL_PREFIX = "jdbc:webdocwf:xml:";
  private Properties info = null;
  private String filePath;


  /* If set to true, driver will log into xmldriver.log file, in working directory */
  private static boolean ENABLE_LOG = false;


  /**
   *Gets the propertyInfo attribute of the XmlDriver object
   *
   * @param  url               Description of Parameter
   * @param  info              Description of Parameter
   * @return                   The propertyInfo value
   * @exception  SQLException  Description of Exception
   * @since
   */
  public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
       throws SQLException
  {
    return new DriverPropertyInfo[0];
  }


  /**
   *Gets the majorVersion attribute of the XmlDriver object
   *
   * @return    The majorVersion value
   * @since
   */
  public int getMajorVersion()
  {
    return 1;
  }


  /**
   *Gets the minorVersion attribute of the XmlDriver object
   *
   * @return    The minorVersion value
   * @since
   */
  public int getMinorVersion()
  {
    return 0;
  }


  /**
   *Description of the Method
   *
   * @param  url               Description of Parameter
   * @param  info              Description of Parameter
   * @return                   Description of the Returned Value
   * @exception  SQLException  Description of Exception
   * @since
   */
  public Connection connect(String url, Properties info) throws SQLException
  {
    DriverManager.println("XmlJdbc - XmlDriver:connect() - url=" + url);
    // check for correct url
    if (!url.startsWith(URL_PREFIX))
    {
      return null;
    }
    // get filepath from url
    this.filePath = url.substring(URL_PREFIX.length());
    //if file do not ends with .xml,add one
    if( !filePath.endsWith(".xml") ) {
          this.filePath += this.DEFAULT_EXTENSION;
    }
    DriverManager.println("XmlJdbc - XmlDriver:connect() - filePath=" + filePath);
    // check if filepath is a correct path.
//    File checkPath;
//    checkPath = new File(filePath);
//
//    if (!checkPath.exists())
//    {
//      this.createDatabase();
//    }
    return new XmlConnection(filePath, info);
  }


  /**
   *Description of the Method
   *
   * @param  url               Description of Parameter
   * @return                   Description of the Returned Value
   * @exception  SQLException  Description of Exception
   * @since
   */
  public boolean acceptsURL(String url) throws SQLException
  {
    DriverManager.println("XmlJdbc - XmlDriver:accept() - url=" + url);
    return url.startsWith(URL_PREFIX);
  }


  /**
   *Description of the Method
   *
   * @return    Description of the Returned Value
   * @since
   */
  public boolean jdbcCompliant()
  {
    return false;
  }
  // This static block inits the driver when the class is loaded by the JVM.
  static
  {
    try
    {
      java.sql.DriverManager.registerDriver(new XmlDriver());
    }
    catch (SQLException e)
    {
      throw new RuntimeException(
          "FATAL ERROR: Could not initialise Xml driver ! Message was: "
           + e.getMessage());
    }
  }

  public static void log( String message) {
      if ( XmlDriver.ENABLE_LOG ) {
        try {
          File file = new File("xmldriver.log");
          if (!file.exists())
            file.createNewFile();
          java.io.RandomAccessFile fileLogr = new java.io.RandomAccessFile(file,
              "rw");
          fileLogr.seek(fileLogr.length());
          fileLogr.writeBytes("XmlJdbc, "+message + "\r\n");
          fileLogr.close();
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -