protected Object execute(Object thiz, Object[] args) throws Exception {
final String invitationMsg = (String) args[0];
long expiryTime;
String cookie;
ContactListProvider contactList;
if(args.length == 2) {
final Scriptable options = (Scriptable) args[1];
Object expiryTimeObj = options.getField(OPTIONS_FIELD_EXPIRY_TIME);
if(expiryTimeObj.equals(UNDEFINED)) {
expiryTime = 0;
} else {
try {
expiryTime = Long.parseLong(expiryTimeObj.toString());
} catch(Exception e) {
expiryTime = 0;
}
}
try {
cookie = (String) options.getField(OPTIONS_FIELD_COOKIE);
} catch(Exception e) {
cookie = null;
}
try {
BBMPlatformUser[] contacts = (BBMPlatformUser[]) options.getField(OPTIONS_FIELD_CONTACTS);
contactList = new Util.SimpleContactListProvider(contacts);
} catch(Exception e) {
contactList = null;
}
} else {
expiryTime = 0;
cookie = null;
contactList = null;
}
// Validate args
if(invitationMsg != null && invitationMsg.length() > _connection.getMaxInvitationMessageLength()) {
throw new IllegalArgumentException("inviteMessage.length > " + _connection.getMaxInvitationMessageLength());
}
if(cookie != null && cookie.length() > _connection.getMaxCookieLength()) {
throw new IllegalArgumentException("cookie.length > " + _connection.getMaxCookieLength());
}
final String finalCookie = cookie;
final long finalExpTime = expiryTime;
final ContactListProvider finalContactList = contactList;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
try {
_connection.sendInvitation(invitationMsg, finalCookie, finalExpTime, finalContactList);