001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: /*
026: */
027: package gov.nist.siplite.header;
028:
029: import gov.nist.core.*;
030:
031: /**
032: * Call ID Header
033: *
034: *
035: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
036: *
037: * IMPL_NOTE: think about removing the specific parser for CallIdHeader.
038: *
039: */
040: public class CallIdHeader extends ParameterLessHeader {
041: /** Caller ID header label. */
042: public static final String NAME = Header.CALL_ID;
043:
044: /** Handle to class. */
045: public static Class clazz;
046:
047: /**
048: * Caller Identifier field.
049: */
050: protected CallIdentifier callIdentifier;
051:
052: static {
053: clazz = new CallIdHeader().getClass();
054: }
055:
056: /**
057: * Default constructor.
058: */
059: public CallIdHeader() {
060: super (CALL_ID);
061: }
062:
063: /**
064: * Compares two call ids for equality.
065: *
066: * @param other Object to set
067: * @return true if the two call ids are equals, false otherwise
068: */
069: public boolean equals(Object other) {
070: if (!this .getClass().equals(other.getClass())) {
071: return false;
072: }
073: CallIdHeader that = (CallIdHeader) other;
074:
075: return this .callIdentifier.equals(that.callIdentifier);
076: }
077:
078: /**
079: * Gets the encoded version of this id.
080: *
081: * @return String.
082: */
083: public String encode() {
084: return headerName + Separators.COLON + Separators.SP
085: + callIdentifier.encode() + Separators.NEWLINE;
086: }
087:
088: /**
089: * Encodes the body part of this header (leave out the hdrName).
090: *
091: * @return String encoded body part of the header.
092: */
093: public String encodeBody() {
094: if (callIdentifier == null)
095: return "";
096: else
097: return callIdentifier.encode();
098: }
099:
100: /**
101: * Gets the Caller Id field. This does the same thing as
102: * encodeBody.
103: * @return String the encoded body part of the
104: */
105: public String getCallId() {
106: return encodeBody();
107: }
108:
109: /**
110: * Gets the call Identifer member.
111: * @return CallIdentifier
112: */
113: public CallIdentifier getCallIdentifer() {
114: return callIdentifier;
115: }
116:
117: /**
118: * Sets the CallId field
119: * @param cid String to set. This is the body part of the Call-Id
120: * header. It must have the form localId@host or localId.
121: * @throws IllegalArgumentException if cid is null, not a token, or is
122: * not a token@token.
123: */
124: public void setCallId(String cid) throws IllegalArgumentException {
125: callIdentifier = new CallIdentifier(cid);
126: }
127:
128: /**
129: * Sets the callIdentifier member.
130: * @param cid CallIdentifier to set (localId@host).
131: */
132: public void setCallIdentifier(CallIdentifier cid) {
133: callIdentifier = cid;
134: }
135:
136: /**
137: * Clone - do a deep copy.
138: * @return Object CallIdHeader
139: */
140: public Object clone() {
141: CallIdHeader retval = new CallIdHeader();
142: if (this .callIdentifier != null)
143: retval.callIdentifier = (CallIdentifier) this .callIdentifier
144: .clone();
145: return retval;
146: }
147:
148: /**
149: * Gets the caller id header value.
150: * @return the caller id value
151: */
152: public Object getValue() {
153: return callIdentifier;
154:
155: }
156:
157: /**
158: * Sets the header value field.
159: * @param value is the value field to set.
160: * @throws IllegalArgumentException if the value is invalid.
161: */
162: public void setHeaderValue(String value)
163: throws IllegalArgumentException {
164: setCallId(value);
165: }
166: }
|