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: * Please note access to the internal structures of this class is not michael@0: * synchronized and therefore this class may be thread-unsafe. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: public class BasicHttpParams extends AbstractHttpParams implements Serializable, Cloneable { michael@0: michael@0: private static final long serialVersionUID = -7086398485908701455L; michael@0: michael@0: /** Map of HTTP parameters that this collection contains. */ michael@0: private final HashMap parameters = new HashMap(); michael@0: michael@0: public BasicHttpParams() { michael@0: super(); michael@0: } michael@0: michael@0: public Object getParameter(final String name) { michael@0: return this.parameters.get(name); michael@0: } michael@0: michael@0: public HttpParams setParameter(final String name, final Object value) { michael@0: this.parameters.put(name, value); michael@0: return this; michael@0: } michael@0: michael@0: public boolean removeParameter(String name) { michael@0: //this is to avoid the case in which the key has a null value michael@0: if (this.parameters.containsKey(name)) { michael@0: this.parameters.remove(name); michael@0: return true; michael@0: } else { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Assigns the value to all the parameter with the given names michael@0: * michael@0: * @param names array of parameter names michael@0: * @param value parameter value michael@0: */ michael@0: public void setParameters(final String[] names, final Object value) { michael@0: for (int i = 0; i < names.length; i++) { michael@0: setParameter(names[i], value); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Is the parameter set? michael@0: *
michael@0: * Uses {@link #getParameter(String)} (which is overrideable) to michael@0: * fetch the parameter value, if any. michael@0: *
michael@0: * Also @see {@link #isParameterSetLocally(String)} michael@0: * michael@0: * @param name parameter name michael@0: * @return true if parameter is defined and non-null michael@0: */ michael@0: public boolean isParameterSet(final String name) { michael@0: return getParameter(name) != null; michael@0: } michael@0: michael@0: /** michael@0: * Is the parameter set in this object? michael@0: *
michael@0: * The parameter value is fetched directly. michael@0: *
michael@0: * Also @see {@link #isParameterSet(String)} michael@0: * michael@0: * @param name parameter name michael@0: * @return true if parameter is defined and non-null michael@0: */ michael@0: public boolean isParameterSetLocally(final String name) { michael@0: return this.parameters.get(name) != null; michael@0: } michael@0: michael@0: /** michael@0: * Removes all parameters from this collection. michael@0: */ michael@0: public void clear() { michael@0: this.parameters.clear(); michael@0: } michael@0: michael@0: /** michael@0: * Creates a copy of these parameters. michael@0: * This implementation calls {@link #clone()}. michael@0: * michael@0: * @return a new set of params holding a copy of the michael@0: * local parameters in this object. michael@0: * michael@0: * @deprecated michael@0: * @throws UnsupportedOperationException if the clone() fails michael@0: */ michael@0: public HttpParams copy() { michael@0: try { michael@0: return (HttpParams) clone(); michael@0: } catch (CloneNotSupportedException ex) { michael@0: throw new UnsupportedOperationException("Cloning not supported"); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Clones the instance. michael@0: * Uses {@link #copyParams(HttpParams)} to copy the parameters. michael@0: */ michael@0: public Object clone() throws CloneNotSupportedException { michael@0: BasicHttpParams clone = (BasicHttpParams) super.clone(); michael@0: copyParams(clone); michael@0: return clone; michael@0: } michael@0: michael@0: protected void copyParams(HttpParams target) { michael@0: Iterator iter = parameters.entrySet().iterator(); michael@0: while (iter.hasNext()) { michael@0: Map.Entry me = (Map.Entry) iter.next(); michael@0: if (me.getKey() instanceof String) michael@0: target.setParameter((String)me.getKey(), me.getValue()); michael@0: } michael@0: } michael@0: michael@0: }