One of the problems in web application design is the disconnect between traditional programming languages and the statelessness of the web. There are ways to work around this, storing session information in hidden fields, setting cookies and tracking session information there or on the server. There are languages designed for the web such as PHP and ASP. Traditional languages are made to work with the web: Java and Perl being two big examples. But none of these capture the nature of the client/server model fundamental to web applications. All of them require some reinvention of the wheel each time an application is built.
Written in an XML language, eXtensible State Machines (XSM) are the controllers in a Model-Controller-View design. They describe what an application can do when in a particular state by detailing what information will allow the application to change to another state and how the business logic is brought into play when the application transitions between two states. The resulting state of the application determines which view is presented to the customer. Session management, state and data persistence are all handled seamlessly behind the scenes of the application.
The basic XSM skeleton is a set of states and transitions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<statemachine> <state id="step1"> <transition state="step2"/> </state> <state id="step2"> <transition state="step1"/> <transition state="step3"/> </state> <state id="step3"> <transition state="step2"/> <transition state="finish"/> </state> <state id="finish"> <transition state="step3"/> </state> </statemachine> |
1 |
<span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">Of course, this is a fairly simple application with three steps and a finish. This is typical of a straight forward procedure customers might need to go through to accomplish some task, such as creating an account on a site. These types of applications are generically known as wizards. Because the program is written in XML though, we can abstract this pattern:</span> |
1 2 3 4 5 6 7 8 9 10 11 |
<?xml-stylesheet file="/sys/xsm/wizard" type="xslt" ?> <statemachine xmlns:wiz="http://ns.gestinanna.org/xsm/xsl/wizard" > <wiz:steps> <wiz:step/> <wiz:step/> <wiz:step/> </wiz:steps> <state id="finish"/> </statemachine> |
1 |
<span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">XSLT is the language for transforming XML documents, so we can depend on XSLT to provide our macro language, as seen with the wizard example above.</span> |
But XSLT can't provide our business logic. That's where we get to the eXtensible part of XSM. By defining libraries of tags (taglibs), we can create the glue between our controllers and our business logic, application servers, databases, etc. The core of XSM is concerned with describing the general flow and structure of the application. The scripting and taglib extensions allow it to interact with the rest of the business system.
For more information on XSM, please look at the Gestinanna distribution on CPAN . This system is a work in progress, but with a little work can already run some simple applications. I'll write more in-depth about XSM and taglibs in another post.