Source Code Cross Referenced for RemoteDevice.java in  » 6.0-JDK-Modules » j2me » javax » bluetooth » 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 » javax.bluetooth 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Portions Copyright  2000-2007 Sun Microsystems, Inc. All Rights
005:         * Reserved.  Use is subject to license terms.
006:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License version
010:         * 2 only, as published by the Free Software Foundation.
011:         * 
012:         * This program is distributed in the hope that it will be useful, but
013:         * WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * General Public License version 2 for more details (a copy is
016:         * included at /legal/license.txt).
017:         * 
018:         * You should have received a copy of the GNU General Public License
019:         * version 2 along with this work; if not, write to the Free Software
020:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
021:         * 02110-1301 USA
022:         * 
023:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
024:         * Clara, CA 95054 or visit www.sun.com if you need additional
025:         * information or have any questions.
026:         */
027:
028:        /*
029:         * (c) Copyright 2001, 2002 Motorola, Inc.  ALL RIGHTS RESERVED.
030:         */
031:        package javax.bluetooth;
032:
033:        import java.io.IOException;
034:        import javax.microedition.io.Connection;
035:        import com.sun.kvem.jsr082.bluetooth.BluetoothConnection;
036:        import com.sun.kvem.jsr082.bluetooth.BCC;
037:
038:        /**
039:         * This class is defined by the JSR-82 specification
040:         * <em>Java&trade; APIs for Bluetooth&trade; Wireless Technology,
041:         * Version 1.1.</em>
042:         */
043:        // JAVADOC COMMENT ELIDED 
044:        public class RemoteDevice {
045:            // JAVADOC COMMENT ELIDED
046:            private long l_address;
047:
048:            // JAVADOC COMMENT ELIDED
049:            private String s_address;
050:
051:            // JAVADOC COMMENT ELIDED
052:            private String friendlyName;
053:
054:            // JAVADOC COMMENT ELIDED 
055:            protected RemoteDevice(String address) {
056:                if (address == null) {
057:                    throw new NullPointerException("null address");
058:                }
059:                final String errorMsg = "Malformed address: " + address;
060:
061:                if (address.length() != 12) {
062:                    throw new IllegalArgumentException(errorMsg);
063:                }
064:
065:                if (address.startsWith("-")) {
066:                    throw new IllegalArgumentException(errorMsg);
067:                }
068:
069:                try {
070:                    l_address = Long.parseLong(address, 16);
071:                } catch (NumberFormatException e) {
072:                    throw new IllegalArgumentException(errorMsg);
073:                }
074:
075:                // should be upper case only
076:                address = address.toUpperCase();
077:
078:                try {
079:                    String lAddr = LocalDevice.getLocalDevice()
080:                            .getBluetoothAddress();
081:
082:                    if (address.equals(lAddr)) {
083:                        throw new IllegalArgumentException(
084:                                "Can't use the local address.");
085:                    }
086:                } catch (BluetoothStateException e) {
087:                    throw new RuntimeException(
088:                            "Can't initialize bluetooth support");
089:                }
090:                s_address = address;
091:            }
092:
093:            // JAVADOC COMMENT ELIDED 
094:            public boolean isTrustedDevice() {
095:                return BCC.getInstance().isTrusted(getBluetoothAddress());
096:            }
097:
098:            // JAVADOC COMMENT ELIDED 
099:            public String getFriendlyName(boolean alwaysAsk) throws IOException {
100:                // contact the remote device if name is not known or alwaysAsk is true
101:                if (friendlyName == null || alwaysAsk) {
102:                    friendlyName = BCC.getInstance().getFriendlyName(
103:                            getBluetoothAddress());
104:                }
105:                return friendlyName;
106:            }
107:
108:            // JAVADOC COMMENT ELIDED 
109:            public final String getBluetoothAddress() {
110:                return s_address;
111:            }
112:
113:            // JAVADOC COMMENT ELIDED 
114:            public boolean equals(Object obj) {
115:                return obj instanceof  RemoteDevice
116:                        && l_address == ((RemoteDevice) obj).l_address;
117:            }
118:
119:            // JAVADOC COMMENT ELIDED 
120:            public int hashCode() {
121:                return (int) ((l_address >>> 24) ^ (l_address & 0xffffffL));
122:            }
123:
124:            // JAVADOC COMMENT ELIDED 
125:            public static RemoteDevice getRemoteDevice(Connection conn)
126:                    throws IOException {
127:                return BluetoothConnection.getConnection(conn)
128:                        .getRemoteDevice();
129:            }
130:
131:            // JAVADOC COMMENT ELIDED 
132:            public boolean authenticate() throws IOException {
133:                if (!BCC.getInstance().isConnected(getBluetoothAddress())) {
134:                    throw new IOException(
135:                            "There are no open connections between the "
136:                                    + "local device and this RemoteDevice.");
137:                }
138:
139:                return BCC.getInstance().authenticate(getBluetoothAddress());
140:            }
141:
142:            // JAVADOC COMMENT ELIDED 
143:            public boolean authorize(Connection conn) throws IOException {
144:                BluetoothConnection btconn = BluetoothConnection
145:                        .getConnection(conn);
146:
147:                if (!equals(btconn.getRemoteDevice())) {
148:                    throw new IllegalArgumentException(
149:                            "The specified connection "
150:                                    + "is not a connection to this RemoteDevice.");
151:                }
152:                if (!btconn.isServerSide()) {
153:                    throw new IllegalArgumentException(
154:                            "The local device is client "
155:                                    + "rather than the server for the specified connection.");
156:                }
157:
158:                return authenticate()
159:                        && (isTrustedDevice() || btconn.isAuthorized() || btconn
160:                                .authorize());
161:            }
162:
163:            // JAVADOC COMMENT ELIDED 
164:            public boolean encrypt(Connection conn, boolean on)
165:                    throws IOException {
166:                BluetoothConnection btconn = BluetoothConnection
167:                        .getConnection(conn);
168:                if (!equals(btconn.getRemoteDevice())) {
169:                    throw new IllegalArgumentException(
170:                            "The specified connection "
171:                                    + "is not a connection to this RemoteDevice.");
172:                }
173:                if (on && !authenticate()) {
174:                    return false;
175:                }
176:                return btconn.encrypt(on);
177:            }
178:
179:            // JAVADOC COMMENT ELIDED 
180:            public boolean isAuthenticated() {
181:                return BCC.getInstance().isAuthenticated(getBluetoothAddress());
182:            }
183:
184:            // JAVADOC COMMENT ELIDED 
185:            public boolean isAuthorized(Connection conn) throws IOException {
186:                BluetoothConnection btconn = BluetoothConnection
187:                        .getConnection(conn);
188:                RemoteDevice device;
189:
190:                try {
191:                    device = btconn.getRemoteDevice();
192:                } catch (IllegalArgumentException e) {
193:                    return false;
194:                }
195:                if (!equals(device)) {
196:                    throw new IllegalArgumentException(
197:                            "The specified connection "
198:                                    + "is not a connection to this RemoteDevice.");
199:                }
200:
201:                return btconn.isServerSide() && btconn.isAuthorized();
202:            }
203:
204:            // JAVADOC COMMENT ELIDED
205:            public boolean isEncrypted() {
206:                return BCC.getInstance().isEncrypted(getBluetoothAddress());
207:            }
208:        } // end of class 'RemoteDevice' definition
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.