FileDocCategorySizeDatePackage
RemoteDevice.javaAPI DocphoneME MR2 API (J2ME)6600Wed May 02 18:00:30 BST 2007javax.bluetooth

RemoteDevice

public class RemoteDevice extends Object
This class is defined by the JSR-82 specification Java™ APIs for Bluetooth™ Wireless Technology, Version 1.1.

Fields Summary
private long
l_address
private String
s_address
private String
friendlyName
Constructors Summary
protected RemoteDevice(String address)

        if (address == null) {
            throw new NullPointerException("null address");
        }
        final String errorMsg = "Malformed address: " + address;

        if (address.length() != 12) {
            throw new IllegalArgumentException(errorMsg);
        }

        if (address.startsWith("-")) {
            throw new IllegalArgumentException(errorMsg);
        }

        try {
            l_address = Long.parseLong(address, 16);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(errorMsg);
        }

        // should be upper case only
        address = address.toUpperCase();

        try {
            String lAddr = LocalDevice.getLocalDevice().getBluetoothAddress();

            if (address.equals(lAddr)) {
                throw new IllegalArgumentException(
                        "Can't use the local address.");
            }
        } catch (BluetoothStateException e) {
            throw new RuntimeException("Can't initialize bluetooth support");
        }
        s_address = address;
    
Methods Summary
public booleanauthenticate()

        if (!BCC.getInstance().isConnected(getBluetoothAddress())) {
            throw new IOException("There are no open connections between the " +
                    "local device and this RemoteDevice.");
        }

        return BCC.getInstance().authenticate(getBluetoothAddress());
    
public booleanauthorize(javax.microedition.io.Connection conn)

        BluetoothConnection btconn = BluetoothConnection.getConnection(conn);

        if (!equals(btconn.getRemoteDevice())) {
            throw new IllegalArgumentException("The specified connection " +
                    "is not a connection to this RemoteDevice.");
        }
        if (!btconn.isServerSide()) {
            throw new IllegalArgumentException("The local device is client " +
                    "rather than the server for the specified connection.");
        }

        return authenticate() && (isTrustedDevice() || btconn.isAuthorized() ||
                btconn.authorize());
    
public booleanencrypt(javax.microedition.io.Connection conn, boolean on)

        BluetoothConnection btconn = BluetoothConnection.getConnection(conn);
        if (!equals(btconn.getRemoteDevice())) {
            throw new IllegalArgumentException("The specified connection " +
                    "is not a connection to this RemoteDevice.");
        }
        if (on && !authenticate()) {
            return false;
        }
        return btconn.encrypt(on);
    
public booleanequals(java.lang.Object obj)

        return obj instanceof RemoteDevice &&
                l_address == ((RemoteDevice) obj).l_address;
    
public final java.lang.StringgetBluetoothAddress()

        return s_address;
    
public java.lang.StringgetFriendlyName(boolean alwaysAsk)

        // contact the remote device if name is not known or alwaysAsk is true
        if (friendlyName == null || alwaysAsk) {
            friendlyName = BCC.getInstance().getFriendlyName(
                    getBluetoothAddress());
        }
        return friendlyName;
    
public static javax.bluetooth.RemoteDevicegetRemoteDevice(javax.microedition.io.Connection conn)

        return BluetoothConnection.getConnection(conn).getRemoteDevice();
    
public inthashCode()

        return (int) ((l_address >>> 24) ^ (l_address & 0xffffffL));
    
public booleanisAuthenticated()

        return BCC.getInstance().isAuthenticated(getBluetoothAddress());
    
public booleanisAuthorized(javax.microedition.io.Connection conn)

        BluetoothConnection btconn = BluetoothConnection.getConnection(conn);
        RemoteDevice device;

        try {
            device = btconn.getRemoteDevice();
        } catch (IllegalArgumentException e) {
            return false;
        }
        if (!equals(device)) {
            throw new IllegalArgumentException("The specified connection " +
                    "is not a connection to this RemoteDevice.");
        }

        return btconn.isServerSide() && btconn.isAuthorized();
    
public booleanisEncrypted()

        return BCC.getInstance().isEncrypted(getBluetoothAddress());
    
public booleanisTrustedDevice()

        return BCC.getInstance().isTrusted(getBluetoothAddress());