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.javax.sdp.fields;
028:
029: import gov.nist.core.*;
030: import java.util.*;
031: import gov.nist.javax.sdp.*;
032:
033: /**
034: * Time Field.
035: * @version JSR141-PUBLIC-REVIEW (subject to change).
036: *
037: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
038: *
039: */
040: public class TimeField extends SDPField {
041: /** Start time. */
042: protected long startTime;
043: /** Stop time. */
044: protected long stopTime;
045:
046: /** Default constructor. */
047: public TimeField() {
048: super (TIME_FIELD);
049: }
050:
051: /**
052: * Gets the start time.
053: * @return start time
054: */
055: public long getStartTime() {
056: return startTime;
057: }
058:
059: /**
060: * Gets the stop time.
061: * @return start stop time
062: */
063: public long getStopTime() {
064: return stopTime;
065: }
066:
067: /**
068: * Sets the start time member.
069: * @param startTime tthe new start time
070: */
071: public void setStartTime(long startTime) {
072: this .startTime = startTime;
073: }
074:
075: /**
076: * Sets the stop time member.
077: * @param stopTime the new stop mtime
078: */
079: public void setStopTime(long stopTime) {
080: this .stopTime = stopTime;
081: }
082:
083: /**
084: * Returns the start time of the conference/session.
085: * @throws SdpParseException if a parsing error occurs
086: * @return the date
087: */
088: public Date getStart() throws SdpParseException {
089: return new Date(startTime * 1000 + SdpConstants.NTP_CONST);
090: }
091:
092: /**
093: * Returns the stop time of the session.
094: * @throws SdpParseException if a parsing error occurs
095: * @return the stop time of the session.
096: */
097: public Date getStop() throws SdpParseException {
098: return new Date(stopTime * 1000 + SdpConstants.NTP_CONST);
099: }
100:
101: /**
102: * Sets the stop time of the session.
103: * @param stop the new stop time
104: * @throws SdpException if the date is null
105: */
106: public void setStop(Date stop) throws SdpException {
107: if (stop == null)
108: throw new SdpException("The date is null");
109: else {
110: this .stopTime = stop.getTime() / 1000
111: - SdpConstants.NTP_CONST;
112: }
113: }
114:
115: /**
116: * Sets the start time of the conference/session.
117: * @param start the new start time for the session.
118: * @throws SdpException if the date is null
119: */
120: public void setStart(Date start) throws SdpException {
121: if (start == null)
122: throw new SdpException("The date is null");
123: else {
124: this .startTime = start.getTime() / 1000
125: - SdpConstants.NTP_CONST;
126: }
127: }
128:
129: /**
130: * Returns whether the field will be output as a typed time
131: * or a integer value.
132: *
133: * Typed time is formatted as an integer followed by a unit character.
134: * The unit indicates an appropriate multiplier for
135: * the integer.
136: *
137: * The following unit types are allowed.
138: * <pre>
139: * d - days (86400 seconds)
140: * h - hours (3600 seconds)
141: * m - minutes (60 seconds)
142: * s - seconds ( 1 seconds)
143: * </pre>
144: * @return true, if the field will be output as a
145: * typed time; false, if as an integer value.
146: */
147: public boolean getTypedTime() {
148: return false;
149: }
150:
151: /**
152: * Sets whether the field will be output as a typed time or a integer value.
153: *
154: * Typed time is formatted as an integer followed by a unit character.
155: * The unit indicates an appropriate multiplier for
156: * the integer.
157: *
158: * The following unit types are allowed.
159: * <pre>
160: * d - days (86400 seconds)
161: * h - hours (3600 seconds)
162: * m - minutes (60 seconds)
163: * s - seconds ( 1 seconds)
164: * </pre>
165: * @param typedTime if set true, the start and stop times will
166: * be output in an optimal typed time format; if false, the
167: * times will be output as integers.
168: */
169: public void setTypedTime(boolean typedTime) {
170:
171: }
172:
173: /**
174: * Returns whether the start and stop times were set to zero (in NTP).
175: * @return true if tsrat or stop time are zero
176: */
177: public boolean isZero() {
178: long stopTime = getStopTime();
179: long startTime = getStartTime();
180: if (stopTime == 0 && startTime == 0)
181: return true;
182: else
183: return false;
184: }
185:
186: /**
187: * Sets the start and stop times to zero (in NTP).
188: */
189: public void setZero() {
190: setStopTime(0);
191: setStartTime(0);
192: }
193:
194: /**
195: * Gets the string encoded version of this object.
196: * @return encoded string of object contents
197: * @since v1.0
198: */
199: public String encode() {
200: return new StringBuffer().append(TIME_FIELD).append(startTime)
201: .append(Separators.SP).append(stopTime).append(
202: Separators.NEWLINE).toString();
203: }
204:
205: /**
206: * Copies the current instance.
207: * @return the copy of this object
208: */
209: public Object clone() {
210: TimeField retval = new TimeField();
211: retval.startTime = this.startTime;
212: retval.stopTime = this.stopTime;
213: return retval;
214: }
215:
216: }
|