List of usage examples for javax.ejb SessionContext lookup
Object lookup(String name) throws IllegalArgumentException;
java:
namespace. From source file:org.jboss.ejb3.examples.ch05.encryption.EncryptionBean.java
/** * Obtains the environment entry with the specified name, casting to a String, * and returning the result. If the entry is not assignable * to a String, an {@link IllegalStateException} will be raised. In the event that the * specified environment entry cannot be found, a warning message will be logged * and we'll return null./*w ww . j a va 2 s . co m*/ * * @param envEntryName * @return * @throws IllegalStateException */ private String getEnvironmentEntryAsString(final String envEntryName) throws IllegalStateException { // See if we have a SessionContext final SessionContext context = this.context; if (context == null) { log.warning("No SessionContext, bypassing request to obtain environment entry: " + envEntryName); return null; } // Lookup in the Private JNDI ENC via the injected SessionContext Object lookupValue = null; try { lookupValue = context.lookup(envEntryName); log.fine("Obtained environment entry \"" + envEntryName + "\": " + lookupValue); } catch (final IllegalArgumentException iae) { // Not found defined within this EJB's Component Environment, // so return null and let the caller handle it log.warning("Could not find environment entry with name: " + envEntryName); return null; } // Cast String returnValue = null; try { returnValue = String.class.cast(lookupValue); } catch (final ClassCastException cce) { throw new IllegalStateException("The specified environment entry, " + lookupValue + ", was not able to be represented as a " + String.class.getName(), cce); } // Return return returnValue; }