[Nice-commit] Nice/src/nice/tools/code TypeImport.java,1.6,1.7 ClassLoader.java,1.1,1.2
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-07-02 19:31:14
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14796/src/nice/tools/code Modified Files: TypeImport.java ClassLoader.java Log Message: Abstracted the resource location in pathes in the nice.tools.locator package. Index: TypeImport.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/TypeImport.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TypeImport.java 2 Jul 2004 12:12:20 -0000 1.6 --- TypeImport.java 2 Jul 2004 19:31:03 -0000 1.7 *************** *** 179,222 **** currentClasspath = classpath; ! LinkedList components = new LinkedList(); ! ! int start = 0; ! // skip starting separators ! while (start<classpath.length() && ! classpath.charAt(start) == File.pathSeparatorChar) ! start++; ! ! while(start<classpath.length()) ! { ! int end = classpath.indexOf(File.pathSeparatorChar, start); ! if (end == -1) ! end = classpath.length(); ! ! String pathComponent = classpath.substring(start, end); ! if (pathComponent.length() > 0) ! try{ ! File f = nice.tools.util.System.getFile(pathComponent); ! if (f.canRead()) ! components.add(f.getCanonicalFile().toURL()); ! else ! { ! if (!f.exists()) ! User.warning("Classpath component " + pathComponent + " does not exist"); ! else ! User.warning("Classpath component " + pathComponent + " is not readable"); ! } ! } ! catch(java.net.MalformedURLException e){ ! User.warning("Classpath component " + pathComponent + " is invalid"); ! } ! catch(java.io.IOException e){ ! User.warning("Classpath component " + pathComponent + " is invalid"); ! } ! start = end+1; ! } ! classLoader = new java.net.URLClassLoader ! ((URL[]) components.toArray(new URL[components.size()]), ! /* no parent */ null); } } --- 179,193 ---- currentClasspath = classpath; ! URL[] path = nice.tools.locator.dispatch.parsePath ! (classpath, ! new gnu.mapping.Procedure1() { ! public Object apply1(Object o) { ! String message = (String) o; ! User.warning(message); ! return null; ! } ! }); ! classLoader = new java.net.URLClassLoader(path, /* no parent */ null); } } Index: ClassLoader.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/ClassLoader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ClassLoader.java 1 Jul 2004 11:41:41 -0000 1.1 --- ClassLoader.java 2 Jul 2004 19:31:03 -0000 1.2 *************** *** 33,84 **** { this.registrar = registrar; ! this.locations = splitPath(classpath); } public ClassType load(String className) { ! String filesystemName = className.replace('.', File.separatorChar) + ".class"; ! String jarName = className.replace('.', '/') + ".class"; ! ! for (int i = 0; i < locations.length; i++) ! { ! InputStream input = null; ! if (locations[i] instanceof File) ! { ! File dir = (File) locations[i]; ! File file = new File(dir, filesystemName); ! try { ! input = new FileInputStream(file); ! } ! catch(FileNotFoundException ex) { ! } ! } ! else ! { ! JarFile jar = (JarFile) locations[i]; ! JarEntry e = jar.getJarEntry(jarName); ! if (e != null) ! try { ! input = jar.getInputStream(e); ! } ! catch(java.io.IOException ex) { ! } ! } ! if (input != null) ! { ! ClassType res = new ClassType(); ! registrar.register(className, res); ! try { ! new ClassFileInput(res, input); ! return res; ! } ! catch (IOException ex) { ! } ! } ! } ! return null; } --- 33,64 ---- { this.registrar = registrar; ! this.locator = new nice.tools.locator.Locator ! (classpath, ! new gnu.mapping.Procedure1() { ! public Object apply1(Object o) { ! return null; ! } ! }); } public ClassType load(String className) { ! String name = className.replace('.', '/') + ".class"; ! java.net.URLConnection resource = locator.get(name); ! if (resource == null) ! return null; ! try { ! InputStream input = resource.getInputStream(); ! ClassType res = new ClassType(); ! registrar.register(className, res); ! new ClassFileInput(res, input); ! return res; ! } ! catch (IOException ex) { ! return null; ! } } *************** *** 88,94 **** /** where to find compiled packages. */ ! private final Object[] locations; ! /** Map from class names to types. Used to avoid loading several copies of the same class. */ --- 68,74 ---- /** where to find compiled packages. */ ! private final nice.tools.locator.Locator locator; ! /** Map from class names to types. Used to avoid loading several copies of the same class. */ *************** *** 99,140 **** public abstract void register(String className, ClassType type); } - - private static Object[] splitPath (String path) - { - LinkedList res = new LinkedList(); - - int start = 0; - // skip starting separators - while (start < path.length() && - path.charAt(start) == File.pathSeparatorChar) - start++; - - while(start < path.length()) - { - int end = path.indexOf(File.pathSeparatorChar, start); - if (end == -1) - end = path.length(); - - String pathComponent = path.substring(start, end); - if (pathComponent.length() > 0) - { - File f = nice.tools.util.System.getFile(pathComponent); - // Ignore non-existing directories and archives - if (f.exists()) - { - if (pathComponent.endsWith(".jar")) - try{ - res.add(new JarFile(f)); - } - catch(IOException e){} - else - res.add(f); - } - } - start = end + 1; - } - - return res.toArray(new Object[res.size()]); - } - } --- 79,81 ---- |