View Javadoc

1   /**
2    *  BlueCove - Java library for Bluetooth
3    *  Copyright (C) 2006-2008 Vlad Skarzhevskyy
4    *
5    *  Licensed to the Apache Software Foundation (ASF) under one
6    *  or more contributor license agreements.  See the NOTICE file
7    *  distributed with this work for additional information
8    *  regarding copyright ownership.  The ASF licenses this file
9    *  to you under the Apache License, Version 2.0 (the
10   *  "License"); you may not use this file except in compliance
11   *  with the License.  You may obtain a copy of the License at
12   *
13   *    http://www.apache.org/licenses/LICENSE-2.0
14   *
15   *  Unless required by applicable law or agreed to in writing,
16   *  software distributed under the License is distributed on an
17   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   *  KIND, either express or implied.  See the License for the
19   *  specific language governing permissions and limitations
20   *  under the License.
21   *
22   *  @author vlads
23   *  @version $Id: Connection.java 2476 2008-12-01 17:41:59Z skarzhevskyy $
24   */
25  package com.intel.bluetooth.btgoep;
26  
27  import java.io.IOException;
28  
29  import javax.bluetooth.ServiceRecord;
30  import javax.bluetooth.ServiceRegistrationException;
31  import javax.obex.Authenticator;
32  import javax.obex.ClientSession;
33  import javax.obex.HeaderSet;
34  import javax.obex.Operation;
35  import javax.obex.ServerRequestHandler;
36  import javax.obex.SessionNotifier;
37  
38  import com.ibm.oti.connection.CreateConnection;
39  import com.intel.bluetooth.BluetoothConnectionAccess;
40  import com.intel.bluetooth.BluetoothConnectionAccessAdapter;
41  import com.intel.bluetooth.BluetoothConnectionNotifierServiceRecordAccess;
42  import com.intel.bluetooth.BluetoothConsts;
43  import com.intel.bluetooth.MicroeditionConnector;
44  
45  /**
46   * This class is Proxy for btgoep (OBEX over RFCOMM) Connection implementations
47   * for IBM J9 support
48   * <p>
49   * You need to configure -Dmicroedition.connection.pkgs=com.intel.bluetooth if
50   * not installing bluecove.jar to "%J9_HOME%\lib\jclMidp20\ext\
51   * <p>
52   * <b><u>Your application should not use this class directly.</u></b>
53   *
54   */
55  public class Connection extends BluetoothConnectionAccessAdapter implements CreateConnection, ClientSession,
56  		SessionNotifier, BluetoothConnectionNotifierServiceRecordAccess {
57  
58  	private javax.microedition.io.Connection impl;
59  
60  	public Connection() {
61  		impl = null;
62  	}
63  
64  	public void setParameters(String spec, int access, boolean timeout) throws IOException {
65  		impl = MicroeditionConnector.open(BluetoothConsts.PROTOCOL_SCHEME_BT_OBEX + ":" + spec, access, timeout);
66  	}
67  
68  	public javax.microedition.io.Connection setParameters2(String spec, int access, boolean timeout) throws IOException {
69  		setParameters(spec, access, timeout);
70  		return this;
71  	}
72  
73  	/*
74  	 * (non-Javadoc)
75  	 *
76  	 * @see com.intel.bluetooth.BluetoothConnectionAccessAdapter#getImpl()
77  	 */
78  	protected BluetoothConnectionAccess getImpl() {
79  		return (BluetoothConnectionAccess) impl;
80  	}
81  
82  	public void close() throws IOException {
83  		impl.close();
84  	}
85  
86  	public HeaderSet connect(HeaderSet headers) throws IOException {
87  		return ((ClientSession) impl).connect(headers);
88  	}
89  
90  	public HeaderSet createHeaderSet() {
91  		return ((ClientSession) impl).createHeaderSet();
92  	}
93  
94  	public HeaderSet delete(HeaderSet headers) throws IOException {
95  		return ((ClientSession) impl).delete(headers);
96  	}
97  
98  	public HeaderSet disconnect(HeaderSet headers) throws IOException {
99  		return ((ClientSession) impl).disconnect(headers);
100 	}
101 
102 	public Operation get(HeaderSet headers) throws IOException {
103 		return ((ClientSession) impl).get(headers);
104 	}
105 
106 	public long getConnectionID() {
107 		return ((ClientSession) impl).getConnectionID();
108 	}
109 
110 	public Operation put(HeaderSet headers) throws IOException {
111 		return ((ClientSession) impl).put(headers);
112 	}
113 
114 	public void setAuthenticator(Authenticator auth) {
115 		((ClientSession) impl).setAuthenticator(auth);
116 
117 	}
118 
119 	public void setConnectionID(long id) {
120 		((ClientSession) impl).setConnectionID(id);
121 	}
122 
123 	public HeaderSet setPath(HeaderSet headers, boolean backup, boolean create) throws IOException {
124 		return ((ClientSession) impl).setPath(headers, backup, create);
125 	}
126 
127 	public javax.microedition.io.Connection acceptAndOpen(ServerRequestHandler handler) throws IOException {
128 		return ((SessionNotifier) impl).acceptAndOpen(handler);
129 	}
130 
131 	public javax.microedition.io.Connection acceptAndOpen(ServerRequestHandler handler, Authenticator auth)
132 			throws IOException {
133 		return ((SessionNotifier) impl).acceptAndOpen(handler, auth);
134 	}
135 
136 	/*
137 	 * (non-Javadoc)
138 	 *
139 	 * @see com.intel.bluetooth.BluetoothConnectionNotifierServiceRecordAccess#getServiceRecord()
140 	 */
141 	public ServiceRecord getServiceRecord() {
142 		return ((BluetoothConnectionNotifierServiceRecordAccess) impl).getServiceRecord();
143 	}
144 
145 	/*
146 	 * (non-Javadoc)
147 	 *
148 	 * @see com.intel.bluetooth.BluetoothConnectionNotifierServiceRecordAccess#updateServiceRecord(boolean)
149 	 */
150 	public void updateServiceRecord(boolean acceptAndOpen) throws ServiceRegistrationException {
151 		((BluetoothConnectionNotifierServiceRecordAccess) impl).updateServiceRecord(acceptAndOpen);
152 	}
153 
154 }