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: package gov.nist.javax.sdp;
026:
027: import gov.nist.javax.sdp.fields.*;
028: import java.util.*;
029:
030: /**
031: * Implementation of Time Description
032: *
033: * @version JAIN-SIP-1.1
034: *
035: *
036: *<a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
037: *
038: */
039: public class TimeDescriptionImpl {
040: /** Time field. */
041: private TimeField timeImpl;
042: /** Vector of repeat times. */
043: private Vector repeatList;
044:
045: /** Creates new TimeDescriptionImpl */
046: public TimeDescriptionImpl() {
047: timeImpl = new TimeField();
048: repeatList = new Vector();
049:
050: }
051:
052: /**
053: * Constructs a time description with an initial time field.
054: * @param timeField to set
055: */
056: public TimeDescriptionImpl(TimeField timeField) {
057: this .timeImpl = timeField;
058: repeatList = new Vector();
059: }
060:
061: /**
062: * Returns the Time field.
063: * @return Time
064: */
065: public TimeField getTime() {
066: return timeImpl;
067: }
068:
069: /**
070: * Sets the Time field.
071: * @param timeField Time to set
072: * @throws SdpException if the time is null
073: */
074: public void setTime(TimeField timeField) throws SdpException {
075: if (timeField == null) {
076: throw new SdpException("The parameter is null");
077: } else {
078: if (timeField instanceof TimeField) {
079: this .timeImpl = (TimeField) timeField;
080: } else
081: throw new SdpException(
082: "The parameter is not an instance of TimeField");
083: }
084: }
085:
086: /**
087: * Returns the list of repeat times (r= fields)
088: * specified in the SessionDescription.
089: * @param create boolean to set
090: * @return Vector
091: */
092: public Vector getRepeatTimes(boolean create) {
093: return this .repeatList;
094: }
095:
096: /**
097: * Returns the list of repeat times (r= fields)
098: * specified in the SessionDescription.
099: * @param repeatTimes Vector to set
100: * @throws SdpException if the parameter is null
101: */
102: public void setRepeatTimes(Vector repeatTimes) throws SdpException {
103: this .repeatList = repeatTimes;
104: }
105:
106: /**
107: * Adds a repeat field.
108: * @param repeatField repeat field to add.
109: */
110: public void addRepeatField(RepeatField repeatField) {
111: if (repeatField == null)
112: throw new NullPointerException("null repeatField");
113: this .repeatList.addElement(repeatField);
114: }
115:
116: /**
117: * Encodes contents as a string.
118: * @return encoded string of object contents
119: */
120: public String toString() {
121: String retval = timeImpl.encode();
122: for (int i = 0; i < this .repeatList.size(); i++) {
123: RepeatField repeatField = (RepeatField) this.repeatList
124: .elementAt(i);
125: retval += repeatField.encode();
126: }
127: return retval;
128: }
129:
130: }
|