Use rational xde to accelerate J2EE development

Source: Internet
Author: User
Tags websphere application server
Rationalxde TM provides a truly seamless integrated Visual Modeling Environment for the most popular integrated development environment (IDE. Rational xde not only has automatic generation CodeAnd code/model synchronization functions, it also has more features to assist in software development. To make better use of rational xde, you need to understand the powerful J2EE mode and code template capabilities provided by xde. You can apply the J2EE mode and code template during development, you can also define and create them by yourself. This article will show you how to use the capabilities provided by rational xde to complete the development of a simple J2EE project.

Overview of a simple application

To demonstrate how to use the unique capabilities of rational xde, we will implement some of the features of a simple web application, an application system for loan management, the system allows lenders and loan administrators to perform some simple tasks.

Lender

    • Online Payment

    • View the installment plan in a browser

Loan administrator

    • Create one or more loan projects for the customer

    • Obtain information about subscription and loan repayment

Let's assume that we must use an existing infrastructure platform: an IBM WebSphere Application Server and several databases.

First, we can use the free-form modeling capabilities provided by rational xde to express the direction and thoughts of related solutions without limits, as shown in figure 1. This free-form diagram provides us with the obvious benefit: they allow you to still use the same tool and make it easy to integrate planning documents into projects.

Figure 1: the free form diagram shows the main points of the solution more extensively.

Automated Analysis and Design Behavior

Once the initial plan is completed, we can start the analysis and design work. Although rational xde runs in a software development tool, it provides all the capabilities to complete traditional analysis and design activities-case modeling, time sequence diagrams, and so on. In fact, rational xde also provides the Rational Unified Process? Configuration for Java developers (rcjd), rcjd provides proven guidance for Java software development.

Figure 2 shows the initial use case model of a simple loan management system, which is obtained through discussion with the customer and further refinement.

Figure 2: Use Case model of a simple loan management system

For simplicity, we will only describe one of the cases to demonstrate the role of rational xde in this process. Select "show installment payment. The initial sequence diagram details the basic use case scenarios, as shown in figure 3.

Figure 3: detailed timeline of the basic process for displaying installment Use Cases

Obviously, this is a high-level interactive view, and it does not involve any details of the internal work of the system. We recommend that you use analysis-level classes to provide more detailed content for rational uniied process. See Figure 4.

Figure 4: detailed master process of the installment loan use case

How to describe the content of this image more accurately is beyond the scope of this article.ArticleGet more detailed information from the first three resource references listed at the end. Note that in the example, we chose to divide the edge class into two pages. A simpler approach is to accept all edge interactions through a single element.

Create a model in custom Mode

You may have a certain understanding of the design pattern like Gang of Four. These defined patterns are supported in rational xde, and we will show the usage of some patterns later in this article. Rational xde further supports the mode, which provides the ability to simplify the definition of your own mode through UML. The ability of this custom mode not only allows you to implement your own design, but also automates some boring work in the modeling process, such as generating multiple use case flowcharts. In typical cases, the use case has more than one event stream. For example, it is shown that the installment loan use case has at least two event streams: one is the scenario of successful archiving, and the other is the scenario where the operation fails when the loan details are obtained. Figure 5 shows a custom mode (ucartifacts) that generates a main event stream (SUCCESS) and two failed event streams for us.

Figure 5: Event flowchart for automated Use Case Generation in the Custom mode (ucartifacts)

This simple mode contains two input parameters: ausecase as the use case model element input, and anactor as the role model element input. Create an object with the name of the input parameter. The name of the use case is added to the boundary, control, or entity name. These objects are used to define the main event flow diagram and the sequence diagram of two optional event flow diagrams, which are based on the standard UML diagram provided by xde. Creating a sequence chart for a use case is very simple. You can drag/drop related objects in the Model Browser to create a sequence chart. Each of the two optional event streams can use the role created in the mode, any boundary object, control object, and entity object. We can complete the use case chart by drawing the required messages between different objects and deleting any analysis objects not involved in the event stream.

Implementation Design

Figure 6: initial class diagram of the "show installment loan" use case

Figure 6 shows the class diagram of the "show installment loan" Use Case.

This figure shows the basic roles that implement key requirements, but the classes used in other use cases are not taken into account. To achieve unified analysis and modeling, we need to use the same method to analyze other use cases and then merge the results. At this stage, we primarily aim to identify and exclude duplicate classes and merge similar and overlapping functions into the same class. For example, we can combine amortization and makepaymentcontrol into a separate control object that can process multiple use cases. Here we will focus on the "show installment loans" use cases, but not all of them. You can refer to the first three articles in the resource section at the end of this article to learn more about use cases.

J2EE Implementation Scheme

So far, we have discussed almost nothing to do with specific implementation technologies. Now let's take a look at how xde is applied to J2EE development. In general, the analysis class we discussed above will be mapped to the following J2EE technology:

Boundary)

    • Html
    • Assumerver page (JSP)

Control Object)

    • Servlets
    • Session beans
    • Message Driven beans

Entity object)

    • Entity beans
    • JavaBean

Choosing the correct and reasonable J2EE technology when developing your application system is just the beginning. Because different technologies can be used to achieve similar solutions, the most reasonable choice depends on your implementation details and system requirements.

Of course, the coolest part of the rational xde J2EE mode is that each mode is fully implemented by xde. All you need to do is provide business logic for your application. In this section, let's take a look at the details you need to know to use the front controller mode.

Establish the relationship between requests and Use Cases

A request (for example, a form submission) must be simply specified to a specific use case. In the implementation of the Front Controller mode we discussed, this information should be transmitted through the hidden fields in the form. The name of the use case should be set when the form is created. When a form is submitted, the Controller simply parses parameters to determine which use case should be called. When a request is not explicitly specified for a specific use case, a default Use Case function is usually set to process the request (see below ).

  
           
           

show amortization

enter the following information about the loan:

principal dollars

Rate %

duration years

Request Processing through Controller

The controller does not need any implementation work. The implementation of the mode extracts hidden parameters according to the required logic, requests the relevant helper bean, and entrusts helper bean for processing. Figure 7 shows the static relationship between the page and the Controller. The complete automatically generated request processing code is shown in the code list below figure 7.

Figure 7: Relationship between forms and controllers

// Check if we have a use case name passed on the URL. String usecase = httprequest. getparameter ("usecase"); ihelper = NULL; If (usecase! = NULL) {// dynamically instantiate a helper and call it. ihelper = (ihelper) thehelperfactory. create (usecase); If (ihelper = NULL) ihelper = (ihelper) thehelperfactory. createdefaulthelper ();} else {ihelper = (ihelper) thehelperfactory. createdefaulthelper ();} ihelper. processrequest (httprequest, httpresponse );

Establishes the ing between use cases and helper Bean

You can add the ing information in the helperfactory constructor to establish the ing between the use case and helper bean. The ing between the "show installment loan" and "set loan" use cases is simple. Please refer to the following code snippet. This Code only needs to be placed in the appropriate and pre-defined position of the helperfactory constructor during design.

// Establish showamortization Use Case mapping to its helper classusecasename = "showamortization"; classname = "showamortizationhelper"; addmap (usecasename, classname ); // establish setuploan Use Case mapping to its respective helper classusecasename = "setuploan"; classname = "setuploanhelper"; addmap (usecasename, classname );

Implementation of helper Bean

Obviously, the implementation of helper bean in this scenario should be different for different use cases. Generally, a helper bean usually needs to extract appropriate form parameters from the equivalent additional information in the request and collected and other participants (for example, Session Bean and Entity Bean, then, a processing result that can be used for display is generated.

For some examples of this processing process, see the following list. Note that the xde mode engine completely eliminates the need to manually create a helper class. All you need to do is simply select the "generated value" option in the wizard and enter the helper class name. Figure 8 shows the wizard.

// Extract the info from the request parameterstring sprincipal = httprequest. getparameter ("principal ");..... // Locate the amortization EJB using the service locator ...... // Call the remote method on the session beanfloat totalinterest = theremote. amortize (principal, rate, terminyears); // put data in the amortvaluebeanamortvaluebean AVB = new amortvaluebean (); AVB. setprincipal (principal );..... // Set the session attributehttprequest. getsession (). setattribute ("AVB", AVB );

Figure 8: automatically generate basic helper Bean

Display result

Once again, there are different ways to do the same job. In typical cases, the data should be available for JSP, and JSP will be responsible for the data display format. Figure 9 shows the static relationship. For this method, JSPSource codeShown in Figure 9.

Figure 9 relationship between JSP and formatted/displayed data

Extracts data from the 'avb' bean instance and formats/displays it <JSP: usebean class = "amortvaluebean" id = "AVB" Scope = "session"/> <B> results of your loan amortization request: <br> pricipal entered: <% = AVB. getprincipal () %> <br> yy. total payments: <% = AVB. gettotalpayments () %> <br> </B> <p> <a href = "mainloan.html"> back to main page </a>

Code Template)

The code template is another capability provided by rational xde to simplify developers' development work. They provide very effective mechanisms:

    • Code snippets andAlgorithmReuse
    • A solution that achieves consistency based on code sharing for specific problems
    • Create Standard Header information and comments

Rational xde provides substantial support for code templates. In addition to scalable and built-in infrastructure, it also provides the following capabilities:

    • Bind one or more code templates to one method
    • Remove the binding of a code template as needed
    • Reschedule the binding order to meet the code generation needs
    • Parameterized Code Template

In our example, you can create a code template to create a ing between the use case and the helper class. Then you can bind the code template to the constructor multiple times, and provide different default values for the code template to generate custom code.

Figure 10 shows an example.

Figure 10: Code Template for creating case and helper bean ing

Code templates can also be used as part of custom patterns, so you can use rational xde to create a more scalable application framework. In fact, the rational xde also uses code templates and patterns internally.

Capabilities to achieve other capabilities of the product. For example, the generation of Code related to getters and setters and the implementation of design patterns all use the code template capabilities.

End-to-End scenario

For the simple application in this article, we have covered the specific design and implementation details. Now Let's combine these parts. The next two sequence diagrams capture end-to-end interaction between different objects, including participants from two modes.

Figure 11 shows the front-end activity: the form is submitted to the Controller. The controller obtains the Helper bean and requires it to process external requests.

Figure 11: The form is submitted and processed by the Controller.

Figure 12 is the continuation of the previous sequence chart. It displays various initialization actions of helper bean, and the final request is forwarded to the JSP page responsible for formatting and displaying the computing result. The JSP page displays the result to the end user. Note that the service locator mode is used when obtaining the required EJB.

Figure 12: helper bean executes the processing process and displays the result

Modes and code templates simplify and accelerate J2EE development

I hope this article will convey the benefits that rational xde brings to developers in the J2EE project. The patterns and code templates in rational xde provide a simple way to use classic solutions to accelerate software development. Other capabilities of rational xde-such as the ability to automatically synchronize and create custom patterns and code templates-will free developers from tedious and repetitive tasks and further accelerate software. development.

References

    • Khawar Ahmed and Cary umrysh: developing enterprise-level Java applications using J2EE and UML Addison-Wesley, 2001.

    • Ivar jakbson, Magnus christerson, Patrik Jonsson, and Gunnar overgaard, object-oriented software engineering, Addison-Wesley, 1992.

    • Rational Unified Process Guide: Analysis

    • Grady booch, James Rumbaugh, and Ivar Jacob, User Guide to unified modeling language E. Addison-Wesley, 1999.

About the author

Khawar Z. Ahmed is a member of the IBM Rational xde technology market department and is responsible for the Java platform version of xde. He is also a bookDeveloping Enterprise Java applications with J2EE and UMLYou can contact him through the kzahmed@us.ibm.com.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.