Source Code Cross Referenced for PIMProxy.java in  » 6.0-JDK-Modules » j2me » com » sun » kvem » midp » pim » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.kvem.midp.pim 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *   
0003:         *
0004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
0005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
0006:         * 
0007:         * This program is free software; you can redistribute it and/or
0008:         * modify it under the terms of the GNU General Public License version
0009:         * 2 only, as published by the Free Software Foundation.
0010:         * 
0011:         * This program is distributed in the hope that it will be useful, but
0012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014:         * General Public License version 2 for more details (a copy is
0015:         * included at /legal/license.txt).
0016:         * 
0017:         * You should have received a copy of the GNU General Public License
0018:         * version 2 along with this work; if not, write to the Free Software
0019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020:         * 02110-1301 USA
0021:         * 
0022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0023:         * Clara, CA 95054 or visit www.sun.com if you need additional
0024:         * information or have any questions.
0025:         */
0026:
0027:        package com.sun.kvem.midp.pim;
0028:
0029:        import java.util.Vector;
0030:        import java.util.Hashtable;
0031:        import java.util.Enumeration;
0032:
0033:        import javax.microedition.pim.PIMException;
0034:        import javax.microedition.pim.PIM;
0035:
0036:        import com.sun.midp.main.Configuration;
0037:        import com.sun.kvem.midp.pim.formats.FormatSupport;
0038:
0039:        /**
0040:         * Porting layer implementation for PIM functionality.
0041:         */
0042:        public class PIMProxy extends PIMHandler {
0043:
0044:            /**
0045:             * Table of fields for any list.
0046:             */
0047:            private Hashtable listFields = new Hashtable();
0048:
0049:            /**
0050:             * Table of attributes for any list.
0051:             */
0052:            private Hashtable listAttributes = new Hashtable();
0053:
0054:            /**
0055:             * List handle for which fields have been already initialized.
0056:             */
0057:            private Object initialized = null;
0058:
0059:            /**
0060:             * Field for storing data handler between native calls
0061:             */
0062:            private int dataHandler;
0063:
0064:            /**
0065:             * Field for storing items counter between native calls
0066:             */
0067:            private int itemCounter;
0068:
0069:            /**
0070:             * Constant representing a Contact List.
0071:             * List handle for which fields have been already initialized.
0072:             */
0073:            public static final int CONTACT_LIST = 1;
0074:
0075:            /**
0076:             * Constant representing an Event List.
0077:             */
0078:            public static final int EVENT_LIST = 2;
0079:
0080:            /**
0081:             * Constant representing a ToDo List.
0082:             */
0083:            public static final int TODO_LIST = 3;
0084:
0085:            /**
0086:             * This class holds information about a single list.
0087:             */
0088:            private class List {
0089:                /** Native handle of the list */
0090:                int handle;
0091:
0092:                /** Type of the list: CONTACT_LIST, EVENT_LIST or TODO_LIST */
0093:                int type;
0094:
0095:                /**
0096:                 * The only constructor for this list descriptor.
0097:                 *
0098:                 * @param listHandle low-level (native) handle of the list
0099:                 * @param listType CONTACT_LIST, EVENT_LIST or TODO_LIST
0100:                 */
0101:                List(int listHandle, int listType) {
0102:                    handle = listHandle;
0103:                    type = listType;
0104:                }
0105:            }
0106:
0107:            /**
0108:             * This class holds information about a single list item.
0109:             */
0110:            private class Item {
0111:                /** Native handle of the item */
0112:                int handle;
0113:
0114:                /** Binary data of the item */
0115:                byte[] rawData;
0116:
0117:                /** Descriptor of the list containing this item */
0118:                List list;
0119:
0120:                /** Array of categories the item belongs to */
0121:                String[] categories;
0122:
0123:                /**
0124:                 * Simple constructor for this item descriptor.
0125:                 *
0126:                 * @param list descriptor of the list where the item belongs
0127:                 * @param handle low-level (native) handle of the item
0128:                 * @param dataLength size of item's data (in bytes)
0129:                 */
0130:                Item(List list, int handle, int dataLength) {
0131:                    this .handle = handle;
0132:                    rawData = new byte[dataLength];
0133:                    this .list = list;
0134:                    categories = null;
0135:                }
0136:
0137:                /**
0138:                 * Constructor that allows to specify categories of the item.
0139:                 *
0140:                 * @param list descriptor of the list where the item belongs
0141:                 * @param handle low-level (native) handle of the item
0142:                 * @param dataLength size of item's data (in bytes)
0143:                 * @param cats array of categories the item belongs to
0144:                 */
0145:                Item(List list, int handle, int dataLength, String[] cats) {
0146:                    this (list, handle, dataLength);
0147:                    setCategories(cats);
0148:                }
0149:
0150:                /**
0151:                 * Sets categories for the item.
0152:                 *
0153:                 * @param cats array of categories the item belongs to
0154:                 */
0155:                void setCategories(String[] cats) {
0156:                    categories = cats;
0157:                }
0158:
0159:                /**
0160:                 * Returns item's categories.
0161:                 *
0162:                 * @return array of categories the item belongs to
0163:                 */
0164:                String[] getCategories() {
0165:                    String[] cats = new String[categories == null ? 0
0166:                            : categories.length];
0167:                    if (cats.length > 0) {
0168:                        System.arraycopy(categories, 0, cats, 0,
0169:                                categories.length);
0170:                    }
0171:                    return cats;
0172:                }
0173:            }
0174:
0175:            /**
0176:             * Set up field and attribute descriptions.
0177:             *
0178:             * @param listHandle descriptor of the list which fields and
0179:             *        attributes will be retrieved
0180:             */
0181:            synchronized private void initialize(Object listHandle) {
0182:                if (initialized != listHandle) {
0183:                    listFields.clear();
0184:                    listAttributes.clear();
0185:                    int list = ((List) listHandle).handle;
0186:
0187:                    int[] tmpArray = new int[1];
0188:                    int numFields = getFieldsCount0(list, tmpArray);
0189:                    if (numFields <= 0) {
0190:                        return;
0191:                    }
0192:                    PIMFieldDescriptor[] desc = new PIMFieldDescriptor[numFields];
0193:                    for (int i = 0; i < numFields; i++) {
0194:                        int numLabels = getFieldLabelsCount0(list, i,
0195:                                tmpArray[0]);
0196:                        desc[i] = new PIMFieldDescriptor(0, 0, false, null,
0197:                                " ", new String[numLabels], 0L, 0);
0198:                    }
0199:                    getFields0(list, desc, tmpArray[0]);
0200:                    for (int i = 0; i < numFields; i++) {
0201:                        listFields
0202:                                .put(new Integer(desc[i].getField()), desc[i]);
0203:                    }
0204:
0205:                    tmpArray[0] = 0;
0206:                    int numAttributes = getAttributesCount0(list, tmpArray);
0207:                    PIMAttribute[] attr = new PIMAttribute[numAttributes];
0208:                    for (int i = 0; i < numAttributes; i++) {
0209:                        attr[i] = new PIMAttribute();
0210:                    }
0211:                    getAttributes0(list, attr, tmpArray[0]);
0212:                    for (int i = 0; i < numAttributes; i++) {
0213:                        listAttributes.put(new Integer(attr[i].getAttr()),
0214:                                attr[i]);
0215:                    }
0216:
0217:                    initialized = listHandle;
0218:                }
0219:            }
0220:
0221:            /**
0222:             *  Gets the descriptor for given field.
0223:             *
0224:             * @param field the field ID
0225:             *
0226:             * @return field descriptor
0227:             */
0228:            private PIMFieldDescriptor getFieldDescriptor(int field) {
0229:                return (PIMFieldDescriptor) listFields.get(new Integer(field));
0230:            }
0231:
0232:            /**
0233:             * Gets all fields that are supported in this list.  All fields supported by
0234:             * this list, including both standard and extended, are returned in this
0235:             * array.
0236:             *
0237:             * @param listHandle handle of the list
0238:             * @return  an int array containing all fields supported by this list.  The
0239:             *          order of the fields returned is unspecified.  If there are no
0240:             *          supported fields, a zero-length array is returned.
0241:             */
0242:            public int[] getSupportedFields(Object listHandle) {
0243:                initialize(listHandle);
0244:                int[] result = new int[listFields.size()];
0245:                Enumeration fieldNumbers = listFields.keys();
0246:                for (int i = 0; i < result.length; i++) {
0247:                    result[i] = ((Integer) fieldNumbers.nextElement())
0248:                            .intValue();
0249:                }
0250:                return result;
0251:            }
0252:
0253:            /**
0254:             * Checks if field is supported in list.
0255:             * @param listHandle handle of the list
0256:             * @param field identifier of field
0257:             * @return <code>true</code> if field supported
0258:             */
0259:            public boolean isSupportedField(Object listHandle, int field) {
0260:                initialize(listHandle);
0261:                return getFieldDescriptor(field) != null;
0262:            }
0263:
0264:            /**
0265:             * Checks if field has default value.
0266:             * @param listHandle handle of the list
0267:             * @param field identifier of field
0268:             * @return <code>true</code> if field supported
0269:             */
0270:            public boolean hasDefaultValue(Object listHandle, int field) {
0271:                initialize(listHandle);
0272:                return getFieldDescriptor(field).hasDefaultValue();
0273:            }
0274:
0275:            /**
0276:             * Gets the data type of the field.
0277:             * @param listHandle handle of the list
0278:             * @param field identifier of field
0279:             * @return data type identifier
0280:             */
0281:            public int getFieldDataType(Object listHandle, int field) {
0282:                initialize(listHandle);
0283:                try {
0284:                    return getFieldDescriptor(field).getDataType();
0285:                } catch (NullPointerException npe) {
0286:                    return -1;
0287:                }
0288:            }
0289:
0290:            /**
0291:             * Gets the label of the field.
0292:             * @param listHandle handle of the list
0293:             * @param field identifier of field
0294:             * @return label of the field
0295:             */
0296:            public String getFieldLabel(Object listHandle, int field) {
0297:                initialize(listHandle);
0298:                try {
0299:                    return getFieldDescriptor(field).getLabel();
0300:                } catch (NullPointerException npe) {
0301:                    return null;
0302:                }
0303:            }
0304:
0305:            /**
0306:             * Gets the default integer value for the given field. This will
0307:             *  only
0308:             * return a valid value if hasDefaultValue(listType, field) returns true.
0309:             * @param listHandle handle of the list
0310:             * @param field identifier of field
0311:             * @return default value of the field
0312:             */
0313:            public int getDefaultIntValue(Object listHandle, int field) {
0314:                initialize(listHandle);
0315:                PIMFieldDescriptor descriptor = getFieldDescriptor(field);
0316:                return ((Integer) descriptor.getDefaultValue()).intValue();
0317:            }
0318:
0319:            /**
0320:             * Gets the default string value for the given field. This will
0321:             * only
0322:             * return a valid value if hasDefaultValue(listType, field) returns true.
0323:             * @param listHandle handle of the list
0324:             * @param field identifier of field
0325:             * @return default value of the field
0326:             */
0327:            public String getDefaultStringValue(Object listHandle, int field) {
0328:                initialize(listHandle);
0329:                return null;
0330:            }
0331:
0332:            /**
0333:             * Gets the default String[] value for the given field. This will
0334:             * only
0335:             * return a valid value if hasDefaultValue(listType, field) returns true.
0336:             * @param listHandle handle of the list
0337:             * @param field identifier of field
0338:             * @return default value of the field
0339:             */
0340:            public String[] getDefaultStringArrayValue(Object listHandle,
0341:                    int field) {
0342:                int length = getStringArraySize(listHandle, field);
0343:                return new String[length];
0344:            }
0345:
0346:            /**
0347:             * Gets the default date value for the given field. This will only
0348:             * return a valid value if hasDefaultValue(listType, field) returns true.
0349:             * @param listHandle handle of the list
0350:             * @param field identifier of field
0351:             * @return default value of the field
0352:             */
0353:            public long getDefaultDateValue(Object listHandle, int field) {
0354:                initialize(listHandle);
0355:                return 0;
0356:            }
0357:
0358:            /**
0359:             * Gets the default byte[] value for the given field. This will
0360:             * only
0361:             * return a valid value if hasDefaultValue(listType, field) returns true.
0362:             * @param listHandle handle of the list
0363:             * @param field identifier of field
0364:             * @return default value of the field
0365:             */
0366:            public byte[] getDefaultBinaryValue(Object listHandle, int field) {
0367:                initialize(listHandle);
0368:                return null;
0369:            }
0370:
0371:            /**
0372:             * Gets the default boolean value for the given field. This will
0373:             * only
0374:             * return a valid value if hasDefaultValue(listType, field) returns true.
0375:             * @param listHandle handle of the list
0376:             * @param field identifier of field
0377:             * @return default value of the field
0378:             */
0379:            public boolean getDefaultBooleanValue(Object listHandle, int field) {
0380:                initialize(listHandle);
0381:                return false;
0382:            }
0383:
0384:            /**
0385:             * Gets the supported attributes for the given field.
0386:             * @param listHandle handle of the list
0387:             * @param field identifier of field
0388:             * @return array of supported attributes of the field
0389:             */
0390:            public int[] getSupportedAttributes(Object listHandle, int field) {
0391:                initialize(listHandle);
0392:                long attributes = getFieldDescriptor(field)
0393:                        .getSupportedAttributes();
0394:                int listType = ((List) listHandle).type;
0395:                // ATTR_NONE is supported for all Contact fields
0396:                int elementCount = listType == PIM.CONTACT_LIST ? 1 : 0;
0397:                for (long a = attributes; a > 0; a >>= 1) {
0398:                    if ((a & 1) == 1) {
0399:                        elementCount++;
0400:                    }
0401:                }
0402:                int[] result = new int[elementCount];
0403:                if (elementCount > 0) {
0404:                    int a = 1;
0405:                    int i;
0406:                    if (listType == PIM.CONTACT_LIST) {
0407:                        result[0] = PIMItem.ATTR_NONE;
0408:                        i = 1;
0409:                    } else {
0410:                        i = 0;
0411:                    }
0412:                    for (; i < elementCount; i++) {
0413:                        while ((attributes & a) == 0)
0414:                            a <<= 1;
0415:                        result[i] = a;
0416:                        a <<= 1;
0417:                    }
0418:                }
0419:                return result;
0420:            }
0421:
0422:            /**
0423:             * Gets a mask containing all possible attributes for the given field.
0424:             *
0425:             * @param listHandle handle of the list
0426:             * @param field the field number
0427:             * @return supported attribute mask
0428:             */
0429:            public int getSupportedAttributesMask(Object listHandle, int field) {
0430:                initialize(listHandle);
0431:                return (int) getFieldDescriptor(field).getSupportedAttributes();
0432:            }
0433:
0434:            /**
0435:             * Gets attribute label for the given field attribute.
0436:             *
0437:             * @param listHandle handle of the list
0438:             * @param attribute identifier of attribute
0439:             * @return attribute label
0440:             */
0441:            public String getAttributeLabel(Object listHandle, int attribute) {
0442:                initialize(listHandle);
0443:                if (attribute == PIMItem.ATTR_NONE) {
0444:                    String tag = "PIM.Attributes.None";
0445:                    return Configuration
0446:                            .getPropertyDefault(tag, "Label_" + tag);
0447:                }
0448:                try {
0449:                    return ((PIMAttribute) listAttributes.get(new Integer(
0450:                            attribute))).getLabel();
0451:                } catch (NullPointerException npe) {
0452:                    return null;
0453:                }
0454:            }
0455:
0456:            /**
0457:             * Checks if attribute is supported.
0458:             *
0459:             * @param listHandle handle of the list
0460:             * @param field the field number
0461:             * @param attribute identifier of attribute
0462:             * @return <code>true</code> if attribute is supported
0463:             */
0464:            public boolean isSupportedAttribute(Object listHandle, int field,
0465:                    int attribute) {
0466:                initialize(listHandle);
0467:                if (attribute == PIMItem.ATTR_NONE) {
0468:                    return true;
0469:                } else {
0470:                    long attributes = getFieldDescriptor(field)
0471:                            .getSupportedAttributes();
0472:                    return (attributes & attribute) != 0;
0473:                }
0474:            }
0475:
0476:            /**
0477:             * Checks if size of the string array.
0478:             *
0479:             * @param listHandle handle of the list
0480:             * @param field the field number
0481:             * @return size of the string array
0482:             */
0483:            public int getStringArraySize(Object listHandle, int field) {
0484:                initialize(listHandle);
0485:                try {
0486:                    return getFieldDescriptor(field).getStringArraySize();
0487:                } catch (NullPointerException e) {
0488:                    // debug.exception(Debug.LIGHT, e);
0489:                    return 0;
0490:                }
0491:            }
0492:
0493:            /**
0494:             * Gets the array of supported elements.
0495:             *
0496:             * @param listHandle handle of the list
0497:             * @param field the field number
0498:             * @return array of supported elements
0499:             */
0500:            public int[] getSupportedArrayElements(Object listHandle, int field) {
0501:                int size = getStringArraySize(listHandle, field);
0502:                int[] result = new int[size];
0503:                for (int i = 0; i < size; i++) {
0504:                    result[i] = i;
0505:                }
0506:                return result;
0507:            }
0508:
0509:            /**
0510:             * Gets the array element label.
0511:             *
0512:             * @param listHandle handle of the list
0513:             * @param field the field number
0514:             * @param arrayElement the element identifier
0515:             * @return label fro the array element
0516:             */
0517:            public String getArrayElementLabel(Object listHandle, int field,
0518:                    int arrayElement) {
0519:                initialize(listHandle);
0520:                return getFieldDescriptor(field).getElementlabel(arrayElement);
0521:            }
0522:
0523:            /**
0524:             * Checks if the array element is supported.
0525:             *
0526:             * @param listHandle handle of the list
0527:             * @param field the field number
0528:             * @param arrayElement the element identifier
0529:             * @return <code>true</code> if attribute element is supported
0530:             */
0531:            public boolean isSupportedArrayElement(Object listHandle,
0532:                    int field, int arrayElement) {
0533:                return arrayElement >= 0
0534:                        && arrayElement < getStringArraySize(listHandle, field);
0535:            }
0536:
0537:            /**
0538:             * Get the maximum number of values that can be stored in the given field.
0539:             *
0540:             * @param listHandle handle of the list
0541:             * @param field the field type
0542:             * @return the maximum value
0543:             */
0544:            public int getMaximumValues(Object listHandle, int field) {
0545:                initialize(listHandle);
0546:                return getFieldDescriptor(field).getMaximumValues();
0547:            }
0548:
0549:            /**
0550:             * Get the supported list names for the given list type. All list elements
0551:             * must be unique within the list.
0552:             *
0553:             * @param listType the type of the list
0554:             * @return a non-null array of supported list names. A copy of this array is
0555:             * returned by PIM.listPIMLists()
0556:             */
0557:            synchronized public String[] getListNames(int listType) {
0558:                int namesCount = getListNamesCount0(listType);
0559:                String[] listNames = new String[namesCount];
0560:
0561:                if (namesCount != 0) {
0562:                    getListNames0(listNames);
0563:                }
0564:
0565:                return listNames;
0566:            }
0567:
0568:            /**
0569:             * Get the name of the default list for the given type.
0570:             *
0571:             * @param listType the type of the list
0572:             * @return the name of the default list, or null if no list of this type
0573:             * is supported.
0574:             */
0575:            public String getDefaultListName(int listType) {
0576:                String propertyName;
0577:
0578:                if (listType == PIM.CONTACT_LIST) {
0579:                    propertyName = "DefaultContactList";
0580:                } else if (listType == PIM.EVENT_LIST) {
0581:                    propertyName = "DefaultEventList";
0582:                } else if (listType == PIM.TODO_LIST) {
0583:                    propertyName = "DefaultTodoList";
0584:                } else {
0585:                    return null;
0586:                }
0587:
0588:                return Configuration.getProperty(propertyName);
0589:            }
0590:
0591:            /**
0592:             * Opens list.
0593:             *
0594:             * @param listType the type of the list
0595:             * @param listName the name of the list
0596:             * @param openMode open mode:
0597:             * <ul>
0598:             *  <li> {@link javax.microedition.pim.PIM#READ_ONLY}
0599:             *  <li> {@link javax.microedition.pim.PIM#WRITE_ONLY}
0600:             *  <li> {@link javax.microedition.pim.PIM#READ_WRITE}
0601:             * </ul>
0602:             * @return list handle that will be used to access this list
0603:             * @throws PIMException  in case of I/O error.
0604:             */
0605:            public Object openList(int listType, String listName, int openMode)
0606:                    throws PIMException {
0607:                int listHandle = listOpen0(listType, listName, openMode);
0608:                if (listHandle == 0) {
0609:                    throw new PIMException("Unable to open list");
0610:                }
0611:                return new List(listHandle, listType);
0612:            }
0613:
0614:            /**
0615:             * Closes list.
0616:             *
0617:             * @param listHandle handle of list
0618:             * @throws PIMException  in case of I/O error.
0619:             */
0620:            public void closeList(Object listHandle) throws PIMException {
0621:                if (!listClose0(((List) listHandle).handle)) {
0622:                    throw new PIMException();
0623:                }
0624:            }
0625:
0626:            /**
0627:             * Get list element keys.
0628:             *
0629:             * @param listHandle handle of the list
0630:             * @return an array of objects representing PIM element keys. These keys
0631:             * are to be passed to getListElement() and commitListElement().
0632:             * @throws PIMException  in case of I/O error.
0633:             */
0634:            synchronized public Object[] getListKeys(Object listHandle)
0635:                    throws PIMException {
0636:                Vector keys = new Vector();
0637:                int[] itemDesc = new int[4];
0638:                int handle = ((List) listHandle).handle;
0639:
0640:                while (getNextItemDescription0(handle, itemDesc)) {
0641:                    Item nextItem = new Item((List) listHandle, itemDesc[0],
0642:                            itemDesc[1]);
0643:                    getNextItemData0(nextItem.handle, nextItem.rawData,
0644:                            itemDesc[3]);
0645:                    keys.addElement(nextItem);
0646:                    String catList = getItemCategories0(nextItem.handle,
0647:                            itemDesc[3]);
0648:                    if (catList != null) {
0649:                        nextItem.setCategories(FormatSupport.split(catList,
0650:                                ',', 0));
0651:                    }
0652:                }
0653:                Item[] items = new Item[keys.size()];
0654:                for (int index = 0; index < items.length; index++) {
0655:                    items[index] = (Item) keys.elementAt(index);
0656:                }
0657:                return items;
0658:            }
0659:
0660:            /**
0661:             * Get the data for a list element.
0662:             * @param listHandle handle of the list
0663:             * @param elementKey the key of the requested element
0664:             * @return a byte array containing the element data in a supported format
0665:             * @throws PIMException  in case of I/O error.
0666:             */
0667:            public byte[] getListElement(Object listHandle, Object elementKey)
0668:                    throws PIMException {
0669:                return ((Item) elementKey).rawData;
0670:            }
0671:
0672:            /**
0673:             * Get categories for the specified list element.
0674:             * @param listHandle handle of list
0675:             * @param elementKey the key of the requested element
0676:             * @return an array of categories names
0677:             * @throws PIMException  in case of I/O error.
0678:             */
0679:            public String[] getListElementCategories(Object listHandle,
0680:                    Object elementKey) throws PIMException {
0681:
0682:                return ((Item) elementKey).getCategories();
0683:            }
0684:
0685:            /**
0686:             * Commit a list element.
0687:             *
0688:             * @param listHandle handle of the list
0689:             * @param elementKey the key of the element to be stored, or null if this
0690:             * is a new element.
0691:             * @param element element data in a form that can be interpreted
0692:             * by getListElement()
0693:             * @param categories list of categories which the list element belongs to
0694:             * @return a non-null key for this element, to be used in future calls
0695:             * to commitListElement() and getListElement()
0696:             * @throws PIMException  in case of I/O error.
0697:             */
0698:            synchronized public Object commitListElement(Object listHandle,
0699:                    Object elementKey, byte[] element, String[] categories)
0700:                    throws PIMException {
0701:                Item item = (Item) elementKey;
0702:                List list = (List) listHandle;
0703:
0704:                if (elementKey == null) {
0705:                    /* Add new item */
0706:                    int itemHandle = addItem0(list.handle, element,
0707:                            categories == null ? null : FormatSupport.join(
0708:                                    categories, ","));
0709:                    if (itemHandle == 0) {
0710:                        throw new PIMException("Unable to add new item");
0711:                    }
0712:                    item = new Item(list, itemHandle, element.length,
0713:                            categories);
0714:                    item.rawData = element;
0715:                } else if (element == null) {
0716:                    /* Remove item */
0717:                    if (!removeItem0(list.handle, item.handle)) {
0718:                        throw new PIMException("Unable to delete item");
0719:                    }
0720:                } else {
0721:                    item.rawData = element;
0722:                    if (!commitItemData0(list.handle, item.handle, element,
0723:                            categories == null ? null : FormatSupport.join(
0724:                                    categories, ","))) {
0725:                        throw new PIMException("Unable to update",
0726:                                PIMException.UPDATE_ERROR);
0727:                    }
0728:                }
0729:                return item;
0730:            }
0731:
0732:            /**
0733:             * Gets the set of categories defined for a list.
0734:             *
0735:             * @param listHandle handle of the list
0736:             * @return the set of defined categories
0737:             * @throws PIMException  If an error occurs or
0738:             * the list is no longer accessible or closed.
0739:             */
0740:            public String[] getCategories(Object listHandle)
0741:                    throws PIMException {
0742:                String categories = getListCategories0(((List) listHandle).handle);
0743:                return categories != null ? FormatSupport.split(categories,
0744:                        ',', 0) : new String[0];
0745:            }
0746:
0747:            /**
0748:             * Adds a category to the categories defined for a list.
0749:             *
0750:             * @param listHandle handle of list
0751:             * @param category category name
0752:             * @throws PIMException  If an error occurs or
0753:             * the list is no longer accessible or closed.
0754:             * @see #getCategories
0755:             */
0756:            public void addCategory(Object listHandle, String category)
0757:                    throws PIMException {
0758:                if (getCategories(listHandle).length == getListMaxCategories0(((List) listHandle).handle)) {
0759:                    throw new PIMException(
0760:                            "Maximum number of categories exceeded",
0761:                            PIMException.MAX_CATEGORIES_EXCEEDED);
0762:                }
0763:                if (!addListCategory0(((List) listHandle).handle, category)) {
0764:                    throw new PIMException("Unable to add category",
0765:                            PIMException.UPDATE_ERROR);
0766:                }
0767:            }
0768:
0769:            /**
0770:             * Deletes a category from the categories defined for a list.
0771:             *
0772:             * @param listHandle handle of list
0773:             * @param category category name
0774:             * @throws PIMException  If an error occurs or
0775:             * the list is no longer accessible or closed.
0776:             * @see #getCategories
0777:             */
0778:            public void deleteCategory(Object listHandle, String category)
0779:                    throws PIMException {
0780:                if (!deleteListCategory0(((List) listHandle).handle, category)) {
0781:                    throw new PIMException("Unable to delete category",
0782:                            PIMException.UPDATE_ERROR);
0783:                }
0784:            }
0785:
0786:            /**
0787:             * Rename a category.
0788:             *
0789:             * @param listHandle handle of list
0790:             * @param currentCategory current category name
0791:             * @param newCategory new category name
0792:             * @throws PIMException  If an error occurs or
0793:             * the list is no longer accessible or closed.
0794:             * @see #getCategories
0795:             */
0796:            public void renameCategory(Object listHandle,
0797:                    String currentCategory, String newCategory)
0798:                    throws PIMException {
0799:                if (!renameListCategory0(((List) listHandle).handle,
0800:                        currentCategory, newCategory)) {
0801:                    throw new PIMException("Unable to rename category",
0802:                            PIMException.UPDATE_ERROR);
0803:                }
0804:            }
0805:
0806:            /**
0807:             * Returns number of lists of the specified type.
0808:             *
0809:             * @param listType CONTACT_LIST, EVENT_LIST or TODO_LIST
0810:             *
0811:             * @return number of lists
0812:             * @see #getListNames0
0813:             */
0814:            private native int getListNamesCount0(int listType);
0815:
0816:            /**
0817:             * Retrieves list names for the selected list type.
0818:             *
0819:             * @param names array where list names will be stored
0820:             *        (must have sufficient number of elements for list names)
0821:             * @see #getListNamesCount0
0822:             */
0823:            private native void getListNames0(String[] names);
0824:
0825:            /**
0826:             * Opens the specified list.
0827:             *
0828:             * @param listType CONTACT_LIST, EVENT_LIST or TODO_LIST
0829:             * @param listName name of the list to open
0830:             * @param mode open mode:
0831:             * <ul>
0832:             *  <li> {@link javax.microedition.pim.PIM#READ_ONLY}
0833:             *  <li> {@link javax.microedition.pim.PIM#WRITE_ONLY}
0834:             *  <li> {@link javax.microedition.pim.PIM#READ_WRITE}
0835:             * </ul>
0836:             *
0837:             * @return native handle of the opened list
0838:             * @see #listClose0
0839:             */
0840:            private native int listOpen0(int listType, String listName, int mode);
0841:
0842:            /**
0843:             * Closes the specified list.
0844:             *
0845:             * @param listHandle native handle of the list that was previously opened
0846:             *
0847:             * @return <code>true</code> on success, <code>false</code> otherwise
0848:             * @see #listOpen0
0849:             */
0850:            private native boolean listClose0(int listHandle);
0851:
0852:            /**
0853:             * Retrieves general information about the next item in the list.
0854:             *
0855:             * @param listHandle native handle of the list that was previously opened
0856:             * @param description buffer to store the item description
0857:             *
0858:             * @return <code>true</code> on success, <code>false</code> otherwise
0859:             */
0860:            private native boolean getNextItemDescription0(int listHandle,
0861:                    int[] description);
0862:
0863:            /**
0864:             * Retrieves next item's data from the list.
0865:             *
0866:             * @param itemHandle native handle of the item
0867:             * @param data buffer to store the item's data
0868:             * @param dataHandle handle for data buffer
0869:             * @return <code>true</code> on success, <code>false</code> otherwise
0870:             */
0871:            private native boolean getNextItemData0(int itemHandle,
0872:                    byte[] data, int dataHandle);
0873:
0874:            /**
0875:             * Writes modified item data to persistent storage.
0876:             *
0877:             * @param listHandle native handle of the list that was previously opened
0878:             * @param itemHandle native handle of the item
0879:             * @param data raw data of the item
0880:             * @param categories item's categories, separated by comma
0881:             *
0882:             * @return <code>true</code> on success, <code>false</code> otherwise
0883:             */
0884:            private native boolean commitItemData0(int listHandle,
0885:                    int itemHandle, byte[] data, String categories);
0886:
0887:            /**
0888:             * Adds item to the list.
0889:             *
0890:             * @param listHandle native handle of the list that was previously opened
0891:             * @param data raw data of the item
0892:             * @param categories item's categories, separated by comma
0893:             *
0894:             * @return native handle of the item
0895:             */
0896:            private native int addItem0(int listHandle, byte[] data,
0897:                    String categories);
0898:
0899:            /**
0900:             * Removes specified item from the list.
0901:             *
0902:             * @param listHandle native handle of the list that was previously opened
0903:             * @param itemHandle native handle of the item
0904:             *
0905:             * @return <code>true</code> on success, <code>false</code> otherwise
0906:             */
0907:            private native boolean removeItem0(int listHandle, int itemHandle);
0908:
0909:            /**
0910:             * Retrieves categories defined for the specified list.
0911:             *
0912:             * @param listHandle native handle of the list that was previously opened
0913:             *
0914:             * @return item's categories, separated by comma
0915:             */
0916:            private native String getListCategories0(int listHandle);
0917:
0918:            /**
0919:             * Returns maximum number of categories supported for the given list.
0920:             *
0921:             * @param listHandle native handle of the list that was previously opened
0922:             *
0923:             * @return maximum number of categories for the list
0924:             */
0925:            private native int getListMaxCategories0(int listHandle);
0926:
0927:            /**
0928:             * Adds category to the specified list.
0929:             *
0930:             * @param listHandle native handle of the list that was previously opened
0931:             * @param category name of the category to add
0932:             *
0933:             * @return <code>true</code> on success, <code>false</code> otherwise
0934:             */
0935:            private native boolean addListCategory0(int listHandle,
0936:                    String category);
0937:
0938:            /**
0939:             * Removes category from the specified list.
0940:             *
0941:             * @param listHandle native handle of the list that was previously opened
0942:             * @param category name of the category to delete
0943:             *
0944:             * @return <code>true</code> on success, <code>false</code> otherwise
0945:             */
0946:            private native boolean deleteListCategory0(int listHandle,
0947:                    String category);
0948:
0949:            /**
0950:             * Renames category supported by the given list.
0951:             *
0952:             * @param listHandle native handle of the list that was previously opened
0953:             * @param currentCategory old category name
0954:             * @param newCategory new category name
0955:             *
0956:             * @return <code>true</code> on success, <code>false</code> otherwise
0957:             */
0958:            private native boolean renameListCategory0(int listHandle,
0959:                    String currentCategory, String newCategory);
0960:
0961:            /**
0962:             * Retrieves list of categories the specified item belongs to.
0963:             *
0964:             * @param itemHandle native handle of the item
0965:             * @param dataHandle handle for data buffer
0966:             * @return item's categories, separated by comma
0967:             */
0968:            private native String getItemCategories0(int itemHandle,
0969:                    int dataHandle);
0970:
0971:            /**
0972:             * Returns number of fields supported by the given list.
0973:             *
0974:             * @param listHandle native handle of the list that was previously opened
0975:             * @param dataHandle to save data handle in
0976:             *
0977:             * @return number of supported fields
0978:             */
0979:            private native int getFieldsCount0(int listHandle, int[] dataHandle);
0980:
0981:            /**
0982:             * Returns number of labels for the specified field.
0983:             *
0984:             * @param listHandle native handle of the list that was previously opened
0985:             * @param fieldIndex index of the field
0986:             * @param dataHandle handle of data
0987:             *
0988:             * @return number of labels
0989:             */
0990:            private native int getFieldLabelsCount0(int listHandle,
0991:                    int fieldIndex, int dataHandle);
0992:
0993:            /**
0994:             * Retrieves information about all fields supported by the list.
0995:             *
0996:             * @param listHandle native handle of the list that was previously opened
0997:             * @param desc array where field descriptions will be stored
0998:             * @param dataHandle handle of data
0999:             */
1000:            private native void getFields0(int listHandle,
1001:                    PIMFieldDescriptor[] desc, int dataHandle);
1002:
1003:            /**
1004:             * Returns number of attributes supported by the given list.
1005:             *
1006:             * @param listHandle native handle of the list that was previously opened
1007:             *
1008:             * @param dataHandle array to store data handle in
1009:             * @return number of supported attributes
1010:             */
1011:            private native int getAttributesCount0(int listHandle,
1012:                    int[] dataHandle);
1013:
1014:            /**
1015:             * Retrieves information about all attributes supported by the list.
1016:             *
1017:             * @param listHandle native handle of the list that was previously opened
1018:             * @param attr array where attribute descriptions will be stored
1019:             * @param dataHandle data handle
1020:             */
1021:            private native void getAttributes0(int listHandle,
1022:                    PIMAttribute[] attr, int dataHandle);
1023:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.