001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/message/AbstractHttpMessage.java $
003: * $Revision: 610464 $
004: * $Date: 2008-01-09 18:10:55 +0100 (Wed, 09 Jan 2008) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.message;
033:
034: import java.util.Iterator;
035:
036: import org.apache.http.Header;
037: import org.apache.http.HeaderIterator;
038: import org.apache.http.HttpMessage;
039: import org.apache.http.params.HttpParams;
040: import org.apache.http.params.BasicHttpParams;
041:
042: /**
043: * Basic implementation of an HTTP message that can be modified.
044: *
045: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
046: *
047: * @version $Revision: 610464 $
048: *
049: * @since 4.0
050: */
051: public abstract class AbstractHttpMessage implements HttpMessage {
052:
053: private final HeaderGroup headergroup;
054:
055: private HttpParams params;
056:
057: protected AbstractHttpMessage(final HttpParams params) {
058: super ();
059: this .headergroup = new HeaderGroup();
060: this .params = params;
061: }
062:
063: protected AbstractHttpMessage() {
064: this (null);
065: }
066:
067: // non-javadoc, see interface HttpMessage
068: public boolean containsHeader(String name) {
069: return this .headergroup.containsHeader(name);
070: }
071:
072: // non-javadoc, see interface HttpMessage
073: public Header[] getHeaders(final String name) {
074: return this .headergroup.getHeaders(name);
075: }
076:
077: // non-javadoc, see interface HttpMessage
078: public Header getFirstHeader(final String name) {
079: return this .headergroup.getFirstHeader(name);
080: }
081:
082: // non-javadoc, see interface HttpMessage
083: public Header getLastHeader(final String name) {
084: return this .headergroup.getLastHeader(name);
085: }
086:
087: // non-javadoc, see interface HttpMessage
088: public Header[] getAllHeaders() {
089: return this .headergroup.getAllHeaders();
090: }
091:
092: // non-javadoc, see interface HttpMessage
093: public void addHeader(final Header header) {
094: this .headergroup.addHeader(header);
095: }
096:
097: // non-javadoc, see interface HttpMessage
098: public void addHeader(final String name, final String value) {
099: if (name == null) {
100: throw new IllegalArgumentException(
101: "Header name may not be null");
102: }
103: this .headergroup.addHeader(new BasicHeader(name, value));
104: }
105:
106: // non-javadoc, see interface HttpMessage
107: public void setHeader(final Header header) {
108: this .headergroup.updateHeader(header);
109: }
110:
111: // non-javadoc, see interface HttpMessage
112: public void setHeader(final String name, final String value) {
113: if (name == null) {
114: throw new IllegalArgumentException(
115: "Header name may not be null");
116: }
117: this .headergroup.updateHeader(new BasicHeader(name, value));
118: }
119:
120: // non-javadoc, see interface HttpMessage
121: public void setHeaders(final Header[] headers) {
122: this .headergroup.setHeaders(headers);
123: }
124:
125: // non-javadoc, see interface HttpMessage
126: public void removeHeader(final Header header) {
127: this .headergroup.removeHeader(header);
128: }
129:
130: // non-javadoc, see interface HttpMessage
131: public void removeHeaders(final String name) {
132: if (name == null) {
133: return;
134: }
135: for (Iterator i = this .headergroup.iterator(); i.hasNext();) {
136: Header header = (Header) i.next();
137: if (name.equalsIgnoreCase(header.getName())) {
138: i.remove();
139: }
140: }
141: }
142:
143: // non-javadoc, see interface HttpMessage
144: public HeaderIterator headerIterator() {
145: return this .headergroup.iterator();
146: }
147:
148: // non-javadoc, see interface HttpMessage
149: public HeaderIterator headerIterator(String name) {
150: return this .headergroup.iterator(name);
151: }
152:
153: // non-javadoc, see interface HttpMessage
154: public HttpParams getParams() {
155: if (this .params == null) {
156: this .params = new BasicHttpParams();
157: }
158: return this .params;
159: }
160:
161: // non-javadoc, see interface HttpMessage
162: public void setParams(final HttpParams params) {
163: if (params == null) {
164: throw new IllegalArgumentException(
165: "HTTP parameters may not be null");
166: }
167: this.params = params;
168: }
169: }
|