connectionregistry.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 843 行 · 第 1/3 页

JAVA
843
字号
                continue;            }            midlet.destroyMidlet();        }    }    /**     * Called when a MIDlet is added to the list, not used by this class.     *     * @param midlet The proxy of the MIDlet being added     */    public void midletAdded(MIDletProxy midlet) {}    /**     * Called when the state of a MIDlet in the list is updated.     *     * @param midlet The proxy of the MIDlet that was updated     * @param fieldId code for which field of the proxy was updated     */    public void midletUpdated(MIDletProxy midlet, int fieldId) {}    /**     * Called when a MIDlet is removed from the list, the connections     * in "launch pending" state for this MIDlet will be checked in.     *     * @param midlet The proxy of the removed MIDlet     */    public void midletRemoved(MIDletProxy midlet) {        checkInByMidlet0(midlet.getSuiteId(), midlet.getClassName());    }    /**     * Called when error occurred while starting a MIDlet object. The     * connections in "launch pending" state for this MIDlet will be checked     * in.     *     * @param externalAppId ID assigned by the external application manager     * @param suiteId Suite ID of the MIDlet     * @param className Class name of the MIDlet     * @param errorCode start error code     * @param errorDetails start error code     */    public void midletStartError(int externalAppId, int suiteId,                                 String className, int errorCode,                                 String errorDetails) {        checkInByMidlet0(suiteId, className);    }    /**     * Initializes the security token for this class, so it can     * perform actions that a normal MIDlet Suite cannot.     *     * @param token security token for this class.     */    public static void initSecurityToken(SecurityToken token) {        if (classSecurityToken == null) {            classSecurityToken = token;        }    }    /**     * Register a dynamic connection.     *     * @param midletSuite <code>MIDlet</code> suite to register connection for     * @param connection generic connection <em>protocol</em>, <em>host</em>     *               and <em>port number</em>     *               (optional parameters may be included     *               separated with semi-colons (;))     * @param midlet  class name of the <code>MIDlet</code> to be launched,     *               when new external data is available     * @param filter a connection URL string indicating which senders     *               are allowed to cause the MIDlet to be launched     *     * @exception ClassNotFoundException if the <code>MIDlet</code> class     *               name can not be found in the current     *               <code>MIDlet</code> suite     * @exception IOException if the connection is already     *              registered or if there are insufficient resources     *              to handle the registration request     * @see #unregisterConnection     */    public static void registerConnection(MIDletSuite midletSuite,            String connection, String midlet, String filter)        throws ClassNotFoundException, IOException {        checkRegistration(connection, midlet, filter);        registerConnectionInternal(midletSuite,                            connection, midlet, filter, true);    }    /**     * Check the registration arguments.     * @param connection preparsed connection to check     * @param midlet  class name of the <code>MIDlet</code> to be launched,     *               when new external data is available     * @param filter a connection URL string indicating which senders     *               are allowed to cause the MIDlet to be launched     * @exception  IllegalArgumentException if connection or filter is not     *               valid     * @exception ConnectionNotFoundException if PushRegistry doesn't support     *               this kind of connections     */    static void checkRegistration(String connection, String midlet,                                  String filter)                                  throws ConnectionNotFoundException {        ProtocolPush.getInstance(connection)            .checkRegistration(connection, midlet, filter);    }    /**     * Register a dynamic connection with the     * application management software. Once registered,     * the dynamic connection acts just like a     * connection preallocated from the descriptor file.     * The internal implementation includes the storage name     * that uniquely identifies the <code>MIDlet</code>.     * This method bypasses the class loader specific checks     * needed by the <code>Installer</code>.     *     * @param midletSuite MIDlet suite for the suite registering,     *                   the suite only has to implement isRegistered,     *                   checkForPermission, and getID.     * @param connection generic connection <em>protocol</em>, <em>host</em>     *               and <em>port number</em>     *               (optional parameters may be included     *               separated with semi-colons (;))     * @param midlet  class name of the <code>MIDlet</code> to be launched,     *               when new external data is available     * @param filter a connection URL string indicating which senders     *               are allowed to cause the MIDlet to be launched     * @param registerConnection if true, register a connection with a     *         protocol,     *         used by the installer when redo old connections during an     *         aborted update     *     * @exception ClassNotFoundException if the <code>MIDlet</code> class     *               name can not be found in the current     *               <code>MIDlet</code> suite     * @exception IOException if the connection is already     *              registered or if there are insufficient resources     *              to handle the registration request     *     * @see #unregisterConnection     */    static void registerConnectionInternal(            final MIDletSuite midletSuite,            final String connection,            final String midlet,            final String filter,            final boolean registerConnection)        throws ClassNotFoundException, IOException {        if (registerConnection) {            /*             * No need to register connection when bypassChecks: restoring             * RFC: why add0 below?             */            ProtocolPush.getInstance(connection)                .registerConnection(midletSuite, connection, midlet, filter);        }        String asciiRegistration = connection                  + "," + midlet                  + "," + filter                  + "," + suiteIdToString(midletSuite);        int ret = add0(asciiRegistration);        if (ret == -1) {            // in case of Bluetooth URL, unregistration within Bluetooth            // PushRegistry was already performed by add0()            throw new IOException("Connection already registered: " + connection);        } else if (ret == -2) {            throw new OutOfMemoryError("Connection registering");        } else if (ret == -3) {            throw new IllegalArgumentException("Connection not found");        }    }    /**     * Remove a dynamic connection registration.     *     * @param midletSuite <code>MIDlet</code> suite to unregister connection     *             for     * @param connection generic connection <em>protocol</em>,     *             <em>host</em> and <em>port number</em>     * @exception SecurityException if the connection was     *            not registered by the current <code>MIDlet</code>     *            suite     * @return <code>true</code> if the unregistration was successful,     *         <code>false</code> the  connection was not registered.     * @see #registerConnection     */    public static boolean unregisterConnection(MIDletSuite midletSuite,            String connection) {        int ret =  del0(connection, suiteIdToString(midletSuite));        if (ret == -2) {            throw new SecurityException("wrong suite");        }        return ret != -1;    }    /**     * Check in a push connection into AMS so the owning MIDlet can get     * launched next time data is pushed. This method is used when a MIDlet     * will not be able to get the connection and close (check in) the     * connection for some reason. (normally because the user denied a     * permission)     * <p>     * For datagram connections this function will discard the cached message.     * <p>     * For server socket connections this function will close the     * accepted connection.     *     * @param connection generic connection <em>protocol</em>, <em>host</em>     *              and <em>port number</em>     *              (optional parameters may be included     *              separated with semi-colons (;))     * @exception IllegalArgumentException if the connection string is not     *              valid     * @exception SecurityException if the <code>MIDlet</code> does not     *              have permission to clear a connection     * @return <code>true</code> if the check in was successful,     *         <code>false</code> the connection was not registered.     * @see #unregisterConnection     */    static boolean checkInConnectionInternal(final String connection) {        /* Verify that the connection requested is valid. */        if (connection == null || connection.length() == 0) {            throw new IllegalArgumentException("Connection missing");        }        byte[] asciiRegistration = Util.toCString(connection);        return checkInByName0(asciiRegistration) != -1;    }    /**     * Return a list of registered connections for the current     * <code>MIDlet</code> suite.     *     * @param midletSuite <code>MIDlet</code> suite to list connections for     * @param available if <code>true</code>, only return the list of     *      connections with input available     * @return array of connection strings, where each connection is     *       represented by the generic connection <em>protocol</em>,     *       <em>host</em> and <em>port number</em> identification     */    public static String [] listConnections(MIDletSuite midletSuite,            boolean available) {        return connectionsToArray(listConnections(midletSuite.getID(),                               available));    }    /**     * Return a list of registered connections for given     * <code>MIDlet</code> suite. AMS permission is required.     *     * @param id identifies the specific <code>MIDlet</code>     *               suite to be launched     * @param available if <code>true</code>, only return the list of     *      connections with input available     *     * @return array of connection strings, where each connection is     *       represented by the generic connection <em>protocol</em>,     *       <em>host</em> and <em>port number</em> identification     */    static String listConnections(int id, boolean available) {        byte[] nativeID;        String connections = null;        byte[] connlist;        nativeID = Util.toCString(suiteIdToString(id));        connlist = new byte[512];        if (list0(nativeID, available, connlist, 512) == 0) {            connections = Util.toJavaString(connlist);        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?