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

JavaBCC

public class JavaBCC extends BCC
Java-based Bluetooth Control Center.

Fields Summary
private Hashtable
piconet
Hashtable of PicoNodes.
private int
accessCode
Inquiry access code for the local device.
private int
deviceClassBase
Device class without service classes.
private DeviceClass
deviceClass
Device class and service classes of the local device.
private boolean
isBluetoothEnabled
Identifies weither the Bluetooth device is on.
private String
friendlyName
The friendly name for the device.
private String
passKey
Pass key for the device.
Constructors Summary
protected JavaBCC()
Constructs an instance.


    
        
      
        loadPropertyValues();
        deviceClass = new DeviceClass(deviceClassBase);
    
Methods Summary
public voidaddConnection(java.lang.String address)
Registers a new connection to a remote device.

param
address the Bluetooth address of the remote device

        PicoNode pico = (PicoNode)piconet.get(address);
        if (pico == null) {
            piconet.put(address, pico = new PicoNode());
        }
        pico.connections++;
    
public booleanauthenticate(java.lang.String address)
Authenticates remote device.

param
address Bluetooth address of a remote device
return
true if the device was authenticated, false otherwise

        PicoNode pico = (PicoNode)piconet.get(address);
        if (pico == null) {
            return false;
        }
        pico.authenticated = true;
        return true;
    
public booleanauthorize(java.lang.String address, int handle)
Authorizes a Bluetooth connection.

param
address the Bluetooth address of the remote device
param
handle handle for the service record of the srvice the remote device is trying to access
return
true if authorization succeeded, false otherwise

        return true;
    
public booleanbond(java.lang.String address, java.lang.String pin)
Initiates pairing with a remote device.

param
address the Bluetooth address of the device with which to pair
param
pin an array containing the PIN code
return
true if the device was authenticated, false otherwise

        return true;
    
public booleanenableBluetooth()
Enables Bluetooth radio and the Bluetooth protocol stack for use.

return
true if the operation succeeded, false otherwise

        isBluetoothEnabled = true;
        return true;
    
public booleanencrypt(java.lang.String address, boolean enable)

        return false;
    
public intgetAccessCode()

        return accessCode;
    
public java.lang.StringgetBluetoothAddress()
Returns local Bluetooth address.

return
local Bluetooth address

        return com.sun.midp.jsr082.BluetoothUtils.getAddressString(
            DeviceEmul.getLocalDeviceEmul().getAddress());
    
public intgetConnectionCount(java.lang.String address)
Returns the number of connections to the remote device.

param
address the Bluetooth address of the remote device
return
number of connections established with the remote device

        PicoNode pico = (PicoNode)piconet.get(address);
        return pico != null ? pico.connections : 0;
    
public DeviceClassgetDeviceClass()

        return deviceClass;
    
public java.lang.StringgetFriendlyName()
Returns user-friendly name for the local device.

return
User-friendly name for the local device, or null if the name could not be retrieved

        return friendlyName;
    
public java.lang.StringgetFriendlyName(java.lang.String address)
Retrieves the user-friendly name for specified remote device.

param
address Bluetooth address of a remote device
return
name of the remote device, or null if the name could not be retrieved

        return address;
    
private static booleangetInternalBooleanProperty(java.lang.String key, boolean def)
Gets the internal property indicated by the specified key as an boolean or returns the specified default value if property reading failed.

param
key the name of the internal property.
param
def the default value for the property if there is no property with the key.
return
the boolean value of the internal property or def if there is no property with that key or the value is not valid.
exception
NullPointerException if key is null.
exception
IllegalArgumentException if key is empty.

        // Implicitly throw NPE if key is null
        if (key.length() ==  0) {
            throw new IllegalArgumentException("Key cannot be empty");
        }

        boolean val = def;
        String prop = Configuration.getProperty(key);
        if (prop != null) {
            if (prop.equalsIgnoreCase("true") || 
                prop.equalsIgnoreCase("yes")) {
                val = true;
            } else if (prop.equalsIgnoreCase("false") ||
                       prop.equalsIgnoreCase("no")) {
                val = false;
            }
        }
        return val;
    
private static intgetInternalIntProperty(java.lang.String key, int radix, int def)
Gets the internal property indicated by the specified key as an int in the specified radix or returns the specified default value if property reading failed.

param
key the name of the internal property.
param
radix the radix to be used.
param
def the default value for the property if there is no property with the key.
return
the integer value of the internal property or def if there is no property with that key or the value is not valid.
exception
NullPointerException if key is null.
exception
IllegalArgumentException if key is empty.

        // Implicitly throws NPE if key is null
        if (key.length() ==  0) {
            throw new IllegalArgumentException("Key cannot be empty");
        }

        try {
            String prop = Configuration.getProperty(key);
            return Integer.parseInt(prop, radix);
        } catch (NumberFormatException nfe) {
            return def;
        }
    
private static java.lang.StringgetInternalStringProperty(java.lang.String key, java.lang.String def)
Gets the internal property indicated by the specified key as an String or returns the specified default value if the property is not found.

param
key the name of the internal property.
param
def the default value for the property if there is no property with the key.
return
the String value of the internal property or def if there is no property with that key.
exception
NullPointerException if key is null.
exception
IllegalArgumentException if key is empty.

        // Implicitly throw NPE if key is null
        if (key.length() ==  0) {
            throw new IllegalArgumentException("Key cannot be empty");
        }

        String prop = Configuration.getProperty(key);
        return (prop != null) ? prop : def;
    
public java.lang.StringgetPasskey(java.lang.String address)
Retrieves PIN code to use for pairing with a remote device. If the PIN code is not known, PIN entry dialog is displayed.

param
address the Bluetooth address of the remote device
return
string containing the PIN code

        return passKey;
    
public java.util.VectorgetPreknownDevices()
Returns list of preknown devices in a Vector.

return
Vector object containing preknown devices

        return null;
    
public booleanisAuthenticated(java.lang.String address)
Checks if a remote device was authenticated.

param
address Bluetooth address of a remote device
return
true if the device was authenticated, false otherwise

        return true;
    
public booleanisBluetoothEnabled()
Queries the power state of the Bluetooth device.

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

         return isBluetoothEnabled;
    
public booleanisConnectable()
Checks if the local device is in connectable mode.

return
true if the device is connectable, false otherwise

        return true;
    
public booleanisEncrypted(java.lang.String address)
Checks if connections to a remote are encrypted.

param
address Bluetooth address of a remote device
return
true if connections to the device are encrypted, false otherwise

        return true;
    
public booleanisPaired(java.lang.String address)
Checks if the local device has a bond with a remote device.

param
address Bluetooth address of a remote device
return
true if the two devices were paired, false otherwise

        return true;
    
public booleanisTrusted(java.lang.String address)
Checks if a remote device is trusted (authorized for all services).

param
address Bluetooth address of a remote device
return
true if the device is trusted, false otherwise

        return true;
    
private voidloadPropertyValues()
Extracts initial configuration values from properties.

        // extract the bluetooth device power state
        isBluetoothEnabled = getInternalBooleanProperty("bluetooth.enable",
            isBluetoothEnabled);

        // extract the device friendly name.
        friendlyName = getInternalStringProperty(
            "bluetooth.device.friendlyName", friendlyName);

        // extract the device class.
        deviceClassBase = getInternalIntProperty("bluetooth.device.class", 16,
            deviceClassBase);

        // extract the discoverable mode.
        accessCode = getInternalIntProperty("bluetooth.device.accessCode", 16,
            accessCode);
    
public voidremoveConnection(java.lang.String address)
Unregisters an existing connection to a remote device.

param
address the Bluetooth address of the remote device

        PicoNode pico = (PicoNode)piconet.get(address);
        if (pico.connections == 0) {
            throw new RuntimeException("No open connections for " + address);
        }
        if (--pico.connections == 0) {
            piconet.remove(address);
        }
    
public booleansetAccessCode(int accessCode)

        if (DeviceEmul.getLocalDeviceEmul().updateDiscoverable(accessCode)) {
            this.accessCode = accessCode;
            return true;
        }
        return false;
    
public booleansetServiceClasses(int classes)

        deviceClass = new DeviceClass(deviceClassBase | classes);
        DeviceEmul.getLocalDeviceEmul().updateDeviceClass(deviceClass);
        return true;