org.objectweb.cjdbc.controller.connection
Class DriverClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byorg.objectweb.cjdbc.controller.connection.DriverClassLoader

public class DriverClassLoader
extends java.lang.ClassLoader

This class defines a DriverClassLoader used to load drivers with their own classloder to be able to handle different implementations of drivers sharing the same class name. For example if you want to connect to two backends of the same vendor, but running with different releases and requiring a driver compatible with the respective database release

Version:
1.0
Author:
Emmanuel Cecchet

Nested Class Summary
 
Nested classes inherited from class java.lang.ClassLoader
 
Field Summary
private  java.util.Hashtable htJarContents
          we cache the contents of the jar files, as we don't want to have to read the file for every single class we are going to need
private  java.io.File path
          path on filesystem where the driver is located
 
Fields inherited from class java.lang.ClassLoader
 
Constructor Summary
(package private) DriverClassLoader(java.lang.ClassLoader parent, java.io.File pPath)
          Creates a new DriverClassLoader.java object
 
Method Summary
private  java.lang.String convertClassNameToResourceName(java.lang.String className)
          convert the class name into the rescource name.
protected  java.lang.Class findClass(java.lang.String className)
          finds the specified class
private  byte[] findClassInJarFile(java.io.File dir, java.lang.String className)
          Find the first jar file containing the className and load it
protected  java.net.URL findResource(java.lang.String name)
           
private  void loadJarFile(java.lang.String jarFileName)
          Load the contents of jar file in the cache
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

path

private java.io.File path
path on filesystem where the driver is located


htJarContents

private java.util.Hashtable htJarContents
we cache the contents of the jar files, as we don't want to have to read the file for every single class we are going to need

Constructor Detail

DriverClassLoader

DriverClassLoader(java.lang.ClassLoader parent,
                  java.io.File pPath)
Creates a new DriverClassLoader.java object

Parameters:
parent - classloader, null if no parent classloader should be used
pPath - path where the driver classfiles of jar files are located
Method Detail

findClass

protected java.lang.Class findClass(java.lang.String className)
                             throws java.lang.ClassNotFoundException
finds the specified class

Throws:
java.lang.ClassNotFoundException
See Also:
ClassLoader.findClass(java.lang.String)

findClassInJarFile

private byte[] findClassInJarFile(java.io.File dir,
                                  java.lang.String className)
                           throws java.io.IOException
Find the first jar file containing the className and load it

Parameters:
dir - directory where we are looking for jar files
className - name of the class we are looking for
Returns:
the class as byte[]
Throws:
java.io.IOException - if an error occurs

findResource

protected java.net.URL findResource(java.lang.String name)
See Also:
ClassLoader.findResource(java.lang.String)

convertClassNameToResourceName

private java.lang.String convertClassNameToResourceName(java.lang.String className)
convert the class name into the rescource name. This method is just replacing the '.' in the name with a '/' and adding the suffix '.class'

Parameters:
className -
Returns:
resource name

loadJarFile

private void loadJarFile(java.lang.String jarFileName)
                  throws java.io.IOException
Load the contents of jar file in the cache

Parameters:
jarFileName - name of the jar file we want to load
Throws:
java.io.IOException


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.