[Webfunds-commits] java/webfunds/client/plugins Plugin.java PluginManager.java WalletContext.java WalletManager.java

Ian Grigg iang@cypherpunks.ai
Fri, 13 Apr 2001 13:43:17 -0400 (AST)


iang        01/04/13 13:43:16

  Modified:    webfunds/client Client.java Core.java
               webfunds/client/plugins Plugin.java PluginManager.java
                        WalletContext.java WalletManager.java
  Log:
  Uses Log all through,  uses CommsManager all through.

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

Index: Client.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Client.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- Client.java	2001/03/07 00:10:14	1.26
+++ Client.java	2001/04/13 17:43:15	1.27
@@ -1,4 +1,4 @@
-/* $Id: Client.java,v 1.26 2001/03/07 00:10:14 gelderen Exp $
+/* $Id: Client.java,v 1.27 2001/04/13 17:43:15 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -38,7 +38,7 @@
             wallet = new SOXWallet();
             ui = new UInterfaceImpl2();
             cs = new ChangeContractStore();
-            wallet.setStore(new SepFileStore(new File("tempdata") ));
+            // wallet.setStore(new SepFileStore(new File("tempdata") ));
             
         }
         catch(Exception ex)



1.74      +19 -8     java/webfunds/client/Core.java

Index: Core.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Core.java,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -r1.73 -r1.74
--- Core.java	2001/04/07 00:09:22	1.73
+++ Core.java	2001/04/13 17:43:15	1.74
@@ -1,4 +1,4 @@
-/* $Id: Core.java,v 1.73 2001/04/07 00:09:22 iang Exp $
+/* $Id: Core.java,v 1.74 2001/04/13 17:43:15 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All rights reserved.
@@ -15,10 +15,14 @@
 import webfunds.openpgp.provider.CryptixOpenPGP;
 
 import webfunds.util.SecureRandomHack;
+import webfunds.util.Log;
 
+import webfunds.comms.BasicCommsManager;
+import webfunds.comms.CommsManager;
+import webfunds.comms.NetWatcher;
+
 import webfunds.utils.Debug;
 import webfunds.utils.MultiPrintStream;
-import webfunds.utils.NetWatcher;
 import webfunds.utils.VersionNumbers;
 
 import webfunds.ricardian.ContractStore;
@@ -67,8 +71,10 @@
     private WalletManager         wm;
     private Store                 st;
     private Addressbook           ad;
+
+    private Log                   bug;
 
-    PrintWriter bug;
+    private CommsManager          comms;
 
     public Core(File userDir, boolean useDefaults, boolean testMode)
     {
@@ -110,7 +116,7 @@
             System.exit(1);
         }
 
-        bug = new PrintWriter(System.err, true);
+        bug = new Log();
         debug(bug, " ");
         if (testMode)   // set this after rather than save it in props file
             props.put("test.mode", "true");
@@ -118,6 +124,7 @@
         setProperties(props);
 
         NetWatcher.setNetOff();   // stop conversion attempts going out
+        comms = new BasicCommsManager(bug);
 
         setUInterface(new UInterfaceImpl());
         File dataDir    = new File(userDir, "data2");
@@ -184,9 +191,13 @@
         Store soxstore = SepFileStore.getInstance(soxDir, bug, "s2 ");
         webfunds.client.sox.StoreReceiptStore.convert(soxstore, bug);
 
+        // cleanup some olf files:  an old named SOXServer:
         File soxServers = new File(soxDir, "SOXServers");
         File denat = new File(soxServers, "Denationalisation");
         denat.delete();
+        // // delete old "Issuers" store in SOX wallet.  Damn, it's a dir.
+        // File oldIssuers = new File(soxDir, "Issuers");
+        // oldIssuers.delete();
 
         logend("DB done.");
 
@@ -206,9 +217,9 @@
         logmsg(" CP:     ab1: " + ab1);
         setAccountBrowser(ab1);
         logmsg(" CP: wallets ");
-        setWalletManager(new WalletManager(bug));
+        setWalletManager(new WalletManager(comms, bug));
         logmsg(" CP: plugins ");
-        setPluginManager(new PluginManager(bug));
+        setPluginManager(new PluginManager(comms, bug));
         logmsg(" CP: set.");
 
 
@@ -217,8 +228,8 @@
         //
         // Need to move all this into the PluginManager (same as wallets).
         //
-        // Here, we need to add a PrintWriter in that
-        // can be sent to the author of the Plugin.
+        // Here, we need to add a Log in that can record
+        // results to be sent to the author of the Plugin.
         // Same for wallets probably.
         //
         String[] plugins = {



1.10      +11 -8     java/webfunds/client/plugins/Plugin.java

Index: Plugin.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/Plugin.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Plugin.java	2000/06/05 02:43:22	1.9
+++ Plugin.java	2001/04/13 17:43:16	1.10
@@ -1,5 +1,5 @@
 /*
- * $Id: Plugin.java,v 1.9 2000/06/05 02:43:22 gelderen Exp $
+ * $Id: Plugin.java,v 1.10 2001/04/13 17:43:16 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -11,7 +11,10 @@
 import java.io.PrintWriter;
 
 import webfunds.sox.ItemId;
+import webfunds.util.Log;
 import webfunds.utils.Diagnostics;
+
+import webfunds.comms.CommsManager;
 import webfunds.store.Store;
 
 import webfunds.client.contracts.ChangeContractStore;
@@ -36,6 +39,7 @@
 
     protected UInterface          ui;
     protected ChangeContractStore cs;
+    protected CommsManager        comms;
     protected Store               store;
 
     public Plugin() { }
@@ -44,15 +48,13 @@
      * Diagnostics.  We need a proper diags module.
      * PM may in future provide individual files for Plugin debug purposes.
      */
-    protected PrintWriter bug = null;
+    protected Log bug = null;
     protected String      fix = "";
-    public void debug(PrintWriter pw, String s)
-                                  { bug = new PrintWriter(pw, true); fix = s; }
+    public void debug(Log log, String s) { bug = log; fix = s; }
     public void logmsg(String s)  { if (bug != null) bug.println(fix + s); }
-    public PrintWriter getDebug() { return bug ; }
-    // hmm, no autoflush.
-    public PrintWriter err()
-           { return (bug == null) ? new PrintWriter(System.err, true) : bug ; }
+    public PrintWriter getDebug() { return new PrintWriter(bug, true) ; }
+    public Log         getLog() { return bug ; }
+    public PrintWriter err() { return (bug == null) ? new Log() : bug ; }
 
 
 
@@ -139,6 +141,7 @@
                                                      { cs = contractstore; }
     public void setUInterface(UInterface uinterface) { ui = uinterface; }
     public void setStore(Store store)                { this.store = store; }
+    public void setCommsManager(CommsManager comms)  { this.comms = comms; }
 
 
 }



1.22      +23 -13    java/webfunds/client/plugins/PluginManager.java

Index: PluginManager.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/PluginManager.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- PluginManager.java	2001/04/07 00:09:46	1.21
+++ PluginManager.java	2001/04/13 17:43:16	1.22
@@ -1,5 +1,5 @@
 /* 
- * $Id: PluginManager.java,v 1.21 2001/04/07 00:09:46 iang Exp $
+ * $Id: PluginManager.java,v 1.22 2001/04/13 17:43:16 iang Exp $
  *
  * Copyright (c) 1995-2000 Systemics Inc on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -9,14 +9,17 @@
 import java.beans.*;
 import java.util.*;
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 
-import webfunds.sox.ItemId;
 import webfunds.util.IniFileReader;
 import webfunds.util.FormattedFileException;
+import webfunds.util.Log;
+
+import webfunds.comms.CommsManager;
+
+import webfunds.sox.ItemId;
 
 import webfunds.ricardian.ContractException;
 
@@ -35,18 +38,24 @@
 public class PluginManager
     extends Manager implements CorePart
 {
-    private Vector     plugins;
-    private Hashtable  walletPlugins;
+    private final static String TAB = "    ",
+                                fix = "PM+ ";
+
+    private CommsManager comms;
+    private Vector       plugins;
+    private Hashtable    walletPlugins;
 
     public String getType() { return "PluginManager"; }
 
 
-    public PluginManager(PrintWriter bug)
+    public PluginManager(CommsManager comms, Log bug)
     {
-        debug(bug, "    PM+ ");
+        debug(bug, TAB + fix);
         classloader = this.getClass().getClassLoader();
-        plugins = new Vector();
-        walletPlugins = new Hashtable();
+
+        this.comms         = comms;
+        this.plugins       = new Vector();
+        this.walletPlugins = new Hashtable();
     }
 
 
@@ -149,7 +158,7 @@
             throw new PluginException(e.getMessage());
         }
 
-        plugin.debug(getDebug(), classname + " ");
+        plugin.debug(getLog(), classname + " ");
 
         prepare(plugin, plugins);
         //updateAccountBrowser();
@@ -206,7 +215,7 @@
     //    throws PluginException
     {
 
-        plugin.debug(getDebug(), plugin.getClass() + " ");
+        plugin.debug(getLog(), plugin.getClass() + " ");
 
         Vector plugins = getPluginVector(wi);
         prepare(plugin, plugins);
@@ -278,7 +287,7 @@
             throw new PluginException(s) ;
         }
 
-        pug.debug(getDebug(), main + " ");
+        pug.debug(getLog(), main + " ");
 
         prepare(pug, plugins);
         //updateAccountBrowser();
@@ -316,10 +325,11 @@
         Plugin plug = (Plugin)clas.newInstance();
         //Plugin plug = (Plugin)Beans.instantiate(classloader, classname);
 
-        plug.debug(getDebug(), "    " + classname + " ");
+        plug.debug(getLog(), "    " + classname + " ");
         plug.setPluginManager(this);
         plug.setUInterface(core.getUInterface(this));
         plug.setContractStore(core.getContractStore(this));
+        plug.setCommsManager(comms);
         return plug;
     }
 



1.3       +13 -3     java/webfunds/client/plugins/WalletContext.java

Index: WalletContext.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/WalletContext.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WalletContext.java	2001/03/18 03:21:06	1.2
+++ WalletContext.java	2001/04/13 17:43:16	1.3
@@ -1,4 +1,4 @@
-/* $Id: WalletContext.java,v 1.2 2001/03/18 03:21:06 iang Exp $
+/* $Id: WalletContext.java,v 1.3 2001/04/13 17:43:16 iang Exp $
  *
  * Copyright (c) 2000 Systemics Inc. All rights reserved.
  */
@@ -10,12 +10,15 @@
 import java.security.SecureRandom;
 import java.util.Properties;
 
+import webfunds.store.Store;
+import webfunds.store.StoreException;
+
+import webfunds.comms.CommsManager;
+
 import webfunds.client.Addressbook;
 import webfunds.client.WalletInterface;
 import webfunds.client.UInterface;
 import webfunds.client.contracts.ChangeContractStore;
-import webfunds.store.Store;
-import webfunds.store.StoreException;
 
 
 
@@ -23,11 +26,15 @@
 {
     /** how to interpret low level names to printable names */
     Addressbook getAddressbook(WalletInterface wi);
+
     SecureRandom getSecureRandom();
+
     /** the persistant storage object available from client */
     Store getStore(WalletInterface wi) throws StoreException;
+
     /** the GUI */
     UInterface getUInterface(WalletInterface wi);
+
     /** the PluginManager for modifying the GUI's menus */
     PluginManager getPluginManager(WalletInterface wi);
 
@@ -37,6 +44,9 @@
 
     /** get a Properties object with undefined properties set within */
     Properties getProperties(WalletInterface wi);
+
+    /** get a CommsManager that gives access to the net */
+    CommsManager getCommsManager(WalletInterface wi);
 
 
     // XXX: ChangeContractStore is misnamed and prolly too specific.



1.7       +38 -16    java/webfunds/client/plugins/WalletManager.java

Index: WalletManager.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/plugins/WalletManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WalletManager.java	2001/04/07 00:09:46	1.6
+++ WalletManager.java	2001/04/13 17:43:16	1.7
@@ -1,5 +1,5 @@
 /*
- * $Id: WalletManager.java,v 1.6 2001/04/07 00:09:46 iang Exp $
+ * $Id: WalletManager.java,v 1.7 2001/04/13 17:43:16 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -12,14 +12,16 @@
 import java.util.Properties;
 import java.io.IOException;
 import java.io.FileNotFoundException;
-import java.io.PrintWriter;
 import java.io.FileInputStream;
 import java.io.File;
 import java.security.SecureRandom;
 
 import webfunds.util.IniFileReader;
 import webfunds.util.FormattedFileException;
+import webfunds.util.Log;
 
+import webfunds.comms.CommsManager;
+
 import webfunds.ricardian.ContractException;
 
 import webfunds.client.Addressbook;
@@ -39,16 +41,21 @@
 public class WalletManager
     extends Manager implements CorePart, WalletContext
 {
+    private final static String TAB = "",
+                                fix = "WM ";
     
+    private CommsManager comms;
     private Vector       wallets;
     private Hashtable    homes;   // place for read-only files owned by wallet
     
-    public WalletManager(PrintWriter bug)
+    public WalletManager(CommsManager comms, Log bug)
     {
-        debug(bug, "WM ");
+        debug(bug, TAB + fix);
         Beans.setGuiAvailable(true);
-        wallets = new Vector();
-        homes = new Hashtable();
+
+        this.comms   = comms;
+        this.wallets = new Vector();
+        this.homes   = new Hashtable();
     }
 
     public String getType()
@@ -76,7 +83,7 @@
             wallet = (WalletInterface)Beans.instantiate(classloader, classname);
 
             logmsg("debug");
-            PrintWriter bug = getDebug();
+            Log bug = getLog();
             //bug.println("setting debug for " + classname);
             wallet.debug(bug);
             homes.put(wallet, ".");       // access to static info in dir
@@ -115,6 +122,11 @@
         return core.getUInterface(this);
     }
     
+    public CommsManager getCommsManager(WalletInterface wi)
+    {
+        return comms;
+    }
+    
     public ChangeContractStore getContractStore(WalletInterface wi)
     {
         return core.getContractStore(this);
@@ -177,23 +189,32 @@
 
 
 
+    protected void error(String e)   
+    {
+        logmsg("[ " + e + " ]");
+
+        try {
+            getUInterface(null).errorMessage(e);
+        } catch (Exception ex) {
+            logmsg("Ug, error call failed!  " + ex);
+        }
+    }
+
+
+
     /**
      *  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()) ;
-//        }
+        PluginClassLoader cl = new PluginClassLoader();
 
         try {
             addWallet(cl, classname, ".");
         } catch (PluginException ex) {
-            logmsg("Failed: " + classname + ": " + ex.getMessage());
+            error("Standard WebFunds Wallet has failed: " + classname + 
+                  "\n\n     " + ex + vvv);
         }   
         
         updateAccountBrowser();
@@ -215,7 +236,8 @@
                 logmsg("    " + plug + " - - - - - - - - - - - - - - - -");
                 add3rdPartyWallet(walletDir, plug);
             } catch (PluginException ex) {
-                logmsg("Failed: " + plug + ": " + ex.getMessage() + vvv);
+                error("Plugin 3rd party Wallet has failed: " + plug +
+                      "\n\n    " + ex.getMessage() + vvv);
             }   
         }
         updateAccountBrowser();
@@ -289,7 +311,7 @@
         {
             logmsg("debug");
             //bug.println("setting debug for " + classname);
-            wallet.debug(getDebug());
+            wallet.debug(getLog());
             homes.put(wallet, home);        // access to static info in dir
             wallet.setWalletContext(this);