FileDocCategorySizeDatePackage
BluetoothProtocol.javaAPI DocphoneME MR2 API (J2ME)8452Wed May 02 18:00:30 BST 2007com.sun.midp.io

BluetoothProtocol

public abstract class BluetoothProtocol extends Object implements com.sun.cldc.io.ConnectionBaseInterface
Provides abstract base for bluetooth protocols.

Fields Summary
private int
protocol
Particular protocol type.
protected com.sun.midp.io.BluetoothUrl
url
Keeps set of fields specified by URL.
Constructors Summary
protected BluetoothProtocol(int protocol)
Constructs an instance.

param
protocol specifies particular protocol, must be one of BluetoothUrl.L2CAP, BluetoothUrl.RFCOMM, BluetoothUrl.OBEX


                          
       
        this.protocol = protocol;
    
Methods Summary
protected voidcheckForPermission(com.sun.midp.security.SecurityToken token, int permission)
Makes sure caller has the com.sun.midp permission set to "allowed".

param
token security token of the calling class, may be null
param
permission requested permission ID
exception
IOInterruptedException if another thread interrupts the calling thread while this method is waiting to preempt the display.


        if (token != null) {
            token.checkIfPermissionAllowed(permission);
        } else {

            MIDletSuite midletSuite =
                MIDletStateHandler.getMidletStateHandler().getMIDletSuite();

            if (midletSuite != null) {
                try {
                    midletSuite.checkForPermission(permission,
                                                   url.getResourceName());
                } catch (InterruptedException ie) {
                    throw new InterruptedIOException(
                        "Interrupted while trying to ask the user permission");
                }
            }
        }
    
private voidcheckOpenMode(int mode)
Ensures open mode requested is READ_WRITE or READ or WRITE

param
mode open mode to be checked
exception
IllegalArgumentException if mode given is invalid IMPL_NOTE check if other modes are needed

        if (mode != Connector.READ_WRITE &&
            mode != Connector.READ &&
            mode != Connector.WRITE) {
            throw new IllegalArgumentException("Unsupported mode: " + mode);
        }
    
protected voidcheckUrl(com.sun.midp.io.BluetoothUrl url)
Ensures URL parameters have valid values. This implementation contains common checks and is called from subclasses before making protocol specific ones.

param
url URL to check
exception
IllegalArgumentException if invalid url parameters found
exception
BluetoothConnectionException if url parameters are not acceptable due to Bluetooth stack limitations


        /*
         * IMPL_NOTE: revisit this code if TCK changes.
         * IllegalArgumentException seems to be right one here, not
         * BluetoothConnectionException. However TCK expects the latter
         * in several cases. Once IllegalArgumentException becomes
         * preferable this check can be placed to BluetoothUrl.
         * Questionable TCK tests:
         * bluetooth.Connector.Security.openClientTests,
         * bluetooth.Connector.Security.openServerTests
         */
        if ((url.encrypt || url.authorize) && !url.authenticate) {
            throw new BluetoothConnectionException(
                BluetoothConnectionException.UNACCEPTABLE_PARAMS,
                "Invalid Authenticate parameter");
        }
    
protected abstract javax.microedition.io.ConnectionclientConnection(com.sun.midp.security.SecurityToken token, int mode)
Ensures that permissions are proper and creates client side connection.

param
token security token if passed by caller, or null client side connection.
param
mode I/O access mode
return
connection created, defined in subclasses
exception
IOException if opening connection fails.

public javax.microedition.io.ConnectionopenPrim(java.lang.String name, int mode, boolean timeouts)
Implements the openPrim() of ConnectionBaseInerface and allows to get connection by means of Connector.open() call.

param
name the target for the connection
param
mode I/O access mode
param
timeouts ignored
return
L2CAP connection open.
exception
IOException if opening connection fails.

        return openPrim(null, name, mode, timeouts);
    
public javax.microedition.io.ConnectionopenPrim(java.lang.Object token, java.lang.String name, int mode, boolean timeouts)
Checks permissions and opens requested connection.

param
token security token of the calling class
param
name the URL without protocol name and colon.
param
mode connector.READ_WRITE or connector.READ or connector.WRITE
param
timeouts ignored.
return
a notifier in case of server connection string, open connection in case of client one.
exception
IOException if opening connection fails.


        return openPrimImpl(token,
            new BluetoothUrl(protocol, name), mode);
    
protected javax.microedition.io.ConnectionopenPrimImpl(java.lang.Object token, com.sun.midp.io.BluetoothUrl url, int mode)
Checks permissions and opens requested connection.

param
token security token passed by calling class
param
url BluetoothUrl instance that defines required connection stringname the URL without protocol name and colon
param
mode connector.READ_WRITE or connector.READ or connector.WRITE
return
a notifier in case of server connection string, open connection in case of client one.
exception
IOException if opening connection fails.

        checkOpenMode(mode);
        checkUrl(url);
        this.url = url;

        return url.isServer?
            serverConnection((SecurityToken)token, mode):
            clientConnection((SecurityToken)token, mode);
    
protected abstract javax.microedition.io.ConnectionserverConnection(com.sun.midp.security.SecurityToken token, int mode)
Ensures that permissions are proper and creates required notifier at server side.

param
token security token if passed by caller, or null
param
mode I/O access mode
return
server notifier, defined in subclasses
exception
IOException if opening connection fails.