001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.transport.http;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import java.util.Collection;
024: import java.util.Enumeration;
025: import java.util.HashMap;
026: import java.util.Map;
027: import java.util.Set;
028:
029: /**
030: * Pass-Thru / delayed get of the values from HttpServletRequest
031: */
032: public class TransportHeaders implements Map {
033: HttpServletRequest req;
034: HashMap headerMap = null;
035:
036: public TransportHeaders(HttpServletRequest req) {
037: this .req = req;
038: }
039:
040: private void init() {
041: headerMap = new HashMap();
042: Enumeration headerNames = req.getHeaderNames();
043:
044: while (headerNames.hasMoreElements()) {
045: String key = (String) headerNames.nextElement();
046: String value = req.getHeader(key);
047:
048: headerMap.put(key, value);
049: }
050: }
051:
052: public int size() {
053: if (headerMap == null) {
054: init();
055: }
056: return headerMap.size();
057: }
058:
059: public void clear() {
060: if (headerMap != null) {
061: headerMap.clear();
062: }
063: }
064:
065: public boolean isEmpty() {
066: if (headerMap == null) {
067: init();
068: }
069: return headerMap.isEmpty();
070: }
071:
072: public boolean containsKey(Object key) {
073: if (headerMap == null) {
074: init();
075: }
076: return headerMap.containsKey(key);
077: }
078:
079: public boolean containsValue(Object value) {
080: if (headerMap == null) {
081: init();
082: }
083: return headerMap.containsValue(value);
084: }
085:
086: public Collection values() {
087: if (headerMap == null) {
088: init();
089: }
090: return headerMap.values();
091: }
092:
093: public void putAll(Map t) {
094: if (headerMap == null) {
095: init();
096: }
097: headerMap.putAll(t);
098: }
099:
100: public Set entrySet() {
101: if (headerMap == null) {
102: init();
103: }
104: return headerMap.entrySet();
105: }
106:
107: public Set keySet() {
108: if (headerMap == null) {
109: init();
110: }
111: return headerMap.keySet();
112: }
113:
114: public Object get(Object key) {
115: if (headerMap == null) {
116: return req.getHeader((String) key);
117: }
118: return headerMap.get(key);
119: }
120:
121: public Object remove(Object key) {
122: if (headerMap == null) {
123: init();
124: }
125: return headerMap.remove(key);
126: }
127:
128: public Object put(Object key, Object value) {
129: if (headerMap == null) {
130: init();
131: }
132: return headerMap.put(key, value);
133: }
134: }
|