Tutorial: Design Patterns in the VSM



Similar documents
Tutorial: Building a Web Application with Struts

How to Build an E-Commerce Application using J2EE. Carol McDonald Code Camp Engineer

Java 2 Platform, Enterprise Edition (J2EE) Bruno Souza Java Technologist, Sun Microsystems, Inc.

JEE Web Applications Jeff Zhuk

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

NetBeans IDE Field Guide

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Client-server 3-tier N-tier

In this chapter, we lay the foundation for all our further discussions. We start

Core J2EE Patterns, Frameworks and Micro Architectures

Introduction to Sun ONE Application Server 7

MERMIG The advanced collaboration software

Contents. Client-server and multi-tier architectures. The Java 2 Enterprise Edition (J2EE) platform

Partitioning and Clustering Demonstration

Glassfish, JAVA EE, Servlets, JSP, EJB

Japan Communication India Skill Development Center

Net-WMS FP Net-WMS SPECIFIC TARGETED RESEARCH OR INNOVATION PROJECT. Networked Businesses. D.8.1 Networked architecture J2EE compliant

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

Title Page. Hosted Payment Page Guide ACI Commerce Gateway

What Is the Java TM 2 Platform, Enterprise Edition?

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

Architectural Overview

Getting Started with Web Applications

Design Approaches of Web Application with Efficient Performance in JAVA

MVC pattern in java web programming

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

BEAWebLogic. Portal. Portlet Development Guide

WebObjects Web Applications Programming Guide. (Legacy)

How To Understand The Architecture Of Java 2Ee, J2Ee, And J2E (Java) In A Wordpress Blog Post

SSC - Web development Model-View-Controller for Java web application development

Oracle WebLogic Server 11g: Administration Essentials

Oracle9i Application Server: Options for Running Active Server Pages. An Oracle White Paper July 2001

A framework for web-based product data management using J2EE

Oracle Hyperion Financial Management Developer and Customization Guide

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

How To Develop A Web Service In A Microsoft J2Ee (Java) 2.5 (Oracle) 2-Year Old (Orcient) 2Dj (Oracles) 2E (Orca) 2Gj (J

Virtual Credit Card Processing System

Course Name: Course in JSP Course Code: P5

WEB APPLICATION DEVELOPMENT. UNIT I J2EE Platform 9

IBM Rational Rapid Developer Components & Web Services

zen Platform technical white paper

Red Hat Enterprise Portal Server: Architecture and Features

EJB & J2EE. Component Technology with thanks to Jim Dowling. Components. Problems with Previous Paradigms. What EJB Accomplishes

How to make a good Software Requirement Specification(SRS)

JReport Server Deployment Scenarios

Web Development in Java

Oracle Hyperion Financial Management Custom Pages Development Guide

Building and Using Web Services With JDeveloper 11g

WebSphere Portal Server and Web Services Whitepaper

Building Clustered Enterprise Applications

}w!"#$%&'()+,-./012345<ya

Customer Bank Account Management System Technical Specification Document

Pentesting Web Frameworks (preview of next year's SEC642 update)

Consuming and Producing Web Services with WST and JST. Christopher M. Judd. President/Consultant Judd Solutions, LLC

Portals, Portlets & Liferay Platform

CS169.1x Lecture 5: SaaS Architecture and Introduction to Rails " Fall 2012"

Accessing Data with ADOBE FLEX 4.6

Address Phone & Fax Internet

Architecture Guide Jahia EE v6.1

Using EMC Documentum with Adobe LiveCycle ES

<Insert Picture Here> Betting Big on JavaServer Faces: Components, Tools, and Tricks

DTS Web Developers Guide

Chapter -5 SCALABILITY AND AVAILABILITY

This training is targeted at System Administrators and developers wanting to understand more about administering a WebLogic instance.

Enterprise Integration Architectures for the Financial Services and Insurance Industries

Client/server is a network architecture that divides functions into client and server

Mobile Trillium Engine

Model-View-Controller. and. Struts 2

JAVA ENTERPRISE IN A NUTSHELL. Jim Farley and William Crawford. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo.

Complete Java Web Development

Jaspersoft APIs. Integrating BI with your Applications. Community and Professional Editions

SAP NetWeaver Portal Development Kits for.net and Java

Web Container Components Servlet JSP Tag Libraries

Proposal for DSpace Web MVC

Using Tomcat with CA Clarity PPM

Mastering Tomcat Development

IBM WebSphere Server Administration

Pro<DOC/> e-commerce Technology An Introduction

Course Description. Course Audience. Course Outline. Course Page - Page 1 of 5

: Test 217, WebSphere Commerce V6.0. Application Development

Commercial software development with the help of J2EE architecture and MVC

INTERNET PROGRAMMING AND DEVELOPMENT AEC LEA.BN Course Descriptions & Outcome Competency

Framework Adoption for Java Enterprise Application Development

Developing Web Services with Documentum

Oracle Identity Analytics Architecture. An Oracle White Paper July 2010

2012 LABVANTAGE Solutions, Inc. All Rights Reserved.

JAVA. EXAMPLES IN A NUTSHELL. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo. Third Edition.

ten best practices for J2EE development

A Comparative Study of Web Development Technologies Using Open Source and Proprietary Software

J2EE Web Development. Agenda. Application servers. What is J2EE? Main component types Application Scenarios J2EE APIs and Services.

RNM Reply Network Manager

Web-JISIS Reference Manual

ACM Crossroads Student Magazine The ACM's First Electronic Publication

Sophos Mobile Control Technical guide

Instituto Politécnico Nacional Escuela Superior de Cómputo. THEMATIC UNIT: I Introduction to Web Applications

Java Technology in the Design and Implementation of Web Applications

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

Productivity Comparison for Building Applications and Web Services

Research Article. ISSN (Print) *Corresponding author Lili Wang

Transcription:

Tutorial: Design Patterns in the VSM A software design pattern describes an approach to solving a recurring programming problem or performing a task. The design patterns discussed in this article can improve the performance of J2EE applications over the Internet or an intranet, and make them more flexible and easier to maintain. OTN members can download complete VSM source code and installation instructions. Contents 1. Concepts 2. Design 3. Required Software 4. Setup 5. Implementation 6. Resources 7. Feedback

Required Software This tutorial presents several code examples. If you want to study them in context, download and install the VSM source code. If you also want to build and run the VSM application, you will need the software listed in the Required Software section of About the Virtual Shopping Mall.

Concepts The VSM sample application demonstrates ways to implement the following design patterns. Model-View-Controller Session Façade Value Object Service Locator UUID for EJB MVC (Model View Controller) The MVC design pattern differs from the others discussed in this article, which describe ways to solve specific programming problems or perform specific tasks, because the MVC design pattern describes an approach to an application as a whole. The approach is multi-tiered and modular; the MVC design pattern identifies three entities, each operating in a different logical layer within the application space: Model: A back-end representation of enterprise data and business logic, the model also maintains data about the state of the application. In many cases, the model is a logical representation of a real-world process. View: The front-end presentation layer that renders the model for end-users. Views also provide user interfaces for accessing the enterprise data represented by the model. Controller: The middle tier of the MVC pattern. The controller defines application behavior, selecting views for presentation and capturing a user's interactions with views and routing them as commands to the model. The MVC design pattern defines a clear separation of application logic, presentation details, business rules and data. As a result, multiple clients, displays, and devices can use the same application and business rules to work with the same data. The following figure shows how model, view, and controller interact.

This version of the VSM uses Apache Struts as the MVC framework. For more information, see the tutorial Building a Web Application with Struts. Session Façade The Session Façade design pattern is useful in situations where client objects need to interact with a set of EJBs to perform tasks in a workflow. For example, in the VSM environment, customers browse shops and order products, shop owners track orders and maintain inventory, and adminstrators approve and reject requests for new shops and manage category lists. In an implementation where client objects interact directly with the underlying EJBs, the following problems can arise: When an EJB's interface changes, client objects must also be updated. This situation is analogous to the brittle class problem common in object-oriented programming. To carry out a workflow, client objects must make numerous remote calls to access the EJBs, leading to increased network traffic and reduced performance. A session façade solves such problems by presenting client objects with a unified interface to the underlying EJBs. Client objects interact only with the façade, which resides on the server and invokes the appropriate EJB methods. As a result, dependencies and communication between clients and EJBs is reduced. A session façade can also simplify transaction management: for example, when a database transaction involves multiple method calls, all could be wrapped in one method of the façade and the transaction could be monitored at that level. The following figures show this client-ejb interaction with and without the session façade, and how the session façade reduces network traffic.

Without Session Façade With Session Façade (CartManagerBean) Value Object The Value Object design pattern (also known as Data Transfer Object) describes a container for a set of related data. It is often (but not necessarily) used with the Session Façade pattern to reduce network traffic and the number of method calls required to get an entity's attribute values. For example, when a customer uses the VSM to buy a product, the application generates an order comprising several attributes including order ID, order date, customer name, and shipping address. To retrieve the details of an order, an application that does not implement the Value Object pattern would have to make a remote get method call for each attribute (example: Orders.getOrderID), adding to network traffic and increasing EJB container resource usage. The figures below show interactions with and without the Value Object design pattern, and how the pattern reduces network traffic. Without Value Object With Value Object (OrderDetails)

Service Locator The Service Locator design pattern gives clients a simple interface to the potentially complex details of finding and creating application objects and services. Without a Service Locator, clients must use the JNDI (Java Naming and Directory Interface ) API to perform resource-intensive lookup and creation tasks. A Service Locator simplifies client-side code: it abstracts and encapsulates such dependencies and network details, and moves logic to the server tier. In addition, the Service Locator caches the initial context objects and references to the factory objects (e.g., EJBHome interfaces, JMS connection factories) shares them with other clients to improve overall application performance. UUID for EJB The UUID for EJB design pattern is described in the book EJB Design Patterns by Floyd Marinescu. Here is an excerpt from the text: "A UUID is a primary key encoded as a string that contains an amalgamation of system information that makes the generated UUID completely unique over space and time, irrespective of when and where it was generated. As a completely decentralized algorithm, there can be multiple instances of UUIDs across a cluster and even in the same server, allowing for fast and efficient primary key generation."

Design The VSM sample application was designed to demonstrate key features of Oracle9i JDeveloper, including: Implementation of J2EE design patterns. Struts, an open source framework for building Web applications. The core of the Struts framework is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and Extensible Markup Language (XML). Support for Struts is built into JDeveloper, and OTN developers used it to build the interface and Web application for VSM end-users and shop owners. For details, see Building the End-User's Interface (Struts). Architecture Diagram The following figure gives a high-level view of the VSM architecture.

Entity Diagram The figures below were created using JDeveloper. They show the most important VSM entities and the relationships between them.

Other apects of the VSM design are covered in various lessons in this tutorial series.

Setup No special setup steps are required to implement J2EE design patterns. If you use Oracle9i JDeveloper as your IDE, add the J2EE library to your project. For coding details, see the Implementation section. To configure your system to build and run the VSM sample application, see the Setup section of About the Virtual Shopping Mall.

Implementation The VSM sample application demonstrates ways to implement the following design patterns. Model-View-Controller Session Façade Value Object Service Locator MVC (Model View Controller) The MVC design pattern defines a clear separation of application logic, presentation details, business rules and data. As a result, multiple clients, displays, and devices can use the same application and business rules to work with the same data. The model is implemented by EJBs and other Java classes, many of which represent real-world objects. such as shops, shopping carts, and orders. For implementation examples, see MallAdministration.java, ShopOwner.java, and ShoppingCart.java. The views are provided by JavaServer Pages (JSPs) rendered in a browser. Examples include shoppingmall.jsp, shopowner.jsp, and shoppingcart.jsp. The central controller is implemented by Apache Struts and the servlet is org.apache.struts.action.actionservlet. When an end-user interacts with a view (for example, by submitting a form), this HTTP servlet dispatches the action to a controller object which in turn invokes methods on objects in the model. Session Façade In the VSM, the CartManagerBean implements a session façade that provides an interface to the EJBs that manage the items in a customer's shopping cart. The CartManagerBean exposes the checkoutcart method to clients, encapsulating inventory management and order creation tasks performed by underlying objects InventoryManager and OrdersBean (accessed via OrdersHome).

public StringBuffer checkoutcart( ShoppingCart cart ) throws CartException { try { // Get the order home OrdersHome home = (OrdersHome)ServiceLocator.getLocator(). getservice( "Orders" );... // For each item in the cart for( int i = cart.getitems().length - 1; i >= 0; i-- ) { currentitem = (CartItem)cart.getItems()[i]; // check the inventory if(!inventorymanager.inventorycheck( currentitem.getid(), currentitem.getquantity() ) ) { response.append( "Failure," ); response.append( currentitem.getid() ); response.append( "," ); response.append( InventoryManager.getInventory(currentItem.getID())); continue;... // Create the order and add it to the table order = home.create( new Integer( orderid ), details ); shops.put( shopid, order );... // Add it to the order for the shop order.setorderitemid( item ); cart.removeitem( i ); if( response.length() < 1 ) { response.append( "Checked out your cart successfully" ); return response;...... Value Object Tthe VSM implements the Value Object design pattern in several places, creating a container object and sending it across the network to the client, which can then access the data via local method calls. For example, the following code from CartManagerBean.checkOutCart uses an OrderDetails object to store data for a given order.

public StringBuffer checkoutcart( ShoppingCart cart ) throws CartException {... // Create order details details = new OrderDetails( orderid, new Date(), cart.getusername(), shopid.intvalue(), shippingaddress.getaddress(), shippingaddress.getcity(), shippingaddress.getstate(), shippingaddress.getcountry(), shippingaddress.getzip(), shippingaddress.getphone() ); // Create the order and add it to the table order = home.create( new Integer( orderid ), details ); shops.put( shopid, order );... The VSM application implements the Value Object design pattern in these files: UserDetails.java ItemDetails.java ItemAttributes.java OrderDetails.java ShopDetails.java Service Locator In the VSM, ServiceLocator.java implements this design pattern. This singleton class is the central place for looking up objects in the JNDI tree, as shown in the following code from ServiceLocator.getService, which finds an object matching a supplied JNDI name.

public class ServiceLocator {... /** * Method to return an object in the default JNDI context, with * the supplied JNDI name. * @param <b>jndiname</b> The JNDI name * @returns <b>object</b> The object in the JNDI tree for this name. * @throws <b>utilityexception</b> Exception this method can throw */ public Object getservice( String jndiname ) throws UtilityException { try { // If the service is not in the cache, if(!homecache.containskey( jndiname ) ) { // Get the object for the supplied jndi name and put it in the cache homecache.put( jndiname, defaultcontext.lookup( jndiname ) ); catch( NamingException ex ) { throw new UtilityException( "Exception thrown from getservice " + "method of ServiceLocator class of given "+ "status : " + ex.getmessage() ); catch( SecurityException ex ) { throw new UtilityException( "Exception thrown from from getservice " + "method of ServiceLocator class of given "+ "status : " + ex.getmessage() ); // Return object from cache return homecache.get( jndiname );...

Resources This tutorial is part of a series based on the Virtual Shopping Mall (VSM) sample application. Following are links to resources that can help you understand and apply the concepts and techniques presented in the tutorials. See the Required Software section to obtain the VSM source code and related files. Resource Oracle9i JDeveloper Online Help J2EE Design Patterns URL http://otn.oracle.com/jdeveloper903/help/ http://java.sun.com/blueprints/patterns/j2ee_patterns/index.html EJB Design Patterns http://www.theserverside.com/books/ejbdesignpatterns/index.jsp J2EE 1.3 SDK http://java.sun.com/j2ee/sdk_1.3/

Feedback If you have questions or comments about this tutorial, you can: Post a message in the OTN Sample Code discussion forum. OTN developers and other experts monitor the forum. Send email to the author. mailto:robert.hall@oracle.com If you have suggestions or ideas for future tutorials, you can Post a message in the OTN Member Feedback forum. Send email to mailto:raghavan.sarathy@oracle.com.