michael@0: /* michael@0: * ==================================================================== michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.params; michael@0: michael@0: /** michael@0: * {@link HttpParams} implementation that delegates resolution of a parameter michael@0: * to the given default {@link HttpParams} instance if the parameter is not michael@0: * present in the local one. The state of the local collection can be mutated, michael@0: * whereas the default collection is treated as read-only. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: public final class DefaultedHttpParams extends AbstractHttpParams { michael@0: michael@0: private final HttpParams local; michael@0: private final HttpParams defaults; michael@0: michael@0: /** michael@0: * Create the defaulted set of HttpParams. michael@0: * michael@0: * @param local the mutable set of HttpParams michael@0: * @param defaults the default set of HttpParams, not mutated by this class michael@0: */ michael@0: public DefaultedHttpParams(final HttpParams local, final HttpParams defaults) { michael@0: super(); michael@0: if (local == null) { michael@0: throw new IllegalArgumentException("HTTP parameters may not be null"); michael@0: } michael@0: this.local = local; michael@0: this.defaults = defaults; michael@0: } michael@0: michael@0: /** michael@0: * Creates a copy of the local collection with the same default michael@0: * michael@0: * @deprecated michael@0: */ michael@0: public HttpParams copy() { michael@0: HttpParams clone = this.local.copy(); michael@0: return new DefaultedHttpParams(clone, this.defaults); michael@0: } michael@0: michael@0: /** michael@0: * Retrieves the value of the parameter from the local collection and, if the michael@0: * parameter is not set locally, delegates its resolution to the default michael@0: * collection. michael@0: */ michael@0: public Object getParameter(final String name) { michael@0: Object obj = this.local.getParameter(name); michael@0: if (obj == null && this.defaults != null) { michael@0: obj = this.defaults.getParameter(name); michael@0: } michael@0: return obj; michael@0: } michael@0: michael@0: /** michael@0: * Attempts to remove the parameter from the local collection. This method michael@0: * does not modify the default collection. michael@0: */ michael@0: public boolean removeParameter(final String name) { michael@0: return this.local.removeParameter(name); michael@0: } michael@0: michael@0: /** michael@0: * Sets the parameter in the local collection. This method does not michael@0: * modify the default collection. michael@0: */ michael@0: public HttpParams setParameter(final String name, final Object value) { michael@0: return this.local.setParameter(name, value); michael@0: } michael@0: michael@0: /** michael@0: * michael@0: * @return the default HttpParams collection michael@0: */ michael@0: public HttpParams getDefaults() { michael@0: return this.defaults; michael@0: } michael@0: michael@0: }