[Webfunds-commits] java/webfunds/utils DirClassLoader.java

Ian Grigg iang@cypherpunks.ai
Sat, 30 Sep 2000 14:42:31 -0400 (AST)


iang        00/09/30 14:42:31

  Modified:    webfunds/utils DirClassLoader.java
  Log:
  added constructor for internal wallet

Revision  Changes    Path
1.5       +32 -6     java/webfunds/utils/DirClassLoader.java

Index: DirClassLoader.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/utils/DirClassLoader.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DirClassLoader.java	2000/09/17 19:40:08	1.4
+++ DirClassLoader.java	2000/09/30 18:42:31	1.5
@@ -1,5 +1,5 @@
 /*
- * $Id: DirClassLoader.java,v 1.4 2000/09/17 19:40:08 iang Exp $
+ * $Id: DirClassLoader.java,v 1.5 2000/09/30 18:42:31 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -55,12 +55,35 @@
             throw new FileNotFoundException("dir not readable: " + dir);
 
         this.dir = f;
+        init(systemClasses);
+    }
+
+    /**
+     *  Loader to allow dynamic loading from systemClasses only.
+     *  Compatible with other constructors, but uses Classpath only,
+     *  so non-3rd-party packages can be treated in the same way.
+     * 
+     *  @param systemClasses a list of hierarchies that are system, not plugin.
+     *         (Note that "java" is added by default)
+     */
+    public DirClassLoader(String[] systemClasses)
+    {
+        super();
 
+        this.dir = null;
+
+        init(systemClasses);
+    }
+
+    public void init(String[] systemClasses)
+    {
         sysClasses.put("java", "java");
         for (int i = 0; i < systemClasses.length; i++)
             sysClasses.put(systemClasses[i], systemClasses[i]);
     }
 
+
+
     protected byte[] loadClassData(String name)
         throws ClassNotFoundException
     {
@@ -75,7 +98,7 @@
 
         File f = new File(dir, name + ".class");
 
-        logmsg(" reading " + f);
+        // logmsg(" reading " + f);
         if (!f.exists())
             throw new ClassNotFoundException("file not found: " + name);
         if (!f.canRead())
@@ -100,7 +123,7 @@
             throw new ClassNotFoundException("IOEx on " + name + ": " + ex);
         }
 
-        logmsg("found " + classData.length + " bytes");
+        // logmsg("found " + classData.length + " bytes");
         return classData ;
     }
 
@@ -119,17 +142,20 @@
             String base = name.substring(0, name.indexOf("."));
             if (sysClasses.get(base) != null)
             {
-logmsg("system " + name);
+// logmsg("system " + name);
                  cuss = findSystemClass(name);
             }
-            else
+            else if (dir != null)
             {
                 byte[] data = loadClassData(name);
                 if (data == null || data.length == 0)
                     return null ;
-logmsg("define " + name);
+// logmsg("define " + name);
                 cuss = defineClass(name, data, 0, data.length);
             }
+            else
+                throw new ClassNotFoundException(name + " not in classpath");
+
             cache.put(name, cuss);
         }