FileDocCategorySizeDatePackage
StorageAccountWrapper.javaAPI DocApache Lucene 2.1.04036Wed Feb 14 10:46:04 GMT 2007org.apache.lucene.gdata.storage.lucenestorage

StorageAccountWrapper

public class StorageAccountWrapper extends Object implements StorageWrapper
Wrapps a User Object. The wrapper provides also a Lucene repesentation of the user; User Objects will not be Buffered in the lucene storage component. Each User will be written imidialtely.
author
Simon Willnauer

Fields Summary
private static final Log
LOG
public static final String
FIELD_ACCOUNTNAME
Lucene field for the username
public static final String
FIELD_PASSWORD
Lucene field for the password
public static final String
FIELD_AUTHORNAME
Lucene field for the author name
public static final String
FIELD_AUTHORMAIL
Lucene field for the author mail address
public static final String
FIELD_AUTHORHREF
Lucene field for the author link
public static final String
FIELD_ROLES
Lucene field fot the userroles
private final org.apache.lucene.gdata.data.GDataAccount
user
Constructors Summary
public StorageAccountWrapper(org.apache.lucene.gdata.data.GDataAccount user)

param
user - the user to be wrapped

                 
        
        if(user == null)
            throw new IllegalArgumentException("user must not be null");
        this.user = user;
    
Methods Summary
public static org.apache.lucene.gdata.data.GDataAccountbuildEntity(org.apache.lucene.document.Document doc)

param
doc - a lucene document representation of an user
return
- the user to build from the document. or null if the document is null

        if(doc == null)
            return null;
        
        GDataAccount user = new GDataAccount();
        user.setName(doc.get(FIELD_ACCOUNTNAME));
        user.setPassword(doc.get(FIELD_PASSWORD));
        user.setAuthorname(doc.get(FIELD_AUTHORNAME));
        user.setAuthorMail(doc.get(FIELD_AUTHORMAIL));
        try{
        user.setRolesAsInt(Integer.parseInt(doc.get(FIELD_ROLES)));
        }catch (NumberFormatException e) {
            LOG.info("Can't parse userroles: "+user.getName()+" throws NumberFormatException. -- skipping --",e);
        }
        try {
            if(doc.get(FIELD_AUTHORHREF)!= null)
                user.setAuthorLink(new URL(doc.get(FIELD_AUTHORHREF)));
        } catch (MalformedURLException e) {
            LOG.info("SPECIFIED URL for user: "+user.getName()+" throws MalformedURLException. -- skipping --",e);
        }
        return user;
    
public org.apache.lucene.document.DocumentgetLuceneDocument()

see
org.apache.lucene.gdata.storage.lucenestorage.StorageWrapper#getLuceneDocument()

        Document doc = new Document();
        
        doc.add(new Field(FIELD_ACCOUNTNAME,this.user.getName(),Field.Store.YES,Field.Index.UN_TOKENIZED));
        doc.add(new Field(FIELD_PASSWORD,this.user.getPassword()==null?"":this.user.getPassword(),Field.Store.YES,Field.Index.NO));
        doc.add(new Field(FIELD_AUTHORNAME,this.user.getAuthorname()==null?"":this.user.getAuthorname(),Field.Store.YES,Field.Index.NO));
        doc.add(new Field(FIELD_AUTHORMAIL,this.user.getAuthorMail()==null?"":this.user.getAuthorMail(),Field.Store.YES,Field.Index.NO));
        doc.add(new Field(FIELD_AUTHORHREF,this.user.getAuthorLink()==null?"":this.user.getAuthorLink().toString(),Field.Store.YES,Field.Index.NO));
        doc.add(new Field(FIELD_ROLES, Integer.toString(this.user.getRolesAsInt()),Field.Store.YES,Field.Index.NO)); 
       
        return doc;
    
public org.apache.lucene.gdata.data.GDataAccountgetUser()

return
- the wrapped user

        return this.user;