Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2006, 2007, 2008, 2009, 2010 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.tapestry5;
 
 
The TapestryFilter is responsible for intercepting all requests into the web application. It identifies the requests that are relevant to Tapestry, and lets the servlet container handle the rest. It is also responsible for initializing Tapestry.

The application is primarily configured via context-level init parameters.

tapestry.app-package
The application package (used to search for pages, components, etc.)

In addition, a JVM system property affects configuration: tapestry.execution-mode (with default value "production"). This property is a comma-separated list of execution modes. For each mode, an additional init parameter is checked for: tapestry.mode-modules; this is a comma-separated list of module class names to load. In this way, more precise control over the available modules can be obtained which is often needed during testing.

 
 public class TapestryFilter implements Filter
 {
     private final Logger logger = LoggerFactory.getLogger(TapestryFilter.class);
 
     private FilterConfig config;
 
     private Registry registry;
 
     private HttpServletRequestHandler handler;

    
Key under which that Tapestry IoC org.apache.tapestry5.ioc.Registry is stored in the ServletContext. This allows other code, beyond Tapestry, to obtain the Registry and, from it, any Tapestry services. Such code should be careful about invoking org.apache.tapestry5.ioc.Registry.cleanupThread() appropriately.
 
     public static final String REGISTRY_CONTEXT_NAME = "org.apache.tapestry5.application-registry";

    
Initializes the filter using the org.apache.tapestry5.internal.TapestryAppInitializer. The application name is the capitalization of the filter name (as specified in web.xml).
 
     public final void init(FilterConfig filterConfigthrows ServletException
     {
          = filterConfig;
 
         ServletContext context = .getServletContext();
 
         String filterName = .getFilterName();
 
         SymbolProvider provider = new ServletContextSymbolProvider(context);
 
         String executionMode = System.getProperty("tapestry.execution-mode""production");
 
         TapestryAppInitializer appInitializer = new TapestryAppInitializer(provider,
                 filterName"servlet"executionMode);
 
         appInitializer.addModules(provideExtraModuleDefs(context));
 
          = appInitializer.createRegistry();
 
         context.setAttribute();
 
         ServletApplicationInitializer ai = .getService("ServletApplicationInitializer",
                ServletApplicationInitializer.class);
        ai.initializeApplication(filterConfig.getServletContext());
         = .getService("HttpServletRequestHandler"HttpServletRequestHandler.class);
        init();
        appInitializer.announceStartup();
    }
    protected final FilterConfig getFilterConfig()
    {
        return ;
    }

    
Invoked from init(javax.servlet.FilterConfig) after the Registry has been created, to allow any additional initialization to occur. This implementation does nothing, and my be overriden in subclasses.

Parameters:
registry from which services may be extracted
Throws:
javax.servlet.ServletException
    protected void init(Registry registrythrows ServletException
    {
    }

    
Overridden in subclasses to provide additional module definitions beyond those normally located. This implementation returns an empty array.
    protected ModuleDef[] provideExtraModuleDefs(ServletContext context)
    {
        return new ModuleDef[0];
    }
    public final void doFilter(ServletRequest requestServletResponse responseFilterChain chain)
            throws IOExceptionServletException
    {
        try
        {
            boolean handled = .service((HttpServletRequestrequest,
                    (HttpServletResponseresponse);
            if (!handled)
                chain.doFilter(requestresponse);
        }
        finally
        {
            .cleanupThread();
        }
    }

    
Shuts down and discards the registry. Invokes destroy(org.apache.tapestry5.ioc.Registry) to allow subclasses to peform any shutdown logic, then shuts down the registry, and removes it from the ServletContext.
    public final void destroy()
    {
        destroy();
        .shutdown();
         = null;
         = null;
         = null;
    }

    
Invoked from destroy() to allow subclasses to add additional shutdown logic to the filter. The Registry will be shutdown after this call. This implementation does nothing, and may be overridden in subclasses.

Parameters:
registry
    protected void destroy(Registry registry)
    {
    }
New to GrepCode? Check out our FAQ X