Scbcd Study Guide

981
SCBCD Study Guide SCBCD Study Guide Next SCBCD Study Guide IBA JV Mikalai Zaikin <NZaikin[at]iba.by> Copyright © 2004 Mikalai Zaikin Redistribution of this document is permitted as long as it is not used for profits. March 2004 Revision History Revision 2.4 31 Mar 2004 MZ Proposed Final Draft 3. Revision 2.3 22 Dec 2003 MZ Proposed Final Draft 2. Revision 2.2 19 Dec 2003 MZ Proposed Final Draft 1. Revision 2.1 7 Dec 2003 MZ Chap 1.4, 13 updates. Revision 2.0 4 Dec 2003 MZ Chap 14 updates. Revision 1.9 3 Dec 2003 MZ Chap 14.2, 14.3 updates. Abstract The purpose of this document is to help in preparation for exam CX-310-090 (Sun Certified Business Component Developer for the Java 2 Platform, Enterprise Edition 1.3). http://java.boot.by/bcd-guide/ 第 1 頁 / 共 6 2004/6/12 下午 11:55:46

Transcript of Scbcd Study Guide

SCBCD Study Guide

SCBCD Study Guide Next

SCBCD Study GuideIBA JV Mikalai Zaikin

Copyright 2004 Mikalai Zaikin Redistribution of this document is permitted as long as it is not used for profits. March 2004Revision History Revision 2.4 Proposed Final Draft 3. Revision 2.3 Proposed Final Draft 2. Revision 2.2 Proposed Final Draft 1. Revision 2.1 Chap 1.4, 13 updates. Revision 2.0 Chap 14 updates. Revision 1.9 Chap 14.2, 14.3 updates. 3 Dec 2003 MZ 4 Dec 2003 MZ 7 Dec 2003 MZ 19 Dec 2003 MZ 22 Dec 2003 MZ 31 Mar 2004 MZ

Abstract The purpose of this document is to help in preparation for exam CX-310-090 (Sun Certified Business Component Developer for the Java 2 Platform, Enterprise Edition 1.3).

http://java.boot.by/bcd-guide/ 1 / 6 2004/6/12 11:55:46

SCBCD Study Guide

This document should not be used as the only study material for SCBDC test. It covers all objective topics, but it is not enough. I tried to make this document as much accurate as possible, but if you find any error, please let me know.

Table of Contents Foreword Preface I. Exam Objectives 1. EJB Overview Identify the use, benefits, and characteristics of Enterprise JavaBeans technology, for version 2.0 of the EJB specification. Identify EJB 2.0 container requirements. Identify correct and incorrect statements or examples about EJB programming restrictions. 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. 2. Client View of a Session Bean Identify correct and incorrect statements or examples about the client view of a session bean's local and remote home interfaces, including the code used by a client to locate a session bean's home interface. Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces. 3. Session Bean Component Contract Identify correct and incorrect statements or examples about session beans, including conversational state, the SessionBean interface, and create methods. 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 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 session bean's caller has a particular role, allow the instance to mark the current transaction as a rollback, retrieve the UserTransaction interface, prepare the instance for reuse following passivation, release resources prior to removal, identify the invoker of the bean instance's component interface, be notified that a new transaction has begun, and be notified that the current transaction has completed. Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both. 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 container provider.http://java.boot.by/bcd-guide/ 2 / 6 2004/6/12 11:55:46

SCBCD Study Guide

4.

5.

6.

7.

Given a list of requirements, identify those which are the requirements for a session bean class, a remote component interface, a remote home interface, create methods, business methods, a local component interface, and a local home interface. Session Bean Life Cycle Identify correct and incorrect statements or examples about the life cycle of a stateful or stateless session bean instance. 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 methods, UserTransaction methods, Java Naming and Directory Interface API (JNDI API) access to java:comp/env environment naming context, resource manager access, and other enterprise bean access. Given a list of scenarios, identify which will result in an ejbRemove method not being called on a bean instance. Client View of an Entity Identify correct and incorrect statements or examples about the client of an entity bean's local and remote home interface, including viewing the code used to locate an entity bean's home interface and the home interface methods provided to the client. Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject). Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject). 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 methods. Component Contract for Container-Managed Persistence (CMP) Identify correct and incorrect statements or examples about the entity bean provider's view and programming contract for CMP, including the requirements for a CMP entity bean. Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean. Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean. Match the name with a description of purpose or functionality, for each of the following deployment descriptor elements: ejb-name, abstract-schema-name, ejbrelation, ejb-relationship-role, cmr-field, cmr-field-type, and relationship-rolesource. Identify correctly-implemented deployment descriptor elements for a CMP bean (including container-managed relationships). Identify the interfaces and methods a CMP entity bean must and must not implement. CMP Entity Bean Life Cycle

http://java.boot.by/bcd-guide/ 3 / 6 2004/6/12 11:55:46

SCBCD Study Guide

Identify correct and incorrect statements or examples about the life cycle of a CMP entity bean. 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, ejbCreate, ejbPostCreate, ejbActivate, ejbPassivate, ejbRemove, ejbLoad, ejbStore, ejbFind, ejbHome, and ejbSelect. From a list, identify the responsibility of the container for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbCreate, ejbPostCreate, ejbActivate, ejbPassivate, ejbRemove, ejbLoad, ejbStore, ejbFind, ejbHome, and ejbSelect. 8. Entity Beans From a list of behaviors, match them with the appropriate EntityContext method responsible for that behavior. Identify correct and incorrect statements or examples about an entity bean's primary key and object identity. 9. EJB-QL Identify correct and incorrect syntax for an EJB QL query including the SELECT, FROM, and WHERE clauses. Identify correct and incorrect statements or examples about the purpose and use of EJB QL. Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions. 10. Message-Driven Bean Component Contract Identify correct and incorrect statements or examples about the client view of a message-driven bean, and the life cycle of a message-driven bean. Identify the interfaces and methods a JMS message-driven bean must implement. Identify the use and behavior of the MessageDrivenContext interface methods. From a list, identify the responsibility of the bean provider and the responsibility of the container provider for a message-driven bean. 11. Transactions Identify correct and incorrect statements or examples about EJB transactions, including bean-managed transaction demarcation and container-managed transaction demarcation. Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements related to transactions and the identification of the methods of a particular bean type for which a transaction attribute must be specified. Given a list of transaction behaviors, match them with the appropriate transaction attributes. Given a list of responsibilities, identify whose which are the Container's with respect to transactions, including the handling of getRollbackOnly, setRollbackOnly, getUserTransaction, SessionSynchronzation callbacks, for both container and bean-managed transactions. 12. Exceptions

http://java.boot.by/bcd-guide/ 4 / 6 2004/6/12 11:55:46

SCBCD Study Guide

Identify correct and incorrect statements or examples about exception handling in EJB. 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 recognize responsibilities for which neither the bean provider or the container provider are responsible. Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans. 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 the client's view of exceptions received from an enterprise bean invocation. 13. Enterprise Bean Environment Identify correct and incorrect statements or examples about an enterprise bean's environment JNDI API naming. 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. Given a list of responsibilities, identify which belong to the deployer, bean provider, application assembler, container provider, system administrator, or any combination. 14. Security Management Identify correct and incorrect statements about the EJB support for security management including security roles, security role references, and method permissions. From a list of responsibilities, identify which belong to the application assembler, bean provider, deployer, container provider, or system administrator. Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's security context. Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag. II. Appendixes A. First Appendix First Section Second Section Third Section Bibliography

Next Forewordhttp://java.boot.by/bcd-guide/ 5 / 6 2004/6/12 11:55:46

SCBCD Study Guide

http://java.boot.by/bcd-guide/ 6 / 6 2004/6/12 11:55:46

Foreword

Foreword Prev Next

ForewordA preface.

Prev SCBCD Study Guide

Up Home

Next Preface

http://java.boot.by/bcd-guide/pr01.html2004/6/12 11:55:49

SCBCD Study Guide

SCBCD Study Guide Next

SCBCD Study GuideIBA JV Mikalai Zaikin

Copyright 2004 Mikalai Zaikin Redistribution of this document is permitted as long as it is not used for profits. March 2004Revision History Revision 2.4 Proposed Final Draft 3. Revision 2.3 Proposed Final Draft 2. Revision 2.2 Proposed Final Draft 1. Revision 2.1 Chap 1.4, 13 updates. Revision 2.0 Chap 14 updates. Revision 1.9 Chap 14.2, 14.3 updates. 3 Dec 2003 MZ 4 Dec 2003 MZ 7 Dec 2003 MZ 19 Dec 2003 MZ 22 Dec 2003 MZ 31 Mar 2004 MZ

Abstract The purpose of this document is to help in preparation for exam CX-310-090 (Sun Certified Business Component Developer for the Java 2 Platform, Enterprise Edition 1.3).

http://java.boot.by/bcd-guide/index.html 1 / 6 2004/6/12 11:55:51

SCBCD Study Guide

This document should not be used as the only study material for SCBDC test. It covers all objective topics, but it is not enough. I tried to make this document as much accurate as possible, but if you find any error, please let me know.

Table of Contents Foreword Preface I. Exam Objectives 1. EJB Overview Identify the use, benefits, and characteristics of Enterprise JavaBeans technology, for version 2.0 of the EJB specification. Identify EJB 2.0 container requirements. Identify correct and incorrect statements or examples about EJB programming restrictions. 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. 2. Client View of a Session Bean Identify correct and incorrect statements or examples about the client view of a session bean's local and remote home interfaces, including the code used by a client to locate a session bean's home interface. Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces. 3. Session Bean Component Contract Identify correct and incorrect statements or examples about session beans, including conversational state, the SessionBean interface, and create methods. 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 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 session bean's caller has a particular role, allow the instance to mark the current transaction as a rollback, retrieve the UserTransaction interface, prepare the instance for reuse following passivation, release resources prior to removal, identify the invoker of the bean instance's component interface, be notified that a new transaction has begun, and be notified that the current transaction has completed. Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both. 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 container provider.http://java.boot.by/bcd-guide/index.html 2 / 6 2004/6/12 11:55:51

SCBCD Study Guide

4.

5.

6.

7.

Given a list of requirements, identify those which are the requirements for a session bean class, a remote component interface, a remote home interface, create methods, business methods, a local component interface, and a local home interface. Session Bean Life Cycle Identify correct and incorrect statements or examples about the life cycle of a stateful or stateless session bean instance. 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 methods, UserTransaction methods, Java Naming and Directory Interface API (JNDI API) access to java:comp/env environment naming context, resource manager access, and other enterprise bean access. Given a list of scenarios, identify which will result in an ejbRemove method not being called on a bean instance. Client View of an Entity Identify correct and incorrect statements or examples about the client of an entity bean's local and remote home interface, including viewing the code used to locate an entity bean's home interface and the home interface methods provided to the client. Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject). Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject). 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 methods. Component Contract for Container-Managed Persistence (CMP) Identify correct and incorrect statements or examples about the entity bean provider's view and programming contract for CMP, including the requirements for a CMP entity bean. Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean. Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean. Match the name with a description of purpose or functionality, for each of the following deployment descriptor elements: ejb-name, abstract-schema-name, ejbrelation, ejb-relationship-role, cmr-field, cmr-field-type, and relationship-rolesource. Identify correctly-implemented deployment descriptor elements for a CMP bean (including container-managed relationships). Identify the interfaces and methods a CMP entity bean must and must not implement. CMP Entity Bean Life Cycle

http://java.boot.by/bcd-guide/index.html 3 / 6 2004/6/12 11:55:51

SCBCD Study Guide

Identify correct and incorrect statements or examples about the life cycle of a CMP entity bean. 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, ejbCreate, ejbPostCreate, ejbActivate, ejbPassivate, ejbRemove, ejbLoad, ejbStore, ejbFind, ejbHome, and ejbSelect. From a list, identify the responsibility of the container for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbCreate, ejbPostCreate, ejbActivate, ejbPassivate, ejbRemove, ejbLoad, ejbStore, ejbFind, ejbHome, and ejbSelect. 8. Entity Beans From a list of behaviors, match them with the appropriate EntityContext method responsible for that behavior. Identify correct and incorrect statements or examples about an entity bean's primary key and object identity. 9. EJB-QL Identify correct and incorrect syntax for an EJB QL query including the SELECT, FROM, and WHERE clauses. Identify correct and incorrect statements or examples about the purpose and use of EJB QL. Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions. 10. Message-Driven Bean Component Contract Identify correct and incorrect statements or examples about the client view of a message-driven bean, and the life cycle of a message-driven bean. Identify the interfaces and methods a JMS message-driven bean must implement. Identify the use and behavior of the MessageDrivenContext interface methods. From a list, identify the responsibility of the bean provider and the responsibility of the container provider for a message-driven bean. 11. Transactions Identify correct and incorrect statements or examples about EJB transactions, including bean-managed transaction demarcation and container-managed transaction demarcation. Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements related to transactions and the identification of the methods of a particular bean type for which a transaction attribute must be specified. Given a list of transaction behaviors, match them with the appropriate transaction attributes. Given a list of responsibilities, identify whose which are the Container's with respect to transactions, including the handling of getRollbackOnly, setRollbackOnly, getUserTransaction, SessionSynchronzation callbacks, for both container and bean-managed transactions. 12. Exceptions

http://java.boot.by/bcd-guide/index.html 4 / 6 2004/6/12 11:55:51

SCBCD Study Guide

Identify correct and incorrect statements or examples about exception handling in EJB. 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 recognize responsibilities for which neither the bean provider or the container provider are responsible. Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans. 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 the client's view of exceptions received from an enterprise bean invocation. 13. Enterprise Bean Environment Identify correct and incorrect statements or examples about an enterprise bean's environment JNDI API naming. 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. Given a list of responsibilities, identify which belong to the deployer, bean provider, application assembler, container provider, system administrator, or any combination. 14. Security Management Identify correct and incorrect statements about the EJB support for security management including security roles, security role references, and method permissions. From a list of responsibilities, identify which belong to the application assembler, bean provider, deployer, container provider, or system administrator. Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's security context. Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag. II. Appendixes A. First Appendix First Section Second Section Third Section Bibliography

Next Forewordhttp://java.boot.by/bcd-guide/index.html 5 / 6 2004/6/12 11:55:51

SCBCD Study Guide

http://java.boot.by/bcd-guide/index.html 6 / 6 2004/6/12 11:55:51

Preface

Preface Prev Next

PrefaceThis document is available in 2 formats: single page and chunked pages If you would like to have PDF (printable eBook for Adobe Acrobat Reader) version or CHM (single file copy of web-site to browse offline) version of SCBCD Study Guide, please, contact me.

Prev Foreword

Up Home

Next Part I. Exam Objectives

http://java.boot.by/bcd-guide/pr02.html2004/6/12 11:55:54

Part I. Exam Objectives

Part I. Exam Objectives Prev Next

Exam ObjectivesPrev Preface Up Home Next Chapter 1. EJB Overview

http://java.boot.by/bcd-guide/pt01.html2004/6/12 11:55:56

Chapter 1. EJB Overview

Chapter 1. EJB Overview Prev Part I. Exam Objectives Next

Chapter 1. EJB Overview

Identify the use, benefits, and characteristics of Enterprise JavaBeans technology, for version 2.0 of the EJB specification.Characteristics Enterprise JavaBeans architecture is the standard component architecture for building distributed object-oriented business applications. Enterprise JavaBeans architecture makes it possible to build distributed applications by combining components developed using tools from different vendors. Application developers do not have to understand low-level transaction and state management details, multi-threading, connection pooling, and other complex low-level APIs. Enterprise JavaBeans applications follow the Write Once, Run Anywhere philosophy of the Java programming language. The Enterprise JavaBeans architecture addresses the development, deployment, and runtime aspects of an enterprise applications life cycle. Enterprise JavaBeans architecture defines the contracts that enable tools from multiple vendors to develop and deploy components Enterprise JavaBeans architecture is compatible with the CORBA protocols. This allows remote invocations on session and entity beans from J2EE components that are deployed in products from different vendors. Benefits Defines the integration of EJB with the Java Message Service. Introduces message-driven beans (MDB) - a stateless components that are invoked by the container as a result of the arrival of a JMS message (MDB does not have home/home-local or remote/local interfaces). Provides a local client view and support for efficient, lightweight access to enterprise beans from local clients. Provides improved support for the persistence of entity beans.http://java.boot.by/bcd-guide/ch01.html 1 / 2 2004/6/12 11:55:58

Chapter 1. EJB Overview

Provides improved support for the management of relationships among entity beans (Local CMP Beans only). Provides a query syntax (EJB QL) for entity bean finder and select methods (CMP only). Provides support for additional methods in the home interface (business logic methods via ejbHome().

Prev Part I. Exam Objectives

Up Home

Next Identify EJB 2.0 container requirements.

http://java.boot.by/bcd-guide/ch01.html 2 / 2 2004/6/12 11:55:58

Identify EJB 2.0 container requirements.

Identify EJB 2.0 container requirements. Prev Chapter 1. EJB Overview Next

Identify EJB 2.0 container requirements.The EJB Provider can rely on the EJB 2.0 Container Provider to provide the following APIs:

Java 2 Platform, Standard Edition, v1.3 (J2SE) APIs EJB 2.0 Standard Extension JDBC 2.0 Standard Extension (support for row sets only) JNDI 1.2 Standard Extension JTA 1.0.1 Standard Extension (the UserTransaction interface only) JMS 1.0.2 Standard Extension JavaMail 1.1 Standard Extension (for sending mail only) JAXP 1.0

Prev Chapter 1. EJB Overview

Up Home

Next Identify correct and incorrect statements or examples about EJB programming restrictions.

http://java.boot.by/bcd-guide/ch01s02.html2004/6/12 11:56:00

Identify correct and incorrect statements or examples about EJB programming restrictions.

Identify correct and incorrect statements or examples about EJB programming restrictions. Prev Chapter 1. EJB Overview Next

Identify correct and incorrect statements or examples about EJB programming restrictions.An enterprise Bean must not use read/write static fields. Using read-only ( final) static fields is allowed. An enterprise Bean must not use thread synchronization primitives to synchronize execution of multiple instances. An enterprise Bean must not use the AWT functionality to attempt to output information to a display, or to input information from a keyboard. An enterprise bean must not use the java.io package to attempt to access files and directories in the file system. An enterprise bean must not attempt to listen on a socket, accept connections on a socket, or use a socket for multicast. Enterprise bean instance is allowed be a network socket client. The enterprise bean must not attempt to use the Reflection API to access information that the security rules of the Java programming language make unavailable. The enterprise bean must not attempt to create a class loader; obtain the current class loader; set the context class loader; set security manager; create a new security manager; stop the JVM; or change the input, output, and error streams. The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread; or to change a threads priority or name. The enterprise bean must not attempt to directly read or write a file descriptor. The enterprise bean must not attempt to obtain the security policy information for a particular code source. The enterprise bean must not attempt to load a native library. The enterprise bean must not attempt to gain access to packages and classes that the usual rules of the Java programming language make unavailable to the enterprise bean. The enterprise bean must not attempt to define a class in a package.

http://java.boot.by/bcd-guide/ch01s03.html 1 / 2 2004/6/12 11:56:02

Identify correct and incorrect statements or examples about EJB programming restrictions.

The enterprise bean must not attempt to pass this as an argument or method result. The enterprise bean must pass the result of SessionContext.getEJBObject(), SessionContext. getEJBLocalObject(), EntityContext.getEJBObject(), or EntityContext.getEJBLocalObject() instead.

Prev Identify EJB 2.0 container requirements.

Up Home

Next Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information.

http://java.boot.by/bcd-guide/ch01s03.html 2 / 2 2004/6/12 11:56:02

Match EJB roles with the corresponding description of the role's resp...where the description may include deployment descriptor information.

Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information. Prev Chapter 1. EJB Overview Next

Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information.There are 6 roles defined : Bean Provider The Bean Provider is the producer of enterprise beans. His or her output is an ejb-jar file that contains one or more enterprise beans. The Bean Provider is responsible for the Java classes that implement the enterprise bean's business methods; the definition of the bean's home and component interfaces; and the bean's deployment descriptor. The deployment descriptor (DD) includes the STRUCTURAL information (e.g. the name of the enterprise bean class) of the enterprise bean and declares all the enterprise bean's external dependencies (e.g. the names and types of resources that the enterprise bean uses). Bean Provider is responsible for packaging the enterprise beans in an ejb-jar file. The deployment descriptor must include the structural information. Structural information describes the structure of an enterprise bean and declares an enterprise bean's external dependencies. The structural information cannot be changed because doing so could break the enterprise bean's function. MUST USE the enterprise-beans element to list all the enterprise beans in the ejb-jar file. Application Assembler The Application Assembler combines enterprise beans into larger deployable application units. The input to the Application Assembler is one or more ejb-jar files produced by the Bean Provider. The Application Assembler outputs one or more ejb-jar files that contain the enterprise beans along with their application assembly instructions. The Application Assembler inserts the application assembly instructions into the deployment descriptors. The deployment descriptor must include the application assembly information. Application assembly information describes how the enterprise bean (or beans) in the ejb-jar file is composed into a larger application deployment unit. Assembly level information can be changed without breaking the enterprise bean's function, although doing so may alter the behavior of an assembled application. Deployer

http://java.boot.by/bcd-guide/ch01s04.html 1 / 3 2004/6/12 11:56:05

Match EJB roles with the corresponding description of the role's resp...where the description may include deployment descriptor information.

The Deployer takes one or more ejb-jar files produced by a Bean Provider or Application Assembler and deploys the enterprise beans contained in the ejb-jar files in a specific operational environment. The operational environment includes a specific EJB Server and Container. The Deployer must resolve all the external dependencies declared by the Bean Provider (e.g. the Deployer must ensure that all resource manager connection factories used by the enterprise beans are present in the operational environment, and he or she must bind them to the resource manager connection factory references declared in the deployment descriptor), and must follow the application assembly instructions defined by the Application Assembler. To perform his or her role, the Deployer uses tools provided by the EJB Container Provider. Uses the deployment tools provided by the EJB Container provider to deploy ejb-jar files produced by the Bean Providers and Application Assemblers. EJB Server Provider The EJB server provider is a specialist in the area of distributed transaction management, distributed objects, and other lower-level system services. A typical EJB server provider is an operating system vendor, middleware vendor, or database vendor. The job of the server provider is to provide a runtime EJB server environment that is compliant with the EJB specification. IBM is a server provider of the WebSphere Application Server. EJB Container Provider From the perspective of the enterprise beans, the Container is a part of the target operational environment. The Container runtime provides the deployed enterprise beans with transaction and security management, network distribution of remote clients, scalable management of resources, and other services that are generally required as part of a manageable server platform. Responsible for providing the DEPLOYMENT TOOLS used by the Deployer to deploy enterprise beans packaged in the ejb-jar file. Responsible for providing all the runtime services for the deployed enterprise bean instances. The focus of a Container Provider is on the development of a scalable, secure, transactionenabled container that is integrated with an EJB Server. The Container Provider insulates the enterprise Bean from the specifics of an underlying EJB Server by providing a simple, standard API between the enterprise Bean and the container. This API is the Enterprise JavaBeans component contract. The Container Provider also manages the persistence issues for its entity beans that use container-managed persistence (CMP). The Container Provider's tools generate code that moves data between the enterprise bean's container-managed fields and a database or an existing application. This code generation typically takes place at deployment time (vendor-specific).

http://java.boot.by/bcd-guide/ch01s04.html 2 / 3 2004/6/12 11:56:05

Match EJB roles with the corresponding description of the role's resp...where the description may include deployment descriptor information.

System Administrator The System Administrator is responsible for the configuration and administration of the enterprise's computing and networking infrastructure that includes the EJB Server and Container. The System Administrator is also responsible for overseeing the well-being of the deployed enterprise beans applications at runtime. Responsible for configuring the EJB Container and server, setting up security management, integrating resource managers with the EJB Container.

Prev Identify correct and incorrect statements or examples about EJB programming restrictions.

Up Home

Next Given a list, identify which are requirements for an EJB-jar file.

http://java.boot.by/bcd-guide/ch01s04.html 3 / 3 2004/6/12 11:56:05

Given a list, identify which are requirements for an EJB-jar file.

Given a list, identify which are requirements for an EJB-jar file. Prev Chapter 1. EJB Overview Next

Given a list, identify which are requirements for an EJB-jar file.The ejb-jar file MUST CONTAIN, either by inclusion or by reference (Class-Path attribute in the Manifest file), the class files of each enterprise bean as follows:

The enterprise bean class. The enterprise bean home and component interfaces. The primary key class if the bean is an entity bean. All the classes and interfaces that each enterprise bean class and the home and component interfaces depend on, except J2EE and J2SE classes.

The Application Assembler MUST NOT package the stubs of the EJBHome and EJBObject interfaces in the ejb-jar file.

Prev Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information.

Up Home

Next Chapter 2. Client View of a Session Bean

http://java.boot.by/bcd-guide/ch01s05.html2004/6/12 11:56:12

Chapter 2. Client View of a Session Bean

Chapter 2. Client View of a Session Bean Prev Part I. Exam Objectives Next

Chapter 2. Client View of a Session Bean

Identify correct and incorrect statements or examples about the client view of a session bean's local and remote home interfaces, including the code used by a client to locate a session bean's home interface.A client locates a session beans home interface using JNDI. For example, the remote home interface for the Cart session bean can be located using the following code segment:

Context initialContext = new InitialContext(); CartHome cartHome = (CartHome)javax.rmi.PortableRemoteObject.narrow( initialContext.lookup(java:comp/env/ejb/cart), CartHome.class);

If the Cart session bean provides a local client view instead of a remote client view and CartHome is a local home interface, this lookup might be as follows:

Context initialContext = new InitialContext(); CartHome cartHome = (CartHome) initialContext.lookup(java:comp/env/ejb/cart);

A client can pass a remote home object reference to another application. The receiving application can use the home interface in the same way that it would use a remote home object reference obtained via JNDI. A client can pass a local home object reference to another application through its local interface. A local home object reference cannot be passed as an argument or result of a method on an enterprise beans remote home or remote interface. The REMOTE HOME interface allows a client to do the following:

Create a new session object. Remove a session object (using bean's HANDLE).

http://java.boot.by/bcd-guide/ch02.html 1 / 3 2004/6/12 11:56:14

Chapter 2. Client View of a Session Bean

Get the javax.ejb.EJBMetaData interface for the session bean. The javax.ejb.EJBMetaData interface is intended to allow application assembly tools to discover information about the session bean, and to allow loose client/server binding and client-side scripting. Obtain a handle for the REMOTE home interface. The home handle can be SERIALIZED and written to stable storage. Later, possibly in a different JVM, the handle can be deserialized from stable storage and used to obtain back a reference of the remote home interface.

public interface EJBHome extends Remote { EJBMetaData getEJBMetaData() throws RemoteException; HomeHandle getHomeHandle() throws RemoteException; void remove(Handle handle) throws RemoteException, RemoveException; void remove(Object primaryKey) throws RemoteException, RemoveException; // only Entity EJB !!! }

The LOCAL HOME interface allows a local client to do the following:

Create a new session object.

public interface EJBLocalHome { void remove(Object primaryKey) throws RemoveException, EJBException; // only Entity EJB !!! }

EJBMetaData and HomeHandle are ONLY accessible for REMOTE HOME interfaces. EJBHome interface extends Remote (marker) interface. Session bean can be removed ONLY using it's handle (remote view ONLY), since it does not have primary key.

Prev Given a list, identify which are requirements for an EJB-jar file.

Up Home

Next Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces.

http://java.boot.by/bcd-guide/ch02.html 2 / 3 2004/6/12 11:56:14

Chapter 2. Client View of a Session Bean

http://java.boot.by/bcd-guide/ch02.html 3 / 3 2004/6/12 11:56:14

Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces.

Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces. Prev Chapter 2. Client View of a Session Bean Next

Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces.A client NEVER DIRECTLY accesses instances of the session beans class. A client always uses the session beans COMPONENT interface to access a session beans instance. The class that implements the session beans component interface is provided by the container. A session EJBObject supports:

The business logic methods of the object. The session EJBObject delegates invocation of a business method to the session bean instance. Get the session objects remote home interface. Get the session objects handle. Test if the session object is identical with another session object. Remove the session object.

public interface EJBObject extends Remote { EJBHome getEJBHome() throws RemoteException; Handle getHandle() throws RemoteException; Object getPrimaryKey() throws RemoteException; boolean isIdentical(EJBObject obj) throws RemoteException; void remove() throws RemoteException, RemoveException; }

A session EJBLocalObject supports:

The business logic methods of the object. The session EJBLocalObject delegates invocation of a business method to the session bean instance. Get the session objects local home interface. Test if the session object is identical with another session object. Remove the session object.

public interface EJBLocalObject { EJBLocalHome getEJBLocalHome() throws EJBException; Object getPrimaryKey() throws EJBException; boolean isIdentical(EJBLocalObject obj) throws EJBException; void remove() throws RemoveException, EJBException;http://java.boot.by/bcd-guide/ch02s02.html 1 / 2 2004/6/12 11:56:17

Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces.

}

Method getPrimaryKey() on session bean will throw EJBException (local SB) or RemoteException (remote SB) because session bean does not have primary key. EJBObject interface extends Remote (marker) interface.

Prev Chapter 2. Client View of a Session Bean

Up Home

Next Chapter 3. Session Bean Component Contract

http://java.boot.by/bcd-guide/ch02s02.html 2 / 2 2004/6/12 11:56:17

Chapter 3. Session Bean Component Contract

Chapter 3. Session Bean Component Contract Prev Part I. Exam Objectives Next

Chapter 3. Session Bean Component Contract

Identify correct and incorrect statements or examples about session beans, including conversational state, the SessionBean interface, and create methods.Session bean is specified at deployment as having one of the following state management modes:

STATELESS the session bean instances contain no conversational state between methods; any instance can be used for any client. STATEFUL the session bean instances contain conversational state which must be retained across methods and transactions.

The conversational state of a STATEFUL session object is defined as the session bean instances field values. In advanced cases, a session objects conversational state may contain open resources, such as open sockets and open database cursors. A container cannot retain such open resources when a session bean instance is passivated. A developer of such a session bean must close and open the resources in the ejbPassivate and ejbActivate notifications. All session beans must implement the SessionBean interface.

public interface SessionBean extends EnterpriseBean { void ejbActivate() throws EJBException, RemoteException; void ejbPassivate() throws EJBException, RemoteException; void ejbRemove() throws EJBException, RemoteException; void setSessionContext(SessionContext ctx) throws EJBException, RemoteException; } public interface EnterpriseBean extends Serializable { }

A client creates a session bean instance using one of the create methods defined in the session beans home interface:

public interface CartHome extends javax.ejb.EJBHome {http://java.boot.by/bcd-guide/ch03.html 1 / 3 2004/6/12 11:56:20

Chapter 3. Session Bean Component Contract

CartRemote create(String customerName, String account) throws RemoteException, BadAccountException, CreateException; CartRemote createLargeCart(String customerName, String account) throws RemoteException, BadAccountException, CreateException; }

..... CartRemote cart = cartHome.create(John, 7506);

or for LOCAL view:

public interface CartHome extends javax.ejb.EJBLocalHome { CartLocal create(String customerName, String account) throws BadAccountException, CreateException; CartLocal createLargeCart(String customerName, String account) throws BadAccountException, CreateException; }

..... CartLocal cart = cartHome.create(John, 7506);

The container creates an instance of a session bean in three steps: 1. The container calls the bean class newInstance() method to create a new session bean instance. 2. The container calls the setSessionContext(context) method to pass the context object to the instance. 3. The container calls the instances ejbCreate() method whose signature matches the signature of the create() method invoked by the client. Each session bean class must have at LEAST one ejbCreate() method (NOTE: for Entity Beans create methods are optional). Invoking create() method by client on home interface of STATELESS session bean will NOT invoke ejbCreate() method on bean object. It only creates new EJB(Local)Object. ejbCreate() on STATELESS session bean is invoked by EJB container when it decides to put object in methodready pool. For STATELESS session beans container handles creating of instances.http://java.boot.by/bcd-guide/ch03.html 2 / 3 2004/6/12 11:56:20

Chapter 3. Session Bean Component Contract

Invoking remove() method by client on home interface of STATELESS session bean will NOT invoke ejbRemove() method on bean object. It does nothing. ejbRemove() on STATELESS session bean is invoked by EJB container when it decides to remove object from method-ready pool. For STATELESS session beans container handles removing of instances. Invoking create() method by client on home interface of STATEFUL session bean will invoke ejbCreate() method on bean object. More precisely: newInstance(), setSessionContext(context), ejbCreate([ARGS]). Invoking remove() method by client on home interface of STATEFUL session bean will invoke ejbRemove() method on bean object. The home interface of a STATELESS session bean must have one (and ONLY one) create() method that takes NO arguments. The create() method of the remote home interface must return the session beans remote interface. The create method of the local home interface must return the session beans local interface. STATELESS session bean CAN have instance variables, but there is no guarantee, that these variables will be accessed by the same client. However, the instance variables of the instance can contain the state across client-invoked method calls. Examples of such states include an open database connection and an object reference to an EJB object. A STATELESS session bean MUST NOT implement the javax.ejb.SessionSynchronization interface.

Prev Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces.

Up Home

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

http://java.boot.by/bcd-guide/ch03.html 3 / 3 2004/6/12 11:56:20

Identify the use and the behavior of the ejbPassivate method in a sessi...ding the responsibilities of both the container and the bean provider.

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. Prev Chapter 3. Session Bean Component Contract Next

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.Bean Provider's responsibility Passivation is performed only for STATEFUL session beans. The Bean Provider is required to ensure that the ejbPassivate method leaves the instance fields ready to be serialized by the Container. The objects that are assigned to the instances non-transient fields after the ejbPassivate method completes must be one of the following:

A serializable object. A null. An enterprise beans remote interface reference. An enterprise beans remote home interface reference. An entity beans local interface reference. An entity beans local home interface reference. A reference to the SessionContext object. A reference to the environment naming context (java:comp/env JNDI) A reference to the UserTransaction interface. A reference to a resource manager connection factory. An object that is not directly serializable, because it contains references on "nonserializable" objects mentioned above.

Bean Provider must close all JDBC connections in ejbPassivate and assign the instances fields storing the connections to null. The Bean Provider must assume that the content of transient fields MAY be lost between the ejbPassivate and ejbActivate notifications. Container's responsibility The container performs the Java programming language Serialization (or its equivalent) of the instances state after it invokes the ejbPassivate method on the instance. The container must be able to properly save and restore the reference to the home and component interfaces of the enterprise beans stored in the instances state even if the classes that implement the object references are not serializable. If the session bean instance stores in its conversational state an object reference to the javax.ejb. SessionContext interface, java:comp/env JNDI context or UserTransaction interface, the container

http://java.boot.by/bcd-guide/ch03s02.html 1 / 2 2004/6/12 11:56:23

Identify the use and the behavior of the ejbPassivate method in a sessi...ding the responsibilities of both the container and the bean provider.

must be able to save and restore the object reference across the instances passivation. The container may destroy a session bean instance if the instance does not meet the requirements for serialization after ejbPassivate. While the container is not required to use the Serialization protocol for the Java programming language to store the state of a passivated session instance, it must achieve the equivalent result. The one exception is that containers are NOT REQUIRED to reset the value of transient fields during activation (as opposed to pure Serialization, which GUARANTEES that transient variables will come back with default values for that type). Passivation typically happens spontaneously based on the needs of the container. It happens just BEFORE writing state to secondary storage. Activation typically occurs when a client calls a method. It happens just AFTER reading state from secondary storage.

Prev Chapter 3. Session Bean Component Contract

Up

Next 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 session bean's caller has a particular role, allow the instance to mark the current transaction as a rollback, retrieve the UserTransaction interface, prepare the instance for reuse following passivation, release resources prior to removal, identify the invoker of the bean instance's component interface, be notified that a new transaction has begun, and be notified that the current transaction has completed.

Home

http://java.boot.by/bcd-guide/ch03s02.html 2 / 2 2004/6/12 11:56:23

Identify the interface and method for each of the following: retrieve t...has begun, and be notified that the current transaction has completed.

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 session bean's caller has a particular role, allow the instance to mark the current transaction as a rollback, retrieve the UserTransaction interface, prepare the instance for reuse following passivation, release resources prior to removal, identify the invoker of the bean instance's component interface, be notified that a new transaction has begun, and be notified that the current transaction has completed. Prev Chapter 3. Session Bean Component Contract Next

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 session bean's caller has a particular role, allow the instance to mark the current transaction as a rollback, retrieve the UserTransaction interface, prepare the instance for reuse following passivation, release resources prior to removal, identify the invoker of the bean instance's component interface, be notified that a new transaction has begun, and be notified that the current transaction has completed.A container provides the session bean instances with a SessionContext, which gives the session bean instance access to the instances context maintained by the container. The SessionContext interface has the following methods:

The getEJBObject method returns the session beans remote interface. The getEJBHome method returns the session beans remote home interface. The getEJBLocalObject method returns the session beans local interface. The getEJBLocalHome method returns the session beans local home interface. The getCallerPrincipal method returns the java.security.Principal that identifies the invoker of the bean instances EJB object. The isCallerInRole method tests if the session bean instances caller has a particular role. The setRollbackOnly method allows the instance to mark the current transaction such that the only outcome of the transaction is a rollback. ONLY instances of a session bean with CONTAINER-managed transaction (CMT) demarcation can use this method. The getRollbackOnly method allows the instance to test if the current transaction has been marked for rollback. ONLY instances of a session bean with CONTAINER-managed transaction (CMT) demarcation can use this method. The getUserTransaction method returns the javax.transaction.UserTransaction interface. The instance can use this interface to demarcate transactions and to obtain transaction status. ONLY instances of a session bean with BEAN-managed transaction demarcation (BMT) can use this method.

public interface SessionContext extends EJBContext { EJBLocalObject getEJBLocalObject() throws IllegalStateException; EJBObject getEJBObject() throws IllegalStateException; } public interface EJBContext {http://java.boot.by/bcd-guide/ch03s03.html 1 / 3 2004/6/12 11:56:25

Identify the interface and method for each of the following: retrieve t...has begun, and be notified that the current transaction has completed.

EJBHome getEJBHome(); EJBLocalHome getEJBLocalHome(); java.security.Principal getCallerPrincipal(); boolean isCallerInRole(String roleName); UserTransaction getUserTransaction() throws IllegalStateException; void setRollbackOnly() throws IllegalStateException; boolean getRollbackOnly() throws IllegalStateException; } /** * This interface represents the abstract notion of a principal, which * can be used to represent any entity, such as an individual, a * corporation, and a login id. */ public interface Principal { public String getName(); }

The ejbRemove notification signals that the instance is in the process of being removed by the container. In the ejbRemove method, the instance typically releases the same resources that it releases in the ejbPassivate method. The Bean Provider CANNOT assume that the Container will always invoke the ejbRemove() method on a session bean instance. The following scenarios result in ejbRemove() NOT being called on an instance:

A crash of the EJB Container. A SYSTEM exception thrown from the instances method to the Container. A timeout of client inactivity while the instance is in the passive state. The timeout is specified by the Deployer in an EJB Container implementation specific way.

If the session bean instance allocates resources in the ejbCreate(...) method and/or in the business methods, and normally releases the resources in the ejbRemove() method, these resources will not be automatically released in the above scenarios. The application using the session bean should provide some clean up mechanism to periodically clean up the unreleased resources. The ejbPassivate notification signals the intent of the container to passivate the instance. The ejbActivate notification signals the instance it has just been reactivated. Because containers automatically maintain the conversational state of a session bean instance when it is passivated, most session beans can ignore these notifications. Their purpose is to allow session beans to maintain those open resources that need to be closed prior to an instances passivation and then reopened during an instances activation (for example, DB connections). A STATEFUL session bean class (CMT only) can optionally implement the javax.ejb.http://java.boot.by/bcd-guide/ch03s03.html 2 / 3 2004/6/12 11:56:25

Identify the interface and method for each of the following: retrieve t...has begun, and be notified that the current transaction has completed.

SessionSynchronization interface. This interface provides the session bean instances with transaction synchronization notifications. The instances can use these notifications, for example, to manage database data they may cache within transactions :

The afterBegin notification signals a session bean instance that a new transaction has begun. The container invokes this method before the first business method within a transaction (which is not necessarily at the beginning of the transaction). The afterBegin notification is invoked with the transaction context. The instance may do any database work it requires within the scope of the transaction. The beforeCompletion notification is issued when a session bean instances client has completed work on its current transaction but prior to committing the resource managers used by the instance. At this time, the instance should write out any database updates it has cached. The instance can cause the transaction to roll back by invoking the setRollbackOnly method on its session context. The afterCompletion notification signals that the current transaction has completed. A completion status of true indicates that the transaction has committed; a status of false indicates that a rollback has occurred. Since a session bean instances conversational state is not transactional, it may need to manually reset its state if a rollback occurred.

public interface SessionSynchronization { void afterBegin() throws EJBException, RemoteException; void afterCompletion(boolean committed) throws EJBException, RemoteException; void beforeCompletion() throws EJBException, RemoteException; }

ONLY a STATEFUL Session bean with CONTAINER-managed transaction (CMT) demarcation may implement the SessionSynchronization interface. A stateless Session bean MUST NOT implement the SessionSynchronization interface.

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

Up Home

Next Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both.

http://java.boot.by/bcd-guide/ch03s03.html 3 / 3 2004/6/12 11:56:25

Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both.

Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both. Prev Chapter 3. Session Bean Component Contract Next

Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both.The conversational state of a STATEFUL session object is defined as the session bean instances field values, plus the transitive closure of the objects from the instances fields reached by following Java object references. STATELESS session beans are session beans whose instances have no conversational state. This means that all bean instances are equivalent when they are not involved in servicing a clientinvoked method. Because all instances of a STATELESS session bean are equivalent, the container can choose to delegate a client-invoked method to any available instance. This means, for example, that the Container may delegate the requests from the same client within the same transaction to different instances, and that the Container may interleave requests from multiple transactions to the same instance. There is no fixed mapping between clients and STATELESS instances. The container simply delegates a clients work to any available instance that is method-ready. There is "method ready" STATE for STATEFUL session beans. Because they have relationship: one client - one bean. There is "method ready" POOL for STATELESS session beans. Because they have relationship: one client - many beans.

Prev

Up

Next

http://java.boot.by/bcd-guide/ch03s04.html 1 / 2 2004/6/12 11:56:28

Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both.

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 session bean's caller has a particular role, allow the instance to mark the current transaction as a rollback, retrieve the UserTransaction interface, prepare the instance for reuse following passivation, release resources prior to removal, identify the invoker of the bean instance's component interface, be notified that a new transaction has begun, and be notified that the current transaction has completed.

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 container provider. Home

http://java.boot.by/bcd-guide/ch03s04.html 2 / 2 2004/6/12 11:56:28

Given a list of responsibilities related to session beans, identify thos...r and those which are the responsibility of the EJB container provider.

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 container provider. Prev Chapter 3. Session Bean Component Contract Next

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 container provider.Bean Provider's responsibility The session bean provider is responsible for providing the following class files:

Session bean class. Session beans remote interface and remote home interface, if the session bean provides a remote client view. Session beans local interface and local home interface, if the session bean provides a local client view.

Container Provider's responsibility The container provider is responsible for providing the deployment tools and for managing the session bean instances at runtime. The deployment tools provided by the container are responsible for the generation of additional classes when the session bean is deployed. The tools obtain the information that they need for generation of the additional classes by introspecting the classes and interfaces provided by the enterprise bean provider and by examining the session beans deployment descriptor. The deployment tools must generate the following classes:

A class class). A class A class class). A class

that implements the session beans remote home interface (session EJBHome that implements the session beans remote interface (session EJBObject class). that implements the session beans local home interface (session EJBLocalHome that implements the session beans local interface (session EJBLocalObject class).

The deployment tools may also generate a class that mixes some container-specific code with the session bean class. This code may, for example, help the container to manage the bean instances at runtime. The tools can use subclassing, delegation, and code generation.

The session EJBHome class, which is generated by the deployment tools, implements the session beans remote home interface. This class implements the methods of the javax.ejb.

http://java.boot.by/bcd-guide/ch03s05.html 1 / 2 2004/6/12 11:56:30

Given a list of responsibilities related to session beans, identify thos...r and those which are the responsibility of the EJB container provider.

EJBHome interface and the create methods specific to the session bean. The implementation of each create(...) method invokes a matching ejbCreate(...) method. The session EJBObject class, which is generated by the deployment tools, implements the session beans remote interface. It implements the methods of the javax.ejb.EJBObject interface and the business methods specific to the session bean. The implementation of each business method must activate the instance (if the instance is in the passive state) and invoke the matching business method on the instance. The session EJBLocalHome class, which is generated by the deployment tools, implements the session beans local home interface. This class implements the methods of the javax.ejb. EJBLocalHome interface and the create methods specific to the session bean. The implementation of each create(...) method invokes a matching ejbCreate(...) method. The session EJBLocalObject class, which is generated by the deployment tools, implements the session beans local interface. It implements the methods of the javax.ejb. EJBLocalObject interface and the business methods specific to the session bean. The implementation of each business method must activate the instance (if the instance is in the passive state) and invoke the matching business method on the instance. The deployment tools are responsible for implementing the handle classes for the session beans REMOTE HOME and REMOTE interfaces. The deployment tools are responsible for implementing the class that provides meta-data to the remote client view contract. The class must be a valid RMI Value class and must implement the javax.ejb.EJBMetaData interface. The container must ensure that ONLY ONE thread can be executing an instance at any time. If a client request arrives for an instance while the instance is executing another request, the container may throw the java.rmi.RemoteException to the second request if the client is a remote client, or the javax.ejb.EJBException if the client is a local client. The container MUST follow the rules with respect to transaction scoping, security checking, and exception handling. The container MUST implement the SessionContext.getEJBObject() method such that the bean instance can use the Java language cast to convert the returned value to the session beans remote interface type. Specifically, the bean instance does not have to use the PortableRemoteObject.narrow(...) method for the type conversion.

Prev Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both.

Up

Next Given a list of requirements, identify those which are the requirements for a session bean class, a remote component interface, a remote home interface, create methods, business methods, a local component interface, and a local home interface.

Home

http://java.boot.by/bcd-guide/ch03s05.html 2 / 2 2004/6/12 11:56:30

Given a list of requirements, identify those which are the requirement...ess methods, a local component interface, and a local home interface.

Given a list of requirements, identify those which are the requirements for a session bean class, a remote component interface, a remote home interface, create methods, business methods, a local component interface, and a local home interface. Prev Chapter 3. Session Bean Component Contract Next

Given a list of requirements, identify those which are the requirements for a session bean class, a remote component interface, a remote home interface, create methods, business methods, a local component interface, and a local home interface.The following are the requirements for session BEAN CLASS:

The class MUST implement, directly or indirectly, the javax.ejb.SessionBean interface. The class MUST be defined as public, MUST NOT be final, and MUST NOT be abstract (NOTE, CMP ENTITY bean class MUST be abstract). The class MUST have a public constructor that takes NO parameters. The Container uses this constructor to create instances of the session bean class. The class MUST NOT define the finalize() method. The class may, but is not required to, implement the session beans component interface (NOTE: AVOID passing of this). The class MUST implement the business methods and the ejbCreate methods. If the class is a STATEFUL session bean, it may optionally implement the javax.ejb. SessionSynchronization interface. The session bean class may have superclasses and/or superinterfaces. If the session bean has superclasses, then the business methods, the ejbCreate methods, the methods of the SessionBean interface, and the methods of the optional SessionSynchronization interface may be defined in the session bean class, or in any of its superclasses. The session bean class is allowed to implement other methods (for example helper methods invoked internally by the business methods) in addition to the methods required by the EJB specification.

The session BEAN CLASS may define zero or more business methods whose signatures must follow these rules:

The method names can be arbitrary, but they MUST NOT start with ejb to avoid conflicts with the callback methods used by the EJB architecture. The business method MUST be declared as public. The method MUST NOT be declared as final or static. The argument and return value types for a method MUST be legal types for RMI/IIOP if the method corresponds to a business method on the session beans remote interface. The throws clause may define arbitrary application exceptions.

The session BEAN CLASS must define one or more ejbCreate(...) methods whose signatures must follow these rules:

http://java.boot.by/bcd-guide/ch03s06.html 1 / 4 2004/6/12 11:56:33

Given a list of requirements, identify those which are the requirement...ess methods, a local component interface, and a local home interface.

The method name MUST have ejbCreate as its prefix. The method MUST be declared as public. The method MUST NOT be declared as final or static. The return type MUST be void. The method arguments MUST be legal types for RMI/IIOP if there is a create(...) corresponding to the ejbCreate(...) method on the session beans remote home interface. The throws clause may define arbitrary application exceptions, possibly including the javax. ejb.CreateException.

The following are the requirements for the session beans REMOTE [component] interface:

The interface MUST extend the javax.ejb.EJBObject interface. The methods defined in this interface MUST follow the rules for RMI/IIOP. This means that their argument and return values must be of valid types for RMI/IIOP, and their throws clauses must include the java.rmi.RemoteException. The remote interface is allowed to have superinterfaces. Use of interface inheritance is subject to the RMI/IIOP rules for the definition of remote interfaces. For each method defined in the remote interface, there must be a matching method in the session beans class. The matching method must have:r r r

The same name. The same number and types of arguments, and the same return type. All the exceptions defined in the throws clause of the matching method of the session bean class must be defined in the throws clause of the method of the remote interface.

The remote interface methods must not expose local interface types, local home interface types, or the managed collection classes that are used for entity beans with containermanaged persistence as arguments or results.

The following are the requirements for the session beans REMOTE HOME interface:

The interface MUST extend the javax.ejb.EJBHome interface. The methods defined in this interface MUST follow the rules for RMI/IIOP. This means that their argument and return values MUST be of valid types for RMI/IIOP, and that their throws clauses MUST include the java.rmi.RemoteException. The remote home interface is allowed to have superinterfaces. Use of interface inheritance is subject to the RMI/IIOP rules for the definition of remote interfaces. A session beans remote home interface MUST define one or more create(...) methods. (NOTE, Entity Beans may define ZERO create(...) methods). A STATELESS session bean must define exactly ONE create() method with NO arguments. Each create method MUST be named create, and it MUST match one of the ejbCreate methods defined in the session bean class. The matching ejbCreate method MUST have the same number and types of arguments. (Note that the return type is different.) The methods for a STATELESS session bean MUST be named create and ejbCreate. The return type for a create method MUST be the session beans REMOTE

http://java.boot.by/bcd-guide/ch03s06.html 2 / 4 2004/6/12 11:56:33

Given a list of requirements, identify those which are the requirement...ess methods, a local component interface, and a local home interface.

INTERFACE type. All the exceptions defined in the throws clause of an ejbCreate method of the session bean class must be defined in the throws clause of the matching create method of the remote home interface. The throws clause of create(...) MUST include javax.ejb.CreateException.

The following are the requirements for the session beans LOCAL [component] interface:

The interface MUST extend the javax.ejb.EJBLocalObject interface. The throws clause of a method defined in the LOCAL interface MUST NOT include the java. rmi.RemoteException. The local interface is allowed to have superinterfaces. For each method defined in the local interface, there must be a matching method in the session beans class. The matching method must have:r r r

The same name. The SAME number and types of arguments, and the SAME return type. All the exceptions defined in the throws clause of the matching method of the session bean class must be defined in the throws clause of the method of the local interface.

The following are the requirements for the session beans LOCAL HOME interface:

The interface MUST extend the javax.ejb.EJBLocalHome interface. The throws clause of a method in the LOCAL home interface MUST NOT include the java.rmi. RemoteException. The local home interface is allowed to have superinterfaces. A session beans local home interface MUST define one or more create(...) methods. A STATELESS session bean MUST define exactly ONE create() method with NO arguments. Each create method MUST be named create, and it MUST match one of the ejbCreate methods defined in the session bean class. The matching ejbCreate method MUST have the same number and types of arguments. (Note that the return type is different.) The methods for a STATELESS session bean MUST be named create and ejbCreate. The return type for a create method MUST be the session beans local interface type. All the exceptions defined in the throws clause of an ejbCreate method of the session bean class MUST be defined in the throws clause of the matching create method of the local home interface. The throws clause of create method MUST include javax.ejb.CreateException.

Prev

Up

Next

http://java.boot.by/bcd-guide/ch03s06.html 3 / 4 2004/6/12 11:56:33

Given a list of requirements, identify those which are the requirement...ess methods, a local component interface, and a local home interface.

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

Chapter 4. Session Bean Life Cycle Home

http://java.boot.by/bcd-guide/ch03s06.html 4 / 4 2004/6/12 11:56:33

Chapter 4. Session Bean Life Cycle

Chapter 4. Session Bean Life Cycle Prev Part I. Exam Objectives Next

Chapter 4. Session Bean Life Cycle

Identify correct and incorrect statements or examples about the life cycle of a stateful or stateless session bean instance.Stateful Session Bean

A session bean instances life starts when a client invokes a create(...) method on the session beans home interface. This causes the container to invoke newInstance() on the session bean class to create a new session bean instance. Next, the container calls setSessionContext() and ejbCreate(...) on the instance and returns the session object reference to the client. The instance is now in the METHOD READY STATE. The session bean instance is now ready for clients business methods. Based on the transaction attributes in the session beans deployment descriptor and the transaction context associated with the clients invocation, a business method is executed either in a transaction context or with an unspecified transaction context. A non-transactional method is executed while the instance is in the METHOD READY STATE. An invocation of a transactional method causes the instance to be included in a transaction. When the session bean instance is included in a transaction, the container issues the afterBegin() method on it. The afterBegin is delivered to the instance before any business method is executed as part of the transaction. The instance becomes associated with the transaction and will remain associated with the transaction until the transaction completes. Session bean methods invoked by the client in this transaction can now be delegated to the bean instance. An error occurs if a client attempts to invoke a method on the session object and the deployment descriptor for the method requires that the container invoke the method in a different transaction context than the one with which the instance is currently associated or in an unspecified transaction context. If a transaction commit has been requested, the transaction service notifies the container of the commit request before actually committing the transaction, and the container issues a beforeCompletion on the instance. When beforeCompletion is invoked, the instance should write any cached updates to the database. If a transaction rollback had been requested instead, the rollback status is reached without the container issuing a beforeCompletion. The container may not call the beforeCompletion method if the transaction has been marked for rollback (nor does the instance write any cached updates to the database). The transaction service then attempts to commit the transaction, resulting in either a commit or rollback. When the transaction completes, the container issues afterCompletion on the instance, specifying the status of the completion (either commit or rollback). If a rollback occurred, the bean instance may need to reset its conversational state back to the value it had at

http://java.boot.by/bcd-guide/ch04.html 1 / 3 2004/6/12 11:56:36

Chapter 4. Session Bean Life Cycle

the beginning of the transaction. The containers caching algorithm may decide that the bean instance should be evicted from memory (this could be done at the end of each method, or by using an LRU policy). The container issues ejbPassivate on the instance. After this completes, the container saves the instances state to secondary storage. A session bean can be passivated only between transactions, and NOT within a transaction. While the instance is in the passivated state, the Container may remove the session object after the expiration of a timeout specified by the deployer. All object references and handles for the session object become invalid. If a client attempts to invoke the session object, the Container will throw the java.rmi.NoSuchObjectException if the client is a remote client, or the javax.ejb.NoSuchObjectLocalException if the client is a local client. If a client invokes a session object whose session bean instance has been passivated, the container will activate the instance. To activate the session bean instance, the container restores the instances state from secondary storage and issues ejbActivate on it. The session bean instance is again ready for client methods. When the client calls remove() on the home or component interface to remove the session object, the container issues ejbRemove() on the bean instance. This ends the life of the session bean instance and the associated session object. Any subsequent attempt by its client to invoke the session object causes the java.rmi.NoSuchObjectException to be thrown if the client is a remote client, or the javax.ejb.NoSuchObjectLocalException if the client is a local client. (The java.rmi.NoSuchObjectException is a subclass of the java.rmi. RemoteException; the javax.ejb.NoSuchObjectLocalException is a subclass of the javax.ejb. EJBException). The ejbRemove() method cannot be called when the instance is participating in a transaction. An attempt to remove a session object while the object is in a transaction will cause the container to throw the javax.ejb.RemoveException to the client. Note that a container can also invoke the ejbRemove() method on the instance without a client call to remove the session object after the lifetime of the EJB object has expired.

Stateless Session Bean

A stateless session bean instances life starts when the container invokes newInstance() on the session bean class to create a new instance. Next, the container calls setSessionContext () followed by ejbCreate() on the instance. The container can perform the instance creation at any timethere is NO relationship to a clients invocation of the create() method. The session bean instance is now ready to be delegated a business method call from any client. When the container no longer needs the instance (usually when the container wants to reduce the number of instances in the method-ready pool), the container invokes ejbRemove() on it. This ends the life of the stateless session bean instance.

Prev

Up

Next

http://java.boot.by/bcd-guide/ch04.html 2 / 3 2004/6/12 11:56:36

Chapter 4. Session Bean Life Cycle

Given a list of requirements, identify those which are the requirements for a session bean class, a remote component interface, a remote home interface, create methods, business methods, a local component interface, and a local home interface.

Home

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 methods, UserTransaction methods, Java Naming and Directory Interface API (JNDI API) access to java:comp/env environment naming context, resource manager access, and other enterprise bean access.

http://java.boot.by/bcd-guide/ch04.html 3 / 3 2004/6/12 11:56:36

Given a list of methods for a stateful or stateless session bean class,...ing context, resource manager access, and other enterprise bean access.

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 methods, UserTransaction methods, Java Naming and Directory Interface API (JNDI API) access to java:comp/env environment naming context, resource manager access, and other enterprise bean access. Prev Chapter 4. Session Bean Life Cycle Next

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 methods, UserTransaction methods, Java Naming and Directory Interface API (JNDI API) access to java:comp/env environment naming context, resource manager access, and other enterprise bean access.Stateful Session Bean Table 4.1. Operations allowed in the methods of a stateful session beanBean method can perform the following operations Bean method Container-managed transaction demarcation SessionContext methods: getEJBHome, getEJBLocalHome. JNDI access to java:comp/env SessionContext methods: getEJBHome, getEJBLocalHome, getCallerPrincipal, isCallerInRole, getEJBObject, getEJBLocalObject. JNDI access to java:comp/env Resource manager access Enterprise bean access JNDI access to java:comp/env Resource manager access Enterprise bean access SessionContext methods: getEJBHome, getEJBLocalHome. JNDI access to java:comp/env SessionContext methods: getEJBHome, getEJBLocalHome, getCallerPrincipal, isCallerInRole, getEJBObject, getEJBLocalObject, getUserTransaction. UserTransaction methods Bean-managed transaction demarcation

constructor

setSessionContext

ejbCreate ejbRemove ejbActivate ejbPassivate

http://java.boot.by/bcd-guide/ch04s02.html 1 / 3 2004/6/12 11:56:39

Given a list of methods for a stateful or stateless session bean class,...ing context, resource manager access, and other enterprise bean access.

Business method from component interface

SessionContext methods: getEJBHome, getEJBLocalHome, getCallerPrincipal, getRollbackOnly, isCallerInRole, setRollbackOnly, getEJBObject, getEJBLocalObject. JNDI access to java:comp/env Resource manager access Enterprise bean access SessionContext methods: getEJBHome, getEJBLocalHome, getCallerPrincipal, getRollbackOnly, isCallerInRole, setRollbackOnly, getEJBObject, getEJBLocalObject. JNDI access to java:comp/env Resource manager access Enterprise bean access SessionContext methods: getEJBHome, getEJBLocalHome, getCallerPrincipal, isCallerInRole, getEJBObject, getEJBLocalObject. JNDI access to java:comp/env

SessionContext methods: getEJBHome, getEJBLocalHome, getCallerPrincipal, isCallerInRole, getEJBObject, getEJBLocalObject, getUserTransaction. UserTransaction methods JNDI access to java:comp/env Resource manager access Enterprise bean access

afterBegin beforeCompletion

N/A (a bean with bean-managed transaction (BMT) demarcation cannot implement the SessionSynchronization interface)

afterCompletion

Stateless Session Bean Table 4.2. Operations allowed in the methods of a stateless session beanBean method can perform the following operations Bean method

http://java.boot.by/bcd-guide/ch04s02.html 2 / 3 2004/6/12 11:56:39

Given a list of methods for a stateful or stateless session bean class,...ing context, resource manager access, and other enterprise bean access.

Container-managed transaction demarcation constructor SessionContext methods: getEJBHome, getEJBLocalHome. JNDI access to java:comp/env SessionContext methods: getEJBHome, getEJBLocalHome, getEJBObject, getEJBLocalObject. JNDI access to java:comp/env

Bean-managed transaction demarcation SessionContext methods: getEJBHome, getEJBLocalHome. JNDI access to java:comp/env SessionContext methods: getEJBHome, getEJBLocalHome, getEJBObject, getEJBLocalObject, getUserTransaction. JNDI access to java:comp/env

setSessionContext

ejbCreate ejbRemove

SessionContext methods: getEJBHome, getEJBLocalHome, getCallerPrincipal, getRollbackOnly, isCallerInRole, setRollbackOnly, getEJBObject, getEJBLocalObject. Business method from component interface JNDI access to java:comp/env Resource manager access Enterprise bean access

SessionContext methods: getEJBHome, getEJBLocalHome, getCallerPrincipal, isCallerInRole, getEJBObject, getEJBLocalObject, getUserTransaction. UserTransaction methods JNDI access to java:comp/env Resource manager access Enterprise bean access

Prev Chapter 4. Session Bean Life Cycle

Up Home

Next Given a list of scenarios, identify which will result in an ejbRemove method not being called on a bean instance.

http://java.boot.by/bcd-guide/ch04s02.html 3 / 3 2004/6/12 11:56:39

Given a list of scenarios, identify which will result in an ejbRemove method not being called on a bean instance.

Given a list of scenarios, identify which will result in an