Expresso Controller Objects

Expresso complements the J2EE architecture by providing a framework for a clean separation of data, presentation, and application logic.

Version:

Expresso 5.0

Author:

Michael Nash, Sandra Cann, Geeta, Tino Dai & other Contributors

Expresso Components Listing


Caching Configuration Values Controller Objects
Database Objects DB Connection Pooling Email Connectivity
Event Notification and Error Handling Health Check Job Control
Logging Registration & Login Security
Taglibs Unit Testing Workflow
XML


Introduction

An Expresso Controller is a Struts Action subclass. (Contrary to what may be initial expectation, a "Controller" does not therefore extend the Struts ActionServlet.) The Expresso Controller component is thus strictly part of the front end: the web tier. Controller objects provide a means for a sequence of interactions to be encapsulated in a way that makes them available to virtually any kind of user interface (e.g. servlet, JSP, Applet, Application and others). A Controller is a finite-state machine, where the flow from one state to another is directed by the Controller itself, and by the actions the user takes.

Controller objects should be used to encapsulate the logic of your application, especially any user-interaction required. The idea is to take advantage of things that are provided by the framework and not re-invent anything that is not required. You must design your user-interface in a presentation-independent way, thinking in terms of abstract inputs and outputs, to take best advantage of Controller objects. This allows you to take advantage of the GUI-independent user-interface abilities in Expresso, easily modifying the "view" of your application even once the logic is completed.

Expresso has a built-in mechansim by which you can specify security for each of your your controllers. For example, a group of users can be allowed or not allowed to access the entire controller, or can be granted permission to only specified states within a controller. This allows a single controller to be used by a wider audience of users, where all states might be available to only certain users (say, system administrators).

Topics

Introduction
Controller Advantages
MVC Architecture
Struts Integration
Finite-State Machines
UI-Independant
Form-Handling
Conclusion

Controller Advantages

Controllers provide a number of advantages:

  • Encapsulate business logic separately from user interface logic
    Controllers are not concerned with the user interface that presents their Inputs, Outputs and Transitions to the client - this separates the business and user interface logic cleanly, and allows each to be maintained as independently as possible, promoting good design practices.
  • Dynamic Secured Access
    Every state of a controller can be secured, and the security data is easily maintainable via Expresso's built-in capabilities. This allows the security to be updated from any location, and for the changes to take effect immediately. This makes controllers ideal for situations where a user's permissions might be updated dynamically - for example, when a customer completes a controller allowing him access to some on-line information, the succesful completion of one controller could then permit him access to additional states in other controllers.
  • MVC Architecture
    Controller objects provide the "Controller" portion of the MVC architecture in a way that is portable across all types of Java environments. They can scale all the way from a Java Micro-edition environment to a complex multi-server cluster using EJB's and application servers.
  • Default User Interface
    There is a default ViewHandler implementation that is used where no "custom" view is defined, which can be used to run a controller without the need to program a custom GUI or design with JSPs, allowing a basic controller to be deployed very quickly, then perhaps enhanced later with a custom UI.
  • XML User Interface
    An additional user interface option allows controller responses to be sent via XML, optionally transformed via an XSL stylesheet. In addition to providing great UI flexibility, this mode is also very handy for debugging.
  • Session Management
    Controllers themselves do not preserve any information about their state from one invocation to another, requiring their input items and parameters to provide them with the information needed to process the next state. They can, however, use a PersistantSession object to preserve state information across invocations, and to make it available to other controller objects.
  • Test Harnesses
    Useful test harnesses exist for testing controller objects, both from the command line and from a JSP.

MVC Architecture

Keeping the elements of Model (business tier), View (presentation and user interface) and Controller separated is a central issue of good application design. The Expresso "Controller" objects make this easy when building web applications.

Expresso includes a package of components for creating several types of "Controller" objects. These Controller objects encapsulate a series of interactions with the user, in a manner similar to Session EJB's (in fact a Controller can be a Session EJB in an environment where EJB's are supported). The Controller can be utilised from any kind of client: a Servlet, a JSP, an Applet, or an Application.

Struts Integration

The Apache Jakarta project has a sub-project called "Struts" that has complimentary aims to the Controller object in Expresso. Struts is considered by most to be the defacto MVC implmentation. Therefore Expresso is integrated with Expresso (as of v4.0) and brings the best of both worlds to Expresso.

The struts-config.xml file provides the mappings required by the Struts frameworks from URL's to "Action" objects - in this case, to the Controller objects in Expresso (which are sub-classes of the Action object.) In addition to the normal struts-config.xml file, applications that have their own Controller objects can provide mappings for them in separate configuration files. For example, eForum has an eforum-config.xml file that provides mappings for it's Controllers. In this way, the core struts-config.xml file for Expresso does not need to be adjusted as you install or develop other applications, and the individual configurations for your own applications can be easily adjusted and kept independant.

Finite-State Machines

What is a (deterministic) finite state machine? Mathematically, it is a directed graph, where the nodes are "system states" and the arrows are labelled with "user actions". Thus given any state and a user action, exactly one state results and the finte state machine has the responsibility of determining what that resultant state is. Intuitively, you pick some state, follow some user action - via an arrow out of that state - and the node at the end of that arrow tells you what state results due to that action. One state is designated as the "initial state" and some nonempty subset of states as the "final states". Intuitively, the final states are thought of as "successful states": reached via successful completions of (possibly) different user actions.

A Controller object can be thought of as a finite-state machine, transitioning from state to state and performing the appropriate business logic at each state. These states comprise the "Model" of your application - it is here that the application interacts with the database, with the user, with files and other resources, and does it's processing. So if each state represents a particular step or unit of processing, the controller can be thought of as a (finite-state) machine, and the function of transitioning from one state to another is how the controller gets it's work done.


As a controller transitions to a new state, it generates a "ControllerResponse" object. This object contains a group of ControllerElement objects, of 4 types: Inputs, Outputs, Transitions, and Blocks.

UI-Independant

The controller architecture is independant of the method used to present the outputs of the controller to the user - User Interfaces (UI) are available for several different web-application technologies, including:

  • JSP (Java Server Pages). This is a popular method of creating the "view" for Controller objects.
  • WebMacro. This templating engine can be used to create the view as webmacro template files from Controller objects.
  • Text. Useful for testing, ordinary command-line operation of controllers is possible.
  • XSL. Where the UI may be a mobile device, WebTV, a PDF reader, or any of a number of other kinds of browsers, XML outputs can be generated from Controllers that can be transformed via the appropriate XSL stylesheet into WML, PDF, HTML, XHTML, XML, and many other formats. This function is part of the Expresso XML sub-project.

Form-Handling

Special support facilities exist to make using Controller objects easier in a web forms-based environment, providing the ability to validate forms, especially against DB Objects, suppliing error handling and retry abilities, and provide the ability for the user to navigate between forms easily.

Types of Controller

There are several types of controllers available, all extending the base class com.jcorporate.expresso.core.controller.Controller. They each have a specific use:

  • Controller is the base class for all Controller object, and can be directly extended for Controller that either handle their own connections or that do not connect to a database.
  • DBController extends the base Controller object and provides easy access to a database connection from the connection pool..

Controller Objects Included with Expresso

The following table lists some of the important Controller classes included with Expresso. All of them belong to the com.jcorporate.expresso.services.controller package.

Controller Class

Description

CacheControl

Controls the CacheManager. Instead of controlling the CacheManager directly, this allows a user to clear either one or all of the caches and to display current status of the cache.

ControllerSecurityMatrix

Provides an easy conduit for controlling access to controllers and the states within the controllers.

DBMaint

A servlet/controller that enables database maintenance of a specified DBObject.

DBSecurityMatrix

Controls access to DBObjects by authorized people.

EditUserPreference

Allows a user to edit his/her preferences either for a single object or all of he user's own preferences.

ErrorHandler

Displays error to user, logs error and triggers email notification to specificed list of users both local and remote.

JobSecurityMatrix

Allows easy administration of the security rights of user groups to get to certain Jobs and to certain methods in those Jobs (assuming the job has more than one method).

Log Allows for log administration including archiving current log, starting a new empty log, and viewing of both the database log and the text log.
LoginController Validates login/logouts, establishing and releasing session, and basic interaction with the registration systems
LoginListener A skeleton for a developer to extend.
Navigation Provides a framework for navigating around an application. It does this by using the schema object's information
QueueJob Acts as a traffic cop for any named job that the user has access to queue.
Registration Provides a mechanism for self registration of for new system users.
Status Shows various information about the servlet systems, the back-end database connections, and server-task tasks.
ValidationController Monitors and reacts to the user interaction of the URL being clicked from the validation job.

Controllers and EJBs

DBObjects are not Enterprise Java Beans. However, if you have Expresso Framework 5 downloaded on your webserver, you can work with Enterprise Java Beans if you want to. There are no restrictions. However since Expresso does not create or manipulate EJBs directly (at the moment), but instead talks to the database using DBObjects, you will have to do the extra work yourself.

Briefly, EJB technology is designed to be distributed component based, transaction safe, scalable across virtual machines, and portable across J2EE application servers. This is important if you run Enterprise mission-critical applications. In detail, EJB provides the following features:

  • Distributed Component-based - EJB is a component build technology that permits deployment across local and foreign servers.
  • Transaction safe - J2EE specifies level of transaction control for Enterprise JavaBeans so that two separate database transactions can be undertaken without serious race conditions, double insertions, or phantom reads.
  • Scalable - J2EE specifies that application servers can deploy EJBs across virtual machines on different CPUs and across networks. So if you buy an application server you can take advantage of clustering features, load balancing, etc. for your EJBs. (For example, if the server in London crashes, then the one in New York can take over running a bank business 24/7/365 over the web. Moreover, if you find that web business doubles overnight then you can buy more applications servers and spread the work.)
  • Portable - J2EE certified application servers can deploy EJBs that are written on another EJB server. Your mileage may vary if you use proprietary server's features of course, but that's life.
DBObjects (in Expresso 5.0) do not have any of the above Enterprise features. However DBObjects are better than nothing if you have no Object Relational layer. DBObjects are good because you can manipulate database tables within Java, the language we all love. DBObjects are an implementation of a well-recognized software design pattern (see Mark Grand, J2EE Enterprise Patterns, Wiley 2001) For more info look at TheServerSide.com for Chuck Cavaness' preview book chapter on ``EJB and Struts''.

Conclusion

For technical information about how to use controller objects, please refer to the Expresso Developers Guide (EDG) or the Javadocs.

Top of Page


Home | Products | Services | Partners | Customers | About Us | Login | Forums | Contact Us

Copyright © 2001-2002 Jcorporate Ltd. All rights reserved. Copyright Privacy

Last Modified: 25-Nov-2002