1 22 package javax.activation; 23 24 import java.awt.datatransfer.DataFlavor ; 26 import java.awt.datatransfer.UnsupportedFlavorException ; 27 import java.io.OutputStream ; 28 import java.io.IOException ; 29 30 35 class DataSourceDataContentHandler 36 implements DataContentHandler 37 { 38 39 43 46 private DataSource source; 47 48 51 private DataFlavor [] transferFlavors; 52 53 56 private DataContentHandler handler; 57 58 59 63 68 public DataSourceDataContentHandler(DataContentHandler handler, 69 DataSource source) 70 { 71 this.handler = handler; 72 this.source = source; 73 } 74 75 76 80 84 public DataFlavor [] getTransferDataFlavors() 85 { 86 if (transferFlavors==null) 87 { 88 if (handler!=null) 89 transferFlavors = handler.getTransferDataFlavors(); 90 else 91 { 92 transferFlavors = new DataFlavor [1]; 93 String mimeType = source.getContentType(); 94 transferFlavors[0] = new ActivationDataFlavor (mimeType, mimeType); 95 } 96 } 97 return transferFlavors; 98 } 99 100 107 public Object getTransferData(DataFlavor flavor, DataSource source) 108 throws UnsupportedFlavorException , IOException 109 { 110 if (handler!=null) 111 return handler.getTransferData(flavor, source); 112 getTransferDataFlavors(); 113 if (flavor.equals(transferFlavors[0])) 114 return source.getInputStream(); 115 else 116 throw new UnsupportedFlavorException (flavor); 117 } 118 119 125 public Object getContent(DataSource source) 126 throws IOException 127 { 128 if (handler!=null) 129 return handler.getContent(source); 130 else 131 return source.getInputStream(); 132 } 133 134 141 public void writeTo(Object object, String mimeType, OutputStream stream) 142 throws IOException 143 { 144 if (handler!=null) 145 handler.writeTo(object, mimeType, stream); 146 else 147 { 148 String sourceMimeType = source.getContentType(); 149 throw new UnsupportedDataTypeException ("No handler for MIME content type: "+sourceMimeType); 150 } 151 } 152 153 } 154 | Popular Tags |