dblevins 2003/09/03 18:00:02
Modified: specs/activation/src/java/javax/activation DataHandler.java
Log:
Patch: GERONIMO-54
From: Alex Blewitt
The following provides a very simple implementation of DataHandler in
JAF to support MimeMessage's ability to handle simple object types and
text/ types.
Revision Changes Path
1.5 +66 -19
incubator-geronimo/specs/activation/src/java/javax/activation/DataHandler.java
Index: DataHandler.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/specs/activation/src/java/javax/activation/DataHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DataHandler.java 29 Aug 2003 12:45:53 -0000 1.4
+++ DataHandler.java 4 Sep 2003 01:00:02 -0000 1.5
@@ -75,23 +75,70 @@
*/
public class DataHandler implements Transferable {
private DataSource _ds;
-
public DataHandler(DataSource ds) {
_ds = ds;
}
- public DataHandler(Object obj,
- String mimeType) {
- /[EMAIL PROTECTED] implement*/
+ public DataHandler(Object data, String type) {
+ _ds = new ObjectDataSource(data, type);
}
+ static class ObjectDataSource implements DataSource {
+
+ private Object _data;
+ private String _type;
+ public Object getContent() {
+ return _data;
+ }
+ /**
+ * Store an object as a data source type
+ * @param data the object
+ * @param type the mimeType
+ */
+ public ObjectDataSource(Object data, String type) {
+ _data = data;
+ _type = type;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.activation.DataSource#getInputStream()
+ */
+ public InputStream getInputStream() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.activation.DataSource#getOutputStream()
+ */
+ public OutputStream getOutputStream() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.activation.DataSource#getContentType()
+ */
+ public String getContentType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.activation.DataSource#getName()
+ */
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
public DataHandler(URL url) {
/[EMAIL PROTECTED] implement*/
}
public DataSource getDataSource() {
- /[EMAIL PROTECTED] implement*/
- return null;
+ return _ds;
}
public String getName() {
@@ -100,24 +147,19 @@
}
public String getContentType() {
- /[EMAIL PROTECTED] implement*/
- return null;
+ return _ds.getContentType();
}
public InputStream getInputStream() throws IOException {
- /[EMAIL PROTECTED] implement*/
- return null;
-
+ return _ds.getInputStream();
}
public void writeTo(OutputStream os) throws IOException {
- /[EMAIL PROTECTED] implement*/
-
+ // TODO implement
}
public OutputStream getOutputStream() throws IOException {
- /[EMAIL PROTECTED] implement*/
- return null;
+ return _ds.getOutputStream();
}
public synchronized DataFlavor[] getTransferDataFlavors() {
@@ -130,7 +172,8 @@
return false;
}
- public Object getTransferData(DataFlavor flavor) throws
UnsupportedFlavorException, IOException {
+ public Object getTransferData(DataFlavor flavor)
+ throws UnsupportedFlavorException, IOException {
/[EMAIL PROTECTED] implement*/
return null;
}
@@ -155,8 +198,12 @@
}
public Object getContent() throws IOException {
- /[EMAIL PROTECTED] implement*/
- return null;
+ if (_ds instanceof ObjectDataSource) {
+ return ((ObjectDataSource) _ds).getContent();
+ } else {
+ // TODO not yet implemented
+ throw new IOException("TODO Not yet implemented");
+ }
}
public Object getBean(CommandInfo cmdinfo) {