com.ora.jsp.sql
Class DataSourceFactory

java.lang.Object
  extended bycom.ora.jsp.sql.DataSourceFactory
All Implemented Interfaces:
javax.naming.spi.ObjectFactory

public class DataSourceFactory
extends java.lang.Object
implements javax.naming.spi.ObjectFactory

This class is an implementation of the ObjectFactory interface, used by a container to create instances of resources accessible through JNDI. It's intended to be used to create an instance of the DataSource class and configure it as defined by the parameters passed through the JNDI implementation.

Version:
1.0
Author:
Hans Bergsten, Gefion software

Constructor Summary
DataSourceFactory()
           
 
Method Summary
private  java.lang.Object[] buildArgs(java.lang.String value, java.lang.reflect.Method setter)
          Converts the specified String value to the setter methods parameter type, if possible, and returns it as an Object array suitable as the argument to the Method.invoke() method.
private  java.lang.Object coerceValue(java.lang.String value, java.lang.Class type)
          Converts the specified String value to the specified type, if possible, and returns the converted value.
 java.lang.Object getObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable environment)
          Creates an instance of the DataSource based on the configuration info.
private  java.lang.reflect.Method getSetter(java.lang.String prop, java.lang.Object ds)
          Returns the setter method corresponding to the property name in the specified object, or null if no matching setter method is found.
private  void setProperty(java.lang.String prop, java.lang.String value, java.lang.Object ds)
          Sets the specified property to the specified value in the specified object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceFactory

public DataSourceFactory()
Method Detail

getObjectInstance

public java.lang.Object getObjectInstance(java.lang.Object obj,
                                          javax.naming.Name name,
                                          javax.naming.Context nameCtx,
                                          java.util.Hashtable environment)
                                   throws javax.naming.NamingException
Creates an instance of the DataSource based on the configuration info. The class name must be passed as a parameter named "dataSourceClassName". Introspection is used to find and call setter methods in the DataSource corresponding to all other parameters.

Specified by:
getObjectInstance in interface javax.naming.spi.ObjectFactory
Throws:
javax.naming.NamingException

setProperty

private void setProperty(java.lang.String prop,
                         java.lang.String value,
                         java.lang.Object ds)
Sets the specified property to the specified value in the specified object.


getSetter

private java.lang.reflect.Method getSetter(java.lang.String prop,
                                           java.lang.Object ds)
Returns the setter method corresponding to the property name in the specified object, or null if no matching setter method is found.


buildArgs

private java.lang.Object[] buildArgs(java.lang.String value,
                                     java.lang.reflect.Method setter)
Converts the specified String value to the setter methods parameter type, if possible, and returns it as an Object array suitable as the argument to the Method.invoke() method.


coerceValue

private java.lang.Object coerceValue(java.lang.String value,
                                     java.lang.Class type)
Converts the specified String value to the specified type, if possible, and returns the converted value. Only conversion to Integer and Boolean is currently supported, since these types covers all DataSource implementations I've come across. It's easy to add new conversions if needed.