Home > Articles > Programming > Java

This chapter is from the book

Building the Architectural Prototype: Part 1

Part 1 of building the architectural prototype for our EJB solution covers the setup of the environment and the use of a visual modeling tool to facilitate the early aspects of code generation.

Baselining the Environment

Our environment in this evolution of the prototype will be BEA's WebLogic application server. Note that the BMP and CMP implementations will work on any commercial or open-source EJB container that complies with the EJB 2.0 specification. Toward that end, I will show little of anything that is unique to WebLogic. In the appendices I will review the console monitor that BEA provides, as well as a unique deployment descriptor.

As in the previous chapter, you should be able to install the EJB solution right from the download. It is packaged in a standard Enterprise Archive (EAR) file, thus complying with the EJB 2.0 specification. EAR files contain both Web Archive (WAR) files and Enterprise JavaBean Java Archive (JAR) files. The name of the file for Remulak is ejb20_remulak.ear.

Visual Modeling: Its Mission for the Project

Let me stand on my soapbox once again: Too many Java projects fail because the developers' desire to produce code far outweighs the importance of sound project planning and a precise understanding of the application's requirements.

To reemphasize what was stated earlier, if you have come this far in the book and have not seen the benefit of using a visual modeling tool, this chapter either will finally convince you or merely cement your already positive conclusion. Besides the obvious benefits of having a repository of artifacts and a consistent approach to creating them, the visual modeling tool really excels in getting the programming effort started. It also gets high marks for the ongoing evolution of the application by bringing code artifacts back into the model.

In this book we have used Rational Rose as the visual modeling tool. Note, however, that many excellent visual modeling tools on the market support Java code generation, in particular for the EJB environment. Another tool I like a lot—Together Control Center—is produced by TogetherSoft. But be forewarned: These products are quite expensive.

NOTE

This chapter will benefit you greatly even if you don't choose to use a visual modeling tool because I review all of the code in any case.

Like its many competitors in the marketplace, this generation of Computer-Aided Software Engineering (CASE) tools is a skeleton-generation product. Modeling tools are focused on analysis, design, or a combination of the two. Unfortunately, I have been the victim, in a previous life, of being "welded" to my modeling tool, always forced to take the code output it produced and forced again to get it to run in a production environment. These integrated CASE tools demanded that the user learn a new language that would eventually translate into code (e.g., COBOL, C, or C++)—usually not a pretty picture.

The current generation of skeleton-generation tools provides both the analysis and the design transition support, but only the code structure and framework are generated from the model. I really like this approach. It allows the project to apply the rigor of keeping true to the structure of the application design, while not dictating the solution for the how. For instance, it will put in place the class structures, operation signatures, and available message paths to calculate an order discount but not force me to tell it how to calculate the discount. My once negative opinion of integrated modeling tools has been swayed into the positive. In summary, you need a visual modeling tool that generates code in your language of choice.

Visual Modeling: Its Mission for Program Code Generation

Rational Rose generates code strictly from the information found in the class diagram, along with some physical attributes that we give the UML component that has been assigned to realize, or implement, the class.

There is a completed Rose model that you can use if you have a copy of Rational Rose. You can enter each class by hand, along with all of its support material (attributes, operations), or you can use my model as a start to generate your code. I highly recommend the latter.

Reviewing the Setup Issues

We need to revisit the class diagram for Remulak Productions and see how some of the components have been arranged. This review will facilitate how we work with the diagram, and it will help us better manage all aspects of the code generation. FIGURE 12-2 shows Remulak Productions' model, remulakjava.mdl.

On the right-hand side of FIGURE 12-2 is the overall package diagram broken down by the increments, with a note attached describing the use-cases that are being realized. In the browser tree view on the left-hand side, there are now packages under each increment that weren't there before. These packages reflect the physical layering decided on in Chapters 10 and 11.

FIGURE 12-2 Rose model organization

I reemphasize here that in practice you shouldn't worry about being totally accurate with your signature layouts. The model delivered with the book is complete. Just remember that in reality this knowledge will grow with the code. Actually, I find the best source for the signatures are the programmers themselves. Because we will reengineer our code

back into the model, everything will eventually be in sync. For instance, when adding input parameters for operations, you can specify their data types. However, don't bother to add them to the class diagram because when we reverse-engineer the code, Rose will fill in that information for us. We want to get to the code as soon as we can.

Modifying the Code Generation Parameters

With Rose we will generate the code to implement our solution using container-managed persistence (CMP). Before we tell our tool to generate code, we need to tweak some of the Java code generation options that Rose provides. FIGURE 12-3 shows the Options dialog box for Remulak Productions' model.

FIGURE 12-3 Changing the code generation properties

To get to this screen, do the following:

  1. Select Tools from the menu.

  2. Select Options from the drop-down list box.

  3. Select the Java tab.

Note that the drop-down menu in FIGURE 12-3 for Type indicates several things (class, role, and so on). These are all the default options defined at these various levels. We first want to change an option for the type of attribute. To do this we change the PropertyType attribute from Not A Property to Simple. This action will result in get and set operations being defined for each of the class attributes. We'll do the same thing for the type of role, changing its PropertyType attribute as well.

While on the role type, we want to add an item value for Container Class. This attribute defines what type of container to use when dealing with one-to-many or many-to-many relationships between classes. Let's use java.util.ArrayList instead of Vector. Although Vector would work just fine, all the operations that it supports are synchronized and the synchronized keyword is not allowed in Enterprise JavaBeans. So for the type of role, your screen should look something like what you see in FIGURE 12-4.

FIGURE 12-4 Changing type properties for role

A Final Pass at Attributes and Operations

Before actually generating code for Remulak, we need to make a pass through our target classes and tie up any loose ends in the areas of attributes and operations. As mentioned in the previous section, the signature issues are not as great a concern as having good coverage of our attributes is. FIGURE 12-5 shows the Rose attribute dialog box. Here I'm setting the properties for the customerNumber attribute found in the Customer class. For the Type attribute I have selected java.lang.String from the drop-down list. Notice also that the Bean Property type has defaulted to Simple in accordance with the changes made in FIGURE 12-3.

FIGURE 12-5 Attribute definitions

Converting Classes to Enterprise JavaBeans

It's now time to move beyond our logical view of the class diagram and begin to transform it into more of a design view. Because we are implementing our beans in an EJB container, we need to take a class, such as Address, and convert it into an EJB-compliant class.

To do this, first we need to open the class diagram and select a class—say, Address. After selecting the class, we do the following:

  1. Right-click on the class.

  2. Select Java / J2EE from the drop-down list box.

  3. Select EJB: Open Specification.

What will appear next is the dialog box shown in FIGURE 12-6.

FIGURE 12-6 EJB dialog box in Rose

The dialog defaults to making the class an entity bean and container-managed. Notice that there is an option to make it a session bean as well. Our use-case control classes will be session beans, but we'll say more about that later. I also changed the default bean name. Rose takes the class name and adds EJB to the end. I changed the name to AddressBean.

After you have selected OK, the class will be converted to an entity-type EJB. Three classes are created as a result of the Rose dialog. In the case of the Address class, these classes are AddressBean, Address, and AddressHome. An AddressPK class will be created as well, but it will be needed only if the class is identified, from the relational perspective, as having a compound primary key or if it is of a complex type, such as another object. FIGURE 12-7 is a view of the Address class after it has been converted to an EJB.

FIGURE 12-7 Address class after invocation of EJB configuration dialog

EJBs are completely lifecycle driven, meaning that most of the operations that are generated by the conversion wizard are operations that are called, on your behalf, by the EJB container. Our mission in this chapter is to be able to query on a Customer object and display Role and Address objects. As a result, we need to perform this same function on the Customer and Role classes. I won't cover those here, but they follow the same procedure as Address.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020