Java tutorial
package org.apache.http.protocol; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.http.annotation.ThreadSafe; import org.apache.http.util.Args; @ThreadSafe public class BasicHttpContext implements HttpContext { private final Map<String, Object> map; private final HttpContext parentContext; public BasicHttpContext() { this(null); } public BasicHttpContext(HttpContext httpContext) { this.map = new ConcurrentHashMap(); this.parentContext = httpContext; } public Object getAttribute(String str) { Args.notNull(str, "Id"); Object obj = this.map.get(str); if (obj != null || this.parentContext == null) { return obj; } return this.parentContext.getAttribute(str); } public void setAttribute(String str, Object obj) { Args.notNull(str, "Id"); if (obj != null) { this.map.put(str, obj); } else { this.map.remove(str); } } public Object removeAttribute(String str) { Args.notNull(str, "Id"); return this.map.remove(str); } public void clear() { this.map.clear(); } public String toString() { return this.map.toString(); } }