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:
031: /**
032: * Connection Address of the SDP header (appears as part of the
033: * Connection field).
034: *
035: *
036: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
037: *
038: */
039: public class ConnectionAddress extends SDPObject {
040: /** The host address. */
041: protected Host address;
042: /** Time to live. */
043: protected int ttl;
044: /** The target port. */
045: protected int port;
046:
047: /**
048: * Copies the current instance.
049: * @return the copy of this object
050: */
051: public Object clone() {
052: ConnectionAddress retval = new ConnectionAddress();
053: if (address != null)
054: retval.address = (Host) address.clone();
055: retval.ttl = ttl;
056: retval.port = port;
057: return retval;
058: }
059:
060: /**
061: * Gets the target host address.
062: * @return the host address
063: */
064: public Host getAddress() {
065: return address;
066: }
067:
068: /**
069: * Gets the time to live parameter.
070: * @return the time to live value
071: */
072: public int getTtl() {
073: return ttl;
074: }
075:
076: /**
077: * Gets the target port address.
078: * @return the port number
079: */
080: public int getPort() {
081: return port;
082: }
083:
084: /**
085: * Sets the address member.
086: * @param a the new value for address
087: */
088: public void setAddress(Host a) {
089: address = a;
090: }
091:
092: /**
093: * Sets the time to live member.
094: * @param ttl the new time to live value
095: */
096: public void setTtl(int ttl) {
097: this .ttl = ttl;
098: }
099:
100: /**
101: * Sets the port member.
102: * @param p the new target port number
103: */
104: public void setPort(int p) {
105: port = p;
106: }
107:
108: /**
109: * Gets the string encoded version of this object.
110: * @return the encode string of the object contents
111: * @since v1.0
112: */
113: public String encode() {
114: String encoded_string = "";
115:
116: if (address != null)
117: encoded_string = address.encode();
118: if (ttl != 0 && port != 0) {
119: encoded_string += Separators.SLASH + ttl + Separators.SLASH
120: + port;
121: } else if (ttl != 0) {
122: encoded_string += Separators.SLASH + ttl;
123: }
124: return encoded_string;
125: }
126:
127: }
|