java.lang.Object
org.omnifaces.util.JNDIObjectLocator
- All Implemented Interfaces:
Serializable
JNDIObjectLocator is used to centralize JNDI lookups. It minimizes the overhead of JNDI lookups by caching the objects it looks up.
Implements the ServiceLocator design pattern.
Major features are:
- thread-safe
- immutable
- serializable
- selectively disables the cache if objects are remote
Example:
locator = JNDIObjectLocator.builder().build();
MyEJB myEJB1 = locator.getObject(MyEJB.class);
MyEJB myEJB2 = locator.getObject("java:module/MyEJB");
- Since:
- 3.9
- Author:
- Lenny Primak
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Returns the builder of theJNDIObjectLocator.voidClears object cache.<T> TgetEnvEntry(String name) Same asJNDI.getEnvEntry(String), except that this is cached.<T> TReturns an object from JNDI based on beanClass.<T> TReturns an object based on JNDI name.<T> TgetObjectNoCache(String jndiName) Return an object based on JNDI name, bypassing the cache.prependNamespaceIfNecessary(String fieldName) Utility method used in matching fields to EJB injection points to try to find appropriate JNDI object to use for injection.
-
Method Details
-
builder
Returns the builder of theJNDIObjectLocator.- Returns:
- The builder of the
JNDIObjectLocator.
-
getEnvEntry
Same asJNDI.getEnvEntry(String), except that this is cached.- Type Parameters:
T- The expected return type.- Parameters:
name- the environment entry name relative to "java:comp/env".- Returns:
- The environment entry value associated with the given name, or
nullif there is none. - Throws:
ClassCastException- WhenTis of wrong type.- See Also:
-
getObject
Returns an object from JNDI based on beanClass. Uses portable object names and convention to derive appropriate JNDI name.- Type Parameters:
T- Object type.- Parameters:
beanClass- Type of object to look up in JNDI.- Returns:
- Resulting object, or
nullif there is none.
-
getObject
Returns an object based on JNDI name.- Type Parameters:
T- The expected return type.- Parameters:
jndiName- The JNDI name of the object to be retrieved.- Returns:
- The named object, or
nullif there is none. - Throws:
ClassCastException- WhenTis of wrong type.
-
getObjectNoCache
Return an object based on JNDI name, bypassing the cache.- Type Parameters:
T- The expected return type.- Parameters:
jndiName- The JNDI name of the object to be retrieved.- Returns:
- The named object, or
nullif there is none. - Throws:
ClassCastException- WhenTis of wrong type.
-
clearCache
public void clearCache()Clears object cache. -
prependNamespaceIfNecessary
Utility method used in matching fields to EJB injection points to try to find appropriate JNDI object to use for injection. It prepends the given field name with this locator's namespace when the given field name does not already start withJNDI.JNDI_NAMESPACE_PREFIX.- Parameters:
fieldName- The field name to prepend with this locator's name space if necessary.- Returns:
- The given field name, prepended with this locator's name space if necessary.
-