org.omnifaces.util
Class JNDI

java.lang.Object
  extended by org.omnifaces.util.JNDI

public final class JNDI
extends java.lang.Object

Utility class for simplifying some web related tasks that use JNDI under the hood, such as getting the <env-entry> from web.xml.

Note that the JSF spec defines one parameter that can optionally be defined via an env entry instead of the typical context/init parameter; ProjectStage.PROJECT_STAGE_JNDI_NAME. Mojarra defines an additional proprietary one: "java:comp/env/ClientStateSavingPassword".

Since:
1.6
Author:
Arjan Tijms

Method Summary
static
<T> T
getEnvEntry(java.lang.String name)
          Returns the named environment entry for the deployment component from where this is called.
static
<T> T
lookup(java.lang.String name)
          Returns the named object from the default JNDI instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEnvEntry

public static <T> T getEnvEntry(java.lang.String name)
Returns the named environment entry for the deployment component from where this is called. From within the web module this returns the <env-entry-value> of a <env-entry> in web.xml associated with the given <env-entry-name>.

Note that the name used here is relative to "java:comp/env", which is exactly as it appears in web.xml.

Example:

web.xml

 <env-entry>
        <cont>org.omnifaces.TEST_INTEGER</env-entry-name>
        <env-entry-type>java.lang.Integer</env-entry-type>
        <env-entry-value>10</env-entry-value>
 </env-entry>
 
Lookup in Java using relative name
 Integer test = JNDI.getEnvEntry("org.omnifaces.TEST_INTEGER");
 
Lookup in Java using full JNDI name
 Integer test = JNDI.lookup("java:comp/env/org.omnifaces.TEST_INTEGER");
 

Note that even the "full JNDI name" is relative to the "deployment component" from which the lookup is done. To use a true global JNDI name an additional <lookup-name> should be specified in web.xml.

Environment entries can also be injected using Resource.

Parameters:
name - the environment entry name relative to "java:comp/env".
Returns:
The environment entry value associated with the given name, or null if there is none.
Since:
1.6
See Also:
InitialContext.lookup(String)

lookup

public static <T> T lookup(java.lang.String name)
Returns the named object from the default JNDI instance.

Parameters:
name - the name of the object to be retrieved
Returns:
the named object, or null if there is none.
Since:
1.6
See Also:
InitialContext.lookup(String)