FileDocCategorySizeDatePackage
GDataAccount.javaAPI DocApache Lucene 2.1.09550Wed Feb 14 10:46:06 GMT 2007org.apache.lucene.gdata.data

GDataAccount

public class GDataAccount extends Object
The GData-Server system provides acccount to be associated with registered feed. Every feed has an owner account. The account holder is automaticaly in role to modify his feeds. One account can own n feeds having m entries.

Additionally an account can be in role to modify other feeds, create accounts or feeds. See {@link AccountRole} for detailed infomation about roles. One account can also have more than one role. All roles in {@link AccountRole} can be combined

For each account values for author name, author email and author link can be set at creation time or during an update. These values will be used as the corresponding values for the feed {@link org.apache.lucene.gdata.data.ServerBaseFeed#addAuthor(Person)} if no value for the feed has be specified.

author
Simon Willnauer

Fields Summary
private String
name
private String
authorname
private String
authorMail
private URL
authorLink
private String
password
private Set
roles
Constructors Summary
public GDataAccount()
Creates a new GDataAccount. The default role {@link AccountRole#USER} will be set.


                      
      
        this.roles.add(AccountRole.USER);

    
Methods Summary
public static final org.apache.lucene.gdata.data.GDataAccountcreateAdminAccount()

return
- a new Administrator account

        GDataAccount retVal = new GDataAccount();
        retVal.setName("administrator");
        retVal.setPassword("password");
        retVal.setRole(AccountRole.USERADMINISTRATOR);
        retVal.setRole(AccountRole.FEEDAMINISTRATOR);
        retVal.setRole(AccountRole.ENTRYAMINISTRATOR);
        return retVal;
    
public booleanequals(java.lang.Object o)

see
java.lang.Object#equals(java.lang.Object)

        if(this.name == null)
            return super.equals(o);
        if(o == null)
            return false;
        if (this == o)
            return true;
        if (!(o instanceof GDataAccount))
            return false;
        GDataAccount toCompare = (GDataAccount) o;
        if (this.name.equals(toCompare.name))
            return true;
        return false;

    
public java.net.URLgetAuthorLink()

return
- the http link specified for the author

        return this.authorLink;
    
public java.lang.StringgetAuthorMail()

return
- the authors mail address

        return this.authorMail;
    
public java.lang.StringgetAuthorname()

return
- the name specified as being the author name

        return this.authorname;
    
public java.lang.StringgetName()

return
- the account name

        return this.name;
    
public java.lang.StringgetPassword()

return
- the password

        return this.password;
    
public java.util.SetgetRoles()

return
- the set containing all roles

        return this.roles;
    
public intgetRolesAsInt()

see
GDataAccount#setRolesAsInt(int)
return
- the integer representation for the user roles

        // 1 as the Userrole is always set
        int bits = 1;
        for (AccountRole role : this.roles) {
            if (role == AccountRole.ENTRYAMINISTRATOR)
                bits ^= 2;
            else if (role == AccountRole.FEEDAMINISTRATOR)
                bits ^= 4;
            else if (role == AccountRole.USERADMINISTRATOR)
                bits ^= 8;

        }
        return bits;

    
public inthashCode()

see
java.lang.Object#hashCode()

        if(this.name == null)
            return super.hashCode();
        int ret = 37;
        ret = 9 * ret + this.name.hashCode();
        return ret;
    
public static booleanisInRole(int intRole, org.apache.lucene.gdata.data.GDataAccount$AccountRole role)
checks whether the given integer matches the account role.

param
intRole - integer representation of a role
param
role - the account role to match
return
true if and only if the given roles match, otherwise false

        if(role == AccountRole.USER)
            return (intRole&1)>0;
        if (role == AccountRole.ENTRYAMINISTRATOR)
            return (intRole&2) >0 ;
        else if (role == AccountRole.FEEDAMINISTRATOR)
            return (intRole&4) >0 ;
        else if (role == AccountRole.USERADMINISTRATOR)
            return (intRole&8) >0 ;
        return false;
    
public booleanisUserInRole(org.apache.lucene.gdata.data.GDataAccount$AccountRole role)

param
role - the role to check
return
true if the role list contains the given role

        if (role == null)
            return false;
        return this.roles.contains(role);
    
public booleanrequiredValuesSet()
Checks the requiered values for creating an account are set. Required values are name and password the minimum length of these values is 6.

return
true if an only if password and name are not null and the length is > 5

        return (this.name != null && this.password != null
                && this.name.length() > 5 && this.password.length() > 5);
    
public voidsetAuthorLink(java.net.URL authorLink)

param
authorLink - the http link specified for the author

        this.authorLink = authorLink;
    
public voidsetAuthorMail(java.lang.String authorMail)

param
authorMail - the authors mail address

        this.authorMail = authorMail;
    
public voidsetAuthorname(java.lang.String authorname)

param
authorname - the name specified as being the author name

        this.authorname = authorname;
    
public voidsetName(java.lang.String name)

param
name The name to set.

        this.name = name;
    
public voidsetPassword(java.lang.String password)

param
password - the account Password

        this.password = password;
    
public voidsetRole(org.apache.lucene.gdata.data.GDataAccount$AccountRole role)
Adds the given role to the role list

param
role - the role to add to the role list

        if (role == null)
            return;
        this.roles.add(role);
    
public voidsetRolesAsInt(int i)
Sets the roles from a int representation.
  1. The fist bit set indicates a {@link AccountRole#USER} - int value 1
  2. The second bit set indicates a {@link AccountRole#ENTRYAMINISTRATOR} - int value 2
  3. The third bit set indicates a {@link AccountRole#FEEDAMINISTRATOR} - int value 4
  4. The forth bit set indicates a {@link AccountRole#USERADMINISTRATOR} - int value 8
    1. This method will only set roles, will not remove roles! A combination of roles is also possible e.g. the int value 6 combines {@link AccountRole#ENTRYAMINISTRATOR} and {@link AccountRole#FEEDAMINISTRATOR}.

      param
      i - the integer used to set the roles

      
              if ((i & 2) > 0)
                  this.roles.add(AccountRole.ENTRYAMINISTRATOR);
              if ((i & 4) > 0)
                  this.roles.add(AccountRole.FEEDAMINISTRATOR);
              if ((i & 8) > 0)
                  this.roles.add(AccountRole.USERADMINISTRATOR);
      
          
public java.lang.StringtoString()

see
java.lang.Object#toString()

        StringBuilder builder = new StringBuilder("GdataAccount: ");
        builder.append("name: ").append(this.name);
        builder.append(" password: ").append((this.password!= null?" length: "+this.password.length():null));
        builder.append(" author: ").append(this.authorname);
        builder.append(" author email: ").append(this.authorMail);
        builder.append(" author link: ").append(this.authorLink!=null?"":this.authorLink);
        return builder.toString();