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

This page discusses - 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

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

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.

An enterprise bean instance locates the environment naming context using the JNDI interfaces. An instance creates a javax.naming.InitialContext object by using the constructor with NO arguments, and looks up the environment naming via the InitialContext under the name java:comp/env. The enterprise bean's ENVIRONMENT ENTRIES are stored directly in the environment naming context, or in any of its direct or indirect subcontexts.


public void setTaxInfo(int numberOfExemptions, ...)
	throws InvalidNumberOfExemptionsException {
	...
	// Obtain the enterprise bean's environment naming context.
	Context initCtx = new InitialContext();
	Context myEnv = (Context)initCtx.lookup("java:comp/env");

	// Obtain the maximum number of tax exemptions
	// configured by the Deployer.
	Integer max = (Integer)myEnv.lookup("maxExemptions");

	// Obtain the minimum number of tax exemptions
	// configured by the Deployer.
	Integer min = (Integer)myEnv.lookup("minExemptions");

	// Use the environment entries to customize business logic.
	if (numberOfExeptions > Integer.intValue(max) ||
		numberOfExemptions < Integer.intValue(min))
		throw new InvalidNumberOfExemptionsException();

	// Get some more environment entries. These environment
	// entries are stored in subcontexts.
	String val1 = (String)myEnv.lookup("foo/name1");
	Boolean val2 = (Boolean)myEnv.lookup("foo/bar/name2");

	// The enterprise bean can also lookup using full pathnames.
	Integer val3 = (Integer)
	initCtx.lookup("java:comp/env/name3");
	Integer val4 = (Integer)
	initCtx.lookup("java:comp/env/foo/name4");
	...
}

				

<session>
	...
	<ejb-name>EmployeeService</ejb-name>
	<ejb-class>com.wombat.empl.EmployeeServiceBean</ejb-class>
	...
	<env-entry>
		<description>
			The maximum number of tax exemptions
			allowed to be set.
		</description>
		<env-entry-name>maxExemptions</env-entry-name>
		<env-entry-type>java.lang.Integer</env-entry-type>
		<env-entry-value>15</env-entry-value>
	</env-entry>

	<env-entry>
		<description>
			The minimum number of tax exemptions
			allowed to be set.
		</description>
		<env-entry-name>minExemptions</env-entry-name>
		<env-entry-type>java.lang.Integer</env-entry-type>
		<env-entry-value>1</env-entry-value>
	</env-entry>

	<env-entry>
		<env-entry-name>foo/name1</env-entry-name>
		<env-entry-type>java.lang.String</env-entry-type>
		<env-entry-value>value1</env-entry-value>
	</env-entry>

	<env-entry>
		<env-entry-name>foo/bar/name2</env-entry-name>
		<env-entry-type>java.lang.Boolean</env-entry-type>
		<env-entry-value>true</env-entry-value>
	</env-entry>

	<env-entry>
		<description>Some description.</description>
		<env-entry-name>name3</env-entry-name>
		<env-entry-type>java.lang.Integer</env-entry-type>
	</env-entry>

	<env-entry>
		<env-entry-name>foo/name4</env-entry-name>
		<env-entry-type>java.lang.Integer</env-entry-type>
		<env-entry-value>10</env-entry-value>
	</env-entry>
	...
</session>

				

The following example illustrates how an enterprise bean uses an EJB REFERENCE to locate the remote home interface of another enterprise bean.

public class EmployeeServiceBean implements SessionBean {
	public void changePhoneNumber(...) {
		...

		// Obtain the default initial JNDI context.
		Context initCtx = new InitialContext();

		// Look up the home interface of the EmployeeRecord
		// enterprise bean in the environment.
		Object result = initCtx.lookup("java:comp/env/ejb/EmplRecord");

		// Convert the result to the proper type.
		EmployeeRecordHome emplRecordHome = (EmployeeRecordHome)
			javax.rmi.PortableRemoteObject.narrow(result,
			EmployeeRecordHome.class);

		...
	}
}
					

<session>
	...
	<ejb-name>EmployeeService</ejb-name>
	<ejb-class>com.wombat.empl.EmployeeServiceBean</ejb-class>
	...
	<ejb-ref>
		<description>
			This is a reference to the entity bean that
			encapsulates access to employee records.
		</description>
		<ejb-ref-name>ejb/EmplRecord</ejb-ref-name>
		<ejb-ref-type>Entity</ejb-ref-type>
		<home>com.wombat.empl.EmployeeRecordHome</home>
		<remote>com.wombat.empl.EmployeeRecord</remote>
	</ejb-ref>

	<ejb-ref>
		<ejb-ref-name>ejb/Payroll</ejb-ref-name>
		<ejb-ref-type>Entity</ejb-ref-type>
		<home>com.aardvark.payroll.PayrollHome</home>
		<remote>com.aardvark.payroll.Payroll</remote>
	</ejb-ref>

	<ejb-ref>
		<ejb-ref-name>ejb/PensionPlan</ejb-ref-name>
		<ejb-ref-type>Session</ejb-ref-type>
		<home>com.wombat.empl.PensionPlanHome</home>
		<remote>com.wombat.empl.PensionPlan</remote>
	</ejb-ref>
	...
</session>

					

The following illustrates an ejb-link in the deployment descriptor. The Application Assembler uses the ejb-link element to indicate that the EJB reference EmplRecord declared in the EmployeeService enterprise bean has been linked to the EmployeeRecord enterprise bean.


<session>
	...
	<ejb-name>EmployeeService</ejb-name>
	<ejb-class>com.wombat.empl.EmployeeServiceBean</ejb-class>
	...
	<ejb-ref>
		<ejb-ref-name>ejb/EmplRecord</ejb-ref-name>
		<ejb-ref-type>Entity</ejb-ref-type>
		<home>com.wombat.empl.EmployeeRecordHome</home>
		<remote>com.wombat.empl.EmployeeRecord</remote>
		<ejb-link>EmployeeRecord</ejb-link>
	</ejb-ref>
	...
</session>

...

<entity>
	<ejb-name>EmployeeRecord</ejb-name>
	<home>com.wombat.empl.EmployeeRecordHome</home>
	<remote>com.wombat.empl.EmployeeRecord</remote>
	...
</entity>

					

The following example illustrates using the ejb-link element to indicate an enterprise bean reference to the ProductEJB enterprise bean that is in the same J2EE application unit but in a different ejb-jar file:


<entity>
	...
	<ejb-name>OrderEJB</ejb-name>
	<ejb-class>com.wombat.orders.OrderBean</ejb-class>
	...
	<ejb-ref>
		<ejb-ref-name>ejb/Product</ejb-ref-name>
		<ejb-ref-type>Entity</ejb-ref-type>
		<home>com.acme.orders.ProductHome</home>
		<remote>com.acme.orders.Product</remote>
		<ejb-link>../products/product.jar#ProductEJB</ejb-link>
	</ejb-ref>
	...
</entity>

					

The following code sample illustrates obtaining a JDBC connection:

public class EmployeeServiceBean implements SessionBean {
	EJBContext ejbContext;

	public void changePhoneNumber(...) {
		...

		// obtain the initial JNDI context
		Context initCtx = new InitialContext();

		// perform JNDI lookup to obtain resource manager
		// connection factory
		javax.sql.DataSource ds = (javax.sql.DataSource)
			initCtx.lookup("java:comp/env/jdbc/EmployeeAppDB");

		// Invoke factory to obtain a connection. The security
		// principal is not given, and therefore
		// it will be configured by the Deployer.
		java.sql.Connection con = ds.getConnection();
		...
	}
}
					

The following example is the declaration of resource manager connection factory references used by the EmployeeService enterprise bean:


<enterprise-beans>
	<session>
		...
		<ejb-name>EmployeeService</ejb-name>
		<ejb-class>com.wombat.empl.EmployeeServiceBean</ejb-class>
		...
		<resource-ref>
			<description>
				A data source for the database in which
				the EmployeeService enterprise bean will
				record a log of all transactions.
			</description>
			<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>
		...
	</session>
</enterprise-beans>

					

The following example illustrates the declaration of the JMS resource manager connection factory references:


<enterprise-beans>
	<session>
		...
		<resource-ref>
			<description>
				A queue connection factory used by the
				MySession enterprise bean to send
				notifications.
			</description>
			<res-ref-name>jms/QueueConnFactory</res-ref-name>
			<res-type>javax.jms.QueueConnectionFactory</res-type>
			<res-auth>Container</res-auth>
			<res-sharing-scope>Unshareable</res-sharing-scope>
		</resource-ref>
		...
	</session>
</enterprise-beans>

					

The following example illustrates how an enterprise bean uses a RESOURCE ENVIRONMENT REFERENCE to locate a JMS Destination:

public class StockServiceBean implements SessionBean {
	public void processStockInfo(...) {
		...

		// Obtain the default initial JNDI context
		Context initCtx = new InitialContext();

		// Look up the JMS StockQueue in the environment.
		Object result = initCtx.lookup("java:comp/env/jms/StockQueue");

		// Convert the result to the proper type.
		javax.jms.Queue queue = (javax.jms.Queue)result;
	}
}
					
In the example, the Bean Provider of the StockServiceBean enterprise bean has ASSIGNED the environment entry jms/StockQueue as the RESOURCE ENVIRONMENT REFERENCE name to refer to a JMS queue.

The following example illustrates the declaration of RESOURCE ENVIRONMENT REFERENCES in the deployment descriptor:


...
<resource-env-ref>
	<description>
		This is a reference to a JMS queue used in the
		processing of Stock info
	</description>
	<resource-env-ref-name>jms/StockQueue</resource-env-ref-name>
	<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
...

					

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.