package de.einwesen.jdbc.poissf;


import java.net.URL;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;

public class PoiSSFDriver implements Driver {

	public static final String CONNECT_ERROR = "Could not create connection";
	public static final String CONNECTION_IS_CLOSED = "Connection is closed";
	public static final String STATEMENT_IS_CLOSED = "Statement is closed";
	public static final String RESULTSET_IS_CLOSED = "ResultSet is closed";
	public static final String CURSOR_ON_INVALID_ROW = "Cursor is not on a valid row";
	public static final String ERROR_RETRIEVING_DATA = "Error retrieving data from cell";
	public static final String INCOMPATIBLE_DATATYPE = "Incompatible datatype in cell";
	public static final String RESULT_SET_NOT_UPDATETABLE = "ResultSet is not updatetable";
	public static final String INVALID_COLUMN_INDEX = "Invalid columnIndex %d";
	public static final String NOT_IMPLEMENTED_YET = "Not implemented yet";
	public static final String PARAMETER_MAY_NOT_BE_NULL = "parameter %s my not be null";
	
	private static final String URL_PREFIX = "jdbc:poissf:";
	private static final String URL_PATTERN = URL_PREFIX + "file:///.*\\.xls(x|$)";
	
    static{
        try{
            DriverManager.registerDriver(new PoiSSFDriver());
        }catch(SQLException ex){
            throw new ExceptionInInitializerError(ex);
        }
    }

    
	private PoiSSFDriver() {}
	
	@Override
	public Connection connect(String url, Properties info) throws SQLException {
		if (acceptsURL(url)) {
			try {
				return new PoiSSFConnection(new URL(url.substring(URL_PREFIX.length())));
			} catch (Throwable e) {
				throw new SQLException(CONNECT_ERROR, e);
			}
		} else {
			return null;			
		}
		
	}

	@Override
	public boolean acceptsURL(String url) throws SQLException {
		return url != null && url.toLowerCase().matches(URL_PATTERN);
	}

	@Override
	public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
		return new DriverPropertyInfo[0];
	}

	@Override
	public int getMajorVersion() {
		return 0;
	}

	@Override
	public int getMinorVersion() {
		return 1;
	}

	@Override
	public boolean jdbcCompliant() {
		return false;
	}

	@Override
	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
		throw new SQLFeatureNotSupportedException();
	}

}

@@ -358,22 +358,37 @@
 ver %7B%0A%0A%09
-public
+/* package-private */
  static 
@@ -444,30 +444,45 @@
 nnection%22;%0A%09
-public
+/* package-private */
  static fina
@@ -530,38 +530,53 @@
 on is closed%22;%0A%09
-public
+/* package-private */
  static final St
@@ -618,38 +618,53 @@
 nt is closed%22;%0A%09
-public
+/* package-private */
  static final St
@@ -710,30 +710,45 @@
 s closed%22;%0A%09
-public
+/* package-private */
  static fina
@@ -809,30 +809,45 @@
 alid row%22;%0A%09
-public
+/* package-private */
  static fina
@@ -907,38 +907,53 @@
 ta from cell%22;%0A%09
-public
+/* package-private */
  static final St
@@ -1011,30 +1011,45 @@
  in cell%22;%0A%09
-public
+/* package-private */
  static fina
@@ -1115,30 +1115,45 @@
 atetable%22;%0A%09
-public
+/* package-private */
  static fina
@@ -1207,30 +1207,45 @@
 Index %25d%22;%0A%09
-public
+/* package-private */
  static fina
@@ -1299,22 +1299,37 @@
  yet%22;%0A%09
-public
+/* package-private */
  static 

change constant visibility