Jeff, Enclosed is a diff for the CommandFactory which is the only code I change. I'll zip up the two auxiliary files and example app and send them as an attachment. Once the patch below has been applied simply unzip the archive on top of your Maverick directory to put the additional classes and example app in the correct place in your source tree.
Note that the example is very simple (a single page) and though it demonstrates that the code works, it does not demonstrate its usefulness. The example could easily have been written as a single controller. I have been trying to think of a compelling use-case for you that is also simple enough for an example application, but not come up with anything so far. Interestingly enough this whole concept of controller chaining came up in a meeting here yesterday. Another development group here was describing a homespun MVC framework they wrote after finding that their app was complex enough that they needed controller chaining to simplify the app eliminate duplicated code. Consider that a typical Maverick controller is responsible for the doing following: 1. translate parameters passed in the Request into a useable data structure 2. perform business logic given the request inputs 3. make a view decision on the basis of the request & outcome of business logic 4. prepare a model appropriate for the view rendered I may have several controllers that have different code for these first three functions, but that the fourth is duplicated across several controllers. Rather than loop back through the dispatcher, controller chaining allows application flow to immediately pass to the model-creator controller. On the other hand, several controllers may have the same business logic, but different criteria for selecting the view. Using a chaining approach allows us to easily mix and match this functionality for a single command. Perhaps more compelling is when the business logic in a controller is complex and involves multiple steps some which may be shared by other business processes. Handling this with additional layers of inheritance can become very tricky--particularly when we want one process to borrow steps from two other processes. Controller chaining provides an easy way to break up a process and reuse particular pieces of it in other processes. I'll keep thinking and perhaps I can come up with compelling example that is simple enough for an example app. Thanks for looking at this! John-Mason Shackelford Software Developer Pearson Educational Measurement - eMeasurement Group 2510 North Dodge St. Iowa City, IA 52245 ph. 319-354-9200x6214 [EMAIL PROTECTED] http://etest.ncspearson.com cvs server: Diffing . Index: CommandFactory.java =================================================================== RCS file: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/flow/CommandFactory.j ava,v retrieving revision 1.5 diff -u -r1.5 CommandFactory.java --- CommandFactory.java 6 Jun 2002 12:23:53 -0000 1.5 +++ CommandFactory.java 13 Feb 2003 17:06:28 -0000 @@ -4,6 +4,7 @@ */ package org.infohazard.maverick.flow; +import java.util.List; import java.util.Map; import javax.servlet.ServletConfig; import org.jdom.Element; @@ -24,6 +25,9 @@ /** */ protected final static String TAG_CONTROLLER = "controller"; + /** */ + protected final static String TAG_PIPELINE = "pipeline"; + /** */ protected ViewRegistry viewReg; @@ -47,9 +51,16 @@ */ public Command createCommand(Element commandNode) throws ConfigException { - Controller ctl = this.controllerFact.createController(commandNode.getChild(TAG_CONTROLLER)); - - Map viewsMap = this.viewReg.createViewsMap(commandNode.getChildren(TAG_VIEW)); + Map viewsMap = + this.viewReg.createViewsMap(commandNode.getChildren(TAG_VIEW)); + + // if we have a pipeline child element, use an appropriate Command object + Element pipeline = commandNode.getChild(TAG_PIPELINE); + if(pipeline != null) { + return new CommandPipeline(pipeline, viewsMap); + } + + Controller ctl = this.controllerFact.createController(commandNode.getChild(TAG_CONTROLLER)); + if (viewsMap.size() > 1) return new CommandMultipleViews(ctl, viewsMap); else @@ -60,5 +71,7 @@ return new CommandSingleView(ctl, theView); } } + + } **************************************************************************** This email may contain confidential material. If you were not an intended recipient, Please notify the sender and delete all copies. We may monitor email to and from our network. ****************************************************************************
Maverick.zip
Description: Binary data