Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You 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.catalina.core;
 
 
 
 
Wrapper around a javax.servlet.ServletRequest that transforms an application request object (which might be the original one passed to a servlet, or might be based on the 2.3 javax.servlet.ServletRequestWrapper class) back into an internal org.apache.catalina.Request.

WARNING: Due to Java's lack of support for multiple inheritance, all of the logic in ApplicationRequest is duplicated in ApplicationHttpRequest. Make sure that you keep these two classes in synchronization when making changes!

Author(s):
Craig R. McClanahan
Version:
$Revision: 1458 $ $Date: 2010-05-01 01:47:43 +0200 (Sat, 01 May 2010) $
 
 
 
 
     // ------------------------------------------------------- Static Variables
 

    
The set of attribute names that are special for request dispatchers.
 
     protected static final String specials[] =
         . };
 
 
     // ----------------------------------------------------------- Constructors
 

    
Construct a new wrapped request around the specified servlet request.

Parameters:
request The servlet request being wrapped
 
     public ApplicationRequest(ServletRequest request) {
 
         super(request);
         setRequest(request);
 
     }
 
 
     // ----------------------------------------------------- Instance Variables
 

    
The request attributes for this request. This is initialized from the wrapped request, but updates are allowed.
 
     protected HashMap attributes = new HashMap();
 
 
     // ------------------------------------------------- ServletRequest Methods
 

    
Override the getAttribute() method of the wrapped request.

Parameters:
name Name of the attribute to retrieve
    public Object getAttribute(String name) {
        synchronized () {
            return (.get(name));
        }
    }


    
Override the getAttributeNames() method of the wrapped request.
    public Enumeration getAttributeNames() {
        synchronized () {
            return (new Enumerator(.keySet()));
        }
    }


    
Override the removeAttribute() method of the wrapped request.

Parameters:
name Name of the attribute to remove
    public void removeAttribute(String name) {
        synchronized () {
            .remove(name);
            if (!isSpecial(name))
                getRequest().removeAttribute(name);
        }
    }


    
Override the setAttribute() method of the wrapped request.

Parameters:
name Name of the attribute to set
value Value of the attribute to set
    public void setAttribute(String nameObject value) {
        synchronized () {
            .put(namevalue);
            if (!isSpecial(name))
                getRequest().setAttribute(namevalue);
        }
    }
    // ------------------------------------------ ServletRequestWrapper Methods


    
Set the request that we are wrapping.

Parameters:
request The new wrapped request
    public void setRequest(ServletRequest request) {
        super.setRequest(request);
        // Initialize the attributes for this request
        synchronized () {
            .clear();
            Enumeration names = request.getAttributeNames();
            while (names.hasMoreElements()) {
                String name = (Stringnames.nextElement();
                Object value = request.getAttribute(name);
                .put(namevalue);
            }
        }
    }
    // ------------------------------------------------------ Protected Methods


    
Is this attribute name one of the special ones that is added only for included servlets?

Parameters:
name Attribute name to be tested
    protected boolean isSpecial(String name) {
        for (int i = 0; i < .i++) {
            if ([i].equals(name))
                return (true);
        }
        return (false);
    }
New to GrepCode? Check out our FAQ X