001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package gov.nist.siplite.header;
028:
029: import gov.nist.core.*;
030:
031: /**
032: * RSeq Header.
033: *
034: * The RSeq header is used in provisional responses in order to transmit
035: * them reliably. For details please see RFC 3262, section 7.1
036: */
037: public class RSeqHeader extends ParameterLessHeader {
038:
039: /**
040: * Sequence number field.
041: */
042: protected Integer seqNum;
043:
044: /** Sequence number header field label. */
045: public static final String NAME = Header.RSEQ;
046:
047: /** Handle for class. */
048: protected static Class clazz;
049:
050: static {
051: clazz = new RSeqHeader().getClass();
052: }
053:
054: /**
055: * Default constructor.
056: */
057: public RSeqHeader() {
058: super (RSEQ);
059: seqNum = new Integer(0);
060: }
061:
062: /**
063: * Constructor given a seq number.
064: * @param num the initial sequence number
065: */
066: public RSeqHeader(int num) {
067: super (RSEQ);
068: seqNum = new Integer(num);
069: headerValue = String.valueOf(num);
070: }
071:
072: /**
073: * Gets the sequence number header field.
074: * @return the sequence number
075: */
076: public int getRSeqNum() {
077: return seqNum.intValue();
078: }
079:
080: /**
081: * Sets the sequence number member.
082: * @param num sequence number to be set
083: */
084: public void setRSeqNum(int num) throws IllegalArgumentException {
085: if (num < 0)
086: throw new IllegalArgumentException("parameter is <0");
087:
088: seqNum = new Integer(num);
089: headerValue = String.valueOf(num);
090: }
091:
092: /**
093: * Encodes into a canonical string.
094: * @return String
095: */
096: public String encodeBody() {
097: if (seqNum == null)
098: return "0";
099: else
100: return seqNum.toString();
101: }
102:
103: /**
104: * Copies the current instance.
105: * @return copy of the current object
106: */
107: public Object clone() {
108: RSeqHeader retval = new RSeqHeader();
109:
110: if (seqNum != null) {
111: retval.seqNum = new Integer(seqNum.intValue());
112: }
113:
114: return retval;
115: }
116:
117: /**
118: * Gets the sequence number header value.
119: * @return the sequence number
120: */
121: public Object getValue() {
122: return this .seqNum;
123: }
124:
125: /**
126: * Sets the header value field.
127: * @param value is the value field to set.
128: * @throws IllegalArgumentException if the value is invalid.
129: */
130: public void setHeaderValue(String value)
131: throws IllegalArgumentException {
132: int val;
133:
134: try {
135: val = Integer.parseInt(value);
136: setRSeqNum(val);
137: } catch (IllegalArgumentException iae) {
138: throw iae;
139: }
140: }
141: }
|