You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/08/01 17:47:55 UTC
git commit: WICKET-4688 Make use of the generic type passed to
IPageFactory#newPage() and return the typed Page
Updated Branches:
refs/heads/master fc485be5b -> e64451443
WICKET-4688 Make use of the generic type passed to IPageFactory#newPage() and return the typed Page
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/e6445144
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/e6445144
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/e6445144
Branch: refs/heads/master
Commit: e644514433e634a0e24c151f10cdf4cdd82d7229
Parents: fc485be
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Aug 1 18:47:31 2012 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Aug 1 18:47:31 2012 +0300
----------------------------------------------------------------------
.../main/java/org/apache/wicket/IPageFactory.java | 13 +++----
.../apache/wicket/session/DefaultPageFactory.java | 26 +++++++-------
2 files changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/e6445144/wicket-core/src/main/java/org/apache/wicket/IPageFactory.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/IPageFactory.java b/wicket-core/src/main/java/org/apache/wicket/IPageFactory.java
index 2f23e49..7006003 100644
--- a/wicket-core/src/main/java/org/apache/wicket/IPageFactory.java
+++ b/wicket-core/src/main/java/org/apache/wicket/IPageFactory.java
@@ -28,7 +28,7 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
* {@link org.apache.wicket.request.flow.ResetResponseException} thrown from the constructing page's
* constructor bubble up.
*
- * @see org.apache.wicket.settings.ISessionSettings#setPageFactory(IPageFactory)
+ * @see org.apache.wicket.Application#newPageFactory()
* @see Session#getPageFactory()
*
* @author Juergen Donnerstag
@@ -40,14 +40,14 @@ public interface IPageFactory
* Creates a new page using a page class.
*
* @param <C>
- *
+ * the type of the page class
* @param pageClass
* The page class to instantiate
* @return The page
* @throws WicketRuntimeException
* Thrown if the page cannot be constructed
*/
- <C extends IRequestablePage> IRequestablePage newPage(final Class<C> pageClass);
+ <C extends IRequestablePage> C newPage(final Class<C> pageClass);
/**
* Creates a new Page, passing PageParameters to the Page constructor if such a constructor
@@ -55,7 +55,7 @@ public interface IPageFactory
* available default constructor will be used.
*
* @param <C>
- *
+ * the type of the page class
* @param pageClass
* The class of Page to create
* @param parameters
@@ -64,13 +64,12 @@ public interface IPageFactory
* @throws WicketRuntimeException
* Thrown if the page cannot be constructed
*/
- <C extends IRequestablePage> IRequestablePage newPage(final Class<C> pageClass,
- final PageParameters parameters);
+ <C extends IRequestablePage> C newPage(final Class<C> pageClass, final PageParameters parameters);
/**
* Checks whether a page can be instantiated using a bookmarkable URL.
*
- * @param C
+ * @param <C>
* the type of the page class
* @param pageClass
* The class of page to check for bookmarkability
http://git-wip-us.apache.org/repos/asf/wicket/blob/e6445144/wicket-core/src/main/java/org/apache/wicket/session/DefaultPageFactory.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/session/DefaultPageFactory.java b/wicket-core/src/main/java/org/apache/wicket/session/DefaultPageFactory.java
index cc8ac3a..a58830a 100644
--- a/wicket-core/src/main/java/org/apache/wicket/session/DefaultPageFactory.java
+++ b/wicket-core/src/main/java/org/apache/wicket/session/DefaultPageFactory.java
@@ -55,20 +55,20 @@ public final class DefaultPageFactory implements IPageFactory
private final ConcurrentMap<String, Boolean> pageToBookmarkableCache = Generics.newConcurrentHashMap();
@Override
- public final <C extends IRequestablePage> Page newPage(final Class<C> pageClass)
+ public final <C extends IRequestablePage> C newPage(final Class<C> pageClass)
{
try
{
// throw an exception in case default constructor is missing
// => improved error message
- Constructor<? extends IRequestablePage> constructor = pageClass.getConstructor((Class<?>[])null);
+ Constructor<C> constructor = pageClass.getConstructor((Class<?>[])null);
return processPage(newPage(constructor, null), null);
}
catch (NoSuchMethodException e)
{
// a bit of a hack here..
- Constructor<?> constructor = constructor(pageClass, PageParameters.class);
+ Constructor<C> constructor = constructor(pageClass, PageParameters.class);
if (constructor != null)
{
PageParameters pp = new PageParameters();
@@ -83,11 +83,11 @@ public final class DefaultPageFactory implements IPageFactory
}
@Override
- public final <C extends IRequestablePage> Page newPage(final Class<C> pageClass,
+ public final <C extends IRequestablePage> C newPage(final Class<C> pageClass,
final PageParameters parameters)
{
// Try to get constructor that takes PageParameters
- Constructor<?> constructor = constructor(pageClass, PageParameters.class);
+ Constructor<C> constructor = constructor(pageClass, PageParameters.class);
// If we got a PageParameters constructor
if (constructor != null)
@@ -112,11 +112,11 @@ public final class DefaultPageFactory implements IPageFactory
* @return The page constructor, or null if no one-arg constructor can be found taking the given
* argument type.
*/
- private <C extends IRequestablePage> Constructor<?> constructor(final Class<C> pageClass,
+ private <C extends IRequestablePage> Constructor<C> constructor(final Class<C> pageClass,
final Class<PageParameters> argumentType)
{
// Get constructor for page class from cache
- Constructor<?> constructor = constructorForClass.get(pageClass);
+ Constructor<C> constructor = (Constructor<C>) constructorForClass.get(pageClass);
// Need to look up?
if (constructor == null)
@@ -127,7 +127,7 @@ public final class DefaultPageFactory implements IPageFactory
constructor = pageClass.getConstructor(new Class[] { argumentType });
// Store it in the cache
- Constructor<?> tmpConstructor = constructorForClass.putIfAbsent(pageClass, constructor);
+ Constructor<C> tmpConstructor = (Constructor<C>) constructorForClass.putIfAbsent(pageClass, constructor);
if (tmpConstructor != null)
{
constructor = tmpConstructor;
@@ -161,17 +161,17 @@ public final class DefaultPageFactory implements IPageFactory
* Thrown if the Page cannot be instantiated using the given constructor and
* argument.
*/
- private Page newPage(final Constructor<?> constructor, final Object argument)
+ private <C extends IRequestablePage> C newPage(final Constructor<C> constructor, final PageParameters argument)
{
try
{
if (argument != null)
{
- return (Page)constructor.newInstance(argument);
+ return constructor.newInstance(argument);
}
else
{
- return (Page)constructor.newInstance();
+ return constructor.newInstance();
}
}
catch (InstantiationException e)
@@ -194,7 +194,7 @@ public final class DefaultPageFactory implements IPageFactory
}
}
- private Page processPage(final Page page, final PageParameters pageParameters)
+ private <C extends IRequestablePage> C processPage(final C page, final PageParameters pageParameters)
{
// the page might have not propagate page parameters from constructor. if that's the case
// we force the parameters
@@ -203,7 +203,7 @@ public final class DefaultPageFactory implements IPageFactory
page.getPageParameters().overwriteWith(pageParameters);
}
- page.setWasCreatedBookmarkable(true);
+ ((Page)page).setWasCreatedBookmarkable(true);
return page;
}