You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2009/11/12 08:02:43 UTC
svn commit: r835269 -
/wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java
Author: ivaynberg
Date: Thu Nov 12 07:02:43 2009
New Revision: 835269
URL: http://svn.apache.org/viewvc?rev=835269&view=rev
Log:
WUICKET-2572
Modified:
wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java
Modified: wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java?rev=835269&r1=835268&r2=835269&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java (original)
+++ wicket/branches/wicket-1.4.x/wicket-spring/src/main/java/org/apache/wicket/spring/SpringWebApplicationFactory.java Thu Nov 12 07:02:43 2009
@@ -23,10 +23,13 @@
import org.apache.wicket.protocol.http.IWebApplicationFactory;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WicketFilter;
+import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.context.ApplicationContext;
+import org.springframework.web.context.ConfigurableWebApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
-
+import org.springframework.web.context.support.XmlWebApplicationContext;
/**
* Implementation of IWebApplicationFactory that pulls the WebApplication object out of spring
@@ -68,19 +71,70 @@
* </pre>
*
*
+ * <p>
+ * This factory is also capable of creating an additional application context (path to which is
+ * specified via the {@code contextConfigLocation} filter param) and chaining it to the global one
+ * </p>
+ *
+ * <pre>
+ * <filter>
+ * <filter-name>MyApplication</filter-name>
+ * <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+ * <init-param>
+ * <param-name>applicationClassName</param-name>
+ * <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
+ * </init-param>
+ * <init-param>
+ * <param-name>contextConfigLocation</param-name>
+ * <param-value>classpath:com/myapplication/customers-app/context.xml</param-value>
+ * </init-param>
+ * </filter>
+ * </pre>
+ *
+ *
* @author Igor Vaynberg (ivaynberg)
* @author Janne Hietamäki (jannehietamaki)
*
*/
public class SpringWebApplicationFactory implements IWebApplicationFactory
{
+
+ /**
+ * Returns location of context config that will be used to create an additional application
+ * context for this application
+ *
+ * @param filter
+ * @return location of context config
+ */
+ protected final String getContextConfigLocation(WicketFilter filter)
+ {
+ return filter.getFilterConfig().getInitParameter("contextConfigLocation");
+ }
+
+ /**
+ * Factory method used to create a new instance of the additional application context, by
+ * default an instance o {@link XmlWebApplicationContext} will be created.
+ *
+ * @return application context instance
+ */
+ protected ConfigurableWebApplicationContext newApplicationContext()
+ {
+ return new XmlWebApplicationContext();
+ }
+
/**
* @see IWebApplicationFactory#createApplication(WicketFilter)
*/
public WebApplication createApplication(WicketFilter filter)
{
ServletContext sc = filter.getFilterConfig().getServletContext();
- ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
+
+ WebApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(sc);
+
+ if (getContextConfigLocation(filter) != null)
+ {
+ ac = createWebApplicationContext(ac, filter);
+ }
String beanName = filter.getFilterConfig().getInitParameter("applicationBean");
return createApplication(ac, beanName);
@@ -115,4 +169,44 @@
return (WebApplication)beans.values().iterator().next();
}
}
+
+ /**
+ * Creates and initializes a new {@link WebApplicationContext}, with the given context as the
+ * parent. Based on the logic in {@link FrameworkServlet#createWebApplicationContext}
+ *
+ * @param parent
+ * parent application context
+ * @param filter
+ * wicket filter
+ * @return instance of additional application context
+ * @throws BeansException
+ */
+ protected final WebApplicationContext createWebApplicationContext(WebApplicationContext parent,
+ WicketFilter filter) throws BeansException
+ {
+ ConfigurableWebApplicationContext wac = newApplicationContext();
+ wac.setParent(parent);
+ wac.setServletContext(filter.getFilterConfig().getServletContext());
+ wac.setConfigLocation(getContextConfigLocation(filter));
+
+ postProcessWebApplicationContext(wac, filter);
+ wac.refresh();
+
+ return wac;
+ }
+
+ /**
+ * This is a hook for potential subclasses to perform additional processing on the context.
+ * Based on the logic in {@link FrameworkServlet#postProcessWebApplicationContext}
+ *
+ * @param wac
+ * additional application context
+ * @param filter
+ * wicket filter
+ */
+ protected void postProcessWebApplicationContext(ConfigurableWebApplicationContext wac,
+ WicketFilter filter)
+ {
+ // noop
+ }
}
\ No newline at end of file