Android Open Source - android-sqlite-server Abstract Command Message






From Project

Back to project page android-sqlite-server.

License

The source code is released under:

Apache License

If you think the Android project android-sqlite-server listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.devtcg.sqliteserver.impl.binder.protocol;
/*from  w ww .  j  av  a 2 s .c  o  m*/
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import org.devtcg.sqliteserver.impl.binder.ClientTransactor;
import org.devtcg.sqliteserver.impl.binder.SQLiteServerProtocolException;

/**
 * Client representation of the RPC call (represents a request and its response
 * from the server).
 * <p>
 * TODO: Reimplement commands using an auto-generated aidl interface to avoid the need to
 * allocate a Bundle.
 */
public abstract class AbstractCommandMessage {
    public static final String KEY_METHOD_NAME = "method_name";
    public static final String KEY_CLIENT_BINDER = "client_binder";

    public static final String KEY_SERVER_EXCEPTION_HELPER = "server_exception_helper";

    private final ClientTransactor mTransactor;
    private final MethodName mMethodName;

    private Bundle mRequest;
    private Bundle mResponse;

    public AbstractCommandMessage(ClientTransactor transactor, MethodName methodName) {
        mTransactor = transactor;
        mMethodName = methodName;
    }

    public void transact() throws SQLiteException {
        mRequest = createRequest();
        mRequest = onBuildRequest(mRequest);
        mResponse = mTransactor.transact(mRequest);
        interpretResponse();
    }

    private void handleErrorIfApplicable() throws SQLiteException {
        if (mResponse.containsKey(KEY_SERVER_EXCEPTION_HELPER)) {
            // Throws in this method for remote processes...
            ExceptionTransportHelper exceptionHelper =
                    mResponse.getParcelable(KEY_SERVER_EXCEPTION_HELPER);

            // And here for local processes...
            exceptionHelper.propagateLocalException();
            throw new AssertionError("Must not reach here...");
        }
    }

    private void interpretResponse() throws SQLiteException {
        handleErrorIfApplicable();
        try {
            onParseResponse(mResponse);
        } catch (SQLiteServerProtocolException e) {
            throw new SQLiteException("SQLiteServer error", e);
        }
    }

    protected final Bundle getResponse() {
        return mResponse;
    }

    protected Bundle createRequest() {
        Bundle request = new Bundle();
        request.putInt(KEY_METHOD_NAME, mMethodName.ordinal());
        request.putParcelable(KEY_CLIENT_BINDER, mTransactor.getClientHandle());
        return request;
    }

    protected abstract Bundle onBuildRequest(Bundle request);
    protected abstract void onParseResponse(Bundle response)
            throws SQLiteServerProtocolException;
}




Java Source Code List

aosp.android.database.BulkCursorDescriptor.java
aosp.android.database.BulkCursorNative.java
aosp.android.database.BulkCursorToCursorAdaptor.java
aosp.android.database.CrossProcessCursorWrapper.java
aosp.android.database.CursorToBulkCursorAdaptor.java
aosp.android.database.IBulkCursor.java
aosp.android.database.MoreDatabaseUtils.java
org.devtcg.sqliteserver.SQLiteContentProviderServer.java
org.devtcg.sqliteserver.SQLiteServerConnectionManager.java
org.devtcg.sqliteserver.SQLiteServerConnection.java
org.devtcg.sqliteserver.SQLiteServer.java
org.devtcg.sqliteserver.SQLiteServiceServer.java
org.devtcg.sqliteserver.exception.SQLiteServerException.java
org.devtcg.sqliteserver.impl.ExecutorHelper.java
org.devtcg.sqliteserver.impl.SQLiteExecutor.java
org.devtcg.sqliteserver.impl.ServerImplProvider.java
org.devtcg.sqliteserver.impl.binder.AbstractBinderClient.java
org.devtcg.sqliteserver.impl.binder.BinderHandle.java
org.devtcg.sqliteserver.impl.binder.BundleUtils.java
org.devtcg.sqliteserver.impl.binder.ClientTransactor.java
org.devtcg.sqliteserver.impl.binder.ContentObserverProxy.java
org.devtcg.sqliteserver.impl.binder.ContentProviderClient.java
org.devtcg.sqliteserver.impl.binder.SQLiteServerProtocolException.java
org.devtcg.sqliteserver.impl.binder.ServerImpl.java
org.devtcg.sqliteserver.impl.binder.ServerState.java
org.devtcg.sqliteserver.impl.binder.ServiceClient.java
org.devtcg.sqliteserver.impl.binder.ThreadAffinityExecutor.java
org.devtcg.sqliteserver.impl.binder.protocol.AbstractCommandHandler.java
org.devtcg.sqliteserver.impl.binder.protocol.AbstractCommandMessage.java
org.devtcg.sqliteserver.impl.binder.protocol.AcquireCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.BeginTransactionCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.DeleteCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.EndTransactionCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.ExceptionTransportHelper.java
org.devtcg.sqliteserver.impl.binder.protocol.ExecSQLCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.InsertCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.MethodName.java
org.devtcg.sqliteserver.impl.binder.protocol.RawQueryCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.ReleaseCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.SetTransactionSuccessfulCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.UpdateCommand.java
org.devtcg.sqliteserver.sample.MyActivity.java
org.devtcg.sqliteserver.sample.MyOpenHelper.java
org.devtcg.sqliteserver.sample.TestContentProvider.java
org.devtcg.sqliteserver.sample.TestService.java