CVS: Tapestry/framework/src/net/sf/tapestry/engine BaseEngine.java,NONE,1.1.2.1 RequestCycle.java,1.12.2.2,1.12.2.3 DirectService.java,1.7.2.1,1.7.2.2 ActionService.java,1.8.2.1,1.8.2.2 AbstractEngine.java,1.34.2.6,1.34.2.7 SimpleEngine.java,1.6,1.6.2.1 ResetService.java,1.6.2.1,1.6.2.2
Howard Lewis Ship <[email protected]>
| Newsgroups | gmane.comp.java.tapestry.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine
In directory sc8-pr-cvs1:/tmp/cvs-serv9155/framework/src/net/sf/tapestry/engine
Modified Files:
Tag: hship-2-3
RequestCycle.java DirectService.java ActionService.java
AbstractEngine.java SimpleEngine.java ResetService.java
Added Files:
Tag: hship-2-3
BaseEngine.java
Log Message:
Automatically register components as page listeners if they implement necessary interfaces
Major rework on page property persistance
[ 653358 ] IPage.getName() == qualified name
[ 608768 ] Changes saved AFTER IPage.detach()
--- NEW FILE: BaseEngine.java ---
package net.sf.tapestry.engine;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.*;
import net.sf.tapestry.ApplicationRuntimeException;
import net.sf.tapestry.IPageRecorder;
import net.sf.tapestry.IRequestCycle;
import net.sf.tapestry.Tapestry;
import net.sf.tapestry.record.SessionPageRecorder;
/**
* Concrete implementation of {@link net.sf.tapestry.IEngine} used for relatively
* small applications. All page state information is maintained in memory (transiently).
* Instances of {@link net.sf.tapestry.record.SimplePageRecorder} are used to
* maintain page state persistantly
* within the {@link javax.servlet.http.HttpSession}.
*
* @author Howard Lewis Ship
* @version $Id: BaseEngine.java,v 1.1.2.1 2002/12/30 03:04:56 hship Exp $
*
**/
public class BaseEngine extends AbstractEngine
{
private static final long serialVersionUID = -7051050643746333380L;
private final static int MAP_SIZE = 3;
private transient Map _recorders;
private transient Set _activePageNames;
/**
* Removes all page recorders that contain no changes, or
* are marked for discard. Subclasses
* should invoke this implementation in addition to providing
* thier own.
*
**/
protected void cleanupAfterRequest(IRequestCycle cycle)
{
if (Tapestry.isEmpty(_recorders))
return;
Iterator i = _recorders.entrySet().iterator();
while (i.hasNext())
{
Map.Entry entry = (Map.Entry) i.next();
String pageName = (String) entry.getKey();
IPageRecorder recorder = (IPageRecorder) entry.getValue();
if (!recorder.getHasChanges() || recorder.isMarkedForDiscard())
{
recorder.discard();
i.remove();
_activePageNames.remove(pageName);
}
}
}
public void forgetPage(String name)
{
if (_recorders == null)
return;
IPageRecorder recorder = (IPageRecorder) _recorders.get(name);
if (recorder == null)
return;
if (recorder.isDirty())
throw new ApplicationRuntimeException(
Tapestry.getString("BaseEngine.recorder-has-uncommited-changes", name));
recorder.discard();
_recorders.remove(name);
_activePageNames.remove(name);
}
/**
* Returns an unmodifiable {@link Collection} of the page names for which
* {@link IPageRecorder} instances exist.
*
*
**/
public Collection getActivePageNames()
{
if (_activePageNames == null)
return Collections.EMPTY_LIST;
return Collections.unmodifiableCollection(_activePageNames);
}
public IPageRecorder getPageRecorder(String pageName, IRequestCycle cycle)
{
if (_activePageNames == null || !_activePageNames.contains(pageName))
return null;
IPageRecorder result = null;
if (_recorders != null)
return result = (IPageRecorder) _recorders.get(pageName);
// So the page is active, but not in the cache of page recoders,
// so (re-)create the page recorder.
if (result == null)
result = createPageRecorder(pageName, cycle);
return result;
}
public IPageRecorder createPageRecorder(String pageName, IRequestCycle cycle)
{
if (_recorders == null)
_recorders = new HashMap(MAP_SIZE);
else
{
if (_recorders.containsKey(pageName))
throw new ApplicationRuntimeException(
Tapestry.getString("BaseEngine.duplicate-page-recorder", pageName));
}
// Force the creation of the HttpSession
cycle.getRequestContext().createSession();
setStateful();
IPageRecorder result = new SessionPageRecorder();
result.initialize(pageName, cycle);
_recorders.put(pageName, result);
if (_activePageNames == null)
_activePageNames = new HashSet();
_activePageNames.add(pageName);
return result;
}
/**
* Reconstructs the list of active page names
* written by {@link #writeExternal(ObjectOutput)}.
*
**/
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
super.readExternal(in);
int count = in.readInt();
if (count > 0)
_activePageNames = new HashSet(count);
for (int i = 0; i < count; i++)
{
String name = in.readUTF();
_activePageNames.add(name);
}
}
/**
* Writes the engine's persistent state; this is simply the list of active page
* names. For efficiency, this is written as a count followed by each name
* as a UTF String.
*
**/
public void writeExternal(ObjectOutput out) throws IOException
{
super.writeExternal(out);
if (Tapestry.isEmpty(_activePageNames))
{
out.writeInt(0);
return;
}
int count = _activePageNames.size();
out.writeInt(count);
Iterator i = _activePageNames.iterator();
while (i.hasNext())
{
String name = (String) i.next();
out.writeUTF(name);
}
}
}
Index: RequestCycle.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/RequestCycle.java,v
retrieving revision 1.12.2.2
retrieving revision 1.12.2.3
diff -C2 -d -r1.12.2.2 -r1.12.2.3
*** RequestCycle.java 16 Dec 2002 12:56:35 -0000 1.12.2.2
--- RequestCycle.java 30 Dec 2002 03:04:56 -0000 1.12.2.3
***************
*** 255,261 ****
/**
* Returns the page recorder for the named page. This may come
! * form the cycle's cache of page recorders or, if not yet encountered
! * in this request cycle, the {@link IEngine#getPageRecorder(String)} is
* invoked to get the recorder, if it exists.
**/
--- 255,262 ----
/**
* Returns the page recorder for the named page. This may come
! * from the cycle's cache of page recorders or, if not yet encountered
! * in this request cycle, the {@link IEngine#getPageRecorder(String, IRequestCycle)} is
* invoked to get the recorder, if it exists.
+ *
**/
***************
*** 270,274 ****
return result;
! result = _engine.getPageRecorder(name);
if (result == null)
--- 271,275 ----
return result;
! result = _engine.getPageRecorder(name, this);
if (result == null)
***************
*** 361,365 ****
public void renderPage(IMarkupWriter writer) throws RequestCycleException
{
! String pageName = _page.getName();
_monitor.pageRenderBegin(pageName);
--- 362,366 ----
public void renderPage(IMarkupWriter writer) throws RequestCycleException
{
! String pageName = _page.getPageName();
_monitor.pageRenderBegin(pageName);
***************
*** 424,428 ****
{
IPage page = form.getPage();
! String pageName = page.getName();
_monitor.pageRewindBegin(pageName);
--- 425,429 ----
{
IPage page = form.getPage();
! String pageName = page.getPageName();
_monitor.pageRewindBegin(pageName);
***************
*** 499,503 ****
public void rewindPage(String targetActionId, IComponent targetComponent) throws RequestCycleException
{
! String pageName = _page.getName();
_monitor.pageRewindBegin(pageName);
--- 500,504 ----
public void rewindPage(String targetActionId, IComponent targetComponent) throws RequestCycleException
{
! String pageName = _page.getPageName();
_monitor.pageRewindBegin(pageName);
***************
*** 619,623 ****
{
IPage page = event.getComponent().getPage();
! String pageName = page.getName();
if (LOG.isDebugEnabled())
--- 620,624 ----
{
IPage page = event.getComponent().getPage();
! String pageName = page.getPageName();
if (LOG.isDebugEnabled())
***************
*** 649,657 ****
LOG.debug("Discarding page " + name);
! IPageRecorder recorder = _engine.getPageRecorder(name);
if (recorder == null)
{
-
_page = getPage(name);
--- 650,657 ----
LOG.debug("Discarding page " + name);
! IPageRecorder recorder = _engine.getPageRecorder(name, this);
if (recorder == null)
{
_page = getPage(name);
Index: DirectService.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/DirectService.java,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -C2 -d -r1.7.2.1 -r1.7.2.2
*** DirectService.java 19 Dec 2002 12:27:00 -0000 1.7.2.1
--- DirectService.java 30 Dec 2002 03:04:56 -0000 1.7.2.2
***************
*** 73,79 ****
if (complex)
! context[i++] = renderPage.getName();
! context[i++] = componentPage.getName();
context[i++] = component.getIdPath();
--- 73,79 ----
if (complex)
! context[i++] = renderPage.getPageName();
! context[i++] = componentPage.getPageName();
context[i++] = component.getIdPath();
Index: ActionService.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/ActionService.java,v
retrieving revision 1.8.2.1
retrieving revision 1.8.2.2
diff -C2 -d -r1.8.2.1 -r1.8.2.2
*** ActionService.java 19 Dec 2002 12:27:00 -0000 1.8.2.1
--- ActionService.java 30 Dec 2002 03:04:56 -0000 1.8.2.2
***************
*** 63,67 ****
serviceContext[i++] = stateful;
! serviceContext[i++] = responsePage.getName();
serviceContext[i++] = (String) parameters[0];
--- 63,67 ----
serviceContext[i++] = stateful;
! serviceContext[i++] = responsePage.getPageName();
serviceContext[i++] = (String) parameters[0];
***************
*** 71,75 ****
if (complex)
! serviceContext[i++] = componentPage.getName();
serviceContext[i++] = component.getIdPath();
--- 71,75 ----
if (complex)
! serviceContext[i++] = componentPage.getPageName();
serviceContext[i++] = component.getIdPath();
Index: AbstractEngine.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/AbstractEngine.java,v
retrieving revision 1.34.2.6
retrieving revision 1.34.2.7
diff -C2 -d -r1.34.2.6 -r1.34.2.7
*** AbstractEngine.java 21 Dec 2002 13:05:46 -0000 1.34.2.6
--- AbstractEngine.java 30 Dec 2002 03:04:56 -0000 1.34.2.7
***************
*** 86,90 ****
* can be restored inside {@link #setupForRequest(RequestContext)}.
*
! * <p>In practice, a subclass (usually {@link SimpleEngine})
* is used without subclassing. Instead, a
* visit object is specified. To facilitate this, the application specification
--- 86,90 ----
* can be restored inside {@link #setupForRequest(RequestContext)}.
*
! * <p>In practice, a subclass (usually {@link BaseEngine})
* is used without subclassing. Instead, a
* visit object is specified. To facilitate this, the application specification
***************
*** 1336,1340 ****
{
IPage page = source.getPage(fakeCycle, name, null);
! IPageRecorder recorder = getPageRecorder(name);
recorder.rollback(page);
--- 1336,1340 ----
{
IPage page = source.getPage(fakeCycle, name, null);
! IPageRecorder recorder = getPageRecorder(name, fakeCycle);
recorder.rollback(page);
Index: SimpleEngine.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/SimpleEngine.java,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -C2 -d -r1.6 -r1.6.2.1
*** SimpleEngine.java 27 Nov 2002 17:58:51 -0000 1.6
--- SimpleEngine.java 30 Dec 2002 03:04:56 -0000 1.6.2.1
***************
*** 1,216 ****
package net.sf.tapestry.engine;
- import java.io.IOException;
- import java.io.ObjectInput;
- import java.io.ObjectOutput;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
-
- import net.sf.tapestry.ApplicationRuntimeException;
- import net.sf.tapestry.IPageRecorder;
- import net.sf.tapestry.IRequestCycle;
- import net.sf.tapestry.Tapestry;
- import net.sf.tapestry.record.SimplePageRecorder;
-
/**
! * Concrete implementation of {@link net.sf.tapestry.IEngine} used for relatively
! * small applications. All page state information is maintained in memory. Since
! * the instance is stored within the {@link javax.servlet.http.HttpSession},
! * all page state information
! * will be carried along to other servers in the cluster.
! *
* @author Howard Lewis Ship
* @version $Id$
! *
**/
! public class SimpleEngine extends AbstractEngine
{
- /**
- * @since 2.0.4
- *
- **/
-
- private static final long serialVersionUID = -1658741363570905534L;
-
- private final static int MAP_SIZE = 3;
-
- private Map recorders;
-
- /**
- * Restores the object state as written by
- * {@link #writeExternal(ObjectOutput)}.
- *
- **/
-
- public void readExternal(ObjectInput in)
- throws IOException, ClassNotFoundException
- {
- int i, count;
- String pageName;
- SimplePageRecorder recorder;
-
- super.readExternal(in);
-
- count = in.readInt();
-
- if (count == 0)
- return;
-
- recorders = new HashMap(MAP_SIZE);
-
- for (i = 0; i < count; i++)
- {
- pageName = in.readUTF();
-
- // Putting a cast here is not super-efficient, but keeps
- // us sane!
-
- recorder = (SimplePageRecorder) in.readObject();
-
- recorders.put(pageName, recorder);
- }
- }
-
- /**
- * Invokes the superclass implementation, then
- * writes the number of recorders as an int (may be zero).
- *
- * <p>For each recorder, writes
- * <ul>
- * <li>page name ({@link String})
- * <li>page recorder ({@link SimplePageRecorder})
- * </ul>
- *
- **/
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- Iterator i;
- Map.Entry entry;
-
- super.writeExternal(out);
-
- if (recorders == null)
- {
- out.writeInt(0);
- return;
- }
-
- out.writeInt(recorders.size());
-
- i = recorders.entrySet().iterator();
-
- while (i.hasNext())
- {
- entry = (Map.Entry) i.next();
-
- out.writeUTF((String) entry.getKey());
- out.writeObject(entry.getValue());
- }
-
- }
-
- /**
- * Removes all page recorders that contain no changes, or
- * are marked for discard. Subclasses
- * should invoke this implementation in addition to providing
- * thier own.
- *
- **/
-
- protected void cleanupAfterRequest(IRequestCycle cycle)
- {
- Iterator i;
- Map.Entry entry;
- IPageRecorder recorder;
-
- if (recorders == null)
- return;
-
- i = recorders.entrySet().iterator();
-
- while (i.hasNext())
- {
- entry = (Map.Entry) i.next();
- recorder = (IPageRecorder) entry.getValue();
-
- if (!recorder.getHasChanges() || recorder.isMarkedForDiscard())
- i.remove();
- }
- }
-
- public void forgetPage(String name)
- {
- IPageRecorder recorder;
-
- if (recorders == null)
- return;
-
- recorder = (IPageRecorder) recorders.get(name);
- if (recorder == null)
- return;
-
- if (recorder.isDirty())
- throw new ApplicationRuntimeException(
- Tapestry.getString("SimpleEngine.recorder-has-uncommited-changes", name));
-
- recorders.remove(name);
- }
! /**
! * Returns an unmodifiable {@link Collection} of the page names for which
! * {@link IPageRecorder} instances exist.
! *
! **/
!
! public Collection getActivePageNames()
! {
! if (recorders == null)
! return Collections.EMPTY_LIST;
!
! return Collections.unmodifiableCollection(recorders.keySet());
! }
!
! public IPageRecorder getPageRecorder(String pageName)
! {
! if (recorders == null)
! return null;
!
! return (IPageRecorder) recorders.get(pageName);
! }
!
! public IPageRecorder createPageRecorder(String pageName, IRequestCycle cycle)
! {
! IPageRecorder result;
!
! if (recorders == null)
! recorders = new HashMap(MAP_SIZE);
! else
! {
! if (recorders.containsKey(pageName))
! throw new ApplicationRuntimeException(
! Tapestry.getString("SimpleEngine.duplicate-page-recorder", pageName));
! }
!
! // Here's the key thing that identifies SimpleApplication as simple.
! // It uses a SimplePageRecorder (that simply stores the page property changes
! // in the HttpSession).
!
! result = new SimplePageRecorder();
!
! recorders.put(pageName, result);
!
! // Force the creation of the HttpSession
!
! cycle.getRequestContext().createSession();
!
! setStateful();
!
! return result;
! }
!
! }
\ No newline at end of file
--- 1,18 ----
package net.sf.tapestry.engine;
/**
! * Placeholder used for backwards compatibility. Use or subclass
! * {@link net.sf.tapestry.engine.BaseEngine} instead.
! *
! * @deprecated To be removed after release 2.4, use
! * {@link net.sf.tapestry.engine.BaseEngine} instead.
! *
* @author Howard Lewis Ship
* @version $Id$
! *
**/
! public class SimpleEngine extends BaseEngine
{
! }
Index: ResetService.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/ResetService.java,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -C2 -d -r1.6.2.1 -r1.6.2.2
*** ResetService.java 12 Dec 2002 12:42:39 -0000 1.6.2.1
--- ResetService.java 30 Dec 2002 03:04:56 -0000 1.6.2.2
***************
*** 38,42 ****
String[] context = new String[1];
! context[0] = component.getPage().getName();
return assembleGesture(cycle, RESET_SERVICE, context, null, true);
--- 38,42 ----
String[] context = new String[1];
! context[0] = component.getPage().getPageName();
return assembleGesture(cycle, RESET_SERVICE, context, null, true);
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf