001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/params/DefaultedHttpParams.java $
003: * $Revision: 610763 $
004: * $Date: 2008-01-10 13:01:13 +0100 (Thu, 10 Jan 2008) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.params;
033:
034: import org.apache.http.params.HttpParams;
035:
036: /**
037: * {@link HttpParams} implementation that delegates resolution of a parameter
038: * to the given default {@link HttpParams} instance if the parameter is not
039: * present in the local one. The state of the local collection can be mutated,
040: * whereas the default collection is treated as read-only.
041: *
042: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
043: *
044: * @version $Revision: 610763 $
045: */
046: public final class DefaultedHttpParams extends AbstractHttpParams {
047:
048: private final HttpParams local;
049: private final HttpParams defaults;
050:
051: public DefaultedHttpParams(final HttpParams local,
052: final HttpParams defaults) {
053: super ();
054: if (local == null) {
055: throw new IllegalArgumentException(
056: "HTTP parameters may not be null");
057: }
058: this .local = local;
059: this .defaults = defaults;
060: }
061:
062: /**
063: * Creates a copy of the local collection with the same default
064: */
065: public HttpParams copy() {
066: HttpParams clone = this .local.copy();
067: return new DefaultedHttpParams(clone, this .defaults);
068: }
069:
070: /**
071: * Retrieves the value of the parameter from the local collection and, if the
072: * parameter is not set locally, delegates its resolution to the default
073: * collection.
074: */
075: public Object getParameter(final String name) {
076: Object obj = this .local.getParameter(name);
077: if (obj == null && this .defaults != null) {
078: obj = this .defaults.getParameter(name);
079: }
080: return obj;
081: }
082:
083: /**
084: * Attempts to remove the parameter from the local collection. This method
085: * <i>does not</i> modify the default collection.
086: */
087: public boolean removeParameter(final String name) {
088: return this .local.removeParameter(name);
089: }
090:
091: /**
092: * Sets the parameter in the local collection. This method <i>does not</i>
093: * modify the default collection.
094: */
095: public HttpParams setParameter(final String name, final Object value) {
096: return this .local.setParameter(name, value);
097: }
098:
099: public HttpParams getDefaults() {
100: return this.defaults;
101: }
102:
103: }
|