1 /******************************************************************************* 2 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * 3 *******************************************************************************/ 4 package gov.nist.javax.sip.header.extensions; 5 import java.text.ParseException; 6 import gov.nist.javax.sip.header.*; 7 8 import javax.sip.header.ExtensionHeader; 9 /* 10 * This code is in the public domain. 11 */ 12 13 /** 14 * Replaces SIPHeader. 15 * ToDo: add support for early-only flag. 16 * 17 * @author P, Musgrave <pmusgrave@mkcnetworks.com> <br/> 18 * 19 * @version JAIN-SIP-1.2 20 * 21 * 22 */ 23 24 public class Replaces 25 extends ParametersHeader implements ExtensionHeader, ReplacesHeader { 26 27 // TODO: Need a unique UID 28 private static final long serialVersionUID = 8765762413224043300L; 29 30 // TODO: When the MinSEHeader is added to javax - move this there...pmusgrave 31 public static final String NAME = "Replaces"; 32 33 /** 34 * callIdentifier field 35 */ 36 public CallIdentifier callIdentifier; 37 public String callId; 38 39 /** 40 * Default constructor 41 */ Replaces()42 public Replaces() { 43 super(NAME); 44 } 45 46 /** Constructor given the call Identifier. 47 *@param callId string call identifier (should be localid@host) 48 *@throws IllegalArgumentException if call identifier is bad. 49 */ Replaces(String callId)50 public Replaces(String callId) throws IllegalArgumentException { 51 super(NAME); 52 this.callIdentifier = new CallIdentifier(callId); 53 } 54 55 /** 56 * Encode the body part of this header (i.e. leave out the hdrName). 57 * @return String encoded body part of the header. 58 */ encodeBody()59 public String encodeBody() { 60 if (callId == null) 61 return null; 62 else { 63 String retVal = callId; 64 if (!parameters.isEmpty()) { 65 retVal += SEMICOLON + parameters.encode(); 66 } 67 return retVal; 68 } 69 } 70 71 /** 72 * get the CallId field. This does the same thing as encodeBody 73 * 74 * @return String the encoded body part of the 75 */ getCallId()76 public String getCallId() { 77 return callId; 78 } 79 80 /** 81 * get the call Identifer member. 82 * @return CallIdentifier 83 */ getCallIdentifer()84 public CallIdentifier getCallIdentifer() { 85 return callIdentifier; 86 } 87 88 /** 89 * set the CallId field 90 * @param cid String to set. This is the body part of the Call-Id 91 * header. It must have the form localId@host or localId. 92 * @throws IllegalArgumentException if cid is null, not a token, or is 93 * not a token@token. 94 */ setCallId(String cid)95 public void setCallId(String cid) { 96 callId = cid; 97 } 98 99 /** 100 * Set the callIdentifier member. 101 * @param cid CallIdentifier to set (localId@host). 102 */ setCallIdentifier(CallIdentifier cid)103 public void setCallIdentifier(CallIdentifier cid) { 104 callIdentifier = cid; 105 } 106 107 /** 108 * Get the to-tag parameter from the address parm list. 109 * @return tag field 110 */ getToTag()111 public String getToTag() { 112 if (parameters == null) 113 return null; 114 return getParameter(ParameterNames.TO_TAG); 115 } 116 /** 117 * Set the to-tag member 118 * @param t tag to set. From tags are mandatory. 119 */ setToTag(String t)120 public void setToTag(String t) throws ParseException { 121 if (t == null) 122 throw new NullPointerException("null tag "); 123 else if (t.trim().equals("")) 124 throw new ParseException("bad tag", 0); 125 this.setParameter(ParameterNames.TO_TAG, t); 126 } 127 /** Boolean function 128 * @return true if the Tag exist 129 */ hasToTag()130 public boolean hasToTag() { 131 return hasParameter(ParameterNames.TO_TAG); 132 } 133 134 /** remove Tag member 135 */ removeToTag()136 public void removeToTag() { 137 parameters.delete(ParameterNames.TO_TAG); 138 } 139 /** 140 * Get the from-tag parameter from the address parm list. 141 * @return tag field 142 */ getFromTag()143 public String getFromTag() { 144 if (parameters == null) 145 return null; 146 return getParameter(ParameterNames.FROM_TAG); 147 } 148 /** 149 * Set the to-tag member 150 * @param t tag to set. From tags are mandatory. 151 */ setFromTag(String t)152 public void setFromTag(String t) throws ParseException { 153 if (t == null) 154 throw new NullPointerException("null tag "); 155 else if (t.trim().equals("")) 156 throw new ParseException("bad tag", 0); 157 this.setParameter(ParameterNames.FROM_TAG, t); 158 } 159 /** Boolean function 160 * @return true if the Tag exist 161 */ hasFromTag()162 public boolean hasFromTag() { 163 return hasParameter(ParameterNames.FROM_TAG); 164 } 165 166 /** remove Tag member 167 */ removeFromTag()168 public void removeFromTag() { 169 parameters.delete(ParameterNames.FROM_TAG); 170 } 171 172 173 setValue(String value)174 public void setValue(String value) throws ParseException { 175 // not implemented. 176 throw new ParseException(value,0); 177 178 } 179 180 // public Object clone() { 181 // CallID retval = (CallID) super.clone(); 182 // if (this.callIdentifier != null) 183 // retval.setCallIdentifier( (CallIdentifier) this.callIdentifier.clone() ); 184 // return retval; 185 // } 186 } 187 /* 188 * $Log: Replaces.java,v $ 189 * Revision 1.3 2009/07/17 18:57:42 emcho 190 * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. 191 * 192 * Revision 1.2 2006/10/27 20:58:31 mranga 193 * Issue number: 194 * Obtained from: 195 * Submitted by: 196 * Reviewed by: mranga 197 * doc fixups 198 * CVS: ---------------------------------------------------------------------- 199 * CVS: Issue number: 200 * CVS: If this change addresses one or more issues, 201 * CVS: then enter the issue number(s) here. 202 * CVS: Obtained from: 203 * CVS: If this change has been taken from another system, 204 * CVS: then name the system in this line, otherwise delete it. 205 * CVS: Submitted by: 206 * CVS: If this code has been contributed to the project by someone else; i.e., 207 * CVS: they sent us a patch or a set of diffs, then include their name/email 208 * CVS: address here. If this is your work then delete this line. 209 * CVS: Reviewed by: 210 * CVS: If we are doing pre-commit code reviews and someone else has 211 * CVS: reviewed your changes, include their name(s) here. 212 * CVS: If you have not had it reviewed then delete this line. 213 * 214 * Revision 1.1 2006/10/12 11:57:51 pmusgrave 215 * Issue number: 79, 80 216 * Submitted by: pmusgrave@newheights.com 217 * Reviewed by: mranga 218 * 219 * Revision 1.3 2006/07/19 15:05:20 pmusgrave 220 * Modify encodeBody so it uses callId and not CallIdentifier 221 * 222 * Revision 1.2 2006/04/17 23:41:31 pmusgrave 223 * Add Session Timer and Replaces headers 224 * 225 * Revision 1.1.1.1 2006/03/15 16:00:07 pmusgrave 226 * Source with additions 227 * 228 * Revision 1.3 2005/04/16 20:38:48 dmuresan 229 * Canonical clone() implementations for the GenericObject and GenericObjectList hierarchies 230 * 231 * Revision 1.2 2004/01/22 13:26:29 sverker 232 * Issue number: 233 * Obtained from: 234 * Submitted by: sverker 235 * Reviewed by: mranga 236 * 237 * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. 238 * 239 * CVS: ---------------------------------------------------------------------- 240 * CVS: Issue number: 241 * CVS: If this change addresses one or more issues, 242 * CVS: then enter the issue number(s) here. 243 * CVS: Obtained from: 244 * CVS: If this change has been taken from another system, 245 * CVS: then name the system in this line, otherwise delete it. 246 * CVS: Submitted by: 247 * CVS: If this code has been contributed to the project by someone else; i.e., 248 * CVS: they sent us a patch or a set of diffs, then include their name/email 249 * CVS: address here. If this is your work then delete this line. 250 * CVS: Reviewed by: 251 * CVS: If we are doing pre-commit code reviews and someone else has 252 * CVS: reviewed your changes, include their name(s) here. 253 * CVS: If you have not had it reviewed then delete this line. 254 * 255 */ 256 257