* @see blackberry.core.ScriptableFunctionBase#execute(java.lang.Object, java.lang.Object[])
*/
public Object execute( Object thiz, Object[] args ) throws Exception {
AppointmentObject[] appointmentsFound = new AppointmentObject[ 0 ];
TestableScriptableObject testable = null;
String orderByField = "";
int maxReturn = -1;
String serviceName = "";
boolean isAscending = true;
if( !FindNamespace.isValidFindArguments( args, true ) ) {
return appointmentsFound;
}
if( args.length > 0 ) {
testable = (TestableScriptableObject) args[ 0 ];
}
if( args.length > 1 ) {
if( args[ 1 ] != null ) {
orderByField = (String) args[ 1 ];
}
}
if( args.length > 2 ) {
if( args[ 2 ] != null ) {
Integer i = (Integer) args[ 2 ];
maxReturn = i.intValue();
}
}
if( args.length > 3 ) {
if( args[ 3 ] != null ) {
ServiceObject s = (ServiceObject) args[ 3 ];
serviceName = s.getName();
}
}
if( args.length > 4 ) {
if( args[ 4 ] != null ) {
Boolean b = (Boolean) args[ 4 ];
isAscending = b.booleanValue();
}
}
boolean isSorted = orderByField != null && orderByField.length() > 0 ? true : false;
EventList eventList;
try {
if( serviceName.length() == 0 ) {
eventList = (EventList) PIM.getInstance().openPIMList( PIM.EVENT_LIST, PIM.READ_WRITE );
} else {
eventList = (EventList) PIM.getInstance().openPIMList( PIM.EVENT_LIST, PIM.READ_WRITE, serviceName );
}
} catch( PIMException pime ) {
return appointmentsFound;
}
Vector found = new Vector();
Enumeration e;
int iElement = 0;
try {
e = eventList.items();
while( e.hasMoreElements() ) {
Event evt = (Event) e.nextElement();
AppointmentObject appointment = new AppointmentObject( evt );
if( testable != null ) {
if( testable.test( appointment ) ) {
FindNamespace.insertElementByOrder( found, appointment, orderByField, isAscending );
iElement++;
}
} else {
FindNamespace.insertElementByOrder( found, appointment, orderByField, isAscending );