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 /******************************************* 27 * PRODUCT OF PT INOVACAO - EST DEPARTMENT * 28 *******************************************/ 29 30 package gov.nist.javax.sip.header.ims; 31 32 import java.text.ParseException; 33 34 import javax.sip.header.ExtensionHeader; 35 36 import gov.nist.javax.sip.header.ims.PChargingVectorHeader; 37 import gov.nist.javax.sip.header.ims.ParameterNamesIms; 38 39 /** 40 * P-Charging-Vector header SIP Private Header: RFC 3455. 41 * 42 * @author ALEXANDRE MIGUEL SILVA SANTOS 43 */ 44 45 public class PChargingVector extends gov.nist.javax.sip.header.ParametersHeader 46 implements PChargingVectorHeader, SIPHeaderNamesIms, ExtensionHeader { 47 48 /** 49 * Default Constructor 50 */ PChargingVector()51 public PChargingVector() { 52 53 super(P_CHARGING_VECTOR); 54 } 55 56 /* 57 * (non-Javadoc) 58 * 59 * @see gov.nist.javax.sip.header.ParametersHeader#encodeBody() 60 */ encodeBody()61 protected String encodeBody() { 62 63 StringBuffer encoding = new StringBuffer(); 64 /* 65 * no need to check for the presence of icid-value. According to the 66 * spec above this is a mandatory field. if it does not exist, then we 67 * should throw an exception 68 * 69 * JvB 26/5: fix for issue #159, check for quotes around icid value 70 */ 71 gov.nist.core.NameValue nv = getNameValue( ParameterNamesIms.ICID_VALUE ); 72 nv.encode( encoding ); 73 74 //the remaining parameters are optional. 75 // check for their presence, then add the parameter if it exists. 76 if (parameters.containsKey(ParameterNamesIms.ICID_GENERATED_AT)) 77 encoding.append(SEMICOLON).append( 78 ParameterNamesIms.ICID_GENERATED_AT).append(EQUALS).append( 79 getICIDGeneratedAt()); 80 81 if (parameters.containsKey(ParameterNamesIms.TERM_IOI)) 82 83 encoding.append(SEMICOLON).append(ParameterNamesIms.TERM_IOI) 84 .append(EQUALS).append(getTerminatingIOI()); 85 86 if (parameters.containsKey(ParameterNamesIms.ORIG_IOI)) 87 88 encoding.append(SEMICOLON).append(ParameterNamesIms.ORIG_IOI) 89 .append(EQUALS).append(getOriginatingIOI()); 90 91 return encoding.toString(); 92 } 93 94 /** 95 * <p> 96 * Get the icid-value parameter value 97 * </p> 98 * 99 * @return the value of the icid-value parameter 100 */ getICID()101 public String getICID() { 102 103 return getParameter(ParameterNamesIms.ICID_VALUE); 104 } 105 106 /** 107 * <p> 108 * Set the icid-value parameter 109 * </p> 110 * 111 * @param icid - 112 * value to set in the icid-value parameter 113 * @throws ParseException 114 */ setICID(String icid)115 public void setICID(String icid) throws ParseException { 116 117 if (icid == null) 118 throw new NullPointerException( 119 "JAIN-SIP Exception, " 120 + "P-Charging-Vector, setICID(), the icid parameter is null."); 121 122 setParameter(ParameterNamesIms.ICID_VALUE, icid); 123 124 } 125 126 /** 127 * <p> 128 * Get the icid-generated-at parameter value 129 * </p> 130 * 131 * @return the icid-generated-at parameter value 132 */ getICIDGeneratedAt()133 public String getICIDGeneratedAt() { 134 135 return getParameter(ParameterNamesIms.ICID_GENERATED_AT); 136 137 } 138 139 /** 140 * <p> 141 * Set the icid-generated-at parameter 142 * </p> 143 * 144 * @param host - 145 * value to set in the icid-generated-at parameter 146 * @throws ParseException 147 */ setICIDGeneratedAt(String host)148 public void setICIDGeneratedAt(String host) throws ParseException { 149 150 if (host == null) 151 throw new NullPointerException( 152 "JAIN-SIP Exception, " 153 + "P-Charging-Vector, setICIDGeneratedAt(), the host parameter is null."); 154 155 setParameter(ParameterNamesIms.ICID_GENERATED_AT, host); 156 157 } 158 159 /** 160 * <p> 161 * Get the orig-ioi parameter value 162 * </p> 163 * 164 * @return the orig-ioi parameter value 165 */ getOriginatingIOI()166 public String getOriginatingIOI() { 167 168 return getParameter(ParameterNamesIms.ORIG_IOI); 169 } 170 171 /** 172 * <p> 173 * Set the orig-ioi parameter 174 * </p> 175 * 176 * @param origIOI - 177 * value to set in the orig-ioi parameter. If value is null or 178 * empty, the parameter is removed 179 * @throws ParseException 180 */ setOriginatingIOI(String origIOI)181 public void setOriginatingIOI(String origIOI) throws ParseException { 182 183 if (origIOI == null || origIOI.length() == 0) { 184 removeParameter(ParameterNamesIms.ORIG_IOI); 185 } else 186 setParameter(ParameterNamesIms.ORIG_IOI, origIOI); 187 188 } 189 190 /** 191 * <p> 192 * Get the term-ioi parameter value 193 * </p> 194 * 195 * @return the term-ioi parameter value 196 */ getTerminatingIOI()197 public String getTerminatingIOI() { 198 199 return getParameter(ParameterNamesIms.TERM_IOI); 200 } 201 202 /** 203 * <p> 204 * Set the term-ioi parameter 205 * </p> 206 * 207 * @param termIOI - 208 * value to set in the term-ioi parameter. If value is null or 209 * empty, the parameter is removed 210 * @throws ParseException 211 */ setTerminatingIOI(String termIOI)212 public void setTerminatingIOI(String termIOI) throws ParseException { 213 214 if (termIOI == null || termIOI.length() == 0) { 215 removeParameter(ParameterNamesIms.TERM_IOI); 216 } else 217 setParameter(ParameterNamesIms.TERM_IOI, termIOI); 218 219 } 220 setValue(String value)221 public void setValue(String value) throws ParseException { 222 throw new ParseException(value, 0); 223 224 } 225 226 } 227