FileDocCategorySizeDatePackage
AddressParcelHelper.javaAPI DocAndroid 1.5 API2931Wed May 06 22:42:46 BST 2009com.android.im.engine

AddressParcelHelper

public class AddressParcelHelper extends Object
A helper for marshalling and unmarshaling an Address Object to a Parcel. The Address is only an abstract representation, the underlying protocol implementation MUST provide a public default constructor and register their implementing class here.

Fields Summary
private static Class[]
sAddressClasses
Constructors Summary
private AddressParcelHelper()


      
    
Methods Summary
private static intgetClassIndex(Address address)

        for(int i = 0; i < sAddressClasses.length; i++) {
            if(address.getClass() == sAddressClasses[i]) {
                return i;
            }
        }
        throw new RuntimeException("Unregistered Address type: " + address);
    
public static AddressreadFromParcel(android.os.Parcel source)

        int classIndex = source.readInt();
        if(classIndex == -1) {
            return null;
        }
        if(classIndex < 0 || classIndex >= sAddressClasses.length) {
            throw new RuntimeException("Unknown Address type index: " + classIndex);
        }
        try {
            Address address = (Address)sAddressClasses[classIndex].newInstance();
            address.readFromParcel(source);
            return address;
        } catch (InstantiationException e) {
            Log.e("AddressParcel", "Default constructor are required on Class"
                    + sAddressClasses[classIndex].getName());
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            Log.e("AddressParcel", "Default constructor are required on Class"
                    + sAddressClasses[classIndex].getName());
            throw new RuntimeException(e);
        }
    
public static voidwriteToParcel(android.os.Parcel dest, Address address)

        if(address == null) {
            dest.writeInt(-1);
        } else {
            dest.writeInt(getClassIndex(address));
            address.writeToParcel(dest);
        }