FileDocCategorySizeDatePackage
LocalDeviceImpl.javaAPI DocphoneME MR2 API (J2ME)9692Wed May 02 18:00:32 BST 2007com.sun.kvem.jsr082.bluetooth

LocalDeviceImpl

public final class LocalDeviceImpl extends Object
The LocalDeviceImpl class is a LocalDevice API class implementation. This is a singleton class.

Fields Summary
private static final boolean
DEBUG
Set to false in RR version - then the javac skip the code.
private static LocalDeviceImpl
instance
Keeps this singleton object.
private String
bluetoothAddress
Keeps bluetooth address of this device.
private CancelerOfLIAC
cancelerOfLIAC
Timeout canceller of limited discoverable mode.
Constructors Summary
private LocalDeviceImpl()
Constructs the only instance of LocalDeviceImpl.

    
Methods Summary
public java.lang.StringgetBluetoothAddress()

        return BCC.getInstance().getBluetoothAddress();
    
public javax.bluetooth.DeviceClassgetDeviceClass()

        return BCC.getInstance().getDeviceClass();
    
public intgetDiscoverable()

        return BCC.getInstance().getAccessCode();
    
public java.lang.StringgetFriendlyName()

        return BCC.getInstance().getFriendlyName();
    
public static synchronized com.sun.kvem.jsr082.bluetooth.LocalDeviceImplgetInstance()
Retrieves singleton instance.

return
the only instance of LocalDeviceImpl
throws
BluetoothStateException if an error occured.

        if (instance == null) {
            instance = new LocalDeviceImpl();
        }
        return instance;
    
public java.lang.StringgetProperty(java.lang.String property)

        return System.getProperty(property);
    
public javax.bluetooth.ServiceRecordgetRecord(javax.microedition.io.Connection notifier)

        if (notifier == null) {
            throw new NullPointerException("Null notifier specified.");
        }
        if (!(notifier instanceof BluetoothNotifier)) {
            if (!(notifier instanceof SessionNotifierImpl)) {
                throw new IllegalArgumentException("Invalid notifier class.");
            }
            Connection transport =
                ((SessionNotifierImpl)notifier).getTransport();
            if (!(transport instanceof BluetoothNotifier)) {
                throw new IllegalArgumentException("Invalid notifier class.");
            }
            return ((BluetoothNotifier)transport).getServiceRecord();
        }
        return ((BluetoothNotifier)notifier).getServiceRecord();
    
public booleanisPowerOn()
Checks if Bluetooth device is turned on.

return
true is the Bluetooth device is on, false otherwise.

        return BCC.getInstance().isBluetoothEnabled();
    
public booleansetDiscoverable(int accessCode)

        // Check if the specified mode has a valid value
        if (accessCode != DiscoveryAgent.GIAC &&
                accessCode != DiscoveryAgent.LIAC &&
                accessCode != DiscoveryAgent.NOT_DISCOVERABLE &&
                (accessCode < 0x9E8B00 || accessCode > 0x9E8B3F)) {
            throw new IllegalArgumentException("Access code is out of range: "
                    + "0x" + Integer.toHexString(accessCode).toUpperCase());
        }
        synchronized (cancelerOfLIAC) {
            /*
             * Accroding to the spec, the device should only be limited
             * discoverable (DiscoveryAgent.LIAC) for 1 minute -
             * then back to the PREVIOUS discoverable mode.
             */
            int oldAccessCode = BCC.getInstance().getAccessCode();
            if (BCC.getInstance().setAccessCode(accessCode)) {
                cancelerOfLIAC.notifyNewAccessCode(oldAccessCode, accessCode);
                if (accessCode != DiscoveryAgent.NOT_DISCOVERABLE) {
                    // Start SDDB if discoverable mode was set successfully
                    // IMPL_NOTE: Do we really need this step?
                    SDDB.getInstance();
                }
                return true;
            }
        }
        return false;
    
public voidupdateRecord(javax.bluetooth.ServiceRecord srvRecord)

        if (DEBUG) {
            System.out.println("LocalDeviceImpl.updateRecord");
        }
        if (srvRecord == null) {
            throw new NullPointerException("Null record specified.");
        }
        if (!(srvRecord instanceof ServiceRecordImpl)) {
            throw new IllegalArgumentException("Invalid service record class.");
        }
        ServiceRecordImpl record = (ServiceRecordImpl)srvRecord;
        BluetoothNotifier notifier = record.getNotifier();
        if (notifier == null) {
            throw new IllegalArgumentException(
                    "Service record is not from local SDDB.");
        }
        notifier.updateServiceRecord(record);