javauis/mmapi_qt/baseline/javasrc/com/nokia/microedition/media/ConnectorDataSource.java
equal
deleted
inserted
replaced
30 * DataSource that uses Connector to create connections and |
30 * DataSource that uses Connector to create connections and |
31 * InputStreams. |
31 * InputStreams. |
32 */ |
32 */ |
33 public class ConnectorDataSource extends InputStreamDataSource |
33 public class ConnectorDataSource extends InputStreamDataSource |
34 { |
34 { |
35 // Connection object. |
|
36 StreamConnection iConnection; |
|
37 |
|
38 /** |
35 /** |
39 * Constructor. |
36 * Constructor. |
40 * @param aLocator Locator to connect. |
37 * @param aLocator Locator to connect. |
41 */ |
38 */ |
42 public ConnectorDataSource(Locator aLocator) |
39 public ConnectorDataSource(Locator aLocator) |
43 throws IOException, MediaException |
40 throws IOException, MediaException |
44 { |
41 { |
|
42 |
45 super(aLocator.getLocatorString()); |
43 super(aLocator.getLocatorString()); |
46 open(); // open iConnection |
44 open(); // open iConnection |
|
45 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"ConnectorDataSource constructor after open()"); |
47 iSourceStream = new InputStreamSourceStream( |
46 iSourceStream = new InputStreamSourceStream( |
48 iConnection.openInputStream()); |
47 iConnection.openInputStream()); |
|
48 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"ConnectorDataSource constructor -"); |
49 } |
49 } |
50 |
50 |
51 /** |
51 /** |
52 * Open connection and initialize |
52 * Open connection and initialize |
53 */ |
53 */ |
61 // derived classes may do additional checks |
61 // derived classes may do additional checks |
62 checkConnection(connection); |
62 checkConnection(connection); |
63 |
63 |
64 // Only StreamConnection is supported |
64 // Only StreamConnection is supported |
65 iConnection = (StreamConnection)connection; |
65 iConnection = (StreamConnection)connection; |
|
66 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"ConnectorDataSource open()"); |
66 } |
67 } |
67 catch (ConnectionNotFoundException cnfe) |
68 catch (ConnectionNotFoundException cnfe) |
68 { |
69 { |
69 // ConnectionNotFoundException extends IOException, |
70 // ConnectionNotFoundException extends IOException, |
70 // we must throw MediaException in this case. |
71 // we must throw MediaException in this case. |
82 { |
83 { |
83 // Returned connection object was not StreamConnection |
84 // Returned connection object was not StreamConnection |
84 // or connection was not supported in checkConnection method. |
85 // or connection was not supported in checkConnection method. |
85 throw new MediaException(cce.getMessage()); |
86 throw new MediaException(cce.getMessage()); |
86 } |
87 } |
|
88 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"ConnectorDataSource open() -"); |
87 } |
89 } |
88 |
90 |
89 /** |
91 /** |
90 * from DataSource |
92 * from DataSource |
91 * Connect to the stream |
93 * Connect to the stream |
98 if (iConnection == null) |
100 if (iConnection == null) |
99 { |
101 { |
100 try |
102 try |
101 { |
103 { |
102 open(); |
104 open(); |
|
105 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"ConnectorDataSource connect() after open()"); |
103 iSourceStream.setStream(iConnection.openInputStream()); |
106 iSourceStream.setStream(iConnection.openInputStream()); |
104 } |
107 } |
105 catch (MediaException me) |
108 catch (MediaException me) |
106 { |
109 { |
107 // MediaException cannot be thrown from this method. |
110 // MediaException cannot be thrown from this method. |
108 throw new IOException( |
111 throw new IOException( |
109 "failed to connect to stream, " + me.getMessage()); |
112 "failed to connect to stream, " + me.getMessage()); |
110 } |
113 } |
111 } |
114 } |
|
115 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"ConnectorDataSource connect() -"); |
112 } |
116 } |
113 |
117 |
114 /** |
118 /** |
115 * from DataSource |
119 * from DataSource |
116 * Disconnect from the stream |
120 * Disconnect from the stream |
155 */ |
159 */ |
156 protected void checkConnection(Connection aConnection) throws IOException |
160 protected void checkConnection(Connection aConnection) throws IOException |
157 { |
161 { |
158 // This class does not do additional checks. |
162 // This class does not do additional checks. |
159 } |
163 } |
|
164 |
160 } |
165 } |
161 // End of File |
166 // End of File |
162 |
167 |