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.siplite.address;
026:
027: import java.util.Vector;
028:
029: /**
030: * Implementation of the TelURL interface.
031: *
032: * @version JAIN-SIP-1.1
033: *
034: *
035: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
036: *
037: */
038: public class TelURL extends URI {
039:
040: /** Currrent telephone portion of URI. */
041: protected TelephoneNumber telephoneNumber;
042:
043: /** Creates a new instance of TelURLImpl */
044: public TelURL() {
045: this .scheme = "tel";
046: }
047:
048: /**
049: * Sets the telephone number.
050: * @param telephoneNumber telephone number to set.
051: */
052:
053: public void setTelephoneNumber(TelephoneNumber telephoneNumber) {
054: this .telephoneNumber = telephoneNumber;
055: }
056:
057: /**
058: * Returns the value of the <code>isdnSubAddress</code> parameter, or null
059: * if it is not set.
060: *
061: * @return the value of the <code>isdnSubAddress</code> parameter
062: */
063: public String getIsdnSubAddress() {
064: return telephoneNumber.getIsdnSubaddress();
065: }
066:
067: /**
068: * Returns the value of the <code>postDial</code> parameter, or null if it
069: * is not set.
070: *
071: * @return the value of the <code>postDial</code> parameter
072: */
073: public String getPostDial() {
074: return telephoneNumber.getPostDial();
075: }
076:
077: /**
078: * Returns <code>true</code> if this TelURL is global i.e. if the TelURI
079: * has a global phone user.
080: *
081: * @return <code>true</code> if this TelURL represents a global phone user,
082: * and <code>false</code> otherwise.
083: */
084: public boolean isGlobal() {
085: return telephoneNumber.isGlobal();
086: }
087:
088: /**
089: * This method determines if this is a URI with a scheme of "sip"
090: * or "sips".
091: *
092: * @return true if the scheme is "sip" or "sips", false otherwise.
093: */
094: public boolean isSipURI() {
095: return false;
096: }
097:
098: /**
099: * This method determines if this is a URI with a scheme of
100: * "tel"
101: *
102: * @return true if the scheme is "tel", false otherwise.
103: */
104: public boolean isTelURL() {
105: return true;
106: }
107:
108: /**
109: * Sets phone user of this TelURL to be either global or local. The default
110: * value is false, hence the TelURL is defaulted to local.
111: *
112: * @param global - the boolean value indicating if the TelURL has a global
113: * phone user.
114: */
115: public void setGlobal(boolean global) {
116: this .telephoneNumber.setGlobal(true);
117: }
118:
119: /**
120: * Sets ISDN subaddress of this TelURL. If a subaddress is present, it is
121: * appended to the phone number after ";isub=".
122: *
123: * @param isdnSubAddress - new value of the <code>isdnSubAddress</code>
124: * parameter
125: */
126: public void setIsdnSubAddress(String isdnSubAddress) {
127: this .telephoneNumber.setIsdnSubaddress(isdnSubAddress);
128: }
129:
130: /**
131: * Sets post dial of this TelURL. The post-dial sequence describes what and
132: * when the local entity should send to the phone line.
133: *
134: * @param postDial - new value of the <code>postDial</code> parameter
135: */
136: public void setPostDial(String postDial) {
137: this .telephoneNumber.setPostDial(postDial);
138: }
139:
140: /**
141: * Set the telephone number.
142: * @param telephoneNumber -- long phone number to set.
143: */
144: public void setPhoneNumber(String telephoneNumber) {
145: this .telephoneNumber.setPhoneNumber(telephoneNumber);
146: }
147:
148: /**
149: * Get the telephone number.
150: *
151: * @return -- the telephone number.
152: */
153: public String getPhoneNumber() {
154: return this .telephoneNumber.getPhoneNumber();
155: }
156:
157: /**
158: * Return the string encoding.
159: *
160: * @return -- the string encoding.
161: */
162: public String toString() {
163: return this .scheme + ":" + telephoneNumber.encode();
164: }
165:
166: /**
167: * Encodes contents in a string.
168: * @return encoded string of object contents
169: */
170: public String encode() {
171: return this .scheme + ":" + telephoneNumber.encode();
172: }
173:
174: /**
175: * Returns the URI part of the address (without parameters)
176: * i.e. scheme:user@host:port.
177: * @return URI part of the address
178: */
179: public String getPlainURI() {
180: StringBuffer retval = new StringBuffer();
181: retval.append(scheme).append(":");
182: if (telephoneNumber.isGlobal()) {
183: retval.append("+");
184: }
185: retval.append(telephoneNumber.getPhoneNumber());
186: return retval.toString();
187: }
188:
189: /**
190: * Returns an Iterator over the names (Strings) of all parameters present
191: * in this ParametersHeader.
192: * @return an Iterator over all the parameter names
193: *
194: */
195: public Vector getParameterNames() {
196: if (null != telephoneNumber) {
197: return telephoneNumber.parms.getNames();
198: }
199: return null;
200: }
201:
202: /**
203: * Deep copy clone operation.
204: *
205: * @return -- a cloned version of this telephone number.
206: */
207: public Object clone() {
208: TelURL retval = new TelURL();
209: retval.scheme = this .scheme;
210: if (this .telephoneNumber != null) {
211: retval.telephoneNumber = (TelephoneNumber) this.telephoneNumber
212: .clone();
213: }
214: return retval;
215: }
216:
217: }
|