SARS - Software Engineering
Download
Report
Transcript SARS - Software Engineering
SUN J2EE Architecture
(Introduction, J2EE Patterns, Samples)
-- Understanding the SUN J2EE Architecture -© Josef Schiefer, IBM Watson
Process Information Factory
Tiered Approach (5 Tiers)
SUN J2EE Architecture
SUN J2EE Architecture
Front Controller / Dispatcher
SUN J2EE Architecture
Front Controller Interaction
SUN J2EE Architecture
Front Controller Alternatives…
SUN J2EE Architecture
Servlet Front Controller
SUN J2EE Architecture
JSP Front Controller
SUN J2EE Architecture
JSP Front Controller – JSP Code
<%@page contentType="text/html"%>
<%@ page import="corepatterns.util.*" %>
<html>
<head><title>JSP Front Controller</title></head>
<body>
<h3><center> Employee Profile </h3>
<%
/**Control logic goes here... We either dispatch to another JSP at this point or simply allow the remaining portions of scriptlet code to execute**/
String page;
/**ApplicationResources provides a simple API for
retrieving constants and other preconfigured values**/
ApplicationResources resource = ApplicationResources.getInstance();
try{
RequestHelper helper = new RequestHelper(request); // Use a helper object to gather parameter
Command cmdHelper= helper.getCommand(); // Command helper perform custom operation
page = cmdHelper.execute(request, response);
} catch (Exception e){
request.setAttribute(resource.getMessageAttr(),"Exception occured : " + e.getMessage());
page = resource.getErrorPage(e);
}
// dispatch control to view
if(page!=null){
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page);
dispatcher.forward(request, response);
}
%>
<FORM method=POST >
<table width="60%">
<tr>
<td> Not detected next page </td>
</tr>
</table>
</FORM>
</body>
</html>
SUN J2EE Architecture
Servlet Controller Strategy
SUN J2EE Architecture
Command & Controller Strategy
SUN J2EE Architecture
Screen Mappings
<request-mappings>
<screen-definition url="/WEB-INF/xml/screendefinitions.xml" language="en_US"/>
<screen-definition url="/WEB-INF/xml/ja/screendefinitions.xml" language="ja_JP"/>
<default-screen>MAIN</default-screen>
<signin-screen>SIGN_IN</signin-screen>
<signin-error-screen>SIGN_IN_ERROR</signin-error-screen>
<url-mapping url="/main" screen="MAIN"/>
<url-mapping url="/search" screen="SEARCH"/>
<url-mapping url="/category" screen="CATEGORY"/>
…..
<url-mapping url="/verifysignin" screen="SIGN_IN_SUCCESS" useRequestHandler="true"
useFlowHandler="true">
<request-handlerclass>com.sun.j2ee.blueprints.petstore.control.web.handlers.SigninHandler</request-handler-class>
<flow-handler
class="com.sun.j2ee.blueprints.petstore.control.web.handlers.SigninFlowHandler">
<handler-result result="2" screen="SIGN_IN_ERROR"/>
<handler-result result="1" screen="SIGN_IN_SUCCESS"/>
</flow-handler>
</url-mapping>
…..
<exception-mapping exceptionclass="com.sun.j2ee.blueprints.petstore.control.exceptions.SigninFailedException"
screen="SIGN_IN_ERROR"/>
</request-mappings>
SUN J2EE Architecture
Screen Definitions
<screen-definitions>
<template>/template.jsp</template>
<screen>
<screen-name>main</screen-name>
<parameter key="title" value="Welcome to the BluePrints Petstore" direct="true"/>
<parameter key="banner" value="/banner.jsp" direct="false"/>
<parameter key="sidebar" value="/sidebar.jsp" direct="false"/>
<parameter key="body" value="/main.jsp" direct="false"/>
<parameter key="mylist" value="/mylist.jsp" direct="false"/>
<parameter key="advicebanner" value="/advice_banner.jsp" direct="false"/>
<parameter key="footer" value="/footer.jsp" direct="false"/>
</screen>
<screen>
<screen-name>cart</screen-name>
<parameter key="title" value="Cart" direct="true"/>
<parameter key="banner" value="/banner.jsp" direct="false"/>
<parameter key="sidebar" value="/sidebar.jsp" direct="false"/>
<parameter key="body" value="/cart.jsp" direct="false"/>
<parameter key="mylist" value="/mylist.jsp" direct="false"/>
<parameter key="footer" value="/footer.jsp" direct="false"/>
<parameter key="advicebanner" value="/advice_banner.jsp" direct="false"/>
</screen>
….
</screen-definitions>
SUN J2EE Architecture
Example – Flight Reservation
SUN J2EE Architecture
Screen Flow Management / Controllers
SUN J2EE Architecture
Class Model – Web Application
SUN J2EE Architecture
Class Diagram - Flight Management
SUN J2EE Architecture
Controllers/Events/Actions
SUN J2EE Architecture
: MainServlet
: Custom erh
: ScreenFlowManager
: RequestDispatcher
: RequestProcessor
: WebController
: EJBControllerEJB
: StateMachine
Typical
Web
Request
doPost()
processRequest()
: WebAction
doStart()
processRequest()
Event
handleEvent()
handleEvent()
processEvent
: EJBAction
processEvent()
EventResponse
EventResponse
EventResponse
EventResponse
doEnd()
getNextScreen()
nextScreen
forward(nextScreen)
Web Page
SUN J2EE Architecture
Here
logi
Price Itinerary
: Fli ghtInfoEJBActi on
: Fli ghtManagementFacadeEJB
: Fli ghtInformationEJB
: Fli ghtEJB
: SeatsInfoEJB
getFlightInformati on()
Fli ghtInformati on
The inform ation which
fl ights are part of the
itinerary are contained in
the event information.
cal cul ateIti neraryPrice()
* getFlight()
* getSeatsInfos()
SeatsInfos
*getPrice()
Pri ce
summ arized fli ght pri ces
SUN J2EE Architecture
Component
Diagram
EJBAction
actions
EJBActionSupport
events
StateMachine
JSP Pages
<<fil...
FlightManager.WAR
<<SessionBea...
EJBControllerEJB
ejb
<<fil...
FlightManagement.JAR
WebActionException
WebAction
controller
webactions
WebActionSupport
web
<<fil...
FlightManager.EAR
screenflow
<<Servle...
MainServlet
<<fil...
FlightInformation.JAR
RequestProcessor
ScreenFlowManager
FlowHandler
FlowHandlerException
<<fil...
CustomerTavelAgent.JAR
ServiceLocator
<<fil...
SignOn.JAR
WebController
SUN J2EE Architecture
Summary
5 Tiers Architecture
Event objects are used to pass data between the layers
Heavy usage of local interfaces for EJBs (support of fine-grained
objects)
Web Action / EJB Actions
Web Controller / EJB Controller
EJB/Web Packaging
Screen Dispatchers / Screen Management / Screen Mappings
J2EE Patterns
http://developer.java.sun.com/developer/technicalArticles/J2EE/pat
terns
J2EE Blueprints
http://java.sun.com/blueprints
SUN J2EE Architecture