|
![]() |
||||||||
PREV NEXT | FRAMES NO FRAMES |
See:
Description
Packages | |
---|---|
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 withCursorBind
. A similar approach is used when injecting from XML sources (seeDOMFeeder
andXMLBind
).
metagloss List |
Stock android List hosts = new ArrayList(); Cursor cursor = ...; int id = cursor.getColumnIndex(UserHostTable.ID); int userTableId = cursor.getColumnIndex(UserHostTable.USER_TABLE_ID); int cpid = cursor.getColumnIndex(UserHostTable.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(); host.setDatabaseId(cursor.getInt(id)); host.setUserId(cursor.getInt(userTableId)); host.setCPID(cursor.getString(cpid)); host.setName(cursor.getString(name)); host.setHostId(cursor.getInt(hostId)); host.setCreationTime(cursor.getLong(createdOn)); host.setCredit(cursor.getInt(credit)); host.setCreditRAC(cursor.getInt(rac)); host.setCPUCount(cursor.getInt(cpuCount)); host.setFlops(cursor.getInt(flops)); host.setMips(cursor.getInt(mips)); host.setVendor(cursor.getInt(vendor)); host.setModel(cursor.getInt(model)); host.setOSName(cursor.getInt(os)); hosts.add(host); } cursor.close(); // etc |
Creating ContentValues from data object
Instances of classes annotated withCursorBind
are simple to parse intoContentValues
.
metagloss 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()); |
As released binary
- Make sure that Eclipse is installed and that ADT is at least at version
0.9.8
- Download the latest version.
- Go to File | Import...
- In the Import window, choose General / Existing Projects into Workspace
- Choose Select archive file and point it to the location of the downloaded metagloss.tar.gz
- Check metagloss and click Finish
- RMB click on your android project of choice, choose Properties | Android
- Press the appropriate Add..., choose metagloss
From svn
- Make sure that Eclipse is installed and that ADT is at least at version
0.9.8
- Open Eclipse and check out metagloss project from http://metagloss.svn.sourceforge.net/svnroot/metagloss/trunk/metagloss
- RMB click on your android project of choice, choose Properties | Android
- 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 http://projectlombok.org/features/index.html - the binary is already distributed inside thelib
folder - to configure Eclipse. To make it play (relatively) nice with Eclipse/ADT, configure as follows:In the future, metagloss will also provide a delomboked release.
- Install Project Lombok (see above).
- Open Eclipse
- RMB click your android project, choose Build Path | Add Libraries...
- Choose User Library, next window, click User Libraries
- Click New... and give it an appropriate name
- Select your newly created library, click Add JARs...
- Locate and add lombok.jar, typically in your
$ECLIPSE_HOME
- Click OK to return to the previous window
- Check your newly crated lombok (user) library
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |