Source Code Cross Referenced for Protocol.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » io » j2me » btl2cap » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.midp.io.j2me.btl2cap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.midp.io.j2me.btl2cap;
028:
029:        import java.io.IOException;
030:        import javax.microedition.io.Connection;
031:        import javax.bluetooth.L2CAPConnection;
032:        import javax.bluetooth.BluetoothConnectionException;
033:
034:        import com.sun.midp.io.BluetoothUrl;
035:        import com.sun.midp.io.BluetoothProtocol;
036:        import com.sun.midp.security.Permissions;
037:        import com.sun.midp.security.SecurityToken;
038:        import com.sun.midp.main.Configuration;
039:
040:        /**
041:         * Provides "btl2cap" protocol implementation
042:         */
043:        public class Protocol extends BluetoothProtocol {
044:            /** Keeps maximum MTU supported by the BT stack. */
045:            static final int MAX_STACK_MTU;
046:
047:            static {
048:                int maxReceiveMTU;
049:                try {
050:                    maxReceiveMTU = Integer.parseInt(System
051:                            .getProperty("bluetooth.l2cap.receiveMTU.max"));
052:                } catch (NumberFormatException e) {
053:                    maxReceiveMTU = L2CAPConnection.DEFAULT_MTU;
054:                }
055:                MAX_STACK_MTU = maxReceiveMTU;
056:            }
057:
058:            /**
059:             * Constructs an instance.
060:             */
061:            public Protocol() {
062:                super (BluetoothUrl.L2CAP);
063:            }
064:
065:            /**
066:             * Cheks permissions and opens requested connection.
067:             *
068:             * @param token security token passed by calling class
069:             * @param url <code>BluetoothUrl</code> instance that defines required 
070:             *        connection stringname the URL without protocol name and colon
071:             * @param mode Connector.READ_WRITE or Connector.READ or Connector.WRITE
072:             *
073:             * @return a notifier in case of server connection string, open connection
074:             * in case of client one.
075:             *
076:             * @exception IOException if opening connection fails.
077:             */
078:            public Connection openPrim(Object token, BluetoothUrl url, int mode)
079:                    throws IOException {
080:                return openPrimImpl(token, url, mode);
081:            }
082:
083:            /** 
084:             * Ensures URL parameters have valid values. Sets receiveMTU if undefined.
085:             * @param url URL to check
086:             * @exception IllegalArgumentException if invalid url parameters found
087:             * @exception BluetoothConnectionException if url parameters are not 
088:             *            acceptable due to Bluetooth stack limitations
089:             */
090:            protected void checkUrl(BluetoothUrl url)
091:                    throws IllegalArgumentException,
092:                    BluetoothConnectionException {
093:
094:                if (url.receiveMTU == -1) {
095:                    url.receiveMTU = L2CAPConnection.DEFAULT_MTU;
096:                }
097:
098:                if (url.isSystem()) {
099:                    return;
100:                }
101:
102:                super .checkUrl(url);
103:
104:                if (!url.isServer
105:                        && (url.port <= 0x1000 || url.port >= 0xffff
106:                                || ((url.port & 1) != 1) || ((url.port & 0x100) != 0))) {
107:                    throw new IllegalArgumentException("Invalid PSM: "
108:                            + url.port);
109:                }
110:
111:                // IMPL_NOTE BluetoothConnectionException should be thrown here
112:                // It is temporary substituted by IllegalArgumentException 
113:                // to pass TCK succesfully. To be changed back when fixed
114:                // TCK arrives. The erroneous TCK test is 
115:                // javasoft.sqe.tests.api.javax.bluetooth.Connector.L2Cap.
116:                //                             openClientTests.L2Cap1014()
117:                //
118:                // Correct code here is
119:                // throw new BluetoothConnectionException(
120:                //    BluetoothConnectionException.UNACCEPTABLE_PARAMS,
121:                //    <message>);
122:                if (url.receiveMTU < L2CAPConnection.MINIMUM_MTU) {
123:                    throw new IllegalArgumentException(
124:                            "Receive MTU is too small");
125:                }
126:
127:                if (url.receiveMTU > MAX_STACK_MTU) {
128:                    throw new IllegalArgumentException(
129:                            "Receive MTU is too large");
130:                }
131:
132:                if (url.transmitMTU != -1 && url.transmitMTU > MAX_STACK_MTU) {
133:                    throw new BluetoothConnectionException(
134:                            BluetoothConnectionException.UNACCEPTABLE_PARAMS,
135:                            "Transmit MTU is too large");
136:                }
137:            }
138:
139:            /**
140:             * Ensures that permissions are proper and creates client side connection.
141:             * @param token security token if passed by caller, or <code>null</code>
142:             * @param mode       I/O access mode
143:             * @return proper <code>L2CAPConnectionImpl</code> instance
144:             * @exception IOException if openning connection fails.
145:             */
146:            protected Connection clientConnection(SecurityToken token, int mode)
147:                    throws IOException {
148:                checkForPermission(token, Permissions.BLUETOOTH_CLIENT);
149:                return new L2CAPConnectionImpl(url, mode);
150:            }
151:
152:            /**
153:             * Ensures that permissions are proper and creates required notifier at 
154:             * server side.
155:             * @param token security token if passed by caller, or <code>null</code>
156:             * @param mode       I/O access mode
157:             * @return proper <code>L2CAPNotifierImpl</code> instance
158:             * @exception IOException if openning connection fails
159:             */
160:            protected Connection serverConnection(SecurityToken token, int mode)
161:                    throws IOException {
162:                checkForPermission(token, Permissions.BLUETOOTH_SERVER);
163:                return new L2CAPNotifierImpl(url, mode);
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.