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
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to