Concept
Gross structure
The first cute bits
State of the code
Hopes / plans
Acknowledgments
Javadoc
Concept
(Skip this bit if you know about state machines...)
Web based applications are commonplace now, with complex and detailed
applications online. However, when writing these apps we seem to
be re-learning some of the basic concepts of application development and
design. Web designers are re-learning how to implement principles
like keeping a well defined business model separate from the application
or user interface, managing 'wizards' or other long, structured conversations,
and consistent error handling.
This project is designed to provide tools for implementing many of
these features.
The idea is to model the user interface of the application as a UML
statechart.
Some (though not all) of the states will represent screens or messages
to be sent to the user.
The statechart includes the transitions allowed from state to state
in the form of events which can be thrown from states.
Through some proprietary extensions, the statechart can also include
exception states and wizard-like conversations.
This machine will ensure that the UI always and only follows paths that
are explicitly allowed in the statechart. It provides a simple and
consistent means for exception handling, allowing you to specify states
that should be used as exception handlers. It provides support for
'wizards' by allowing you to specify a set of states that should only be
entered from one point, and should only be exited through a few exit points.
The core is independent of any particular web server, statechart representation,
persistence mechanism, etc.
Gross structure
The statemachine is based around a representation of a statechart.
The chart is modeled internally by five interfaces, Application, State,
Event, StateTransition and UnitOfWork.
The application is represented by Controller and View classes, where
Controllers take responsibility for handling Events, and Views take responsibility
for rendering the current state to the user. Note that this statemachine
does not say anything about the model. The model should be implemented
separately according to your own best design. It can, of course,
interact with any Java-based model, but it does not impose any restrictions
on how the model is designed or written.
The first cute bits
This project is designed from the start to be generic and applicable to
as many situations as possible. As such, everything which is not
central to the statemachine is written as optional packages which implement
interfaces required by the core.
At the moment there are three different varieties of optional package:
-
The application loaders: The statechart can be represented in many different
ways. Initially there will be an xmlapplicationloader, designed to
load the chart from an XML representation. I hope also to have an ejbapplicationloader,
which will use EJBs with container managed persistence.
-
The web server: I have chosen not to tie this to servlet-based web servers,
although there will be a servlet connector with the first release.
There is also a package written to allow this machine drive a UI written
in swing.
-
User session history: The machine supports storing a history of a users
visit to the application. For the servlet connector the machine will
use a session manager based on HttpSession. For the swing version,
it uses a simple in memory solution.
State of the code
The third beta release is now available through sourceforge. The
project page is, obviously enough, http://sourceforge.net/projects/jstatemachine/.
Javadoc for the code that is written is now
online here.
Unfortunately, I cannot show a working version of the project on this
site. I have got other hosting arranged and will be releasing a website
powered by the statemachine as soon as I can work on it.
Hopes and plans
Obviously, I'd like to see this form the basis for a few good sites.
Another thing I'd really like to see is integration with modeling tools.
The first release of the code will include an XML representation of statecharts.
It shouldn't be too difficult to get a good UML modeling tool to output
statecharts as XML and even generate stubs for the View and Controller
classes...
Acknowledgments
This work was inspired by a project completed by my former employer, ebeon.com
of Dublin, Ireland.
The original design work was done by David Anderson, Marcus O'Connell
and myself. The first implementation was completed by David Anderson, Marcus
O'Connell, Martin Byrne and Mark McSherry.
David Anderson then went on to refine the design, and published a white
paper on the subject, available at http://www.uidesign.net/1999/papers/webmvc_part1.html.
This project is a result of taking the original concepts from that design
and re-writing it on a blank page, with particular emphasis on making it
as portable as possible.
The JStateMachine logo was prepared by Mick O'Farrell of Zeebeck
Design.
Finally, I would like to thank the good people at sourceforge.net for
their services and help.