/*
* Copyright (C) 2014 Stefano Fornari.
* All Rights Reserved. No use, copying or distribution of this
* work may be made except in accordance with a valid license
* agreement from Stefano Fornari. This notice must be
* included on all copies, modifications and derivatives of this
* work.
*
* STEFANO FORNARI MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. STEFANO FORNARI SHALL NOT BE LIABLE FOR ANY
* DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*/
package ste.web.http.message;
import java.io.Serializable;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.message.BasicLineFormatter;
public class BasicStatusLine implements StatusLine, Cloneable, Serializable {
private static final long serialVersionUID = -2443303766890459269L;
// ----------------------------------------------------- Instance Variables
/** The protocol version. */
private final ProtocolVersion protoVersion;
/** The status code. */
private int statusCode;
/** The reason phrase. */
private String reasonPhrase;
// ----------------------------------------------------------- Constructors
/**
* Creates a new status line with the given version, status, and reason.
*
* @param version the protocol version of the response
* @param statusCode the status code of the response
* @param reasonPhrase the reason phrase to the status code, or
* <code>null</code>
*/
public BasicStatusLine(final ProtocolVersion version, int statusCode,
final String reasonPhrase) {
super();
if (version == null) {
throw new IllegalArgumentException("protocol version can not be null");
}
setStatusCode(statusCode);
this.protoVersion = version;
this.reasonPhrase = reasonPhrase;
}
// --------------------------------------------------------- Public Methods
@Override
public int getStatusCode() {
return this.statusCode;
}
public void setStatusCode(final int statusCode) {
if (statusCode < 0) {
throw new IllegalArgumentException("status code can not be negative.");
}
this.statusCode = statusCode;
}
@Override
public ProtocolVersion getProtocolVersion() {
return this.protoVersion;
}
@Override
public String getReasonPhrase() {
return this.reasonPhrase;
}
@Override
public String toString() {
// no need for non-default formatting in toString()
return BasicLineFormatter.DEFAULT
.formatStatusLine(null, this).toString();
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}