• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Conditions Of Use
3 *
4 * This software was developed by employees of the National Institute of
5 * Standards and Technology (NIST), an agency of the Federal Government.
6 * Pursuant to title 15 Untied States Code Section 105, works of NIST
7 * employees are not subject to copyright protection in the United States
8 * and are considered to be in the public domain.  As a result, a formal
9 * license is not needed to use the software.
10 *
11 * This software is provided by NIST as a service and is expressly
12 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
15 * AND DATA ACCURACY.  NIST does not warrant or make any representations
16 * regarding the use of the software or the results thereof, including but
17 * not limited to the correctness, accuracy, reliability or usefulness of
18 * the software.
19 *
20 * Permission to use this software is contingent upon your acceptance
21 * of the terms of this agreement
22 *
23 * .
24 *
25 */
26 package gov.nist.javax.sip.address;
27 
28 import gov.nist.core.*;
29 
30 import java.util.Iterator;
31 
32 /**
33  * Telephone number class.
34  * @version 1.2
35  * @version 1.2 $Revision: 1.10 $ $Date: 2009/07/17 18:57:23 $
36  *
37  * @author M. Ranganathan
38  *
39  */
40 public class TelephoneNumber extends NetObject {
41     public static final String POSTDIAL = ParameterNames.POSTDIAL;
42     public static final String PHONE_CONTEXT_TAG =
43         ParameterNames.PHONE_CONTEXT_TAG;
44     public static final String ISUB = ParameterNames.ISUB;
45     public static final String PROVIDER_TAG = ParameterNames.PROVIDER_TAG;
46 
47     /** isglobal field
48      */
49     protected boolean isglobal;
50 
51     /** phoneNumber field
52      */
53     protected String phoneNumber;
54 
55     /** parmeters list
56      */
57     protected NameValueList parameters;
58 
59     /** Creates new TelephoneNumber */
TelephoneNumber()60     public TelephoneNumber() {
61         parameters = new NameValueList();
62     }
63 
64     /** delete the specified parameter.
65      * @param name String to set
66      */
deleteParm(String name)67     public void deleteParm(String name) {
68         parameters.delete(name);
69     }
70 
71     /** get the PhoneNumber field
72      * @return String
73      */
getPhoneNumber()74     public String getPhoneNumber() {
75         return phoneNumber;
76     }
77 
78     /** get the PostDial field
79      * @return String
80      */
getPostDial()81     public String getPostDial() {
82         return (String) parameters.getValue(POSTDIAL);
83     }
84 
85     /**
86      * Get the isdn subaddress for this number.
87      * @return String
88      */
getIsdnSubaddress()89     public String getIsdnSubaddress() {
90         return (String) parameters.getValue(ISUB);
91     }
92 
93     /** returns true if th PostDial field exists
94      * @return boolean
95      */
hasPostDial()96     public boolean hasPostDial() {
97         return parameters.getValue(POSTDIAL) != null;
98     }
99 
100     /** return true if this header has parameters.
101      * @param pname String to set
102      * @return boolean
103      */
hasParm(String pname)104     public boolean hasParm(String pname) {
105         return parameters.hasNameValue(pname);
106     }
107 
108     /**
109      * return true if the isdn subaddress exists.
110      * @return boolean
111      */
hasIsdnSubaddress()112     public boolean hasIsdnSubaddress() {
113         return hasParm(ISUB);
114     }
115 
116     /**
117      * is a global telephone number.
118      * @return boolean
119      */
isGlobal()120     public boolean isGlobal() {
121         return isglobal;
122     }
123 
124     /** remove the PostDial field
125      */
removePostDial()126     public void removePostDial() {
127         parameters.delete(POSTDIAL);
128     }
129 
130     /**
131      * Remove the isdn subaddress (if it exists).
132      */
removeIsdnSubaddress()133     public void removeIsdnSubaddress() {
134         deleteParm(ISUB);
135     }
136 
137     /**
138      * Set the list of parameters.
139      * @param p NameValueList to set
140      */
setParameters(NameValueList p)141     public void setParameters(NameValueList p) {
142         parameters = p;
143     }
144 
145     /** set the Global field
146      * @param g boolean to set
147      */
setGlobal(boolean g)148     public void setGlobal(boolean g) {
149         isglobal = g;
150     }
151 
152     /** set the PostDial field
153      * @param p String to set
154      */
setPostDial(String p)155     public void setPostDial(String p) {
156         NameValue nv = new NameValue(POSTDIAL, p);
157         parameters.set(nv);
158     }
159 
160     /** set the specified parameter
161      * @param name String to set
162      * @param value Object to set
163      */
setParm(String name, Object value)164     public void setParm(String name, Object value) {
165         NameValue nv = new NameValue(name, value);
166         parameters.set(nv);
167     }
168 
169     /**
170      * set the isdn subaddress for this structure.
171      * @param isub String to set
172      */
setIsdnSubaddress(String isub)173     public void setIsdnSubaddress(String isub) {
174         setParm(ISUB, isub);
175     }
176 
177     /** set the PhoneNumber field
178      * @param num String to set
179      */
setPhoneNumber(String num)180     public void setPhoneNumber(String num) {
181         phoneNumber = num;
182     }
183 
encode()184     public String encode() {
185         return encode(new StringBuffer()).toString();
186     }
187 
encode(StringBuffer buffer)188     public StringBuffer encode(StringBuffer buffer) {
189         if (isglobal)
190             buffer.append('+');
191         buffer.append(phoneNumber);
192         if (!parameters.isEmpty()) {
193             buffer.append(SEMICOLON);
194             parameters.encode(buffer);
195         }
196         return buffer;
197     }
198 
199     /**
200      * Returns the value of the named parameter, or null if it is not set. A
201      * zero-length String indicates flag parameter.
202      *
203      * @param name name of parameter to retrieve
204      *
205      * @return the value of specified parameter
206      *
207      */
getParameter(String name)208     public String getParameter(String name) {
209         Object val = parameters.getValue(name);
210         if (val == null)
211             return null;
212         if (val instanceof GenericObject)
213             return ((GenericObject) val).encode();
214         else
215             return val.toString();
216     }
217 
218     /**
219      *
220      * Returns an Iterator over the names (Strings) of all parameters.
221      *
222      * @return an Iterator over all the parameter names
223      *
224      */
getParameterNames()225     public Iterator<String> getParameterNames() {
226         return this.parameters.getNames();
227     }
228 
removeParameter(String parameter)229     public void removeParameter(String parameter) {
230         this.parameters.delete(parameter);
231     }
232 
setParameter(String name, String value)233     public void setParameter(String name, String value) {
234         NameValue nv = new NameValue(name, value);
235         this.parameters.set(nv);
236     }
237 
clone()238     public Object clone() {
239         TelephoneNumber retval = (TelephoneNumber) super.clone();
240         if (this.parameters != null)
241             retval.parameters = (NameValueList) this.parameters.clone();
242         return retval;
243     }
244 
getParameters()245     public NameValueList getParameters() {
246         return this.parameters;
247     }
248 }
249