O'Reilly logo

Enterprise JavaBeans, Second Edition by Richard Monson-Haefel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Default JNDI Context

Environment variables have undergone a fairly [a-z]adical change. Environment properties in EJB 1.0 are a powerful mechanism for modifying the behavior of a component without changing the component’s code. In EJB 1.0, the environment properties are accessible to the bean through the EJBContext.getEnvironment() method, are set by the bean developer, and can be modified by the deployer. In EJB 1.0, the environment variables might, for example, be used to set a maximum withdraw amount for an account bean, as in the following code:

// EJB 1.0
public class AccountBean implements javax.ejb.EntityBean {

    public EntityContext context;

    public void withdraw(double amount) throws MaximumLimitException {
        try {
            Properties environment = context.getEnvironment();
            String value = environment.getProperty("withdraw_limit");
            Double limit = new Double(value);
            if ( amount > limit.doubleValue()) {
                throw new MaximumLimitException();
            else {
                 // continue processing
            }
        }
    }
}

EJB 1.1 changes the environment properties from the java.util.Properties class, used in EJB 1.0, to a set of JNDI entries that exist in a name space called the environment naming context. All deployed beans in EJB 1.1 have an environment naming context (default JNDI context) that can be accessed using the JNDI API. This default JNDI context provides a set of immutable JNDI entries specific to each type of bean. The default JNDI context provides the bean with access to environment variables which can be of type String ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required