[Webfunds-commits] java/webfunds/client/sox SOXWallet.java StoreAccountStore.java

Ian Grigg iang@cypherpunks.ai
Mon, 25 Sep 2000 23:11:48 -0400 (AST)


iang        00/09/25 23:11:48

  Modified:    webfunds/client WalletInterface.java
               webfunds/client/plugins PluginClassLoader.java
                        PluginManager.java WalletManager.java
               webfunds/client/sox SOXWallet.java StoreAccountStore.java
  Log:
  many small patches to get 3rd party wallets working (again)
  (all my testing was for naught, as my CLASSPATH was too helpful :<
   yesterday's patch set is incomplete for 3rd party wallets, today
   needed as well.)

Revision  Changes    Path
1.39      +9 -1      java/webfunds/client/WalletInterface.java

Index: WalletInterface.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/WalletInterface.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- WalletInterface.java	2000/09/24 23:19:09	1.38
+++ WalletInterface.java	2000/09/26 03:11:46	1.39
@@ -1,5 +1,5 @@
 /*
- * $Id: WalletInterface.java,v 1.38 2000/09/24 23:19:09 iang Exp $
+ * $Id: WalletInterface.java,v 1.39 2000/09/26 03:11:46 iang Exp $
  *
  * Copyright (c) 1995-2000 Systemics Ltd on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -65,6 +65,14 @@
      */
     void setWalletContext(WalletContext wm);
     
+    /**
+     *  adminEvent() codes.
+     */
+    public static final int  CODE_SHUTDOWN = 0,  // stop, clean up everything
+                             CODE_FREEZE   = 1,  // to persistant files, backup
+                             CODE_UNFREEZE = 2;  // ok, carry on, backup done
+
+
     /**
      *  Signal the wallet.  For some reason, the application has
      *  decided to conduct some admin, and wishes to freeze or



1.2       +2 -2      java/webfunds/client/plugins/PluginClassLoader.java

Index: PluginClassLoader.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/PluginClassLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PluginClassLoader.java	1999/10/31 17:35:41	1.1
+++ PluginClassLoader.java	2000/09/26 03:11:46	1.2
@@ -1,5 +1,5 @@
 /*
- * $Id: PluginClassLoader.java,v 1.1 1999/10/31 17:35:41 iang Exp $
+ * $Id: PluginClassLoader.java,v 1.2 2000/09/26 03:11:46 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -18,7 +18,7 @@
 class PluginClassLoader
     extends DirClassLoader
 {
-    static String[] hierarchies = { "webfunds", "hotlava", "sun" };
+    static String[] hierarchies = { "webfunds", "javax" };
 
     /**
      * Call this with "webfunds" and "sun" for example to block



1.16      +62 -28    java/webfunds/client/plugins/PluginManager.java

Index: PluginManager.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/PluginManager.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- PluginManager.java	2000/09/24 23:17:02	1.15
+++ PluginManager.java	2000/09/26 03:11:46	1.16
@@ -1,5 +1,5 @@
 /* 
- * $Id: PluginManager.java,v 1.15 2000/09/24 23:17:02 iang Exp $
+ * $Id: PluginManager.java,v 1.16 2000/09/26 03:11:46 iang Exp $
  *
  * Copyright (c) 1995-2000 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -57,14 +57,20 @@
 
         PluginInfo[] array;
         int pugs;
-        Vector wp = getPluginVector(wi);
 
+        //
+        //  The "official" WebFunds plugins.
+        //
         pugs = plugins.size();
         array = new PluginInfo[pugs];
         for (int i = 0; i < pugs; i++)
             array[i] = (PluginInfo)plugins.elementAt(i);
         core.getAccountBrowser(this).setPlugins(array, wi);
 
+        //
+        //  The additional plugins added by the wallet itself.
+        //
+        Vector wp = getPluginVector(wi);
         pugs = wp.size();
         array = new PluginInfo[pugs];
         for (int i = 0; i < pugs; i++)
@@ -139,6 +145,10 @@
         plugins.addElement(pluginfo);
     }
 
+    /**
+     *  Plug in the plugin of this name, must be in the classpath somewhere.
+     *  @except PluginException if failed to instantiate
+     */
     public void addPlugin(String classname,  WalletInterface wi)
         throws PluginException
     {
@@ -157,8 +167,19 @@
             throw new PluginException(e.getMessage());
         }
 
-        plugin.debug(getDebug(), classname + " ");
+        addPlugin(plugin, wi);
+    }
 
+    /**
+     *  Plug in this plugin, already instantiated as an object
+     *  (for those with their own class loader such as a wallet).
+     */
+    public void addPlugin(Plugin plugin,  WalletInterface wi)
+    //    throws PluginException
+    {
+
+        plugin.debug(getDebug(), plugin.getClass() + " ");
+
         Vector plugins = getPluginVector(wi);
         prepare(plugin, plugins);
         //updateAccountBrowser();
@@ -261,20 +282,42 @@
         plugged();
     }
 
+    /**
+     *  Common instantiation work.
+     */
+    private Plugin getInstance(Object context, String classname)
+        throws Exception
+    {
+        ClassLoader cl = context.getClass().getClassLoader();
+        Class clas;
+        if (cl == null)
+            clas = Class.forName(classname);
+        else
+        {
+            logmsg("trying for " + classname);
+            clas = cl.loadClass(classname);
+        }
+
+        Plugin plug = (Plugin)clas.newInstance();
+        //Plugin plug = (Plugin)Beans.instantiate(classloader, classname);
+
+        plug.debug(getDebug(), "    " + classname + " ");
+        plug.setPluginManager(this);
+        plug.setUInterface(core.getUInterface(this));
+        plug.setContractStore(core.getContractStore(this));
+        return plug;
+    }
+
+    /**
+     *  General Plugins, on Menu bar at top.
+     */
     public void getInstance(String classname)
     {
         try
         {
-            Class clas = Class.forName(classname);
-            Plugin plug = (Plugin)clas.newInstance();
-            //Plugin plug = (Plugin)Beans.instantiate(classloader, classname);
-            plug.debug(getDebug(), "    " + classname + " ");
-            plug.setPluginManager(this);
-            plug.setUInterface(core.getUInterface(this));
-            plug.setContractStore(core.getContractStore(this));
+            Plugin plug = getInstance(this, classname);
             plug.init();
             plug.start();
-// logmsg("After plug.start()");
         }
         catch (Exception e)
         {
@@ -285,21 +328,16 @@
         }
     }
 
+    /**
+     *  Contract Plugins, on popup menu for each contract level.
+     */
     public void getInstance(String classname,
                 WalletInterface wi, AccountInfo acct,
                 ItemId contract)
     {
         try
         {
-// logmsg("trying for " + classname);
-            Class clas = Class.forName(classname);
-// logmsg(clas + " .newInstance();");
-            Plugin plug = (Plugin)clas.newInstance();
-            //Plugin plug = (Plugin)Beans.instantiate(classloader, classname);
-            plug.debug(getDebug(), "    " + classname + " ");
-            plug.setPluginManager(this);
-            plug.setUInterface(core.getUInterface(this));
-            plug.setContractStore(core.getContractStore(this));
+            Plugin plug = getInstance(wi, classname);
             plug.init(wi, acct, contract);
             plug.start();
         }
@@ -312,21 +350,17 @@
         }
     }
 
+    /**
+     *  Account Plugins, on popup menu for each account level.
+     */
     public void getInstance(String classname,
                             WalletInterface wi, AccountInfo info)
     {
         try
         {
-            Class clas = Class.forName(classname);
-            Plugin plug = (Plugin)clas.newInstance();
-            //Plugin plug = (Plugin)Beans.instantiate(classloader, classname);
-            plug.debug(getDebug(), "    " + classname + " ");
-            plug.setPluginManager(this);
-            plug.setUInterface(core.getUInterface(this));
-            plug.setContractStore(core.getContractStore(this));
+            Plugin plug = getInstance(wi, classname);
             plug.init(wi, info);
             plug.start();
-//System.err.println("After plug.start()");
         }
         catch (Exception e)
         {



1.2       +4 -2      java/webfunds/client/plugins/WalletManager.java

Index: WalletManager.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/WalletManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WalletManager.java	2000/09/17 20:43:33	1.1
+++ WalletManager.java	2000/09/26 03:11:46	1.2
@@ -1,5 +1,5 @@
 /*
- * $Id: WalletManager.java,v 1.1 2000/09/17 20:43:33 iang Exp $
+ * $Id: WalletManager.java,v 1.2 2000/09/26 03:11:46 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -37,7 +37,7 @@
 {
     
     private Vector       wallets;
-    private Hashtable    homes;
+    private Hashtable    homes;   // place for read-only files owned by wallet
     
     public WalletManager(PrintWriter bug)
     {
@@ -97,8 +97,10 @@
         return array;
     }
     
+    // what was this call for?
     public void removeWallet(WalletInterface wallet)
     {
+        wallet.adminEvent(WalletInterface.CODE_SHUTDOWN, "removal");
         wallets.removeElement(wallet);
         homes.remove(wallet);
         updateAccountBrowser();



1.135     +5 -9      java/webfunds/client/sox/SOXWallet.java

Index: SOXWallet.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/SOXWallet.java,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- SOXWallet.java	2000/09/24 23:19:10	1.134
+++ SOXWallet.java	2000/09/26 03:11:47	1.135
@@ -1,4 +1,4 @@
-/* $Id: SOXWallet.java,v 1.134 2000/09/24 23:19:10 iang Exp $
+/* $Id: SOXWallet.java,v 1.135 2000/09/26 03:11:47 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -54,6 +54,7 @@
 import webfunds.client.Transaction;
 import webfunds.client.UInterface;
 import webfunds.client.plugins.WalletContext;
+//import webfunds.client.plugins.WalletManager;
 import webfunds.client.WalletInterface;
 import webfunds.client.sox.StoreAccountStore;
 
@@ -266,13 +267,6 @@
     }
 
 
-    /**
-     *  adminEvent() codes.
-     */
-    public static final int  CODE_SHUTDOWN = 0,  // stop, clean up everything
-                             CODE_FREEZE   = 1,  // to persistant files, backup
-                             CODE_UNFREEZE = 2;  // ok, carry on, backup done
-
     private boolean   closed;
     public boolean    isClosed()                     { return closed; }
     private int       closeCode;
@@ -288,13 +282,15 @@
      */
     public int adminEvent(int code, String reason)
     {
-        if ((code == CODE_UNFREEZE) && (closeCode == CODE_SHUTDOWN))
+        if ((code == WalletInterface.CODE_UNFREEZE) &&
+            (closeCode == WalletInterface.CODE_SHUTDOWN))
             return -1;
 
         closeCode = code;
         closeReason = reason;
 
-        if ((code == CODE_SHUTDOWN) || (code == CODE_FREEZE))
+        if ((code == WalletInterface.CODE_SHUTDOWN) ||
+            (code == WalletInterface.CODE_FREEZE))
         {
             closed = true;
             closeErrorReason = "Closed.\n\n    \"" + reason + "\"";



1.20      +11 -6     java/webfunds/client/sox/StoreAccountStore.java

Index: StoreAccountStore.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/StoreAccountStore.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- StoreAccountStore.java	2000/06/20 09:57:36	1.19
+++ StoreAccountStore.java	2000/09/26 03:11:47	1.20
@@ -1,5 +1,5 @@
 /*
- * $Id: StoreAccountStore.java,v 1.19 2000/06/20 09:57:36 iang Exp $
+ * $Id: StoreAccountStore.java,v 1.20 2000/09/26 03:11:47 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -31,9 +31,10 @@
     public StoreAccountStore(Store store)
     {
         if (store == null)
-            throw new RuntimeException("StoreAccountStore store == null");
+            throw new IllegalArgumentException("StoreAccountStore store==null");
         this.store = store;        
         this.finder = null;        
+logmsg("SAS " + this.getClass().getClassLoader());
     }
     
     /**
@@ -43,7 +44,7 @@
     public StoreAccountStore(Store store, IssuerFinder finder)
     {
         if (store == null)
-            throw new RuntimeException("StoreAccountStore store == null");
+            throw new IllegalArgumentException("StoreAccountStore store==null");
         this.store  = store;        
         this.finder = finder;
     }
@@ -55,12 +56,16 @@
         // throws StoreException
     {
         Account[] retval = new Account[store.size()];
+logmsg("there are " + retval.length + " accounts in store...");
+logmsg(" CL " + this.getClass().getClassLoader());
         int i = 0;
         try
         {
             for (Enumeration e = store.elements();e.hasMoreElements(); i++)
             {
+logmsg("    get: " + i);
                 retval[i] = new Account((byte[])e.nextElement());
+logmsg("    got: " + i);
             }
         }
         catch (SOXPacketException ex)
@@ -77,7 +82,7 @@
         throws StoreException
     {
         if (acct == null)
-            throw new RuntimeException("getAccount(null)");
+            throw new IllegalArgumentException("getAccount(null)");
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try {
@@ -95,7 +100,7 @@
         throws StoreException
     {
         if (acct == null)
-            throw new RuntimeException("getAccount(null)");
+            throw new IllegalArgumentException("getAccount(null)");
 
         String key = Hex.data2hex(acct.getId().getId());
         store.remove(key);
@@ -109,7 +114,7 @@
         throws StoreException
     {
         if (acct == null)
-            throw new RuntimeException("getAccount(null)");
+            throw new IllegalArgumentException("getAccount(null)");
 
         logmsg("get " + acct);
         String key = Hex.data2hex(acct.getId());