com.primix.tapestry.pageload
Class PageSource

java.lang.Object
  |
  +--com.primix.tapestry.pageload.PageSource
All Implemented Interfaces:
IPageSource, IRenderDescription

public class PageSource
extends java.lang.Object
implements IPageSource, IRenderDescription

A source for pages for a particular application. Each application should have its own PageSource, storing it into the ServletContext using a unique key (usually built from the application name).

The PageSource acts as a pool for IPage instances. Pages are retrieved from the pool using getPage(IEngine, String, IMonitor) and are later returned to the pool using releasePage(IPage).

In addition, this class acts as a cache of serveral common objects:

This caching allows common objects to be created once, and used across all components and pages. Without pooling, objects would often be duplicated.

TBD: Pooled pages stay forever. Need a strategy for cleaning up the pool, tracking which pages have been in the pool the longest, etc. A mechanism for reporting pool statistics would be useful.

Version:
$Id: PageSource.java,v 1.20 2001/09/11 21:41:12 hship Exp $
Author:
Howard Ship

Constructor Summary
PageSource(IResourceResolver resolver)
           
 
Method Summary
protected  MultiKey buildKey(IEngine engine, java.lang.String pageName)
          Builds a key for a named page in the application's current locale.
protected  MultiKey buildKey(IPage page)
          Builds a key from an existing page, using the page's name and locale.
 IAsset getContextAsset(java.lang.String assetPath)
          Gets a cached asset.
 IAsset getExternalAsset(java.lang.String URL)
          Gets a cached asset.
 IBinding getFieldBinding(java.lang.String fieldName)
          Gets a field binding for the named field (the name includes the class name and the field).
 IPage getPage(IEngine engine, java.lang.String pageName, IMonitor monitor)
          Gets the page from a pool, or otherwise loads the page.
 IAsset getPrivateAsset(java.lang.String resourcePath)
          Gets a cached asset.
 IResourceResolver getResourceResolver()
           
 IBinding getStaticBinding(java.lang.String value)
          Like getFieldBinding(String), except for StaticBindings.
 void releasePage(IPage page)
          Returns the page to the appropriate pool.
 void renderDescription(IResponseWriter writer)
          Object should render a description of itself to the writer.
 void reset()
          Invoked (during testing primarily) to release the entire pool of pages, and the caches of bindings and assets.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PageSource

public PageSource(IResourceResolver resolver)
Method Detail

getResourceResolver

public IResourceResolver getResourceResolver()

buildKey

protected MultiKey buildKey(IEngine engine,
                            java.lang.String pageName)
Builds a key for a named page in the application's current locale.

buildKey

protected MultiKey buildKey(IPage page)
Builds a key from an existing page, using the page's name and locale. This is used when storing a page into the pool.

getPage

public IPage getPage(IEngine engine,
                     java.lang.String pageName,
                     IMonitor monitor)
              throws PageLoaderException
Gets the page from a pool, or otherwise loads the page. This operation is threadsafe ... it synchronizes on the pool of pages.
Specified by:
getPage in interface IPageSource

releasePage

public void releasePage(IPage page)
Returns the page to the appropriate pool.
Specified by:
releasePage in interface IPageSource

reset

public void reset()
Invoked (during testing primarily) to release the entire pool of pages, and the caches of bindings and assets.
Specified by:
reset in interface IPageSource

getFieldBinding

public IBinding getFieldBinding(java.lang.String fieldName)
Gets a field binding for the named field (the name includes the class name and the field). If no such binding exists, then one is created, otherwise the existing binding is returned.
Specified by:
getFieldBinding in interface IPageSource

getStaticBinding

public IBinding getStaticBinding(java.lang.String value)
Like getFieldBinding(String), except for StaticBindings.
Specified by:
getStaticBinding in interface IPageSource

getExternalAsset

public IAsset getExternalAsset(java.lang.String URL)
Description copied from interface: IPageSource
Gets a cached asset.
Specified by:
getExternalAsset in interface IPageSource

getContextAsset

public IAsset getContextAsset(java.lang.String assetPath)
Description copied from interface: IPageSource
Gets a cached asset.
Specified by:
getContextAsset in interface IPageSource

getPrivateAsset

public IAsset getPrivateAsset(java.lang.String resourcePath)
Description copied from interface: IPageSource
Gets a cached asset.
Specified by:
getPrivateAsset in interface IPageSource

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

renderDescription

public void renderDescription(IResponseWriter writer)
Description copied from interface: IRenderDescription
Object should render a description of itself to the writer.
Specified by:
renderDescription in interface IRenderDescription
Since:
1.0.6