FileDocCategorySizeDatePackage
ProtocolBase.javaAPI DocphoneME MR2 API (J2ME)11122Wed May 02 18:00:42 BST 2007com.sun.midp.io.j2me.sip

ProtocolBase

public abstract class ProtocolBase extends Object implements com.sun.cldc.io.ConnectionBaseInterface
This class implements the base necessary functionality for a SIP connection. Classes sip.Protocol and sips.Protocol are subclasses of ProtocolBase class This class is a thin wrapper around the NIST JSR180 implementation of the sip URI protocol handler. This class handles the security token intialization and invokes the NISt handler.

Fields Summary
private static SecurityToken
classSecurityToken
Security token for SIP/SIPS protocol class
Constructors Summary
Methods Summary
protected voidcheckForPermission(java.lang.String name, java.lang.String protocol, int permission)
Checks for the required permission.

param
name resource to insert into the permission question
param
protocol protocol name
param
permission value of the permission constant
exception
IOInterruptedException if another thread interrupts the calling thread while this method is waiting to preempt the display.

        Scheduler scheduler;
        MIDletSuite midletSuite;

        scheduler = Scheduler.getScheduler();
        midletSuite = scheduler.getMIDletSuite();

        // there is no suite running when installing from the command line
        if (midletSuite == null) {
            return;
        }
        name = protocol + ":" + name;
        try {
            midletSuite.checkForPermission(permission, name);
        } catch (InterruptedException ie) {
            throw new InterruptedIOException(
                    "Interrupted while trying to ask the user permission");
        }
    
public booleanisProtocolSupported(java.lang.String protocol)
Checks if transport protocol is supported.

param
protocol protocol name
return
true when protocol is supported


                         
        
        if (protocol == null) {
          return false;
        } else {
            return protocol.equalsIgnoreCase(SIPConstants.TRANSPORT_UDP) ||
                protocol.equalsIgnoreCase(SIPConstants.TRANSPORT_TCP);
        }
    
protected ConnectionopenConn(java.lang.String name, java.lang.String scheme)
Open a client or server socket connection.

The name string for this protocol should be: {scheme}:[{target}][{params}] where: scheme is SIP(S) scheme supported by the system sip target is user network address in form of {user_name}@{target_host}[:{port}] or {telephone_number}, see examples below. params stands for additional SIP URI parameters like ;transport=udp Opening new client connection (SipClientConnection): If the target host is included a, SipClientConnection will be returned. Examples: sip:bob@biloxi.com?sips:alice@10.128.0.8:5060 sip:alice@company.com:5060;transport=tcp sip:+358-555-1234567;postd=pp22@foo.com;user=phone Opening new server connection (SipConnectionNotifier): Three forms of SIP URIs are allowed where the target host is omitted: sips:nnnn, returns SipConnectionNotifier listening to incoming SIP requests on port number nnnn. sip:, returns SipConnectionNotifier listening to incoming SIP requests on a port number allocated by the system. sip:[nnnn];type=application/x-type, returns SipConnectionNotifier listening to incoming SIP requests that match to the MIME type application/x-type (specified in the URI parameter type). Port number is optional. Examples of opening a SIP connection: SipClientConnection scn = (SipClientConnection) Connector.open(sips:bob@biloxi.com); SipClientConnection scn= (SipClientConnection) Connector.open(sip:alice@company.com:5060;transport=tcp); SipConnectionNotifier scn = (SipConnectionNotifier) Connector.open(sip:5060); SipConnectionNotifier scn = (SipConnectionNotifier) Connector.open(sip:5080); SipConnectionNotifier scn = (SipConnectionNotifier) Connector.open(sip:);

param
name the [{target}][{params}] for the connection
param
scheme the scheme name (sip or sips)
return
client or server SIPS connection
exception
IOException if an I/O error occurs.
exception
ConnectionNotFoundException if the host cannot be connected to
exception
IllegalArgumentException if the name is malformed

        
        Connection retval = null;
        URLParser parser = new URLParser(scheme + ":" + name);
        SipURI inputURI = null;
        
        try {
            inputURI = (SipURI)parser.parseWholeString();
        } catch (ParseException exc) {
            throw new IllegalArgumentException(exc.getMessage());
        }
        
        String transport = inputURI.getTransportParam();
        if (transport == null) { // get default transport name
            transport =  SIPConstants.TRANSPORT_UDP;
        } else if (!transport.equalsIgnoreCase(SIPConstants.TRANSPORT_UDP) &&
            !transport.equalsIgnoreCase(SIPConstants.TRANSPORT_TCP)) {
            throw new SipException(SipException.TRANSPORT_NOT_SUPPORTED);
        }
        
        
        if (transport == null) { // get default transport name
            transport =  SIPConstants.TRANSPORT_UDP;
        }
        int portNum = inputURI.getPort();
        
        boolean isSecure = inputURI.isSecure();
        
        StackConnector stackConnector =
            StackConnector.getInstance(classSecurityToken);
        
        if (inputURI.isServer()) { // server URI
            String mimeType = inputURI.getTypeParam();
            if (inputURI.isShared()) { // sip:*;type="application/..."
                if (mimeType == null) { // no type parameter
                    throw new IllegalArgumentException("No type parameter "
                        + "in shared URI");
                }
                retval = (Connection)stackConnector.
                    createSharedSipConnectionNotifier(
                        isSecure,
                        transport,
                        mimeType);
            } else { // dedicated sip:5060;...
                retval = (Connection)stackConnector.
                    createSipConnectionNotifier(
                        portNum,
                        isSecure,
                        transport,
                        mimeType);
            }
        } else { // client URI

            if (portNum == -1) { // set default port
                inputURI.setPort(SIPConstants.DEFAULT_NONTLS_PORT);
            }

            retval = (Connection) stackConnector.
                createSipClientConnection(inputURI);
        }
        return retval;
    
public java.io.DataInputStreamopenDataInputStream()
Throw IOException on call openInputStream() method.

return
nothing
exception
IOException always throws

        throw new IOException("SIP connection doesn't support input stream");
    
public java.io.DataOutputStreamopenDataOutputStream()
Throw IOException on call openInputStream() method.

return
nothing
exception
IOException always throws

        throw new IOException("SIP connection doesn't support output stream");
    
public java.io.InputStreamopenInputStream()
Throw IOException on call openInputStream() method.

return
nothing
exception
IOException always throws

        throw new IOException("SIP connection doesn't support input stream");
    
public java.io.OutputStreamopenOutputStream()
Throw IOException on call openInputStream() method.

return
nothing
exception
IOException always throws

        throw new IOException("SIP connection doesn't support output stream");
    
public abstract ConnectionopenPrim(java.lang.String name, int mode, boolean timeouts)
Sets up the state of the connection, but does not actually connect to the server until there's something to do.

param
name the URL for the connection, without the without the protocol part.
param
mode the access mode, ignored
param
timeouts flag to indicate that the caller wants timeout exceptions, ignored
return
reference to this connection
exception
IllegalArgumentException if a parameter is invalid
exception
ConnectionNotFoundException if the connection cannot be found
exception
IOException if some other kind of I/O error occurs