Return-Path: Delivered-To: apmail-struts-dev-archive@www.apache.org Received: (qmail 65831 invoked from network); 27 Oct 2004 07:51:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 27 Oct 2004 07:51:26 -0000 Received: (qmail 4207 invoked by uid 500); 27 Oct 2004 07:51:19 -0000 Delivered-To: apmail-struts-dev-archive@struts.apache.org Received: (qmail 3994 invoked by uid 500); 27 Oct 2004 07:51:17 -0000 Mailing-List: contact dev-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Struts Developers List" Reply-To: "Struts Developers List" Delivered-To: mailing list dev@struts.apache.org Received: (qmail 3980 invoked by uid 500); 27 Oct 2004 07:51:17 -0000 Received: (qmail 3975 invoked by uid 99); 27 Oct 2004 07:51:17 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 27 Oct 2004 00:51:16 -0700 Received: (qmail 65729 invoked by uid 65534); 27 Oct 2004 07:51:15 -0000 Date: 27 Oct 2004 07:51:15 -0000 Message-ID: <20041027075115.65726.qmail@minotaur.apache.org> From: craigmcc@apache.org To: commits@struts.apache.org Subject: svn commit: rev 55676 - struts/trunk/contrib/struts-shale/src/java/org/apache/shale/impl X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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; + +/** + *

A Filter implementation that invokes the required + * Application Controller functionality on every request. In + * addition, it performs overall application startup and shutdown + * operations on behalf of the framework.

+ * + * $Id$ + */ + +public class ImplApplicationFilter implements Filter { + + + // ------------------------------------------------------ Instance Variables + + + /** + *

Filter configuration object for this Filter.

+ */ + private FilterConfig config = null; + + + /** + *

The ServletContext instance for our web application.

+ */ + private ServletContext context = null; + + + /** + *

The JSF PhaseListener that we have registered.

+ */ + private PhaseListener phaseListener = null; + + + // ---------------------------------------------------------- Filter Methods + + + /** + *

Perform application shutdown finalization as necessary.

+ */ + public void destroy() { + + config = null; + context = null; + if (phaseListener != null) { + getLifecycle().removePhaseListener(phaseListener); + } + phaseListener = null; + + } + + + /** + *

Perform per-request application controler functionality.

+ * + * @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 + + } + + + /** + *

Perform application startup intiialization as necessary.

+ * + * @param config FilterConfig for this filter + */ + public void init(FilterConfig config) throws ServletException { + + this.config = config; + context = config.getServletContext(); + phaseListener = new ImplPhaseListener(); + getLifecycle().addPhaseListener(phaseListener); + + } + + + // --------------------------------------------------------- Private Methods + + + /** + *

Return the JSF Lifecycle instance for this + * web application.

+ */ + 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 @@ /** *

JavaServer Faces PhaseListener that implements phase - * related functionality. FIXME - register this with JSF appropriately.

+ * related functionality.

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