EJB introduction

xiaoxiao2021-03-06  14

EJB

1. EJB architecture:

Includes the client, server side.

Client: Contains the EJB interface (including local and remote EJB interfaces) required to call EJB components; the server-side handle handles.

Server: Contains an instance implemented by EJB components; container code used to map between clients and EJB components.

The EJB client application uses JNDI to find instance references to the local interface, call and reference all methods and properties of the EJB component via the EJB interface.

2. Steps to develop EJB procedures:

Develop a main interface, develop component interface, develop a bean implementation class, write deployment files.

Developer interface: Bean's primary interface program, named Home, inherit EJBHOME, responsible for bean's life cycle (generated, delete, looking for bean). Simply provide the primary interface, the implementation of the class method is done by the container. The method has Create, Remove, Search, etc.

Development component interface: named , inherit EJBOBJECT Automatically generated when deployed.

Developing bean implementation class: named EJB to implement the sessionBean interface. Implement EJBCREATE, EJBREMOVE, etc.

Write a deployment document: The complete bean consists of the Java class and the EJB-JAR.XML file descriptions its characteristics, package it, placed in the deploy folder in JBoss.

3. Develop and deploy test procedures:

Develop a servlet test, place the test program in the Tomcat's WebApps.

4. Session bean:

Divided into stateful session beans and stateless session beans. The EJB container judges whether or not a sessionBean provides a Save status for a sessionBean via ejb-jar.xml.

All sessionBeans's life cycle is controlled by container, and beans have direct references from Beans. When deploying an EJB, the container assigns several instances to Component Pool for this bean. When the customer requests a bean, the J2EE server assigns a pre-instantiated bean, in the customer's session, you can only quote a bean, Multiple methods of this bean can be implemented. If another customer requests the same bean, the container checks the pool in the pool (not in the method and transaction, if a customer will reference a bean for a long time, you need to wait for a method to perform another method, this time Also idle), if all instances have been used, automatically generate a new instance in the pool and assign to the requester. When the load is reduced, the pool will automatically manage the number of bean instances, and release excess instances from the pool.

5. State conversation bean:

Saving data between customer access, maintaining the status value of all instance data in the BEAN during the customer reference.

There are four states: there is no existence, the method is now, the method is from the transaction.

There is no statement: the initialization status of SESSIONBEAN does not exist. When the customer refers to a bean, a bean is initialized in the following figure. Methods Some: If the customer calls the remove () method back to the absence of state, and trigger the bean's EJBREMOVE () method. If the customer does not call the bean or the server is ready to release some memory resources, the container call ejbpassivate () divides these beans from the component pool, and release the allocated resource. When the request is passivated bean, the container calls ejbactivate () activates the bean, bean to allocate the resources required for Bean when the method is ready. Bean itself can manage the BMT Bean-Managed Transactions, or by the container management transaction (CMT Container-Managed Transactions). For the CMT, the container opens the transaction at the beginning of the method, and implements transactions at the end of the method. Get all states of the transaction via afterbegin () () () (), aftercompletion (), afterCompletion (TRUE) indicates that the transaction is complete, and aftercompletion (false) means that the transaction is revoked.

SetSessionContext () places the context of the object into the object variable, the container automatically calls the EJBREMOVE () method before ending the session bean or automatically timeout death, this method can be used to release the resource,

6. No state session bean:

Data will not be saved between customer access, and instance variables cannot be declared, and the method can only operate the parameters.

If the data is the instantata of the data, use a stateless session bean. Disadvantages: This stored data stored on the server is saved in the customer, and each time you call these data to be passed to the bean by parameters. If the data status is very sensitive, do not use stateless session beans.

There are two states: there is, there is no existence.

Only providing business logic for customers, the server side does not save any data status of the client, which is saved on the client.

When the client does not have a stateless session bean, create a bean through the CREATE () method of the remote host (), newinstance () is responsible for instantiation beans, EJB container calls the bean class's setSessionContext () method to pass the running environment object sessionContext BEAN, then call the EJBCREATE () method for initialization and resource allocation.

7. JBoss:

Use JBoss to run EJB, put EJB .jar files in the JBoss Deploy folder. This JBoss version is jboss2.2.1. Place all Class files all of the EJB in Tomcat's WebAPPS.

Configure EJB-JAR.XML files:

this is hello ejb

Hellobean

Hello

Hello.HelloHome

Hello.Hello

Hello.Helloejb

stateless container

EJB-NAME - is an EJB interface name. The interface here is Hello.

Home - is the main interface, including a complete package.

EJB-CLASS - is an instance of EJB, including a complete package name.

Remote - is an EJB interface class name, including a complete package name.

Session-Type - There are two values ​​stateless, stateful.

8. Entity Bean:

The object used to represent the underlying object, commonly used to map records in the relational database. The field of the relational database can be mapped in one-to-one to an Entity bean, the relationship between the tables can be regarded as the relationship between the Entity bean, and an Entity bean instance may correspond to a record or a query result.

Persistence: Any change in database records should also be related to related beans in the synchronous component pool. This process is persistence and is the most important feature of Entity Bean. It can be divided into: CMP Container-Managed Persistence and Bean Management Persistence (BMP bean-managed persistence).

Container Manager: It is an operator responsible for synchronization between Bean and the underlying database table record value. The persistence of CMP beans is responsible by the EJB container, and the operation of the database is described by the EJB deployer when deploying EJB, and SQL operation and synchronization work is implemented by the container. The persistence of BMP bean is responsible by bean, which is responsible for interacting with the database with the database.

9. EJB 1.1 CMP in the specification:

The bean written in the CMP mode is mapped by the deployer when deployed.

To the actual database field, this enhances the transplantability of the program. You don't have to consider how CMP Bean connects to the database, which specifies a database connection pool for a database connection pool by deployers while deploying beans.

When designing a CMP bean, the bean is fixed to map an entity table, and each specified field in the table is mapped into a public type variable of the bean. In actual development, only in the implementation class of the bean, this variable is applied. , Mapping operations and SQL processing are automatically completed by deployers and containers.

Only the entity bean has a primary key, and an instance of each entity bean represents a record. The primary key type generally corresponds to the data table master keyword type. In the implementation class of the bean, ejbcreate (), the CMP bean returns a value of a null type. BMP bean returns a primary key type object; in the remote primary interface of the bean, create () is used to insert a data and return according to Ejbcreate (). A reference to a bean.

CMP beans need to design: remote primary interface, component interface, and bean implementation classes.

10. Entity Bean life cycle:

When the customer is called after the end of an Entity Bean and releases the resource, the Entity Bean instance still exists in the component pool, and maintains persistence with the mapping database record.

The start state of the Entity bean does not exist. When the customer is inserted directly into the record, the new record will be mapped in the instance of the bean to the component pool, and the state is existent, not reference, can pass through the main interface Find methods find these objects to the existence, reference status, can also be deleted by home.remove () and return to the initial state. In the initial state via Home.create () can be present, reference state, the referenced handle is returned by the CREATE method. The business method of the component can be called only when the presentation is present. Use Set NULL to release resources, Remove () using primary interfaces and component interfaces will delete the mapped data record, release the Entity Bean resources, but the reference resource is still not released, only set null can Release the reference resource. When the database record is inserted directly into the data by other applications or processes, the container will automatically maintain its persistence, and after the client is executed, it must release the resources of its reference. When the remote customer calls the CREATE () of the remote primary interface, the container calls newInstance () to create a bean instance, calling set throughTyContext () passes the current situation to the bean, enter the pool sharing phase. Call ejbcreate (), ejbpostcreate () to fully initialize the bean and enter the preparation phase, the BEAN business logic method that enters the preparation phase can be called by the customer, when calling setXX or getXX, the container (CMP) or bean (bmp) will call multiple times Update (EJBStore ()) and extraction (EJBLOAD ()) to maintain the persistence of components.

11. Develop CMP bean:

Developer interface: inherit EJBHOME,

Development component interface: Inherited EJBObject, the method declared in the component interface must be implemented in the bean class, the primary key of the component has the default operation method, so you can use getPrimary () to get the primary key of the component without using GetPrimary (), return one. Object type, through the traceable type in the client program.

Development bean implementation class: implement the EntityBean interface, EJBLOAD () reads a data record from the database, ejbstore () Submit the current data status to record, ejbremove () releases instance objects and deletes data records for related maps, setentityContext () The current bean instance accesses the bean situation, unsetentityContext () releases a specific situation resource. Entity Bean activation call order: ejbactivate () - ejbphad (); Sequence at the time of passivation: ejbstore () - Ejbpassivate (); return to the CMP EJBCREATE () Return to the main keyword type, due to the container, here Only related map fields are required in the method, and then return NULL. The mapping fields associated with the database table must be defined in the class.

Write a deployment file: Deployment file is EJB-JAR.XML.

For CMP Bean, when a bean instance is referenced by a customer, the container will automatically read the instance field of the bean, then the container is related to the database, and the changed data is saved. After the execution, Bean is passivated, and the EJBPassivate is called. ) To notify bean. Then call this bean again, bean first calls the ejbactivate () to inform the bean, the bean instance is activated, then from the database

Take the data and automatically map the data value to the instance of the bean, then call ejbload (), the instance is once again initialized, and finally the business method to be executed will be implemented. 12. Develop BMP bean:

When a bean instance is referenced by a customer, and after a business method is executed, the container performs EJBStore (), and the data is saved in the database, and the bean is passivated after execution, and the ejbpassivate () notifies the bean. When the customer calls this bean's business method, the passivated bean is reactivated, and the EJB object calls EJBACTIVATE () informing the bean, the bean instance is activated, then call the bean's EjbLoad (), this method is responsible for from the database The extraction data, the bean instance is initialized, and finally the business method to be executed will be implemented.

All database operations are required to be completed by a bean instance.

SetXXX (): To set the value of the field; getxxx (): to get the value of the bean field; ejbcreate (): Implemented by the developer, return to the primary key value of the creation record; EjbLoad (): to implement component non-persistent status cache Persistent information; EJBStore (): Turning information from the non-persistent status of the components to a persistent state; ejbremove (): must be implemented by the developer; unsetentityContext (): Release the context resource cached in setentityContext () and achieved Resource; setentityContext (): Sets the situation resource, initialize the database connection object; EJBActivate (): Sets the primary key value through the situation parameter; ejbpassivate (): Cancel the persistence of the bean and database records and enter the passivation state.

Developer interface: Like the main interface developed in the development of CMP BEAN.

Development component interface: Like the main connector of the development CMP bean.

Implementation class for the development of beans: Bean is not in declaring the global class variable, mapping of class variables to be managed. An EntityContext context variable is required, which is obtained by getPrimaryKey () of this variable to be saved in the situation in the context to reinitialize the data of the bean during bean. Because the database is to be done directly, a DataSource object is defined, and the object from the connection pool is initialized from the connection pool. The defined Connect object will be referenced when a database connection is obtained. Define a STATIC variable for a string type to store a JNDI name that gets a database resource.

EJB core technology and its application [repost]

Thesis:

The full name of EJB is Enterprise Java Bean. It is a commercial application component technology in Java. The role EJB component structure in the EJB structure is based on components-based distributed computing structures, which are components in distributed application ...

I. Introduction to EJB Technology

The full name of EJB is Enterprise Java Bean. It is a commercial application component technology in Java. The role EJB component structure in the EJB structure is a component-based distributed computing structure, which is a component in a distributed application.

A complete EJB-based distributed computing structure consists of six roles, which can be provided by different developers, and every role must follow the EJB specification provided by Sun to ensure compatibility between each other. Sex. These six characters are EJB component developers, Application ASSEMBLERs, deployers, EJB server providers, EJB container providers (EJB container providers, System Administrator: 2, analysis of each role in EJB

1, EJB component developer (Enterprise Bean Provider)

EJB component developers are responsible for developing EJB components that performs business logic rules, and the EJB components developed into EJB-JAR files. The EJB component developer is responsible for defining the EJB's REMOTE and HOME interface, writing EJB Class, executing business logic, providing deployment descriptor. The deployment file contains the name of EJB, and the resource configuration used by EJB, such as JDBC, etc. EJB Components Developers are typical business application development field experts.

EJB component developers do not need to be proficient in system-level programming, so you don't need to know some system-level processing details, such as transactions, synchronization, security, distributed calculations.

2, Application Components (Application Assembler)

Application portfoliors are responsible for using various EJB combined a complete application system. Application portfoliors sometimes need to provide some related programs, such as in an e-commerce system, application portfoliors need to provide JSP (Java Server Page).

Application portfoliors must master the EJB HOME and REMOTE interface used, but do not need to know the implementation of these interfaces.

3, deployer (deployer)

Deployers are responsible for deploying the EJB-JAR file into the user's system environment. The system environment contains some EJB Server and EJB Container. Deployers must guarantee that all resources declared by the EJB component developer in the deployment file, for example, deployers must configure the database resources required for EJB.

Deployment procedures Two steps: Deployers first use the tools provided by EJB Container to generate some classes and interfaces, so that EJB Container can use these classes and interfaces to manage EJBs in operation. Deployers Install the EJB component and other classes generated in the previous step to EJB Container. Deployers are an expert in an EJB operating environment.

In some cases, deployers need to understand the business methods included in EJB in deployment to write some simple program tests after deployment.

4, EJB server provider (EJB Server Provider)

The EJB server provider is an expert in the system, proficient in distributed transaction management, distributed object management, and other system-level services. EJB server providers are generally provided by operating system developers, middleware developers, or database developers.

In the current EJB specification, assume that the EJB server provider and the EJB container provider come from the same developer, so no interface criteria between the EJB server provider and the EJB container provider are defined.

5, EJB container provider (EJB Container Provider)

The EJB container provider provides the following features:

Provide EJB deployment tools to provide a running environment for deploying EJB components. The EJB container is responsible for providing transaction management, safety management such as EJB.

The EJB container provider must be a system-level programming expert, but also have some experience in the application. The work of the EJB container provider is mainly focused on the development of a retractable and transaction management functionality in the EJB server. EJB container providers provide a set of standards for EJB component developers, easy-to-use API access to EJB containers, so that EJB component developers do not need to understand various technical details in the EJB server. The EJB container provider is responsible for providing system monitoring tools to monitor EJB containers in real time and the state of EJB components running in the container.

6. System administrator

The system administrator is responsible for providing an enterprise-class computing and network environment for EJB servers and containers.

System administrators are responsible for monitoring the operation of EJB components using the Monitoring Management Tools provided by EJB servers and containers.

Third, EJB architecture:

The EJB distributed application is an API technology based on the object component model, the low-level transaction service. EJB technology simplifies the development and configuration of enterprise application systems written in Java language. EJB technology defines a set of reusable components: Enterprise Beans. You can take advantage of these components, build your distributed application like wood. When you write the code, these components are combined into a specific file. Each file has one or more Enterprise Beans, plus some configuration parameters. Finally, these Enterprise Beans are configured to a platform with EJB containers. Customers are able to locate a beans through these beans's Home interface, and generate an instance of this beans. In this way, customers can call Beans Application and Remote Interface.

The EJB server manages EJB containers and functions as bridges of the container and low-level platforms. It provides the ability to access system services to the EJB container. For example: the management and transaction management of the database, or for other Enterprise application servers. All EJB instances run in the EJB container.

The container provides a system-level service that controls the life cycle of EJB. There are some easy-to-use management tools in EJB, such as: The Deployment Descriptor defines different application functions that customers accessible. The container reaches this effect by accessing these functions that only allow authorized customers. The Remote Connectivity-Container manages the low-level communication Issues for remote links, and has hidden communications details for Enterprise Beas developers and customers. EJB developers are like a local platform when writing application methods. Customers are not clear that the methods they call may be processed remotely. Life Cycle Managing - Customer Create an instance of Enterprise Beans and typically cancel an instance. The container manages instances of Enterprise Beans, enabling Enterprise Beans to maximize the maximum efficiency and memory utilization. The container can activate and make Enterprise Beans to maintain the instance pool shared by many customers. and many more.

The TRASCTION Management-Configuration Description Defines the needs of the transaction processing of Enterprise Beans. The container manages complex Issues that manages distributed transactions. These transactions may have to update the database between different platforms. The container makes each of these transactions independently and does not interfere with each other. Ensure that all updated databases are successful, and whether they are rolled back to the state before transaction.

The EJB component is a component of an enterprise-class application based on distributed transactions. All EJBs have the following features: EJB contains application logic for processing corporate data. Define the EJB customer interface. Such interfaces are not affected by the containers and servers. Thus, when an EJB is set to an application, do not change the code and recompile. EJB can be customized for various system-level services, such as security and transactional characteristics, are not belonging to the EJB class. Instead, it is implemented by a tool for configuring and assembling an application. There are two types of EJB: Session Beans and Entity Beans.Session Beans are an object that is performed as a single user. As a corresponding to the remote task request, the container generates an instance of a session beans. A session beans have a user. From a certain extent, a session bean represents the user of the user. Thesession beans can also be used for transactions, it can update the shared data, but it does not depict these Shared data. The life cycle of Session Beans is relatively short. Typically, the session beans are only living when the user keeps a session. Once the user quits, Session Beans will no longer be associated with the user. Session Beans is seen as instantaneous because if the container crashes, the user must re-establish a new session object to continue the session. Session bean is typical to declare interoperability or session with users. That is, the session bean masters the user's information through the customer session. A stateful session bean called a stateful Session bean. When the user terminates interoperability with the session beans. The session is terminated, and the bean no longer has a status value. Session bean may also be a stateless session bean. The stateless session beans do not have information or status of its customers. Users can call Beans to complete some operations. However, Beans only knows the user's parameter variable when the method is called. Beans do not continue to maintain these parameter variables after the method call is completed. Thus, all instances of all stateful session beans are the same unless it is in the method call. In this way, the stateless session beans can support multiple users. The container can declare a stateful session beans. You can specify any Session Beans to any user.

Entity Beans provides a view of the data in the database. For example: an Entity bean can simulate a line of data in a database table. Multiple clients can share access to the same entity bean. Multiple Client can also access the same Entity Bean.EnTity Beans to access or update the underlying data through the context of the transaction. In this way, the integrity of the data can be guaranteed. Entity Beans can survive the time of relatively long, and the status is continuous. Entity Beans has always survive as long as the data in the database exists. Not in accordance with the application or service process. Even if the EJB container crashes, Entity Beans is also survived. The Entity Beans life cycle can be managed by the container or Beans. If the container is controlled to ensure continuous ISSUS for Entity Beans. If you manage it yourself by Beans, you must write the code of Entity Beans, including access to the database.

Entity Beans is identified by the primary key (a unique object identifier) ​​of Primary Key). Typically, the primary key is the same as one of the data in the identity database, such as one line in a table, and the primary key. The primary key is that the client is able to locate a specific data block.

Fourth, develop EJB

1, class introduction:

The main steps of developing EJBs Generally, the entire development step (development, configuration, assembly) includes the following aspects. Development: First, you must define three classes: Bean class itself, BEAN's local and remote interface classes. Configuration: The configuration includes generating a configuration descriptor - this is an XML file that declares the attribute of Enterprise Bean, binds the bean's class file (including the stub file and the Skeleton file). Finally, put these configurations in a JAR file. It is also necessary to define environmental properties in the configurator. Assembly application: Includes Enterprise Beans to the Server server to test the connection of each layer. The program assembly combines several Enterprise Beans with other components. Combine into a complete application. Or combine several Enterprise Beans into a complex ENTERPRISE BEAN. Manage Enterprise Bean. We must define and write basic classes in EJB. Such as Enterprise Bean: This is the implementation of Enterprise Bean internal application logic. Write the remote interface class for Enterprise Bean. Write the local interface class for Enterprise Bean. Description Primary key, primary key class is only required for Entity Beans. Specify the name of the primary key in the Configuration Descriptor of Enterprise Bean. The Enterprise Beans provider defines the remote interface and the local interface to implement the EJB class itself. The client invoked the EJB implemented interface in the Remote Interface. The HOME interface provides a way to generate and locate the Remote interface instance.

In the implementation of the Enterprise Bean itself, there is no formal connection between the local home interface, and the remote Remote interface (such as inheritance relationship). However, the methods declared in three classes must abide by the specification defined in EJB. For example: You declare an application method or application logic in Enterprise Bean. This method is also declared in the Remote interface of Beans, then these two places must be the same name. There must be at least one crete () method in the implementation of the bean: ejbcreate (). However, there can be multiple CREATE () methods with different parameters.

In the Home interface, you must also have the same method definition (the number of parameters is the same). EjbcReate () method returns a persistent object for container management. They all returns a host key value for container management persistence. However, the type of return value in the corresponding CREATE () method of Home is the Remote interface.

Note: The EJBCREATE method implemented by the entity bean is a bit different. Entity Beans may not define the EJBCREATE method. If the entity is applied to the database through the application or through the database management program, the entity bean omits the EJBCREATE method. The value returned by EJBCREATE is the primary key type. If the EJBCREATE method is a method of managing persistence of persistence, its return value is a null type. If the entity bean implements the persistence of bean management, the EJBCREATE method is the primary key type of the returned value. The task of the container is to combine the implementation classes of each interface and Enterprise Bean. Ensure that the interfaces and implementations are corresponding when compiling and running.

EJB's implementation class, each interface should be inherited from different base classes. A session bean must realize the base class javax.ejb.sessionBean. The entity bean must realize the base class javax.ejb.entiybean. These EJB base classes are inherited from Javax.ejb.EnterpriseBean. Javax.ejb.EnterpriseBean is inherited from java.io.serializable. Every Enterprise Bean must have a Remote interface. The Remote Interface defines the logical operation that the application specifies the customer call. These are some public methods that can be called by the customer, usually implemented by the Enterprise Beans class. Note that Enterprise Bean's customers do not directly access beans. Instead, it is accessed through the Remote interface. The Remote interface of the Enterprise Bean class extends the public Java interface of the Javax.ejb.EJBObject class. Javax.ejb.ejbObject is the base class for all Remote interfaces. Code is as follows: package javax.ejb; public interface EJBObject extends java.rmi.Remote {public EJBHome getEJBHome () throws java.rmi.RemoteException; public Object getPrimaryKey () throws java.rmi.RemoteException; public void Remove () throws java .rmi.remtoeexception, java.rmi.removeexception public handle getHandle () throws java.rmi.RemoteException; Boolean isidentical (EJBOBJECT P0) throws java.rmi.RemoteException;}

The getejbhome () method allows you to get a related HOME interface. For entity beans, the primary key value of entity beans is obtained by getPrimaryKey () method. Remove () can delete an Enterprise Bean. Specific semantics are explained in context in the life cycle of various different types of Enterprise Beans. Method GetHandle () returns a persistent handle of an Enterprise Bean instance. The isindentical () method allows you to compare if Enterprise Beans is the same.

2, method:

The method in all Remote interfaces must be declared as public (public) and must throw java.rmi.RemoteXception. In addition, the parameters defined in all Remote interfaces must be valid in RMI-IIOP. For each method defined in the Remote interface, there must be a corresponding method in the Enterprise Bean class. Corresponding methods must have the same name, the same type, and quantity parameters, the same return value, and also throw the same exception. The following code showed an ATM example of the Remote interface ATM of the session bean ,. Declare an application method TRANSFER (). The black body part indicates that some content must be in the EJB specification. The REMOTE interface must expand the javax.ejb.ejbobject class. Each method from the Enterprise Bean call from the client must be declared in the Remote interface. The transfer () method throws two accidents. The InsufficientFundSexception exception is an accident defined by the application. Public Interface ATM EXTENDS JAVAX.EJB.EJBOBJECT {Public Void (String Source, String Target, Float Amount) throws java.rmi.RemoteException, insufficientfundsexception;}

The HOME interface must define one or more Create () methods. Each such CREATE () method must be named CREATE. Also, its parameters, whether it is a type or quantity, it must correspond to the EJBCREATE () method in the bean class. Note that the return value type of the EJBCREATE () method in the home interface in the Home interface is different. The Home interface of the entity bean also includes a Find () method. Each HOME interface extends the Javax.ejb.ejbHome interface. The following code shows the definition of the javax.ejb.ejbhome interface:

package javax.ejb; public interface EJBHome extends java.rmi.Remote () {void remove (Handle handle) throws java.rmi.RemoteException, RemoveException; void remove (Object primarykey) throws java.rmi.RemoteException, RemoveException; EJBMetaData getEJBMetaData ( "THROWS RemoteException; HomeHandle GethomeHandle () THROWS RemoteException;

Here, two remove () methods are provided to delete instances of Enterprise Beans. The first Remove method is to remove an instance of an Enterprise Bean through a handle. The second REMOVE method deletes an instance of an Enterprise Bean through a primary key. In numerous Enterprise Bean instances, the handle is uniquely identified an instance. A handle has the same lifetime as the Enterprise Bean it references. Considering an entity object, the customer can re-obtain an instance of the corresponding Enterprise Bean through a handle. A handle can correspond to multiple instances of an Enterprise Bean object. For example, even if the host where the Enterprise Bean object is located, or the ENTERPRISE BEAN object moves between different machines, the handle is still valid. The handle here is a Serialized handle, a reference to a CORBA object serialized with characters in CORBA. The second REMOVE operation in the EJBHOME interface determines the Enterprise Bean to be deleted through its primary key. The primary key can be any type of the Java Object class, however, you must implement Java serializable interface. The primary key is the main method of identifying the entity bean. Typically, the primary key is a keyword in the database, uniquely defining data represented by entity beans. Method GeTejbMetadata () returns the Metadata interface of the Enterprise Bean object. This interface allows customers to get metadata information for Enterprise Beans. When developing tools to compile link applications, or when configuring tools to configure, Metadata information may be used. Javax.ejb.ejbmetata interface provides a method of obtaining a javax.ejb.ejbhome interface, home class, remote interface, and a primary key. A iSSSSON () method is also provided to determine that the object in which this HOME interface is session bean or an entity bean.

The isStateLessSession () method indicates that this session bean is status or stateless. The following code shows the code for the defined section of the javax.eb.ejbmetadata interface.

Public javax.ejb; Public interface EJBMetaData {EJBHome getEJBHome (); Class getHomeInterfaceClass (); Class getRemoteInterfaceClasss (); Class getPrimaryKeyClass (); Boolean isSession (); Boolean isStatelesssSession ();}

For each Create () method, the EJB specification defines the following naming convention. Its return value is the type of Remote interface of the session bean. The name of the method can only be CREATE (). Every ejbcreate () method in the session bean class must have a CREATE () corresponding. The type and quantity of the parameters of each CREATE () method must correspond to the EJBCREATE () method in the session bean class. Methods must throw java.rmi.RemoteException. Methods must throw javax.rmi.createexeption. The parameter of the CREATE () method is used to initialize the new session bean object. The following code shows the different Create () methods of a session bean object, where the part must be displayed with bold: public interface atmhome extends javax.ejb.ejbhome {atm crete () throws java.rmi.RemoteException, javax.ejb. CreateException; Atm create (Profile preferredProfile) throws java.rmi.RemoteExeption, javax.ehrows java.rmi.RemoteException, RemoveException; EJBMetaData getEJBMetaData () throws RemoteException; Homehandle getHomeHandle () throws RemoteException;}

Here, two remove () methods are provided to delete instances of Enterprise Beans. The first Remove method is to remove an instance of an Enterprise Bean through a handle. The second REMOVE method deletes an instance of an Enterprise Bean through a primary key. In numerous Enterprise Bean instances, the handle is uniquely identified an instance. A handle has the same lifetime as the Enterprise Bean it references. Considering an entity object, the customer can re-obtain an instance of the corresponding Enterprise Bean through a handle. A handle can correspond to multiple instances of an Enterprise Bean object. For example, even if the host where the Enterprise Bean object is located, or the ENTERPRISE BEAN object moves between different machines, the handle is still valid. The handle here is a Serialized handle, a reference to a CORBA object serialized with characters in CORBA.

The second REMOVE operation in the EJBHOME interface determines the Enterprise Bean to be deleted through its primary key. The primary key can be any type of the Java Object class, however, you must implement Java serializable interface. The primary key is the main method of identifying the entity bean. Typically, the primary key is a keyword in the database, uniquely defining data represented by entity beans. Method GeTejbMetadata () returns the Metadata interface of the Enterprise Bean object. This interface allows customers to get metadata information for Enterprise Beans. When developing tools to compile link applications, or when configuring tools to configure, Metadata information may be used. Javax.ejb.ejbmetata interface provides a method of obtaining a javax.ejb.ejbhome interface, home class, remote interface, and a primary key. A iSSSSON () method is also provided to determine that the object in which this HOME interface is session bean or an entity bean. The isStateLessSession () method indicates that this session bean is status or stateless. The following code shows the code for the defined section of the javax.eb.ejbmetadata interface. Public javax.ejb; Public interface EJBMetaData {EJBHome getEJBHome (); Class getHomeInterfaceClass (); Class getRemoteInterfaceClasss (); Class getPrimaryKeyClass (); Boolean isSession (); Boolean isStatelesssSession ();}

Five, EJB programming environment:

1, use jbuilder

JBuilder and EJB Container are seamlessly connected. JBuilder and Inprise application servers include tools for developing and configuring Enterprise Beans, and libraries required: Run and Manage Enterprise Beans, Naming Services, Transaction Services, Java Databases, APIs needed to develop Enterprise Beans, an enhancement Java-to-IIOP compiler, support value type, and RMI signal, etc.

JBuilder also provides a tool and wizard for fast development applications Enterprise Beans. By simple and intuitive steps, the wizard helps you build an Enterprise Bean. I set some default values, generated the template of the bean. Only, we can add our own application logic. JBuilder also provides an EJB interface generation wizard. The wizard generates a Remote interface and a Home interface based on the public method of Enterprise Bean. JBuilder also provides a wizard of a configurator to help us build an XML descriptor file step by step. And generate the Stubs to a JAR file.

2. Use an integrated environment other than JBuilder:

If you use other integrated environments (IDEs). To determine the container tools that integrated analog environment IDE. Also verify that the IDE supports the corresponding version of the EJB specification, and it is necessary to determine if it is correctly supporting the EJB API.

To determine the version of the JD to the supported EJB container. You can determine the version of the support JDK supported by the EJB container by checking the installation instructions of the Inprise.

When configuring Enterprise Beans, you must use the tools provided by the INPRISE application server. These tools can edit and modify the INPRISE configuration descriptor provided by third-party agents. It is also possible to verify the configuration descriptor to verify the source code of the bean. Six, a simple Hello example

1, install APUSIC APPLICATION Server

Note: The following is the installation process of the APusic Application Server as an example. For other platforms, please refer to the APUSIC Application Server installation manual.

Download JDK1.2, Apusic Application Server must run in a JDK 1.2 environment. You can download the latest JDK from the following site.

http://java.sun.com

Download Apusic Application ServeRapusic Application Server Trial You can get from the following URL:

http://www.apusic.com/download/enter.jsp

After the download is complete, you can get a parcel file apusic.zip, select the installation directory, assume it to install it to / usr, use the following command:

A directory APUSIC will appear under CD / USRJAR XVF APUSIC.zip / usr, and all programs of the APUSIC Application Server are extracted under / usr / apusic. Add the following path to classpath /usr/apusic/lib/apusic.jarricanjava_home/lib/toLs.jar

Run the APUSIC Application Server with the following command

Java -XMS64M com.apusic.server.main -root / usr / apusic

2. Define EJB Remote Interface (Remote Interface)

Any EJB is called via Remote Interface, and EJB developers first define this EJB can be called all methods of being called in the Remote Interface. The class that executes the Remote Interface is generated by the EJB generation tool.

The following is the Remote Inteface program of HelloBean:

Package ejb.hello;

Import java.rmi.RemoteException; import java.rmi.remote; import javax.ejb. *;

Public interface hello extends ejbobject, remote {

// this Method Just Get "Hello World" from HelloBean.public String Gethello () THROWS RemoteException;}

3. Define Home Interface

The EJB container creates an EJB instance via the HOME interface of EJB, like the Remote Interface, and executes the Home Interface class is generated by the EJB generation tool.

The following is the HELLOBEAN's Home Interface:

Package ejb.hello;

Import javax.ejb. *; import java.rmi.remote; import java.rmi.RemoteException; import java.util. *;

/ *** this interface is extremely simple it declares online. * / Public interface hellohome extends ejbhome {public hello create () throws createException, RemoteException

}

4, write EJB classes

In the EJB class, the programmer must give the specific implementation of the remote approach defined in the Remote Interface. The EJB class also includes a method that must be implemented in some EJB specification. These methods have a more unified implementation template, and the programmer only costs in the implementation of the specific business method.

The following is the Hellobean code:

Package ejb.hello;

Import javax.ejb. *; import java.util. *; import java.rmi. *;

Public Class HelloBean Implements SessionBean {Static Final Boolean Verbose = true;

Private Transient sessionContext CTX;

//Mplement the methods in the sessionbean // interfacepublic void ejbactivate () {if (verbose) System.out.println ("Ejbactivate Called");}

Public void ejbremove () {if (verbose) System.out.println ("Ejbremove Called");}

Public void ejbpassivate () {if (verbose) System.out.println ("ejbpassivate caled";

/ *** sets the session context. ** @Param sessionContext * / public void setsessionContext (sessioncontext ctx) {if (verbose) system.out.println ("setsessionContext caled); this.ctx = ctx;}

/ *** This method corresponds to the create method in * the home interface HelloHome.java. * The parameter sets of the two methods are * identical. When the client calls * HelloHome.create (), the container allocates an * instance of The ejbean and calls ejbcreate (). * / public void ejbcreate () {if (verbose) System.out.Println ("ejbcreate caled");} / *** **** Here is the business logic **** ** The getHello Just Return A "Hello World" string. * / Public string getHello () throws remoteException {return ("Hello World");}} 5, create an ejb-jar.xml file

The EJB-JAR.XML file is the deployment description file of EJB, including the various configuration information of EJB, such as the state bean (Stateful Bean), stateless bean (STATELESS BEAN), trading type, etc. See the EJB specification for more information on EJB-JAR.XML files. The following is a Hellobean profile:

http://java.sun.com/j2ee/dtds/ejb-jar_1_2.dtd ";> Hello Ejb.hello.hellohome ejb.hello.hello ejb.hello.hellobean stateless < Transaction-type> Container Hello * Required 6, compilation and deployment

Compile the Java source file and package Class and EJB-JAR.XML to Hello.jar after compiling

Mkdir Buildmkdir Build / Meta-Infcp EJB-JAR.XML Build / Meta-Infjavac -d Build * .javacd Buildjar CVF Hello.jar meta-inf ejbcd ..

Generate the JAR file that can be deployed to the APusic Application Server with the EJB tool:

Java com.apusic.ejb.utils.ejbgen -d /usr/apusic/classes/hello.jar build / hello.jar

Add /usr/apusic/classes/hello.jar to ClassPath

Add Hello.jar to the APUSIC Application Server configuration file. Add the following lines in /usr/apusic/config/server.xml:

Classes / Hello.jar Hello HelloHome < / bean>

Start server

Java -XMS64M com.apusic.server.main -root / usr / apusic7, write client call

You can call Hellobean from Java Client, JSP, Servlet, or other EJB. Calling EJB has the following steps: Get the EJB Home Interface by JNDI (Java Naming Directory Interface) Creating an EJB object via EJB Home Interface, and getting its Remote Interface call EJB method via Remote Interface

The following is an example of calling Hellobean from Java Client:

Package ejb.hello; import javax.naming.Context; import javax.naming.initialcontext; import java.util.hashtable; import javax.ejb. *; import java.rmi.RemoteException;

/ *** @Author Copyright (c) 2000 by apusic, inc. All rights reserved. * / Public class helloclient {public static void main (string args [= ") {string url =" RMI: // localhost: 6888 "; Context initCtx = null; HelloHome hellohome = null; try {Hashtable env = new Hashtable (); env.put (Context.INITIAL_CONTEXT_FACTORY, "com.apusic.jndi.InitialContextFactory"); env.put (Context.PROVIDER_URL, url); INitctX = new initialcontext (ENV); (Exception E) {system.out.println ("Cannot Get Initial Context: E.getMessage ()); System.exit (1);} try {hellohome = (HelloHome INitctx.lookup ("HelloHome"); Hello Hello = HelloHome.create (); string s = hello.getHello (); system.out.println (s);} catch (exception e) {system.out.println E.getMessage ()); system.exit (1);}}

}

Run HelloClient, you can get the following output: Hello World

EJB (Enterprise Javabeans) can not be a new concept, but many people will be dizzy when they hear or see this noun. The EJB component is bundled in the J2EE specification, bundled the application's representation layer and the backend information system (such as a database or main frame computer). The EJB architecture uses both the functionality of the EJB object and uses the environment they run. Why is an EJB from a conceptually seen, EJB object encapsulates business objects and their concepts, allowing developers to focus on the details of the solution. From a design perspective, EJB should be light and interacting. This initiative can make a single EJB, whether it may use an EJB representing independent development or the third party manufacturer to develop, whether it is a business application. It can be used in a variety of applications. For example, CRM (customer relationship management) tool and electronic user. These have been configured with adaptive objects to illustrate the XML file of EJB in deployment descriptors. The deployment descriptor allows you to modify EJB properties and behavior without recompilation. EJB's office EJB object resides in the EJB container, the latter is a environment where developers provide various services. The container may be responsible for processing security, transaction, and instance management depending on the specific configuration. Since the programmer does not need to complete these tasks, the development time is greatly saved. There is a significant difference between the two concepts of J2EE servers and EJB containers, and EJB containers may belong to a part of the J2EE server, but it is not necessarily a necessary component. In the case of a J2EE server component, the EJB client usually takes the form of Java Servlet or JSP. However, due to the cancellation of the ITE level of the J2EE web layer, the standard EJB container service can accept multiple types of client programs, requested by applications written in Java or other languages. Communication with EJB containers is the prerequisite for customer operation. EJB content EJB object is divided into the following three categories:

· Session Beans

· Entity Beans

• Message Driver Beans determines the Bean type used by the bean behavior according to the required Bean. The role of the session beans session (Session) Beans is based on the session. After the client requests and receives the bean function, the session with a specific bean is terminated and does not leave a record of the session. The session bean type can also be further subdivided into stateless or state. The stateless session beans do not know the customer or the context of the requested request, thereby making it an ideal tool for a single request / response application. For example, the bug tracking system for a user searches all public bugs is this. The client application contacts a stateless session bean and delivers the search parameters. Next, this bean accesses the database, selects an entry that matches the search criteria, and retransmits the record back to the client. After the communication is complete, Bean does not retain interactive information. Therefore, multiple client programs can access stateless session beans at the same time, but they will not interact. Conversely, stateful session beans will connect the request with a specific customer to establish a one-to-one relationship between the customer and the bean. Shopping cart bean is an example. User implements a standard e-commerce task, add the product in the shopping cart, and enter the address information and then subscribe. Shopping cart beans maintain state, so it knows that all of these variables are associated with a particular customer. Entity Beans Entity (Entity) Beans indicates business objects or data that have long after session termination. They usually exist as a single record in the database, of course, its storage form may also adopt other media, such as files, and the like. An object represents a user, has a name, contact information, language selection, and so on, which represent the use of entity beans. As one of the most essential connotation of persistence, the unique identification of the entity bean acts as a role of identifying and retrieving the correct object information. Entity Beans requires primary keys as a unique identifier for the "secondary" package object. The two Beans types above the BEANs are served in EJB customers in synchronization. The customer issued a request and then waited for the bean to send the result. Message Driven Beans Avoid this possible bottleneck problem. The Java Messaging Service is used in Java Messaging Service. The client can generate a message and publish the message to the message queue. Message Driver Bean uses or retrieves messages to perform its content. This event or data is communicated into an asynchronous form; customers or beans do not need to rely on the direct response of the other party. For example, a bank official in London uses an application to publish the latest exchange rate message. At this time, the deployment of an external trading bean in Boston gets this message from the message queue and updates the relevant records in the database. In the ideal case, the message-driven bean transmits the information to an entity bean that handles the database transaction. In this way, each bean forwards it unable to process tasks to create a real distributed component structure. The principle of EJB does not consider the category of EJB, and the above three types form an EJB object: the implementation of the local interface, remote interface and bean. The client uses Java Name and Directory Interface JNDI (Java Naming and Directory Interface) to locate the local interface (JNDI) of the bean. The local interface then returns an instance of the remote interface, while exposing the necessary Bean implementation methods. The client program calls the appropriate method. The code shown in List A illustrates the above process.

Listing a first comes The EJB Client Class-in this case, a Very Simple Stand-alone user interface: import javax.ejb. *; Import javax.naming. *; Import java.util. *; Import org.shifter.ejb. *; public class VerySimpleClient {public static void main (String [] args) {try {Context ctx = getInitialContex (); VerySimpleHome home = (VerySimpleHome) ctx.lookup ( "simpleton"); VerySimple ejb = home.create (); Ejb.setname ("Fredrick"); system.out.println ("my name is" ejb.getname ()); ejb.remove ();} catch (exception e) {E.PrintStackTrace ();}} PUBLIC static Context getInitialContext () throws NamingException {// Retrieve the Context via JNDI lookup}} Now, we define the Home and Remote interfaces The client interacts directly with these classes: package org.shifter.ejb; // The home interface import javax. .ejb *;. import java.rmi.RemoteException; public interface VerySimpleHome extends EJBHome {public VerySimple create () throws CreateException, RemoteException;} package org.shifter.ejb; // The remote i nterface import javax.ejb *;. import java.rmi.RemoteException; public interface VerySimple extends EJBObject {public String getName () throws RemoteException; public void setName (String n) throws RemoteException;} Finally, we have the implementation of the EJB, where all functionality occurs: package org.shifter.ejb; import javax.ejb *; public class testertwoEJB implements javax.ejb.SessionBean {// Member variables private String name; private SessionContext ctx;.

// Default constructor public testertwoEJB () {} // Called by the create () method of the home interface.public void ejbCreate () {} // Called by the remove () method of the home interface.public void ejbRemove () {} // Called when the EJB container makes this bean active.public void ejbActivate () {// Resource allocation might go here.} // Called when the EJB container makes this bean inactive. public void ejbPassivate () {// Resource Clean Up Might Go Here.} // set the runtime context public void setsessionContext (sessioncontext ctx) {this.ctx = ctx;} // ***** // the folload methods area the only ones visible // to ejb clients THROUGH this bean's remote interface. // ***** public string getName () {return name;} public void setName (String n) {name = (n! = null)? N: "igor";}} you may Additional methods need to be implemented according to the type of beans. For example, if the customer needs to locate the entity bean, then your local interface will include the FindByPrimaryKey () method, which uses the primary key class as its parameters to return the appropriate object. As early as possible, the deployment descriptor packaged by each EJB object tells the behavior of the EJB container object. One of the descriptors, that is, the so-called ejb-jar.xml is to complete the above functions, which is a stateless session bean with all methods of container management transaction, as shown in List B.

Listing B VerySimple org.shifter.ejb.verysimpleHome org.shifter.ejb. VERYSIMPLE org.shifter.ejb.verysimpleejb stateless container VERYSIMPLE * Required According to the type of EJB container, another deployment descriptor tells the container how to identify and locate using JNDI BEAN. Taking the WebLogic server as an example, this role is WebLogic-EJB-JAR.XML, and the situation is shown in the program list C. Listing C VERYSIMPLE SimpleTon The usage of all EJBs involves some inherent dangers and possible problems. Programmers must comply with a lot of grammar and behavioral rules when encoding the EJB object. They must also determine the persistence management of bean itself or EJB containers; selecting errors may be data. Containers can even crash to destroy the event's session beans. The container may also lose information when trying to rollback transactions. Deploying an EJB object is a monotonous repetition process, which is almost impossible to make debugging in the case of the container source code. However, EJB component is highly highlighted, which saves its code, saving a lot of time and money during the development process. Developers can focus on the business logic itself, and deliver tasks such as security and transaction rollback to the EJB container. Reliable object instance management and convenient configuration is the highlight advantage of EJB. Learning and mastering the design rules of EJB is indeed a very time and effort, but its structure itself produces a very beneficial benefit during the development of applications. Author: BUILDER.COM

Deployment Procedures Enterprise JavaBeans (EJB) components are installed in a specific process called deployment. Support for deployment procedures by the container assembly. At the high level, the deployment consists of the following steps: BEAN developers create the required class file, interface file, and control information. Container analysis Enter files and generates the necessary classes. The container adds an entry to the JNDI namespace pointing to the local object. The developer of the EJB component writes the BEAN's Java source file, which contains the business logic method for this bean, and includes the ejbcreate () method. The Bean class must also implement a javax.ejb.sessionBean interface or a javax.ejb.entityBean interface. In addition, Bean's developers write interface files to define an extension to javax.ejb.ejbhome interfaces and javax.eb.ejbobject interfaces. The EJBHOME interface is extended, called the BEAN's local interface, including a creation method, and if the bean is an entity bean, it also contains a Finder method. The extension of the EJBObject interface is called the Remote Interface of the bean, specifies the business logic method defined in the bean itself. BEAN's developers provide control information consisting of deployment descriptors, environmental properties, and list files. The deployment descriptor is a serialization instance of a javax.ejb.deployment.sessionDescriptor object or a javax.ejb.deployment.EntityDescriptor object. Environmental Properties As the key-value pair stored in a file, this file can be accessed via the Java.util.Properties object. The single file is required to identify enterprise beans and its related files. Enterprise beans class files, class files, deployment descriptor files, environmental properties files, and monitored files are archived using file formats named EJB-JAR. The generated EJB-JAR file is provided to the container as an input to the deployment process. At deployment, the container analyzes the contents of the EJB-JAR file and takes the necessary operations to make this bean available. These operations include generating a new Java class that implements the local and remote interfaces of Beans, and the local interface is bound to the JNDI namespace, generating pile modules and Skeleton Helper classes, which are required to support RMI communications. The container can also generate a subclass of the bean, incorporating the code-specific code to facilitate the management of Beans. The class generated by the container is usually dedicated to the container, and is portable as the EJB component itself. Persistence, transaction, and safety provide persistence, transaction and security services for EJB components, EJB containers can play a major role. Is the responsibility of these services to the container or assume that the responsibility is responsible by bean itself, and the EJB specification provides flexibility in developers of Beans. For example, persistence support for entity beans can be managed by bean or by container management. If the EJB component developer chooses to use the container management persistence, they will add a property called ContainerManageDfields in the deployment descriptor. Depending on the EJB specification: "The value of the ContainerManageDfields property is a list of instance fields, the enterprise-level bean provider wants, the container manages these instance fields by loading or stores it from the database, the enterprise-class bean code should not contain any database access Calling - Database Access Call will be generated by the container tool in deployment. "Dedicated to the container that provides container management persistence support, usually provides a rich deployment time tool to allow enterprise-class Bean deployers to establish instance fields to basic data sources. Mapping.

It is generally believed that although the container provider's tool simplifies the mapping process, the mapping process may still involve the Bean deployer (ie the mapping process is not fully automatic). "Enterprise JavaBeans Specification 1.0) In addition to supporting container management persistence, the EJB architecture also supports the management of containers to transactions. This specification specifies:" Enterprise JavaBeans is a Advanced Component Framework, which trying to make application developers The complexity of the system. Therefore, most enterprise beans and their clients do not need to access transaction management through program. "Enterprise Javabeans Specification 1.0) When the BEAN's developer relies on the container, it is called the container management trimming, the container is used in the transaction attribute provided by the deployment:" Whenever the client calls enterprise beans, containers Will involve this method call. This intervention allows the container to explicitly control the transaction bound by transaction attribute. For example, if the enterprise-class bean deploys the TX_Required transaction property, the container will automatically start the transaction whenever the client calls the enterprise bean that supports transactions, and the client does not associate with any transaction context. "Enterprise JavaBeans Specification 1.0) If the developer chooses to support transactions within Beans, they specify the TX_Bean_managed transaction property in the deployment descriptor, and then you can freely use the Javax.Transaction.Usertransaction interface to divide the transaction boundary in Bean itself. Out of the TX_Bean_managed transaction property, the container knows that there is no need to intervene transaction support. By enhancing the restrictions specified in the AccessControlEntry object and the RunaS security ID, the container provides secure support for EJB components. AccessControLEntry objects on the bean level or for a single method, the Identity object Enterprise-class beans associates. Edentity object reflects users or roles that allow calls to beans. When the container is trying to access the data source or another bean, they will also apply Runas security identities to the EJB component. You can set the Runas identity as equivalent A particular user account, a system account or client security identity. Access control and RunaS information is specified in the deployment descriptor in the deployment descriptor, which will affect the container management bean. Although the EJB 1.0 specification also refers to security issues, more detailed security features, see subsequent versions of this specification. The relationship between CORBA and EJB technology Request a proxy architecture (CORBA) is a platform neutral and language of distributed objects. The neutral computing environment lays the foundation. In the CORBA environment, the function resides in the object, and the client can access these objects through the object request agent (ORB). The complete CORBA implementation provides ORB, which is called CORBA object service. Several runtime services for the CORBA utility. You can also provide only ORBs, which do not provide associated object services and utilities (for example, IBM provides such two independent ORBs). Software that implements basic ORB function is called ORB Core. In order to support language-independent, the CORBA application is written in the interface definition language (IDL). This language is similar to C in syntax, but does not include semantic: The operation specified in the IDL is an operation interface, not an operation implementation. Because of its support for multiple platforms and multiple languages, CORBA is ideal for managing the size of the company's size. Design EJB specification is also to support enterprise information systems.

Say this, is CORBA a competitor? According to the frequently asked Questions for Enterprise JavaBeans, the answer is negative: "In fact, EJB technology has a great supplemental Corba.Corba provides a powerful standard infrastructure that builds EJB servers on this structure .EJB technology. Enables the top floor of the CORBA infrastructure to build applications easier. "(Enterprise JavaBeans Frequently Asked Questions) Although the EJB specification and CORBA specification descriptions are different technologies, EJB implements certain aspects of current using CORBA technology. An example is RMI / IIOP. EJB specification requires EJB components and its containers to use Remote Method Invocation (RMI) technology to implement method calls between distributed objects. RMI specifies the syntax and semantics of the remote method, but does not specify which transport protocols should be used to provide network connections. The CORBA Internet Object Request Agent Protocol (IIOP) basically defines a method of transferring CORBA messages through TCP / IP. Developing an EJB implementation using the IIOP message form to exchange RMI data, how the EJB application can effectively use the part of CORBA technology. This network also supports interoperability with the CORBA application, which uses IIOP to send local CORBA messages, independent of RMI. IBM's EJB implementation, WebSphere Application Server, optimizes IIOP usage, how to make a clear distributed object reside on the same server and only call IIOP when the object is actually remote. In order to facilitate the development of enterprise systems that are incorporated into EJB technology, Sun Microsystems created a mapping between EJB specification and CORBA. The EJB architecture is mapped to CORBA, which affects several aspects of EJB technology, including object distribution, naming, and transactions. The main purpose of the CORBA mapping is to ensure interoperability between the EJB servers constructed by different manufacturers. Interoperability offers the following benefits: CORBA client can access the EJB component client program on CORBA-based EJB server can call to CORBA objects in transactions, and mix with the enterprise-class bean's call. Multiple beans, while these beans are also located on CORBA-based multi-EJB servers from different vendors using ORB clients from a vendor, and can access another manufacturer's CORBA-based EJB server to beans to access EJB components. The CORBA client, the bean interface is mapped to IDL. For example, the Buy () and Sell () methods defined in the stock trading bean can be specified as CORBA operations in the IDL file. Non-Bean's CORBA client, such as a C client, you can access this bean, and use standard CORBA call to call the bean method. If the container uses IIOP as its distributed object protocol, the duties of the container are to generate IDLs corresponding to enterprise-class beans and their interfaces. EJB Naming Services, which is based on the CORBA Object Services Naming service, so that the EJB component can be used for CORBA clients.

Java Naming and Directory Interface (JNDI) provides an interface to the CORBA naming service, and the client can access the service through the JNDI call indirect access to the underlying naming service, or you can access the service directly through the CORBA Object Services (COS) name API. EJB transaction supports Corba Transaction Service (Object Transaction Service (OTS). Java Transaction Service (JTS) represents the Java binding of the OTS, which is language neutral. CORBA-based EJB containers must identify transactions issued by the CORBA client through the OTS interface, and the EJB application emitted through the Java Transaction API interface, JTA is an application-level interface to JTS. The JTA also represents the Java binding of the Open Group XA interface to connect the application resource to an external transaction manager. The JAVAX.TRANSACTION.USERTRRANSACTION interface in JIA provides an API for the application level control of the transaction boundary. Usertransaction interface, which can be used as a bean with TX_Bean_Managed from its transaction property to be used by Java clients. Using EJB components Because the EJB architecture is designed to be highly flexible and supports the use of any complicated way to connect the enterprise bean, many different scenarios can be constructed, and how the application can use Enterprise Beans. A useful solution proposes to represent the EJB component as a key component of the three-layer information system, which connects the enterprise data, transaction, and application resources to the web. The EJB-based three-layer programming model will depend on the web browser as the first layer, and the web server supporting the application is the second floor, depending on the enterprise information resources as the third layer. In this programming model, in addition to EJB technology, Java Servlet technology, JavaBeans technology, and Java Server Page (JSP) technology are also implemented. The figure below shows the arrangement of each layer: The first layer is a thin client-typically a web browser, which can handle normal web data types such as HTML and GIF, and support HTTP communication. The second layer is a web application server, which is a web server with code to deliver running for applications that can be called through the web server. Existing web applications are used along the CGI-BIN programming model, but it is expected that the second-layer application development will turn to the Java Servlet programming model, which provides significant improved performance and portability. In addition to supporting Java Servlet, the web application server will also add an EJB server function to support applications using EJB components. The third layer represents enterprise information resources, which can include relational databases and object-oriented databases, transaction monitors, and customized applications. EJB technology plays a key role in this design because it resides in the second layer of application components, and the interface between the third floor, it is standardized. Java Servlet, Java Beans, and Java Server Page are not essential elements for the EJB application solution, but they can work with the EJB component to provide Java-based cohesive application environments.

The environment depicted here will assign the following responsibilities to the Java component participating in the work: Specify the Java Servlet's role JSP page processing data representation and user interface Java Bean acts as a "data package", storage intermediate The result of the data EJB component provides a mechanism for accessing the enterprise information resource. You can use a hypothesis, EJB-based web application update existing inventory, and use container management persistence and container management transactions, will access the inventory database location package Inside the entity EJB assembly. Inventory tickets can be entered via web browser, the browser provides an HTML form to capture product numbers, suppliers, etc., and call a servlet when submitted. The servlet code acts as an application controller role to determine which corporate databases need to be updated, requiring users to apise the information. The servlet can access the main inventory database by representing its entity bean, and call the JNDI interface to get a reference to the local object of this bean, and then use the finder method to locate the remote objects of the requested product number. At this time, by calling the remote object, the servlet can update the inventory count, and then the container will delegate this method to the EJB component. Because the container is updated according to the database, it is maintained in the transparent manner to the BEAN transparent, and the data is written to the database to ensure data persistence, so the data is maintained. Any result information returns from the EJB component to the servlet, you can use the setter method to store in an attribute of a (non-enterprise) Java Bean. The servlet can transfer control to an appropriate JSP page to combine these results into the representation and return the result to the user. The JSP page is likely to be composed of static text and variable information placeholders related to a single transaction. The JSP page uses the Getter method to get variable data elements from the Java Bean before sending a data to the browser. EJB-based three-layer design provides several benefits, including: Accessing the business logic of enterprise data can be packaged in reusable, portable enterprise beans. Existing enterprise systems can be integrated into enterprise-class beans only need to be modified or do not need to be modified. The runtime services required by the enterprise application, such as transactions, and persistence, can be broken down from the bean and specify containers to this bean. You can modify the servlet of the Control Application Process without changing the EJB component. The Servlet code can focus on application control logic without considering data representation. The JSP page can be mixed together and generate information. System components written in Java language are portable for any platform with JVM. Conclusion In the process of developing an enterprise information system that supports key tasks, the EJB specification represents the next stage of development of Java technology. The EJB component extends to the server field with the JavaBeans specification, so that the development of business logic components can be reused across enterprise applications, and can transplant cross-supporting Java. Since it contains an Object distribution based on RMI technology, the discretion of multi-layer executable components is supported, allowing maximum implementation and high scalability. If the regular enterprise application runtime service is redefined as an object service that can be specified to the container, the developer that allows EJB components to concentrate on business logic, reducing the complexity related to the runtime service. And platform relevance. Enhance the Java operating environment to include standard interfaces, relational database access, transaction services, and remote object access, so that Java developers can write robust enterprise applications without having to leave the Java programming environment.

Use other Java technology-such as Java Servlet and JavaServer Pages technology - with EJB components, you can create a compact programming model for large enterprise systems, but because of using clever interfaces, it simplifies development work. . Moreover, because the EJB architecture is a logical extension of the JavaBeans component model, the business logic developed as an EJB component can be reused across multiple enterprise applications. Another benefit of an enterprise-level Bean architecture is to provide a direct integration channel of existing enterprise information systems, which may be unansee with the Java programming language or bean programming model. Because of existing enterprise information resources - custom new varieties for relational databases, transaction monitors, and business applications - can be connected to the web front end by encapsulating them in the EJB component, without replacing the application or rewriting the main code Segment, so customers protect their existing IT investments. Considering the huge prospects of EJB technology, the IT industry welcomes EJB specification with considerable interest, is not surprising. One of the biggest benefits provided by the EJB architecture may be to leave business logic programming with complex set components of business logic and enterprise-class server-side running environments. If the container deploys the EJB component has undertaken the role of the management runtime service (such as persistence, transaction, and concurrent database access), the BEAN's developer can freely focus on the software components of the development package business logic. Javasoft Vice President expressed the importance of EJB technology (from Sun Microstems website): "The 'Enterprise JavaBeans API will provide a new strategic weapon for enterprise developers and solution providers for them to build next-generation industry, Based on key business applications, the Vice President of the Javasoft Software Products for 'Sun Microstems, Jon Kannegaard, said:' Because applications designed with Enterprise JavaBeans API will work with existing enterprise systems, companies use Java platforms to get new The competitive advantage, but also retains their investment in prior art, 'Kannegaard continues. "Use Enterprise JavaBeans API, developers will be able to eliminate complexity during application development. This is possible because each Enterprise JavaBeans component encapsulates a basic business feature. At present, developers must know how to write business logic and specialized system-level procedures to control the ability such as security features and handle multiple transactions - a boring and complex task. Enterprise JavaBeans API enables all developers to focus on writing a logical solution to business issues, rather than concentrating on writing code to simplify different technologies. "(Press Release: Sun Releases Draft Enterprise JavaBeans Specification for Public Review) reference site by associated FAQs Sun-depth understanding of Java technology and EJB architecture access to Enterprise JavaBeans Specification 1.0, please see the Enterprise JavaBeans specification See the full press release... The IBM WebSphere Application Server uses EJB technology. The Summary Ken Nordby is a software engineer in IBM Software Development Laborators, which is located in Research Triangle Park in North Carolina.

As a member of the SWG Product Affinity Services business team, Ken works with IBMs developed and consulted for IBM WebSphere Application Server (IBM technology). You can contact Ken through nordby@us.ibm.com. What is ENTERPRISE JAVABEANS component? (1) Recommended: SIMON Category: Java Published: 2002-04-09 Popularity: 1781

Part 1: EJB architecture history and objectives This article provides an overprise javabeans (EJB) technology to allow readers to quickly understand the basic concepts. Part 1 describes the history and certain goals, advantages and techniques of EJB technology. For the sake of simplicity, there is a choice to tell some key elements of EJB technology. Note that although the EJB component relies on some basic Java services such as Java Transaction Service, the benefits of using EJB components and meet these components do not need to master the knowledge of these related technologies. Enterprise Javabeans Technology has been well received since 1998. The following paragraph is an example: "Since I have introduced more than two years, Enterprise JavaBeansTM technology has also maintained an unprecedented momentum in the development team of platform suppliers and businesses. This is because EJBTM server-side component model is simplified The development of the middleware components, these intermediate components are transactional, retractable and portable .Enterprise JavaBeans servers provide automatic support for middleware services such as transaction, security, database connection and other), decrease The complexity of the development of middleware. "(Sun Microsystems website) Enterprise JavaBeans This name uses Java Bean - this portable, reusable Java software component reputation. Enterprise JavaBeans technology extends the concept of Java components from the client domain to the server domain: This is a one-time meaning of Java technology growth. It has developed Java technology into a strong, retractable environment that supports tasks. Key enterprise information system. The Java Application on the server is a reason why you get praise in the web developer is that it supports downloadable Java programs called applets. The support of Applet is built into the Applet class to the Java Development Kit (JDK) of the 1.0 version. According to the Time framework of version 1.0, Java development is an applet and an application as a center. JAVA readings based on JDK 1.0 are from the perspective of Applet and applications: "Java programs consist of one of more class definitions, each class definition has compiled into its own Java virtual The .class file of the machine code. One of these classes must define a method called main () (), the program is starting from this method. To call a Java program, you need to run Java Interpreter Java, and specify main () The name of the method of the method. Please note that Java Applet is not an application - it is a Java class that is loaded and running the Java application (such as a web browser or applet viewer). "(See Flanagan) The Java In a nutshell) Java application can run on the server, but no matter whether it is in a client-server environment or in a web-based environment, JDK does not provide the Java application to the server machine. Or bag. Recognizing the potential of Java as a server language in the web environment, Sun Microsystems wrote the Java Servlet specification. Servlet is similar to applet, which is a Java program designed to run on a web server machine: "Servlet is a web component managed by the container, which can generate dynamic content.

Servlet is a small, unrelated to the platform, is compiled into an architecture code in the architecture. This code can be dynamically loaded on a web server and running it by this web server. The servlet interacts with a Web client through a request-response model implemented by a servlet container. This request-response model is based on the Hypertext Transfer Protocol (HTTP) behavior. "(See JavaSoft's" Java Servlet API Specification ") Under a web server control, run a number of small user programs on multiple servers, this idea is not fresh - a period of time, the public gateway interface (CGI) program ( It is often called the CGI script that has been playing this role and promotes the popularity of the Web. However, Java Servlet can achieve this with higher efficiency and portability, so it is expected to eventually replace the CGI program. Servlet provides a running environment (often referred to as a servlet engine) to existing, itself does not support the Java executable web server. Java servlet, to create a web application for the application using Java The program has opened up a new way. However, only servlet does not provide a complete model for real enterprise calculations. CGI app itself is often not a complete application, when processing information requested from users on a web browser, CGI It is just an intermediate step in the entire process. For example, a common use of the CGI application is to access the database. When used for this task, the CGI program provides a way to connect the user's data request to the meeting. The requested corporate database .CGI program often acts as an intermediate software, receives a request from a web browser, and decides which compute resources must be called to meet these requests, and send back responses to the browser. Java servlet is the same as the CGI program, the most suitable Acting the intermediate layer component of the connection front-end Web request and backend data resources. The three-layer architecture web programming evolution to the server-side Java application, which also brings the evolution of the architecture, making it separated from the conventional client - server two The layer model is developed to a three-layer approach. The two models have been innovative because it unresses some computing tasks from the main processor. General LAN-based database applications is an example Among them, the database manager server software resides on a dedicated server machine, and the user accesses the database through the client code on their workstation. As the client-server model grows to the use, it will appear. The server scalability and the focus of client code size and complexity. So three-layer architecture to avoid weaknesses that have been perceived in the two-layer model, so that the Web can become a computing platform: " Many people ... assertion, traditional client / server two-layer architecture does not have good scalability because the number of user connection and data access cannot be predicted, and there is also a problem in some system management. To handle the limitations of the two-layer architecture, many developments are turning to the three-layer architecture. This architecture can be roughly defined as: a representation of the representation of the client layer, an intermediate server, and a backend. The purpose of this idea is to mitigate code expansion on the client or database server, centralized management business logic, more flexibly use the database, not only to use the stored process and trigger. "(See KIM" Looking for A 3-Tier App Builder? ") A three-layer structure model is often imagined as a web browser as a client layer .Web browser is a true general client, Make it from the concept of "fat client" of the two layers.

If the browser is recognized as a standard thin client for the web application architecture, what will the function of the fat client reside in the two-layer model? Now, the application dedicated function is not to place back to the server (such as database manager), but intentionally resides it on a new intermediate layer. The intermediate layer supports application server software, which is a form of middleware that is in the first floor of the thin client's minimum function and the rich features of the server-side service system on the third layer. Since the three-layer architecture is closely related to the web processing model, the intermediate application server is often considered a functional extension of the web server. Existing web applications utilize the CGI program, transmit users from the web browser to the unmopable business system, and return to the browser, which is an implementation of the three-layer model. These applications have gradually transferred to servlet technology. The three-layer model is enhanced. JavaBeans Components JavaBeans Specifies the concept of "Component Software" into Java programming. Components are self-contained, reusable software units; and JavaBeans components, you can use visual application development tools to write them into the Java program. The Javabeans specification provides a "Component" Method for "Component". Any Java class with a certain feature and an event interface can be a bean. (See JavaSoft, "Using the Beans Development Kit 1.0") If the software reuse is a good idea, should you make every Java class be a Java Bean? If the Java class meets certain guidelines, they are suitable as a role of bean: Before developing any new software, it is worth considering whether it is developed in the form of javabean. Such software modules may be adapted to make a JavaBean if the software module is capable of being able to operate, but also customizes some effects. To help you determine if the software to be developed should be a Javabean, assume it should be written in Java, please ask you the following questions and make a decision accordingly: Do you plan to make it reuse? Or, will it be reusable? Do you want to use it with other reusable Java components? Do you expect to use it in the IDE tool? If the answer to the above problem is affirmative, it should be developed as JavaBean. (See DeveloperWorks "JavaBeans Guidelines" JavaBean concept is to support reusable components in the Java programming environment, which is a general design method for Java programs running on clients or server machines. Due to the emphasis on visible builder tools, since many Java Beans are graphical user interface (GUI) components, JavaBean components may be considered a client technology. However, Java Bean is not required to be visible, and they can also be used in server environments. Java classes encoding Java Beans typically have the following features: use design mode. These modes are the coding convention for methods and interfaces. Support visual software development tools. Classs must be displayed (called attributes), methods, and events. Can be customized. Customization includes supporting the default attribute editor or providing a single custom rule. Customization enables the developer to change the behavior of Bean without having to change source code. Support from introspection.

This refers to the disclosure of the properties, methods, and events to other classes, can accomplish this in design mode or by creating a BeanInfo class. It is lasting. This allows a bean to be customized in a visual builder, and then saved in its custom state. Java 2 Platform, Enterprise Edition Sun Microsystems launched a technological innovation called Java 2 Platform, Enterprise Edition (J2EE) to extend the range of Java platforms to large-scale server environment: "On April 12, 1997, Sun An innovation result of developing Java platforms for corporate environments is announced. Using open Java Community Process, Sun promotes a set of standard Java extensions, called Enterprise Java API. These application programming interfaces (APIs) are each The implementation of a variety of middleware provides a programming interface that does not depend on the vendor. The mainprise java API is the Enterprise JavaBeans API, the latter defines a server-side component model for the Java application server, and a supplier Programming interface. "(See Thomas" Java 2 Platform, Enterprise Edition: Ensuring Consistency, Portability, And Interoperability) J2EE provides the Enterprise JavaBeans technology. In fact, SUN envisages several software technologies to make such components, which will enable large companies to transplant in the Java environment with task-critical business systems, and Enterprise JavaBeans technology is only one of these technologies. The EJB component is defined according to their own specification, but EJB technology is not an independent technology. It is built on other Java technology, which is jointly provided by Sun and other IT companies, and they provide this framework, which is called Java 2 Platform, Enterprise Edition. J2EE includes the following technologies: Enterprise JavaBeans (EJB) technology Java Interface Definition Language (IDL) Java Message Service (JMS) API Java Naming and Directory Interface (JNDI) Java Remote Method Invocation (RMI) and Object Serialization Java Servlet API Java Transaction API (JTA) Java Transaction Service (JTS) JavaServer Pages (JSP) Technology JDBC Database Access API is involved in this enterprise Java framework, does not mean that each technology relies on all other technologies. Separate specification documents indicate the correlation of each technology. For example, the Enterprise JavaBeans Specification 1.0 release indicates the correlation with JNDI when locating each component, and the correlation between the JTA when the program is started and stopped in programming. EJB technology design objectives EJB specification was announced in December 1997 in December 1997 in March 1997. The specification author has developed the following objectives for the EJB architecture: Enterprise JavaBeans architecture will be a standard component architecture for building distributed object-oriented business applications in Java programming languages.

The Enterprise JavaBeans Architecture will be possible to build a distributed application by combining components developed using tools from different vendors. The Enterprise JavaBeans architecture will make the written application easy: application developers will not have to know the details of low-level transactions and status management details, multi-thread, resource sharing, and other complex low-level APIs. However, the expert-level programmers will be allowed to access the lower API directly. Enterprise JavaBeans Applications will follow the principles of "one writing, running" in the Java programming language. The EJB component can only be developed once, then deploy on multiple platforms without re-compiling or modifying the source code. The Enterprise JavaBeans architecture will handle development, deployment, and operations in the business cycle of the enterprise application. The Enterprise JavaBeans Architecture will define some conventions that make the tools provided by multiple vendors to develop and deploy components that can be interoperable at runtime. The Enterprise JavaBeans architecture will be compatible with existing server platforms. The vendor will be able to extend their existing products to support Enterprise JavaBeans components. The Enterprise JavaBeans architecture will be compatible with other APIs written in Java programming languages. The Enterprise JavaBeans architecture will provide interoperability between EJB components and non-Java programming language applications. The Enterprise JavaBeans architecture will be compatible with CORBA. What is the benefit of using EJB technology? What is the benefit of enterprises and developers? It is listed below to benefit from the Enterprise JavaBeans environment: EJB components make writing applications easier. Although the EJB architecture is complex, application developers generally do not have to write code for accessing system services. A system component called an EJB container allows system services to be used for the task of EJB components. Server-side business logic can be transplanted. In addition to the inherent portability of Java language, the EJB architecture also provides a set of standardized application programming interfaces between Beans and the containers that support the bean. This allows developers to transplant Beans from one operating environment to another, without having to rewrite their source code. Server-side applications can be installed from existing software components, which is the same as the client application can be assembled from existing Java Beans, so that the software can be reused. The EJB architecture has built-in support for typical enterprise-class system services, including distributed objects, transaction processing, database, security, and global naming. Many IT suppliers adopt an EJB architecture because there is such a commitment: customers will be able to purchase software components from selected vendors, such as EJB components, containers, and EJB servers; also committed different suppliers Products, as long as it meets the EJB architecture, it is interoperable. Applications built with EJB components can be ported from one server to another, which supports scalability because in the EJB model, each software component is strictly separated. The EJB architecture guarantees the original IT investment, which is allowed to replace the existing technology by allowing existing information systems and asset "package" without requiring customers. In fact, companies that store data in the relational database have already had a prototype entry bean, waiting for access to the EJB shell. Further investigation JAVA Naming and Directory Interface (JAVA Naming and Directory Interface (JNDI) to access various directory services. JNDI is divided into two parts: Application Programming Interface (API) and Service Provider Interface (SPI): "JNDI Architecture consists of JNDI API and JNDI SPI. JNDI API allows Java applications to access various named namings and directory services.

JNDI SPI is designed to serve an supplier (also including directory service providers). This makes a wide variety of directory services and naming services to be transparently inserted into the JAVA application using the JNDI API. (See JavaSoft, "JNDI: Java Naming and Directory Interface" JNDI API and different dedicated naming techniques or directory technologies are connected together, and there are also any supplier directory services, so it can be used for EJB components. The transplantability contributes. For example, customers can choose from a variety of different technologies to provide directory services for their EJB applications, including: LDAP: Sun LDAP service provider supports 2nd Edition and 3rd editions of LDAP protocols. NIS: Sun provides an NIS service provider (NIS, network information service, previously referred to as yellow pages). COS Name: Sun's COS Name Service Provider provides access to CORBA naming services. File System: Sun provides a service provider to access the file system. RMI Registration: Sun provides a service provider for RMI registration. Novell: There are several service providers to provide access to directory service NDS and NetWare 3X connection library, Novell file system, and other Novell services (such as extended NCP). Although the JNDI specification is neutralized to the supplier, it should not be considered that the application server that implements JNDI interfaces must access service provider code from multiple vendors. The key concept of the JNDI naming architecture includes: the binding between objects and names. Some bindings are called name contexts. Name the system, that is, several groups named context. Namespace refers to all names in a naming system. Name is classified as atom name, composite name, and synthetic name. The atom name is indivisible and can be bound to an object. The composite name is a combination of atom name, while the synthesis name spans multiple naming systems. Naming context is especially important: All named operations are made on context objects, and the name resolution process always starts from the initial name context. How is the EJB application use JNDI? JNDI's main use is to retrieve reference to EJB components. Because the EJB framework is a distributed object framework, the EJB application should not assume the location of the EJB component. JNDI is a mechanism for obtaining starting references to beans. When a bean is installed on an Enterprise Bean server, a software component called an EJB container is responsible for creating each name - object binding, making the required Java class file to use this bean. Application uses JNDI lookup method to retrieve an object reference, in the following example: Context initialContext = new InitialContext (); CartHome cartHome = javax.rmi.PortableRemoteObject.narrow (initialContext.lookup ( "applications / shopping_cart"), CartHome.class ); The application is responsible to know the external name, the application is to reference an Enterprise Bean through this name, and get references to the bean through JNDI. Further investigation of JTA except JNDI, the Enterprise JavaBeans architecture also uses Java Transaction API (JTA). Because the transaction is important for maintenance data integrity and reliability, support transaction processing is a basic part of the EJB architecture.

If an enterprise application is distributed, transaction processing will be more important: "The concept of transaction is an important programming example, its purpose is to simplify application structures that require both reliability and requireability, especially those who need to access sharing Data Applications. The concept of transaction is earliered in a business-operated application, where it is used to protect data in a centralized database. Later, the concept of transaction has been extended to a wider range of environments for distributed computing. Today, the transaction is the key to building a reliable distributed application. This has been widely recognized. "(See the" Transaction Service Specification "of the object management group) Sometimes the transaction is a work unit with the following characteristics: atomicity - if Because of the failure, all results are revoked - the result of the transaction reserved the constant characteristic Isolated - the intermediate state is invisible for other transactions - the result of the completed transaction is the termination of a lasting transaction. Mode: Submitting a transaction will make all the changes permanently, and rollback back is a transaction to revoke all its changes. Object Management Organization (OMG) is an object-oriented transaction service, an object transaction service (OTS) creates a specification. OTS is the basis for transaction services in the EJB architecture. The following affairs is the transaction model used by Enterprise Bean: OMG Object Services (OTS) Sun Microsystems Transaction Service (JTS) Sun Microsystems Java Transaction API (JTA) Open Group (X / Open) XA interface This object-independent object transaction service provides basic concepts, definitions, and features for a strong distributed transaction service. Java Transaction Service is OTS's Java mapping, in org.omg.costrasactions and org.omg.costsportability these two packages. JTS supports services such as transactional boundaries and transaction environments. The JTS function is accessed by the application via Java Transaction API. Java Transaction API Specifies a variety of advanced interfaces between transaction managers and other system components involved in distributed transactions, these system components include applications, application servers, and resource managers. The JTA feature allows transactions managed by the application itself, managed by the application server or by an external transaction manager. The JTA interface is included in the two packets of javax.transaction and javax.transaction.xa. The XA interface defines the agreement between the External Transaction Manager in the resource manager and distributed transaction environment. External Transaction Manager can coordinate transactions across multiple resources. The XA's Java mapping is included in the Java Transaction API. The second part of the content preview "What is Enterprise JavaBeans Component?" Will discuss the EJB programming model. References To learn more about Java technology and EJB architectural structure, please visit Sun's website. For Java Programming from Applet and Applications, please read the java in a nutshell in David Flanagan. Download a copy of the Java Servlet API Specification. Download the "Looking for A 3-Tier App Builder" (PDF) written by TOM KIM in Java Developer's Journal No. 3 No. 1 Medium TOM KIM. Participate in the "Using The Beans Development Kit 1.0" course in Javasoft.

Some supplementary guidelines can be found in "Javabeans Guidelines", which enables you to develop performance-based beans, which can perform well in most environments, including popular Ide and various browsers. Read the Detailed Description of J2EE in "Java 2 Platform, Enterprise Edition: Ensuring Consistency, Portability, and Interoperability" written by Patricia Seybold Group. An overview of the JNDI architecture and interfaces in JNDI: Java Naming and Directory Interface, and various situations and examples. Learn Java 2 Platform, the Java technology Enterprise Edition contains: Java IDLJava Message Service (JMS) API Java Naming and Directory Interface (JNDI) Java Remote Method Invocation (RMI) Java Transaction API (JTA) Java Transaction Service (JTS) JavaServer Pages (JSP) Technical JDBC Data Access API To understand common problems, with LDAP-related RFCs and more, visit the LDAP website of Mark Wahl. To learn how to configure Linux to NIS (YP) or NIS clients and how to install it into a NIS server, please consult Linux NIS (YP) / Nys / NIS HOWTO. Download Naming Services of Java IDL COS Naming. Learn more about Java Remote Method Invocation (RMI), including specifications, examples, and common problems. Learn about the large number of products and solutions from Novell. Visit the website of Object Management Group (OMG). Check out the XA Interface specification of the open group. About the author Ken Nordby is a software engineer in the IBM software development laboratory of Research Triangle Park, North Carolina. As a member of the SWG Product Affinity Services Working Group, Ken and his IBM colleagues are engaged in the development and consultation of IBM WebSphere Application Server (Enterprise Javabeans IBM implementation). You can contact Ken through nordby@us.ibm.com. Part ICI: EJB Programming Model The second part of this article describes the role of Java interfaces and classes required to create Enterprise JavaBean components. In addition to encoding the Bean class itself, EJB developers must also define a local interface and a remote interface for beans. The implementation class of these interfaces is typically generated by the container, so the deployment EJB component is a cooperation behavior of developers and EJB containers. The second part also distinguishes two main types of Enterprise Beans, namely session beans, and entity beans, and illustrates the relationship between EJB containers and EJB servers. The three key features of the Enterprise Bean programming model are: object-oriented, object distributed and use a proxy object. Since this programming model uses Java technology, it is inherently object-oriented. This model is also distributed, refers to Bean theoretically, transparent. According to ENTERPRISE JAVABeans (EJB) specification, "Generally, the actual location of the EJB class and EJB containers is transparent to the client.

"When the client wants to access the EJB component. Bean itself is unacceptable to the client, and the access to the bean method is provided by the Helper class. Interface, delegate and proxy When the Java programmer write a Enterprise JavaBeans component The class they created must implement an EJB interface, and it must contain a method called ejbcreate (). An EJB interface - such as the sessionBean interface - specifies some methods, including the following: ejbactivate () Ejbpassivate () EJBREMOVE () setSessionContext () EJBACTIVATE () and EJBPassivate () methods Notify a bean that manages the BEAN's container assembly to switch between the bean between active and passive (this is usually referring to the memory or swap to disk). The ejbremove () method makes the bean know that it has been removed from the container.SetSessionContext () method enables the bean to associate with a context object, this context is to facilitate the BEAN to communicate with its container .Ejbcreate () method is not from zero Create Enterprise Bean. When the client wants to create a new Enterprise Bean, the bean's container will call the new BEAN object to instantiate the new bean object. Then the container calls the setSessionContext () method to create context. Objects are used to communicate with beans. Finally, the container calls the EJBCREATE () method in the new bean. Methods like ejbcreate (), ejbactivate (), and ejbpassivate () are sometimes referred to as an object survival process, to distinguish business logic Method. When developers designed a new EJB component, the code written in the ENTERPRISE BEAN class is not enough. EJB programmers must also write two Java interfaces that will be used by the Helper class. These mandatory interfaces must extend the standard EJBOBJECT And the EJBHOME interface, and the two interfaces are extensions of the Java.rmi.Remote Marker interface. The interface of the extended standard EJBObject interface is called the remote interface of Enterprise Bean, which specifies the business method defined in Bean itself. Program call When the business method in Enterprise Bean, the application does not access the bean itself. In fact, the method call is passed to the object that implements the EJBObject interface extension. This approach is called a delegation, it is a design key in the EJB architecture: "The client never directly accesses an instance of the Enterprise Bean class. The client always uses Enterprise Beans to access the Enterprise Bean instance. Implement Enterprise The class of the Remote interface of the bean is provided by the container. The distributed object of this type is called the EJB object. "(Enterprise JavaBeans Specification 1.0) Bean is called its remote interface to the EJBOBJECT interface, and the object of the remote interface is called For the EJB object. Enterprise Bean must also have a local interface. This interface is an extension of the standard EJBHOME interface. Objects to implement the local interface of the bean are called local objects. Local objects contain a create () method, this method is called by the application, and the application must create a bean instance. The CREATE () method in the local object creates a new EJB object. It does not create a new Enterprise Bean instance because it is not allowed to access beans directly.

EJB objects and local objects serve as a proxy for bean objects because they call on the bean receiving method. The EJB object is mainly served as a proxy for the Bean business method; the local object is mainly served as a proxy for the BEAN survival cycle method. Use the create () method for EJB components and do not have to instantiate new beans. The container determines how best to meet the creation request, for some types of beans, it can reuse the existing instance: "Client uses the Create and REMOVE methods on the local interface of the session bean. Although the client thinks it is controlling the EJB instance The survival cycle, however, is the container in processing Create and Remove calls, and does not have to create and delete EJB instances. There is no fixed mapping between clients and ... instances. Containers just entrust the client's work Any method is ready for useful instance. "Enterprise JavaBeans Specification 1.0) Creating a new bean instance is controlled by the container and can publish the Create () method asynchronously with the client. When creating an EJB component, the developer is responsible for defining the EJBObject interface and the EJBHOME interface, but does not need to write code of the class of these interfaces. EJB container software components automatically create these classes. The following code segment explains how the client application may use Enterprise Bean called CartBean for online shopping: carthome cartHome = javax.rmi.portableremoteObject.narrow (InitialContext.lookup ("Applications / Shopping_cart"), CartHome.Class; Cart Cart = CARTHOME.CREATE (); cart.additem (item29); cart.additem (item67); cart.additem (item91); cart.purchase (); cart.remove (); carthome is a class that implements local interfaces ( Extension of the EJBHOME interface). CART is a class that implements a remote interface (extension of the EJBObject interface). When the client calls an application method (such as addItem () and purchase ()), they are called on the CART object, and this object then delegates the implementation of these methods to the bean itself. The functionality of Enterprise Bean is obtained by its agent EJB object (ie, Cart). What happens if you visit Cart Bean at the same time? Enterprise Bean developers do not need to write code to support concurrency access. Concurrently supported by EJB container. The following figure illustrates the relationship between each EJB object:

Server and container EJB architecture includes two concepts of EJB servers and EJB containers. The EJB server acts as a component execution system, as described in the EJB White Paper: "Enterprise JavaBeans specification defines a standard model for each support fully portable Java application server. Any vendor can use this model to implement Enterprise JavaBeans components support. A variety of systems (such as TP monitors, CORBA runtime systems, COM runtime systems, database systems, web server systems, or other server-based runtime systems) can be adjusted to enteterprise JavaBeans capable of supporting portable Components. "(Thomas, Enterprise JavaBeans Technology: Server Component Model for the Java Platform) EJB Server provides an operating environment for applications using EJB components, and provides all required services to support EJB architectures. Packing EJB server software does not pre-specify. One way is to enhance it as a functional enhancement into the application server, which is the method used in IBM WebSphere Application Server, Advanced Edition, Version 2.0. The EJB component is not directly executed at the top of the EJB server. A intermediate software component called an EJB container runs in an EJB server environment, providing operational environments for these beans themselves. The EJB container is completely transparent to the EJB application, but it plays a key role in supporting Bean operations. In order to enable Enterprise Beans to act as reusable software components, they cannot have built-in correlations for specific servers or platform functions. Several common types of server-side functions have been "separated from" in the bean design, and the responsibility of this feature is transferred to the container component. For example, the container will be used to take over security, concurrency, transaction, exchange to the auxiliary memory and other services, so that Bean is protected from server-dependent, and will be optimized according to business logic, not by service. Logic is optimized. EJB white paper describes the role of the container: "EJB container management is deployed in the Enterprise Bean. Client applications are not interacting directly with Enterprise Bean. In contrast, client applications are through two package interfaces generated by containers (EJB Home Interface and EJB Object interfaces are interacting with Enterprise Bean. When the client calls various operations using the package interface, the container intercepts each method call and inserts management services. "(Thomas, Enterprise JavaBeans Technology: Server Component Model for the Java Platform) You can expect EJB container software generally with EJB server software, although these components are allowed to be separated. In addition to providing access to runtime services such as transaction processing and security), it is also desirable that EJB containers include a variety of necessary tools to support Enterprise Beans installation, operation, and management. For example, there is a need to explain the content of the EJB JAR file. There is a tool generated database access to obtain persistence provided by the container, and tool monitoring is running the behavior, and implement security. Bean style EJB components are divided into two main categories - session beans and entity beans. These categories can also be further subdivided according to the method of processing status, transaction and persistence.

Session beans typically have the following properties: representing a single client execution can be a transactionality that can update the relatively shorter life of the data survival in the shared database is usually a client's survival of any persistent data, which is managed by the container. Judgment to delete the entity bean when the EJB server fails, is typically having the following attributes: the data in the database is transactional to allow multiple users to access multiple users can have a long-term persistence data can be managed by the container to manage after the EJB server fails. Continue to survive EJB specification The description of the session bean and entity beans is as follows: "For clients, session Enterprise Beans is a non-persistent object, which implements business logic running on the server. Imagine a session object The way: The session object is a logical extension of the client program running on the server. The session object is not shared between multiple clients. "For the client, entity Enterprise Bean is a persistent object, which represents a storage in a lasting Object views of entities in sex memory (eg, a database), or an entity implemented by existing enterprise applications. "Enterprise JavaBeans Specification 1.0) With a rough statement, session bean represents such an operation, it retrieves or stores data to meet user requests; and entity bean represents a data set, you can access these data sets to meet user requests The easiest way of conversation bean is a stateful session bean because these beans can distinguish their status, all instances are exactly the same. Container manages the survival cycle of stateless session beans, the way By creating a sufficient number of beans to accommodate the client's workload and delete it when you don't need them. Passivation, the idle bean is written to disk, no useful session. To call bean, client The program calls the Standard Create () method in the local interface, although this operation does not necessarily lead to a new bean instance. The container can choose to send the client request to an existing object. Conversely, the container can create a new The instance, and independent of the Create () method published by the client. Create () calls released on the EJB local object returns a reference to the EJB object, this EJB object represents Enterprise Bean. Once the client has an EJB object reference It can publish the business method to the EJB object. The container will entrust these methods to bean itself. The container components responsible for the management session bean do not need to inform whether the session bean is stateless. Session bean is still there is still still Status at the installation. If the session bean reserves status information between method calls, it is stateful. By calling the ejbpassivate () method, the container can determine the state session bean passivate, or write auxiliary Memory. EJB specification does not require containers to use Java serialization protocols when passivating Beans, but they must provide an equivalent function. When the container decides to exchange a non-active session bean back to the memory, it will cancel it Passive bean serial, and calls the ejbactivate () method. Developers with state session beans are responsible for ensuring status data is serialized. In the cluster's application server environment, there is a status session bean time, because Not all servers support the synchronization of the status session bean of the cluster. Status Session Bean can be transactional.

By using the method in the Javax.Transaction.UserTransaction interface, such as Begin (), Commit () and Rollback (), beans can control the transaction; BEAN can receive a notification on transaction status by implementing a Javax.ejb.Sessionsynchronization interface. EJB containers do not need to infer which beans require transaction support; the UserTransaction interface can only be used for Beans that are labeled as transactions when installing. The entity bean entity bean is similar to meeting beans in the architecture, but they provide access to corporate data, not to support user sessions. An entity bean can support multiple concurrent users, while the container makes access and transaction synchronization. Entity Beans also has primary keys for supporting the Finder method in the local object. A client that knows the primary key of entity beans can get an object reference by calling the Findby PrimaryKey () method on the local object. Unlike session beans, the local object of the entity bean has a Finder method except for the Create method. Persistence is a basic attribute of entity beans. The EJB specification allows two forms of entity persistence: BEAN management persistence and container management persistence. For entity beans in the representative database, Bean's management of persistence means that calls to database access are directly written in the enterprise bean (using JDBC or SQLJ). This method is straightforward, but it reduces portability. The management of containers on persistence means that Beans are not affected by database calls. Inform the container during installation, the persistence of the bean data is installed, while the container is responsible for generating a code that implements persistence. This approach allows the bean to be more portable, even achievable extent to which different data sources can be used. However, this method requires complex functions in the container. When the entity bean object is associated with the EJB object, the former is in the ready state; otherwise they will be in a shared state. When the client calls the method in the EJB object, the container looks for an instance of the associated entity bean (if present), or transmits an instance from the shared state. Entity beans in ready state can receive a business method call to them by commissioning from the client. They can also perform the EJBLOAD () and EJBSTORE () methods when the container request is requested. The LOAD method and the Store method are intended to maintain the consistency between the entity beans and the underlying data storage. Entity beans support multiple users and access data. EJB specification declaration, maintaining data integrity is the responsibility of the container: "Enterprise Bean developers do not need to worry about the concurrent access from multiple transactions when writing business methods .Enterprise bean developers can assume that they can be assumed to be used for multiple transactions Access each entity bean will ensure proper synchronization. "(Enterprise JavaBeans Specification 1.0) Container Complete this task is usually by locking data in the database and accessing serialization, or by creating a number of entity beans. Examples, and allowing computing control in the underlying data store to manage access. The third part of the content preview "What is ENTERPRISE JAVABEANS Component?" Will discuss the special deployment process of installing the EJB component. It will also show that CORBA is the competitor of EJB components (the answer is "NO" - see how the EJB technology supplements CORBA). Finally, you will see a use of EJB-based three-layer programming models. Reference Enterprise JavaBeans Specification 1.0.

To learn more about the EJB architecture, see Anne Thomas Enterprise JavaBeans Technology: Server Component Model for the Java Platform, Patricia Seybold Group. To learn more about Java technology and EJB architecture, please visit Sun's website. About the author Ken Nordby is a software engineer in IBM Software Development Lab, which is located in Research Triangle Park, North Carolina. As a member of the SWG Product Affinity Services, Ken has worked with such IBM people, and they are engaged in development and consulting for IBM's WebSphere Application Server (i.e., Enterprise JavaBeans Technology IBM). You can contact Ken through nordby@us.ibm.com. Author: Ken Nordby original source: ibm

What is ENTERPRISE JAVABEANS component? (3) Recommended: Simon Category: Java Published: 2002-04-11 Popularity: 1239

Part III: Deploying and using Enterprise JavaBeans Components Part 3 describes the deployment procedures of Enterprise JavaBeans components, deployment is not just installation because it usually involves code generation. Deployment also uses a special deployment descriptor file that supports the parameters that control the enterprise-level bean behavior (such as a bean requires transactions). This feature deployed by Bean supports the descriptive, program - specific EJB target of Bean. Part 3 also compares two main types of persistence, Bean management persistence and container management persistence, and discusses the relationship between EJB components and CORBA. A simple three-layer EJB application is also given. Deployment Procedures Enterprise JavaBeans (EJB) components are installed in a specific process called deployment. Support for deployment procedures by the container assembly. At the high level, the deployment consists of the following steps: BEAN developers create the required class file, interface file, and control information. Container analysis Enter files and generates the necessary classes. The container adds an entry to the JNDI namespace pointing to the local object. The developer of the EJB component writes the BEAN's Java source file, which contains the business logic method for this bean, and includes the ejbcreate () method. The Bean class must also implement a javax.ejb.sessionBean interface or a javax.ejb.entityBean interface. In addition, Bean's developers write interface files to define an extension to javax.ejb.ejbhome interfaces and javax.eb.ejbobject interfaces. The EJBHOME interface is extended, called the BEAN's local interface, including a creation method, and if the bean is an entity bean, it also contains a Finder method. The extension of the EJBObject interface is called the Remote Interface of the bean, specifies the business logic method defined in the bean itself. BEAN's developers provide control information consisting of deployment descriptors, environmental properties, and list files. The deployment descriptor is a serialization instance of a javax.ejb.deployment.sessionDescriptor object or a javax.ejb.deployment.EntityDescriptor object. Environmental Properties As the key-value pair stored in a file, this file can be accessed via the Java.util.Properties object. The single file is required to identify enterprise beans and its related files. Enterprise beans class files, class files, deployment descriptor files, environmental properties files, and monitored files are archived using file formats named EJB-JAR. The generated EJB-JAR file is provided to the container as an input to the deployment process. At deployment, the container analyzes the contents of the EJB-JAR file and takes the necessary operations to make this bean available. These operations include generating a new Java class that implements the local and remote interfaces of Beans, and the local interface is bound to the JNDI namespace, generating pile modules and Skeleton Helper classes, which are required to support RMI communications. The container can also generate a subclass of the bean, incorporating the code-specific code to facilitate the management of Beans. The class generated by the container is usually dedicated to the container, and is portable as the EJB component itself. Persistence, transaction, and safety provide persistence, transaction and security services for EJB components, EJB containers can play a major role. Is the responsibility of these services to the container or assume that the responsibility is responsible by bean itself, and the EJB specification provides flexibility in developers of Beans. For example, persistence support for entity beans can be managed by bean or by container management.

If the EJB component developer chooses to use the container management persistence, they will add a property called ContainerManageDfields in the deployment descriptor. Depending on the EJB specification: "The value of the ContainerManageDfields property is a list of instance fields, the enterprise-level bean provider wants, the container manages these instance fields by loading or stores it from the database, the enterprise-class bean code should not contain any database access Calling - Database Access Call will be generated by the container tool in deployment. "Dedicated to the container that provides container management persistence support, usually provides a rich deployment time tool to allow enterprise-class Bean deployers to establish instance fields to basic data sources. Mapping. It is generally believed that although the container provider's tool simplifies the mapping process, the mapping process may still involve the Bean deployer (ie the mapping process is not fully automatic). "Enterprise JavaBeans Specification 1.0) In addition to supporting container management persistence, the EJB architecture also supports the management of containers to transactions. This specification specifies:" Enterprise JavaBeans is a Advanced Component Framework, which trying to make application developers The complexity of the system. Therefore, most enterprise beans and their clients do not need to access transaction management through program. "Enterprise Javabeans Specification 1.0) When the BEAN's developer relies on the container, it is called the container management trimming, the container is used in the transaction attribute provided by the deployment:" Whenever the client calls enterprise beans, containers Will involve this method call. This intervention allows the container to explicitly control the transaction bound by transaction attribute. For example, if the enterprise-class bean deploys the TX_Required transaction property, the container will automatically start the transaction whenever the client calls the enterprise bean that supports transactions, and the client does not associate with any transaction context. "Enterprise JavaBeans Specification 1.0) If the developer chooses to support transactions within Beans, they specify the TX_Bean_managed transaction property in the deployment descriptor, and then you can freely use the Javax.Transaction.Usertransaction interface to divide the transaction boundary in Bean itself. Out of the TX_Bean_managed transaction property, the container knows that there is no need to intervene transaction support. By enhancing the restrictions specified in the AccessControlEntry object and the RunaS security ID, the container provides secure support for EJB components. AccessControLEntry objects on the bean level or for a single method, the Identity object Enterprise-class beans associates. Edentity object reflects users or roles that allow calls to beans. When the container is trying to access the data source or another bean, they will also apply Runas security identities to the EJB component. You can set the Runas identity as equivalent A particular user account, a system account or client security identity. Access control and RunaS information is specified in the deployment descriptor in the deployment descriptor, which will affect the container management bean's behavioral way. Although the EJB 1.0 specification also refers to security issues, more detailed security functions, see the subsequent version of this specification. The relationship between Corba and EJB technology Request a proxy architecture (CORBA) is a platform neutral and language of distributed objects. The neutral computing environment lays the foundation. In the CORBA environment, the function resides in the object, and the client can access these objects through the object request agent (ORB). The complete CORBA implementation provides ORB, which is called CORBA object service. Several runtime services for CORBA utilities.

You can also provide only ORB, which does not provide associated object services and utilities (for example, IBM provides such two independent ORBs). Software that implements basic ORB functions is called ORB core. In order to support language-independent, the CORBA application is written in the Interface Definition Language (IDL). This language is similar to C in syntax, but does not include semantic: The operation specified in IDL is an operation interface instead of operation. The CORBA is ideal for managing the information system for managing the size of the company's size. The design EJB specification is also to support enterprise information systems. Say this, is CORBA a competitor? According to the frequently asked Questions for Enterprise JavaBeans, the answer is negative: "In fact, EJB technology has a great supplemental Corba.Corba provides a powerful standard infrastructure that builds EJB servers on this structure .EJB technology. Enables the top floor of the CORBA infrastructure to build applications easier. "(Enterprise JavaBeans Frequently Asked Questions) Although the EJB specification and CORBA specification descriptions are different technologies, EJB implements certain aspects of current using CORBA technology. An example is RMI / IIOP. EJB specification requires EJB components and its containers to use Remote Method Invocation (RMI) technology to implement method calls between distributed objects. RMI specifies the syntax and semantics of the remote method, but does not specify which transport protocols should be used to provide network connections. The CORBA Internet Object Request Agent Protocol (IIOP) basically defines a method of transferring CORBA messages through TCP / IP. Developing an EJB implementation using the IIOP message form to exchange RMI data, how the EJB application can effectively use the part of CORBA technology. This network also supports interoperability with the CORBA application, which uses IIOP to send local CORBA messages, independent of RMI. IBM's EJB implementation, WebSphere Application Server, optimizes IIOP usage, how to make a clear distributed object reside on the same server and only call IIOP when the object is actually remote. In order to facilitate the development of enterprise systems that are incorporated into EJB technology, Sun Microsystems created a mapping between EJB specification and CORBA. The EJB architecture is mapped to CORBA, which affects several aspects of EJB technology, including object distribution, naming, and transactions. The main purpose of the CORBA mapping is to ensure interoperability between the EJB servers constructed by different manufacturers. Interoperability offers the following benefits: CORBA client can access the EJB component client program on CORBA-based EJB server can call to CORBA objects in transactions, and mix with the enterprise-class bean's call. Multiple beans, while these beans are also located on CORBA-based multi-EJB servers from different vendors using ORB clients from a vendor, and can access another manufacturer's CORBA-based EJB server to beans to access EJB components. The CORBA client, the bean interface is mapped to IDL. For example, the Buy () and Sell () methods defined in the stock trading bean can be specified as CORBA operations in the IDL file.

Non-Bean's CORBA client, such as a C client, you can access this bean, and use standard CORBA call to call the bean method. If the container uses IIOP as its distributed object protocol, the duties of the container are to generate IDLs corresponding to enterprise-class beans and their interfaces. EJB Naming Services, which is based on the CORBA Object Services Naming service, so that the EJB component can be used for CORBA clients. Java Naming and Directory Interface (JNDI) provides an interface to the CORBA naming service, and the client can access the service through the JNDI call indirect access to the underlying naming service, or you can access the service directly through the CORBA Object Services (COS) name API. EJB transaction supports Corba Transaction Service (Object Transaction Service (OTS). Java Transaction Service (JTS) represents the Java binding of the OTS, which is language neutral. CORBA-based EJB containers must identify transactions issued by the CORBA client through the OTS interface, and the EJB application emitted through the Java Transaction API interface, JTA is an application-level interface to JTS. The JTA also represents the Java binding of the Open Group XA interface to connect the application resource to an external transaction manager. The JAVAX.TRANSACTION.USERTRRANSACTION interface in JIA provides an API for the application level control of the transaction boundary. Usertransaction interface, which can be used as a bean with TX_Bean_Managed from its transaction property to be used by Java clients. Using EJB components Because the EJB architecture is designed to be highly flexible and supports the use of any complicated way to connect the enterprise bean, many different scenarios can be constructed, and how the application can use Enterprise Beans. A useful solution proposes to represent the EJB component as a key component of the three-layer information system, which connects the enterprise data, transaction, and application resources to the web. The EJB-based three-layer programming model will depend on the web browser as the first layer, and the web server supporting the application is the second floor, depending on the enterprise information resources as the third layer. In this programming model, in addition to EJB technology, Java Servlet technology, JavaBeans technology, and Java Server Page (JSP) technology are also implemented. The figure below shows the arrangement of each layer:

The first layer is a thin client-is usually a web browser that can handle normal web data types such as HTML and GIF, and support HTTP communication. The second layer is a web application server, which is a web server with code to deliver running for applications that can be called through the web server. Existing web applications are used along the CGI-BIN programming model, but it is expected that the second-layer application development will turn to the Java Servlet programming model, which provides significant improved performance and portability. In addition to supporting Java Servlet, the web application server will also add an EJB server function to support applications using EJB components. The third layer represents enterprise information resources, which can include relational databases and object-oriented databases, transaction monitors, and customized applications. EJB technology plays a key role in this design because it resides in the second layer of application components, and the interface between the third floor, it is standardized. Java Servlet, Java Beans, and Java Server Page are not essential elements for the EJB application solution, but they can work with the EJB component to provide Java-based cohesive application environments. The environment depicted here will assign the following responsibilities to the Java component participating in the work: Specify the Java Servlet's role JSP page processing data representation and user interface Java Bean acts as a "data package", storage intermediate The result of the data EJB component provides a mechanism for accessing the enterprise information resource. You can use a hypothesis, EJB-based web application update existing inventory, and use container management persistence and container management transactions, will access the inventory database location package Inside the entity EJB assembly. Inventory tickets can be entered via web browser, the browser provides an HTML form to capture product numbers, suppliers, etc., and call a servlet when submitted. The servlet code acts as an application controller role to determine which corporate databases need to be updated, requiring users to apise the information. The servlet can access the main inventory database by representing its entity bean, and call the JNDI interface to get a reference to the local object of this bean, and then use the finder method to locate the remote objects of the requested product number. At this time, by calling the remote object, the servlet can update the inventory count, and then the container will delegate this method to the EJB component. Because the container is updated according to the database, it is maintained in the transparent manner to the BEAN transparent, and the data is written to the database to ensure data persistence, so the data is maintained. Any result information returns from the EJB component to the servlet, you can use the setter method to store in an attribute of a (non-enterprise) Java Bean. The servlet can transfer control to an appropriate JSP page to combine these results into the representation and return the result to the user. The JSP page is likely to be composed of static text and variable information placeholders related to a single transaction. The JSP page uses the Getter method to get variable data elements from the Java Bean before sending a data to the browser. EJB-based three-layer design provides several benefits, including: Accessing the business logic of enterprise data can be packaged in reusable, portable enterprise beans. Existing enterprise systems can be integrated into enterprise-class beans only need to be modified or do not need to be modified. The runtime services required by the enterprise application, such as transactions, and persistence, can be broken down from the bean and specify containers to this bean.

You can modify the servlet of the Control Application Process without changing the EJB component. The Servlet code can focus on application control logic without considering data representation. The JSP page can be mixed together and generate information. System components written in Java language are portable for any platform with JVM. Conclusion In the process of developing an enterprise information system that supports key tasks, the EJB specification represents the next stage of development of Java technology. The EJB component extends to the server field with the JavaBeans specification, so that the development of business logic components can be reused across enterprise applications, and can transplant cross-supporting Java. Since it contains an Object distribution based on RMI technology, the discretion of multi-layer executable components is supported, allowing maximum implementation and high scalability. If the regular enterprise application runtime service is redefined as an object service that can be specified to the container, the developer that allows EJB components to concentrate on business logic, reducing the complexity related to the runtime service. And platform relevance. Enhance the Java operating environment to include standard interfaces, relational database access, transaction services, and remote object access, so that Java developers can write robust enterprise applications without having to leave the Java programming environment. Use other Java technology-such as Java Servlet and JavaServer Pages technology - with EJB components, you can create a compact programming model for large enterprise systems, but because of using clever interfaces, it simplifies development work. . Moreover, because the EJB architecture is a logical extension of the JavaBeans component model, the business logic developed as an EJB component can be reused across multiple enterprise applications. Another benefit of an enterprise-level Bean architecture is to provide a direct integration channel of existing enterprise information systems, which may be unansee with the Java programming language or bean programming model. Because of existing enterprise information resources - custom new varieties for relational databases, transaction monitors, and business applications - can be connected to the web front end by encapsulating them in the EJB component, without replacing the application or rewriting the main code Segment, so customers protect their existing IT investments. Considering the huge prospects of EJB technology, the IT industry welcomes EJB specification with considerable interest, is not surprising. One of the biggest benefits provided by the EJB architecture may be to leave business logic programming with complex set components of business logic and enterprise-class server-side running environments. If the container deploys the EJB component has undertaken the role of the management runtime service (such as persistence, transaction, and concurrent database access), the BEAN's developer can freely focus on the software components of the development package business logic. Javasoft Vice President expressed the importance of EJB technology (from Sun Microstems website): "The 'Enterprise JavaBeans API will provide a new strategic weapon for enterprise developers and solution providers for them to build next-generation industry, Based on key business applications, the Vice President of the Javasoft Software Products for 'Sun Microstems, Jon Kannegaard, said:' Because applications designed with Enterprise JavaBeans API will work with existing enterprise systems, companies use Java platforms to get new The competitive advantage, but also retains their investment in prior art, 'Kannegaard continues. "Use Enterprise JavaBeans API, developers will be able to eliminate complexity during application development.

This is possible because each Enterprise JavaBeans component encapsulates a basic business feature. At present, developers must know how to write business logic and specialized system-level procedures to control the ability such as security features and handle multiple transactions - a boring and complex task. Enterprise JavaBeans API enables all developers to focus on writing a logical solution to business issues, rather than concentrating on writing code to simplify different technologies. "(Press Release: Sun Releases Draft Enterprise JavaBeans Specification for Public Review) reference site by associated FAQs Sun-depth understanding of Java technology and EJB architecture access to Enterprise JavaBeans Specification 1.0, please see the Enterprise JavaBeans specification See the full press release... The IBM WebSphere Application Server uses EJB technology. The Summary Ken Nordby is a software engineer in IBM Software Development Laborators, which is located in North Carolina Research Triangle Park. Members of the Swg Product Affinity Services business team, Ken with IBM WebSphere Application Server (Enterprise JavaBeans Technology IBM Implementation) works together for IBM people working together. You can contact Ken in nordby@us.ibm.com and Ken .EJB (Enterprise Javabeans) can not be a new concept, but many people are hearing Or when you see this noun, you will be dizzy. EjB component is bundled in the J2EE specification, bundled the application's representation layer and backend information system (such as database or main framework). Ejb architecture is used The function of the EJB object uses the environment they run. Why is an EJB from a concept, EJB object encapsulates business objects and its concepts, allowing developers to focus on the details of the solution. From the perspective of design Look, EJB should be a light and interacting. This initiative can make a single EJB, whether it is a business application that may adopt an EJB represents autonomous development or the third party manufacturer's development can be used in a variety of applications. Program. For example, CRM (Customer Relationship Management) tool and electronic user. These have an adaptive object configured to describe the XML file of EJB in the deployment descriptor. Deployment descriptor allows not recompile You can modify the EJB attribute and behavior. EJB object reside in the EJB container, the latter is the environment that provides developers with a variety of services. Containers may be responsible for handling security, transaction, and instance management depending on the specific configuration. Due to the program There is no need to complete these tasks again to make the development time. There is a significant difference between the two concepts of J2EE servers and EJB containers, EJB containers It may be part of the J2EE server, but it is not necessarily a necessary component. In the case of a J2EE server component, the EJB client usually takes the form of Java Servlet or JSP. However, due to the cancellation of the ITE level of the J2EE web layer, the standard EJB container service can accept multiple types of client programs, requested by applications written in Java or other languages. Communication with EJB containers is the prerequisite for customer operation. EJB content EJB object is divided into the following three categories:

· Session Beans

· Entity Beans

• Message Driver Beans determines the Bean type used by the bean behavior according to the required Bean. The role of the session beans session (Session) Beans is based on the session. After the client requests and receives the bean function, the session with a specific bean is terminated and does not leave a record of the session. The session bean type can also be further subdivided into stateless or state. The stateless session beans do not know the customer or the context of the requested request, thereby making it an ideal tool for a single request / response application. For example, the bug tracking system for a user searches all public bugs is this. The client application contacts a stateless session bean and delivers the search parameters. Next, this bean accesses the database, selects an entry that matches the search criteria, and retransmits the record back to the client. After the communication is complete, Bean does not retain interactive information. Therefore, multiple client programs can access stateless session beans at the same time, but they will not interact. Conversely, stateful session beans will connect the request with a specific customer to establish a one-to-one relationship between the customer and the bean. Shopping cart bean is an example. User implements a standard e-commerce task, add the product in the shopping cart, and enter the address information and then subscribe. Shopping cart beans maintain state, so it knows that all of these variables are associated with a particular customer. Entity Beans Entity (Entity) Beans indicates business objects or data that have long after session termination. They usually exist as a single record in the database, of course, its storage form may also adopt other media, such as files, and the like. An object represents a user, has a name, contact information, language selection, and so on, which represent the use of entity beans. As one of the most essential connotation of persistence, the unique identification of the entity bean acts as a role of identifying and retrieving the correct object information. Entity Beans requires primary keys as a unique identifier for the "secondary" package object. The two Beans types above the BEANs are served in EJB customers in synchronization. The customer issued a request and then waited for the bean to send the result. Message Driven Beans Avoid this possible bottleneck problem. The Java Messaging Service is used in Java Messaging Service. The client can generate a message and publish the message to the message queue. Message Driver Bean uses or retrieves messages to perform its content. This event or data is communicated into an asynchronous form; customers or beans do not need to rely on the direct response of the other party. For example, a bank official in London uses an application to publish the latest exchange rate message. At this time, the deployment of an external trading bean in Boston gets this message from the message queue and updates the relevant records in the database. In the ideal case, the message-driven bean transmits the information to an entity bean that handles the database transaction. In this way, each bean forwards it unable to process tasks to create a real distributed component structure. The principle of EJB does not consider the category of EJB, and the above three types form an EJB object: the implementation of the local interface, remote interface and bean. The client uses Java Name and Directory Interface JNDI (Java Naming and Directory Interface) to locate the local interface (JNDI) of the bean. The local interface then returns an instance of the remote interface, while exposing the necessary Bean implementation methods. The client program calls the appropriate method. The code shown in List A illustrates the above process.

Listing a first comes The EJB Client Class-in this case, a Very Simple Stand-alone user interface: import javax.ejb. *; Import javax.naming. *; Import java.util. *; Import org.shifter.ejb. *; public class VerySimpleClient {public static void main (String [] args) {try {Context ctx = getInitialContex (); VerySimpleHome home = (VerySimpleHome) ctx.lookup ( "simpleton"); VerySimple ejb = home.create (); Ejb.setname ("Fredrick"); system.out.println ("my name is" ejb.getname ()); ejb.remove ();} catch (exception e) {E.PrintStackTrace ();}} PUBLIC static Context getInitialContext () throws NamingException {// Retrieve the Context via JNDI lookup}} Now, we define the Home and Remote interfaces The client interacts directly with these classes: package org.shifter.ejb; // The home interface import javax. .ejb *;. import java.rmi.RemoteException; public interface VerySimpleHome extends EJBHome {public VerySimple create () throws CreateException, RemoteException;} package org.shifter.ejb; // The remote i nterface import javax.ejb *;. import java.rmi.RemoteException; public interface VerySimple extends EJBObject {public String getName () throws RemoteException; public void setName (String n) throws RemoteException;} Finally, we have the implementation of the EJB, where all functionality occurs: package org.shifter.ejb; import javax.ejb *; public class testertwoEJB implements javax.ejb.SessionBean {// Member variables private String name; private SessionContext ctx;.

// Default constructor public testertwoEJB () {} // Called by the create () method of the home interface.public void ejbCreate () {} // Called by the remove () method of the home interface.public void ejbRemove () {} // Called when the EJB container makes this bean active.public void ejbActivate () {// Resource allocation might go here.} // Called when the EJB container makes this bean inactive. public void ejbPassivate () {// Resource Clean Up Might Go Here.} // set the runtime context public void setsessionContext (sessioncontext ctx) {this.ctx = ctx;} // ***** // the folload methods area the only ones visible // to ejb clients THROUGH this bean's remote interface. // ***** public string getName () {return name;} public void setName (String n) {name = (n! = null)? N: "igor";}} you may Additional methods need to be implemented according to the type of beans. For example, if the customer needs to locate the entity bean, then your local interface will include the FindByPrimaryKey () method, which uses the primary key class as its parameters to return the appropriate object. As early as possible, the deployment descriptor packaged by each EJB object tells the behavior of the EJB container object. One of the descriptors, that is, the so-called ejb-jar.xml is to complete the above functions, which is a stateless session bean with all methods of container management transaction, as shown in List B.

Listing B VerySimple org.shifter.ejb.verysimpleHome org.shifter.ejb. VERYSIMPLE org.shifter.ejb.verysimpleejb stateless container VERYSIMPLE * Required According to the type of EJB container, another deployment descriptor tells the container how to identify and locate using JNDI BEAN. Taking the WebLogic server as an example, this role is WebLogic-EJB-JAR.XML, and the situation is shown in the program list C. Listing C VERYSIMPLE SimpleTon The usage of all EJBs involves some inherent dangers and possible problems. Programmers must comply with a lot of grammar and behavioral rules when encoding the EJB object. They must also determine the persistence management of bean itself or EJB containers; selecting errors may be data. Containers can even crash to destroy the event's session beans. The container may also lose information when trying to rollback transactions. Deploying an EJB object is a monotonous repetition process, which is almost impossible to make debugging in the case of the container source code. However, EJB component is highly highlighted, which saves its code, saving a lot of time and money during the development process. Developers can focus on the business logic itself, and deliver tasks such as security and transaction rollback to the EJB container. Reliable object instance management and convenient configuration is the highlight advantage of EJB. Learning and mastering the design rules of EJB is indeed a very time and effort, but its structure itself produces a very beneficial benefit during the development of applications. Author: BUILDER.COM

Deployment Procedures Enterprise JavaBeans (EJB) components are installed in a specific process called deployment. Support for deployment procedures by the container assembly. At the high level, the deployment consists of the following steps: BEAN developers create the required class file, interface file, and control information. Container analysis Enter files and generates the necessary classes. The container adds an entry to the JNDI namespace pointing to the local object. The developer of the EJB component writes the BEAN's Java source file, which contains the business logic method for this bean, and includes the ejbcreate () method. The Bean class must also implement a javax.ejb.sessionBean interface or a javax.ejb.entityBean interface. In addition, Bean's developers write interface files to define an extension to javax.ejb.ejbhome interfaces and javax.eb.ejbobject interfaces. The EJBHOME interface is extended, called the BEAN's local interface, including a creation method, and if the bean is an entity bean, it also contains a Finder method. The extension of the EJBObject interface is called the Remote Interface of the bean, specifies the business logic method defined in the bean itself. BEAN's developers provide control information consisting of deployment descriptors, environmental properties, and list files. The deployment descriptor is a serialization instance of a javax.ejb.deployment.sessionDescriptor object or a javax.ejb.deployment.EntityDescriptor object. Environmental Properties As the key-value pair stored in a file, this file can be accessed via the Java.util.Properties object. The single file is required to identify enterprise beans and its related files. Enterprise beans class files, class files, deployment descriptor files, environmental properties files, and monitored files are archived using file formats named EJB-JAR. The generated EJB-JAR file is provided to the container as an input to the deployment process. At deployment, the container analyzes the contents of the EJB-JAR file and takes the necessary operations to make this bean available. These operations include generating a new Java class that implements the local and remote interfaces of Beans, and the local interface is bound to the JNDI namespace, generating pile modules and Skeleton Helper classes, which are required to support RMI communications. The container can also generate a subclass of the bean, incorporating the code-specific code to facilitate the management of Beans. The class generated by the container is usually dedicated to the container, and is portable as the EJB component itself. Persistence, transaction, and safety provide persistence, transaction and security services for EJB components, EJB containers can play a major role. Is the responsibility of these services to the container or assume that the responsibility is responsible by bean itself, and the EJB specification provides flexibility in developers of Beans. For example, persistence support for entity beans can be managed by bean or by container management. If the EJB component developer chooses to use the container management persistence, they will add a property called ContainerManageDfields in the deployment descriptor. Depending on the EJB specification: "The value of the ContainerManageDfields property is a list of instance fields, the enterprise-level bean provider wants, the container manages these instance fields by loading or stores it from the database, the enterprise-class bean code should not contain any database access Calling - Database Access Call will be generated by the container tool in deployment. "Dedicated to the container that provides container management persistence support, usually provides a rich deployment time tool to allow enterprise-class Bean deployers to establish instance fields to basic data sources. Mapping.

It is generally believed that although the container provider's tool simplifies the mapping process, the mapping process may still involve the Bean deployer (ie the mapping process is not fully automatic). "Enterprise JavaBeans Specification 1.0) In addition to supporting container management persistence, the EJB architecture also supports the management of containers to transactions. This specification specifies:" Enterprise JavaBeans is a Advanced Component Framework, which trying to make application developers The complexity of the system. Therefore, most enterprise beans and their clients do not need to access transaction management through program. "Enterprise Javabeans Specification 1.0) When the BEAN's developer relies on the container, it is called the container management trimming, the container is used in the transaction attribute provided by the deployment:" Whenever the client calls enterprise beans, containers Will involve this method call. This intervention allows the container to explicitly control the transaction bound by transaction attribute. For example, if the enterprise-class bean deploys the TX_Required transaction property, the container will automatically start the transaction whenever the client calls the enterprise bean that supports transactions, and the client does not associate with any transaction context. "Enterprise JavaBeans Specification 1.0) If the developer chooses to support transactions within Beans, they specify the TX_Bean_managed transaction property in the deployment descriptor, and then you can freely use the Javax.Transaction.Usertransaction interface to divide the transaction boundary in Bean itself. Out of the TX_Bean_managed transaction property, the container knows that there is no need to intervene transaction support. By enhancing the restrictions specified in the AccessControlEntry object and the RunaS security ID, the container provides secure support for EJB components. AccessControLEntry objects on the bean level or for a single method, the Identity object Enterprise-class beans associates. Edentity object reflects users or roles that allow calls to beans. When the container is trying to access the data source or another bean, they will also apply Runas security identities to the EJB component. You can set the Runas identity as equivalent A particular user account, a system account or client security identity. Access control and RunaS information is specified in the deployment descriptor in the deployment descriptor, which will affect the container management bean. Although the EJB 1.0 specification also refers to security issues, more detailed security features, see subsequent versions of this specification. The relationship between CORBA and EJB technology Request a proxy architecture (CORBA) is a platform neutral and language of distributed objects. The neutral computing environment lays the foundation. In the CORBA environment, the function resides in the object, and the client can access these objects through the object request agent (ORB). The complete CORBA implementation provides ORB, which is called CORBA object service. Several runtime services for the CORBA utility. You can also provide only ORBs, which do not provide associated object services and utilities (for example, IBM provides such two independent ORBs). Software that implements basic ORB function is called ORB Core. In order to support language-independent, the CORBA application is written in the interface definition language (IDL). This language is similar to C in syntax, but does not include semantic: The operation specified in the IDL is an operation interface, not an operation implementation. Because of its support for multiple platforms and multiple languages, CORBA is ideal for managing the size of the company's size. Design EJB specification is also to support enterprise information systems.

Say this, is CORBA a competitor? According to the frequently asked Questions for Enterprise JavaBeans, the answer is negative: "In fact, EJB technology has a great supplemental Corba.Corba provides a powerful standard infrastructure that builds EJB servers on this structure .EJB technology. Enables the top floor of the CORBA infrastructure to build applications easier. "(Enterprise JavaBeans Frequently Asked Questions) Although the EJB specification and CORBA specification descriptions are different technologies, EJB implements certain aspects of current using CORBA technology. An example is RMI / IIOP. EJB specification requires EJB components and its containers to use Remote Method Invocation (RMI) technology to implement method calls between distributed objects. RMI specifies the syntax and semantics of the remote method, but does not specify which transport protocols should be used to provide network connections. The CORBA Internet Object Request Agent Protocol (IIOP) basically defines a method of transferring CORBA messages through TCP / IP. Developing an EJB implementation using the IIOP message form to exchange RMI data, how the EJB application can effectively use the part of CORBA technology. This network also supports interoperability with the CORBA application, which uses IIOP to send local CORBA messages, independent of RMI. IBM's EJB implementation, WebSphere Application Server, optimizes IIOP usage, how to make a clear distributed object reside on the same server and only call IIOP when the object is actually remote. In order to facilitate the development of enterprise systems that are incorporated into EJB technology, Sun Microsystems created a mapping between EJB specification and CORBA. The EJB architecture is mapped to CORBA, which affects several aspects of EJB technology, including object distribution, naming, and transactions. The main purpose of the CORBA mapping is to ensure interoperability between the EJB servers constructed by different manufacturers. Interoperability offers the following benefits: CORBA client can access the EJB component client program on CORBA-based EJB server can call to CORBA objects in transactions, and mix with the enterprise-class bean's call. Multiple beans, while these beans are also located on CORBA-based multi-EJB servers from different vendors using ORB clients from a vendor, and can access another manufacturer's CORBA-based EJB server to beans to access EJB components. The CORBA client, the bean interface is mapped to IDL. For example, the Buy () and Sell () methods defined in the stock trading bean can be specified as CORBA operations in the IDL file. Non-Bean's CORBA client, such as a C client, you can access this bean, and use standard CORBA call to call the bean method. If the container uses IIOP as its distributed object protocol, the duties of the container are to generate IDLs corresponding to enterprise-class beans and their interfaces. EJB Naming Services, which is based on the CORBA Object Services Naming service, so that the EJB component can be used for CORBA clients.

Java Naming and Directory Interface (JNDI) provides an interface to the CORBA naming service, and the client can access the service through the JNDI call indirect access to the underlying naming service, or you can access the service directly through the CORBA Object Services (COS) name API. EJB transaction supports Corba Transaction Service (Object Transaction Service (OTS). Java Transaction Service (JTS) represents the Java binding of the OTS, which is language neutral. CORBA-based EJB containers must identify transactions issued by the CORBA client through the OTS interface, and the EJB application emitted through the Java Transaction API interface, JTA is an application-level interface to JTS. The JTA also represents the Java binding of the Open Group XA interface to connect the application resource to an external transaction manager. The JAVAX.TRANSACTION.USERTRRANSACTION interface in JIA provides an API for the application level control of the transaction boundary. Usertransaction interface, which can be used as a bean with TX_Bean_Managed from its transaction property to be used by Java clients. Using EJB components Because the EJB architecture is designed to be highly flexible and supports the use of any complicated way to connect the enterprise bean, many different scenarios can be constructed, and how the application can use Enterprise Beans. A useful solution proposes to represent the EJB component as a key component of the three-layer information system, which connects the enterprise data, transaction, and application resources to the web. The EJB-based three-layer programming model will depend on the web browser as the first layer, and the web server supporting the application is the second floor, depending on the enterprise information resources as the third layer. In this programming model, in addition to EJB technology, Java Servlet technology, JavaBeans technology, and Java Server Page (JSP) technology are also implemented. The figure below shows the arrangement of each layer: The first layer is a thin client-typically a web browser, which can handle normal web data types such as HTML and GIF, and support HTTP communication. The second layer is a web application server, which is a web server with code to deliver running for applications that can be called through the web server. Existing web applications are used along the CGI-BIN programming model, but it is expected that the second-layer application development will turn to the Java Servlet programming model, which provides significant improved performance and portability. In addition to supporting Java Servlet, the web application server will also add an EJB server function to support applications using EJB components. The third layer represents enterprise information resources, which can include relational databases and object-oriented databases, transaction monitors, and customized applications. EJB technology plays a key role in this design because it resides in the second layer of application components, and the interface between the third floor, it is standardized. Java Servlet, Java Beans, and Java Server Page are not essential elements for the EJB application solution, but they can work with the EJB component to provide Java-based cohesive application environments.

The environment depicted here will assign the following responsibilities to the Java component participating in the work: Specify the Java Servlet's role JSP page processing data representation and user interface Java Bean acts as a "data package", storage intermediate The result of the data EJB component provides a mechanism for accessing the enterprise information resource. You can use a hypothesis, EJB-based web application update existing inventory, and use container management persistence and container management transactions, will access the inventory database location package Inside the entity EJB assembly. Inventory tickets can be entered via web browser, the browser provides an HTML form to capture product numbers, suppliers, etc., and call a servlet when submitted. The servlet code acts as an application controller role to determine which corporate databases need to be updated, requiring users to apise the information. The servlet can access the main inventory database by representing its entity bean, and call the JNDI interface to get a reference to the local object of this bean, and then use the finder method to locate the remote objects of the requested product number. At this time, by calling the remote object, the servlet can update the inventory count, and then the container will delegate this method to the EJB component. Because the container is updated according to the database, it is maintained in the transparent manner to the BEAN transparent, and the data is written to the database to ensure data persistence, so the data is maintained. Any result information returns from the EJB component to the servlet, you can use the setter method to store in an attribute of a (non-enterprise) Java Bean. The servlet can transfer control to an appropriate JSP page to combine these results into the representation and return the result to the user. The JSP page is likely to be composed of static text and variable information placeholders related to a single transaction. The JSP page uses the Getter method to get variable data elements from the Java Bean before sending a data to the browser. EJB-based three-layer design provides several benefits, including: Accessing the business logic of enterprise data can be packaged in reusable, portable enterprise beans. Existing enterprise systems can be integrated into enterprise-class beans only need to be modified or do not need to be modified. The runtime services required by the enterprise application, such as transactions, and persistence, can be broken down from the bean and specify containers to this bean. You can modify the servlet of the Control Application Process without changing the EJB component. The Servlet code can focus on application control logic without considering data representation. The JSP page can be mixed together and generate information. System components written in Java language are portable for any platform with JVM. Conclusion In the process of developing an enterprise information system that supports key tasks, the EJB specification represents the next stage of development of Java technology. The EJB component extends to the server field with the JavaBeans specification, so that the development of business logic components can be reused across enterprise applications, and can transplant cross-supporting Java. Since it contains an Object distribution based on RMI technology, the discretion of multi-layer executable components is supported, allowing maximum implementation and high scalability. If the regular enterprise application runtime service is redefined as an object service that can be specified to the container, the developer that allows EJB components to concentrate on business logic, reducing the complexity related to the runtime service. And platform relevance. Enhance the Java operating environment to include standard interfaces, relational database access, transaction services, and remote object access, so that Java developers can write robust enterprise applications without having to leave the Java programming environment.

Use other Java technology-such as Java Servlet and JavaServer Pages technology - with EJB components, you can create a compact programming model for large enterprise systems, but because of using clever interfaces, it simplifies development work. . Moreover, because the EJB architecture is a logical extension of the JavaBeans component model, the business logic developed as an EJB component can be reused across multiple enterprise applications. Another benefit of an enterprise-level Bean architecture is to provide a direct integration channel of existing enterprise information systems, which may be unansee with the Java programming language or bean programming model. Because of existing enterprise information resources - custom new varieties for relational databases, transaction monitors, and business applications - can be connected to the web front end by encapsulating them in the EJB component, without replacing the application or rewriting the main code Segment, so customers protect their existing IT investments. Considering the huge prospects of EJB technology, the IT industry welcomes EJB specification with considerable interest, is not surprising. One of the biggest benefits provided by the EJB architecture may be to leave business logic programming with complex set components of business logic and enterprise-class server-side running environments. If the container deploys the EJB component has undertaken the role of the management runtime service (such as persistence, transaction, and concurrent database access), the BEAN's developer can freely focus on the software components of the development package business logic. Javasoft Vice President expressed the importance of EJB technology (from Sun Microstems website): "The 'Enterprise JavaBeans API will provide a new strategic weapon for enterprise developers and solution providers for them to build next-generation industry, Based on key business applications, the Vice President of the Javasoft Software Products for 'Sun Microstems, Jon Kannegaard, said:' Because applications designed with Enterprise JavaBeans API will work with existing enterprise systems, companies use Java platforms to get new The competitive advantage, but also retains their investment in prior art, 'Kannegaard continues. "Use Enterprise JavaBeans API, developers will be able to eliminate complexity during application development. This is possible because each Enterprise JavaBeans component encapsulates a basic business feature. At present, developers must know how to write business logic and specialized system-level procedures to control the ability such as security features and handle multiple transactions - a boring and complex task. Enterprise JavaBeans API enables all developers to focus on writing a logical solution to business issues, rather than concentrating on writing code to simplify different technologies. "(Press Release: Sun Releases Draft Enterprise JavaBeans Specification for Public Review) reference site by associated FAQs Sun-depth understanding of Java technology and EJB architecture access to Enterprise JavaBeans Specification 1.0, please see the Enterprise JavaBeans specification See the full press release... The IBM WebSphere Application Server uses EJB technology. The Summary Ken Nordby is a software engineer in IBM Software Development Laborators, which is located in Research Triangle Park in North Carolina.

As a member of the SWG Product Affinity Services business team, Ken works with IBMs developed and consulted for IBM WebSphere Application Server (IBM technology). You can contact Ken through nordby@us.ibm.com. What is ENTERPRISE JAVABEANS component? (1) Recommended: SIMON Category: Java Published: 2002-04-09 Popularity: 1781

Part 1: EJB architecture history and objectives This article provides an overprise javabeans (EJB) technology to allow readers to quickly understand the basic concepts. Part 1 describes the history and certain goals, advantages and techniques of EJB technology. For the sake of simplicity, there is a choice to tell some key elements of EJB technology. Note that although the EJB component relies on some basic Java services such as Java Transaction Service, the benefits of using EJB components and meet these components do not need to master the knowledge of these related technologies. Enterprise Javabeans Technology has been well received since 1998. The following paragraph is an example: "Since I have introduced more than two years, Enterprise JavaBeansTM technology has also maintained an unprecedented momentum in the development team of platform suppliers and businesses. This is because EJBTM server-side component model is simplified The development of the middleware components, these intermediate components are transactional, retractable and portable .Enterprise JavaBeans servers provide automatic support for middleware services such as transaction, security, database connection and other), decrease The complexity of the development of middleware. "(Sun Microsystems website) Enterprise JavaBeans This name uses Java Bean - this portable, reusable Java software component reputation. Enterprise JavaBeans technology extends the concept of Java components from the client domain to the server domain: This is a one-time meaning of Java technology growth. It has developed Java technology into a strong, retractable environment that supports tasks. Key enterprise information system. The Java Application on the server is a reason why you get praise in the web developer is that it supports downloadable Java programs called applets. The support of Applet is built into the Applet class to the Java Development Kit (JDK) of the 1.0 version. According to the Time framework of version 1.0, Java development is an applet and an application as a center. JAVA readings based on JDK 1.0 are from the perspective of Applet and applications: "Java programs consist of one of more class definitions, each class definition has compiled into its own Java virtual The .class file of the machine code. One of these classes must define a method called main () (), the program is starting from this method. To call a Java program, you need to run Java Interpreter Java, and specify main () The name of the method of the method. Please note that Java Applet is not an application - it is a Java class that is loaded and running the Java application (such as a web browser or applet viewer). "(See Flanagan) The Java In a nutshell) Java application can run on the server, but no matter whether it is in a client-server environment or in a web-based environment, JDK does not provide the Java application to the server machine. Or bag. Recognizing the potential of Java as a server language in the web environment, Sun Microsystems wrote the Java Servlet specification. Servlet is similar to applet, which is a Java program designed to run on a web server machine: "Servlet is a web component managed by the container, which can generate dynamic content.

Servlet is a small, unrelated to the platform, is compiled into an architecture code in the architecture. This code can be dynamically loaded on a web server and running it by this web server. The servlet interacts with a Web client through a request-response model implemented by a servlet container. This request-response model is based on the Hypertext Transfer Protocol (HTTP) behavior. "(See JavaSoft's" Java Servlet API Specification ") Under a web server control, run a number of small user programs on multiple servers, this idea is not fresh - a period of time, the public gateway interface (CGI) program ( It is often called the CGI script that has been playing this role and promotes the popularity of the Web. However, Java Servlet can achieve this with higher efficiency and portability, so it is expected to eventually replace the CGI program. Servlet provides a running environment (often referred to as a servlet engine) to existing, itself does not support the Java executable web server. Java servlet, to create a web application for the application using Java The program has opened up a new way. However, only servlet does not provide a complete model for real enterprise calculations. CGI app itself is often not a complete application, when processing information requested from users on a web browser, CGI It is just an intermediate step in the entire process. For example, a common use of the CGI application is to access the database. When used for this task, the CGI program provides a way to connect the user's data request to the meeting. The requested corporate database .CGI program often acts as an intermediate software, receives a request from a web browser, and decides which compute resources must be called to meet these requests, and send back responses to the browser. Java servlet is the same as the CGI program, the most suitable Acting the intermediate layer component of the connection front-end Web request and backend data resources. The three-layer architecture web programming evolution to the server-side Java application, which also brings the evolution of the architecture, making it separated from the conventional client - server two The layer model is developed to a three-layer approach. The two models have been innovative because it unresses some computing tasks from the main processor. General LAN-based database applications is an example Among them, the database manager server software resides on a dedicated server machine, and the user accesses the database through the client code on their workstation. As the client-server model grows to the use, it will appear. The server scalability and the focus of client code size and complexity. So three-layer architecture to avoid weaknesses that have been perceived in the two-layer model, so that the Web can become a computing platform: " Many people ... assertion, traditional client / server two-layer architecture does not have good scalability because the number of user connection and data access cannot be predicted, and there is also a problem in some system management. To handle the limitations of the two-layer architecture, many developments are turning to the three-layer architecture. This architecture can be roughly defined as: a representation of the representation of the client layer, an intermediate server, and a backend. The purpose of this idea is to mitigate code expansion on the client or database server, centralized management business logic, more flexibly use the database, not only to use the stored process and trigger. "(See KIM" Looking for A 3-Tier App Builder? ") A three-layer structure model is often imagined as a web browser as a client layer .Web browser is a true general client, Make it from the concept of "fat client" of the two layers.

If the browser is recognized as a standard thin client for the web application architecture, what will the function of the fat client reside in the two-layer model? Now, the application dedicated function is not to place back to the server (such as database manager), but intentionally resides it on a new intermediate layer. The intermediate layer supports application server software, which is a form of middleware that is in the first floor of the thin client's minimum function and the rich features of the server-side service system on the third layer. Since the three-layer architecture is closely related to the web processing model, the intermediate application server is often considered a functional extension of the web server. Existing web applications utilize the CGI program, transmit users from the web browser to the unmopable business system, and return to the browser, which is an implementation of the three-layer model. These applications have gradually transferred to servlet technology. The three-layer model is enhanced. JavaBeans Components JavaBeans Specifies the concept of "Component Software" into Java programming. Components are self-contained, reusable software units; and JavaBeans components, you can use visual application development tools to write them into the Java program. The Javabeans specification provides a "Component" Method for "Component". Any Java class with a certain feature and an event interface can be a bean. (See JavaSoft, "Using the Beans Development Kit 1.0") If the software reuse is a good idea, should you make every Java class be a Java Bean? If the Java class meets certain guidelines, they are suitable as a role of bean: Before developing any new software, it is worth considering whether it is developed in the form of javabean. Such software modules may be adapted to make a JavaBean if the software module is capable of being able to operate, but also customizes some effects. To help you determine if the software to be developed should be a Javabean, assume it should be written in Java, please ask you the following questions and make a decision accordingly: Do you plan to make it reuse? Or, will it be reusable? Do you want to use it with other reusable Java components? Do you expect to use it in the IDE tool? If the answer to the above problem is affirmative, it should be developed as JavaBean. (See DeveloperWorks "JavaBeans Guidelines" JavaBean concept is to support reusable components in the Java programming environment, which is a general design method for Java programs running on clients or server machines. Due to the emphasis on visible builder tools, since many Java Beans are graphical user interface (GUI) components, JavaBean components may be considered a client technology. However, Java Bean is not required to be visible, and they can also be used in server environments. Java classes encoding Java Beans typically have the following features: use design mode. These modes are the coding convention for methods and interfaces. Support visual software development tools. Classs must be displayed (called attributes), methods, and events. Can be customized. Customization includes supporting the default attribute editor or providing a single custom rule. Customization enables the developer to change the behavior of Bean without having to change source code. Support from introspection.

This refers to the disclosure of the properties, methods, and events to other classes, can accomplish this in design mode or by creating a BeanInfo class. It is lasting. This allows a bean to be customized in a visual builder, and then saved in its custom state. Java 2 Platform, Enterprise Edition Sun Microsystems launched a technological innovation called Java 2 Platform, Enterprise Edition (J2EE) to extend the range of Java platforms to large-scale server environment: "On April 12, 1997, Sun An innovation result of developing Java platforms for corporate environments is announced. Using open Java Community Process, Sun promotes a set of standard Java extensions, called Enterprise Java API. These application programming interfaces (APIs) are each The implementation of a variety of middleware provides a programming interface that does not depend on the vendor. The mainprise java API is the Enterprise JavaBeans API, the latter defines a server-side component model for the Java application server, and a supplier Programming interface. "(See Thomas" Java 2 Platform, Enterprise Edition: Ensuring Consistency, Portability, And Interoperability) J2EE provides the Enterprise JavaBeans technology. In fact, SUN envisages several software technologies to make such components, which will enable large companies to transplant in the Java environment with task-critical business systems, and Enterprise JavaBeans technology is only one of these technologies. The EJB component is defined according to their own specification, but EJB technology is not an independent technology. It is built on other Java technology, which is jointly provided by Sun and other IT companies, and they provide this framework, which is called Java 2 Platform, Enterprise Edition. J2EE includes the following technologies: Enterprise JavaBeans (EJB) technology Java Interface Definition Language (IDL) Java Message Service (JMS) API Java Naming and Directory Interface (JNDI) Java Remote Method Invocation (RMI) and Object Serialization Java Servlet API Java Transaction API (JTA) Java Transaction Service (JTS) JavaServer Pages (JSP) Technology JDBC Database Access API is involved in this enterprise Java framework, does not mean that each technology relies on all other technologies. Separate specification documents indicate the correlation of each technology. For example, the Enterprise JavaBeans Specification 1.0 release indicates the correlation with JNDI when locating each component, and the correlation between the JTA when the program is started and stopped in programming. EJB technology design objectives EJB specification was announced in December 1997 in December 1997 in March 1997. The specification author has developed the following objectives for the EJB architecture: Enterprise JavaBeans architecture will be a standard component architecture for building distributed object-oriented business applications in Java programming languages.

The Enterprise JavaBeans Architecture will be possible to build a distributed application by combining components developed using tools from different vendors. The Enterprise JavaBeans architecture will make the written application easy: application developers will not have to know the details of low-level transactions and status management details, multi-thread, resource sharing, and other complex low-level APIs. However, the expert-level programmers will be allowed to access the lower API directly. Enterprise JavaBeans Applications will follow the principles of "one writing, running" in the Java programming language. The EJB component can only be developed once, then deploy on multiple platforms without re-compiling or modifying the source code. The Enterprise JavaBeans architecture will handle development, deployment, and operations in the business cycle of the enterprise application. The Enterprise JavaBeans Architecture will define some conventions that make the tools provided by multiple vendors to develop and deploy components that can be interoperable at runtime. The Enterprise JavaBeans architecture will be compatible with existing server platforms. The vendor will be able to extend their existing products to support Enterprise JavaBeans components. The Enterprise JavaBeans architecture will be compatible with other APIs written in Java programming languages. The Enterprise JavaBeans architecture will provide interoperability between EJB components and non-Java programming language applications. The Enterprise JavaBeans architecture will be compatible with CORBA. What is the benefit of using EJB technology? What is the benefit of enterprises and developers? It is listed below to benefit from the Enterprise JavaBeans environment: EJB components make writing applications easier. Although the EJB architecture is complex, application developers generally do not have to write code for accessing system services. A system component called an EJB container allows system services to be used for the task of EJB components. Server-side business logic can be transplanted. In addition to the inherent portability of Java language, the EJB architecture also provides a set of standardized application programming interfaces between Beans and the containers that support the bean. This allows developers to transplant Beans from one operating environment to another, without having to rewrite their source code. Server-side applications can be installed from existing software components, which is the same as the client application can be assembled from existing Java Beans, so that the software can be reused. The EJB architecture has built-in support for typical enterprise-class system services, including distributed objects, transaction processing, database, security, and global naming. Many IT suppliers adopt an EJB architecture because there is such a commitment: customers will be able to purchase software components from selected vendors, such as EJB components, containers, and EJB servers; also committed different suppliers Products, as long as it meets the EJB architecture, it is interoperable. Applications built with EJB components can be ported from one server to another, which supports scalability because in the EJB model, each software component is strictly separated. The EJB architecture guarantees the original IT investment, which is allowed to replace the existing technology by allowing existing information systems and asset "package" without requiring customers. In fact, companies that store data in the relational database have already had a prototype entry bean, waiting for access to the EJB shell. Further investigation JAVA Naming and Directory Interface (JAVA Naming and Directory Interface (JNDI) to access various directory services. JNDI is divided into two parts: Application Programming Interface (API) and Service Provider Interface (SPI): "JNDI Architecture consists of JNDI API and JNDI SPI. JNDI API allows Java applications to access various named namings and directory services.

JNDI SPI is designed to serve an supplier (also including directory service providers). This makes a wide variety of directory services and naming services to be transparently inserted into the JAVA application using the JNDI API. (See JavaSoft, "JNDI: Java Naming and Directory Interface" JNDI API and different dedicated naming techniques or directory technologies are connected together, and there are also any supplier directory services, so it can be used for EJB components. The transplantability contributes. For example, customers can choose from a variety of different technologies to provide directory services for their EJB applications, including: LDAP: Sun LDAP service provider supports 2nd Edition and 3rd editions of LDAP protocols. NIS: Sun provides an NIS service provider (NIS, network information service, previously referred to as yellow pages). COS Name: Sun's COS Name Service Provider provides access to CORBA naming services. File System: Sun provides a service provider to access the file system. RMI Registration: Sun provides a service provider for RMI registration. Novell: There are several service providers to provide access to directory service NDS and NetWare 3X connection library, Novell file system, and other Novell services (such as extended NCP). Although the JNDI specification is neutralized to the supplier, it should not be considered that the application server that implements JNDI interfaces must access service provider code from multiple vendors. The key concept of the JNDI naming architecture includes: the binding between objects and names. Some bindings are called name contexts. Name the system, that is, several groups named context. Namespace refers to all names in a naming system. Name is classified as atom name, composite name, and synthetic name. The atom name is indivisible and can be bound to an object. The composite name is a combination of atom name, while the synthesis name spans multiple naming systems. Naming context is especially important: All named operations are made on context objects, and the name resolution process always starts from the initial name context. How is the EJB application use JNDI? JNDI's main use is to retrieve reference to EJB components. Because the EJB framework is a distributed object framework, the EJB application should not assume the location of the EJB component. JNDI is a mechanism for obtaining starting references to beans. When a bean is installed on an Enterprise Bean server, a software component called an EJB container is responsible for creating each name - object binding, making the required Java class file to use this bean. Application uses JNDI lookup method to retrieve an object reference, in the following example: Context initialContext = new InitialContext (); CartHome cartHome = javax.rmi.PortableRemoteObject.narrow (initialContext.lookup ( "applications / shopping_cart"), CartHome.class ); The application is responsible to know the external name, the application is to reference an Enterprise Bean through this name, and get references to the bean through JNDI. Further investigation of JTA except JNDI, the Enterprise JavaBeans architecture also uses Java Transaction API (JTA). Because the transaction is important for maintenance data integrity and reliability, support transaction processing is a basic part of the EJB architecture.

If an enterprise application is distributed, transaction processing will be more important: "The concept of transaction is an important programming example, its purpose is to simplify application structures that require both reliability and requireability, especially those who need to access sharing Data Applications. The concept of transaction is earliered in a business-operated application, where it is used to protect data in a centralized database. Later, the concept of transaction has been extended to a wider range of environments for distributed computing. Today, the transaction is the key to building a reliable distributed application. This has been widely recognized. "(See the" Transaction Service Specification "of the object management group) Sometimes the transaction is a work unit with the following characteristics: atomicity - if Because of the failure, all results are revoked - the result of the transaction reserved the constant characteristic Isolated - the intermediate state is invisible for other transactions - the result of the completed transaction is the termination of a lasting transaction. Mode: Submitting a transaction will make all the changes permanently, and rollback back is a transaction to revoke all its changes. Object Management Organization (OMG) is an object-oriented transaction service, an object transaction service (OTS) creates a specification. OTS is the basis for transaction services in the EJB architecture. The following affairs is the transaction model used by Enterprise Bean: OMG Object Services (OTS) Sun Microsystems Transaction Service (JTS) Sun Microsystems Java Transaction API (JTA) Open Group (X / Open) XA interface This object-independent object transaction service provides basic concepts, definitions, and features for a strong distributed transaction service. Java Transaction Service is OTS's Java mapping, in org.omg.costrasactions and org.omg.costsportability these two packages. JTS supports services such as transactional boundaries and transaction environments. The JTS function is accessed by the application via Java Transaction API. Java Transaction API Specifies a variety of advanced interfaces between transaction managers and other system components involved in distributed transactions, these system components include applications, application servers, and resource managers. The JTA feature allows transactions managed by the application itself, managed by the application server or by an external transaction manager. The JTA interface is included in the two packets of javax.transaction and javax.transaction.xa. The XA interface defines the agreement between the External Transaction Manager in the resource manager and distributed transaction environment. External Transaction Manager can coordinate transactions across multiple resources. The XA's Java mapping is included in the Java Transaction API. The second part of the content preview "What is Enterprise JavaBeans Component?" Will discuss the EJB programming model. References To learn more about Java technology and EJB architectural structure, please visit Sun's website. For Java Programming from Applet and Applications, please read the java in a nutshell in David Flanagan. Download a copy of the Java Servlet API Specification. Download the "Looking for A 3-Tier App Builder" (PDF) written by TOM KIM in Java Developer's Journal No. 3 No. 1 Medium TOM KIM. Participate in the "Using The Beans Development Kit 1.0" course in Javasoft.

Some supplementary guidelines can be found in "Javabeans Guidelines", which enables you to develop performance-based beans, which can perform well in most environments, including popular Ide and various browsers. Read the Detailed Description of J2EE in "Java 2 Platform, Enterprise Edition: Ensuring Consistency, Portability, and Interoperability" written by Patricia Seybold Group. An overview of the JNDI architecture and interfaces in JNDI: Java Naming and Directory Interface, and various situations and examples. Learn Java 2 Platform, the Java technology Enterprise Edition contains: Java IDLJava Message Service (JMS) API Java Naming and Directory Interface (JNDI) Java Remote Method Invocation (RMI) Java Transaction API (JTA) Java Transaction Service (JTS) JavaServer Pages (JSP) Technical JDBC Data Access API To understand common problems, with LDAP-related RFCs and more, visit the LDAP website of Mark Wahl. To learn how to configure Linux to NIS (YP) or NIS clients and how to install it into a NIS server, please consult Linux NIS (YP) / Nys / NIS HOWTO. Download Naming Services of Java IDL COS Naming. Learn more about Java Remote Method Invocation (RMI), including specifications, examples, and common problems. Learn about the large number of products and solutions from Novell. Visit the website of Object Management Group (OMG). Check out the XA Interface specification of the open group. About the author Ken Nordby is a software engineer in the IBM software development laboratory of Research Triangle Park, North Carolina. As a member of the SWG Product Affinity Services Working Group, Ken and his IBM colleagues are engaged in the development and consultation of IBM WebSphere Application Server (Enterprise Javabeans IBM implementation). You can contact Ken through nordby@us.ibm.com. Part ICI: EJB Programming Model The second part of this article describes the role of Java interfaces and classes required to create Enterprise JavaBean components. In addition to encoding the Bean class itself, EJB developers must also define a local interface and a remote interface for beans. The implementation class of these interfaces is typically generated by the container, so the deployment EJB component is a cooperation behavior of developers and EJB containers. The second part also distinguishes two main types of Enterprise Beans, namely session beans, and entity beans, and illustrates the relationship between EJB containers and EJB servers. The three key features of the Enterprise Bean programming model are: object-oriented, object distributed and use a proxy object. Since this programming model uses Java technology, it is inherently object-oriented. This model is also distributed, refers to Bean theoretically, transparent. According to ENTERPRISE JAVABeans (EJB) specification, "Generally, the actual location of the EJB class and EJB containers is transparent to the client.

"When the client wants to access the EJB component. Bean itself is unacceptable to the client, and the access to the bean method is provided by the Helper class. Interface, delegate and proxy When the Java programmer write a Enterprise JavaBeans component The class they created must implement an EJB interface, and it must contain a method called ejbcreate (). An EJB interface - such as the sessionBean interface - specifies some methods, including the following: ejbactivate () Ejbpassivate () EJBREMOVE () setSessionContext () EJBACTIVATE () and EJBPassivate () methods Notify a bean that manages the BEAN's container assembly to switch between the bean between active and passive (this is usually referring to the memory or swap to disk). The ejbremove () method makes the bean know that it has been removed from the container.SetSessionContext () method enables the bean to associate with a context object, this context is to facilitate the BEAN to communicate with its container .Ejbcreate () method is not from zero Create Enterprise Bean. When the client wants to create a new Enterprise Bean, the bean's container will call the new BEAN object to instantiate the new bean object. Then the container calls the setSessionContext () method to create context. Objects are used to communicate with beans. Finally, the container calls the EJBCREATE () method in the new bean. Methods like ejbcreate (), ejbactivate (), and ejbpassivate () are sometimes referred to as an object survival process, to distinguish business logic Method. When developers designed a new EJB component, the code written in the ENTERPRISE BEAN class is not enough. EJB programmers must also write two Java interfaces that will be used by the Helper class. These mandatory interfaces must extend the standard EJBOBJECT And the EJBHOME interface, and the two interfaces are extensions of the Java.rmi.Remote Marker interface. The interface of the extended standard EJBObject interface is called the remote interface of Enterprise Bean, which specifies the business method defined in Bean itself. Program call When the business method in Enterprise Bean, the application does not access the bean itself. In fact, the method call is passed to the object that implements the EJBObject interface extension. This approach is called a delegation, it is a design key in the EJB architecture: "The client never directly accesses an instance of the Enterprise Bean class. The client always uses Enterprise Beans to access the Enterprise Bean instance. Implement Enterprise The class of the Remote interface of the bean is provided by the container. The distributed object of this type is called the EJB object. "(Enterprise JavaBeans Specification 1.0) Bean is called its remote interface to the EJBOBJECT interface, and the object of the remote interface is called For the EJB object. Enterprise Bean must also have a local interface. This interface is an extension of the standard EJBHOME interface. Objects to implement the local interface of the bean are called local objects. Local objects contain a create () method, this method is called by the application, and the application must create a bean instance. The CREATE () method in the local object creates a new EJB object. It does not create a new Enterprise Bean instance because it is not allowed to access beans directly.

EJB objects and local objects serve as a proxy for bean objects because they call on the bean receiving method. The EJB object is mainly served as a proxy for the Bean business method; the local object is mainly served as a proxy for the BEAN survival cycle method. Use the create () method for EJB components and do not have to instantiate new beans. The container determines how best to meet the creation request, for some types of beans, it can reuse the existing instance: "Client uses the Create and REMOVE methods on the local interface of the session bean. Although the client thinks it is controlling the EJB instance The survival cycle, however, is the container in processing Create and Remove calls, and does not have to create and delete EJB instances. There is no fixed mapping between clients and ... instances. Containers just entrust the client's work Any method is ready for useful instance. "Enterprise JavaBeans Specification 1.0) Creating a new bean instance is controlled by the container and can publish the Create () method asynchronously with the client. When creating an EJB component, the developer is responsible for defining the EJBObject interface and the EJBHOME interface, but does not need to write code of the class of these interfaces. EJB container software components automatically create these classes. The following code segment explains how the client application may use Enterprise Bean called CartBean for online shopping: carthome cartHome = javax.rmi.portableremoteObject.narrow (InitialContext.lookup ("Applications / Shopping_cart"), CartHome.Class; Cart Cart = CARTHOME.CREATE (); cart.additem (item29); cart.additem (item67); cart.additem (item91); cart.purchase (); cart.remove (); carthome is a class that implements local interfaces ( Extension of the EJBHOME interface). CART is a class that implements a remote interface (extension of the EJBObject interface). When the client calls an application method (such as addItem () and purchase ()), they are called on the CART object, and this object then delegates the implementation of these methods to the bean itself. The functionality of Enterprise Bean is obtained by its agent EJB object (ie, Cart). What happens if you visit Cart Bean at the same time? Enterprise Bean developers do not need to write code to support concurrency access. Concurrently supported by EJB container. The following figure illustrates the relationship between each EJB object:

Server and container EJB architecture includes two concepts of EJB servers and EJB containers. The EJB server acts as a component execution system, as described in the EJB White Paper: "Enterprise JavaBeans specification defines a standard model for each support fully portable Java application server. Any vendor can use this model to implement Enterprise JavaBeans components support. A variety of systems (such as TP monitors, CORBA runtime systems, COM runtime systems, database systems, web server systems, or other server-based runtime systems) can be adjusted to enteterprise JavaBeans capable of supporting portable Components. "(Thomas, Enterprise JavaBeans Technology: Server Component Model for the Java Platform) EJB Server provides an operating environment for applications using EJB components, and provides all required services to support EJB architectures. Packing EJB server software does not pre-specify. One way is to enhance it as a functional enhancement into the application server, which is the method used in IBM WebSphere Application Server, Advanced Edition, Version 2.0. The EJB component is not directly executed at the top of the EJB server. A intermediate software component called an EJB container runs in an EJB server environment, providing operational environments for these beans themselves. The EJB container is completely transparent to the EJB application, but it plays a key role in supporting Bean operations. In order to enable Enterprise Beans to act as reusable software components, they cannot have built-in correlations for specific servers or platform functions. Several common types of server-side functions have been "separated from" in the bean design, and the responsibility of this feature is transferred to the container component. For example, the container will be used to take over security, concurrency, transaction, exchange to the auxiliary memory and other services, so that Bean is protected from server-dependent, and will be optimized according to business logic, not by service. Logic is optimized. EJB white paper describes the role of the container: "EJB container management is deployed in the Enterprise Bean. Client applications are not interacting directly with Enterprise Bean. In contrast, client applications are through two package interfaces generated by containers (EJB Home Interface and EJB Object interfaces are interacting with Enterprise Bean. When the client calls various operations using the package interface, the container intercepts each method call and inserts management services. "(Thomas, Enterprise JavaBeans Technology: Server Component Model for the Java Platform) You can expect EJB container software generally with EJB server software, although these components are allowed to be separated. In addition to providing access to runtime services such as transaction processing and security), it is also desirable that EJB containers include a variety of necessary tools to support Enterprise Beans installation, operation, and management. For example, there is a need to explain the content of the EJB JAR file. There is a tool generated database access to obtain persistence provided by the container, and tool monitoring is running the behavior, and implement security. Bean style EJB components are divided into two main categories - session beans and entity beans. These categories can also be further subdivided according to the method of processing status, transaction and persistence.

Session beans typically have the following properties: representing a single client execution can be a transactionality that can update the relatively shorter life of the data survival in the shared database is usually a client's survival of any persistent data, which is managed by the container. Judgment to delete the entity bean when the EJB server fails, is typically having the following attributes: the data in the database is transactional to allow multiple users to access multiple users can have a long-term persistence data can be managed by the container to manage after the EJB server fails. Continue to survive EJB specification The description of the session bean and entity beans is as follows: "For clients, session Enterprise Beans is a non-persistent object, which implements business logic running on the server. Imagine a session object The way: The session object is a logical extension of the client program running on the server. The session object is not shared between multiple clients. "For the client, entity Enterprise Bean is a persistent object, which represents a storage in a lasting Object views of entities in sex memory (eg, a database), or an entity implemented by existing enterprise applications. "Enterprise JavaBeans Specification 1.0) With a rough statement, session bean represents such an operation, it retrieves or stores data to meet user requests; and entity bean represents a data set, you can access these data sets to meet user requests The easiest way of conversation bean is a stateful session bean because these beans can distinguish their status, all instances are exactly the same. Container manages the survival cycle of stateless session beans, the way By creating a sufficient number of beans to accommodate the client's workload and delete it when you don't need them. Passivation, the idle bean is written to disk, no useful session. To call bean, client The program calls the Standard Create () method in the local interface, although this operation does not necessarily lead to a new bean instance. The container can choose to send the client request to an existing object. Conversely, the container can create a new The instance, and independent of the Create () method published by the client. Create () calls released on the EJB local object returns a reference to the EJB object, this EJB object represents Enterprise Bean. Once the client has an EJB object reference It can publish the business method to the EJB object. The container will entrust these methods to bean itself. The container components responsible for the management session bean do not need to inform whether the session bean is stateless. Session bean is still there is still still Status at the installation. If the session bean reserves status information between method calls, it is stateful. By calling the ejbpassivate () method, the container can determine the state session bean passivate, or write auxiliary Memory. EJB specification does not require containers to use Java serialization protocols when passivating Beans, but they must provide an equivalent function. When the container decides to exchange a non-active session bean back to the memory, it will cancel it Passive bean serial, and calls the ejbactivate () method. Developers with state session beans are responsible for ensuring status data is serialized. In the cluster's application server environment, there is a status session bean time, because Not all servers support the synchronization of the status session bean of the cluster. Status Session Bean can be transactional.

By using the method in the Javax.Transaction.UserTransaction interface, such as Begin (), Commit () and Rollback (), beans can control the transaction; BEAN can receive a notification on transaction status by implementing a Javax.ejb.Sessionsynchronization interface. EJB containers do not need to infer which beans require transaction support; the UserTransaction interface can only be used for Beans that are labeled as transactions when installing. The entity bean entity bean is similar to meeting beans in the architecture, but they provide access to corporate data, not to support user sessions. An entity bean can support multiple concurrent users, while the container makes access and transaction synchronization. Entity Beans also has primary keys for supporting the Finder method in the local object. A client that knows the primary key of entity beans can get an object reference by calling the Findby PrimaryKey () method on the local object. Unlike session beans, the local object of the entity bean has a Finder method except for the Create method. Persistence is a basic attribute of entity beans. The EJB specification allows two forms of entity persistence: BEAN management persistence and container management persistence. For entity beans in the representative database, Bean's management of persistence means that calls to database access are directly written in the enterprise bean (using JDBC or SQLJ). This method is straightforward, but it reduces portability. The management of containers on persistence means that Beans are not affected by database calls. Inform the container during installation, the persistence of the bean data is installed, while the container is responsible for generating a code that implements persistence. This approach allows the bean to be more portable, even achievable extent to which different data sources can be used. However, this method requires complex functions in the container. When the entity bean object is associated with the EJB object, the former is in the ready state; otherwise they will be in a shared state. When the client calls the method in the EJB object, the container looks for an instance of the associated entity bean (if present), or transmits an instance from the shared state. Entity beans in ready state can receive a business method call to them by commissioning from the client. They can also perform the EJBLOAD () and EJBSTORE () methods when the container request is requested. The LOAD method and the Store method are intended to maintain the consistency between the entity beans and the underlying data storage. Entity beans support multiple users and access data. EJB specification declaration, maintaining data integrity is the responsibility of the container: "Enterprise Bean developers do not need to worry about the concurrent access from multiple transactions when writing business methods .Enterprise bean developers can assume that they can be assumed to be used for multiple transactions Access each entity bean will ensure proper synchronization. "(Enterprise JavaBeans Specification 1.0) Container Complete this task is usually by locking data in the database and accessing serialization, or by creating a number of entity beans. Examples, and allowing computing control in the underlying data store to manage access. The third part of the content preview "What is ENTERPRISE JAVABEANS Component?" Will discuss the special deployment process of installing the EJB component. It will also show that CORBA is the competitor of EJB components (the answer is "NO" - see how the EJB technology supplements CORBA). Finally, you will see a use of EJB-based three-layer programming models. Reference Enterprise JavaBeans Specification 1.0.

To learn more about the EJB architecture, see Anne Thomas Enterprise JavaBeans Technology: Server Component Model for the Java Platform, Patricia Seybold Group. To learn more about Java technology and EJB architecture, please visit Sun's website. About the author Ken Nordby is a software engineer in IBM Software Development Lab, which is located in Research Triangle Park, North Carolina. As a member of the SWG Product Affinity Services, Ken has worked with such IBM people, and they are engaged in development and consulting for IBM's WebSphere Application Server (i.e., Enterprise JavaBeans Technology IBM). You can contact Ken through nordby@us.ibm.com. Author: Ken Nordby original source: ibm

What is ENTERPRISE JAVABEANS component? (3) Recommended: Simon Category: Java Published: 2002-04-11 Popularity: 1239

Part III: Deploying and using Enterprise JavaBeans Components Part 3 describes the deployment procedures of Enterprise JavaBeans components, deployment is not just installation because it usually involves code generation. Deployment also uses a special deployment descriptor file that supports the parameters that control the enterprise-level bean behavior (such as a bean requires transactions). This feature deployed by Bean supports the descriptive, program - specific EJB target of Bean. Part 3 also compares two main types of persistence, Bean management persistence and container management persistence, and discusses the relationship between EJB components and CORBA. A simple three-layer EJB application is also given. Deployment Procedures Enterprise JavaBeans (EJB) components are installed in a specific process called deployment. Support for deployment procedures by the container assembly. At the high level, the deployment consists of the following steps: BEAN developers create the required class file, interface file, and control information. Container analysis Enter files and generates the necessary classes. The container adds an entry to the JNDI namespace pointing to the local object. The developer of the EJB component writes the BEAN's Java source file, which contains the business logic method for this bean, and includes the ejbcreate () method. The Bean class must also implement a javax.ejb.sessionBean interface or a javax.ejb.entityBean interface. In addition, Bean's developers write interface files to define an extension to javax.ejb.ejbhome interfaces and javax.eb.ejbobject interfaces. The EJBHOME interface is extended, called the BEAN's local interface, including a creation method, and if the bean is an entity bean, it also contains a Finder method. The extension of the EJBObject interface is called the Remote Interface of the bean, specifies the business logic method defined in the bean itself. BEAN's developers provide control information consisting of deployment descriptors, environmental properties, and list files. The deployment descriptor is a serialization instance of a javax.ejb.deployment.sessionDescriptor object or a javax.ejb.deployment.EntityDescriptor object. Environmental Properties As the key-value pair stored in a file, this file can be accessed via the Java.util.Properties object. The single file is required to identify enterprise beans and its related files. Enterprise beans class files, class files, deployment descriptor files, environmental properties files, and monitored files are archived using file formats named EJB-JAR. The generated EJB-JAR file is provided to the container as an input to the deployment process. At deployment, the container analyzes the contents of the EJB-JAR file and takes the necessary operations to make this bean available. These operations include generating a new Java class that implements the local and remote interfaces of Beans, and the local interface is bound to the JNDI namespace, generating pile modules and Skeleton Helper classes, which are required to support RMI communications. The container can also generate a subclass of the bean, incorporating the code-specific code to facilitate the management of Beans. The class generated by the container is usually dedicated to the container, and is portable as the EJB component itself. Persistence, transaction, and safety provide persistence, transaction and security services for EJB components, EJB containers can play a major role. Is the responsibility of these services to the container or assume that the responsibility is responsible by bean itself, and the EJB specification provides flexibility in developers of Beans. For example, persistence support for entity beans can be managed by bean or by container management.

If the EJB component developer chooses to use the container management persistence, they will add a property called ContainerManageDfields in the deployment descriptor. Depending on the EJB specification: "The value of the ContainerManageDfields property is a list of instance fields, the enterprise-level bean provider wants, the container manages these instance fields by loading or stores it from the database, the enterprise-class bean code should not contain any database access Calling - Database Access Call will be generated by the container tool in deployment. "Dedicated to the container that provides container management persistence support, usually provides a rich deployment time tool to allow enterprise-class Bean deployers to establish instance fields to basic data sources. Mapping. It is generally believed that although the container provider's tool simplifies the mapping process, the mapping process may still involve the Bean deployer (ie the mapping process is not fully automatic). "Enterprise JavaBeans Specification 1.0) In addition to supporting container management persistence, the EJB architecture also supports the management of containers to transactions. This specification specifies:" Enterprise JavaBeans is a Advanced Component Framework, which trying to make application developers The complexity of the system. Therefore, most enterprise beans and their clients do not need to access transaction management through program. "Enterprise Javabeans Specification 1.0) When the BEAN's developer relies on the container, it is called the container management trimming, the container is used in the transaction attribute provided by the deployment:" Whenever the client calls enterprise beans, containers Will involve this method call. This intervention allows the container to explicitly control the transaction bound by transaction attribute. For example, if the enterprise-class bean deploys the TX_Required transaction property, the container will automatically start the transaction whenever the client calls the enterprise bean that supports transactions, and the client does not associate with any transaction context. "Enterprise JavaBeans Specification 1.0) If the developer chooses to support transactions within Beans, they specify the TX_Bean_managed transaction property in the deployment descriptor, and then you can freely use the Javax.Transaction.Usertransaction interface to divide the transaction boundary in Bean itself. Out of the TX_Bean_managed transaction property, the container knows that there is no need to intervene transaction support. By enhancing the restrictions specified in the AccessControlEntry object and the RunaS security ID, the container provides secure support for EJB components. AccessControLEntry objects on the bean level or for a single method, the Identity object Enterprise-class beans associates. Edentity object reflects users or roles that allow calls to beans. When the container is trying to access the data source or another bean, they will also apply Runas security identities to the EJB component. You can set the Runas identity as equivalent A particular user account, a system account or client security identity. Access control and RunaS information is specified in the deployment descriptor in the deployment descriptor, which will affect the container management bean's behavioral way. Although the EJB 1.0 specification also refers to security issues, more detailed security functions, see the subsequent version of this specification. The relationship between Corba and EJB technology Request a proxy architecture (CORBA) is a platform neutral and language of distributed objects. The neutral computing environment lays the foundation. In the CORBA environment, the function resides in the object, and the client can access these objects through the object request agent (ORB). The complete CORBA implementation provides ORB, which is called CORBA object service. Several runtime services for CORBA utilities.

You can also provide only ORB, which does not provide associated object services and utilities (for example, IBM provides such two independent ORBs). Software that implements basic ORB functions is called ORB core. In order to support language-independent, the CORBA application is written in the Interface Definition Language (IDL). This language is similar to C in syntax, but does not include semantic: The operation specified in IDL is an operation interface instead of operation. The CORBA is ideal for managing the information system for managing the size of the company's size. The design EJB specification is also to support enterprise information systems. Say this, is CORBA a competitor? According to the frequently asked Questions for Enterprise JavaBeans, the answer is negative: "In fact, EJB technology has a great supplemental Corba.Corba provides a powerful standard infrastructure that builds EJB servers on this structure .EJB technology. Enables the top floor of the CORBA infrastructure to build applications easier. "(Enterprise JavaBeans Frequently Asked Questions) Although the EJB specification and CORBA specification descriptions are different technologies, EJB implements certain aspects of current using CORBA technology. An example is RMI / IIOP. EJB specification requires EJB components and its containers to use Remote Method Invocation (RMI) technology to implement method calls between distributed objects. RMI specifies the syntax and semantics of the remote method, but does not specify which transport protocols should be used to provide network connections. The CORBA Internet Object Request Agent Protocol (IIOP) basically defines a method of transferring CORBA messages through TCP / IP. Developing an EJB implementation using the IIOP message form to exchange RMI data, how the EJB application can effectively use the part of CORBA technology. This network also supports interoperability with the CORBA application, which uses IIOP to send local CORBA messages, independent of RMI. IBM's EJB implementation, WebSphere Application Server, optimizes IIOP usage, how to make a clear distributed object reside on the same server and only call IIOP when the object is actually remote. In order to facilitate the development of enterprise systems that are incorporated into EJB technology, Sun Microsystems created a mapping between EJB specification and CORBA. The EJB architecture is mapped to CORBA, which affects several aspects of EJB technology, including object distribution, naming, and transactions. The main purpose of the CORBA mapping is to ensure interoperability between the EJB servers constructed by different manufacturers. Interoperability offers the following benefits: CORBA client can access the EJB component client program on CORBA-based EJB server can call to CORBA objects in transactions, and mix with the enterprise-class bean's call. Multiple beans, while these beans are also located on CORBA-based multi-EJB servers from different vendors using ORB clients from a vendor, and can access another manufacturer's CORBA-based EJB server to beans to access EJB components. The CORBA client, the bean interface is mapped to IDL. For example, the Buy () and Sell () methods defined in the stock trading bean can be specified as CORBA operations in the IDL file.

Non-Bean's CORBA client, such as a C client, you can access this bean, and use standard CORBA call to call the bean method. If the container uses IIOP as its distributed object protocol, the duties of the container are to generate IDLs corresponding to enterprise-class beans and their interfaces. EJB Naming Services, which is based on the CORBA Object Services Naming service, so that the EJB component can be used for CORBA clients. Java Naming and Directory Interface (JNDI) provides an interface to the CORBA naming service, and the client can access the service through the JNDI call indirect access to the underlying naming service, or you can access the service directly through the CORBA Object Services (COS) name API. EJB transaction supports Corba Transaction Service (Object Transaction Service (OTS). Java Transaction Service (JTS) represents the Java binding of the OTS, which is language neutral. CORBA-based EJB containers must identify transactions issued by the CORBA client through the OTS interface, and the EJB application emitted through the Java Transaction API interface, JTA is an application-level interface to JTS. The JTA also represents the Java binding of the Open Group XA interface to connect the application resource to an external transaction manager. The JAVAX.TRANSACTION.USERTRRANSACTION interface in JIA provides an API for the application level control of the transaction boundary. Usertransaction interface, which can be used as a bean with TX_Bean_Managed from its transaction property to be used by Java clients. Using EJB components Because the EJB architecture is designed to be highly flexible and supports the use of any complicated way to connect the enterprise bean, many different scenarios can be constructed, and how the application can use Enterprise Beans. A useful solution proposes to represent the EJB component as a key component of the three-layer information system, which connects the enterprise data, transaction, and application resources to the web. The EJB-based three-layer programming model will depend on the web browser as the first layer, and the web server supporting the application is the second floor, depending on the enterprise information resources as the third layer. In this programming model, in addition to EJB technology, Java Servlet technology, JavaBeans technology, and Java Server Page (JSP) technology are also implemented. The figure below shows the arrangement of each layer:

The first layer is a thin client-is usually a web browser that can handle normal web data types such as HTML and GIF, and support HTTP communication. The second layer is a web application server, which is a web server with code to deliver running for applications that can be called through the web server. Existing web applications are used along the CGI-BIN programming model, but it is expected that the second-layer application development will turn to the Java Servlet programming model, which provides significant improved performance and portability. In addition to supporting Java Servlet, the web application server will also add an EJB server function to support applications using EJB components. The third layer represents enterprise information resources, which can include relational databases and object-oriented databases, transaction monitors, and customized applications. EJB technology plays a key role in this design because it resides in the second layer of application components, and the interface between the third floor, it is standardized. Java Servlet, Java Beans, and Java Server Page are not essential elements for the EJB application solution, but they can work with the EJB component to provide Java-based cohesive application environments. The environment depicted here will assign the following responsibilities to the Java component participating in the work: Specify the Java Servlet's role JSP page processing data representation and user interface Java Bean acts as a "data package", storage intermediate The result of the data EJB component provides a mechanism for accessing the enterprise information resource. You can use a hypothesis, EJB-based web application update existing inventory, and use container management persistence and container management transactions, will access the inventory database location package Inside the entity EJB assembly. Inventory tickets can be entered via web browser, the browser provides an HTML form to capture product numbers, suppliers, etc., and call a servlet when submitted. The servlet code acts as an application controller role to determine which corporate databases need to be updated, requiring users to apise the information. The servlet can access the main inventory database by representing its entity bean, and call the JNDI interface to get a reference to the local object of this bean, and then use the finder method to locate the remote objects of the requested product number. At this time, by calling the remote object, the servlet can update the inventory count, and then the container will delegate this method to the EJB component. Because the container is updated according to the database, it is maintained in the transparent manner to the BEAN transparent, and the data is written to the database to ensure data persistence, so the data is maintained. Any result information returns from the EJB component to the servlet, you can use the setter method to store in an attribute of a (non-enterprise) Java Bean. The servlet can transfer control to an appropriate JSP page to combine these results into the representation and return the result to the user. The JSP page is likely to be composed of static text and variable information placeholders related to a single transaction. The JSP page uses the Getter method to get variable data elements from the Java Bean before sending a data to the browser. EJB-based three-layer design provides several benefits, including: Accessing the business logic of enterprise data can be packaged in reusable, portable enterprise beans. Existing enterprise systems can be integrated into enterprise-class beans only need to be modified or do not need to be modified. The runtime services required by the enterprise application, such as transactions, and persistence, can be broken down from the bean and specify containers to this bean.

You can modify the servlet of the Control Application Process without changing the EJB component. The Servlet code can focus on application control logic without considering data representation. The JSP page can be mixed together and generate information. System components written in Java language are portable for any platform with JVM. Conclusion In the process of developing an enterprise information system that supports key tasks, the EJB specification represents the next stage of development of Java technology. The EJB component extends to the server field with the JavaBeans specification, so that the development of business logic components can be reused across enterprise applications, and can transplant cross-supporting Java. Since it contains an Object distribution based on RMI technology, the discretion of multi-layer executable components is supported, allowing maximum implementation and high scalability. If the regular enterprise application runtime service is redefined as an object service that can be specified to the container, the developer that allows EJB components to concentrate on business logic, reducing the complexity related to the runtime service. And platform relevance. Enhance the Java operating environment to include standard interfaces, relational database access, transaction services, and remote object access, so that Java developers can write robust enterprise applications without having to leave the Java programming environment. Use other Java technology-such as Java Servlet and JavaServer Pages technology - with EJB components, you can create a compact programming model for large enterprise systems, but because of using clever interfaces, it simplifies development work. . Moreover, because the EJB architecture is a logical extension of the JavaBeans component model, the business logic developed as an EJB component can be reused across multiple enterprise applications. Another benefit of an enterprise-level Bean architecture is to provide a direct integration channel of existing enterprise information systems, which may be unansee with the Java programming language or bean programming model. Because of existing enterprise information resources - custom new varieties for relational databases, transaction monitors, and business applications - can be connected to the web front end by encapsulating them in the EJB component, without replacing the application or rewriting the main code Segment, so customers protect their existing IT investments. Considering the huge prospects of EJB technology, the IT industry welcomes EJB specification with considerable interest, is not surprising. One of the biggest benefits provided by the EJB architecture may be to leave business logic programming with complex set components of business logic and enterprise-class server-side running environments. If the container deploys the EJB component has undertaken the role of the management runtime service (such as persistence, transaction, and concurrent database access), the BEAN's developer can freely focus on the software components of the development package business logic. Javasoft Vice President expressed the importance of EJB technology (from Sun Microstems website): "The 'Enterprise JavaBeans API will provide a new strategic weapon for enterprise developers and solution providers for them to build next-generation industry, Based on key business applications, the Vice President of the Javasoft Software Products for 'Sun Microstems, Jon Kannegaard, said:' Because applications designed with Enterprise JavaBeans API will work with existing enterprise systems, companies use Java platforms to get new The competitive advantage, but also retains their investment in prior art, 'Kannegaard continues. "Use Enterprise JavaBeans API, developers will be able to eliminate complexity during application development.

This is possible because each Enterprise JavaBeans component encapsulates a basic business feature. At present, developers must know how to write business logic and specialized system-level procedures to control the ability such as security features and handle multiple transactions - a boring and complex task. Enterprise JavaBeans API enables all developers to focus on writing a logical solution to business issues, rather than concentrating on writing code to simplify different technologies. "(Press Release: Sun Releases Draft Enterprise JavaBeans Specification for Public Review) reference site by associated FAQs Sun-depth understanding of Java technology and EJB architecture access to Enterprise JavaBeans Specification 1.0, please see the Enterprise JavaBeans specification See the full press release... The IBM WebSphere Application Server uses EJB technology. The Summary Ken Nordby is a software engineer in IBM Software Development Laborators, which is located in North Carolina Research Triangle Park. Members of the Swg Product Affinity Services business team, Ken with IBM WebSphere Application Server (Enterprise JavaBeans Technology IBM Implementation) works together with IBM people working together. You can contact Ken in nordby@us.ibm.com with Ken .EJB Getting Started Textbook

Gentle flight 2001-10-17 00: 00:005743 View 1, EJB development

First, general, tell the development steps of EJB. 1.1 SessionBean's development first, write remote interface, inherit the EJBObject interface, write the PUBLIC method you need to call (these methods will be implemented in SessionBean), pay attention to Declaring Throws Java.rmi.RemoteException. For example:.. Package jsper.ejb; import java.rmi *; import javax.ejb *; public interface MyEJB extends EJBObject {public String sayHello () throws java.rmi.RemoteException;} a second step, the write Home Interface (generated EJBObject Quoted Factory generates at least one CREATE method, pay attention to declare throws java.rmi.RemoteException and javax.ejb.createException.

For example: package jsper.ejb; import java.rmi *; import javax.ejb *; public interface MyEJBHome extends EJBHome {MyEJB create () throws java.rmi.RemoteException, javax.ejb.CreateException;} The third step, photo. The implementation of the positive session bean (implementation is defined in a remote interface), you need to implement a javax.ejb.sessionBean interface Note: You cannot directly implement remote interfaces directly, you don't have to throw RemoteExceptionPackage Jsper.ejb; Import Java .rmi.RemoteException; import javax.ejb *;. public class MyEJBClass implements SessionBean {public MyEJBClass () {} // public method defined in SessionBean the void ejbCreate () throws RemoteException, CreateException {} public void ejbActivate () throws RemoteException {} public void ejbPassivate () throws RemoteException {} public void ejbRemove () throws RemoteException {} public void setSessionContext (SessionContext ctx) throws RemoteException {} // here is a specific implementation public String sayHello () {System.out.println ("Hello");}} The fourth step, write a published configuration file EJB-JAR.XML needs to be provided: bean home name - The Nickname That Clients Use to lookup your bean's home object.Enterprise bean class name - the flully qualifi ed name of the enterprise bean class Home interface class name Remote interface class nameRe-entrant -. Whether the enterprise bean allow re-entrant calls This setting must be false for session beans (it applies to entity beans only) stateful or stateless Session. Timeout - The Length of Time (in Seconds) Before aclient SHOULD TIME OUT WHEN CALLING METHODS ON YOUR bean. You can also provide your own configuration information for your own way to control EJB.

Example: helloejbcom.jsper.ejb.myejbhomecom.jsper.ejb.myejbcom.jsper.ejb.myejbclassStateLessContainer fifth step, generate YAR files with JAR tools with JAR tools with jar files EJB-JAR.XML must be on top Meta-Inf subdirectory This sentence is compared to bite mouth, take an example MYLIB ---- Meta-inf - *. Xml | | COM - COUCOUNIU - EJB --- EJBCLASS | - EJBHOME | -EJB is generating .jar files When SH> CD MYLIB / / Note SH> JAR CV0F myejb.jar * Please note: To this step we make things are and unrelated to specific EJB Server, just follow the sixth step in accordance with EJB , Use the published tool for a specific platform to generate a JAR file that is published. Different middleware products This step is very different, and the result is generated to generate remote interfaces and HOME interface implementations that have only its own EJB Server can understand, and packaged in a JAR file is generally very simple, .jar file released to EJB Server This step is very different according to different middleware products, can be divided into two types, which is released when starting, and is generally very simple, with WebLogic as an example: 1, in the weblogic.properties file The configuration is automatically loaded when WebLogic is started. Add an entry such as: WebLogic.ejb.Deploy = C: /WebLogic510/Myserver/ejb_basic_beanmanaged.jar ,/ c: /weblogic510/myserver/ejb_basic_test.jar 2, use deploy or deployertool dynamic loading / uninstall / update the eighth step, write The client's program (I have so far) In the process of publishing EJBs to the EJB Container, we use the publishing tool to bind a directory service of the Container, now we want to call the EJBHOME object from this directory service. Take it, here is divided into both local and external situations: one is the client local call EJB.

For example, the EJB engine and the servlet engine are integrated in the same application server, then there is no need to verify when a servlet is called to call EJB, you can get the implementation of the EJBHOME interface CONTEXT IC = New InitialContext (); system.out.println (" Looking for the EJB Published as 'Hello' "); com.jsper.ejb.myejbhome HomeInterface = (com.jsper.ejb.myejbhome) Ic.lookup (" Hello "); // The name binding when publishing is Hello The implementation of the HOME interface can be obtained from the directory service. It is also our most common way. If the portability is very good external call, you must first pass authentication, such as Oracle8i: String Ejburl = "sess_iiop: // localhost: 2481: ORCL / test / MyEJB "; String username =" scott "; String password =" tiger "; // Setup the environment Hashtable environment = new Hashtable (); // Tell JNDI to speak sess_iiop environment.put (javax.naming.Context.URL_PKG_PREFIXES , "oracle.aurora.jndi"); // Tell sess_iiop who the user is environment.put (Context.SECURITY_PRINCIPAL, username); // Tell sess_iiop what the password is environment.put (Context.SECURITY_CREDENTIALS, password); // Tell sess_iiop to use credential automationenvironment.put (context.security_authentication, servicectx.non_ssl_login); // Lookup the URL com.js per.ejb.MyEJBHome homeInterface = null; try {System.out.println ( "Creating an initial context"); Context ic = new InitialContext (environment); System.out.println ( "Looking for the EJB published as' test / MyEJB '""); HomeInterface = (com.jsper.ejb.myejbhome) Ic.lookup (ejburl);} catch (activationException e) {system.out.println ("Unable to Activate: E.getMessage ()); E.PrintStackTrace (); system.exit (1);} Remaining the way to call: try {// get an inTIALCONTEXT STRING URL = "T3: // localhost: 7001"; Properties H = New Properties ();

h.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); h.put (Context.PROVIDER_URL, url); Context ctx = new InitialContext (h); System.out.println ( "Getting the EJBHome object ..." ); Com.jsper.ejb.ebhome tmp = (com.jsper.ejb.ejbHome) CTX.lookup ("Hello"); // Create Three Element Array Of Count Object EJB EJB = Tmp.Create (); System.out .println (Ejb.sayhello ());} catch (exception e) {E.PrintStackTrace ();} For the specific directory service, the agreement is related, in order to achieve the purpose of portability, I have to do some work, fortunately, no Need to do this. How to set the virtual directory in Tomcat

OF: jdeveloper Add% Tomcat_Home% / conf / server.xml in the following code where the value of PATH is the virtual directory DOCBASE is started with / or the disk It is the absolute path of your hard disk directory. If it is not the relative path relative to% Tomcat_Home%, you can use the following ways to access: http: // localhost: 8080 / jdeveloperhjc http: // localhost: 8080 / JDevelopertest

getting Started

An important feature in JSP technology is that it can access reusable components directly from the JSP page, such as JavaBean.

The JavaBean component is a technology that is not related to the platform-independent components written in Java language, which is the technology supported by major manufacturers in the industry. The Javabean component inherits the platform independence that can be seen in the Java program. Developers can write reusable components and then run on each platform.

The reason for using JavaBean components in the JSP page is to separate the code from the display. We have discussed this concept in an instruction. You can reduce the code in the JSP page by using JavaBean components.

There is a mark responsible for accessing content and display in the JSP page. The logic and program code of the generated content are included in the reusable components, namely JavaBean components.

JavaBean component features

Javabean components are reusable software components, using standard "Method" naming rules. This makes the JavaBean components with predictable behavior and can be used in tools.

The public characteristics of the JavaBean component have properties, methods, and events.

The attribute is part of the JavaBean. They can be other Java objects or original types. We can see the next screen, the properties of the JavaBean component are defined by a pair of public Getter and Setter methods.

A method is a JavaBean available action or service.

The event is a prompt that JavaBean has an event. Behind, we will specifically discuss the function of beans.

Bean in the JSP environment

One way to use JavaBean components is to use it as a data package. An attribute of JavaBean is just the data of the bean (status). Attributes can be accessed by two ways: getter and setter. The value of the property can be accessed by getter method. If the property can be modified, its value can be modified via the setter method.

Take a look at the sample code provided below. This defines a bean property called Time, and its access type is Date (java.util.date).

Public Date getTime ()

Public void setTime (Date NewTime)

The properties and methods in javabean are the APIs that exchange data and service. Access to beans only need to send messages to the bean instance. Most enterprise development tools, such as VisualAge® For Java, can automatically generate Java classes based on the JavaBean specification.

Use JavaBean components in the JSP page

Let's see the advantages of using the JAVabean component in the JSP page.

The Javabean component represents an application's business logic when used in an application server with the Servlet and JSP pages. They offer:

Attributes, used to configure their behavior methods, used to provide business logic properties, package generated dynamic content

When the user issues a request via the browser, it may be requested static or dynamic information. If it is dynamic, a servlet will proceed as follows:

1. Servlet finds one or more JavaBean components that processes the request.

2. It passes the requested parameters to the bean and then calls the business logic method.

3. Then the servlet saves the reference bean and supplies it to the JSP page.

4. The JSP page returns to the browser using the dynamic content stored in the Result bean.

How does the JavaBean component work?

We have mentioned servlets and backend applications, such as databases, providing dynamic content through a Result bean.

The JSP page is to access the Result bean object through a tag. This tag indicates how to find or create a bean.

If you want to access existing beans, it will access from a session or request. If you need to create a bean, it is instantiated from a serialized bean, or a new bean is created.

转载请注明原文地址:https://www.9cbs.com/read-47211.html

New Post(0)