WICKET-4350 Add more programmatic support for web app construction via servlet 3


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/8701ee07
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/8701ee07
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/8701ee07

Branch: refs/heads/master
Commit: 8701ee07dcf894873c417447085289916c765479
Parents: d74a22c
Author: Peter Ertl <p...@apache.org>
Authored: Sat Jan 21 16:01:29 2012 +0100
Committer: Peter Ertl <p...@apache.org>
Committed: Sat Jan 21 16:01:29 2012 +0100

----------------------------------------------------------------------
 .../wicket/protocol/http/WebApplication.java       |   18 ++++++++
 .../apache/wicket/protocol/http/WicketFilter.java  |   32 ++++++++++++++-
 2 files changed, 48 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/8701ee07/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
index 5cf27e0..6df30e0 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
@@ -615,6 +615,24 @@ public abstract class WebApplication extends Application
        }
 
        /**
+        * set runtime configuration type
+        * <p/>
+        * this is a write-once property: once configured it can not be changed 
later on.
+        * 
+        * @param configurationType
+        */
+       public void setConfigurationType(RuntimeConfigurationType 
configurationType)
+       {
+               if (this.configurationType != null)
+               {
+                       throw new IllegalStateException(
+                               "Configuration type is write-once. You can not 
change it. " + "" +
+                               "Current value='" + configurationType);
+               }
+               this.configurationType = Args.notNull(configurationType, 
"configurationType");
+       }
+
+       /**
         * {@inheritDoc}
         */
        @Override

http://git-wip-us.apache.org/repos/asf/wicket/blob/8701ee07/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
index 1a26413..e79b98e 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
@@ -35,6 +35,7 @@ import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.request.http.WebRequest;
 import org.apache.wicket.request.http.WebResponse;
 import org.apache.wicket.util.file.WebXmlFile;
+import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.string.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -95,6 +96,28 @@ public class WicketFilter implements Filter
        private boolean isServlet = false;
 
        /**
+        * default constructor, usually invoked through the servlet 
+        * container by the web.xml configuration
+        */
+       public WicketFilter()
+       {
+       }
+
+       /**
+        * constructor supporting programmatic setup of the filter
+        * <p/>
+        *  this can be useful for programmatically creating and appending the 
+        *  wicket filter to the servlet context using servlet 3 features.
+        * 
+        * @param application
+        *           web application
+        */
+       public WicketFilter(WebApplication application)
+       {
+               this.application = Args.notNull(application, "application");
+       }
+
+       /**
         * @return The class loader
         */
        protected ClassLoader getClassLoader()
@@ -306,8 +329,13 @@ public class WicketFilter implements Filter
                this.isServlet = isServlet;
                initIgnorePaths(filterConfig);
 
-               applicationFactory = getApplicationFactory();
-               application = applicationFactory.createApplication(this);
+               // locate application instance unless it was already specified 
during construction
+               if (application == null)
+               {
+                       applicationFactory = getApplicationFactory();
+                       application = 
applicationFactory.createApplication(this);
+               }
+
                application.setName(filterConfig.getFilterName());
                application.setWicketFilter(this);
 

Reply via email to