|
1 /* |
|
2 * ==================================================================== |
|
3 * Licensed to the Apache Software Foundation (ASF) under one |
|
4 * or more contributor license agreements. See the NOTICE file |
|
5 * distributed with this work for additional information |
|
6 * regarding copyright ownership. The ASF licenses this file |
|
7 * to you under the Apache License, Version 2.0 (the |
|
8 * "License"); you may not use this file except in compliance |
|
9 * with the License. You may obtain a copy of the License at |
|
10 * |
|
11 * http://www.apache.org/licenses/LICENSE-2.0 |
|
12 * |
|
13 * Unless required by applicable law or agreed to in writing, |
|
14 * software distributed under the License is distributed on an |
|
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
16 * KIND, either express or implied. See the License for the |
|
17 * specific language governing permissions and limitations |
|
18 * under the License. |
|
19 * ==================================================================== |
|
20 * |
|
21 * This software consists of voluntary contributions made by many |
|
22 * individuals on behalf of the Apache Software Foundation. For more |
|
23 * information on the Apache Software Foundation, please see |
|
24 * <http://www.apache.org/>. |
|
25 * |
|
26 */ |
|
27 |
|
28 package ch.boye.httpclientandroidlib.message; |
|
29 |
|
30 import java.io.Serializable; |
|
31 |
|
32 import ch.boye.httpclientandroidlib.Header; |
|
33 import ch.boye.httpclientandroidlib.HeaderElement; |
|
34 import ch.boye.httpclientandroidlib.ParseException; |
|
35 |
|
36 /** |
|
37 * Basic implementation of {@link Header}. |
|
38 * |
|
39 * @since 4.0 |
|
40 */ |
|
41 public class BasicHeader implements Header, Cloneable, Serializable { |
|
42 |
|
43 private static final long serialVersionUID = -5427236326487562174L; |
|
44 |
|
45 private final String name; |
|
46 private final String value; |
|
47 |
|
48 /** |
|
49 * Constructor with name and value |
|
50 * |
|
51 * @param name the header name |
|
52 * @param value the header value |
|
53 */ |
|
54 public BasicHeader(final String name, final String value) { |
|
55 super(); |
|
56 if (name == null) { |
|
57 throw new IllegalArgumentException("Name may not be null"); |
|
58 } |
|
59 this.name = name; |
|
60 this.value = value; |
|
61 } |
|
62 |
|
63 public String getName() { |
|
64 return this.name; |
|
65 } |
|
66 |
|
67 public String getValue() { |
|
68 return this.value; |
|
69 } |
|
70 |
|
71 public String toString() { |
|
72 // no need for non-default formatting in toString() |
|
73 return BasicLineFormatter.DEFAULT.formatHeader(null, this).toString(); |
|
74 } |
|
75 |
|
76 public HeaderElement[] getElements() throws ParseException { |
|
77 if (this.value != null) { |
|
78 // result intentionally not cached, it's probably not used again |
|
79 return BasicHeaderValueParser.parseElements(this.value, null); |
|
80 } else { |
|
81 return new HeaderElement[] {}; |
|
82 } |
|
83 } |
|
84 |
|
85 public Object clone() throws CloneNotSupportedException { |
|
86 return super.clone(); |
|
87 } |
|
88 |
|
89 } |