FileDocCategorySizeDatePackage
ContactImpl.javaAPI DocphoneME MR2 API (J2ME)5470Wed May 02 18:00:28 BST 2007com.sun.kvem.midp.pim

ContactImpl

public class ContactImpl extends AbstractPIMItem implements javax.microedition.pim.Contact
Implementation of a PIM contact.

Fields Summary
Constructors Summary
public ContactImpl(AbstractPIMList list)
Constructs a Contact list.

param
list handle for Contact List implementation

        super(list, PIM.CONTACT_LIST);
        if (list != null && !(list instanceof ContactListImpl)) {
            throw new RuntimeException("Wrong list passed");
        }
    
ContactImpl(AbstractPIMList list, javax.microedition.pim.Contact base)
Constructs a Contact list from a handler and base Contact record.

param
list Contact List implementation handler
param
base Contact record template

        super(list, base);
        if (!(list instanceof ContactListImpl)) {
            throw new RuntimeException("Wrong list passed");
        }
    
Methods Summary
public voidaddBinary(int field, int attributes, byte[] value, int offset, int length)
Adds a binary value to the current Contact.

param
field identifier for current element
param
attributes property to insert
param
value binary value to be recorded
param
offset index into value array
param
length size of data to copy

        super.addBinary(field, attributes, value, offset, length);
        if (field == PUBLIC_KEY) {
            // remove any values from PUBLIC_KEY_STRING
            while (countValues(PUBLIC_KEY_STRING) > 0) {
                removeValue(PUBLIC_KEY_STRING, 0);
            }
        }
    
public voidaddString(int field, int attributes, java.lang.String value)
Adds a string to the current Contact.

param
field identifier for current element
param
attributes property to insert
param
value string to be recorded

        super.addString(field, attributes, value);
        if (field == PUBLIC_KEY_STRING) {
            // remove any values from PUBLIC_KEY
            while (countValues(PUBLIC_KEY) > 0) {
                removeValue(PUBLIC_KEY, 0);
            }
        }
    
PIMFormatgetEncodingFormat()
Gets encoding format for this contact record.

return
handle for encoding format

        return new VCard30Format();
    
public intgetPreferredIndex(int field)
Gets preferred index for requested field.

param
field requested element
return
preferred index for requested field

        int indices = countValues(field);
        for (int i = 0; i < indices; i++) {
            int attributes = getAttributes(field, i);
            if ((attributes & ATTR_PREFERRED) != 0) {
                return i;
            }
        }
        return -1;
    
protected intgetRevisionField()
Gets the revision field identifier.

return
revision field identifier

        return REVISION;
    
protected intgetUIDField()
Gets the UID field identifier.

return
UID field identifier

        return UID;
    
static booleanisValidPIMField(int field)
Ensures valid field.

param
field identifier to validate
return
true if contact field identifier is supported

        switch (field) {
            case Contact.ADDR:
            case Contact.BIRTHDAY:
            case Contact.CLASS:
            case Contact.EMAIL:
            case Contact.FORMATTED_ADDR:
            case Contact.FORMATTED_NAME:
            case Contact.NAME:
            case Contact.NICKNAME:
            case Contact.NOTE:
            case Contact.ORG:
            case Contact.PHOTO:
            case Contact.PHOTO_URL:
            case Contact.PUBLIC_KEY:
            case Contact.PUBLIC_KEY_STRING:
            case Contact.REVISION:
            case Contact.TEL:
            case Contact.TITLE:
            case Contact.UID:
            case Contact.URL:
                return true;
            default:
                return false;
        }
    
protected java.lang.StringtoDisplayableString()
Converts the Contact to a printable format.

return
formatted Contact record

        return "Contact[" + formatData() + "]";