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:
031: /**
032: * Expires SIP Header.
033: *
034: * @version JAIN-SIP-1.1
035: *
036: *
037: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
038: *
039: * IMPL_NOTE: think about removing the specific parser for ExpiresHeader.
040: *
041: */
042: public class ExpiresHeader extends ParameterLessHeader {
043:
044: /**
045: * Expires field.
046: */
047: protected Integer expires;
048:
049: /** Expires header field label. */
050: public static final String NAME = Header.EXPIRES;
051:
052: /** Class handle. */
053: public static Class clazz;
054:
055: static {
056: clazz = new ExpiresHeader().getClass();
057: }
058:
059: /**
060: * Default constructor.
061: */
062: public ExpiresHeader() {
063: super (EXPIRES);
064: }
065:
066: /**
067: * Returns canonical form.
068: * @return String
069: */
070: public String encodeBody() {
071: return expires.toString();
072: }
073:
074: /**
075: * Gets the expires value of the ExpiresHeader. This expires value is
076: *
077: * relative time.
078: *
079: *
080: *
081: * @return the expires value of the ExpiresHeader.
082: *
083: * @since JAIN SIP v1.1
084: *
085: */
086: public int getExpires() {
087: return expires.intValue();
088: }
089:
090: /**
091: * Sets the relative expires value of the ExpiresHeader.
092: * The expires value MUST be greater than zero and MUST be
093: * less than 2**31.
094: *
095: * @param expires - the new expires value of this ExpiresHeader
096: *
097: * @throws InvalidArgumentException if supplied value is less than zero.
098: *
099: * @since JAIN SIP v1.1
100: *
101: */
102: public void setExpires(int expires) throws IllegalArgumentException {
103: if (expires < 0)
104: throw new IllegalArgumentException("bad argument "
105: + expires);
106: this .expires = new Integer(expires);
107: }
108:
109: /**
110: * Gets the value for the header as opaque object (returned value
111: * will depend upon the header. Note that this is not the same as
112: * the getHeaderValue above.
113: * @return the expires header field value
114: */
115: public Object getValue() {
116: return expires;
117: }
118:
119: /**
120: * Sets the header value field.
121: * @param value is the value field to set.
122: * @throws IllegalArgumentException if the value is invalid.
123: */
124: public void setHeaderValue(String value)
125: throws IllegalArgumentException {
126: int val;
127:
128: try {
129: val = Integer.parseInt(value);
130: setExpires(val);
131: } catch (IllegalArgumentException iae) {
132: throw iae;
133: }
134: }
135:
136: }
|