[Webfunds-commits] java/webfunds/sox PaymentFactory.java
Ian Grigg
iang@cypherpunks.ai
Fri, 13 Oct 2000 21:28:48 -0400 (AST)
iang 00/10/13 21:28:48
Modified: webfunds/sox PaymentFactory.java
Log:
closer
Revision Changes Path
1.4 +41 -12 java/webfunds/sox/PaymentFactory.java
Index: PaymentFactory.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/PaymentFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PaymentFactory.java 2000/08/16 19:51:19 1.3
+++ PaymentFactory.java 2000/10/14 01:28:48 1.4
@@ -1,4 +1,4 @@
-/* $Id: PaymentFactory.java,v 1.3 2000/08/16 19:51:19 iang Exp $
+/* $Id: PaymentFactory.java,v 1.4 2000/10/14 01:28:48 iang Exp $
*
* Copyright (c) Systemics Inc. 1995-2000 on behalf of
* The WebFunds Development Team. All Rights Reserved.
@@ -9,7 +9,8 @@
public final class PaymentFactory
{
/**
- * Use the numbers 100 - 110 for experimental methods.
+ * Use the numbers 100 - 110 for experimental methods,
+ * not to be used outside your own private circle.
* Once you are ready, ask the WebFunds team to allocate
* you a fixed number from the fixed blocks.
*/
@@ -19,6 +20,7 @@
WAGNER_TOKEN = 3;
private static final String[] typeNames = {
+ "None?",
"SOX Cheque",
"Random Token",
"Wagner Token"
@@ -27,17 +29,44 @@
private PaymentFactory() {}
- public static Payment decode(byte[] buf) throws SOXException
+ public static AbstractPayment decode(byte[] buf)
+ throws SOXPacketException
{
- try
- {
+
+ if (buf == null)
+ throw new IllegalArgumentException("PaymentFactory.decode(null)");
+ if (buf.length < 100)
+ throw new SOXPacketException("too short? " + buf.length);
+
+ int pv = buf[0]; // factory version, old Pay == 0
+ int sv = buf[1]; // within factory, sub version
+
+// try
+// {
+ if (pv == AbstractPayment.SINGLETON_VERSION)
return new Payment(buf);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- throw new SOXException("Payment Decode Error");
- }
+ else if (pv != AbstractPayment.PF_VERSION)
+ throw new SOXPacketException("Not an AbstractPayment: " + pv + ", " + sv);
+
+ if (sv == SOX_CHEQUE)
+ return new Payment(buf);
+ else if (sv == RANDOM_TOKEN)
+ return new TokenPayment(buf);
+ /*
+ else if (sv == WAGNER_TOKEN)
+ return new TokenPayment(buf);
+ */
+
+ else
+ throw new SOXPacketException("Not a known FactoryPayment: "+pv+", "+sv);
+
+
+// }
+// catch (Exception e)
+// {
+// e.printStackTrace();
+// throw new SOXException("Payment Decode Error");
+// }
}
/**
@@ -67,6 +96,6 @@
return "<" + type + " invalid>";
}
- return typeNames[type - 1] + " (" + type + ")";
+ return typeNames[type] + " (" + type + ")";
}
}