110 * section in <em>Java Tutorial</em>. 111 * 112 * @author Blake Sullivan 113 * @author Laurence P. G. Cable 114 * @author Jeff Dunn 115 */ 116 public class DataFlavor implements Externalizable, Cloneable { 117 118 private static final long serialVersionUID = 8367026044764648243L; 119 private static final Class<InputStream> ioInputStreamClass = InputStream.class; 120 121 /** 122 * Tries to load a class from: the bootstrap loader, the system loader, 123 * the context loader (if one is present) and finally the loader specified. 124 * 125 * @param className the name of the class to be loaded 126 * @param fallback the fallback loader 127 * @return the class loaded 128 * @exception ClassNotFoundException if class is not found 129 */ 130 protected final static Class<?> tryToLoadClass(String className, 131 ClassLoader fallback) 132 throws ClassNotFoundException 133 { 134 ReflectUtil.checkPackageAccess(className); 135 try { 136 SecurityManager sm = System.getSecurityManager(); 137 if (sm != null) { 138 sm.checkPermission(new RuntimePermission("getClassLoader")); 139 } 140 ClassLoader loader = ClassLoader.getSystemClassLoader(); 141 try { 142 // bootstrap class loader and system class loader if present 143 return Class.forName(className, true, loader); 144 } 145 catch (ClassNotFoundException exception) { 146 // thread context class loader if and only if present 147 loader = Thread.currentThread().getContextClassLoader(); 148 if (loader != null) { 149 try { 150 return Class.forName(className, true, loader); 151 } 152 catch (ClassNotFoundException e) { 153 // fallback to user's class loader 154 } 155 } 156 } 157 } catch (SecurityException exception) { 158 // ignore secured class loaders 159 } 160 return Class.forName(className, true, fallback); 161 } 162 163 /* 164 * private initializer 165 */ 166 static private DataFlavor createConstant(Class<?> rc, String prn) { 167 try { 168 return new DataFlavor(rc, prn); 169 } catch (Exception e) { 170 return null; 171 } 172 } 173 174 /* 175 * private initializer 176 */ 177 static private DataFlavor createConstant(String mt, String prn) { 178 try { 179 return new DataFlavor(mt, prn); 180 } catch (Exception e) { 181 return null; 182 } 183 } 184 185 /* 186 * private initializer 187 */ 188 static private DataFlavor initHtmlDataFlavor(String htmlFlavorType) { 189 try { 190 return new DataFlavor ("text/html; class=java.lang.String;document=" + 191 htmlFlavorType + ";charset=Unicode"); 192 } catch (Exception e) { 193 return null; 194 } 195 } 196 197 /** 198 * The <code>DataFlavor</code> representing a Java Unicode String class, 199 * where: 200 * <pre> 201 * representationClass = java.lang.String 202 * mimeType = "application/x-java-serialized-object" 203 * </pre> 204 */ 205 public static final DataFlavor stringFlavor = createConstant(java.lang.String.class, "Unicode String"); 206 207 /** 208 * The <code>DataFlavor</code> representing a Java Image class, | 110 * section in <em>Java Tutorial</em>. 111 * 112 * @author Blake Sullivan 113 * @author Laurence P. G. Cable 114 * @author Jeff Dunn 115 */ 116 public class DataFlavor implements Externalizable, Cloneable { 117 118 private static final long serialVersionUID = 8367026044764648243L; 119 private static final Class<InputStream> ioInputStreamClass = InputStream.class; 120 121 /** 122 * Tries to load a class from: the bootstrap loader, the system loader, 123 * the context loader (if one is present) and finally the loader specified. 124 * 125 * @param className the name of the class to be loaded 126 * @param fallback the fallback loader 127 * @return the class loaded 128 * @exception ClassNotFoundException if class is not found 129 */ 130 protected static final Class<?> tryToLoadClass(String className, 131 ClassLoader fallback) 132 throws ClassNotFoundException 133 { 134 ReflectUtil.checkPackageAccess(className); 135 try { 136 SecurityManager sm = System.getSecurityManager(); 137 if (sm != null) { 138 sm.checkPermission(new RuntimePermission("getClassLoader")); 139 } 140 ClassLoader loader = ClassLoader.getSystemClassLoader(); 141 try { 142 // bootstrap class loader and system class loader if present 143 return Class.forName(className, true, loader); 144 } 145 catch (ClassNotFoundException exception) { 146 // thread context class loader if and only if present 147 loader = Thread.currentThread().getContextClassLoader(); 148 if (loader != null) { 149 try { 150 return Class.forName(className, true, loader); 151 } 152 catch (ClassNotFoundException e) { 153 // fallback to user's class loader 154 } 155 } 156 } 157 } catch (SecurityException exception) { 158 // ignore secured class loaders 159 } 160 return Class.forName(className, true, fallback); 161 } 162 163 /* 164 * private initializer 165 */ 166 private static DataFlavor createConstant(Class<?> rc, String prn) { 167 try { 168 return new DataFlavor(rc, prn); 169 } catch (Exception e) { 170 return null; 171 } 172 } 173 174 /* 175 * private initializer 176 */ 177 private static DataFlavor createConstant(String mt, String prn) { 178 try { 179 return new DataFlavor(mt, prn); 180 } catch (Exception e) { 181 return null; 182 } 183 } 184 185 /* 186 * private initializer 187 */ 188 private static DataFlavor initHtmlDataFlavor(String htmlFlavorType) { 189 try { 190 return new DataFlavor ("text/html; class=java.lang.String;document=" + 191 htmlFlavorType + ";charset=Unicode"); 192 } catch (Exception e) { 193 return null; 194 } 195 } 196 197 /** 198 * The <code>DataFlavor</code> representing a Java Unicode String class, 199 * where: 200 * <pre> 201 * representationClass = java.lang.String 202 * mimeType = "application/x-java-serialized-object" 203 * </pre> 204 */ 205 public static final DataFlavor stringFlavor = createConstant(java.lang.String.class, "Unicode String"); 206 207 /** 208 * The <code>DataFlavor</code> representing a Java Image class, |