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 gov.nist.core.*;
028: import gov.nist.siplite.SIPConstants;
029:
030: /**
031: * Telephone number class.
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 TelephoneNumber extends GenericObject {
039: /** Post dial method string. */
040: public static final String POSTDIAL = SIPConstants.GENERAL_POSTDIAL;
041: /** Phone context tag string. */
042: public static final String PHONE_CONTEXT_TAG = SIPConstants.GENERAL_PHONE_CONTEXT_TAG;
043: /** ISDN subaddress parameter label. */
044: public static final String ISUB = SIPConstants.GENERAL_ISUB;
045: /** Provider tag label. */
046: public static final String PROVIDER_TAG = SIPConstants.GENERAL_PROVIDER_TAG;
047:
048: /**
049: * Flag indicating international phone number.
050: */
051: protected boolean isglobal;
052:
053: /**
054: * Phone number field.
055: */
056: protected String phoneNumber;
057:
058: /**
059: * Parmeters list.
060: */
061: protected NameValueList parms;
062:
063: /**
064: * Creates new TelephoneNumber.
065: */
066: public TelephoneNumber() {
067: parms = new NameValueList("telparms");
068: }
069:
070: /**
071: * Deletes the specified parameter.
072: * @param name String to set
073: */
074: public void deleteParm(String name) {
075: parms.delete(name);
076: }
077:
078: /**
079: * Gets the PhoneNumber field.
080: * @return the phone number
081: */
082: public String getPhoneNumber() {
083: return phoneNumber;
084: }
085:
086: /**
087: * Gets the PostDial field.
088: * @return String
089: */
090: public String getPostDial() {
091: return (String) parms.getValue(POSTDIAL);
092: }
093:
094: /**
095: * Get the isdn subaddress for this number.
096: * @return String
097: */
098: public String getIsdnSubaddress() {
099: return (String) parms.getValue(ISUB);
100: }
101:
102: /**
103: * Returns true if the PostDial field exists.
104: * @return true if post dial field is included
105: */
106: public boolean hasPostDial() {
107: return parms.getValue(POSTDIAL) != null;
108: }
109:
110: /**
111: * Returns true if this header has parameters.
112: * @param pname String to set
113: * @return true if parameter is present
114: */
115: public boolean hasParm(String pname) {
116: return parms.hasNameValue(pname);
117: }
118:
119: /**
120: * Returns true if the isdn subaddress exists.
121: * @return True if isdn sub address exists.
122: */
123: public boolean hasIsdnSubaddress() {
124: return hasParm(ISUB);
125: }
126:
127: /**
128: * Returns tru if telephone number is a global telephone number.
129: * @return true if global phone number
130: */
131: public boolean isGlobal() {
132: return isglobal;
133: }
134:
135: /**
136: * Removes the PostDial field.
137: */
138: public void removePostDial() {
139: parms.delete(POSTDIAL);
140: }
141:
142: /**
143: * Removes the isdn subaddress (if it exists).
144: */
145: public void removeIsdnSubaddress() {
146: deleteParm(ISUB);
147: }
148:
149: /**
150: * Sets the list of parameters.
151: * @param p NameValueList to set
152: */
153: public void setParameters(NameValueList p) {
154: parms = p;
155: }
156:
157: /**
158: * Sets the Global field.
159: * @param g boolean to set
160: */
161: public void setGlobal(boolean g) {
162: isglobal = g;
163: }
164:
165: /**
166: * Sets the PostDial field.
167: * @param p String to set
168: */
169: public void setPostDial(String p) {
170: NameValue nv = new NameValue(POSTDIAL, p);
171: parms.add(nv);
172: }
173:
174: /**
175: * Sets the specified parameter.
176: * @param name String to set
177: * @param value Object to set
178: */
179: public void setParm(String name, Object value) {
180: NameValue nv = new NameValue(name, value);
181: parms.add(nv);
182: }
183:
184: /**
185: * Sets the isdn subaddress for this structure.
186: * @param isub String to set
187: */
188: public void setIsdnSubaddress(String isub) {
189: setParm(ISUB, isub);
190: }
191:
192: /**
193: * Sets the PhoneNumber field
194: * @param num String to set
195: */
196: public void setPhoneNumber(String num) {
197: phoneNumber = num;
198: }
199:
200: /**
201: *( Encodes instance contents as a string.
202: * @return encoded string of object contents
203: */
204: public String encode() {
205: String retval = "";
206: if (isglobal)
207: retval += "+";
208: retval += phoneNumber;
209: if (!parms.isEmpty()) {
210: retval += Separators.SEMICOLON;
211: retval += parms.encode();
212: }
213: return retval;
214: }
215:
216: /**
217: * Copies the current object.
218: * @return copy of current instance
219: */
220: public Object clone() {
221: TelephoneNumber retval = new TelephoneNumber();
222: retval.isglobal = this .isglobal;
223: retval.phoneNumber = new String(this .phoneNumber);
224: retval.parms = (NameValueList) this.parms.clone();
225: return retval;
226: }
227:
228: }
|