|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.jndi.AbstractJndiLocator
Convenient superclass for JNDI-based Service Locators. Subclasses are JavaBeans, exposing a jndiName property. This may or may not include the "java:comp/env/" prefix expected by J2EE applications when accessing a locally mapped (ENC - Environmental Naming Context) resource. If it doesn't, the "java:comp/env/" prefix will be prepended if the "resourceRef" property is true (the default is false) and no other scheme like "java:" is given.
Subclasses must implement the located() method to cache the results of the JNDI lookup. They don't need to worry about error handling.
Assumptions: The resource obtained from JNDI can be cached.
Subclasses will often be used as singletons in a bean container. This sometiems presents a problem if that bean container pre-instantiates singletons, since this class does the JNDI lookup in its init method, but the resource being pointed to may not exist at that time, even though it may exist at the time of first usage. The solution is to tell the bean container not to pre-instantiate this class (i.e. lazy load it instead).
setJndiTemplate(org.springframework.jndi.JndiTemplate)
,
setJndiEnvironment(java.util.Properties)
,
setResourceRef(boolean)
Field Summary | |
static java.lang.String |
CONTAINER_PREFIX
JNDI prefix used in a J2EE container |
protected org.apache.commons.logging.Log |
logger
|
Constructor Summary | |
AbstractJndiLocator()
Create a new JNDI locator. |
|
AbstractJndiLocator(java.lang.String jndiName)
Create a new JNDI locator, specifying the JNDI name. |
Method Summary | |
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
java.util.Properties |
getJndiEnvironment()
Return the JNDI enviromment to use for the JNDI lookup. |
java.lang.String |
getJndiName()
Return the JNDI name to look up. |
JndiTemplate |
getJndiTemplate()
Return the JNDI template to use for the JNDI lookup. |
boolean |
isResourceRef()
Return if the lookup occurs in a J2EE container. |
protected abstract void |
located(java.lang.Object jndiObject)
Subclasses must implement this to cache the object this class has obtained from JNDI. |
void |
setJndiEnvironment(java.util.Properties jndiEnvironment)
Set the JNDI environment to use for the JNDI lookup. |
void |
setJndiName(java.lang.String jndiName)
Set the JNDI name. |
void |
setJndiTemplate(JndiTemplate jndiTemplate)
Set the JNDI template to use for the JNDI lookup. |
void |
setResourceRef(boolean resourceRef)
Set if the lookup occurs in a J2EE container, i.e. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static java.lang.String CONTAINER_PREFIX
protected final org.apache.commons.logging.Log logger
Constructor Detail |
public AbstractJndiLocator()
Obviously, this class is typically used via a BeanFactory.
public AbstractJndiLocator(java.lang.String jndiName) throws javax.naming.NamingException, java.lang.IllegalArgumentException
As this is a shortcut, it calls afterPropertiesSet to perform the JNDI lookup immediately.
jndiName
- JNDI name.Method Detail |
public final void setJndiTemplate(JndiTemplate jndiTemplate)
setJndiEnvironment(java.util.Properties)
public final JndiTemplate getJndiTemplate()
public final void setJndiEnvironment(java.util.Properties jndiEnvironment)
setJndiTemplate(org.springframework.jndi.JndiTemplate)
public final java.util.Properties getJndiEnvironment()
public final void setJndiName(java.lang.String jndiName)
jndiName
- JNDI name of bean to look upsetResourceRef(boolean)
public final java.lang.String getJndiName()
public void setResourceRef(boolean resourceRef)
Note: Will only get applied if no other scheme like "java:" is given.
public final boolean isResourceRef()
public final void afterPropertiesSet() throws javax.naming.NamingException, java.lang.IllegalArgumentException
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
javax.naming.NamingException
java.lang.IllegalArgumentException
protected abstract void located(java.lang.Object jndiObject)
jndiObject
- object successfully retrieved from JNDI
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |