Package net.rim.device.api.script

Examples of net.rim.device.api.script.Scriptable


             * In 6.0 - java.util.Date is not passed back, it is a Scriptable object representing the JavaScript Date object.
             * Retrieve the getTime() and create java.util.Date
             */
            if( objective instanceof Scriptable ) {
                try {
                    final Scriptable s = (Scriptable) objective;
                    final Object getTime = s.getField( "getTime" );
                    if( getTime instanceof ScriptableFunction ) {
                        final Double millis = (Double) ( (ScriptableFunction) getTime ).invoke( objective, new Object[] {} );
                        objective = new Date( millis.longValue() );
                    }
                } catch( final Exception e ) {
View Full Code Here


        Object[] valueArr = null;

        try {
            if( value != null ) {
                if( value instanceof Scriptable ) {
                    final Scriptable valuesArray = (Scriptable) value;

                    if( valuesArray.getField( "length" ) != null ) {
                        final int length = ( (Integer) valuesArray.getField( "length" ) ).intValue();
                        valueArr = new Object[ length ];

                        for( int i = 0; i < length; i++ ) {
                            final Object obj = valuesArray.getElement( i );
                            valueArr[ i ] = obj;
                        }
                    }
                } else if( value instanceof Object[] ) {
                    valueArr = (Object[]) value;
View Full Code Here

    /**
     * @see ScriptableFunctionBase#execute(Object, Object[])
     */
    protected Object execute( Object thiz, Object[] args ) throws Exception {

        Scriptable obj = (Scriptable) args[ 0 ];
        int port = ( (Integer) obj.getField( KEY_PORT ) ).intValue();
        String appId = obj.getField( KEY_APP_ID ).toString();
        String serverUrl = obj.getField( KEY_SERVER_URL ).toString();
        String wakeUpPage = obj.getField( KEY_WAKEUP_PAGE ).toString();
        int maxQueueCap = 0;
        Object maxQueueCapObj = obj.getField( KEY_MAX_QUEUE_CAP );
        if( maxQueueCapObj != UNDEFINED ) {
            maxQueueCap = ( (Integer) maxQueueCapObj ).intValue();
        }
        ScriptableFunction onData = (ScriptableFunction) args[ 1 ];
        ScriptableFunction onRegister = (ScriptableFunction) args[ 2 ];
View Full Code Here

     * @see ScriptableFunctionBase#validateArgs(Object[])
     */
    protected void validateArgs( Object[] args ) {
        super.validateArgs( args );

        Scriptable obj = (Scriptable) args[ 0 ];
        try {
            Object port = obj.getField( KEY_PORT );
            if( port != null && port != UNDEFINED ) {
                int portValue = ( (Integer) port ).intValue();
                if( portValue < 0 ) {
                    throw new IllegalArgumentException( "Invalid port." );
                } else if( !PushService.isValidPort( portValue ) ) {
                    throw new IllegalArgumentException( "Reserved port" );
                }
            } else {
                throw new IllegalArgumentException( "Port is missing." );
            }
            Object appId = obj.getField( KEY_APP_ID );
            if( appId == null || appId == UNDEFINED ) {
                throw new IllegalArgumentException( "AppId is missing." );
            }
            Object serverUrl = obj.getField( KEY_SERVER_URL );
            if( serverUrl == null || serverUrl == UNDEFINED ) {
                throw new IllegalArgumentException( "serverUrl is missing." );
            }
            Object wakeUpPage = obj.getField( KEY_WAKEUP_PAGE );
            if( wakeUpPage == null || wakeUpPage == UNDEFINED ) {
                throw new IllegalArgumentException( "AppId is missing." );
            }
        } catch( Exception e ) {
            throw new IllegalArgumentException( "Error retrieving arguments: " + e.getMessage() );
View Full Code Here

    }
   
    private class AddInviteItemFunction extends ScriptableFunctionBase {
       
        protected Object execute(Object thiz, Object[] args) throws Exception {
            final Scriptable options = (Scriptable) args[0];
            final int menuItemId = ((Integer) options.getField("menuItemId")).intValue();
            final int order =      ((Integer) options.getField("order")).intValue();
            final String label =     (String) options.getField("label");
            final String inviteMsg = (String) options.getField("invitationMessage");
           
            _menuMgr.addChannelInvitationMenuItem(menuItemId, inviteMsg, label, order);
            return UNDEFINED;
        }
View Full Code Here

    }
   
    private class AddItemFunction extends ScriptableFunctionBase {
       
        protected Object execute(Object thiz, Object[] args) throws Exception {
            final Scriptable options = (Scriptable) args[0];
           
            final String text = (String) options.getField("text");
           
            // cookie is optional
            final String cookie;
            final Object cookieObj = options.getField("cookie");
            if(cookieObj.equals(UNDEFINED)) {
                cookie = null;
            } else {
                cookie = (String) cookieObj;
            }
           
            // icon is optional
            final int iconID;
            final Object iconURI = options.getField("icon");
            if(iconURI.equals(UNDEFINED)) {
                iconID = -1;
            } else {
                final byte[] iconBytes = Util.requestBitmapBytes((String) iconURI);
                final Bitmap icon = Bitmap.createBitmapFromBytes(iconBytes, 0, iconBytes.length, 1);
View Full Code Here

    } // MyPresenceListener
   
    private class PickUsersFunction extends ScriptableFunctionBase {

        protected Object execute(Object thiz, Object[] args) throws Exception {
            final Scriptable options =                    (Scriptable) args[0];
            final ScriptableFunction onComplete = (ScriptableFunction) args[1];
           
            // title is optional. default = null
            final String title;
            final Object titleObj = options.getField("title");
            if(titleObj.equals(UNDEFINED)) {
                title = null;
            } else {
                title = (String) titleObj;
            }
          
            // multiSelect is optional. default = false
            final Object multiSelectObj = options.getField("multiSelect");
            final boolean multiSelect;
            if(multiSelectObj.equals(UNDEFINED)) {
                multiSelect = false;
            } else {
                multiSelect = ((Boolean) multiSelectObj).booleanValue();
            }
           
            // showSelectAll is optional. default = false
            final Object showSelectAllObj = options.getField("showSelectAll");
            final boolean showSelectAll;
            if(showSelectAllObj.equals(UNDEFINED)) {
                showSelectAll = false;
            } else {
                showSelectAll = ((Boolean) showSelectAllObj).booleanValue();
            }
           
            // type is optional. default = -1
            final Object type =  options.getField("type");
            final int groupTypeInt;
            if(type.equals(UNDEFINED)) {
                groupTypeInt = -1;
            } else {
                groupTypeInt = Util.groupTypeStrToInt((String) type);
            }
           
            // users is optional. default = null
            final Object users = options.getField("users");
            final ContactListProvider userList;
            if(users.equals(UNDEFINED)) {
                userList = null;
            } else {
                BBMPlatformUser[] usersArray = Util.scriptableUsersArrayToUserArray((Scriptable) users);
View Full Code Here

                        }
                        Util.dispatchCallback(onComplete, null);
                    }
                });
            } else if(args.length >= 3) {
                final Scriptable users = (Scriptable) args[2];
               
                // Create contact list
                final BBMPlatformContactList contacts = new BBMPlatformContactList();
                final int numUsers = users.getElementCount();
                for(int i = 0; i < numUsers; i++) {
                    BBMPlatformUser user = (BBMPlatformUser) users.getElement(i);
                    contacts.add((BBMPlatformContact) user.getPresence());
                }
               
                _uiService.startBBMChat(contacts, message);
                Util.dispatchCallback(onComplete, null);
View Full Code Here

    } // StartBBMChatFunction
   
    private class InviteToBBMFunction extends ScriptableFunctionBase {
        protected Object execute(Object thiz, Object[] args) throws Exception {
            final ScriptableFunction onComplete = (ScriptableFunction) args[0];       
            final Scriptable scriptInvitations =          (Scriptable) args[1];
            final BBMInvitationRequest[] invitations = this.scriptInvitesToJava(scriptInvitations);
            this.validateInvitations(invitations);
           
            Dispatcher.getInstance().dispatch(new DispatchableEvent(null) {
                protected void dispatch() {
View Full Code Here

            final BBMInvitationRequest[] javaInvites = new BBMInvitationRequest[numInvites];
            final String fieldName = "name";
            final String fieldPin =  "pin";
           
            for(int i = 0; i < numInvites; i++) {
                Scriptable scriptInvite = (Scriptable) scriptInvites.getElement(i);
                String pinObj =  (String) scriptInvite.getField(fieldPin);
                String nameObj = (String) scriptInvite.getField(fieldName);
               
                javaInvites[i] = new BBMInvitationRequest(pinObj, nameObj);
            }
            return javaInvites;
        }
View Full Code Here

TOP

Related Classes of net.rim.device.api.script.Scriptable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.