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.tcpobex;
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.BluetoothConnectionNotifierServiceRecordAccess;
40  import com.intel.bluetooth.BluetoothConsts;
41  import com.intel.bluetooth.MicroeditionConnector;
42  
43  /**
44   * This class is Proxy for tcpobex (OBEX over TCP) Connection implementations
45   * for IBM J9 support.
46   * <p>
47   * You need to configure -Dmicroedition.connection.pkgs=com.intel.bluetooth if
48   * not installing bluecove.jar to "%J9_HOME%\lib\jclMidp20\ext\
49   * <p>
50   * <b><u>Your application should not use this class directly.</u></b>
51   *
52   */
53  public class Connection implements CreateConnection, ClientSession, SessionNotifier,
54  		BluetoothConnectionNotifierServiceRecordAccess {
55  
56  	private javax.microedition.io.Connection impl;
57  
58  	public Connection() {
59  		impl = null;
60  	}
61  
62  	public void setParameters(String spec, int access, boolean timeout) throws IOException {
63  		impl = MicroeditionConnector.open(BluetoothConsts.PROTOCOL_SCHEME_TCP_OBEX + ":" + spec, access, timeout);
64  	}
65  
66  	public javax.microedition.io.Connection setParameters2(String spec, int access, boolean timeout) throws IOException {
67  		setParameters(spec, access, timeout);
68  		return this;
69  	}
70  
71  	public void close() throws IOException {
72  		impl.close();
73  	}
74  
75  	public HeaderSet connect(HeaderSet headers) throws IOException {
76  		return ((ClientSession) impl).connect(headers);
77  	}
78  
79  	public HeaderSet createHeaderSet() {
80  		return ((ClientSession) impl).createHeaderSet();
81  	}
82  
83  	public HeaderSet delete(HeaderSet headers) throws IOException {
84  		return ((ClientSession) impl).delete(headers);
85  	}
86  
87  	public HeaderSet disconnect(HeaderSet headers) throws IOException {
88  		return ((ClientSession) impl).disconnect(headers);
89  	}
90  
91  	public Operation get(HeaderSet headers) throws IOException {
92  		return ((ClientSession) impl).get(headers);
93  	}
94  
95  	public long getConnectionID() {
96  		return ((ClientSession) impl).getConnectionID();
97  	}
98  
99  	public Operation put(HeaderSet headers) throws IOException {
100 		return ((ClientSession) impl).put(headers);
101 	}
102 
103 	public void setAuthenticator(Authenticator auth) {
104 		((ClientSession) impl).setAuthenticator(auth);
105 
106 	}
107 
108 	public void setConnectionID(long id) {
109 		((ClientSession) impl).setConnectionID(id);
110 	}
111 
112 	public HeaderSet setPath(HeaderSet headers, boolean backup, boolean create) throws IOException {
113 		return ((ClientSession) impl).setPath(headers, backup, create);
114 	}
115 
116 	public javax.microedition.io.Connection acceptAndOpen(ServerRequestHandler handler) throws IOException {
117 		return ((SessionNotifier) impl).acceptAndOpen(handler);
118 	}
119 
120 	public javax.microedition.io.Connection acceptAndOpen(ServerRequestHandler handler, Authenticator auth)
121 			throws IOException {
122 		return ((SessionNotifier) impl).acceptAndOpen(handler, auth);
123 	}
124 
125 	/*
126 	 * (non-Javadoc)
127 	 *
128 	 * @see com.intel.bluetooth.BluetoothConnectionNotifierServiceRecordAccess#getServiceRecord()
129 	 */
130 	public ServiceRecord getServiceRecord() {
131 		return ((BluetoothConnectionNotifierServiceRecordAccess) impl).getServiceRecord();
132 	}
133 
134 	/*
135 	 * (non-Javadoc)
136 	 *
137 	 * @see com.intel.bluetooth.BluetoothConnectionNotifierServiceRecordAccess#updateServiceRecord(boolean)
138 	 */
139 	public void updateServiceRecord(boolean acceptAndOpen) throws ServiceRegistrationException {
140 		((BluetoothConnectionNotifierServiceRecordAccess) impl).updateServiceRecord(acceptAndOpen);
141 	}
142 
143 }