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

Ads

Tutorials   
Chapter 5. Client View of an Entity Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements related to transactions and the identifica Given a list of responsibilities, identify whose which are the Container's with respect to transactions, including the handling of getRollbackOnly, setRollbackOnly, getUserTransacti EJB Transactional Attributes Chapter 11. Transactions Given a list of scenarios, identify which will result in an ejbRemove method not being called on a bean instance. Given a list of responsibilities related to session beans, identify those which are the responsibility of the session bean provider and those which are the responsibility of the EJB contai Given a list of methods for a stateful or stateless session bean class, define which of the following operations can be performed from each of those methods: SessionContext interface metho Chapter 4. Session Bean Life Cycle Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces. Identify the interface and method for each of the following: retrieve the session bean's remote home interface, retrieve the session bean's local component interface, determine if the sessio Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both. Chapter 14. Security Management Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag. Given a list of responsibilities, identify which belong to the deployer, bean provider, application assembler, container provider, system administrator, or any combination. From a list of responsibilities, identify which belong to the application assembler, bean provider, deployer, container provider, or system administrator. Part I. Exam Objectives Preface Identify the interfaces and methods a JMS message-driven bean must implement. Identify the use and behavior of the MessageDrivenContext interface methods. SCBCD Study Guide 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 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. Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans. Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation. Identify correct and incorrect statements or examples about an entity bean's primary key and object identity. 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 Chapter 8. Entity Beans Chapter 13. Enterprise Bean Environment Chapter 2. Client View of a Session Bean Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information. Given a list, identify which are requirements for an EJB-jar file. Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject). Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions. Identify correct and incorrect statements or examples about the purpose and use of EJB QL. Chapter 9. EJB-QL Identify correct and incorrect statements or examples about EJB programming restrictions. Chapter 1. EJB Overview Identify EJB 2.0 container requirements. Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject). Chapter 12. Exceptions 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. 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 Chapter 10. Message-Driven Bean Component Contract Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's security context. From a list, identify the responsibility of the container for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbCreate, ejbPostCreate, ejbActi Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean. Chapter 7. CMP Entity Bean Life Cycle 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 Identify correctly-implemented deployment descriptor elements for a CMP bean (including container-managed relationships).
Ads

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>
...

					

Advertisements

Ads
Share on Google+Share on Google+

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

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 
Comments:0

Ads

 

Ads