struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject svn commit: rev 55676 - struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl
Date Wed, 27 Oct 2004 07:51:15 GMT
Author: craigmcc
Date: Wed Oct 27 00:51:14 2004
New Revision: 55676

Added:
   struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl/ImplApplicationFilter.java
Modified:
   struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl/ImplPhaseListener.java
Log:
Add the beginnings of an "application controller" filter that, at the moment,
just registers the ImplPhaseListener with JSF to provide the prepare() and
destroy() calls part of the ViewController contract.  This is enough to start
writing sample apps that only use the view controller functionality of the
shale proposal, so that we can (a) make sure what's here works, and (b)
examine the example source code for simplicity and usability versus the
traditional options.

Side note -- one of the benefits of Servlet 2.4 is that we're guaranteed
that servlet context listeners have all been called before the filter
initialization takes place.  This is important because we're assuming that
JSF has been initialized before the init() method of this filter is called.
That's guaranteed to be true for either the JSF RI or MyFaces (both of which
use a servlet context listener for their setup) in a Servlet 2.4 environment.
In a Servlet 2.3 environment, the order of initialization calls is not
defined, so it's a hope, rather than a certainty, that JSF will have been
initialized already.


Added: struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl/ImplApplicationFilter.java
==============================================================================
--- (empty file)
+++ struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl/ImplApplicationFilter.java
Wed Oct 27 00:51:14 2004
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.impl;
+
+import java.io.IOException;
+
+import javax.faces.FactoryFinder;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * <p>A <code>Filter</code> implementation that invokes the required
+ * <em>Application Controller</em> functionality on every request.  In
+ * addition, it performs overall application startup and shutdown
+ * operations on behalf of the framework.</p>
+ *
+ * $Id$
+ */
+
+public class ImplApplicationFilter implements Filter {
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    /**
+     * <p>Filter configuration object for this <code>Filter</code>.</p>
+     */
+    private FilterConfig config = null;
+
+
+    /**
+     * <p>The <code>ServletContext</code> instance for our web application.</p>
+     */
+    private ServletContext context = null;
+
+
+    /**
+     * <p>The JSF <code>PhaseListener</code> that we have registered.</p>
+     */
+    private PhaseListener phaseListener = null;
+
+
+    // ---------------------------------------------------------- Filter Methods
+
+
+    /**
+     * <p>Perform application shutdown finalization as necessary.</p>
+     */
+    public void destroy() {
+
+        config = null;
+        context = null;
+        if (phaseListener != null) {
+            getLifecycle().removePhaseListener(phaseListener);
+        }
+        phaseListener = null;
+
+    }
+    
+
+    /**
+     * <p>Perform per-request application controler functionality.</p>
+     *
+     * @param request The request we are processing
+     * @param response The response we are creating
+     * @param chain The filter chain for this request
+     */
+    public void doFilter(ServletRequest request, ServletResponse response,
+      FilterChain chain) throws IOException, ServletException {
+
+        ; // FIXME - do any required preprocessing
+        chain.doFilter(request, response);
+        ; // FIXME - do any required postprocessing
+
+    }
+
+
+    /**
+     * <p>Perform application startup intiialization as necessary.</p>
+     *
+     * @param config <code>FilterConfig</code> for this filter
+     */
+    public void init(FilterConfig config) throws ServletException {
+
+        this.config = config;
+        context = config.getServletContext();
+        phaseListener = new ImplPhaseListener();
+        getLifecycle().addPhaseListener(phaseListener);
+
+    }
+
+
+    // --------------------------------------------------------- Private Methods
+
+
+    /**
+     * <p>Return the JSF <code>Lifecycle</code> instance for this
+     * web application.</p>
+     */
+    private Lifecycle getLifecycle() {
+
+        String lifecycleId =
+          context.getInitParameter("javax.faces.LIFECYCLE_ID");
+        if (lifecycleId == null) {
+            lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE;
+        }
+        LifecycleFactory factory = (LifecycleFactory)
+          FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+        return factory.getLifecycle(lifecycleId);
+
+    }
+
+
+}

Modified: struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl/ImplPhaseListener.java
==============================================================================
--- struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl/ImplPhaseListener.java
(original)
+++ struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl/ImplPhaseListener.java
Wed Oct 27 00:51:14 2004
@@ -28,7 +28,7 @@
 
 /**
  * <p>JavaServer Faces <code>PhaseListener</code> that implements phase
- * related functionality.  FIXME - register this with JSF appropriately.</p>
+ * related functionality.</p>
  *
  * $Id$
  */

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message