What is the Enterprise Bean Environment?
- The enterprise bean environment is a mechanism that allows the enterprise bean’s business logic at the time of assembling it or deploying it.
- The environment provides to the beans to refer to a value, a resource or another component.
- The values that are described in the deployment descriptor are the actual values of the environment refers to the deployment time.
- This environment customizes the bean without accessing, changing the bean’s source code.
- The EJ environment is provided by the container to the bean through JNDI interface.
- Using JNDI the bean code access the environment.
Explain the EJB environment Entries.
EJB environment entries : - The most important role is being played by EJB environment entries to make the beans flexible.
- This topic is worthwhile even for the beginners. Within the EJB environment, it is possible to create the entries, called ‘named value entries’ of the type Byte, Short, Integer, Long, Float and String types.
- The bean deployer can use there references, to modify the business logic of the beans without altering the underlying code.
- This is a very powerful technique when properly used / utilized / applied.
- EJB environment entries are much like a constant variables whose scope is within a particular EJB.
- These are setup in the deployment descriptor, and can be overridden in the deployment plan.
Rules to use EJB Environment entries : 1. Deployment descriptor only must set up these references.
2. The values can overridden at deployment time, provided these values are set at assembly time.
3. The instances of that particular bean deployment only can access these environment entities.
4. At the time of deploying the bean for multiple times on the same server, the environment entries can also have the same name. But there are chances of risk.
5. At runtime, the values of the environment references can not be changed.
Explain the steps involved in accessing one enterprise bean from other.
- The accessibility of one EJB within another, there is a special mechanism is provided by the container.
- Using the logical names called ’EJB references’, this mechanism can be referred.
- These references should be defined in the deployment descriptor which is then used by the container in order to construct the EJB environment.
- The binding the EJB references is used in the EJB code to the homes of other EJB which is need to access is done by the deployment descriptor.
- A local interface should be used to implement the mechanism.
- The sequence of the steps for accessing one EJB from another are as follows :
1. Specifying a local reference for a bean.
2. The deployment descriptor elements for a local reference mirror exactly the elements for a remote reference.
3. Creating a local interface and accessing a bean through it.
- To specify the home interface and local interface , the following steps are to be followed.
1. Specifying the Home Interface : - import "javax.ejb.EJBLocalHome" rather than "javax.ejb.EJBHome", to create the home interface.
- The only exception that must be thrown by methods declared in this interface is:
javax.ejb.CreateException
2. Specifying the Local Interface : - import "javax.ejb.EJBLocalObject" rather than "javax.ejb.EJBObject".
3. Making the Call : - After creating local and home interfaces and specifying the deployment descriptor settings, the JNDI call to lookup to the references of the other EJB is the remaining process.
-
For example : - The following code snippet provides the call:
home = (ProductHome) initCtx.lookup("java:comp/env/ejb/Product");