001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 021 package org.apache.geronimo.jdbc; 022 023 import java.util.List; 024 import java.util.ArrayList; 025 import java.util.Properties; 026 import java.sql.Driver; 027 import java.sql.Connection; 028 import java.sql.SQLException; 029 import java.sql.DriverPropertyInfo; 030 import java.sql.DriverManager; 031 032 /** 033 * Class to sneak around idiotic classloading restrictions in DriverManager. This basically does the same as DriverManager 034 * except that you register Driver instances directly. 035 * @version $Rev: 533154 $ $Date: 2007-04-27 12:06:53 -0400 (Fri, 27 Apr 2007) $ 036 */ 037 public class DelegatingDriver implements Driver { 038 039 private static final List<Driver> DRIVERS = new ArrayList<Driver>(); 040 041 static { 042 try { 043 DriverManager.registerDriver(new DelegatingDriver()); 044 } catch (SQLException e) { 045 throw new RuntimeException(e); 046 } 047 } 048 049 public static void registerDriver(Driver instance) { 050 DRIVERS.add(instance); 051 } 052 053 public static void unregisterDriver(Driver instance) { 054 DRIVERS.remove(instance); 055 } 056 057 public Connection connect(String url, Properties info) throws SQLException { 058 for (Driver driver: DRIVERS) { 059 Connection conn = driver.connect(url, info); 060 if (conn != null) { 061 return conn; 062 } 063 } 064 return null; 065 } 066 067 public boolean acceptsURL(String url) throws SQLException { 068 for (Driver driver: DRIVERS) { 069 if (driver.acceptsURL(url)) { 070 return true; 071 } 072 } 073 return false; 074 } 075 076 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { 077 return new DriverPropertyInfo[0]; 078 } 079 080 public int getMajorVersion() { 081 return 1; 082 } 083 084 public int getMinorVersion() { 085 return 0; 086 } 087 088 public boolean jdbcCompliant() { 089 //Lie through our teeth 090 return true; 091 } 092 }