• 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 * and others.
7 * Pursuant to title 15 Untied States Code Section 105, works of NIST
8 * employees are not subject to copyright protection in the United States
9 * and are considered to be in the public domain.  As a result, a formal
10 * license is not needed to use the software.
11 *
12 * This software is provided by NIST as a service and is expressly
13 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
14 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
16 * AND DATA ACCURACY.  NIST does not warrant or make any representations
17 * regarding the use of the software or the results thereof, including but
18 * not limited to the correctness, accuracy, reliability or usefulness of
19 * the software.
20 *
21 * Permission to use this software is contingent upon your acceptance
22 * of the terms of this agreement
23 *
24 * .
25 *
26 */
27 /*******************************************
28  * PRODUCT OF PT INOVACAO - EST DEPARTMENT *
29  *******************************************/
30 
31 package gov.nist.javax.sip.header.ims;
32 
33 import gov.nist.core.NameValue;
34 import java.text.ParseException;
35 import java.util.ArrayList;
36 import java.util.Iterator;
37 import java.util.LinkedList;
38 import java.util.ListIterator;
39 
40 import javax.sip.header.ExtensionHeader;
41 
42 import gov.nist.javax.sip.header.ims.PChargingFunctionAddressesHeader;
43 import gov.nist.javax.sip.header.ims.ParameterNamesIms;
44 
45 
46 /**
47  * <p>P-Charging-Function-Addresses SIP Private Header. </p>
48  *
49  * <p>Sintax (RFC 3455):</p>
50  * <pre>
51  * P-Charging-Addr        = "P-Charging-Function-Addresses" HCOLON
52  *                           charge-addr-params
53  *                           *(SEMI charge-addr-params)
54  * charge-addr-params     = ccf / ecf / generic-param
55  * ccf                    = "ccf" EQUAL gen-value
56  * ecf                    = "ecf" EQUAL gen-value
57  * gen-value              = token / host / quoted-string
58  * </pre>
59  *
60  * <p>example:</p>
61  *  <p>P-Charging-Function-Addresses: ccf=192.1.1.1; ccf=192.1.1.2;
62  *  ecf=192.1.1.3; ecf=192.1.1.4</p>
63  *
64  * <p>TODO: add PARSER support for IPv6 address.
65  * eg: P-Charging-Function-Addresses: ccf=[5555.b99.c88.d77.e66]; ecf=[5555.6aa.7bb.8cc.9dd] </p>
66  *
67  * @author ALEXANDRE MIGUEL SILVA SANTOS - Nú 10045401
68  */
69 
70 
71 public class PChargingFunctionAddresses
72     extends gov.nist.javax.sip.header.ParametersHeader
73     implements PChargingFunctionAddressesHeader, SIPHeaderNamesIms , ExtensionHeader{
74 
75 
76     // TODO: serialVersionUID
77 
78     /**
79      * Defaul Constructor
80      */
PChargingFunctionAddresses()81     public PChargingFunctionAddresses() {
82 
83         super(P_CHARGING_FUNCTION_ADDRESSES);
84     }
85 
86     /* (non-Javadoc)
87      * @see gov.nist.javax.sip.header.ParametersHeader#encodeBody()
88      */
encodeBody()89     protected String encodeBody() {
90 
91         StringBuffer encoding = new StringBuffer();
92 
93         // issued by Miguel Freitas
94         if (!duplicates.isEmpty())
95         {
96             encoding.append(duplicates.encode());
97         }
98 
99         return encoding.toString();
100 
101     }
102 
103     /**
104      * <p>Set the Charging Collection Function (CCF) Address</p>
105      *
106      * @param ccfAddress - the address to set in the CCF parameter
107      * @throws ParseException
108      */
setChargingCollectionFunctionAddress(String ccfAddress)109     public void setChargingCollectionFunctionAddress(String ccfAddress) throws ParseException {
110 
111         if (ccfAddress == null)
112             throw new NullPointerException(
113                 "JAIN-SIP Exception, "
114                     + "P-Charging-Function-Addresses, setChargingCollectionFunctionAddress(), the ccfAddress parameter is null.");
115 
116        // setParameter(ParameterNamesIms.CCF, ccfAddress);
117         setMultiParameter(ParameterNamesIms.CCF, ccfAddress);
118 
119     }
120 
121     /**
122      * <p>Add another Charging Collection Function (CCF) Address to this header</p>
123      *
124      * @param ccfAddress - the address to set in the CCF parameter
125      * @throws ParseException
126      */
addChargingCollectionFunctionAddress(String ccfAddress)127     public void addChargingCollectionFunctionAddress(String ccfAddress) throws ParseException {
128 
129         if (ccfAddress == null)
130             throw new NullPointerException(
131                 "JAIN-SIP Exception, "
132                     + "P-Charging-Function-Addresses, setChargingCollectionFunctionAddress(), the ccfAddress parameter is null.");
133 
134         this.parameters.set(ParameterNamesIms.CCF, ccfAddress);
135 
136     }
137 
138     /**
139      * <p>Remove a Charging Collection Function (CCF) Address set in this header</p>
140      *
141      * @param ccfAddress - the address in the CCF parameter to remove
142      * @throws ParseException if the address was not removed
143      */
removeChargingCollectionFunctionAddress(String ccfAddress)144     public void removeChargingCollectionFunctionAddress(String ccfAddress) throws ParseException {
145 
146         if (ccfAddress == null)
147             throw new NullPointerException(
148                 "JAIN-SIP Exception, "
149                     + "P-Charging-Function-Addresses, setChargingCollectionFunctionAddress(), the ccfAddress parameter is null.");
150 
151         if(!this.delete(ccfAddress, ParameterNamesIms.CCF)) {
152 
153             throw new ParseException("CCF Address Not Removed",0);
154 
155         }
156 
157     }
158 
159     /**
160      * <p>Get all the Charging Collection Function (CCF) Addresses set in this header</p>
161      *
162      * @return ListIterator that constains all CCF addresses of this header
163      */
getChargingCollectionFunctionAddresses()164     public ListIterator getChargingCollectionFunctionAddresses() {
165 
166         Iterator li = this.parameters.iterator();
167         LinkedList ccfLIST = new LinkedList();
168         NameValue nv;
169         while (li.hasNext()) {
170             nv = (NameValue) li.next();
171             if (nv.getName().equalsIgnoreCase(ParameterNamesIms.CCF)) {
172 
173                 NameValue ccfNV = new NameValue();
174 
175                 ccfNV.setName(nv.getName());
176                 ccfNV.setValueAsObject(nv.getValueAsObject());
177 
178                 ccfLIST.add(ccfNV);
179 
180             }
181         }
182 
183         return ccfLIST.listIterator();
184     }
185 
186     /**
187      * <p>Set the Event Charging Function (ECF) Address</p>
188      *
189      * @param ecfAddress - the address to set in the ECF parameter
190      * @throws ParseException
191      */
setEventChargingFunctionAddress(String ecfAddress)192     public void setEventChargingFunctionAddress(String ecfAddress) throws ParseException {
193 
194         if (ecfAddress == null)
195             throw new NullPointerException(
196                 "JAIN-SIP Exception, "
197                     + "P-Charging-Function-Addresses, setEventChargingFunctionAddress(), the ecfAddress parameter is null.");
198 
199         setMultiParameter(ParameterNamesIms.ECF, ecfAddress);
200        // setParameter(ParameterNamesIms.ECF, ecfAddress);
201 
202     }
203 
204     /**
205      * <p>Add another Event Charging Function (ECF) Address to this header</p>
206      *
207      * @param ecfAddress - the address to set in the ECF parameter
208      * @throws ParseException
209      */
addEventChargingFunctionAddress(String ecfAddress)210     public void addEventChargingFunctionAddress(String ecfAddress) throws ParseException {
211 
212         if (ecfAddress == null)
213             throw new NullPointerException(
214                 "JAIN-SIP Exception, "
215                     + "P-Charging-Function-Addresses, setEventChargingFunctionAddress(), the ecfAddress parameter is null.");
216 
217         this.parameters.set(ParameterNamesIms.ECF, ecfAddress);
218 
219     }
220 
221     /**
222      * <p>Remove a Event Charging Function (ECF) Address set in this header</p>
223      *
224      * @param ecfAddress - the address in the ECF parameter to remove
225      * @throws ParseException if the address was not removed
226      */
removeEventChargingFunctionAddress(String ecfAddress)227     public void removeEventChargingFunctionAddress(String ecfAddress) throws ParseException {
228 
229         if (ecfAddress == null)
230             throw new NullPointerException(
231                 "JAIN-SIP Exception, "
232                     + "P-Charging-Function-Addresses, setEventChargingFunctionAddress(), the ecfAddress parameter is null.");
233 
234         if(!this.delete(ecfAddress, ParameterNamesIms.ECF)) {
235 
236             throw new java.text.ParseException("ECF Address Not Removed",0);
237 
238         }
239 
240     }
241 
242     /**
243      * <p>Get all the Event Charging Function (ECF) Addresses set in this header</p>
244      *
245      * @return ListIterator that constains all CCF addresses of this header
246      */
getEventChargingFunctionAddresses()247     public ListIterator<NameValue> getEventChargingFunctionAddresses() {
248 
249     	LinkedList<NameValue> listw = new LinkedList<NameValue>();
250 
251         Iterator li = this.parameters.iterator();
252         ListIterator<NameValue> ecfLIST = listw.listIterator();
253         NameValue nv;
254         boolean removed = false;
255         while (li.hasNext()) {
256             nv = (NameValue) li.next();
257             if (nv.getName().equalsIgnoreCase(ParameterNamesIms.ECF)) {
258 
259                 NameValue ecfNV = new NameValue();
260 
261                 ecfNV.setName(nv.getName());
262                 ecfNV.setValueAsObject(nv.getValueAsObject());
263 
264                 ecfLIST.add(ecfNV);
265 
266             }
267         }
268 
269         return ecfLIST;
270     }
271 
272     /**
273      * <p>Remove parameter </p>
274      *
275      * @param value - of the parameter
276      * @param name - of the parameter
277      * @return true if parameter was removed, and false if not
278      */
delete(String value, String name)279     public boolean delete(String value, String name) {
280         Iterator li = this.parameters.iterator();
281         NameValue nv;
282         boolean removed = false;
283         while (li.hasNext()) {
284             nv = (NameValue) li.next();
285             if (((String) nv.getValueAsObject()).equalsIgnoreCase(value) && nv.getName().equalsIgnoreCase(name)) {
286                 li.remove();
287                 removed = true;
288             }
289         }
290 
291         return removed;
292 
293     }
294 
setValue(String value)295     public void setValue(String value) throws ParseException {
296         throw new ParseException ( value,0);
297 
298     }
299 
300 }
301