FileDocCategorySizeDatePackage
PushRegistryImpl.javaAPI DocphoneME MR2 API (J2ME)12632Wed May 02 18:00:00 BST 2007com.sun.midp.io.j2me.push

PushRegistryImpl

public final class PushRegistryImpl extends Object
PushRegistry implementation that checks parameters.

Fields Summary
Constructors Summary
private PushRegistryImpl()
Hides the default constructor.

 
Methods Summary
private static voidcheckMidlet(com.sun.midp.midlet.MIDletSuite midletSuite, java.lang.String midlet)
Checks validity of midlet class name.

param
midletSuite host MIDlet suite (MUST be not null
param
midlet Name of MIDlet class to check
throws
ClassNotFoundException if MIDlet is invalid

        checkMidletRegistered(midletSuite, midlet);

        /*
         * IMPL_NOTE: strings in MIDlet-<n> attributes (see the check
         *  above) are not verified to be the names of classes that
         *  subclass javax.microedition.midlet.MIDlet, therefore we
         *  need this check
         */
        final Class midletCls = Class.forName(midlet);
        final boolean isMIDlet = javax.microedition.midlet.MIDlet.class
            .isAssignableFrom(midletCls);

        if (!isMIDlet) {
            throw new ClassNotFoundException("Not a MIDlet");
        }
    
static voidcheckMidletRegistered(com.sun.midp.midlet.MIDletSuite midletSuite, java.lang.String midlet)
Checks that the midlet is registered for the given suite.

param
midletSuite host MIDlet suite (MUST be not null
param
midlet Name of MIDlet class to check
throws
ClassNotFoundException if MIDlet is not registered

        // assert midletSuite != null;
        // RFC: the check below might be unnecessary
        if (midlet == null || midlet.length() == 0) {
            throw new ClassNotFoundException("MIDlet missing");
        }

        if (!midletSuite.isRegistered(midlet)) {
            throw new ClassNotFoundException("No MIDlet-<n> registration");
        }
    
public static java.lang.StringgetFilter(java.lang.String connection)
Retrieve the registered filter for a requested connection.

param
connection generic connection protocol, host and port number (optional parameters may be included separated with semi-colons (;))
return
a filter string indicating which senders are allowed to cause the MIDlet to be launched or null if the connection was not registered
see
#registerConnection


        /* Verify that the connection requested is valid. */
        if (connection == null || connection.length() == 0) {
            return null;
        }

        return ConnectionRegistry.getFilter(connection);
    
public static java.lang.StringgetMIDlet(java.lang.String connection)
Retrieve the registered MIDlet for a requested connection.

param
connection generic connection protocol, host and port number (optional parameters may be included separated with semi-colons (;))
return
class name of the MIDlet to be launched, when new external data is available, or null if the connection was not registered
see
#registerConnection


        /* Verify that the connection requested is valid. */
        if (connection == null || connection.length() == 0) {
            return null;
        }

        return ConnectionRegistry.getMIDlet(connection);
    
private static com.sun.midp.midlet.MIDletSuitegetMIDletSuite()
Gets a midlet suite object.

return
A reference to MIDletSuite object

        return MIDletStateHandler
                .getMidletStateHandler()
                .getMIDletSuite();
    
public static java.lang.String[]listConnections(boolean available)
Return a list of registered connections for the current MIDlet suite.

param
available if true, only return the list of connections with input available
return
array of connection strings, where each connection is represented by the generic connection protocol, host and port number identification

        final MIDletSuite midletSuite = getMIDletSuite();
        if (midletSuite == null) {
            return null;
        }

        return ConnectionRegistry.listConnections(midletSuite, available);
    
public static longregisterAlarm(java.lang.String midlet, long time)
Register a time to launch the specified application. The PushRegistry supports one outstanding wake up time per MIDlet in the current suite. An application is expected to use a TimerTask for notification of time based events while the application is running.

If a wakeup time is already registered, the previous value will be returned, otherwise a zero is returned the first time the alarm is registered.

param
midlet class name of the MIDlet within the current running MIDlet suite to be launched, when the alarm time has been reached
param
time time at which the MIDlet is to be executed in the format returned by Date.getTime()
return
the time at which the most recent execution of this MIDlet was scheduled to occur, in the format returned by Date.getTime()
exception
ConnectionNotFoundException if the runtime system does not support alarm based application launch
exception
ClassNotFoundException if the MIDlet class name can not be found in the current MIDlet suite
see
Date#getTime()
see
Timer
see
TimerTask


        final MIDletSuite midletSuite = getMIDletSuite();
        if (midletSuite == null) {
            throw new IllegalStateException("Not in a MIDlet context");
        }

        checkMidlet(midletSuite, midlet);
        try {
            midletSuite.checkForPermission(Permissions.PUSH, null);
        } catch (InterruptedException ie) {
            throw new RuntimeException(
                "Interrupted while trying to ask the user permission");
        }

        return ConnectionRegistry.registerAlarm(midletSuite, midlet, time);
    
public static voidregisterConnection(java.lang.String connection, java.lang.String midlet, java.lang.String 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 MIDlet.

param
connection generic connection protocol, host and port number (optional parameters may be included separated with semi-colons (;))
param
midlet class name of the MIDlet 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 the connection string is not valid
exception
ConnectionNotFoundException if the runtime system does not support push delivery for the requested connection protocol
exception
IOException if the connection is already registered or if there are insufficient resources to handle the registration request
exception
ClassNotFoundException if the MIDlet class name can not be found in the current MIDlet suite
exception
SecurityException if the MIDlet does not have permission to register a connection
exception
IllegalStateException if the MIDlet suite context is null.
see
#unregisterConnection


        final Connection c = Connection.parse(connection);

        // Quick check of filter to be spec complaint
        if (filter == null) {
            throw new IllegalArgumentException("filter is null");
        }

        final MIDletSuite midletSuite = getMIDletSuite();

        /* This method should only be called by running MIDlets. */
        if (midletSuite == null) {
            throw new IllegalStateException("Not in a MIDlet context");
        }

        /*
         * Validate parameters and Push connection availability
         */
        checkMidlet(midletSuite, midlet);
        /*
         * IMPL_NOTE: as checkRegistration will need to parse
         *  connection and filter anyway, it might be a good
         *  idea to save the results
         */
        ConnectionRegistry.checkRegistration(c, midlet, filter);

        /*
         * Check permissions.
         */
        try {
            midletSuite.checkForPermission(Permissions.PUSH, null);
        } catch (InterruptedException ie) {
            throw new InterruptedIOException(
                "Interrupted while trying to ask the user permission");
        }

        ConnectionRegistry.registerConnection(midletSuite, c, midlet, filter);
    
public static booleanunregisterConnection(java.lang.String connection)
Remove a dynamic connection registration.

param
connection generic connection protocol, host and port number
exception
SecurityException if the connection was not registered by the current MIDlet suite
return
true if the unregistration was successful, false the connection was not registered.
see
#registerConnection


        /* Verify the connection string before using it. */
        if (connection == null || connection.length() == 0) {
            return false;
        }

        final MIDletSuite midletSuite = getMIDletSuite();
        if (midletSuite == null) {
            return false;
        }

        return ConnectionRegistry.unregisterConnection(midletSuite, connection);