FileDocCategorySizeDatePackage
BluetoothPush.javaAPI DocphoneME MR2 API (J2ME)7536Wed May 02 18:00:30 BST 2007com.sun.midp.jsr082.bluetooth

BluetoothPush

public class BluetoothPush extends Object
Bluetooth connect-anytime services support class.

Fields Summary
private static final String
AUTHENTICATED
'authenticated' AllowedSender parameter.
private static final String
AUTHORIZED
'authorized' AllowedSender parameter.
private static final String
BLACKLIST
'blacklist' AllowedSender parameter.
private static ServiceRecordSerializer
srs
Service record serializer instance.
Constructors Summary
Methods Summary
private static native intgetRecordHandle(java.lang.String url)
Retrieves service record handle for a service maintained by Bluetooth push subsytem.

param
url URL used during push entry registration
return
service record handle

public static ServiceRecordImplgetServiceRecord(BluetoothNotifier notifier, java.lang.String url)
Retrieves service record associated with a service maintained by Bluetooth push subsytem.

param
notifier Bluetooth notifier to be used with the service record
param
url URL used during push entry registration
return
service record instance

        return SDDB.getInstance().getServiceRecord(getRecordHandle(url),
                notifier);
    
public static voidregisterUrl(java.lang.String url)
Registers URL within Bluetooth push subsytem.

param
url URL to register
throws
IOException if an I/O error occurs

        ServiceRecordImpl record = null;
        String protocol = url.substring(0, url.indexOf(':")).toUpperCase();
        if (protocol.equals("BTL2CAP")) {
            record = L2CAPNotifierImpl.createServiceRecord(url);
        } else if (protocol.equals("BTSPP")) {
            record = BTSPPNotifierImpl.createServiceRecord(url);
        } else if (protocol.equals("BTGOEP")) {
            record = BTSPPNotifierImpl.createServiceRecord(url);
        } else {
            throw new RuntimeException("Unsupported Bluetooth protocol.");
        }
        if (!BCC.getInstance().isBluetoothEnabled() &&
                !BCC.getInstance().enableBluetooth()) {
            throw new IOException("Bluetooth radio is not enabled.");
        }
        if (!registerUrl(url, srs.serialize(record))) {
            throw new IOException("Error registering Bluetooth URL.");
        }
        if (BCC.getInstance().getAccessCode() != DiscoveryAgent.GIAC) {
            BCC.getInstance().setAccessCode(DiscoveryAgent.GIAC);
        }
        // get the emulation services up and running
        SDDB.getInstance();
    
private static native booleanregisterUrl(java.lang.String url, byte[] data)
Registers URL within Bluetooth push subsystem.

param
url URL to register
param
data serialized service record created from the URL
return
true on success, false on failure

public static voidverifyFilter(java.lang.String filter)
Checks if the specified AllowedSender field is valid.

param
filter filter to verify
throws
IllegalArgumentException if the filter is malformed

        if (filter.length() == 0) {
            throw new IllegalArgumentException();
        }
        filter = filter.toUpperCase();
        int i = 0;
        while (i < filter.length() && i < 12) {
            char c = filter.charAt(i++);
            if (c == '*" || c == '?") {
                continue;
            }
            if (c == ';") {
                i--;
                if (i == 0) {
                    throw new IllegalArgumentException(
                            "Invalid Bluetooth address.");
                }
                break;
            }
            if ((c < '0" || c > '9") && (c < 'A" || c > 'F")) {
                throw new IllegalArgumentException(
                        "Invalid Bluetooth address.");
            }
        }
        filter = filter.substring(i);
        if (filter.length() == 0) {
            return;
        }
        if (filter.startsWith(AUTHENTICATED)) {
            filter = filter.substring(AUTHENTICATED.length());
        } else if (filter.startsWith(AUTHORIZED)) {
            filter = filter.substring(AUTHORIZED.length());
        }
        if (filter.length() == 0) {
            return;
        }
        if (!filter.startsWith(BLACKLIST)) {
            throw new IllegalArgumentException("Invalid parameter.");
        }
        filter = filter.substring(BLACKLIST.length());
        if (filter.length() == 0) {
            throw new IllegalArgumentException("Invalid blacklist.");
        }
        int count = 0;
        while (true) {
            if (++count > 1024) {
                throw new IllegalArgumentException("Blacklist too long.");
            }
            i = 0;
            while (i < filter.length() && i < 12) {
                char c = filter.charAt(i++);
                if (c == '*" || c == '?") {
                    continue;
                }
                if (c == ';") {
                    i--;
                    break;
                }
                if ((c < '0" || c > '9") && (c < 'A" || c > 'F")) {
                    throw new IllegalArgumentException(
                            "Invalid blacklist address.");
                }
            }
            filter = filter.substring(i);
            if (filter.length() == 0) {
                return;
            }
            if (filter.charAt(0) != ';" || filter.length() == 1) {
                throw new IllegalArgumentException("Invalid blacklist.");
            }
            filter = filter.substring(1);
        }
    
public static voidverifyUrl(java.lang.String url)
Checks if the specified URL is valid.

param
url URL to verify
throws
IllegalArgumentException if the URL is malformed


                            
         
        BluetoothUrl btUrl = new BluetoothUrl(url);
        if ((btUrl.encrypt || btUrl.authorize) && !btUrl.authenticate) {
            throw new IllegalArgumentException(
                    "'authenticate=true' parameter is required.");
        }