Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 14: Java Code Generation and Reverse Engineering

}

public void addVetoableChangeListener(VetoableChangeListener listener)

{

commonVCS.addVetoableChangeListener(listener);

}

public void removeVetoableChangeListener(VetoableChangeListener listener)

{

commonVCS.removeVetoableChangeListener(listener);

}

}

/*

SampleClass.removePropertyChangeListener(PropertyChangeListener){

commonPCS.removePropertyChangeListener(listener);

}

*/

/*

SampleClass.addPropertyChangeListener(PropertyChangeListener){

commonPCS.addPropertyChangeListener(listener);

}

*/

Support for J2EE

The J2EE standard is a method for developing complex distributed applications without needing to focus on the details of transaction processing, database connectivity, or security. Instead, J2EE allows the developers to focus on the unique business logic of the application. J2EE elements—including EJBs, servlets, JAR files, and WAR files—are now supported in Rational Rose. In this section, we'll explore how to create each of these

four types of elements in Rose.

EJBs

An Enterprise Java Bean, or EJB, is modeled in Rose as a class with an EJB stereotype. Depending upon the bean type (Entity or Session), the class will have a stereotype of EJBEntity or EJBSession. An entity EJB will have relationships to three other elements: the home interface, the remote interface, and the primary key. Each of these three is modeled in Rose as a class with stereotypes EJBHome−Interface, EJBRemoteInterface, and EJBPrimaryKey, respectively. Figure 14.13 shows an example of an entity EJB.

Figure 14.13: Entity EJB

484

Chapter 14: Java Code Generation and Reverse Engineering

With a session EJB, the class will have relationships to two other classes: the home interface and the remote interface. These classes have stereotypes of EJBHomeInterface and EJBRemoteInterface, respectively.

To create an EJB, select Tools → Java → J2EE → New EJB. Using the window shown in Figure 14.14, enter the type of EJB (Entity or Session), the name of the home interface, the name of the remote interface, and the name of the EJB.

Figure 14.14: Setting EJB properties

If this is an entity bean, use the Bean−Managed or Container−Managed radio buttons to control whether the bean's persistence is managed by the container or within the bean itself.

If the bean is a session bean, use the Stateless or Stateful radio buttons to control whether the client maintains the bean's state between method calls.

If this is an entity EJB, select the Persistence Properties option in the treeview on the left side of the window in Figure 14.14. The Persistence Properties window is shown in Figure 14.15. Using this window, you can set items such as the name of the primary key class and the ejbFinder's method, name, parameter, and parameter type.

Figure 14.15: Setting Persistence properties

You can enter the name of the primary key in the Primary Key Class Name field, or check the Match Pattern check box. If Match Pattern is checked, the name of the primary key will be the bean name followed by the letters "PK."

485

Chapter 14: Java Code Generation and Reverse Engineering

In the Class Methods field, checking the hashcode(), equals(), or toString() check box(es) will cause Rose to generate the selected method(s) in the code.

In the ejbFind<Method> field, you enter the name of an ejbFinder method to create. In the Parameter Name field, enter the parameter(s) for the method. If there are multiple parameters, separate them with commas. In the Parameter Type field, enter the data type for each parameter. Enter the types, separated by commas, in the order in which the parameters are listed.

Select the Deployment Descriptor option in the treeview on the left side of the window to view the Deployment Descriptor window, as shown in Figure 14.16. Once these properties are set, Rose can generate the appropriate XML documents for the descriptor.

Figure 14.16: Setting Deployment Descriptor properties

You have the option to enter a value in the Enterprise Bean's Name field. If you enter a name, this is the name that will be used in the .jar file. If not, Rose will use the implementation bean's name.

Next, check the Is Re−entrant box if more than one client will be able to access the bean's methods.

In the Deployment Descriptor Structural Information area, select one of the following from the drop−down list box:

Cmp−field for a container−managed persistence entry

Env−entry for a environment variable entry

Resource−ref for a resource manager reference entry

Ejb−ref for a reference to the home or remote interface of another EJB

Security−role−ref for a security role reference entry

Then, enter the name, value, and type for the entry. For an ejb−ref entry, specify the home and remote

486

Chapter 14: Java Code Generation and Reverse Engineering

interfaces. Click the Add button to add the entry to the list, and create other entries as needed.

Servlets

Like an EJB, a servlet is modeled in Rose as a class with a special stereotype. In this case, the stereotype is HttpServlet. Using the servlet properties dialog boxes we will discuss in this section, you can control what methods and other properties are created for the servlet.

To create a new servlet, select Tools → Java → J2EE → New Servlet. You will see the J2EE Servlet Specification window, as shown in Figure 14.17.

Figure 14.17: Servlet Specification window

First, enter the name of the servlet. Then, check IsSingleThread if one thread of the servlet instance will execute at a time. Check HttpServlet or GenericServlet if the servlet extends either of these. In the Dispatcher Path field, enter the path to another servlet that will be used to receive requests or send requests to the current servlet. In the Operations area, check the method(s) that you would like Rose to generate for the servlet.

Select the Advanced Properties option on the left side of the window to display the Advanced Properties window, as shown in Figure 14.18.

Figure 14.18: Servlet Advanced Properties window

Select the Context Object check box to create a servlet context object. In the The Request section of the screen, select the method(s) the servlet will use to retrieve requests. In the Servlet Content Type field, enter the type that the servlet will use to respond to a client.

487