1 /* 2 * $HeadURL: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/tags/4.0-alpha2/src/java/org/apache/http/protocol/HttpExecutionContext.java $ 3 * $Revision: 376961 $ 4 * $Date: 2006-02-11 11:32:50 +0100 (Sat, 11 Feb 2006) $ 5 * 6 * ==================================================================== 7 * 8 * Copyright 1999-2006 The Apache Software Foundation 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * ==================================================================== 22 * 23 * This software consists of voluntary contributions made by many 24 * individuals on behalf of the Apache Software Foundation. For more 25 * information on the Apache Software Foundation, please see 26 * <http://www.apache.org/>. 27 * 28 */ 29 30 package org.apache.http.protocol; 31 32 import java.util.HashMap; 33 import java.util.Map; 34 35 36 /** 37 * Default implementation of the {@link HttpContext HttpContext}. 38 * 39 * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> 40 * 41 * @version $Revision: 376961 $ 42 * 43 * @since 4.0 44 */ 45 public class HttpExecutionContext implements HttpContext { 46 47 public static final String HTTP_TARGET_HOST = "http.target_host"; 48 public static final String HTTP_PROXY_HOST = "http.proxy_host"; 49 public static final String HTTP_REQ_SENT = "http.request_sent"; 50 51 private final HttpContext parentContext; 52 private Map map = null; 53 54 public HttpExecutionContext(final HttpContext parentContext) { 55 super(); 56 this.parentContext = parentContext; 57 } 58 59 public Object getAttribute(final String id) { 60 if (id == null) { 61 throw new IllegalArgumentException("Id may not be null"); 62 } 63 Object obj = null; 64 if (this.map != null) { 65 obj = this.map.get(id); 66 } 67 if (obj == null && this.parentContext != null) { 68 obj = this.parentContext.getAttribute(id); 69 } 70 return obj; 71 } 72 73 public void setAttribute(final String id, final Object obj) { 74 if (id == null) { 75 throw new IllegalArgumentException("Id may not be null"); 76 } 77 if (this.map == null) { 78 this.map = new HashMap(); 79 } 80 this.map.put(id, obj); 81 } 82 83 public Object removeAttribute(final String id) { 84 if (id == null) { 85 throw new IllegalArgumentException("Id may not be null"); 86 } 87 if (this.map != null) { 88 return this.map.remove(id); 89 } else { 90 return null; 91 } 92 } 93 94 }