FileDocCategorySizeDatePackage
CursorToBulkCursorAdaptor.javaAPI DocAndroid 1.5 API7650Wed May 06 22:41:54 BST 2009android.database

CursorToBulkCursorAdaptor

public final class CursorToBulkCursorAdaptor extends BulkCursorNative implements IBinder.DeathRecipient
Wraps a BulkCursor around an existing Cursor making it remotable. {@hide}

Fields Summary
private static final String
TAG
private final CrossProcessCursor
mCursor
private CursorWindow
mWindow
private final String
mProviderName
private final boolean
mReadOnly
private ContentObserverProxy
mObserver
Constructors Summary
public CursorToBulkCursorAdaptor(Cursor cursor, IContentObserver observer, String providerName, boolean allowWrite, CursorWindow window)

        try {
            mCursor = (CrossProcessCursor) cursor;
            if (mCursor instanceof AbstractWindowedCursor) {
                AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor;
                if (windowedCursor.hasWindow()) {
                    if (Log.isLoggable(TAG, Log.VERBOSE) || Config.LOGV) {
                        Log.v(TAG, "Cross process cursor has a local window before setWindow in "
                                + providerName, new RuntimeException());
                    }
                }
                windowedCursor.setWindow(window);
            } else {
                mWindow = window;
                mCursor.fillWindow(0, window);
            }
        } catch (ClassCastException e) {
            // TODO Implement this case.
            throw new UnsupportedOperationException(
                    "Only CrossProcessCursor cursors are supported across process for now", e);
        }
        mProviderName = providerName;
        mReadOnly = !allowWrite;

        createAndRegisterObserverProxy(observer);
    
Methods Summary
public voidbinderDied()

        mCursor.close();
        if (mWindow != null) {
            mWindow.close();
        }
    
public voidclose()

        maybeUnregisterObserverProxy();
        mCursor.deactivate();       
        
    
public intcount()

        return mCursor.getCount();
    
private voidcreateAndRegisterObserverProxy(IContentObserver observer)
Create a ContentObserver from the observer and register it as an observer on the underlying cursor.

param
observer the IContentObserver that wants to monitor the cursor
throws
IllegalStateException if an observer is already registered

        if (mObserver != null) {
            throw new IllegalStateException("an observer is already registered");
        }
        mObserver = new ContentObserverProxy(observer, this);
        mCursor.registerContentObserver(mObserver);
    
public voiddeactivate()

        maybeUnregisterObserverProxy();
        mCursor.deactivate();
    
public booleandeleteRow(int position)

        if (mReadOnly) {
            Log.w("ContentProvider", "Permission Denial: modifying "
                    + mProviderName
                    + " from pid=" + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return false;
        }
        if (mCursor.moveToPosition(position) == false) {
            return false;
        }
        return mCursor.deleteRow();
    
public java.lang.String[]getColumnNames()

        return mCursor.getColumnNames();
    
public android.os.BundlegetExtras()

        return mCursor.getExtras();
    
public booleangetWantsAllOnMoveCalls()

        return mCursor.getWantsAllOnMoveCalls();
    
public CursorWindowgetWindow(int startPos)

        mCursor.moveToPosition(startPos);
        
        if (mWindow != null) {
            if (startPos < mWindow.getStartPosition() ||
                    startPos >= (mWindow.getStartPosition() + mWindow.getNumRows())) {
                mCursor.fillWindow(startPos, mWindow);
            }            
            return mWindow;
        } else {
            return ((AbstractWindowedCursor)mCursor).getWindow();
        }
    
private voidmaybeUnregisterObserverProxy()
Unregister the observer if it is already registered.

        if (mObserver != null) {
            mCursor.unregisterContentObserver(mObserver);
            mObserver.unlinkToDeath(this);
            mObserver = null;
        }
    
public voidonMove(int position)

        mCursor.onMove(mCursor.getPosition(), position);
    
public intrequery(IContentObserver observer, CursorWindow window)

        if (mWindow == null) {
            ((AbstractWindowedCursor)mCursor).setWindow(window);
        }
        try {
            if (!mCursor.requery()) {
                return -1;
            }
        } catch (IllegalStateException e) {
            IllegalStateException leakProgram = new IllegalStateException(
                    mProviderName + " Requery misuse db, mCursor isClosed:" +
                    mCursor.isClosed(), e);
            throw leakProgram;
        }
        
        if (mWindow != null) {
            mCursor.fillWindow(0, window);
            mWindow = window;
        }
        maybeUnregisterObserverProxy();
        createAndRegisterObserverProxy(observer);
        return mCursor.getCount();
    
public android.os.Bundlerespond(android.os.Bundle extras)

        return mCursor.respond(extras);
    
public booleanupdateRows(java.util.Map values)

        if (mReadOnly) {
            Log.w("ContentProvider", "Permission Denial: modifying "
                    + mProviderName
                    + " from pid=" + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
            return false;
        }
        return mCursor.commitUpdates(values);