com.google.providerhelper
Class Builder

java.lang.Object
  extended by com.google.providerhelper.Builder

public abstract class Builder
extends java.lang.Object

Builds an object using fields extracted from an Android ContentProvider's Cursor object.

To use it, extend this class, and for each ContentProvider column name (e.g. "foo") which you wish to process, provide a method named setFoo(), i.e., the field's name capitalized and prefixed by "set". This method must take one argument, which must be of type int, long, String, float, or double, depending on the type provided by the ContentProvider, which you have to know because the ContentProvider doesn't expose them. If you want to process the _id field, provide a set_id method.

Builder provides a constructor of one argument, an Android.database.Cursor. This extracts fields from the Cursor and for each field xxx, calls your setXxx method if provided, extracting the expected type of argument from the Cursor.

Because of Java constructor inheritance weirdness, if you add any more constructors to your inheritor class, you must ensure that it also has a zero-argument constructor, which however need not do anything.

This class may be used standalone with Cursor objects obtained anyhow, and is also designed to with the associated Reader class.

Here's an example of a small class which stores the phone number and time of a phone call, and can be initialized using a Cursor from the CallLog.Calls Content Provider, which contains "number" and "date" fields.

  public class Call extends Builder {
    String phoneNumber;
    String date;
    public void setNumber(String number) {
      phoneNumber = number;
    }
    public void setDate(Long date) {
     this.date = 
       DateUtils.formatDateTime(this, date, DateUtils.FORMAT_SHOW_TIME|DateUtils.FORMAT_SHOW_DATE);
    }
    public String toString() {
     return "Called " + number + " at " + date;
    }
  }
  
  // elsewhere
  Cursor cursor = activity.managedQuery(CallLog.Calls.CONTENT_URI, ... );
  // ... navigate cursor ...
  Call call = new Call(cursor); // call.number and call.date are now set
 

See Also:
Reader

Constructor Summary
Builder()
          Only exists to work around Java introspection awkwardness; probably not useful externally.
Builder(Cursor cursor)
          Any class which extends Builder may use this as a constructor.
 
Method Summary
 java.lang.Object load(Cursor cursor)
          This is required because java introspection doesn't allow you to call a non-nullary constructor which is is inherited from a superclass.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Builder

public Builder()
Only exists to work around Java introspection awkwardness; probably not useful externally.


Builder

public Builder(Cursor cursor)
Any class which extends Builder may use this as a constructor.

Parameters:
cursor - An android.database.Cursor associated with a Content Provider
Method Detail

load

public java.lang.Object load(Cursor cursor)
This is required because java introspection doesn't allow you to call a non-nullary constructor which is is inherited from a superclass. So the introspect code in Reader calls the nullary constructor and then this method to fill in the fields. This is probably not useful externally.

Parameters:
cursor - An android.database.Cursor associated with a Content Provider
Returns:
the object that was loaded up.