cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maciek Kaminski" <macie...@tiger.com.pl>
Subject Re: [Schecoon] flow control layer
Date Wed, 27 Feb 2002 11:06:39 GMT
On 26 Feb 2002 at 19:46, Ovidiu Predescu wrote:

> On Tue, 26 Feb 2002 19:07:20 +0300, "Piroumian, Konstantin"
> > ...
> > Yes, that's true. We've been using actions to interact with the flow
> > controller. So, why do we need another language to describe the flow? Why not
> > Java?
> 
> Because Java doesn't have support for continuations.
> 

Actually, it is possible to program flow directly in Java using 
Continuation Passing Style. 

Having continuation interface:

public interface Continuation {
    public Continuation continue(
        PageSender sender, Map objectModel, SourceResolver resolver, URLEncoder 
encoder)
        throws ProcessingException, SAXException, IOException;
}

and engine that maps continuation ids to continuation objects, one can express 
flow as:

public class GuessFlow implements Continuation {
    protected Continuation continue(
        PageSender sender, Map objectModel, SourceResolver resolver)
        throws ProcessingException, SAXException, IOException
    {
        final int secret = 678;

        sender.sendPage("guessNumberForm.xml")

        return new Continuation() {
            public Continuation continue(
                PageSender sender, Map objectModel, SourceResolver resolver)
                throws ProcessingException, SAXException, IOException
            {
                int guess = 
                    Integer.parseInt(
                        ((Request) objectModel.get(Constants.REQUEST_OBJECT))
                        .getParameter("guess"));

                while(secret!=guess) {                    
                    if(secret>guess)
                        sender.sendPage("guessGreaterNumberForm.xml");
                    else
                        sender.sendPage("guessLowerNumberForm.xml");
                    return this;
                }

                sender.sendPage("ok.xml")
                return null;
            }
        };
    }
}

Hope example is self-explaining.

While flow written this way is not as elegant as flow written in scheme, it may 
be implemented in pure java.

Maciek Kaminski
maciejka@tiger.com.pl


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message