Pramati Technologies

Packaging EJB Components

Overview

Packaging EJB Components involves packaging the enterprise beans and Java files. Use the Package Tool in Studio to package ejb components explicitly. EJB modules in Studio act as the JAR and contain all ejb components to be assembled.

Adding a bean or making any changes in the Bean Properties dialog box, always reflect the changes in the added bean. However, if you change the properties of the bean inside a JAR, the changes are not affected in the bean.

Opening a JAR

Open the Package Tool using Tools > Package from the main menu. Click on JAR > New, to create a JAR.

Select JAR > Open > Choose /archive name to open an existing JAR.

The JAR consists of two basic windows:

  1. The left window which displays a tree of all Enterprise JavaBeans present in the opened JAR and
  2. The right window that displays the information corresponding to the tree node selected.

The deployment descriptor is initially populated/developed based on the information provided during bean creation and generation of interfaces by the Bean Wizard and the Interface Wizard respectively. The deployment descriptor for the EJB components is stored as META-INF/ejb-jar.xml. For each enterprise bean, the ejb-jar file must include the following class files:

Adding EJB or Helper Classes

Jar > Add Bean

Select Enterprise JavaBeans from a list of all Enterprise JavaBeans available on the active desk to add to the JAR. If the bean being added to the JAR is a CMP 2.0 entity bean and has relationships with other CMP 2.0 entity beans, then related beans to be added to the JAR.

The Package Tool picks up all the custom classes referred in the home and remote methods either as arguments or as return types, and all the custom classes that are fields of a CMP bean. The JAR tool picks up any classes defined in the home or remote interfaces like exceptions, value objects and other referred beans. The classpath of the Source Root of the bean affects this operation. The tool will add only those classes that are found in the classes directory of the Source Root. Any classes that are found in either the system classpath or the user classpath are not added to the archive.

Adding the Bean classes displays a table on the right side panel and displays files (Home Interface, Remote Interface and Bean class) associated with the Bean.

Resolve the Enterprise JavaBeans environment before packaging it. To specify a parameter, simply click on it. The parameters include:

We recommend that you set these parameters using the Bean Properties Dialog, so that when you move the bean around, all its properties are always associated with the bean and get added to the JAR with the bean.

Adding Files

Tools > Package > JAR > Add Files

This command helps add the helper class files used by the beans present in the JAR. "Select Files to Add" dialog prompts for the following details to be filled before the files are added to the JAR:

HTML files - *.html

Classes files - *.classes

All classes in package com - com/* (Use / if Windows, and / if UNIX)

All classes starting with com.wombat.Foo - com/wombat/Foo.*

All classes starting with Foo *Foo.class

Repeat the process as many times as required. Clicking on OK adds all the files in the target directories.

Removing Beans

Package Tool > JAR > Right Click > Remove Bean

This lists all the beans that can be removed and clicking on OK removes the bean from the JAR. Removing a bean may cause the other beans in the JAR to get affected. Classes of the removed bean might be needed by some other beans to load them when the Java archive opens. It is important to verify that the Java archive has been correctly formed after a remove operation. If the JAR is closed and then re-opened it will point out all the affected beans, if any. These affected beans have to be then added back to the JAR.

If the beans in the JAR are CMP 2.0 entity beans and have relationships with other CMP 2.0 entity beans, then removing one bean will cause other related beans to be removed.

Updating the JAR

Jar file on the Desk > Right Click > Update

Updates the home interface, remote interface, bean classes, static files like and the primary key if it exists, XML entries in the JAR. A bean is considered to have changed if any of its classes (Home, Remote, PK, Bean) have been changed (time stamp check) since the last update to the JAR. The Update tool always refreshes the XML details inside the JAR with the corresponding details from the bean properties except all the deployment time information (like O-R Mapping). All settings must be made in the Bean Properties dialog box. Settings made only at the JAR level will be lost on an update. XML Updation happens on all beans and is not time-stamp based.

Files other than beans are saved with their absolute path. A time stamp based update is used to update the JARs, which makes the updating faster in most scenarios.

Note: These files that are stored with their absolute paths, may not be located if they have been moved from their original location.

Updating a Java archive comprises first locating the beans and files on the desk and the file-system and if they need to be updated, the latest files are added to the JAR. A log of update operations is available on the Update Tab in the Output area of Studio. This log shows normal messages in black, updating messages in green and any failures or errors in red. Usually a remedial measure is also provided in the case of errors. A progress bar indicates the progress of the operation.

Choosing Update brings up a dialog box with a progress bar. All the updating messages are displayed here. To stop updating the JAR, click on Cancel. Studio in the meantime can be used as usual but the JAR being updated cannot be opened. If the package names of the above are changed, then the changed beans are not updated.

For a bean to be located correctly on the desk, it should have been added to JAR, else the bean cannot be located. This scenario is most likely to happen when the JAR was not created using Pramati Studio 3.0. Note that JARs created using earlier versions of Pramati Studio also do not have this information and will not get updated in version 3.0. This information might also get out of synch with the desk's state if you move the bean from the original Module where it was located. The solution is to re-add the entry into the JAR. This will re-create the update information.

Saving the JAR

Tools > Package > Jar > Save saves the open JAR.

Closing the JAR

Tools > Package > Jar > Close closes the current JAR. The Jar is saved before closing.

Reverting the JAR

Tools > Package > JAR > Revert restores the JAR to its last saved state.

Using the Bean Panel

Clicking on the bean name in the JAR brings up a panel on the right side of the dialog box. The following properties are displayed in the Bean section of the panel:

The Details section of the panel, the Bean Type displays the type of the bean. The selection is based on the following criteria:

Select `Reentrant' option if the bean requires loop backs in the same transaction context.

Defining References for a bean

The types of references can be specified for a bean are described in the following sections.

EJB References

The bean provider uses EJB References to refer to the homes of other enterprise beans. During deployment the EJB references are bound to the enterprise bean homes in the target operational environment.

To add the bean references, enter the following information and click Add:

For J2EE, Studio does not support EJBContext.getEnvironment() method. All EJB references are declared using the EJB-ref elements of the deployment descriptor. The scope of the EJB reference is limited to the bean declaring the reference.

Resource References

Any resource that the bean uses can be specified here. Each resource reference added to the JAR describes a single resource manager connection factory reference. These resource references are then bound to the actual resources during deployment.

Clicking on Add adds a new row to the resource reference panel. Edit the following information in the row:

Security Role References

The Security Role references cannot be added until the Security Roles are added in the JAR. Declaring the security roles references allows the security role references to be linked to the JAR level security roles, which have already been defined. Use the Add button to add the references and Delete button to delete them. Enter the following information to create the Security Role References:

Resource Environment References

A resource environment reference is a special entry in the enterprise bean's environment. The resource environment references are bound to administered objects in the target operational environment during deployment. Adding Resource Environment entries allow the ejb-jar consumer to discover all the resource environment references used by the enterprise bean.

To add resource environment entries to the JAR, use the Add button. The two mandatory fields to be described are:

Note: The resource environment reference is not accessible to other enterprise beans at runtime, and other enterprise beans may define resource environment reference elements with the same resource environment reference name without causing a name conflict.

Defining Transaction Attributes

A transaction attribute is a value associated with a method of a session or entity bean's home or component interface or with the on Message method of a message-driven bean. Use the Transaction Attributes panel to set transaction attributes of the beans in the JAR. These attributes define responsibilities of the container for managing the invocation of a business method:

Note: For message-driven-beans, only the Required and NotSupported transactions may be used.
For entity beans that use EJB 2.0 container-managed persistence, only the Required, RequiresNew, or Mandatory transaction attributes should be used. Entity beans can optionally use NotSupported, Supports, and Never transaction attributes, but these transactions will not be portable.

The following are the fields in the transaction attributes panel:

Setting Security Roles

A security role is a semantic grouping of permissions that a given type of user of the application must have in order to successfully use the application. The application assembler defines Security Roles for a JAR composed of one or more Enterprise JavaBeans.

Use the Add button to add a security role in the panel and Delete button to delete the selected role. The role name can be edited.

Defining Method Permissions

Method Permission is a permission to invoke a specified group of methods of the enterprise beans' home and component interfaces. Each security role in the JAR is assigned to a method permission in the deployment descriptor.

Clicking on the Method Permissions panel on the left side of the tree displays the list of method permissions with the following columns:

During deployment, this is then assigned to a security principal defined in the operational environment to be used as the principal for the run-as identity. Instead of selecting a security role, you can also select the `use-caller-identity' element. In this case, the principal associated with the calling client is returned for the getCallerPrincipal() method.

Note: If there are no security roles defined in the JAR, then everybody has a free access to all the bean methods inside the JAR. An assignment restricts the access to a method.

Defining Environment Entries

Declare all environment entries accessed from the EJB code. An environment entry is scoped to the bean. This means:

Clicking on Add adds a new environment entry and the following fields need to be edited in the environment entry row:

To delete an environment entry from the JAR, select the row and click on the Delete button.

Defining Container Managed Fields

If the enterprise bean is an Entity bean with container-managed persistence, the Bean Provider must specify the container-managed fields using the cmp-field elements.

The panel displays the following attributes of the container-managed fields:

Container Managed Relationships Data

This panel displays the container-managed relationships of the entity 2.0 beans with container-managed persistence.

The panel displays the relationships in the JAR with the following attributes:

Finder/Select Methods

This panel is used to specify EJB QL finder or select queries for the entity bean and to specify SQL Queries when the bean is a CMP 1.1 entity bean. The following are the fields in the panel:

Viewing XML Files

The ejb-jar.xml file corresponding to the JAR file can be viewed in the XML node.


Pramati Technologies  © Copyright   TOCPREVNEXTINDEX