org.pojava.persistence.jndi
Class JNDIRegistry

java.lang.Object
  extended by org.pojava.persistence.jndi.JNDIRegistry

public class JNDIRegistry
extends Object

A helper class for stubbing out an InitialContext for unit tests. As a concrete example, this can be used to place DataSource objects into JNDI without running inside an application context.

Author:
John Pile

Method Summary
static DataSource extractDataSource(Properties props, String dsName)
          Extract a JDBC DataSource from a property object.
static Properties fetchProperties(String propertyFile)
          Fetch properties from a custom.properties file.
static Context getInitialContext()
          Get an initial context, making one if it doesn't exist.
static Context getInitialContext(String initialContextFactory)
          Get an initial context, making one if it doesn't exist.
static DataSource lookupDataSource(String key)
          Look up a DataSource from JNDI.
static Object lookupEnv(String name)
          Look up an Environment variable from JNDI.
static Object lookupFullyQualified(String name)
          Lookup an object from JNDI by its fully qualified name.
static void registerDatasourcesFromFile(String propertyFile)
          Register JDBC DataSources from a property file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInitialContext

public static Context getInitialContext()
                                 throws NamingException
Get an initial context, making one if it doesn't exist.

Returns:
Context either newly created or retrieved.
Throws:
NamingException

getInitialContext

public static Context getInitialContext(String initialContextFactory)
                                 throws NamingException
Get an initial context, making one if it doesn't exist.

Returns:
Context either newly created or retrieved.
Throws:
NamingException

lookupEnv

public static Object lookupEnv(String name)
                        throws NamingException
Look up an Environment variable from JNDI.

Parameters:
name -
Returns:
Environment variable retrieved from JNDI.
Throws:
NamingException

lookupDataSource

public static DataSource lookupDataSource(String key)
                                   throws NamingException
Look up a DataSource from JNDI.

Parameters:
key -
Returns:
a DataSource object retrieved from JNDI registry.
Throws:
NamingException

lookupFullyQualified

public static Object lookupFullyQualified(String name)
                                   throws NamingException
Lookup an object from JNDI by its fully qualified name.

Parameters:
name -
Returns:
an object retrieved from the JNDI registry.
Throws:
NamingException

fetchProperties

public static Properties fetchProperties(String propertyFile)
Fetch properties from a custom.properties file.

Parameters:
propertyFile - file holding properties to retrieve
Returns:
Properties retrieved from file

extractDataSource

public static DataSource extractDataSource(Properties props,
                                           String dsName)
                                    throws ClassNotFoundException
Extract a JDBC DataSource from a property object.

Parameters:
props - Properties retrieved from a property file
dsName - Name identifying a DataSource
Returns:
DataSource
Throws:
ClassNotFoundException

registerDatasourcesFromFile

public static void registerDatasourcesFromFile(String propertyFile)
                                        throws ClassNotFoundException,
                                               NamingException
Register JDBC DataSources from a property file

Parameters:
propertyFile -
Throws:
ClassNotFoundException
NamingException


Copyright © 2011. All Rights Reserved.