[Webfunds-commits] java/webfunds/client/sox CancelException.java DepositException.java PaymentException.java SOXWallet.java StoreAccountStore.java WalletException.java

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


iang        00/09/30 14:50:15

  Modified:    webfunds/client Client.java Core.java StoreChanger.java
               webfunds/client/plugins PluginClassLoader.java
                        WalletManager.java
               webfunds/client/sox CancelException.java
                        DepositException.java PaymentException.java
                        SOXWallet.java StoreAccountStore.java
                        WalletException.java
  Log:
  ClassLoader mods so that added wallets can see the data.

Revision  Changes    Path
1.25      +2 -1      java/webfunds/client/Client.java

Index: Client.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Client.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Client.java	2000/07/13 21:05:44	1.24
+++ Client.java	2000/09/30 18:50:07	1.25
@@ -1,4 +1,4 @@
-/* $Id: Client.java,v 1.24 2000/07/13 21:05:44 gelderen Exp $
+/* $Id: Client.java,v 1.25 2000/09/30 18:50:07 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -14,6 +14,7 @@
 import webfunds.client.sox.*;
 import webfunds.client.sox.SOXWallet;
 import webfunds.sox.*;
+import webfunds.store.SepFileStore;
 
 import webfunds.ricardian.Contract;
 import webfunds.client.contracts.ChangeContractStore;



1.67      +2 -2      java/webfunds/client/Core.java

Index: Core.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Core.java,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- Core.java	2000/09/26 22:24:51	1.66
+++ Core.java	2000/09/30 18:50:07	1.67
@@ -1,4 +1,4 @@
-/* $Id: Core.java,v 1.66 2000/09/26 22:24:51 iang Exp $
+/* $Id: Core.java,v 1.67 2000/09/30 18:50:07 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All rights reserved.
@@ -33,7 +33,7 @@
 
 import webfunds.store.Store;
 import webfunds.store.StoreException;
-import webfunds.store.*;
+import webfunds.store.SepFileStore;
 
 
 public final class Core



1.7       +2 -2      java/webfunds/client/StoreChanger.java

Index: StoreChanger.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/StoreChanger.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- StoreChanger.java	2000/06/05 04:23:39	1.6
+++ StoreChanger.java	2000/09/30 18:50:08	1.7
@@ -1,4 +1,4 @@
-/* $Id: StoreChanger.java,v 1.6 2000/06/05 04:23:39 gelderen Exp $
+/* $Id: StoreChanger.java,v 1.7 2000/09/30 18:50:08 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -10,7 +10,7 @@
 import java.util.Enumeration;
 import webfunds.store.Store;
 import webfunds.store.StoreException;
-import webfunds.store.*;
+import webfunds.store.SepFileStore;
 
 public class StoreChanger
 {



1.3       +28 -7     java/webfunds/client/plugins/PluginClassLoader.java

Index: PluginClassLoader.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/PluginClassLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PluginClassLoader.java	2000/09/26 03:11:46	1.2
+++ PluginClassLoader.java	2000/09/30 18:50:08	1.3
@@ -1,5 +1,5 @@
 /*
- * $Id: PluginClassLoader.java,v 1.2 2000/09/26 03:11:46 iang Exp $
+ * $Id: PluginClassLoader.java,v 1.3 2000/09/30 18:50:08 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -18,11 +18,14 @@
 class PluginClassLoader
     extends DirClassLoader
 {
+    /**
+     *  A list of default WebFunds class top level names.
+     *  Used when systemClasses not supplied, below.
+     */
     static String[] hierarchies = { "webfunds", "javax" };
 
     /**
-     * Call this with "webfunds" and "sun" for example to block
-     * the mixing of those classes.  Hmmm.  Is this right?
+     * Call this with a list of additional WebFunds classes to pick up.
      * 
      * @param dir the location of the non-system classes
      * @param systemClasses a list of hierarchies that are system, not plugin.
@@ -35,16 +38,34 @@
     }
 
     /**
-     * Call this with the directory of the plugin.
+     *  Call this with the directory of the plugin classes.
      * 
-     * @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 non-system classes
      */
     public PluginClassLoader(String dir)
         throws FileNotFoundException
     {
         super(dir, hierarchies);
+    }
+
+    /**
+     *  A straight WebFunds class loader.
+     *  This acts the same way as the above 3rd-party loaders, but without
+     *  access to special classes.
+     */
+    public PluginClassLoader(String[] systemClasses)
+    {
+        super(systemClasses);
+    }
+
+    /**
+     *  A straight WebFunds class loader.
+     *  This acts the same way as the above 3rd-party loaders, but without
+     *  access to special classes.
+     */
+    public PluginClassLoader()
+    {
+        super(hierarchies);
     }
 
 



1.3       +73 -22    java/webfunds/client/plugins/WalletManager.java

Index: WalletManager.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/WalletManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WalletManager.java	2000/09/26 03:11:46	1.2
+++ WalletManager.java	2000/09/30 18:50:09	1.3
@@ -1,5 +1,5 @@
 /*
- * $Id: WalletManager.java,v 1.2 2000/09/26 03:11:46 iang Exp $
+ * $Id: WalletManager.java,v 1.3 2000/09/30 18:50:09 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -29,6 +29,7 @@
 
 import webfunds.store.Store;
 import webfunds.store.StoreException;
+import webfunds.store.SepFileStore;
 
 import webfunds.utils.VersionNumbers;
 
@@ -61,7 +62,7 @@
     }
     
 
-    public void addWallet(String classname)
+    public void addWallet(String classname, String old)
     {
         try
         {
@@ -82,7 +83,7 @@
             updateAccountBrowser();
             
         }
-        catch(Exception e)
+        catch(Throwable e)
         {
             e.printStackTrace();
         }
@@ -119,13 +120,34 @@
     public Store getStore(WalletInterface wi)
         throws StoreException
     {
-        return core.getStore(this).getStore(wi.getShortName());
+        String name = wi.getShortName();
+        Store myStore =  core.getStore(this);
+        ClassLoader myCL = myStore.getClassLoader();
+        logmsg("my store has CL " + myCL);
+        if (!(myStore instanceof SepFileStore))
+            throw new StoreException("unknown class: " + myStore.getClass());
+        SepFileStore sep = (SepFileStore)myStore;
+
+        // substitute in the wallet's CL so that it inherits that
+        Class wiClass = wi.getClass();
+        ClassLoader walletCL = wiClass.getClassLoader();
+        logmsg("new store for " + name + ", setting CL " + walletCL);
+        // myStore.setClassLoader(walletCL);
+
+        Store st;
+        if (walletCL == null)
+            st =  sep.getStore(name);
+        else
+            st =  sep.getStore(name, walletCL);
+
+        // put back the real one...  Grotty, could cause thread problems...
+        // myStore.setClassLoader(myCL);
+        return st;
     }
     
     public Addressbook getAddressbook(WalletInterface wi)
     {
-        return core.getAddressbook(this);
-    }
+        return core.getAddressbook(this); }
     
     public SecureRandom getSecureRandom()
     {
@@ -144,7 +166,31 @@
     }
 
 
+
+
     /**
+     *  Plug in the known WebFunds wallets out of the classpath.
+     */
+    public void addWallet(String classname)
+    {
+        logmsg("new (classpath) PCL");
+        PluginClassLoader cl;
+//        try {
+            cl = new PluginClassLoader();
+//        } catch (FileNotFoundException ex) {
+//            throw new PluginException("FNFEx: " + ex.getMessage()) ;
+//        }
+
+        try {
+            addWallet(cl, classname, ".");
+        } catch (PluginException ex) {
+            logmsg("Failed: " + classname + ": " + ex.getMessage());
+        }   
+        
+        updateAccountBrowser();
+    }
+
+    /**
      *  Plug in the 3rd party wallets out of the directory dir.
      */
     public void add3rdPartyWallets(File walletDir)
@@ -160,14 +206,14 @@
                 logmsg("    " + plug + " - - - - - - - - - - - - - - - -");
                 add3rdPartyWallet(walletDir, plug);
             } catch (PluginException ex) {
-                logmsg("        Failed: " + ex + "\n" + vvv);
+                logmsg("Failed: " + plug + ": " + ex.getMessage() + vvv);
             }   
         }
         updateAccountBrowser();
     }
 
     static final String spec  = "wallet.ini";
-    static final String vvv = "Contact your Vendor!";
+    static final String vvv = "\n\nContact your Vendor!";
 
     public void add3rdPartyWallet(File top, String wal)
         throws PluginException
@@ -176,8 +222,8 @@
         File pugSpec = new File(dir, spec);
         logmsg("reading " + pugSpec);
         IniFileReader ini = readAsIniFile(pugSpec);
-        String s = "Wallet " + wal + " failed.\n";
 
+        String s = "Wallet " + wal + " failed.\n";
         String main = ini.getSectionItemValue("java", "main");
         if (main == null || main.length() == 0)
             throw new PluginException(s + "no [java] main in " + pugSpec);
@@ -194,10 +240,16 @@
                    " not a valid plugin home!";
             throw new PluginException(s) ;
         }
+
+        addWallet(cl, main, dir.getPath());
+    }
 
-        String tail = "\n" + "Main " + main +
-                   " not a valid Main entry point!";
-        logmsg("ini says " + main);
+    public void addWallet(PluginClassLoader cl, String main, String home)
+        throws PluginException
+    {
+        String s = "Wallet " + main + " not a valid Main entry point!.\n\n";
+
+        logmsg("class name " + main);
         WalletInterface wallet;
         try {
             Class cuss = cl.loadClass(main);
@@ -208,36 +260,35 @@
             //logmsg("instantiating " + classname);
             //wallet = (WalletInterface)Beans.instantiate(classloader, classname);
         } catch (IllegalAccessException ex) {
-            s += "Ex: " + ex + "\n" + tail;
-            throw new PluginException(s) ;
+            throw new PluginException(s + ex) ;
         } catch (InstantiationException ex) {
-            s += "Ex: " + ex + "\n" + tail;
-            throw new PluginException(s) ;
+            throw new PluginException(s + ex) ;
         } catch (ClassNotFoundException ex) {
-            s += "Ex: " + ex + "\n" + tail;
-            throw new PluginException(s) ;
+            throw new PluginException(s + ex) ;
         }
 
         //loaders.addElement(cl);          // not sure whether this is needed...
 
 
         //
-        // from now on, we have no idea what this code can
-        // do / throw so we need to catch everything ?!?
+        //  From now on, we have no idea what this code can
+        //  do / throw so we need to catch everything ?!?
+        //  Should really designate a proper Ex to throw?
+        //  For now, throws InternalError.
         //
         try
         {
             logmsg("debug");
             //bug.println("setting debug for " + classname);
             wallet.debug(getDebug());
-            homes.put(wallet, dir.getPath());  // access to static info in dir
+            homes.put(wallet, home);        // access to static info in dir
             wallet.setWalletContext(this);
 
             // ? prepare(wallet, plugins);
         }
         catch (Throwable ex)
         {
-            throw new PluginException("badly behaved, ditching");
+            throw new PluginException("Fatal Wallet: " + ex);
         }
 
         wallets.addElement(wallet);



1.4       +2 -2      java/webfunds/client/sox/CancelException.java

Index: CancelException.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/CancelException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CancelException.java	2000/09/17 19:42:24	1.3
+++ CancelException.java	2000/09/30 18:50:09	1.4
@@ -1,5 +1,5 @@
 /*
- * $Id: CancelException.java,v 1.3 2000/09/17 19:42:24 iang Exp $
+ * $Id: CancelException.java,v 1.4 2000/09/30 18:50:09 iang Exp $
  *
  * Copyright (c) 2000 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -18,5 +18,5 @@
     public CancelException(int errno)                { super(errno); }
     public CancelException(int errno, String msg)    { super(errno, msg); }
 
-    public String toString() { return "CanEx: " + super.getMessage(); }
+    public String toString() { return "CanEx: " + super.toString(); }
 }



1.5       +2 -2      java/webfunds/client/sox/DepositException.java

Index: DepositException.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/DepositException.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DepositException.java	2000/07/16 19:24:01	1.4
+++ DepositException.java	2000/09/30 18:50:10	1.5
@@ -1,4 +1,4 @@
-/* $Id: DepositException.java,v 1.4 2000/07/16 19:24:01 iang Exp $
+/* $Id: DepositException.java,v 1.5 2000/09/30 18:50:10 iang Exp $
  *
  * Copyright (c) 2000 Systemics Inc. on behalf of
  * The WebFunds Development Team. All rights reserved.
@@ -18,5 +18,5 @@
     public DepositException(int num, String s) { super(num, s); }
     public DepositException(String s)          { super(s); }
 
-    public String toString() { return "DepEx: " + super.getMessage(); }
+    public String toString() { return "DepEx: " + super.toString(); }
 }



1.2       +2 -2      java/webfunds/client/sox/PaymentException.java

Index: PaymentException.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/PaymentException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PaymentException.java	2000/09/17 19:42:24	1.1
+++ PaymentException.java	2000/09/30 18:50:12	1.2
@@ -1,5 +1,5 @@
 /*
- * $Id: PaymentException.java,v 1.1 2000/09/17 19:42:24 iang Exp $
+ * $Id: PaymentException.java,v 1.2 2000/09/30 18:50:12 iang Exp $
  *
  * Copyright (c) 2000 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -18,5 +18,5 @@
     public PaymentException(int errno)                { super(errno); }
     public PaymentException(int errno, String msg)    { super(errno, msg); }
 
-    public String toString() { return "PayEx: " + super.getMessage(); }
+    public String toString() { return "PayEx: " + super.toString(); }
 }



1.136     +30 -11    java/webfunds/client/sox/SOXWallet.java

Index: SOXWallet.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/SOXWallet.java,v
retrieving revision 1.135
retrieving revision 1.136
diff -u -r1.135 -r1.136
--- SOXWallet.java	2000/09/26 03:11:47	1.135
+++ SOXWallet.java	2000/09/30 18:50:12	1.136
@@ -1,4 +1,4 @@
-/* $Id: SOXWallet.java,v 1.135 2000/09/26 03:11:47 iang Exp $
+/* $Id: SOXWallet.java,v 1.136 2000/09/30 18:50:12 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -26,6 +26,7 @@
 
 import webfunds.store.Store;
 import webfunds.store.StoreException;
+import webfunds.store.SepFileStore;
 
 import webfunds.sox.Account;
 import webfunds.sox.AccountId;
@@ -50,7 +51,6 @@
 // WebFunds Client Application
 import webfunds.client.AccountInfo;
 import webfunds.client.Addressbook;
-import webfunds.client.SepFileStore;
 import webfunds.client.Transaction;
 import webfunds.client.UInterface;
 import webfunds.client.plugins.WalletContext;
@@ -131,8 +131,10 @@
      * For example, we get Stores and Contracts from it.
      *
      * XXX: Context should be set in the ctor.
+     * YYY: Construction is complicated by class loader, hence separate init?
      */
     public void setWalletContext(WalletContext aContext)
+        // should throw something...
     {
         // XXX: in anticipation of moving this to the ctor.
         if( this.context != null )
@@ -153,7 +155,7 @@
         {
             String e = "Error reading stores\n" + ex;
             logmsg(e);
-            throw new Panic(e);
+            throw new InternalError(e);
         }
     }
 
@@ -218,6 +220,7 @@
      *  Unfortunately, it's quite limiting.
      */
     public void setStore(Store store)
+        throws StoreException
     {
         this.store   = store;
 
@@ -228,22 +231,24 @@
         try {
             soxstore = store.getStore("SOXServers", SepFileStore.APPEND);
         } catch (StoreException ex) {  // should delete and start again
-            ex.printStackTrace(err());
+            // ex.printStackTrace(err());
             logmsg("Failed to get SOXServers store: " + ex);
-            System.exit(1);
+            // System.exit(1);
+            throw ex ;
         }
         soxes = new SOXServerStore(soxstore, getDebug());
         IssuerFinder finder = null;
         finder = (IssuerFinder)soxes;
 
         //
-        //  Account and Receipt store.
+        //  Account store.
+        //  Failures here are unrecoverable.
         //
         try
         {
-            System.err.println("Trying to get 'Accounts' store");
+            logmsg("Trying to get 'Accounts' store");
             Store st = store.getStore("Accounts");
-            System.err.println(
+            logmsg(
                 "  We got: " + st +
                 ", with size: " + st.size() );
             StoreAccountStore accs;
@@ -251,13 +256,28 @@
             accs.debug(bug);
 
             accountStore = (AccountStore)accs;
+        }
+        catch (StoreException ex)
+        {
+            logmsg("Couldn't decode account\n" + ex);
+            throw ex ;
+            // System.exit(1);
+        }
+
+        //
+        //  Receipt store.
+        //  Failures here are unrecoverable.
+        //
+        try
+        {
             receiptStore = new StoreReceiptStore(store.getStore("Receipts"));
             //receiptStore.debug(bug);
         }
         catch (StoreException ex)
         {
-            logmsg("Couldn't decode account/receipts\n" + ex);
-            System.exit(1);
+            logmsg("Couldn't decode receipts\n" + ex);
+            throw ex ;
+            // System.exit(1);
         }
 
         //
@@ -2178,8 +2198,7 @@
      *  The address bits are unset.
      */
     protected AccountInfo getAccountInfo(SubAccount sub)
-    {
-        AccountId id = getAccountId(sub);
+    { AccountId id = getAccountId(sub);
         return new AccountInfo(id.getId(), null, this);
     }
 



1.21      +6 -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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- StoreAccountStore.java	2000/09/26 03:11:47	1.20
+++ StoreAccountStore.java	2000/09/30 18:50:13	1.21
@@ -1,5 +1,5 @@
 /*
- * $Id: StoreAccountStore.java,v 1.20 2000/09/26 03:11:47 iang Exp $
+ * $Id: StoreAccountStore.java,v 1.21 2000/09/30 18:50:13 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -34,7 +34,7 @@
             throw new IllegalArgumentException("StoreAccountStore store==null");
         this.store = store;        
         this.finder = null;        
-logmsg("SAS " + this.getClass().getClassLoader());
+//logmsg("SAS " + this.getClass().getClassLoader());
     }
     
     /**
@@ -56,16 +56,16 @@
         // throws StoreException
     {
         Account[] retval = new Account[store.size()];
-logmsg("there are " + retval.length + " accounts in store...");
-logmsg(" CL " + this.getClass().getClassLoader());
+//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);
+//logmsg("    get: " + i);
                 retval[i] = new Account((byte[])e.nextElement());
-logmsg("    got: " + i);
+//logmsg("    got: " + i);
             }
         }
         catch (SOXPacketException ex)



1.6       +2 -2      java/webfunds/client/sox/WalletException.java

Index: WalletException.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/WalletException.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WalletException.java	2000/09/24 23:19:10	1.5
+++ WalletException.java	2000/09/30 18:50:14	1.6
@@ -1,5 +1,5 @@
 /*
- * $Id: WalletException.java,v 1.5 2000/09/24 23:19:10 iang Exp $
+ * $Id: WalletException.java,v 1.6 2000/09/30 18:50:14 iang Exp $
  *
  * Copyright (c) 2000 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -61,7 +61,7 @@
                (number == SOXException.LATER_DOWN);    // no net
     }
 
-    public boolean isAlready()
+    public boolean isAlready()   // already What?
     {
         return (number == ALREADY)            ||
                (number == Errors.ERROR_DEP_ALREADY) ||   // did is used