cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <lgaw...@mobilebox.pl>
Subject Re: ApplesProcessor - a little crazy idea
Date Thu, 13 Oct 2005 16:02:03 GMT
Mark Lundquist wrote:
> 
> On Oct 13, 2005, at 8:42 AM, Sylvain Wallez wrote:
> 
>> I never used Apples, but it looks like some people (and not only their 
>> original creators) are using it.
> 
> 
> I never really did "get" Apples.  Can somebody just sort of give a quick 
> summary of what it's all about, and why I would want to use it?
The quickest summary from apples lamer:

Apples is:
   - a flow interpreter
   - a front controller that allows you to code in java (no scripting!). 
I think a it can be compared to struts controller a little but.
   - it has continuations but they do not suspend apple execution. See 
an example from our codebase:

> public class HanoiApple extends AbstractLogEnabled implements AppleController {
>     // full state of the puzzle is in the following variables
>     public Stack[] stacks;
>     public Object floatingDisk = null;
>     public int moves = 0;
>     public int puzzleSize  = 0;
> 
> 
>     public void process(AppleRequest req, AppleResponse res) throws ProcessingException
{
> 
>         // processing
>         if (stacks == null) {
>             String requestSize = req.getCocoonRequest().getParameter("size");
>             if (requestSize != null) {
>                 try {
>                     int size = Integer.parseInt(requestSize);
>                     intializeStacks(size);
>                 } catch (NumberFormatException ignore) {
>                 }
>             }
>         } else {
>             // decide selected column
>             String requestStack = req.getCocoonRequest().getParameter("stack");
>             if (requestStack != null) {
>                 // do something here
>             }
>         }
> 
>         //view generation
>         if (stacks == null) {
>             res.sendPage("hanoi/intro.jx", null);
>         } else {
>             Map bizdata = new HashMap();
>             bizdata.put("stacks"      , this.stacks);
>             bizdata.put("moves"       , "" + this.moves);
>             bizdata.put("floatingDisk", this.floatingDisk);
>             bizdata.put("nextMove"    , this.floatingDisk==null ? "Lift it!" : "Drop
it!");
>             bizdata.put("puzzleSize"  , "" + this.puzzleSize);
> 
>             res.sendPage("hanoi/hanoi.jx", bizdata);
>         }
> 
>     }
> }

First time the apple is invoked it is created from scratch. Later on if 
continuation is being called the apple object is retrieved from 
continuation and apple.process( req, res ) is called again on the same 
object. You have to maintain view flow yourself. You do not have to 
store data in session but have it isolated in single apple.




-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Mime
View raw message