001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/message/BasicStatusLine.java $
003: * $Revision: 604625 $
004: * $Date: 2007-12-16 15:11:11 +0100 (Sun, 16 Dec 2007) $
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 org.apache.http.HttpStatus;
035: import org.apache.http.ProtocolVersion;
036: import org.apache.http.StatusLine;
037:
038: /**
039: * Represents a status line as returned from a HTTP server.
040: * See <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a> section 6.1.
041: * This class is immutable and therefore inherently thread safe.
042: *
043: * @see HttpStatus
044: * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
045: * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
046: *
047: * @version $Id: BasicStatusLine.java 604625 2007-12-16 14:11:11Z olegk $
048: *
049: * @since 4.0
050: */
051: public class BasicStatusLine implements StatusLine, Cloneable {
052:
053: // ----------------------------------------------------- Instance Variables
054:
055: /** The protocol version. */
056: private final ProtocolVersion protoVersion;
057:
058: /** The status code. */
059: private final int statusCode;
060:
061: /** The reason phrase. */
062: private final String reasonPhrase;
063:
064: // ----------------------------------------------------------- Constructors
065: /**
066: * Creates a new status line with the given version, status, and reason.
067: *
068: * @param version the protocol version of the response
069: * @param statusCode the status code of the response
070: * @param reasonPhrase the reason phrase to the status code, or
071: * <code>null</code>
072: */
073: public BasicStatusLine(final ProtocolVersion version,
074: int statusCode, final String reasonPhrase) {
075: super ();
076: if (version == null) {
077: throw new IllegalArgumentException(
078: "Protocol version may not be null.");
079: }
080: if (statusCode < 0) {
081: throw new IllegalArgumentException(
082: "Status code may not be negative.");
083: }
084: this .protoVersion = version;
085: this .statusCode = statusCode;
086: this .reasonPhrase = reasonPhrase;
087: }
088:
089: // --------------------------------------------------------- Public Methods
090:
091: /**
092: * @return the Status-Code
093: */
094: public int getStatusCode() {
095: return this .statusCode;
096: }
097:
098: /**
099: * @return the HTTP-Version
100: */
101: public ProtocolVersion getProtocolVersion() {
102: return this .protoVersion;
103: }
104:
105: /**
106: * @return the Reason-Phrase
107: */
108: public String getReasonPhrase() {
109: return this .reasonPhrase;
110: }
111:
112: public String toString() {
113: // no need for non-default formatting in toString()
114: return BasicLineFormatter.DEFAULT.formatStatusLine(null, this )
115: .toString();
116: }
117:
118: public Object clone() throws CloneNotSupportedException {
119: return super.clone();
120: }
121:
122: }
|