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 gov.nist.javax.sdp.*;
031:
032: /**
033: * Bandwidth field of a SDP header.
034: *
035: * @version JSR141-PUBLIC-REVIEW (Subject to change)
036: *
037: *
038: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
039: *
040: */
041: public class BandwidthField extends SDPField {
042: /** Bandwidth type. */
043: protected String bwtype;
044: /** Current bandwidth. */
045: protected int bandwidth;
046:
047: /**
048: * Copies the current instance.
049: * @return the copy of this object
050: */
051: public Object clone() {
052: BandwidthField bf = new BandwidthField();
053: bf.bwtype = bwtype;
054: bf.bandwidth = bandwidth;
055: return bf;
056: }
057:
058: /** Default constructor. */
059: public BandwidthField() {
060: super (SDPFieldNames.BANDWIDTH_FIELD);
061: }
062:
063: /**
064: * Gets the current bandwidth type.
065: * @return the bandwidth type
066: */
067: public String getBwtype() {
068: return bwtype;
069: }
070:
071: /**
072: * Gets the current bandwith.
073: * @return the bandwidth
074: */
075: public int getBandwidth() {
076: return bandwidth;
077: }
078:
079: /**
080: * Sets the bandwidth type member.
081: * @param b the new value for band width type
082: */
083: public void setBwtype(String b) {
084: bwtype = b;
085: }
086:
087: /**
088: * Sets the bandwidth member.
089: * @param b the new value for bandwidth
090: */
091: public void setBandwidth(int b) {
092: bandwidth = b;
093: }
094:
095: /**
096: * Gets the string encoded version of this object.
097: * @return the encoded string contents
098: * @since v1.0
099: */
100: public String encode() {
101: String encoded_string = BANDWIDTH_FIELD;
102:
103: if (bwtype != null)
104: encoded_string += bwtype + Separators.COLON;
105: return encoded_string + bandwidth + Separators.NEWLINE;
106: }
107:
108: /**
109: * Returns the bandwidth type.
110: * @throws SdpParseException if a parsing error occurs
111: * @return type
112: */
113: public String getType() throws SdpParseException {
114: return getBwtype();
115: }
116:
117: /**
118: * Sets the bandwidth type.
119: * @param type to set
120: * @throws SdpException if the type is null
121: */
122: public void setType(String type) throws SdpException {
123: if (type == null)
124: throw new SdpException("The type is null");
125: else
126: setBwtype(type);
127: }
128:
129: /**
130: * Returns the bandwidth value measured in kilobits per second.
131: * @throws SdpParseException if a parsing error occurs
132: * @return the bandwidth value
133: */
134: public int getValue() throws SdpParseException {
135: return getBandwidth();
136: }
137:
138: /**
139: * Sets the bandwidth value.
140: * @param value to set
141: * @throws SdpException if the value cannot be set
142: */
143: public void setValue(int value) throws SdpException {
144: setBandwidth(value);
145: }
146:
147: }
|