|
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.ProtocolVersion; |
|
33 import ch.boye.httpclientandroidlib.StatusLine; |
|
34 |
|
35 /** |
|
36 * Basic implementation of {@link StatusLine} |
|
37 * |
|
38 * @version $Id: BasicStatusLine.java 986952 2010-08-18 21:24:55Z olegk $ |
|
39 * |
|
40 * @since 4.0 |
|
41 */ |
|
42 public class BasicStatusLine implements StatusLine, Cloneable, Serializable { |
|
43 |
|
44 private static final long serialVersionUID = -2443303766890459269L; |
|
45 |
|
46 // ----------------------------------------------------- Instance Variables |
|
47 |
|
48 /** The protocol version. */ |
|
49 private final ProtocolVersion protoVersion; |
|
50 |
|
51 /** The status code. */ |
|
52 private final int statusCode; |
|
53 |
|
54 /** The reason phrase. */ |
|
55 private final String reasonPhrase; |
|
56 |
|
57 // ----------------------------------------------------------- Constructors |
|
58 /** |
|
59 * Creates a new status line with the given version, status, and reason. |
|
60 * |
|
61 * @param version the protocol version of the response |
|
62 * @param statusCode the status code of the response |
|
63 * @param reasonPhrase the reason phrase to the status code, or |
|
64 * <code>null</code> |
|
65 */ |
|
66 public BasicStatusLine(final ProtocolVersion version, int statusCode, |
|
67 final String reasonPhrase) { |
|
68 super(); |
|
69 if (version == null) { |
|
70 throw new IllegalArgumentException |
|
71 ("Protocol version may not be null."); |
|
72 } |
|
73 if (statusCode < 0) { |
|
74 throw new IllegalArgumentException |
|
75 ("Status code may not be negative."); |
|
76 } |
|
77 this.protoVersion = version; |
|
78 this.statusCode = statusCode; |
|
79 this.reasonPhrase = reasonPhrase; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------- Public Methods |
|
83 |
|
84 public int getStatusCode() { |
|
85 return this.statusCode; |
|
86 } |
|
87 |
|
88 public ProtocolVersion getProtocolVersion() { |
|
89 return this.protoVersion; |
|
90 } |
|
91 |
|
92 public String getReasonPhrase() { |
|
93 return this.reasonPhrase; |
|
94 } |
|
95 |
|
96 public String toString() { |
|
97 // no need for non-default formatting in toString() |
|
98 return BasicLineFormatter.DEFAULT |
|
99 .formatStatusLine(null, this).toString(); |
|
100 } |
|
101 |
|
102 public Object clone() throws CloneNotSupportedException { |
|
103 return super.clone(); |
|
104 } |
|
105 |
|
106 } |