FileDocCategorySizeDatePackage
UserInfo.javaAPI DocphoneME MR2 API (J2ME)5854Wed May 02 18:00:42 BST 2007gov.nist.siplite.address

UserInfo

public final class UserInfo extends Object
User information part of a URL. This code is in the public domain.

(Omit source code)

Fields Summary
private String
user
user field
private String
password
password field
protected int
userType
userType field
public static final int
TELEPHONE_SUBSCRIBER
Constant field
public static final int
USER
constant field
Constructors Summary
public UserInfo()
Default constructor


            
      
        super();
    
Methods Summary
public voidclearPassword()
Clear the password field.

        this.password = null;
    
public java.lang.Objectclone()
Copies the current instance.

return
a copy of the current instance

        UserInfo retval = new UserInfo();
        try {
            retval.setUser(user);
            retval.setPassword(password);
        } catch (IllegalArgumentException e) {
            // intentionally ignored
            // it shoild be impossible to get here due to this.user
            // and this.password are verified values
        }

        return retval;
    
public java.lang.Stringencode()
Encode the user information as a string.

return
String

        if (password != null) {
            return new StringBuffer().
                    append(user).append(Separators.COLON).
                    append(password).toString();
        } else {
            return user;
        }
    
public booleanequals(java.lang.Object obj)
Compare for equality.

param
obj Object to set
return
true if the two headers are equals, false otherwise.

        if (!getClass().getName().equals(obj.getClass().getName())) {
            return false;
        }
        UserInfo other = (UserInfo) obj;
        if (this.userType != other.userType) {
            return false;
        }
        String u1 = this.user;
        String u2 = other.user;
        if (u1 == null) u1 = "";
        if (u2 == null) u2 = "";
        if (!u1.toLowerCase().equals
            (u2.toLowerCase())) {
            return false;
        }
        u1 = this.password;
        u2 = other.password;
        if (u1 == null) u1 = "";
        if (u2 == null) u2 = "";
        if (!u1.equals(u2)) {
            return false;
        }
        return (true);
    
public java.lang.StringgetPassword()
Get the password field.

return
String

        return password;
    
public java.lang.StringgetUser()
Get the user field.

return
String

        return user;
    
public intgetUserType()
Gets the user type (which can be set to TELEPHONE_SUBSCRIBER or USER).

return
the type of user.

        return userType;
    
public voidsetPassword(java.lang.String p)
Set the password member.

param
p String to set
throws
IllegalArgumentException if user name contains invalid characters

        // IMPL_NOTE: check for the password validity
        password = p;
    
public voidsetUser(java.lang.String user)
Set the user member.

param
user String to set
throws
IllegalArgumentException if user name contains invalid characters

        if (false == Lexer.isValidUserName(user)) {
            throw new IllegalArgumentException("User name '" + user +
                                               "' contains " +
                                               "illegal characters");
        }
        this.user = user;
        // add this (taken form sip_messageParser)
        // otherwise comparison of two SipUrl will fail because this
        // parameter is not set (whereas it is set in sip_messageParser).
        if (user != null && (user.indexOf(Separators.POUND) >= 0 ||
                             user.indexOf(Separators.SEMICOLON) >= 0)) {
            setUserType(UserInfo.TELEPHONE_SUBSCRIBER);
        } else {
            setUserType(UserInfo.USER);
        }
    
public voidsetUserType(int type)
Set the user type (to TELEPHONE_SUBSCRIBER or USER).

param
type int to set
throws
IllegalArgumentException if type is not in range.

        if (type != TELEPHONE_SUBSCRIBER && type != USER) {
            throw new IllegalArgumentException
                    ("Parameter not in range");
        }
        userType = type;