ovidiu 02/03/21 15:19:04
Added: src/scratchpad/schecoon/src/org/apache/cocoon/components/flow
WebContinuation.java
Log:
Added. Maintains a continuation in a scripting language, and the
tree structure created by continuations in the running Web application.
Revision Changes Path
1.1
xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/WebContinuation.java
Index: WebContinuation.java
===================================================================
package org.apache.cocoon.components.flow;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of continuations in a Web environment.
*
* <p>Because a user may click on the back button of the browser and
* restart a saved computation in a continuation, each
* <code>WebContinuation</code> becomes the parent of a subtree of
* continuations.
*
* <p>If there is no parent <code>WebContinuation</code>, the created
* continuation becomes the root of a tree of
* <code>WebContinuation</code>s.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
* @since March 19, 2002
*/
public class WebContinuation
{
/**
* The continuation this object represents.
*/
Object continuation;
/**
* The parent <code>WebContinuation</code> from which processing
* last started. If null, there is no parent continuation
* associated, and this is the first one to be created in a
* processing. In this case this <code>WebContinuation</code>
* instance becomes the root of the tree maintained by the
* <code>ContinuationsManager</code>.
*
* @see ContinuationsManager
*/
WebContinuation parentContinuation;
/**
* The children continuations. These are continuations created by
* resuming the processing from the point stored by
* <code>continuation</code>.
*/
List children = new ArrayList();
/**
* The continuation id used to represent this instance in Web pages.
*/
String id;
/**
* A user definable object. This is present for convenience, to
* store any information associated with this
* <code>WebContinuation</code> a particular implementation might
* need.
*/
Object userObject;
/**
* Create a <code>WebContinuation</code> object. Saves the object in
* the hash table of continuations maintained by
* <code>manager</code> (this is done as a side effect of obtaining
* and identifier from it).
*
* @param continuation an <code>Object</code> value
* @param parentContinuation a <code>WebContinuation</code> value
* @param manager a <code>ContinuationsManagerImpl</code> value
*/
public WebContinuation(Object continuation,
WebContinuation parentContinuation,
ContinuationsManagerImpl manager)
{
this.continuation = continuation;
this.parentContinuation = parentContinuation;
id = manager.generateContinuationId(this);
}
/**
* Return the continuation object.
*
* @return an <code>Object</code> value
*/
public Object getContinuation()
{
return continuation;
}
/**
* Return the parent <code>WebContinuation</code>.
*
* @return a <code>WebContinuation</code> value
*/
public WebContinuation getParentContinuation()
{
return parentContinuation;
}
/**
* Return the children <code>WebContinuation</code> which were
* created as a result of resuming the processing from the current
* <code>continuation</code>.
*
* @return a <code>List</code> value
*/
public List getChildren()
{
return children;
}
/**
* Returns the string identifier of this
* <code>WebContinuation</code>.
*
* @return a <code>String</code> value
*/
public String getId()
{
return id;
}
/**
* Sets the user object associated with this instance.
*
* @param obj an <code>Object</code> value
*/
public void setUserObject(Object obj)
{
this.userObject = obj;
}
/**
* Obtains the user object associated with this instance.
*
* @return an <code>Object</code> value
*/
public Object getUserObject()
{
return userObject;
}
/**
* Returns the hash code of the associated identifier.
*
* @return an <code>int</code> value
*/
public int hashCode()
{
return id.hashCode();
}
/**
* True if the identifiers are the same, false otherwise.
*
* @param another an <code>Object</code> value
* @return a <code>boolean</code> value
*/
public boolean equals(Object another)
{
if (another instanceof WebContinuation)
return id.equals(((WebContinuation)another).id);
return false;
}
/**
* Debugging method.
*
* <p>Assumes the receiving instance as the root of a tree and
* displays the tree of continuations.
*/
public void display()
{
display(0);
}
/**
* Debugging method.
*
* <p>Displays the receiving instance as if it is at the
* <code>indent</code> depth in the tree of continuations. Each
* level is indented 2 spaces.
*
* @param depth an <code>int</code> value
*/
protected void display(int depth)
{
StringBuffer buf = new StringBuffer();
for (int i = 0; i < depth; i++)
buf.append(" ");
String spaces = buf.toString();
System.out.print(spaces); System.out.println("WebContinuation " + id);
int size = children.size();
depth++;
for (int i = 0; i < size; i++)
((WebContinuation)children.get(i)).display(depth);
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]