Wiki source code of [Google Android Client Platform] Extending the Platform
Last modified by sasindarukshan on 2012/08/04 14:11
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | Please refer to platform [[user guide>>doc:Google Android Client~>~>Platform~>~>User Guide||rel="__blank"]] for basic information about the platform. | ||
| 2 | |||
| 3 | = Extending Data Access Layer = | ||
| 4 | |||
| 5 | |||
| 6 | ==== Data.RDB ==== | ||
| 7 | |||
| 8 | Adding a new Table/Entity to Database. | ||
| 9 | In the org.xwiki.android.data.rdb.EntityManager | ||
| 10 | |||
| 11 | {{code language="java"}} | ||
| 12 | @Override | ||
| 13 | public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) | ||
| 14 | { | ||
| 15 | try { | ||
| 16 | Log.i(EntityManager.class.getSimpleName(), "onCreate(): create Database"); | ||
| 17 | add TableUtils.createTable(connectionSource, MyEntity.class); for all your entities | ||
| 18 | TableUtils.createTable(connectionSource, User.class); | ||
| 19 | TableUtils.createTable(connectionSource, FSDocumentReference.class); | ||
| 20 | TableUtils.createTable(connectionSource, SyncOutEntity.class); | ||
| 21 | TableUtils.createTable(connectionSource, OurNewEntity.class); | ||
| 22 | } catch (SQLException e) { | ||
| 23 | Log.e(EntityManager.class.getName(), "Can't create database", e); | ||
| 24 | throw new RuntimeException(e); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | {{/code}} | ||
| 28 | |||
| 29 | |||
| 30 | = Extending Xwiki Application Context = | ||
| 31 | |||
| 32 | The XWiki Application Context is there to provide IoC. API users are advised to use it to get concrete instances for their dependencies on major components. We do this to keep our flexibility. | ||
| 33 | Add a method to create an instance of such a component when there can be more than one implementations for it. | ||
| 34 | Conventions | ||
| 35 | ctx.getComponent() // when you may receive the same component again and again | ||
| 36 | ctx.newComponent() // you receive a new instance of the component. | ||
| 37 | |||
| 38 | |||
| 39 | Example. | ||
| 40 | We have provided | ||
| 41 | |||
| 42 | {{code language="java"}} | ||
| 43 | public class XWikiApplicationContext extends Application implements XWikiApplicationContextAPI | ||
| 44 | { | ||
| 45 | ... | ||
| 46 | public FileStoreManager getFileStoreManager() | ||
| 47 | { ... | ||
| 48 | |||
| 49 | public RESTfulManager newRESTfulManager() | ||
| 50 | { ... | ||
| 51 | {{/code}} | ||
| 52 | |||
| 53 | |||
| 54 | {{info}} | ||
| 55 | please make sure to define your simple dependency injecting method in the XWikiApplicationContextAPI interface as well. | ||
| 56 | {{/info}} |