1 /* 2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java $ 3 * $Revision: 610464 $ 4 * $Date: 2008-01-09 09:10:55 -0800 (Wed, 09 Jan 2008) $ 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 java.io.Serializable; 35 import java.util.Map; 36 import java.util.HashMap; 37 import java.util.Iterator; 38 39 import org.apache.http.params.HttpParams; 40 41 /** 42 * This class represents a collection of HTTP protocol parameters. 43 * Protocol parameters may be linked together to form a hierarchy. 44 * If a particular parameter value has not been explicitly defined 45 * in the collection itself, its value will be drawn from the parent 46 * collection of parameters. 47 * 48 * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> 49 * 50 * @version $Revision: 610464 $ 51 * 52 * @deprecated Please use {@link java.net.URL#openConnection} instead. 53 * Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a> 54 * for further details. 55 */ 56 @Deprecated 57 public final class BasicHttpParams extends AbstractHttpParams 58 implements Serializable, Cloneable { 59 60 private static final long serialVersionUID = -7086398485908701455L; 61 62 /** Map of HTTP parameters that this collection contains. */ 63 private HashMap parameters; 64 BasicHttpParams()65 public BasicHttpParams() { 66 super(); 67 } 68 getParameter(final String name)69 public Object getParameter(final String name) { 70 // See if the parameter has been explicitly defined 71 Object param = null; 72 if (this.parameters != null) { 73 param = this.parameters.get(name); 74 } 75 return param; 76 } 77 setParameter(final String name, final Object value)78 public HttpParams setParameter(final String name, final Object value) { 79 if (this.parameters == null) { 80 this.parameters = new HashMap(); 81 } 82 this.parameters.put(name, value); 83 return this; 84 } 85 removeParameter(String name)86 public boolean removeParameter(String name) { 87 if (this.parameters == null) { 88 return false; 89 } 90 //this is to avoid the case in which the key has a null value 91 if (this.parameters.containsKey(name)) { 92 this.parameters.remove(name); 93 return true; 94 } else { 95 return false; 96 } 97 } 98 99 100 /** 101 * Assigns the value to all the parameter with the given names 102 * 103 * @param names array of parameter name 104 * @param value parameter value 105 */ setParameters(final String[] names, final Object value)106 public void setParameters(final String[] names, final Object value) { 107 for (int i = 0; i < names.length; i++) { 108 setParameter(names[i], value); 109 } 110 } 111 isParameterSet(final String name)112 public boolean isParameterSet(final String name) { 113 return getParameter(name) != null; 114 } 115 isParameterSetLocally(final String name)116 public boolean isParameterSetLocally(final String name) { 117 return this.parameters != null && this.parameters.get(name) != null; 118 } 119 120 /** 121 * Removes all parameters from this collection. 122 */ clear()123 public void clear() { 124 this.parameters = null; 125 } 126 127 /** 128 * Creates a copy of these parameters. 129 * The implementation here instantiates {@link BasicHttpParams}, 130 * then calls {@link #copyParams(HttpParams)} to populate the copy. 131 * 132 * @return a new set of params holding a copy of the 133 * <i>local</i> parameters in this object. 134 */ copy()135 public HttpParams copy() { 136 BasicHttpParams clone = new BasicHttpParams(); 137 copyParams(clone); 138 return clone; 139 } 140 clone()141 public Object clone() throws CloneNotSupportedException { 142 BasicHttpParams clone = (BasicHttpParams) super.clone(); 143 copyParams(clone); 144 return clone; 145 } 146 147 /** 148 * Copies the locally defined parameters to the argument parameters. 149 * This method is called from {@link #copy()}. 150 * 151 * @param target the parameters to which to copy 152 */ copyParams(HttpParams target)153 protected void copyParams(HttpParams target) { 154 if (this.parameters == null) 155 return; 156 157 Iterator iter = parameters.entrySet().iterator(); 158 while (iter.hasNext()) { 159 Map.Entry me = (Map.Entry) iter.next(); 160 if (me.getKey() instanceof String) 161 target.setParameter((String)me.getKey(), me.getValue()); 162 } 163 } 164 165 } 166