001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: /*
026: */
027: package gov.nist.siplite.header;
028:
029: import gov.nist.core.*;
030: import gov.nist.siplite.*;
031:
032: /**
033: * Status Line (for SIPReply) messages.
034: *
035: * @version JAIN-SIP-1.1
036: *
037: *
038: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
039: */
040: public final class StatusLine extends GenericObject {
041: /**
042: * SipVersion field.
043: */
044: protected String sipVersion;
045:
046: /**
047: * Status code field.
048: */
049: protected int statusCode;
050:
051: /**
052: * Reason phrase field.
053: */
054: protected String reasonPhrase;
055:
056: /**
057: * Default Constructor.
058: */
059: public StatusLine() {
060: reasonPhrase = null;
061: sipVersion = SIPConstants.SIP_VERSION_STRING;
062: }
063:
064: /** Class handle. */
065: public static Class clazz;
066:
067: static {
068: clazz = new StatusLine().getClass();
069: }
070:
071: /**
072: * Encodes into a canonical form.
073: * @return String
074: */
075: public String encode() {
076: String encoding = SIPConstants.SIP_VERSION_STRING
077: + Separators.SP + statusCode;
078: if (reasonPhrase != null)
079: encoding += Separators.SP + reasonPhrase;
080: encoding += Separators.NEWLINE;
081: return encoding;
082: }
083:
084: /**
085: * Gets the Sip Version.
086: * @return SipVersion
087: */
088: public String getSipVersion() {
089: return sipVersion;
090: }
091:
092: /**
093: * Gets the Status Code.
094: * @return StatusCode
095: */
096: public int getStatusCode() {
097: return statusCode;
098: }
099:
100: /**
101: * Gets the ReasonPhrase field.
102: * @return ReasonPhrase field
103: */
104: public String getReasonPhrase() {
105: return reasonPhrase;
106: }
107:
108: /**
109: * Sets the sipVersion member.
110: * @param s String to set
111: */
112: public void setSipVersion(String s) {
113: sipVersion = s;
114: }
115:
116: /**
117: * Sets the statusCode member.
118: * @param statusCode int to set
119: */
120: public void setStatusCode(int statusCode) {
121: this .statusCode = statusCode;
122: }
123:
124: /**
125: * Set the reasonPhrase member.
126: * @param reasonPhrase String to set
127: */
128: public void setReasonPhrase(String reasonPhrase) {
129: this .reasonPhrase = reasonPhrase;
130: }
131:
132: /**
133: * Gets the major version number.
134: * @return String major version number
135: */
136: public String getVersionMajor() {
137: if (sipVersion == null)
138: return null;
139: String major = null;
140: boolean slash = false;
141: for (int i = 0; i < sipVersion.length(); i++) {
142: if (sipVersion.charAt(i) == '.')
143: slash = false;
144: if (slash) {
145: if (major == null)
146: major = "" + sipVersion.charAt(i);
147: else
148: major += sipVersion.charAt(i);
149: }
150: if (sipVersion.charAt(i) == '/')
151: slash = true;
152: }
153: return major;
154: }
155:
156: /**
157: * Gets the minor version number.
158: * @return String minor version number
159: */
160: public String getVersionMinor() {
161: if (sipVersion == null)
162: return null;
163: String minor = null;
164: boolean dot = false;
165: for (int i = 0; i < sipVersion.length(); i++) {
166: if (dot) {
167: if (minor == null)
168: minor = "" + sipVersion.charAt(i);
169: else
170: minor += sipVersion.charAt(i);
171: }
172: if (sipVersion.charAt(i) == '.')
173: dot = true;
174: }
175: return minor;
176: }
177:
178: /**
179: * Copies the current instance.
180: * @return copy of the current objectt
181: */
182: public Object clone() {
183: StatusLine retval = new StatusLine();
184:
185: if (this .sipVersion != null)
186: retval.sipVersion = new String(this .sipVersion);
187:
188: retval.statusCode = this .statusCode;
189:
190: if (this .reasonPhrase != null)
191: retval.reasonPhrase = new String(this .reasonPhrase);
192:
193: return retval;
194:
195: }
196:
197: /**
198: * Compares this instance to the requested object.
199: * @param that object for comparison
200: * @return true if the object matches.
201: */
202: public boolean equals(Object that) {
203: if (that instanceof StatusLine)
204: return this .statusCode == ((StatusLine) that).statusCode;
205: else
206: return false;
207: }
208:
209: }
|