そこで、Android 用と J2ME 用の 2 つの実装で、私の要件を満たすインターフェイスを作成しました。
インターフェイスの外観は次のとおりです。
public interface ISDataStore {
/**
* Get number of records in data store.
*/
public int getNumRecords() throws SDataStoreException;
/**
* Get size of one record with specified id in bytes.
*
* @param record_id id of the record
*/
public int getRecordSize(int record_id) throws SDataStoreException;
/**
* Get record.
*
* @param record_id id of the record to read
* @param data byte array where to put the data
* @param offset offset in 'data' array from which should start to copy
*/
public void getRecord(int record_id, byte[] data, int offset) throws SDataStoreException;
/**
* Get record.
*
* @param record_id id of the record to read
*/
public byte[] getRecord(int record_id) throws SDataStoreException;
/**
* Resolves is record with specified id exists or not.
*
* @param record_id id of the record
* @return true if record exists, otherwise false
*/
public boolean isRecordExists(int record_id) throws SDataStoreException;
/**
* Put new record or update existing one.
*
* @param record_id id of the record
* @param data byte array of data
* @param offset offset in the data byte array
* @param length number of bytes to store
*
* @return true if operation was successful, otherwise false
*
*/
public boolean setRecord(int record_id, byte[] data, int offset, int length) throws SDataStoreException;
/**
* Delete the record.
*
* @param record_id id of the record
*
* @return true if operation was successful, otherwise false
*/
public boolean deleteRecord(int record_id) throws SDataStoreException;
/**
* Clear all the records.
*/
public void deleteAll() throws SDataStoreException;
/**
* Close the data store.
*/
public void close() throws SDataStoreException;
}
データ ストア用のファクトリもあります。
public interface ISDataStoreFactory {
/**
* @param dataStoreId id of the data store
* @return ISDataStore with given id. Type of this id depends on target platform
*/
public ISDataStore getDataStore(Object dataStoreId) throws SDataStoreException;
/**
* Destroys data store with given id.
* @param dataStoreId id of the data store. Type of this id depends on target platform
*/
public void destroyDataStore(Object dataStoreId) throws SDataStoreException;
}
Doxygen によって自動生成されたドキュメントは、ここにあります。
インターフェイスとすべての実装を含む Mercurial リポジトリは、ここにあります。
使用方法:
質問で既に述べたように、Android 用のアプリと J2ME 用のアプリがありますが、これらのアプリはどちらも同様のことを行います。(興味のある人は、Bluetooth経由でリモート組み込みデバイスと通信します)
両方のアプリには、主な仕事を行う共通の低レベル部分があります。
私はinterface IMainApp
、そのようなものを持っています:
public interface IMainApp {
public ISDataStoreFactory getDataStoreFactory();
/*
* ... some other methods
*/
}
両方のアプリ (Android 用と J2ME 用) には、このインターフェースの独自の実装があり、その参照を低レベル部分に渡します。低レベル部分が何らかのデータ ストアを開きたい場合、ISDataStoreFactory
返された を使用しIMainApp.getDataStoreFactory
ます。私がやりたいように動作します。
誰にとっても役立つことを願っています。