Chapter 13. Enterprise Bean Environment

This page discusses - Chapter 13. Enterprise Bean Environment

Chapter 13. Enterprise Bean Environment

Chapter 13. Enterprise Bean Environment

Identify correct and incorrect statements or examples about an enterprise bean's environment JNDI API naming.

The enterprise bean's environment is a mechanism that allows customization of the enterprise bean's business logic during DEPLOYMENT or ASSEMBLY. The enterprise bean's environment allows the enterprise bean to be customized without the need to access or change the enterprise bean's source code.

The Container implements the enterprise bean's environment, and provides it to the enterprise bean instance through the JNDI interfaces. The enterprise bean's environment is used as follows:

  1. The enterprise bean's business methods access the environment using the JNDI interfaces. The Bean Provider DECLARES in the deployment descriptor all the environment entries that the enterprise bean expects to be provided in its environment at runtime.

  2. The Container provides an IMPLEMENTATION of the JNDI naming context that stores the enterprise bean environment. The Container also provides the tools that allow the Deployer to create and manage the environment of each enterprise bean.

  3. The Deployer uses the tools provided by the Container to create the environment entries that are declared in the enterprise bean's deployment descriptor. The Deployer can SET and MODIFY the values of the environment entries.

  4. The Container makes the environment naming context AVAILABLE to the enterprise bean instances at runtime. The enterprise bean's instances use the JNDI interfaces to obtain the values of the environment entries.

Each enterprise bean defines its OWN set of environment entries. All instances of an enterprise bean within the same home share the same environment entries; the environment entries are not shared with other enterprise beans. Enterprise bean instances are NOT ALLOWED to modify the bean's environment at runtime.

Each env-entry element describes a single environment entry. The env-entry element consists of an optional description of the environment entry, the environment entry NAME relative to the java:comp/env context, the expected Java TYPE of the environment entry value (i.e., the type of the object returned from the JNDI lookup method), and an OPTIONAL environment entry VALUE.


<!--
The env-entry element contains the declaration of an enterprise
bean's environment entry. The declaration consists of an optional
description, the name of the environment entry, and an optional value.
If a value is not specified, one must be supplied during deployment.
Used in: entity, message-driven, and session
-->

<!ELEMENT env-entry (description?, env-entry-name, env-entry-type,
		env-entry-value?)>

					

An environment entry is scoped to the enterprise bean whose declaration contains the env-entry element. This means that the environment entry is INACCESSIBLE from other enterprise beans at runtime, and that other enterprise beans may define env-entry elements with the same env-entry-name without causing a name conflict.

The environment entry values may be one of the following Java types: String, Character, Integer, Boolean, Double, Byte, Short, Long, and Float.

The environment entry value must be a string that is valid for the constructor of the specified type that takes a single String parameter, or for java.lang.Character, a single character.

The ejb-ref element contains an optional description element; and the MANDATORY ejb-ref-name, ejb-ref-type (value must be either Entity or Session), home, and remote elements.


<!--
The ejb-ref element is used for the declaration of a reference to an
enterprise bean's home. The declaration consists of an optional
description; the EJB reference name used in the code of the enterprise
bean that is referencing the enterprise bean; the expected type of the
referenced enterprise bean; the expected home and remote interfaces
of the referenced enterprise bean; and optional ejb-link information,
used to specify the referenced enterprise bean.
Used in: entity, message-driven, and session
-->

<!ELEMENT ejb-ref (description?, ejb-ref-name, ejb-ref-type, home,
		remote, ejb-link?)>

					

The ejb-local-ref element contains an optional description element; and the MANDATORY ejb-ref-name, ejb-ref-type (value must be either Entity or Session), local-home, and local elements.


<!--
The ejb-local-ref element is used for the declaration of a reference
to an enterprise bean's local home. The declaration consists of an
optional description; the EJB reference name used in the code of the
enterprise bean that is referencing the enterprise bean; the expected
type of the referenced enterprise bean; the expected local home and
local interfaces of the referenced enterprise bean; and optional
ejb-link information, used to specify the referenced enterprise bean.
Used in: entity, session, message-driven
-->

<!ELEMENT ejb-local-ref (description?, ejb-ref-name, ejb-ref-type,
		local-home, local, ejb-link?)>

					

The ejb-ref-name element specifies the EJB reference name; its value is the environment entry name used in the enterprise bean CODE.

An EJB REFERENCE is scoped to the enterprise bean whose declaration contains the ejb-ref or ejb-local-ref element. This means that the EJB reference is NOT ACCESSIBLE to other enterprise beans at runtime, and that other enterprise beans may define ejb-ref and/or ejb-local-ref elements with the same ejb-ref-name without causing a name conflict.

A RESOURCE MANAGER CONNECTION FACTORY is an object that is used to create connections to a resource manager. For example, an object that implements the javax.sql.DataSource interface is a resource manager connection factory for java.sql.Connection objects which implement connections to a database management system.

Each resource-ref element describes a single resource manager connection factory reference. The resource-ref element consists of the description element; the THREE mandatory res-ref-name, res-type, and res-auth elements; and the optional res-sharing-scope element. The res-ref-name element contains the name of the environment entry used in the enterprise bean's CODE. The name of the environment entry is relative to the java:comp/env context (e.g., the name should be jdbc/EmployeeAppDB rather than java:comp/env/jdbc/EmployeeAppDB). The res-type element contains the Java type of the resource manager connection FACTORY. The res-auth element indicates whether the enterprise BEAN CODE performs resource manager sign-on PROGRAMMATICALLY, or whether the Container signs on to the resource manager using the principal mapping information supplied by the Deployer. The Bean Provider indicates the sign-on responsibility by setting the value of the res-auth element to Application or Container. The res-sharing-scope element indicates whether connections to the resource manager obtained through the given resource manager connection factory reference can be shared (by default) or whether connections are unshareable.

A resource manager connection factory reference is scoped to the enterprise bean whose declaration contains the resource-ref element. This means that the resource manager connection factory reference is not accessible from other enterprise beans at runtime, and that other enterprise beans may define resource-ref elements with the same res-ref-name without causing a name conflict.


<!--
The resource-ref element contains a declaration of enterprise bean's
reference to an external resource. It consists of an optional description,
the resource manager connection factory reference name, the
indication of the resource manager connection factory type expected
by the enterprise bean code, the type of authentication (Application
or Container), and an optional specification of the shareability of
connections obtained from the resource (Shareable or Unshareable).
Used in: entity, message-driven, and session

Example:

<resource-ref>
	<res-ref-name>jdbc/EmployeeAppDB</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
	<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
-->

<!ELEMENT resource-ref (description?, res-ref-name, res-type,
		res-auth, res-sharing-scope?)>

					

The Bean Provider is allowed to refer to administered objects that are associated with resources (for example, JMS Destinations) by using "logical" names called RESOURCE ENVIRONMENT REFERENCES. Resource environment references are special entries in the enterprise bean's environment.

Each resource-env-ref element describes the requirements that the referencing enterprise bean has for the referenced administered object. The resource-env-ref element contains an optional description element; and the MANDATORY resource-env-ref-name and resource-env-ref-type elements.

The resource-env-ref-name element specifies the resource environment reference name; its value is the environment entry name used in the enterprise bean CODE. The name of the environment entry is relative to the java:comp/env context (e.g., the name should be jms/StockQueue rather than java:comp/env/jms/StockQueue). The resource-env-ref-type element specifies the expected type of the referenced object. For example, in the case of a JMS Destination, its value must be either javax.jms.Queue or javax.jms.Topic.


<!--
The resource-env-ref element contains a declaration of an enterprise
bean's reference to an administered object associated with a resource
in the enterprise bean's environment. It consists of an optional
description, the resource environment reference name, and an indication
of the resource environment reference type expected by the enterprise
bean code.
Used in: entity, message-driven and session

Examples:

<resource-env-ref>
	<resource-env-ref-name>jms/StockQueue</resource-env-ref-name>
	<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>

-->
<!ELEMENT resource-env-ref (description?, resource-env-ref-name,
		resource-env-ref-type)>

					

Visit http://java.boot.by  for the updates.

    

Prev Up Next
Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation.  Home Identify correct and incorrect statements about the purpose and use of the deployment descriptor elements for environment entries, EJB references, and resource manager connection factory references; including whether a given code listing is appropriate and correct with respect to a particular deployment descriptor element.

Tutorials

  1. Appendix A. First Appendix
  2. Second Section
  3. Third Section
  4. Part II. Appendixes
  5. From a list, identify the responsibility of the bean provider and the responsibility of the container provider for a message-driven bean.
  6. Chapter 6. Component Contract for Container-Managed Persistence (CMP)
  7. Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean.
  8. Identify the interfaces and methods a CMP entity bean must and must not implement.
  9. Match the name with a description of purpose or functionality, for each of the following deployment descriptor elements: ejb-name, abstract-schema-name, ejb-relation, ejb-relat
  10. Identify correctly-implemented deployment descriptor elements for a CMP bean (including container-managed relationships).
  11. From a list, identify the purpose, behavior, and responsibilities of the bean provider for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbC
  12. Chapter 7. CMP Entity Bean Life Cycle
  13. Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean.
  14. From a list, identify the responsibility of the container for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbCreate, ejbPostCreate, ejbActi
  15. Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's security context.
  16. Chapter 10. Message-Driven Bean Component Contract
  17. Identify correct and incorrect statements about the purpose and use of the deployment descriptor elements for environment entries, EJB references, and resource manager connection factory r
  18. Identify the use and the behavior of the ejbPassivate method in a session bean, including the responsibilities of both the container and the bean provider.
  19. Chapter 12. Exceptions
  20. Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject).
  21. Identify EJB 2.0 container requirements.
  22. Chapter 1. EJB Overview
  23. Identify correct and incorrect statements or examples about EJB programming restrictions.
  24. Chapter 9. EJB-QL
  25. Identify correct and incorrect statements or examples about the purpose and use of EJB QL.
  26. Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions.
  27. Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject).
  28. Given a list, identify which are requirements for an EJB-jar file.
  29. Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information.
  30. Chapter 2. Client View of a Session Bean
  31. Chapter 13. Enterprise Bean Environment
  32. Chapter 8. Entity Beans
  33. Identify the use, syntax, and behavior of, the following entity bean home method types, for Container-Managed Persistence (CMP); finder methods, create methods, remove methods, and home me
  34. Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.
  35. Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation.
  36. Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans.
  37. Given a particular method condition, identify the following: whether an exception will be thrown, the type of exception thrown, the container's action, and the client's view.
  38. Given a list of responsibilities related to exceptions, identify those which are the bean provider's, and those which are the responsibility of the container provider. Be prepared to recog
  39. SCBCD Study Guide
  40. Identify the use and behavior of the MessageDrivenContext interface methods.