metagloss 0.0.2

metagloss is an annotation-centric android library for reducing boilerplate code.


net.sf.metagloss Provides a sense of warmth for the classes deeper down the package hierarchy.
net.sf.metagloss.db Provides classes for working with databases.
net.sf.metagloss.injection Provides the InjectionManager and AnnotatedMethod.
net.sf.metagloss.preference Provides the AnnotatedPreferenceActivity along with its set annotations for binding and constraining data.
net.sf.metagloss.xml Provides classes for binding XML data to objects.


metagloss is an annotation-centric android library for reducing boilerplate code. Relying on run-time parsing and compile-time code generation, metagloss provides facilities for mapping XML and databases to data objects, dealing with preference screens and working with DB queries. Annotations are validated during compilation in order to detect typos and misconfigurations.



Enough! or too much.

Creating data objects from an SQLite Cursor

The only thing required to make a class eligible for setter injection is annotating the proper fields or methods with CursorBind. A similar approach is used when injecting from XML sources (see DOMFeeder and XMLBind).


List hosts = new ArrayList();
Cursor cursor = ...;

// conserving space for side-by-side comp.
AssistCursor<UserHostTable> ac =
    new AssistCursor<UserHostTable>(
        UserHostTable.class, cursor);

while (
    Host host = new Host();
cursor.close(); // etc

Stock android

List hosts = new ArrayList();
Cursor cursor = ...;

int id = 
int userTableId =
int cpid =
int name = ...
int hostId = ...
int createdOn = ...
int credit = ...
int rac = ...
int cpuCount = ...
int flops = ...
int mips =  ...
int vendor = ...
int model =  ...
int os =  ...

while (cursor.moveToNext())
    Host host = new Host();

cursor.close(); // etc

Creating ContentValues from data object

Instances of classes annotated with CursorBind are simple to parse into ContentValues.


Host host = ...;
ContentValues cv = new ContentValues();
DBUtils.buildContentValues(cv, host);

Stock android

Host host = ...;
ContentValues cv = new ContentValues();
cv.put(UserHostTable.ID, host.getDatabaseId());
cv.put(UserHostTable.USER_TABLE_ID, host.getUserId());
cv.put(UserHostTable.CPID, host.getCPID());
cv.put(UserHostTable.NAME, host.getName());
cv.put(UserHostTable.HOST_ID, host.getHostId());
cv.put(UserHostTable.CREATED_ON, host.getCreationTime());
cv.put(UserHostTable.CREDIT, host.getCredit());
cv.put(UserHostTable.RAC, host.getCreditRAC());
cv.put(UserHostTable.CPU_COUNT, host.getCPUCount());
cv.put(UserHostTable.FLOPS, host.getFLOPS());
cv.put(UserHostTable.MIPS, host.getMIPS());
cv.put(UserHostTable.VENDOR, host.getVendor());
cv.put(UserHostTable.MODEL, host.getModel());
cv.put(UserHostTable.OS, host.getOSName());

Installing metagloss in Eclipse

As released binary

  1. Make sure that Eclipse is installed and that ADT is at least at version 0.9.8
  2. Download the latest version.
  3. Go to File | Import...
  4. In the Import window, choose General / Existing Projects into Workspace
  5. Choose Select archive file and point it to the location of the downloaded metagloss.tar.gz
  6. Check metagloss and click Finish
  7. RMB click on your android project of choice, choose Properties | Android
  8. Press the appropriate Add..., choose metagloss

From svn

  1. Make sure that Eclipse is installed and that ADT is at least at version 0.9.8
  2. Open Eclipse and check out metagloss project from
  3. RMB click on your android project of choice, choose Properties | Android
  4. Press the appropriate Add..., choose metagloss

Dependency: Project Lombok

Project Lombok is internally used by some parts of metagloss to reduce the boilerplate code (the irony...). To install Project Lombok, follow the instructions on - the binary is already distributed inside the lib folder - to configure Eclipse.

To make it play (relatively) nice with Eclipse/ADT, configure as follows:

  1. Install Project Lombok (see above).
  2. Open Eclipse
  3. RMB click your android project, choose Build Path | Add Libraries...
  4. Choose User Library, next window, click User Libraries
  5. Click New... and give it an appropriate name
  6. Select your newly created library, click Add JARs...
  7. Locate and add lombok.jar, typically in your $ECLIPSE_HOME
  8. Click OK to return to the previous window
  9. Check your newly crated lombok (user) library
In the future, metagloss will also provide a delomboked release.

Setting up the annotation processors

To ease the life of programmers, metagloss provides compile-time validation of annotated classes via a collection of annotation processors. Rudimentary compliance checks are made to ensure that annotations decorate eligible elements and contain sensible data. Any discovered errors and erroneous conditions are emitted as markers inside Eclipse's editor and problem view.

Video is a little out-of-date in regards to metagloss' processors, but the procedure is the same.

Screencasts and videos online

To enable metagloss' annotation processor, bring up your project's properties window: Enable project specific settings for Java Compiler | Annotation Processing and Java Compiler | Annotation Processing | Factory Path. In the Factory Path window, choose Add JARs... and point it to metagloss/lib/metagloss-annotationprocessor.jar.

Naively childish

The library is still maturing from its infant state; as such, drastic changes may occur in-between releases. Future versions will be less prone to invasive changes.

The original code was extrapolated from the more refined parts of BOINC Echo - it's been using metagloss without incident, though it hasn't been extensively tested in other configurations.

Paying tribute where tribute is due

The Taglets Collection is a lib and collection of ready-to-use javadoc taglets/custom tags. The {@at} and {@source} taglets are truly wonderful and should have been part of the javadoc tool long ago.

Project Lombok is a compile-time, annotation-based code generator capable of @Getter/@Setter generation plus @ToString, @EqualsAndHashCode and many more. Inspired piece of work.


Sourceforge project page:
Subversion repository
mailing-list / google group:
metagloss license
ohloh page