org.springframework.jndi
Class JndiObjectFactoryBean

java.lang.Object
  extended byorg.springframework.jndi.AbstractJndiLocator
      extended byorg.springframework.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.

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 non-JNDI replacements. The latter can be used for test setups, standalone clients, etc.

Note that switching to e.g. DriverManagerDataSource is just a matter of configuration: replace the definition of this FactoryBean with a DriverManagerDataSource definition!

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

Field Summary
 
Fields inherited from class org.springframework.jndi.AbstractJndiLocator
CONTAINER_PREFIX, logger
 
Constructor Summary
JndiObjectFactoryBean()
           
 
Method Summary
 java.lang.Object getObject()
          Return the singleton JNDI object.
 java.lang.Class getObjectType()
          Return the type of object that this FactoryBean creates, or null if not known in advance.
 boolean isSingleton()
          Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object?
protected  void located(java.lang.Object jndiObject)
          Subclasses must implement this to cache the object this class has obtained from JNDI.
 
Methods inherited from class org.springframework.jndi.AbstractJndiLocator
afterPropertiesSet, getJndiEnvironment, getJndiName, getJndiTemplate, isResourceRef, setJndiEnvironment, setJndiName, setJndiTemplate, setResourceRef
 
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 jndiObject)
Description copied from class: AbstractJndiLocator
Subclasses must implement this to cache the object this class has obtained from JNDI.

Specified by:
located in class AbstractJndiLocator
Parameters:
jndiObject - object successfully retrieved from JNDI

getObject

public java.lang.Object getObject()
Return the singleton JNDI object.

Specified by:
getObject in interface FactoryBean
Returns:
an instance of the bean (should never be null)

getObjectType

public java.lang.Class getObjectType()
Description copied from interface: FactoryBean
Return the type of object that this FactoryBean creates, or null if not known in advance. This allows to check for specific types of beans without instantiating objects, e.g. on autowiring.

For a singleton, this can simply return getObject().getClass(), or even null, as autowiring will always check the actual objects for singletons. For prototypes, returning a meaningful type here is highly advisable, as autowiring will simply ignore them else.

Specified by:
getObjectType in interface FactoryBean
Returns:
the type of object that this FactoryBean creates, or null
See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class, boolean, boolean)

isSingleton

public boolean isSingleton()
Description copied from interface: FactoryBean
Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object?

The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory.

Specified by:
isSingleton in interface FactoryBean
Returns:
if this bean is a singleton


Copyright (C) 2003-2004 The Spring Framework Project.