From: Erik V. <ev...@us...> - 2009-01-15 20:53:44
|
Update of /cvsroot/rails/18xx/rails/util In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv14080/rails/util Modified Files: ResourceLoader.java Log Message: Fixed code to remove compiler warnings Index: ResourceLoader.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/util/ResourceLoader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ResourceLoader.java 4 Jun 2008 19:00:39 -0000 1.4 --- ResourceLoader.java 15 Jan 2009 20:53:28 -0000 1.5 *************** *** 2,13 **** package rails.util; ! import javax.swing.text.*; ! import javax.swing.text.html.*; ! import java.awt.*; ! import java.net.*; import java.io.*; import java.util.*; ! import java.util.List; ! import java.lang.reflect.*; import org.apache.log4j.Logger; --- 2,14 ---- package rails.util; ! import java.awt.Font; import java.io.*; + import java.lang.reflect.Constructor; + import java.net.Socket; import java.util.*; ! ! import javax.swing.text.*; ! import javax.swing.text.html.HTMLDocument; ! import javax.swing.text.html.HTMLEditorKit; import org.apache.log4j.Logger; *************** *** 16,20 **** * Class ResourceLoader is an utility class to load a resource from a filename * and a list of directory. ! * * @version $Id$ * @author Romain Dolbeau --- 17,21 ---- * Class ResourceLoader is an utility class to load a resource from a filename * and a list of directory. ! * * @version $Id$ * @author Romain Dolbeau *************** *** 27,36 **** * Class ColossusClassLoader allows for class loading outside the CLASSPATH, * i.e. from the various variant directories. ! * * @version $Id$ * @author Romain Dolbeau */ private static class RailsClassLoader extends ClassLoader { ! List directories = null; protected static Logger log = --- 28,37 ---- * Class ColossusClassLoader allows for class loading outside the CLASSPATH, * i.e. from the various variant directories. ! * * @version $Id$ * @author Romain Dolbeau */ private static class RailsClassLoader extends ClassLoader { ! List<String> directories = null; protected static Logger log = *************** *** 45,48 **** --- 46,50 ---- } + @Override public Class<?> findClass(String className) throws ClassNotFoundException { *************** *** 72,76 **** } ! void setDirectories(List d) { directories = d; } --- 74,78 ---- } ! void setDirectories(List<String> d) { directories = d; } *************** *** 109,113 **** /** * Give the String to mark directories. ! * * @return The String to mark directories. */ --- 111,115 ---- /** * Give the String to mark directories. ! * * @return The String to mark directories. */ *************** *** 125,129 **** * Return the first InputStream from file of name filename in the list of * directories, tell the getInputStream not to complain if not found. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). --- 127,131 ---- * Return the first InputStream from file of name filename in the list of * directories, tell the getInputStream not to complain if not found. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). *************** *** 131,135 **** */ public static InputStream getInputStreamIgnoreFail(String filename, ! List directories) { return getInputStream(filename, directories, server != null, false, true); --- 133,137 ---- */ public static InputStream getInputStreamIgnoreFail(String filename, ! List<String> directories) { return getInputStream(filename, directories, server != null, false, true); *************** *** 139,148 **** * Return the first InputStream from file of name filename in the list of * directories. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). * @return The InputStream, or null if it was not found. */ ! public static InputStream getInputStream(String filename, List directories) { return getInputStream(filename, directories, server != null, false, false); --- 141,150 ---- * Return the first InputStream from file of name filename in the list of * directories. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). * @return The InputStream, or null if it was not found. */ ! public static InputStream getInputStream(String filename, List<String> directories) { return getInputStream(filename, directories, server != null, false, false); *************** *** 152,156 **** * Return the first InputStream from file of name filename in the list of * directories. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). --- 154,158 ---- * Return the first InputStream from file of name filename in the list of * directories. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). *************** *** 161,165 **** * @return The InputStream, or null if it was not found. */ ! public static InputStream getInputStream(String filename, List directories, boolean remote, boolean cachedOnly, boolean ignoreFail) { String mapKey = getMapKey(filename, directories); --- 163,167 ---- * @return The InputStream, or null if it was not found. */ ! public static InputStream getInputStream(String filename, List<String> directories, boolean remote, boolean cachedOnly, boolean ignoreFail) { String mapKey = getMapKey(filename, directories); *************** *** 178,182 **** synchronized (fileCache) { InputStream stream = null; ! java.util.Iterator it = directories.iterator(); while (it.hasNext() && (stream == null)) { Object o = it.next(); --- 180,184 ---- synchronized (fileCache) { InputStream stream = null; ! java.util.Iterator<String> it = directories.iterator(); while (it.hasNext() && (stream == null)) { Object o = it.next(); *************** *** 251,257 **** } out.print(filename); ! java.util.Iterator it = directories.iterator(); while (it.hasNext()) { ! out.print(sep + (String) it.next()); } out.println(); --- 253,259 ---- } out.print(filename); ! java.util.Iterator<String> it = directories.iterator(); while (it.hasNext()) { ! out.print(sep + it.next()); } out.println(); *************** *** 277,281 **** /** * Return the content of the specified file as an array of byte. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). --- 279,283 ---- /** * Return the content of the specified file as an array of byte. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). *************** *** 285,289 **** * it fails. */ ! public static byte[] getBytesFromFile(String filename, List directories, boolean cachedOnly, boolean ignoreFail) { InputStream is = --- 287,291 ---- * it fails. */ ! public static byte[] getBytesFromFile(String filename, List<String> directories, boolean cachedOnly, boolean ignoreFail) { InputStream is = *************** *** 305,309 **** /** * Return the content of the specified InputStream as an array of byte. ! * * @param InputStream The InputStream to use. * @return An array of byte representing the content of the InputStream, or --- 307,311 ---- /** * Return the content of the specified InputStream as an array of byte. ! * * @param InputStream The InputStream to use. * @return An array of byte representing the content of the InputStream, or *************** *** 335,339 **** /** * Return the content of the specified byte array as an InputStream. ! * * @param data The byte array to convert. * @return An InputStream whose content is the data byte array. --- 337,341 ---- /** * Return the content of the specified byte array as an InputStream. ! * * @param data The byte array to convert. * @return An InputStream whose content is the data byte array. *************** *** 351,362 **** * Return the first OutputStream from file of name filename in the list of * directories. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). * @return The OutputStream, or null if it was not found. */ ! public static OutputStream getOutputStream(String filename, List directories) { OutputStream stream = null; ! java.util.Iterator it = directories.iterator(); while (it.hasNext() && (stream == null)) { Object o = it.next(); --- 353,364 ---- * Return the first OutputStream from file of name filename in the list of * directories. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). * @return The OutputStream, or null if it was not found. */ ! public static OutputStream getOutputStream(String filename, List<String> directories) { OutputStream stream = null; ! java.util.Iterator<String> it = directories.iterator(); while (it.hasNext() && (stream == null)) { Object o = it.next(); *************** *** 382,391 **** * String describing the content type of the Document. This can currently * load HTML and pure text. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). * @return The Document, or null if it was not found. */ ! public static Document getDocument(String filename, List directories) { InputStream htmlIS = getInputStreamIgnoreFail(filename + ".html", directories); --- 384,393 ---- * String describing the content type of the Document. This can currently * load HTML and pure text. ! * * @param filename Name of the file to load. * @param directories List of directories to search (in order). * @return The Document, or null if it was not found. */ ! public static Document getDocument(String filename, List<String> directories) { InputStream htmlIS = getInputStreamIgnoreFail(filename + ".html", directories); *************** *** 440,444 **** /** * Return the key to use in the image and file caches. ! * * @param filename Name of the file. * @param directories List of directories. --- 442,446 ---- /** * Return the key to use in the image and file caches. ! * * @param filename Name of the file. * @param directories List of directories. *************** *** 446,450 **** * specified file from the specified list of directories. */ ! private static String getMapKey(String filename, List directories) { String[] filenames = new String[1]; filenames[0] = filename; --- 448,452 ---- * specified file from the specified list of directories. */ ! private static String getMapKey(String filename, List<String> directories) { String[] filenames = new String[1]; filenames[0] = filename; *************** *** 454,458 **** /** * Return the key to use in the image cache. ! * * @param filenames Array of name of files. * @param directories List of directories. --- 456,460 ---- /** * Return the key to use in the image cache. ! * * @param filenames Array of name of files. * @param directories List of directories. *************** *** 460,464 **** * specified array of name of files from the specified list of directories. */ ! private static String getMapKey(String[] filenames, List directories) { StringBuffer buf = new StringBuffer(filenames[0]); for (int i = 1; i < filenames.length; i++) { --- 462,466 ---- * specified array of name of files from the specified list of directories. */ ! private static String getMapKey(String[] filenames, List<String> directories) { StringBuffer buf = new StringBuffer(filenames[0]); for (int i = 1; i < filenames.length; i++) { *************** *** 466,470 **** buf.append(filenames[i]); } ! Iterator it = directories.iterator(); while (it.hasNext()) { Object o = it.next(); --- 468,472 ---- buf.append(filenames[i]); } ! Iterator<String> it = directories.iterator(); while (it.hasNext()) { Object o = it.next(); *************** *** 479,483 **** /** * Fix a filename by replacing space with underscore. ! * * @param filename Filename to fix. * @return The fixed filename. --- 481,485 ---- /** * Fix a filename by replacing space with underscore. ! * * @param filename Filename to fix. * @return The fixed filename. *************** *** 489,498 **** /** * Create an instance of the class whose name is in parameter. ! * * @param className The name of the class to use. * @param directories List of directories to search (in order). * @return A new object, instance from the given class. */ ! public static Object getNewObject(String className, List directories) { return getNewObject(className, directories, null); } --- 491,500 ---- /** * Create an instance of the class whose name is in parameter. ! * * @param className The name of the class to use. * @param directories List of directories to search (in order). * @return A new object, instance from the given class. */ ! public static Object getNewObject(String className, List<String> directories) { return getNewObject(className, directories, null); } *************** *** 501,511 **** * Create an instance of the class whose name is in parameter, using * parameters. ! * * If no parameters are given, the default constructor is used. ! * * @TODO this is full of catch(Exception) blocks, which all return null. * Esp. returning null seems a rather bad idea, since it will most likely * turn out to be NPEs somewhere later. ! * * @param className The name of the class to use, must not be null. * @param directories List of directories to search (in order), must not be --- 503,513 ---- * Create an instance of the class whose name is in parameter, using * parameters. ! * * If no parameters are given, the default constructor is used. ! * * @TODO this is full of catch(Exception) blocks, which all return null. * Esp. returning null seems a rather bad idea, since it will most likely * turn out to be NPEs somewhere later. ! * * @param className The name of the class to use, must not be null. * @param directories List of directories to search (in order), must not be *************** *** 516,522 **** * instantiation failed. */ ! public static Object getNewObject(String className, List directories, Object[] parameter) { ! Class theClass = null; cl.setDirectories(directories); try { --- 518,524 ---- * instantiation failed. */ ! public static Object getNewObject(String className, List<String> directories, Object[] parameter) { ! Class<?> theClass = null; cl.setDirectories(directories); try { *************** *** 528,537 **** } if (parameter != null) { ! Class[] paramClasses = new Class[parameter.length]; for (int i = 0; i < parameter.length; i++) { paramClasses[i] = parameter[i].getClass(); } try { ! Constructor c = theClass.getConstructor(paramClasses); return c.newInstance(parameter); } catch (Exception e) { --- 530,539 ---- } if (parameter != null) { ! Class<?>[] paramClasses = new Class[parameter.length]; for (int i = 0; i < parameter.length; i++) { paramClasses[i] = parameter[i].getClass(); } try { ! Constructor<?> c = theClass.getConstructor(paramClasses); return c.newInstance(parameter); } catch (Exception e) { *************** *** 554,563 **** * Force adding the given data as belonging to the given filename in the * file cache. ! * * @param filename Name of the Image file to add. * @param directories List of directories to search (in order). * @param data File content to add. */ ! public static void putIntoFileCache(String filename, List directories, byte[] data) { String mapKey = getMapKey(filename, directories); --- 556,565 ---- * Force adding the given data as belonging to the given filename in the * file cache. ! * * @param filename Name of the Image file to add. * @param directories List of directories to search (in order). * @param data File content to add. */ ! public static void putIntoFileCache(String filename, List<String> directories, byte[] data) { String mapKey = getMapKey(filename, directories); *************** *** 568,572 **** * Force adding the given data as belonging to the given key in the file * cache. ! * * @see #getMapKey(String, List) * @see #getMapKey(String[], List) --- 570,574 ---- * Force adding the given data as belonging to the given key in the file * cache. ! * * @see #getMapKey(String, List) * @see #getMapKey(String[], List) |