public GenericPdu load(Uri uri) throws MmsException {
  GenericPdu pdu=null;
  PduCacheEntry cacheEntry=null;
  int msgBox=0;
  long threadId=DUMMY_THREAD_ID;
  try {
synchronized (PDU_CACHE_INSTANCE) {
      if (PDU_CACHE_INSTANCE.isUpdating(uri)) {
        if (LOCAL_LOGV)         Log.v(TAG,"load: " + uri + " blocked by isUpdating()");
        try {
          PDU_CACHE_INSTANCE.wait();
        }
 catch (        InterruptedException e) {
          Log.e(TAG,"load: ",e);
        }
        cacheEntry=PDU_CACHE_INSTANCE.get(uri);
        if (cacheEntry != null) {
          return cacheEntry.getPdu();
        }
      }
      PDU_CACHE_INSTANCE.setUpdating(uri,true);
    }
    Cursor c=SqliteWrapper.query(mContext,mContentResolver,uri,PDU_PROJECTION,null,null,null);
    PduHeaders headers=new PduHeaders();
    Set<Entry<Integer,Integer>> set;
    long msgId=ContentUris.parseId(uri);
    try {
      if ((c == null) || (c.getCount() != 1) || !c.moveToFirst()) {
        throw new MmsException("Bad uri: " + uri);
      }
      msgBox=c.getInt(PDU_COLUMN_MESSAGE_BOX);
      threadId=c.getLong(PDU_COLUMN_THREAD_ID);
      set=ENCODED_STRING_COLUMN_INDEX_MAP.entrySet();
      for (      Entry<Integer,Integer> e : set) {
        setEncodedStringValueToHeaders(c,e.getValue(),headers,e.getKey());
      }
      set=TEXT_STRING_COLUMN_INDEX_MAP.entrySet();
      for (      Entry<Integer,Integer> e : set) {
        setTextStringToHeaders(c,e.getValue(),headers,e.getKey());
      }
      set=OCTET_COLUMN_INDEX_MAP.entrySet();
      for (      Entry<Integer,Integer> e : set) {
        setOctetToHeaders(c,e.getValue(),headers,e.getKey());
      }
      set=LONG_COLUMN_INDEX_MAP.entrySet();
      for (      Entry<Integer,Integer> e : set) {
        setLongToHeaders(c,e.getValue(),headers,e.getKey());
      }
    }
  finally {
      if (c != null) {
        c.close();
      }
    }
    if (msgId == -1L) {
      throw new MmsException("Error! ID of the message: -1.");
    }
    loadAddress(msgId,headers);
    int msgType=headers.getOctet(PduHeaders.MESSAGE_TYPE);
    PduBody body=new PduBody();
    if ((msgType == PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF) || (msgType == PduHeaders.MESSAGE_TYPE_SEND_REQ)) {
      PduPart[] parts=loadParts(msgId);
      if (parts != null) {
        int partsNum=parts.length;
        for (int i=0; i < partsNum; i++) {
          body.addPart(parts[i]);
        }
      }
    }
switch (msgType) {
case PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND:
      pdu=new NotificationInd(headers);
    break;
case PduHeaders.MESSAGE_TYPE_DELIVERY_IND:
  pdu=new DeliveryInd(headers);
break;
case PduHeaders.MESSAGE_TYPE_READ_ORIG_IND:
pdu=new ReadOrigInd(headers);
break;
case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF:
pdu=new RetrieveConf(headers,body);
break;
case PduHeaders.MESSAGE_TYPE_SEND_REQ:
pdu=new SendReq(headers,body);
break;
case PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND:
pdu=new AcknowledgeInd(headers);
break;
case PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND:
pdu=new NotifyRespInd(headers);
break;
case PduHeaders.MESSAGE_TYPE_READ_REC_IND:
pdu=new ReadRecInd(headers);
break;
case PduHeaders.MESSAGE_TYPE_SEND_CONF:
case PduHeaders.MESSAGE_TYPE_FORWARD_REQ:
case PduHeaders.MESSAGE_TYPE_FORWARD_CONF:
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_REQ:
case PduHeaders.MESSAGE_TYPE_MBOX_STORE_CONF:
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_REQ:
case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_CONF:
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_REQ:
case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_CONF:
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_REQ:
case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_CONF:
case PduHeaders.MESSAGE_TYPE_MBOX_DESCR:
case PduHeaders.MESSAGE_TYPE_DELETE_REQ:
case PduHeaders.MESSAGE_TYPE_DELETE_CONF:
case PduHeaders.MESSAGE_TYPE_CANCEL_REQ:
case PduHeaders.MESSAGE_TYPE_CANCEL_CONF:
throw new MmsException("Unsupported PDU type: " + Integer.toHexString(msgType));
default :
throw new MmsException("Unrecognized PDU type: " + Integer.toHexString(msgType));
}
}
  finally {
synchronized (PDU_CACHE_INSTANCE) {
if (pdu != null) {
assert (PDU_CACHE_INSTANCE.get(uri) == null);
cacheEntry=new PduCacheEntry(pdu,msgBox,threadId);
PDU_CACHE_INSTANCE.put(uri,cacheEntry);
}
PDU_CACHE_INSTANCE.setUpdating(uri,false);
PDU_CACHE_INSTANCE.notifyAll();
}
}
return pdu;
}

public GenericPdu load ( Uri uri ) throws MmsException { GenericPdu pdu = null ; PduCacheEntry cacheEntry = null ; int msgBox = 0 ; long threadId = DUMMY_THREAD_ID ; try { synchronized ( PDU_CACHE_INSTANCE ) { if ( PDU_CACHE_INSTANCE . isUpdating ( uri ) ) { if ( LOCAL_LOGV ) Log . v ( TAG , "load: " + uri + " blocked by isUpdating()" ) ; try { PDU_CACHE_INSTANCE . wait ( ) ; } catch ( InterruptedException e ) { Log . e ( TAG , "load: " , e ) ; } cacheEntry = PDU_CACHE_INSTANCE . get ( uri ) ; if ( cacheEntry != null ) { return cacheEntry . getPdu ( ) ; } } PDU_CACHE_INSTANCE . setUpdating ( uri , true ) ; } Cursor c = SqliteWrapper . query ( mContext , mContentResolver , uri , PDU_PROJECTION , null , null , null ) ; PduHeaders headers = new PduHeaders ( ) ; Set < Entry < Integer , Integer > > set ; long msgId = ContentUris . parseId ( uri ) ; try { if ( ( c == null ) || ( c . getCount ( ) != 1 ) || ! c . moveToFirst ( ) ) { throw new MmsException ( "Bad uri: " + uri ) ; } msgBox = c . getInt ( PDU_COLUMN_MESSAGE_BOX ) ; threadId = c . getLong ( PDU_COLUMN_THREAD_ID ) ; set = ENCODED_STRING_COLUMN_INDEX_MAP . entrySet ( ) ; for ( Entry < Integer , Integer > e : set ) { setEncodedStringValueToHeaders ( c , e . getValue ( ) , headers , e . getKey ( ) ) ; } set = TEXT_STRING_COLUMN_INDEX_MAP . entrySet ( ) ; for ( Entry < Integer , Integer > e : set ) { setTextStringToHeaders ( c , e . getValue ( ) , headers , e . getKey ( ) ) ; } set = OCTET_COLUMN_INDEX_MAP . entrySet ( ) ; for ( Entry < Integer , Integer > e : set ) { setOctetToHeaders ( c , e . getValue ( ) , headers , e . getKey ( ) ) ; } set = LONG_COLUMN_INDEX_MAP . entrySet ( ) ; for ( Entry < Integer , Integer > e : set ) { setLongToHeaders ( c , e . getValue ( ) , headers , e . getKey ( ) ) ; } } finally { if ( c != null ) { c . close ( ) ; } } if ( msgId == - 1L ) { throw new MmsException ( "Error! ID of the message: -1." ) ; } loadAddress ( msgId , headers ) ; int msgType = headers . getOctet ( PduHeaders . MESSAGE_TYPE ) ; PduBody body = new PduBody ( ) ; if ( ( msgType == PduHeaders . MESSAGE_TYPE_RETRIEVE_CONF ) || ( msgType == PduHeaders . MESSAGE_TYPE_SEND_REQ ) ) { PduPart [ ] parts = loadParts ( msgId ) ; if ( parts != null ) { int partsNum = parts . length ; for ( int i = 0 ; i < partsNum ; i ++ ) { body . addPart ( parts [ i ] ) ; } } } switch ( msgType ) { case PduHeaders . MESSAGE_TYPE_NOTIFICATION_IND : pdu = new NotificationInd ( headers ) ; break ; case PduHeaders . MESSAGE_TYPE_DELIVERY_IND : pdu = new DeliveryInd ( headers ) ; break ; case PduHeaders . MESSAGE_TYPE_READ_ORIG_IND : pdu = new ReadOrigInd ( headers ) ; break ; case PduHeaders . MESSAGE_TYPE_RETRIEVE_CONF : pdu = new RetrieveConf ( headers , body ) ; break ; case PduHeaders . MESSAGE_TYPE_SEND_REQ : pdu = new SendReq ( headers , body ) ; break ; case PduHeaders . MESSAGE_TYPE_ACKNOWLEDGE_IND : pdu = new AcknowledgeInd ( headers ) ; break ; case PduHeaders . MESSAGE_TYPE_NOTIFYRESP_IND : pdu = new NotifyRespInd ( headers ) ; break ; case PduHeaders . MESSAGE_TYPE_READ_REC_IND : pdu = new ReadRecInd ( headers ) ; break ; case PduHeaders . MESSAGE_TYPE_SEND_CONF : case PduHeaders . MESSAGE_TYPE_FORWARD_REQ : case PduHeaders . MESSAGE_TYPE_FORWARD_CONF : case PduHeaders . MESSAGE_TYPE_MBOX_STORE_REQ : case PduHeaders . MESSAGE_TYPE_MBOX_STORE_CONF : case PduHeaders . MESSAGE_TYPE_MBOX_VIEW_REQ : case PduHeaders . MESSAGE_TYPE_MBOX_VIEW_CONF : case PduHeaders . MESSAGE_TYPE_MBOX_UPLOAD_REQ : case PduHeaders . MESSAGE_TYPE_MBOX_UPLOAD_CONF : case PduHeaders . MESSAGE_TYPE_MBOX_DELETE_REQ : case PduHeaders . MESSAGE_TYPE_MBOX_DELETE_CONF : case PduHeaders . MESSAGE_TYPE_MBOX_DESCR : case PduHeaders . MESSAGE_TYPE_DELETE_REQ : case PduHeaders . MESSAGE_TYPE_DELETE_CONF : case PduHeaders . MESSAGE_TYPE_CANCEL_REQ : case PduHeaders . MESSAGE_TYPE_CANCEL_CONF : throw new MmsException ( "Unsupported PDU type: " + Integer . toHexString ( msgType ) ) ; default : throw new MmsException ( "Unrecognized PDU type: " + Integer . toHexString ( msgType ) ) ; } } finally { synchronized ( PDU_CACHE_INSTANCE ) { if ( pdu != null ) { assert ( PDU_CACHE_INSTANCE . get ( uri ) == null ) ; cacheEntry = new PduCacheEntry ( pdu , msgBox , threadId ) ; PDU_CACHE_INSTANCE . put ( uri , cacheEntry ) ; } PDU_CACHE_INSTANCE . setUpdating ( uri , false ) ; PDU_CACHE_INSTANCE . notifyAll ( ) ; } } return pdu ; }
load a pdu from storage by given uri .
