FileDocCategorySizeDatePackage
CallIdentifier.javaAPI DocphoneME MR2 API (J2ME)6458Wed May 02 18:00:42 BST 2007gov.nist.siplite.header

CallIdentifier

public final class CallIdentifier extends GenericObject
The call identifer that goes into a callID header and a in-reply-to header.
see
CallIdHeader

Fields Summary
protected String
localId
localId field
protected String
host
host field
Constructors Summary
public CallIdentifier()
Default constructor

public CallIdentifier(String localId, String host)
Constructor

param
localId is the local id.
param
host is the host.

        this.localId = localId;
        this.host = host;
    
public CallIdentifier(String cid)
constructor

param
cid String to set
throws
IllegalArgumentException if cid is null or is not a token, or token@token

        setCallIdHeader(cid);
    
Methods Summary
private voidcheckValue(java.lang.String cid)
Checks Call-Id value validity

param
cid string to be checked
throws
IllegalArgumentException in case of illegal symbol use

        // RFC 3261 p.228
        // Call-ID  =  ( "Call-ID" / "i" ) HCOLON callid
        // callid   =  word [ "@" word ]
        // word        =  1*(alphanum / "-" / "." / "!" / "%" / "*" /
        //                "_" / "+" / "`" / "'" / "~" /
        //                "(" / ")" / "<" / ">" /
        //                ":" / "\" / DQUOTE /
        //                "/" / "[" / "]" / "?" /
        //                "{" / "}" )
        // The word construct is used in
        // Call-ID to allow most separators to be used.
        String word = "-.!%*_+`'~()<>:\\\"/[]?{}";
        char c;
        for (int i = 0; i < cid.length(); i++) {
            c = cid.charAt(i);
            if (Lexer.isAlpha(c) || Lexer.isHexDigit(c) ||
                word.indexOf(c) != -1) {
                 continue;
            }
            throw new IllegalArgumentException("Wrong Call-Id value:"
                                               + "illegal use of symbol '"
                                               +c+"' at '"+cid+"'"); 
        }
    
public java.lang.Objectclone()
Clone - do a deep copy.

return
Object CallIdentifier

        CallIdentifier retval = new CallIdentifier();

        if (this.localId != null) retval.localId = new String(this.localId);
        if (this.host != null) retval.host = new String(this.host);
        return retval;
    
public java.lang.Stringencode()
Get the encoded version of this id.

return
String to set

        if (host != null) {
            return localId + Separators.AT + host;
        } else {
            return localId;
        }
    
public booleanequals(java.lang.Object other)
Compare two call identifiers for equality.

param
other Object to set
return
true if the two call identifiers are equals, false otherwise

        if (! other.getClass().equals(this.getClass())) {
            return false;
        }
        CallIdentifier that = (CallIdentifier) other;
        if (this.localId.compareTo(that.localId) != 0) {
            return false;
        }
        if (this.host == that.host)
            return true;
        if ((this.host == null && that.host != null) ||
                (this.host != null && that.host == null)) return false;
        if (Utils.compareToIgnoreCase(host, that.host) != 0) {
            return false;
        }
        return true;
    
public java.lang.StringgetHost()
get the host field

return
host member String

        return host;
    
public java.lang.StringgetLocalId()
get the LocalId field

return
String

        return localId;
    
public voidsetCallIdHeader(java.lang.String cid)
set the callId field

param
cid Strimg to set
throws
IllegalArgumentException if cid is null or is not a token or token@token

        if (cid == null)
            throw new IllegalArgumentException("NULL!");
        int index = cid.indexOf('@");
        if (index == -1) {
            checkValue(cid);
            localId = cid;
            host = null;
        } else {
            if (index == 0 || index == cid.length()-1) {
                throw new IllegalArgumentException
                        ("CallIdHeader must be token@token or token");
            }
            String temp1 = cid.substring(0, index);
            String temp2 = cid.substring(index+1, cid.length());
            checkValue(temp1);
            checkValue(temp2);
            localId = temp1;
            host = temp2;
        }
    
public voidsetHost(java.lang.String host)
Set the host member

param
host String to set

        this.host = host;
    
public voidsetLocalId(java.lang.String localId)
Set the localId member

param
localId String to set

        this.localId = localId;
    
public java.lang.StringtoString()
Encodes the object. Calls encode().

return
String canonical encoded version of this CallIdentifier.

        return encode();