Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Use Continuations to Develop Complex Web Applications

By Abhijit Belapurkar
2005-04-22


Web Continuations in Apache Cocoon

Apache Cocoon is a Web development framework that allows you to dynamically publish XML content using XSL transformations. Cocoon's support for different transformations means that you can easily present content in multiple formats. Cocoon uses a processing pipeline to describe the sequence of steps followed in handling a request and generating the corresponding response. Each pipeline describes a way of getting some input, followed by a series of processing steps to be performed on the data, and, finally, a mechanism of producing the output.

The individual components plugged in to form the pipeline are declared and wired together in what is called a sitemap. You can define multiple pipelines for a Web application and specify that different ones be called to to handle various requests based on request/environment parameters.

The components provided by Cocoon can be classified into a number of types:

• Generators and Readers are the pipeline's input components.
• Transformers and Actions are the processing components.
• Serializers are the output components.
• Matchers and Selectors handle conditional processing.

To be useful, a pipeline must clearly contain at least a generator, or reader, and a serializer. The number of processing steps in between will depend on the business logic of the application.

Cocoon and MVC
The above-described Cocoon architecture corresponds to MVC's Model 1 architecture in that it lacks a central controller that dispatches requests from the client tier and selects views. However, Cocoon also has provision for Model 2 architectures. In this case, the sitemap must contain an entry that specifies the controller, in addition to the regular pipeline entries. Like in any other Model 2 architecture, the controller directs the business logic that interacts with the application model. In this case, the pipeline concept is still used for handling the view, but is driven from the controller.

The first controller engine supported by Cocoon was based on a version of Rhino JavaScript from Mozilla, because this provided support for continuations as first-class objects. As you'll see in the following example, using Cocoon with the controller means you must write the entire application as a single JavaScript program and register it as the flow controller with the sitemap specified for your Cocoon application.

All of this is much easier to understand in code than in concept. The first thing I need to do is set up the sitemap for the shopping application. I'll then go on to take a look at how the application logic is implemented in JavaScript. Lastly, I'll take a look at the XML files underlying some of the pages of the application with a view to demonstrating a few important concepts.

About the development environment
The development environment for the example application is Cocoon V2.1.5.1 running on Apache Tomcat Server (V5.0.18) on a Windows XP workstation. I assume that you already have downloaded the Cocoon source code, built it, and deployed the Cocoon Web application generated into Tomcat. Therefore, the article source code is for the example application alone. See Resources if you need more download or setup information for Apache Cocoon.

Tutorial Pages:
» A Programming Paradigm to Simplify MVC for the Web
» What is a Continuation, Anyway?
» Problems in Conventional Web development
» The Case for Continuations
» User-Centered Navigation
» You Make the Rules!
» The Continuations Repository
» An Example Application
» Web Continuations in Apache Cocoon
» The Application Sitemap
» The Application Logic
» Understanding the Application Logic
» Resuming the Continuation
» JavaScript vs. the Java language
» Continuations in Java code
» Pros and Cons of Continuations
» Conclusion
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» All about JAXP, Part 1
» Make Database Queries Without the Database
» Load List Values for Improved Efficiency
» 2 Ways To Implement Session Tracking
» A Simple Way to Read an XML File in Java
» Develop Aspect-Oriented Java Applications with Eclipse and AJDT