org.apache.wicket.request.handler
Class PageProvider

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

public class PageProvider
extends java.lang.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(java.lang.Class<? extends IRequestablePage> pageClass)
          Creates a new page provider object.
PageProvider(java.lang.Class<? extends IRequestablePage> pageClass, PageParameters pageParameters)
          Creates a new page provider object.
PageProvider(int pageId, java.lang.Class<? extends IRequestablePage> pageClass, java.lang.Integer renderCount)
          Creates a new page provider object.
PageProvider(int pageId, java.lang.Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, java.lang.Integer renderCount)
          Creates a new page provider object.
PageProvider(int pageId, java.lang.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).
 java.lang.Class<? extends IRequestablePage> getPageClass()
          Returns class of the page.
 java.lang.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()
           
 java.lang.Integer getRenderCount()
          Returns the number of times this page has been rendered.
 boolean isNewPageInstance()
          Returns whether calling getPageInstance() will result in creating new page instance or whether it will be an existing instance (even though it might be pulled from page store).
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageProvider

public PageProvider(int pageId,
                    java.lang.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(int pageId,
                    java.lang.Class<? extends IRequestablePage> pageClass,
                    java.lang.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(int pageId,
                    java.lang.Class<? extends IRequestablePage> pageClass,
                    PageParameters pageParameters,
                    java.lang.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(java.lang.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(java.lang.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()
Description copied from interface: IPageProvider
Returns whether calling getPageInstance() will result in creating new page instance or whether it will be an existing instance (even though it might be pulled from page store).

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

getPageClass

public java.lang.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 -

getPageId

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

Specified by:
getPageId in interface IPageProvider
Returns:
page id

getRenderCount

public java.lang.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.


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