org.apache.wicket.core.request.handler
Class PageProvider

java.lang.Object
  extended by org.apache.wicket.core.request.handler.PageProvider
All Implemented Interfaces:
IPageProvider
Direct Known Subclasses:
PageAndComponentProvider

public class PageProvider
extends Object
implements IPageProvider

Provides page instance for request handlers. Each of the constructors has just enough information to get existing or create new page instance. Requesting or creating page instance is deferred until getPageInstance() is called.

Purpose of this class is to reduce complexity of both IRequestMappers and IRequestHandlers. IRequestMapper examines the URL, gathers all relevant information about the page in the URL (combination of page id, page class, page parameters and render count), creates PageProvider object and creates a IRequestHandler instance that can use the PageProvider to access the page.

Apart from simplifying IRequestMappers and IRequestHandlers PageProvider also helps performance because creating or obtaining page from IPageManager is delayed until the IRequestHandler actually requires the page.

Author:
Matej Knopp

Constructor Summary
PageProvider(Class<? extends IRequestablePage> pageClass)
          Creates a new page provider object.
PageProvider(Class<? extends IRequestablePage> pageClass, PageParameters pageParameters)
          Creates a new page provider object.
PageProvider(Integer pageId, Class<? extends IRequestablePage> pageClass, Integer renderCount)
          Creates a new page provider object.
PageProvider(Integer pageId, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, Integer renderCount)
          Creates a new page provider object.
PageProvider(Integer pageId, Integer renderCount)
          Creates a new page provider object.
PageProvider(IRequestablePage page)
          Creates a new page provider object.
 
Method Summary
 void detach()
          Detaches the page if it has been loaded (that means either PageProvider(IRequestablePage) constructor has been used or getPageInstance() has been called).
 Class<? extends IRequestablePage> getPageClass()
          Returns class of the page.
 Integer getPageId()
          Returns the page id.
 IRequestablePage getPageInstance()
          Returns page instance specified by the constructor.
 PageParameters getPageParameters()
          Returns PageParameters of the page.
protected  IPageSource getPageSource()
           
 Integer getRenderCount()
          Returns the number of times this page has been rendered.
 boolean hasPageInstance()
          Checks whether or not the provider has a page instance.
 boolean isNewPageInstance()
          The page instance is new only if there is no cached instance or the data stores doesn't have a page with that id with the same pageClass.
 boolean isPageInstanceFresh()
          Returns whether or not the page instance held by this provider has been instantiated by the provider.
protected  void setPageParameters(PageParameters pageParameters)
           
 void setPageSource(IPageSource pageSource)
          If the PageProvider is used outside request thread (thread that does not have application instance assigned) it is necessary to specify a IPageSource instance so that PageProvider knows how to get a page instance.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PageProvider

public PageProvider(Integer pageId,
                    Integer renderCount)
Creates a new page provider object. Upon calling of getPageInstance() this provider will return page instance with specified id.

Parameters:
pageId -
renderCount - optional argument

PageProvider

public PageProvider(Integer pageId,
                    Class<? extends IRequestablePage> pageClass,
                    Integer renderCount)
Creates a new page provider object. Upon calling of getPageInstance() this provider will return page instance with specified id if it exists and it's class matches pageClass. If none of these is true new page instance will be created.

Parameters:
pageId -
pageClass -
renderCount - optional argument

PageProvider

public PageProvider(Integer pageId,
                    Class<? extends IRequestablePage> pageClass,
                    PageParameters pageParameters,
                    Integer renderCount)
Creates a new page provider object. Upon calling of getPageInstance() this provider will return page instance with specified id if it exists and it's class matches pageClass. If none of these is true new page instance will be created.

Parameters:
pageId -
pageClass -
pageParameters -
renderCount - optional argument

PageProvider

public PageProvider(Class<? extends IRequestablePage> pageClass,
                    PageParameters pageParameters)
Creates a new page provider object. Upon calling of getPageInstance() this provider will return new instance of page with specified class.

Parameters:
pageClass -
pageParameters -

PageProvider

public PageProvider(Class<? extends IRequestablePage> pageClass)
Creates a new page provider object. Upon calling of getPageInstance() this provider will return new instance of page with specified class.

Parameters:
pageClass -

PageProvider

public PageProvider(IRequestablePage page)
Creates a new page provider object. Upon calling of getPageInstance() this provider will return the given page instance.

Parameters:
page -
Method Detail

getPageInstance

public IRequestablePage getPageInstance()
Description copied from interface: IPageProvider
Returns page instance specified by the constructor.

Specified by:
getPageInstance in interface IPageProvider
Returns:
page instance
See Also:
IPageProvider.getPageInstance()

getPageParameters

public PageParameters getPageParameters()
Description copied from interface: IPageProvider
Returns PageParameters of the page.

Specified by:
getPageParameters in interface IPageProvider
Returns:
page parameters
See Also:
IPageProvider.getPageParameters()

isNewPageInstance

public boolean isNewPageInstance()
The page instance is new only if there is no cached instance or the data stores doesn't have a page with that id with the same pageClass.

Specified by:
isNewPageInstance in interface IPageProvider
Returns:
true if calling IPageProvider.getPageInstance() will create new page instance, false otherwise.
See Also:
IPageProvider.isNewPageInstance()

getPageClass

public Class<? extends IRequestablePage> getPageClass()
Description copied from interface: IPageProvider
Returns class of the page.

Specified by:
getPageClass in interface IPageProvider
Returns:
page class
See Also:
IPageProvider.getPageClass()

getPageSource

protected IPageSource getPageSource()

detach

public void detach()
Detaches the page if it has been loaded (that means either PageProvider(IRequestablePage) constructor has been used or getPageInstance() has been called).

Specified by:
detach in interface IPageProvider

setPageSource

public void setPageSource(IPageSource pageSource)
If the PageProvider is used outside request thread (thread that does not have application instance assigned) it is necessary to specify a IPageSource instance so that PageProvider knows how to get a page instance.

Parameters:
pageSource -

setPageParameters

protected void setPageParameters(PageParameters pageParameters)
Parameters:
pageParameters -

getPageId

public Integer getPageId()
Description copied from interface: IPageProvider
Returns the page id.

Specified by:
getPageId in interface IPageProvider
Returns:
page id

getRenderCount

public Integer getRenderCount()
Description copied from interface: IPageProvider
Returns the number of times this page has been rendered.

Specified by:
getRenderCount in interface IPageProvider
Returns:
the number of times this page has been rendered.

hasPageInstance

public final boolean hasPageInstance()
Checks whether or not the provider has a page instance. This page instance might have been passed to this page provider directly or it may have been instantiated or retrieved from the page store.

Specified by:
hasPageInstance in interface IPageProvider
Returns:
true iff page instance has been created or retrieved

isPageInstanceFresh

public final boolean isPageInstanceFresh()
Returns whether or not the page instance held by this provider has been instantiated by the provider.

Specified by:
isPageInstanceFresh in interface IPageProvider
Returns:
true iff the page instance held by this provider was instantiated by the provider
Throws:
IllegalStateException - if this method is called and the provider does not yet have a page instance, ie if getPageInstance() has never been called on this provider

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.