~ubuntu-branches/ubuntu/trusty/httpcomponents-core/trusty

« back to all changes in this revision

Viewing changes to httpcore/src/main/java/org/apache/http/message/BasicStatusLine.java

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2010-06-12 08:37:34 UTC
  • Revision ID: james.westby@ubuntu.com-20100612083734-1y8kp6qm4sjk60az
Tags: upstream-4.0.1
ImportĀ upstreamĀ versionĀ 4.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/main/java/org/apache/http/message/BasicStatusLine.java $
 
3
 * $Revision: 728464 $
 
4
 * $Date: 2008-12-21 18:59:05 +0100 (Sun, 21 Dec 2008) $
 
5
 *
 
6
 * ====================================================================
 
7
 * Licensed to the Apache Software Foundation (ASF) under one
 
8
 * or more contributor license agreements.  See the NOTICE file
 
9
 * distributed with this work for additional information
 
10
 * regarding copyright ownership.  The ASF licenses this file
 
11
 * to you under the Apache License, Version 2.0 (the
 
12
 * "License"); you may not use this file except in compliance
 
13
 * with the License.  You may obtain a copy of the License at
 
14
 *
 
15
 *   http://www.apache.org/licenses/LICENSE-2.0
 
16
 *
 
17
 * Unless required by applicable law or agreed to in writing,
 
18
 * software distributed under the License is distributed on an
 
19
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
20
 * KIND, either express or implied.  See the License for the
 
21
 * specific language governing permissions and limitations
 
22
 * under the License.
 
23
 * ====================================================================
 
24
 *
 
25
 * This software consists of voluntary contributions made by many
 
26
 * individuals on behalf of the Apache Software Foundation.  For more
 
27
 * information on the Apache Software Foundation, please see
 
28
 * <http://www.apache.org/>.
 
29
 *
 
30
 */
 
31
 
 
32
package org.apache.http.message;
 
33
 
 
34
import org.apache.http.ProtocolVersion;
 
35
import org.apache.http.StatusLine;
 
36
 
 
37
/**
 
38
 * Basic implementation of {@link StatusLine}
 
39
 *
 
40
 * @version $Id: BasicStatusLine.java 728464 2008-12-21 17:59:05Z olegk $
 
41
 * 
 
42
 * @since 4.0
 
43
 */
 
44
public class BasicStatusLine implements StatusLine, Cloneable {
 
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
}