com.interface21.jndi
Class JndiObjectFactoryBean

java.lang.Object
  |
  +--com.interface21.jndi.AbstractJndiLocator
        |
        +--com.interface21.jndi.JndiObjectFactoryBean
All Implemented Interfaces:
FactoryBean, InitializingBean

public class JndiObjectFactoryBean
extends AbstractJndiLocator
implements FactoryBean

FactoryBean that looks up a JNDI object. Behaves like the object when used as bean reference, e.g. for JdbcTemplate's dataSource property. Note that switching to e.g. DriverManagerDataSource is just a matter of configuration: replace the definition of this FactoryBean with a DriverManagerDataSource definition!

The typical usage will be to register this as singleton factory (e.g. for a certain JNDI DataSource) in an application context, and give bean references to application services that need it.

Of course, service implementations can lookup e.g. a DataSource from JNDI themselves, but this class enables central configuration of the JNDI name, and easy switching to mock replacements. The latter can be used for test setups, standalone clients, etc.

Since:
22.05.2003
Author:
Juergen Hoeller
See Also:
JdbcTemplate.setDataSource(javax.sql.DataSource)

Fields inherited from class com.interface21.jndi.AbstractJndiLocator
CONTAINER_PREFIX, logger
 
Constructor Summary
JndiObjectFactoryBean()
           
 
Method Summary
 java.lang.Object getObject()
          Return the singleton JNDI object.
 PropertyValues getPropertyValues()
          Property values to pass to new bean instances created by this factory.
 boolean isSingleton()
          Is the bean managed by this factory a singleton or a prototype?
protected  void located(java.lang.Object o)
          Subclasses must implement this to cache the object this class has obtained from JNDI.
 
Methods inherited from class com.interface21.jndi.AbstractJndiLocator
afterPropertiesSet, getJndiName, getJndiTemplate, isInContainer, setInContainer, setJndiName, setJndiTemplate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JndiObjectFactoryBean

public JndiObjectFactoryBean()
Method Detail

located

protected void located(java.lang.Object o)
Description copied from class: AbstractJndiLocator
Subclasses must implement this to cache the object this class has obtained from JNDI.
Overrides:
located in class AbstractJndiLocator
Following copied from class: com.interface21.jndi.AbstractJndiLocator
Parameters:
o - object successfully retrieved from JNDI

getObject

public java.lang.Object getObject()
Return the singleton JNDI object.
Specified by:
getObject in interface FactoryBean
Following copied from interface: com.interface21.beans.factory.FactoryBean
Returns:
an instance of the bean

isSingleton

public boolean isSingleton()
Description copied from interface: FactoryBean
Is the bean managed by this factory a singleton or a prototype? That is, will getBean() always return the same object?
The singleton status of a FactoryBean will generally be provided by the owning BeanFactory.
Specified by:
isSingleton in interface FactoryBean
Following copied from interface: com.interface21.beans.factory.FactoryBean
Returns:
is this bean a singleton

getPropertyValues

public PropertyValues getPropertyValues()
Description copied from interface: FactoryBean
Property values to pass to new bean instances created by this factory. Mapped directly onto the bean instance using reflection. This occurs after any configuration of the instance performed by the factory itself, and is an optional step within the control of the owning BeanFactory.
Specified by:
getPropertyValues in interface FactoryBean
Following copied from interface: com.interface21.beans.factory.FactoryBean
Returns:
PropertyValues to pass to each new instance, or null (the default) if there are no properties to pass to the instance.


Rod Johnson and Spring contributors 2001-2003.