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

Ian Grigg iang@cypherpunks.ai
Sun, 17 Sep 2000 15:40:09 -0400 (AST)


iang        00/09/17 15:40:09

  Modified:    webfunds/utils DirClassLoader.java VersionNumbers.java
  Log:
  A bit more debugging to see what was going on, and managed to get
  DirClassLoader up and working with external wallets, as per design.
  Not well tested yet, but seems to work.  Debugging still enabled.

Revision  Changes    Path
1.4       +57 -15    java/webfunds/utils/DirClassLoader.java

Index: DirClassLoader.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/utils/DirClassLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DirClassLoader.java	1999/11/21 01:53:26	1.3
+++ DirClassLoader.java	2000/09/17 19:40:08	1.4
@@ -1,5 +1,5 @@
 /*
- * $Id: DirClassLoader.java,v 1.3 1999/11/21 01:53:26 iang Exp $
+ * $Id: DirClassLoader.java,v 1.4 2000/09/17 19:40:08 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -14,6 +14,9 @@
 import java.util.Hashtable;
 
 
+/**
+ *  A Directory-based class loader for plugins and wallets.
+ */
 public class DirClassLoader
     extends ClassLoader
 {
@@ -21,20 +24,28 @@
     Hashtable sysClasses = new Hashtable();
     File dir;
 
+    protected void logmsg(String s) { System.err.println("    DCL " + s); }
+
     /**
-     * Call this with "webfunds" and "sun" for example to block
-     * the mixing of those classes.  Hmmm.  Is this right?
+     *  Loader to allow dynamic loading from directory dir, and having
+     *  access to all classes within systemClasses.
+     * 
+     *  As used in WebFunds, the wallet directory containing the compiled
+     *  classes (for example ../classes) is passed as dir.  Then, the names
+     *  of the WebFunds' other hierarchies is passed as systemClasses,
+     *  so that the rest of WebFunds might be made available to the
+     *  plugged-in wallet.
      * 
-     * @param dir the location of the non-system classes
-     * @param systemClasses a list of hierarchies that are system, not plugin.
-     *        Note that "java" is added by default
+     *  @param dir the location of the classes that this Loader is plugging in.
+     *  @param systemClasses a list of hierarchies that are system, not plugin.
+     *         (Note that "java" is added by default)
      */
     public DirClassLoader(String dir, String[] systemClasses)
         throws FileNotFoundException
     {
         super();
 
-        System.err.println("checking " + dir);
+        logmsg(" checking " + dir);
         File f = new File(dir);
         if (!f.exists())
             throw new FileNotFoundException("dir not found: " + dir);
@@ -53,7 +64,7 @@
     protected byte[] loadClassData(String name)
         throws ClassNotFoundException
     {
-        System.err.println("loading " + name);
+        logmsg(" loading " + name);
         byte[] buf = name.getBytes();
         String sepString = System.getProperty("file.separator");
         byte sep = sepString.getBytes()[0];
@@ -64,7 +75,7 @@
 
         File f = new File(dir, name + ".class");
 
-        System.err.println("reading " + f);
+        logmsg(" reading " + f);
         if (!f.exists())
             throw new ClassNotFoundException("file not found: " + name);
         if (!f.canRead())
@@ -89,10 +100,16 @@
             throw new ClassNotFoundException("IOEx on " + name + ": " + ex);
         }
 
-        System.err.println("found " + classData.length + " bytes");
+        logmsg("found " + classData.length + " bytes");
         return classData ;
     }
 
+    /**
+     *  To load an actual class in dir (above), call loadClass with
+     *  the dot-separated name of the class.
+     *
+     *  @param name is the class name to be loaded (com.my.plugin)
+     */
     public synchronized Class loadClass(String name, boolean resolve)
         throws ClassNotFoundException
     {
@@ -102,7 +119,7 @@
             String base = name.substring(0, name.indexOf("."));
             if (sysClasses.get(base) != null)
             {
-System.err.println("system " + name);
+logmsg("system " + name);
                  cuss = findSystemClass(name);
             }
             else
@@ -110,7 +127,7 @@
                 byte[] data = loadClassData(name);
                 if (data == null || data.length == 0)
                     return null ;
-System.err.println("define " + name);
+logmsg("define " + name);
                 cuss = defineClass(name, data, 0, data.length);
             }
             cache.put(name, cuss);
@@ -124,7 +141,6 @@
     public static void main(String[] args)
         throws Exception
     {
-        args = null; // jikes
         // these are the ones that the WebFunds project knows about
         String[] hierarchies = { "webfunds", "hotlava", "sun" };
 
@@ -132,13 +148,12 @@
         Class cuss = cl.loadClass("test.cp");
         Object obj = cuss.newInstance();
         ExampleClass world = (ExampleClass)obj;
-        world = null; // jikes
 
         ClassLoader cl2 = new DirClassLoader("elsewhere", hierarchies);
         cuss = cl2.loadClass("test.cp");
         obj = cuss.newInstance();
         ExampleClass planet = (ExampleClass)obj;
-        planet = null; // jikes, drop this when below is working.
+
 // I don't understand this.  And it stopped working.
 //        Params params = planet.get();
 //        System.err.println("planet id to world: " + new String(id.getId()));
@@ -146,3 +161,30 @@
 //        world.set(id);
     }
 }
+
+/*
+ * put this file into somewhere/test/cp.java and compile into there.
+
+package test;
+
+import webfunds.sox.AccountId;
+
+public class cp
+    extends webfunds.utils.Plugin
+{
+    static String me = "world";
+    public static void hello() { System.out.println("Hello " + me); }
+    public cp() { System.out.println("hello " + me); }
+    public void set(AccountId id) {  System.out.println("here it is: " + id); }
+
+    public AccountId get()
+    {
+        AccountId id = new AccountId();
+        id.setId(me.getBytes());
+        return id ;
+    }
+}
+
+ * then put the same file in elsewhere/test/cp.java
+ * but change world to planet.
+ */



1.3       +13 -9     java/webfunds/utils/VersionNumbers.java

Index: VersionNumbers.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/utils/VersionNumbers.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- VersionNumbers.java	1999/11/21 01:53:26	1.2
+++ VersionNumbers.java	2000/09/17 19:40:08	1.3
@@ -1,5 +1,5 @@
 /*
- * $Id: VersionNumbers.java,v 1.2 1999/11/21 01:53:26 iang Exp $
+ * $Id: VersionNumbers.java,v 1.3 2000/09/17 19:40:08 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -59,7 +59,7 @@
         String[] list = dir.list();
         if (list == null)
         {
-            logmsg("no plugin directory");
+            logmsg("plugin directory: " + dir + " not present");
             return new String[0] ;
         }
         Vector victor = new Vector();
@@ -69,12 +69,12 @@
         //
         for (int i = 0; i < list.length; i++)
         {
-            String pug = list[i];
-            File pugDir = new File(dir, pug);
+            String product = list[i];
+            File pugDir = new File(dir, product);
 
             if (!pugDir.isDirectory())
                 continue ;
-//logmsg(" dir " + pugDir);
+logmsg(" dir " + product);
 
             //
             //  There is a directory per version within each plugin.
@@ -102,7 +102,7 @@
                     logmsg("no version, skipping " + name);
                     continue ;
                 }
-//logmsg("   "  + name + " gives " + vers);
+logmsg("   "  + name + " gives " + vers);
                 boolean isBetter;
                 try {
                     isBetter = isGreater(vers, thisOne);
@@ -113,22 +113,26 @@
                 }
                 if (isBetter)
                 {
-//logmsg("raising " + name);
+logmsg("      raising " + name);
                     thisOne = vers;
                     thisName = name;
                 }
             }
 
             if (thisName != null)
-                victor.addElement(thisName);
+                victor.addElement(product + File.separator + thisName);
+            else
+                logmsg("    " + dir + " has no version directory?");
         }
 
         int siz = victor.size();
-//logmsg("found " + siz + "!");
+logmsg(" found " + siz + "!");
         String[] found = new String[siz];
         Enumeration e = victor.elements();
         for (int k = 0;  k < siz;  k++)
+{
             found[k] = (String)e.nextElement();
+logmsg("adding ... " + found[k]);}
         if (e.hasMoreElements())
             throw new RuntimeException("more elements in vector");