• 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 /*******************************************************************************
27 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD).        *
28 *******************************************************************************/
29 package gov.nist.javax.sip.header;
30 import javax.sip.header.CallIdHeader;
31 import java.text.ParseException;
32 
33 /**
34  * Call ID SIPHeader.
35  *
36  * @author M. Ranganathan   <br/>
37  * @version 1.2 $Revision: 1.7 $ $Date: 2009/07/17 18:57:27 $
38  * @since 1.1
39  */
40 public class CallID
41     extends SIPHeader
42     implements javax.sip.header.CallIdHeader {
43 
44     /**
45      * Comment for <code>serialVersionUID</code>
46      */
47     private static final long serialVersionUID = -6463630258703731156L;
48     /**
49      * callIdentifier field
50      */
51     protected CallIdentifier callIdentifier;
52 
53     /**
54      * Default constructor
55      */
CallID()56     public CallID() {
57         super(NAME);
58     }
59 
60     /* (non-Javadoc)
61      * @see java.lang.Object#equals(java.lang.Object)
62      *
63      * CallIDs are compared case-insensitively
64      */
equals( Object other )65     public boolean equals( Object other ) {
66 
67         if (this==other) return true;
68 
69         if (other instanceof CallIdHeader) {
70             final CallIdHeader o = (CallIdHeader) other;
71             return this.getCallId().equalsIgnoreCase( o.getCallId() );
72         }
73         return false;
74     }
75 
76 
77     /**
78      * Encode the body part of this header (i.e. leave out the hdrName).
79      *@return String encoded body part of the header.
80      */
encodeBody()81     public String encodeBody() {
82         return encodeBody(new StringBuffer()).toString();
83     }
84 
encodeBody(StringBuffer buffer)85     protected StringBuffer encodeBody(StringBuffer buffer) {
86         if (callIdentifier != null)
87             callIdentifier.encode(buffer);
88 
89         return buffer;
90     }
91 
92     /**
93      * get the CallId field. This does the same thing as
94      * encodeBody
95      * @return String the encoded body part of the
96      */
getCallId()97     public String getCallId() {
98         return encodeBody();
99     }
100 
101     /**
102      * get the call Identifer member.
103      * @return CallIdentifier
104      */
getCallIdentifer()105     public CallIdentifier getCallIdentifer() {
106         return callIdentifier;
107     }
108 
109     /**
110      * set the CallId field
111      * @param cid String to set. This is the body part of the Call-Id
112      *  header. It must have the form localId@host or localId.
113      * @throws IllegalArgumentException if cid is null, not a token, or is
114      * not a token@token.
115      */
setCallId(String cid)116     public void setCallId(String cid) throws ParseException {
117         try {
118             callIdentifier = new CallIdentifier(cid);
119         } catch (IllegalArgumentException ex) {
120             throw new ParseException(cid, 0);
121         }
122     }
123 
124     /**
125      * Set the callIdentifier member.
126      * @param cid CallIdentifier to set (localId@host).
127      */
setCallIdentifier(CallIdentifier cid)128     public void setCallIdentifier(CallIdentifier cid) {
129         callIdentifier = cid;
130     }
131 
132     /** Constructor given the call Identifier.
133      *@param callId string call identifier (should be localid@host)
134      *@throws IllegalArgumentException if call identifier is bad.
135      */
CallID(String callId)136     public CallID(String callId) throws IllegalArgumentException {
137         super(NAME);
138         this.callIdentifier = new CallIdentifier(callId);
139     }
140 
clone()141     public Object clone() {
142         CallID retval = (CallID) super.clone();
143         if (this.callIdentifier != null)
144             retval.callIdentifier = (CallIdentifier) this.callIdentifier.clone();
145         return retval;
146     }
147 }
148