com.radekzitek.userver.http
Class HttpVersion

java.lang.Object
  extended bycom.radekzitek.userver.http.HttpVersion
All Implemented Interfaces:
HttpObject

public class HttpVersion
extends java.lang.Object
implements HttpObject

HttpVersion represents the version of the HTTP protocol.

Author:
rzitek

Field Summary
private static java.util.regex.Pattern HTTP_VERSION_PATTERN
          Regular expression pattern used to parse the version string.
private static org.apache.log4j.Logger LOG
          Log4j logger.
private  int majorVersion
          Major vresion number.
private  int minorVersion
          Minor version number.
 
Constructor Summary
HttpVersion()
          Default HttpVersion constructor.
HttpVersion(int majorVersion, int minorVersion)
          Constructor used to set specific version numbers.
HttpVersion(java.lang.String versionString)
          Contructor used to set the version using the string present in the HTTP request message - HTTP/1.1 for example.
 
Method Summary
 void clear()
          Utility method used to set both major and minor version number to -1 signaling invalid state of the object.
 int getMajorVersion()
          Returns the major version number.
 int getMinorVersion()
          Returns the minor version number.
 void parse(java.lang.String versionString)
          Method used to set the version using the string present in the HTTP request message - HTTP/1.1 for example.
 void setMajorVersion(int majorVersion)
          Sets the major version number.
 void setMinorVersion(int minorVersion)
          Sets the minor version number.
 void setVersion(int majorVersion, int minorVersion)
          Sets both major and minor version number.
 java.lang.String toString()
          Converts the HttpVersion to the string as used in the HTTP request and response messahes - HTTP/1.1 for example.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HTTP_VERSION_PATTERN

private static final java.util.regex.Pattern HTTP_VERSION_PATTERN
Regular expression pattern used to parse the version string.


LOG

private static final org.apache.log4j.Logger LOG
Log4j logger.


majorVersion

private int majorVersion
Major vresion number.


minorVersion

private int minorVersion
Minor version number.

Constructor Detail

HttpVersion

public HttpVersion()
Default HttpVersion constructor. Both major and minor version numbers are set to -1 signaling invalid state of the HttpVersion object.


HttpVersion

public HttpVersion(int majorVersion,
                   int minorVersion)
Constructor used to set specific version numbers.

Parameters:
majorVersion - Major version number to set.
minorVersion - Minor version number to set.

HttpVersion

public HttpVersion(java.lang.String versionString)
            throws HttpVersionFormatException
Contructor used to set the version using the string present in the HTTP request message - HTTP/1.1 for example. The following regular expression is used to parse the string: "HTTP/(\d+)\.(\d+)"

Parameters:
versionString - String used to set the version. Format should be HTTP/m.n where m and n are integers.
Throws:
HttpVersionFormatException - Exception thrown if the parameter string does not match the regular expression above.
Method Detail

clear

public void clear()
Utility method used to set both major and minor version number to -1 signaling invalid state of the object.

Specified by:
clear in interface HttpObject

getMajorVersion

public int getMajorVersion()
Returns the major version number.

Returns:
this HttpVersion's major version number

getMinorVersion

public int getMinorVersion()
Returns the minor version number.

Returns:
this HttpVersion's minor version number

parse

public void parse(java.lang.String versionString)
           throws HttpVersionFormatException
Method used to set the version using the string present in the HTTP request message - HTTP/1.1 for example. The following regular expression is used to parse the string: "HTTP/(\d+)\.(\d+)" This method is available to set the version for already created object. It's used as well by the String based constructor.

Specified by:
parse in interface HttpObject
Parameters:
versionString - String used to set the version. Format should be HTTP/m.n where m and n are integers.
Throws:
HttpVersionFormatException - Exception thrown if the parameter string does not match the regular expression above.

setMajorVersion

public void setMajorVersion(int majorVersion)
Sets the major version number.

Parameters:
majorVersion - the new major version number

setMinorVersion

public void setMinorVersion(int minorVersion)
Sets the minor version number.

Parameters:
minorVersion - the new minor version number

setVersion

public void setVersion(int majorVersion,
                       int minorVersion)
Sets both major and minor version number.

Parameters:
majorVersion - the new major version number
minorVersion - the new minor version number

toString

public java.lang.String toString()
Converts the HttpVersion to the string as used in the HTTP request and response messahes - HTTP/1.1 for example.

Specified by:
toString in interface HttpObject
Returns:
String representation of the HTTP version. Returns null if the object is in invalid state (both version numbers set to -1).