01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package com.sun.midp.io.j2me.btspp;
27:
28: import java.io.IOException;
29: import com.sun.midp.io.BluetoothUrl;
30: import com.sun.midp.io.BluetoothProtocol;
31: import javax.microedition.io.Connection;
32: import javax.bluetooth.BluetoothConnectionException;
33: import com.sun.midp.security.SecurityToken;
34: import com.sun.midp.security.Permissions;
35:
36: /**
37: * Provides 'btspp' protocol support.
38: */
39: public class Protocol extends BluetoothProtocol {
40: /**
41: * Constructs an instance.
42: */
43: public Protocol() {
44: super (BluetoothUrl.RFCOMM);
45: }
46:
47: /**
48: * Ensures URL parameters have valid values.
49: * @param url URL to check
50: * @exception IllegalArgumentException if invalid url parameters found
51: */
52: protected void checkUrl(BluetoothUrl url)
53: throws IllegalArgumentException,
54: BluetoothConnectionException {
55: super .checkUrl(url);
56:
57: if (!url.isServer && (url.port < 1 || url.port > 30)) {
58: throw new IllegalArgumentException("Invalid channel: "
59: + url.port);
60: }
61: }
62:
63: /**
64: * Ensures that permissions are proper and creates client side connection.
65: * @param token security token if passed by caller, or <code>null</code>
66: * @param mode I/O access mode
67: * @return proper <code>BTSPPConnectionImpl</code> instance
68: * @exception IOException if openning connection fails.
69: */
70: protected Connection clientConnection(SecurityToken token, int mode)
71: throws IOException {
72: checkForPermission(token, Permissions.BLUETOOTH_CLIENT);
73: return new BTSPPConnectionImpl(url, mode);
74: }
75:
76: /**
77: * Ensures that permissions are proper and creates required notifier at
78: * server side.
79: * @param token security token if passed by caller, or <code>null</code>
80: * @param mode I/O access mode
81: * @return proper <code>BTSPPNotifierImpl</code> instance
82: * @exception IOException if openning connection fails
83: */
84: protected Connection serverConnection(SecurityToken token, int mode)
85: throws IOException {
86: checkForPermission(token, Permissions.BLUETOOTH_SERVER);
87: return new BTSPPNotifierImpl(url, mode);
88: }
89: }
|