Save This Page
Home » HttpComponents-Core-4.0.1 » org.apache.http.params » [javadoc | source]
    1   /*
    2    * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java $
    3    * $Revision: 744530 $
    4    * $Date: 2009-02-14 18:09:27 +0100 (Sat, 14 Feb 2009) $
    5    *
    6    * ====================================================================
    7    * Licensed to the Apache Software Foundation (ASF) under one
    8    * or more contributor license agreements.  See the NOTICE file
    9    * distributed with this work for additional information
   10    * regarding copyright ownership.  The ASF licenses this file
   11    * to you under the Apache License, Version 2.0 (the
   12    * "License"); you may not use this file except in compliance
   13    * with the License.  You may obtain a copy of the License at
   14    *
   15    *   http://www.apache.org/licenses/LICENSE-2.0
   16    *
   17    * Unless required by applicable law or agreed to in writing,
   18    * software distributed under the License is distributed on an
   19    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   20    * KIND, either express or implied.  See the License for the
   21    * specific language governing permissions and limitations
   22    * under the License.
   23    * ====================================================================
   24    *
   25    * This software consists of voluntary contributions made by many
   26    * individuals on behalf of the Apache Software Foundation.  For more
   27    * information on the Apache Software Foundation, please see
   28    * <http://www.apache.org/>.
   29    *
   30    */
   31   
   32   package org.apache.http.params;
   33   
   34   import org.apache.http.params.HttpParams;
   35   
   36   /**
   37    * {@link HttpParams} implementation that delegates resolution of a parameter
   38    * to the given default {@link HttpParams} instance if the parameter is not 
   39    * present in the local one. The state of the local collection can be mutated,
   40    * whereas the default collection is treated as read-only.
   41    *
   42    * 
   43    * @version $Revision: 744530 $
   44    *
   45    * @since 4.0
   46    */
   47   public final class DefaultedHttpParams extends AbstractHttpParams {
   48   
   49       private final HttpParams local;
   50       private final HttpParams defaults;
   51       
   52       public DefaultedHttpParams(final HttpParams local, final HttpParams defaults) {
   53           super();
   54           if (local == null) {
   55               throw new IllegalArgumentException("HTTP parameters may not be null");
   56           }
   57           this.local = local;
   58           this.defaults = defaults;
   59       }
   60   
   61       /**
   62        * Creates a copy of the local collection with the same default
   63        */
   64       public HttpParams copy() {
   65           HttpParams clone = this.local.copy();
   66           return new DefaultedHttpParams(clone, this.defaults);
   67       }
   68   
   69       /**
   70        * Retrieves the value of the parameter from the local collection and, if the 
   71        * parameter is not set locally, delegates its resolution to the default 
   72        * collection.
   73        */
   74       public Object getParameter(final String name) {
   75           Object obj = this.local.getParameter(name);
   76           if (obj == null && this.defaults != null) {
   77               obj = this.defaults.getParameter(name);
   78           }
   79           return obj;
   80       }
   81   
   82       /**
   83        * Attempts to remove the parameter from the local collection. This method 
   84        * <i>does not</i> modify the default collection.
   85        */
   86       public boolean removeParameter(final String name) {
   87           return this.local.removeParameter(name);
   88       }
   89   
   90       /**
   91        * Sets the parameter in the local collection. This method <i>does not</i> 
   92        * modify the default collection.
   93        */
   94       public HttpParams setParameter(final String name, final Object value) {
   95           return this.local.setParameter(name, value);
   96       }
   97   
   98       public HttpParams getDefaults() {
   99           return this.defaults;
  100       }
  101       
  102   }

Save This Page
Home » HttpComponents-Core-4.0.1 » org.apache.http.params » [javadoc | source]