Methods Summary |
---|
public void | addCategory(java.lang.String category)
checkWritePermission();
checkOpen();
checkNullCategory(category);
PIMHandler handler = PIMHandler.getInstance();
String[] categories = handler.getCategories(handle);
for (int i = 0; i < categories.length; i++) {
if (category.equals(categories[i])) {
return;
}
}
handler.addCategory(handle, category);
String[] newCategories = new String[categories.length + 1];
System.arraycopy(categories, 0, newCategories, 0, categories.length);
newCategories[categories.length] = category;
|
public void | addItem(AbstractPIMItem item)Adds an item to a PIM list.
this.items.addElement(item);
item.setPIMList(this);
|
private void | checkAttribute(int attribute)Ensures the attribute is valid.
if (attribute == 0) {
// OK
return;
} else {
// make sure only one bit is set
while ((attribute & 1) == 0 && attribute != 0) {
attribute >>= 1;
}
if (attribute != 1) {
// more than one bit is set in attribute
throw new IllegalArgumentException(
"Invalid attribute: " + attribute);
}
}
|
private void | checkField(int field)Ensures the field is valid.
if (PIMHandler.getInstance().getFieldDataType(handle, field) == -1) {
throw AbstractPIMItem.complaintAboutField(type, field);
}
|
protected void | checkNullCategory(java.lang.String category)Ensure the category is not missing.
if (category == null) {
throw new NullPointerException("Null category");
}
|
protected void | checkOpen()Ensures that the list is already open.
if (!open) {
throw new PIMException("List is closed.");
}
|
protected void | checkReadPermission()Verifies read permission.
if (mode == PIM.WRITE_ONLY) {
throw new SecurityException("List cannot be read");
}
|
protected void | checkWritePermission()Verifies write permission.
if (mode == PIM.READ_ONLY) {
throw new SecurityException("List cannot be written");
}
|
public void | close()
checkOpen();
this.open = false;
this.items = null;
PIMHandler.getInstance().closeList(handle);
|
java.lang.Object | commit(java.lang.Object key, byte[] data, java.lang.String[] categories)Commits an item to the database
return PIMHandler.getInstance()
.commitListElement(handle, key, data, categories);
|
public void | deleteCategory(java.lang.String category, boolean deleteUnassignedItems)
checkWritePermission();
checkOpen();
checkNullCategory(category);
String[] categories =
PIMHandler.getInstance().getCategories(handle);
int categoryIndex = -1;
for (int i = 0; i < categories.length && categoryIndex == -1; i++) {
if (category.equals(categories[i])) {
categoryIndex = i;
}
}
if (categoryIndex == -1) {
return;
}
String[] newCategories = new String[categories.length - 1];
System.arraycopy(categories, 0, newCategories, 0, categoryIndex);
System.arraycopy(categories, categoryIndex + 1,
newCategories, categoryIndex,
newCategories.length - categoryIndex);
PIMHandler.getInstance().deleteCategory(handle, category);
final AbstractPIMItem[] a = new AbstractPIMItem[items.size()];
items.copyInto(a);
for (int i = 0; i < a.length; i++) {
if (a[i].isInCategory(category)) {
a[i].removeFromCategory(category);
if (deleteUnassignedItems && a[i].getCategories().length == 0) {
items.removeElement(a[i]);
}
}
}
|
public java.lang.String | getArrayElementLabel(int stringArrayField, int arrayElement)
if (getFieldDataType(stringArrayField) != PIMItem.STRING_ARRAY) {
throw new IllegalArgumentException("Not a string array field");
}
if (!isSupportedArrayElement(stringArrayField, arrayElement)) {
// throw new UnsupportedFieldException("Unsupported array element "
// + arrayElement);
throw new IllegalArgumentException("Invalid array element "
+ arrayElement);
}
return PIMHandler.getInstance()
.getArrayElementLabel(handle,
stringArrayField, arrayElement);
|
public java.lang.String | getAttributeLabel(int attribute)
checkAttribute(attribute);
String label =
PIMHandler.getInstance().getAttributeLabel(handle, attribute);
if (label == null) {
throw new IllegalArgumentException("Invalid attribute: "
+ attribute);
}
return label;
|
public java.lang.String[] | getCategories()
checkOpen();
return PIMHandler.getInstance().getCategories(handle);
|
public int | getFieldDataType(int field)
int dataType = PIMHandler.getInstance().getFieldDataType(handle, field);
if (dataType == -1) {
throw AbstractPIMItem.complaintAboutField(type, field);
}
return dataType;
|
public java.lang.String | getFieldLabel(int field)
checkField(field);
return PIMHandler.getInstance().getFieldLabel(handle, field);
|
public java.lang.Object | getHandle()Returns list handle
return handle;
|
public java.lang.String | getName()
return name;
|
public int[] | getSupportedArrayElements(int stringArrayField)
if (getFieldDataType(stringArrayField) != PIMItem.STRING_ARRAY) {
throw new IllegalArgumentException("Not a string array field");
}
return PIMHandler.getInstance()
.getSupportedArrayElements(handle,
stringArrayField);
|
public int[] | getSupportedAttributes(int field)
checkField(field);
return PIMHandler.getInstance().getSupportedAttributes(handle, field);
|
public int[] | getSupportedFields()
return PIMHandler.getInstance().getSupportedFields(handle);
|
int | getType()Gets the type of this PIM list (PIM.CONTACT_LIST, PIM.EVENT_LIST or
PIM.TODO_LIST).
return type;
|
public boolean | isCategory(java.lang.String category)
checkOpen();
checkNullCategory(category);
String[] categories =
PIMHandler.getInstance().getCategories(handle);
for (int i = 0; i < categories.length; i++) {
if (category.equals(categories[i])) {
return true;
}
}
return false;
|
public boolean | isSupportedArrayElement(int stringArrayField, int arrayElement)
int dataType =
PIMHandler.getInstance().getFieldDataType(handle, stringArrayField);
if (dataType != PIMItem.STRING_ARRAY) {
return false;
}
return PIMHandler.getInstance()
.isSupportedArrayElement(handle, stringArrayField, arrayElement);
|
public boolean | isSupportedAttribute(int field, int attribute)
if (!isSupportedField(field)) {
return false;
}
// ATTR_NONE is supported for all fields
if (attribute == PIMItem.ATTR_NONE) {
return true;
}
// if attribute is not a power of 2, forget it
int i = attribute;
while ((i & 1) == 0 && i != 0) {
i >>= 1;
}
if (i != 1) {
return false;
}
return PIMHandler.getInstance()
.isSupportedAttribute(handle, field, attribute);
|
public boolean | isSupportedField(int field)
return PIMHandler.getInstance().isSupportedField(handle, field);
|
public java.util.Enumeration | items()
checkReadPermission();
checkOpen();
final PIMItem[] data = new PIMItem[items.size()];
items.copyInto(data);
return new
/**
* Inner class for List Enumeration.
*/
Enumeration() {
/** Initial offset int the list. */
int index = 0;
/**
* Checks for more elements int the list.
* @return <code>true</code> if more elements exist
*/
public boolean hasMoreElements() {
return index < data.length;
}
/**
* Fetched the next element int the list.
* @return next element int the list
*/
public Object nextElement() {
try {
return data[index++];
} catch (ArrayIndexOutOfBoundsException e) {
throw new NoSuchElementException();
}
}
};
|
public java.util.Enumeration | items(java.lang.String matchingValue)
checkReadPermission();
checkOpen();
matchingValue = matchingValue.toUpperCase();
Vector v = new Vector();
nextItem:
for (Enumeration e = items.elements(); e.hasMoreElements(); ) {
AbstractPIMItem item = (AbstractPIMItem) e.nextElement();
int[] fields = item.getFields();
for (int i = 0; i < fields.length; i++) {
switch (getFieldDataType(fields[i])) {
case PIMItem.STRING:
for (int j = item.countValues(fields[i]) - 1;
j >= 0; j--) {
String value = item.getString(fields[i], j);
if (value != null) {
if (value.toUpperCase().indexOf(matchingValue)
!= -1) {
v.addElement(item);
continue nextItem;
}
}
}
break;
case PIMItem.STRING_ARRAY:
for (int j = item.countValues(fields[i]) - 1;
j >= 0; j--) {
String[] a = item.getStringArray(fields[i], j);
if (a == null) {
continue;
}
for (int k = 0; k < a.length; k++) {
if (a[k] != null) {
if (a[k].toUpperCase()
.indexOf(matchingValue)
!= -1) {
v.addElement(item);
continue nextItem;
}
}
}
}
break;
}
}
}
return v.elements();
|
public java.util.Enumeration | items(javax.microedition.pim.PIMItem matchingItem)
checkReadPermission();
checkOpen();
if (!equals(matchingItem.getPIMList())) {
throw new IllegalArgumentException("Cannot match item "
+ "from another list");
}
int[] searchFields = matchingItem.getFields();
int[] searchFieldDataTypes = new int[searchFields.length];
Object[][] searchData = new Object[searchFields.length][];
for (int i = 0; i < searchFields.length; i++) {
searchFieldDataTypes[i] = getFieldDataType(searchFields[i]);
searchData[i] = new Object[matchingItem
.countValues(searchFields[i])];
for (int j = 0; j < searchData[i].length; j++) {
searchData[i][j] = ((AbstractPIMItem) matchingItem)
.getField(searchFields[i], false, false).getValue(j);
// convert strings to upper case so that they can be matched
// case-insensitively
switch (searchFieldDataTypes[i]) {
case PIMItem.STRING: {
String s = (String) searchData[i][j];
if (s != null) {
searchData[i][j] = s.toUpperCase();
}
break;
}
case PIMItem.STRING_ARRAY: {
String[] a = (String[]) searchData[i][j];
if (a != null) {
for (int k = 0; k < a.length; k++) {
if (a[k] != null) {
a[k] = a[k].toUpperCase();
}
}
}
break;
}
}
}
}
Vector v = new Vector();
nextItem:
for (Enumeration e = items.elements(); e.hasMoreElements(); ) {
AbstractPIMItem item = (AbstractPIMItem) e.nextElement();
// For each field, make sure all data has a match in "item".
for (int i = 0; i < searchFields.length; i++) {
// make sure that every value searchData[i][j]
// (0 < j < matchingItem.countValues())
// has a match in "item".
int field = searchFields[i];
int itemIndices = item.countValues(field);
for (int j = 0; j < searchData[i].length; j++) {
boolean matchedThisIndex = false;
// see if there is a match for searchData[i][j]
for (int k = 0; k < itemIndices && !matchedThisIndex; k++) {
Object value = item.getField(field, false, false)
.getValue(k);
// see if "value" matches searchData[i][j]
switch (searchFieldDataTypes[i]) {
case PIMItem.DATE:
case PIMItem.INT:
case PIMItem.BOOLEAN: {
if (searchData[i][j].equals(value)) {
matchedThisIndex = true;
}
break;
}
case PIMItem.BINARY: {
byte[] a = (byte[]) searchData[i][j];
byte[] b = (byte[]) value;
if (b != null && a.length == b.length) {
boolean arrayMatches = true;
for (int m = 0; m < a.length
&& arrayMatches;
m++) {
arrayMatches = (a[m] == b[m]);
}
matchedThisIndex = arrayMatches;
}
break;
}
case PIMItem.STRING: {
// strings are matched case-insensitively
// and using contains(), not equals()
String s1 = (String) searchData[i][j];
String s2 = (String) value;
if (s2 == null) {
if (s1 == null) {
matchedThisIndex = true;
}
} else if (s2.toUpperCase().indexOf(s1) != -1) {
matchedThisIndex = true;
}
break;
}
case PIMItem.STRING_ARRAY: {
// each element of the string array is matched
// in the same way as a string (above) would be.
String[] a = (String[]) searchData[i][j];
String[] b = (String[]) value;
if (a == null) {
if (b == null) {
matchedThisIndex = true;
}
} else if (b != null && a.length == b.length) {
boolean arrayMatches = true;
for (int m = 0; m < a.length
&& arrayMatches;
m++) {
if (a[m] != null && a[m].length() > 0) {
arrayMatches = (b[m] != null)
&& b[m].toUpperCase()
.indexOf(a[m])
!= -1;
}
}
matchedThisIndex = arrayMatches;
}
break;
}
} // end switch data type
} // end loop over item's indices
if (!matchedThisIndex) {
// no match found for searchData[i][j].
// this means that "item" does not match "matchingItem"
continue nextItem;
}
} // end iteration over matchingItem's indices
} // end iteration over fields being searched
v.addElement(item);
} // end enumeration of items
return v.elements();
|
public java.util.Enumeration | itemsByCategory(java.lang.String category)
checkReadPermission();
checkOpen();
Vector v = new Vector();
if (category == null || category.equals("UNCATEGORIZED")) {
for (Enumeration e = items.elements(); e.hasMoreElements(); ) {
AbstractPIMItem item = (AbstractPIMItem) e.nextElement();
if (item.getCategoriesRaw() == null) {
v.addElement(item);
}
}
} else {
for (Enumeration e = items.elements(); e.hasMoreElements(); ) {
AbstractPIMItem item = (AbstractPIMItem) e.nextElement();
if (item.isInCategory(category)) {
v.addElement(item);
}
}
}
return v.elements();
|
public int | maxCategories()
return -1;
|
public int | maxValues(int field)
try {
checkField(field);
} catch (UnsupportedFieldException e) {
return 0;
}
return PIMHandler.getInstance().getMaximumValues(handle, field);
|
void | removeItem(javax.microedition.pim.PIMItem item)Removes an item from a PIM list.
checkWritePermission();
checkOpen();
if (item == null) {
throw new NullPointerException("Null item");
}
if (!this.items.removeElement(item)) {
throw new PIMException("Item not in list");
}
((AbstractPIMItem) item).remove();
|
public void | renameCategory(java.lang.String currentCategory, java.lang.String newCategory)
checkWritePermission();
checkOpen();
if (currentCategory == null || newCategory == null) {
throw new NullPointerException("Null category");
}
String[] categories =
PIMHandler.getInstance().getCategories(handle);
if (newCategory.equals(currentCategory)) {
return;
}
int oldCategoryIndex = -1;
int newCategoryIndex = -1;
for (int i = 0; i < categories.length; i++) {
if (currentCategory.equals(categories[i])) {
oldCategoryIndex = i;
} else if (newCategory.equals(categories[i])) {
newCategoryIndex = i;
}
}
if (oldCategoryIndex == -1) {
throw new PIMException("No such category: " + currentCategory);
}
if (newCategoryIndex == -1) {
categories[oldCategoryIndex] = newCategory;
PIMHandler.getInstance().renameCategory(handle, currentCategory,
newCategory);
} else {
String[] a = new String[categories.length - 1];
System.arraycopy(categories, 0, a, 0, oldCategoryIndex);
System.arraycopy(categories, oldCategoryIndex + 1,
a, oldCategoryIndex, a.length - oldCategoryIndex);
categories = a;
PIMHandler.getInstance().deleteCategory(handle, currentCategory);
}
for (Enumeration e = items.elements(); e.hasMoreElements(); ) {
AbstractPIMItem item = (AbstractPIMItem) e.nextElement();
if (item.isInCategory(currentCategory)) {
item.removeFromCategory(currentCategory);
item.addToCategory(newCategory);
}
}
|
public int | stringArraySize(int stringArrayField)
if (getFieldDataType(stringArrayField) != PIMItem.STRING_ARRAY) {
throw new IllegalArgumentException("Not a string array field");
}
return PIMHandler.getInstance().getStringArraySize(handle,
stringArrayField);
|