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

ProtocolPush

public abstract class ProtocolPush extends Object
JSR's implementations will provide push behaviour.

Fields Summary
protected static final int
IP4_DELIMITER_COUNT
Number of delimiter characters in IP v4 address
Constructors Summary
Methods Summary
protected voidcheckIIPFilter(java.lang.String filter)
Check IP filter is valid.

param
filter a connection URL string indicating which senders are allowed to cause the MIDlet to be launched
exception
IllegalArgumentException if the connection contains no port value

        int len = filter.length();
        int dotCount = 0;
        boolean dotUnexpected = true;
        boolean failed = false;

        /* IP address characters only for other connections. */
        /* Check for special case - single * char. This is valid filter. */
        if (!"*".equals(filter)) {
            /* All other filters shall be in IPv4 format. */
            for (int i = 0; i < len && !failed; i++) {
                char c = filter.charAt(i);

                if (c == '.") {
                    if (dotUnexpected || i == len-1) {
                        failed = true;
                    } else {
                        dotCount++;
                        if (dotCount > IP4_DELIMITER_COUNT) {
                            failed = true;
                        }
                        dotUnexpected = true;
                    }
                } else
                    if (c != '?" && c != '*" && !('0" <= c && c <= '9")) {
                        /* The only acceptable characters are [*?0-9] */
                        failed = true;
                    } else {
                        dotUnexpected = false;
                    }
            }

            if (failed || dotCount < IP4_DELIMITER_COUNT) {
                throw new IllegalArgumentException("IP Filter \"" + filter + "\" is invalid");
            }
        }
    
protected voidcheckIsNotHost(java.lang.String connection, boolean checkPort)
Check if host is not present.

param
connection generic connection protocol, host and port number (optional parameters may be included separated with semi-colons (;))
param
checkPort check if the port is not omitted
exception
IllegalArgumentException if the connection contains no port value
exception
ConnectionNotFoundException if connection contains any host name

        HttpUrl url = new HttpUrl(connection);
        // Server connections do not have a host
        if (url.host != null) {
            throw new ConnectionNotFoundException(
                "Connection not supported");
        }

        if (checkPort && url.port == -1) {
            new IllegalArgumentException("Port missing");
        }
    
public abstract voidcheckRegistration(java.lang.String connection, java.lang.String midlet, java.lang.String filter)
Called when registration is checked.

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
ClassNotFoundException if the MIDlet class name can not be found in the current MIDlet suite

protected abstract com.sun.midp.io.j2me.push.ProtocolPushgetInstance()
Get instance of this class.

return
class instance

public static com.sun.midp.io.j2me.push.ProtocolPushgetInstance(java.lang.String connection)
Get instance of class depends on protocol.

param
connection generic connection protocol, host and port number (optional parameters may be included separated with semi-colons (;))
return
class instance
exception
IllegalArgumentException if the connection string is not valid
exception
ConnectionNotFoundException if the protocol is not supported or invalid


                 
       

                                                                                                                                
         
           

        /* Verify that the connection requested is valid. */
        if (connection == null || connection.length() == 0) {
            throw new IllegalArgumentException("Connection is empty");
        }

        int index = connection.indexOf(':");
        if (index == -1) {
            throw new IllegalArgumentException("Protocol field is omitted");
        }

        String className = Configuration.getProperty
            (connection.substring(0, index).toLowerCase());

        if (className == null || className.length() == 0) {
            throw new ConnectionNotFoundException("Protocol is invalid " +
                "or not supported");
        }

        try {
            ProtocolPush cl = (ProtocolPush)Class.forName(className).newInstance();
            return cl.getInstance();
        } catch (ClassNotFoundException exc) {
            throw new ConnectionNotFoundException("Protocol is not supported");
        } catch (ClassCastException exc) {
            throw new RuntimeException(
                    "System error loading class " + className + ": " + exc);
        } catch (IllegalAccessException exc) {
            throw new RuntimeException(
                    "System error loading class " + className + ": " + exc);
        } catch (InstantiationException exc) {
            throw new RuntimeException(
                    "System error loading class " + className + ": " + exc);
        }
    
public abstract voidregisterConnection(com.sun.midp.midlet.MIDletSuite midletSuite, java.lang.String connection, java.lang.String midlet, java.lang.String filter)
Called when registration is established.

param
midletSuite MIDlet suite for the suite registering, the suite only has to implement isRegistered, checkForPermission, and getID.
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
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