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: * Connectin Field of the SDP request.
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 ConnectionField extends SDPField {
042: /** Network type. */
043: protected String nettype;
044: /** Address type. */
045: protected String addrtype;
046: /** Connection address. */
047: protected ConnectionAddress address;
048:
049: /**
050: * Copies the current instance.
051: * @return the copy of this object
052: */
053: public Object clone() {
054: ConnectionField retval = new ConnectionField();
055: retval.nettype = this .nettype;
056: retval.addrtype = this .addrtype;
057: if (this .address != null)
058: retval.address = (ConnectionAddress) this .address.clone();
059: return retval;
060: }
061:
062: /** Default constructor. */
063:
064: public ConnectionField() {
065: super (SDPFieldNames.CONNECTION_FIELD);
066: }
067:
068: /**
069: * Gets the network type.
070: * @return the network type
071: */
072: public String getNettype() {
073: return nettype;
074: }
075:
076: /**
077: * Gets the address type.
078: * @return the address type
079: */
080: public String getAddrtype() {
081: return addrtype;
082: }
083:
084: /**
085: * Gets the network connection address.
086: * @return the connection address
087: */
088: public ConnectionAddress getConnectionAddress() {
089: return address;
090: }
091:
092: /**
093: * Sets the network type member.
094: * @param n the new network type
095: */
096: public void setNettype(String n) {
097: nettype = n;
098: }
099:
100: /**
101: * Sets the address type member.
102: * @param a the new address type
103: */
104: public void setAddrType(String a) {
105: addrtype = a;
106: }
107:
108: /**
109: * Sets the address member.
110: * @param a the new connectio address
111: */
112: public void setAddress(ConnectionAddress a) {
113: address = a;
114: }
115:
116: /**
117: * Gets the string encoded version of this object.
118: * @return the encoded text string of this object contents
119: * @since v1.0
120: */
121: public String encode() {
122: String encoded_string = CONNECTION_FIELD;
123: if (nettype != null)
124: encoded_string += nettype;
125: if (addrtype != null)
126: encoded_string += Separators.SP + addrtype;
127: if (address != null)
128: encoded_string += Separators.SP + address.encode();
129: return encoded_string += Separators.NEWLINE;
130: }
131:
132: /**
133: * Encodes contents as a textstring.
134: * @return encoded string of object contents
135: */
136: public String toString() {
137: return this .encode();
138: }
139:
140: /**
141: * Returns the type of the network for this Connection.
142: * @throws SdpParseException if a parsing error occurs
143: * @return the type of the network
144: */
145: public String getAddress() throws SdpParseException {
146: ConnectionAddress connectionAddress = getConnectionAddress();
147: if (connectionAddress == null)
148: return null;
149: else {
150: Host host = connectionAddress.getAddress();
151: if (host == null)
152: return null;
153: else
154: return host.getAddress();
155: }
156: }
157:
158: /**
159: * Returns the type of the address for this Connection.
160: * @throws SdpParseException if a parsing error occurs
161: * @return the type of the address
162: */
163: public String getAddressType() throws SdpParseException {
164: return getAddrtype();
165: }
166:
167: /**
168: * Returns the type of the network for this Connection.
169: * @throws SdpParseException if a parsing error occurs
170: * @return the type of the network
171: */
172: public String getNetworkType() throws SdpParseException {
173: return getNettype();
174: }
175:
176: /**
177: * Sets the type of the address for this Connection.
178: * @param addr to set
179: * @throws SdpException if the type is null
180: */
181: public void setAddress(String addr) throws SdpException {
182: if (addr == null)
183: throw new SdpException("the addr is null");
184: else {
185: if (address == null) {
186: address = new ConnectionAddress();
187: Host host = new Host(addr);
188: address.setAddress(host);
189: } else {
190: Host host = address.getAddress();
191: if (host == null) {
192: host = new Host(addr);
193: address.setAddress(host);
194: } else
195: host.setAddress(addr);
196: }
197: setAddress(address);
198: }
199: }
200:
201: /**
202: * Returns the type of the network for this Connection.
203: * @param type to set
204: * @throws SdpException if the type is null
205: */
206: public void setAddressType(String type) throws SdpException {
207: if (type == null)
208: throw new SdpException("the type is null");
209: this .addrtype = type;
210: }
211:
212: /**
213: * Sets the type of the network for this Connection.
214: * @param type to set
215: * @throws SdpException if the type is null
216: */
217: public void setNetworkType(String type) throws SdpException {
218: if (type == null)
219: throw new SdpException("the type is null");
220: else
221: setNettype(type);
222: }
223:
224: }
|