J2EE Pet Store

xiaoxiao2021-03-06  108

J2EE is an application of Java technology in business operations, which contains multiple operational standards, such as EJB component architecture, JDBC database operation, JMS information transfer, Java Servlets / JSP and other Web component programs, powerful and profound content. In order to let the user can have a template for design J2EE architecture applications, Sun makes a system name "PET Store". This online pet store is an example for the design of Java program and J2EE concept. This system is designed in a formal way, making the person using J2EE architecture with a reference basis. This example comes out, soon it is used as a basis for compatible with J2EE compatible products. Oracle J2EE Application Server (Oracle 9ias), Bea Weblogic Server,

IBM WebSphere has a corresponding product. The spirit of the Java standard is originally a manufacturer to formulate technical standards, and then the best product is selected according to this standard.

The architecture design used by Java PET Store is called MVC design mode. The MVC is a short written in Model-View-Controller, one of the design modes, from SmallTalk. The MVC mode is divided into three classes into three classes. The Model object is specifically used to package the state of the application, and the view is used to demonstrate on the screen. Controller is responsible for defining various action and reactions of the application. The Java pet store system uses the MVC mode to design the entire system architecture, and the objects of each layer are clearly separated. The purpose of the Java Pet Show is to show an expandable corporate computing architecture, which is the three-layer (3-TIERS) design: the data display layer is in the outermost, the middle is the intermediate layer component of the executive business logic, the backend is simple Store the relational database of information. The Java Pet Store was originally used as a J2EE architecture design template and did not specifically for accelerated performance efficiency.

System Architecture and Pet Store Introduction

System architecture

The PET Store website system uses a loosely coupled design architecture, and can interact with multiple data sources, EIS. This example is divided into 4 parts:

1.Web shopping site;

2. Management section, including sales statistics, manual acceptance / reject orders;

3. Order processing, including the following information:

◆ Accept / process order messages through JMS;

◆ Use Java Mail to inform customers;

◆ Order to the supplier through JMS;

◆ Maintain the order database.

4. Supplier, this section includes the following:

◆ Accept orders through JMS;

◆ Delivery goods to users;

◆ Provide a web-based inventory management;

◆ Maintain inventory database.

Pet shop online store features

This store can be accessed through the browser. By browsing, you can put the goods in the shopping cart, create an account / login account, create an order, and pay it by credit card.

Pet store structure

The website service of the pet store is from above. The uppermost layer is WAF (Web Application Framework) to control the screen jump, generate a view, and then call business components to complete business processing (as shown in Figure 1).

Figure 1 Java PET Store Structure

WAF provides services needed for many web applications, including the requested filtration and distribution, the generation of template views, a series of reusable Taglib, and screen process control. Application components encapsulates the logic of processing, which represents commercial data, and operates these business data, and entity EJB represents commercial entities, such as customers, addresses, accounts. Session EJB provides some methods, such as landing a user, outputting a user, managing shopping carts, etc. Other session EJB provides a number of common methods, such as generating a unique marker. Traditional JavaBean components become values ​​objects to deliver data between EJB components and applications. The XML document class is used to process order information. The WAF of this pet store example is the implementation of the J2EE blueprint web layer specification. A web layer process can generally be divided into four steps (as shown in Figure 2):

◆ Explain a request;

◆ Perform a business logic;

◆ Select the next view;

◆ Generate this view.

Figure 2 WAF web layer processing

Pet shop module design

The pet store consists of some independent modules:

◆ Control module It is to distribute requests to each business handling logic, control screen jump, handling corresponding components and users;

◆ Login and registration control modules are implemented and expanded by WAF;

◆ Shopping cart module shopping cart tracking user shopping process;

◆ The login module requires a user to log in to some pages;

◆ The message module is used from the pet store to the like.

◆ Category Module Provides a category view according to user query requirements;

◆ The client module represents customer information, such as addresses, credit cards, contact information, etc. (as shown in Figure 3).

Figure 3 Java PET Store Module Design

In Figure 3, the control module controls all interactions and execution, and each user session has a shopping cart.

Pet shop components

1. EJB, represents business data and executive business logic;

2. JSP page, define the entire application's view framework template (Template.jsp) and template composed of each JSP file, as well as various referenced graphics files;

3. XML file, used to define screen, screen jump control, bind URL to a HTML Action, customize Signon, and J2EE deployment XML files;

4. Servlet shards, used to verify the encoding of the login and output of the user security;

5. Asynchronous information transmitting components, transfer orders using XML package to the order processing center;

6. A installer that generates an example database.

Analyze the application of pet stores

This application is analyzed in accordance with the MVC architecture and hierarchical application model.

Model - View - Control Architecture

1. Application model division method

Analysis of a practical application can have three divisions: the first division method is a model - view-control (MVC) architecture. This method breaks down into data, display, and controls three parts. The second division method divides the application into different levels into different levels, separating the client, web layer, EJBS layer, and bottom data layers or legacy system layers, the hierarchical division method for J2EE applications. The third partition is a traditional functional module division.

The purpose of division is to make complex problems and clarify. Each partition has increased additional complexity, but it also has its benefits. The MVC architecture provides a flexible, reusable, easy test, scalable, and clear design role. Multi-layer design makes it possible to achieve technologies, while feature upgradable and scalability. The modular design decomposes the system into a small direct module, and can be analyzed, tested, and understood separately.

Enterprise-level applications now support multiple types of users using different types of interfaces, such as online stores, need to provide HMTL homepage for web customers.

Wireless customers provide XML homepage, providing a JFC / SWING interface for system administrators, providing an XML-based web service for vendors (see Figure 4).

Figure 4 Various types of user relationship maps supported by the Java PET Store

When developing an application that supports a single type of client, data access logic, display control logic, and interface logic are logically intertwined. But this is very troublesome for enterprise systems that support multiple types of clients. therefore:

◆ For each type of client interface, you need to develop different applications;

◆ Non-interface code for each application is duplicate, and it needs to be repeated in implementation, testing and maintenance;

◆ The copy work itself is expensive because the interface is interleaved with non-interface code;

◆ Repeated work is inevitable, and it is slow and slow.

2. Using the model - View - Control Architecture

The core data and data access functions are separated from the display control logic using these functions in J2EE applications, as shown in Figure 5. This separation allows multiple views to share the same enterprise data model.

Figure 5 MVC architecture

The MVC architecture originated from SmallTalk, initially mapping input, processing, and output tasks in traditional graphical user interface models. However, it can be used directly to map related concepts in multi-storey enterprise applications, and the specific concepts are as follows:

Model represents enterprise data and business rules to control access and data updates. The model is the service software close to the real world, so the modeling technology of the real world can be applied.

View (View) represents the content of the model. It accesses the enterprise data through the model and specifies the display of the data. The view is responsible for the state of the model states to render the data to the user corresponding to the user. You can implement the Push model, that is, the view is registered in the model, or the pull mode, that is, the view is responsible for calling the model when the latest data is required.

Controller converts the view interact with the view into actions performed by the model. In standing GUI clients, user interaction may be a button or menu, and in a web application is a GET and POST HTTP requests. The actions performed by the model include activating the business processing process or changing the model status. Based on the user interaction and model action results, the control is controlled by selecting the appropriate view.

The MVC architecture has the following advantages:

◆ Multi-view uses the same model. The model is separated from the view allows multiple views to use the same enterprise model. Therefore, enterprise-level application model components are easy to implement, test and maintain.

◆ It is easy to support new types of clients. Support a new type of client, just write a view and control, then connect it to an existing enterprise model.

Analyze Java Pet Store Application

view

The view is the interface of the user interface and the application. In the Java PET Store, the view is implemented in the web layer. There are three components implementation views: JSP page, JSP custom tag, and JavaBean. The view part involves three aspects:

Screen

The screen is a page displayed all. As needed, define the following screen in ScreenDefinitions.jsp:

Name: main_screen, default_screen

Name: category_screen

Name: Search_Screen

Name: product_screen

Name: product_details_screen

Name: Cart_Screen

Name: checkout_screen

Name: PlaceOrder_screen

Name: commit_order_screen

Name: Signin_Screen

Name: Signup_Screen

2. template

Because the page of the entire website has the same feature, if each page must have the same elements of LOGO, BANNER, etc., so different components of the template definition page. The template elements defined in this example have FOOTER.JSP, BANNER.JSP, and INDEX.JSP. ScreenDefinitions.jsp defines these template elements, including these template elements, contains them to the page via the Include instruction. 3. The selection of the view selection view is done by control. Control The user displays the ID of the view according to the actual situation, and the run template is displayed on the entire view, as shown in Figure 6. Figure 6 The status of the view selection model model is the data source of the view displayed, but also the specific object of the control. In J2EE, the state of the model is described in three EJBs: stateless session EJB, stateful session EJB and entity EJB. 1. Auxiliary objects have two main accessories: database access objects and value objects. For entity EJB, database access object encapsulates a method of database access, such as Accountdao et al. For all EJB attribute values, it is packaged by a value object, such as ShoppingCartModel, AccountModel, etc. 2. EJBS This example used EJBS as shown in Figure 7. Figure 7 Java PET Store Used EJBS 3. Model status to the boundary binding of the view corresponds to a plurality of views, the binding method of implementing the view is: ModelupDateListener and ModelupDatenotifier implement a registration-listening mode to update the view by calling the listener's PerformUpdate method. E.g:

Public Class AccountWebimpl Extends AccountModel

Implements modelupdatelistener {

Private modelManager mm;

Private account acctejb;

Public AccountWebimpl (ModelManager MM) {

Super (NULL, NULL, NULL};

THIS.MM = mm;

mm.addlistener (JNDINAMES.ACCOUNT_EJBHOME, THIS);

}

Public void performupdate () {

IF (acctejb == null) {

Acctejb = mm.getaccountejb ();

}

Try {

IF (acctejb! = null) Copy (acctejb.getdetails);

} catch (remoteexception re) {

Throw new generalfailureexception (re);

}

}

}

Control control is responsible for handling user requests, calling the corresponding model, updating the status of the model, refresh the view, and returning the user's reasonable page. All control objects of the example are shown in Figure 8. Figure 8 Control Object Figure 1. RequestProcessor RequestProcessor receives and handles all requests for the user, call the RequestToEventTranslator object converts the request into a predefined event, and the view is updated after the event processing is complete. The code is as follows:

Public class requestprocessor {

Private ShoppingClientControllerWebImpl scc;

Private modelManager mm;

Private modelupdatenotifier mun;

Private RequestToeventTranslator EventTranslator; Private SecurityAdapter SecurityAdapter;

Public void init (...) {

MM = (ModelManager) Session.getaTribute ("ModelManager");

Mun = mm;

SCC = New ShoppingClientControllerWebImpl (session);

EventTranslator = New RequestToeventTranslator (this, mm);

}

Public void processRequest (httpservletRequest Req) {

CheckforWebSerLogin (REQ);

EstoreEvent Event = eventTranslator.ProcessRequest (req);

IF (Event! = null) {

Collection updatedmodellist = scc.handleevent (event);

Mun.NotifyListeners (UpdatedModells);

}

}

}

2. ShoppingClientControllerWebImpl ShoppingClientContronerWebImpl is the ShoppingClientController agent object that calls the EJB layer. The code is as follows:

Public class shoppingClientControllerWebimpl {

Private com .... ejb.shoppingClientController sccejb;

PRIVATE HTTPSESSION session;

Public ShoppingClientControllerWebImpl (httpsession session) {

THIS.SESSION = session;

ModelManager MM = (ModelManager) Session.getaTribute ("ModelManager");

SCCEJB = mm.getsccejb ();

}

Public synchronized accountmodel getaccount () {

Return sccejb.getaccount (). getDetails ();

}

......

Public Synchronized Collection Handleevent (ESTOREEVENT ESE) {

Return sccejb.handleevent (eSE);

}

Public synchronized void remove () {

Sccejb.remove ();

}

}

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

New Post(0)