Update of /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts
In directory sc8-pr-cvs1:/tmp/cvs-serv5097/src/java/org/neuclear/asset/contracts
Modified Files:
Asset.java AssetGlobals.java AssetTransactionContract.java
CancelHeldTransferReceipt.java CancelHeldTransferRequest.java
CompleteHeldTransferRequest.java HeldTransferReceipt.java
HeldTransferRequest.java TransferContract.java
TransferReceipt.java TransferRequest.java
Log Message:
Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
- For most cases the main exception to worry about now is InvalidNamedObjectException.
- Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
runtime exception.
- Source and Store patterns each now have their own exceptions that generalizes the various physical
exceptions that can happen in that area.
Index: Asset.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/Asset.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Asset.java 10 Dec 2003 23:52:39 -0000 1.10
--- Asset.java 19 Dec 2003 18:02:35 -0000 1.11
***************
*** 32,35 ****
--- 32,43 ----
$Id$
$Log$
+ Revision 1.11 2003/12/19 18:02:35 pelle
+ Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ runtime exception.
+ - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ exceptions that can happen in that area.
+
Revision 1.10 2003/12/10 23:52:39 pelle
Did some cleaning up in the builders
***************
*** 102,106 ****
*/
public final class Asset extends Identity {
! protected Asset(final SignedNamedCore core, final String repository, final String signer, final String logger, final String receiver, final PublicKey pub, final int decimal, final double minimumTransaction) throws NeuClearException {
super(core, repository, signer, logger, receiver, pub);
this.decimal = decimal;
--- 110,114 ----
*/
public final class Asset extends Identity {
! protected Asset(final SignedNamedCore core, final String repository, final String signer, final String logger, final String receiver, final PublicKey pub, final int decimal, final double minimumTransaction) {
super(core, repository, signer, logger, receiver, pub);
this.decimal = decimal;
***************
*** 142,162 ****
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws NeuClearException, XMLSecurityException {
! if (!elem.getNamespace().equals(AssetGlobals.createNameSpace()))
! throw new UnsupportedOperationException("");
! final String repository = elem.attributeValue(DocumentHelper.createQName("repository", NSTools.NS_NEUID));
! final String signer = elem.attributeValue(DocumentHelper.createQName("signer", NSTools.NS_NEUID));
! final String logger = elem.attributeValue(DocumentHelper.createQName("logger", NSTools.NS_NEUID));
! final String receiver = elem.attributeValue(DocumentHelper.createQName("receiver", NSTools.NS_NEUID));
!
! final Element allowElement = elem.element(DocumentHelper.createQName("allow", NSTools.NS_NEUID));
! final KeyInfo ki = new KeyInfo(allowElement.element(XMLSecTools.createQName("KeyInfo")));
! final PublicKey pub = ki.getPublicKey();
! final String dec = elem.attributeValue("decimalpoints");
! final int decimal = (!Utility.isEmpty(dec)) ? Integer.parseInt(dec) : 0;
! final String min = elem.attributeValue("minimumxact");
! final double minimum = (!Utility.isEmpty(min)) ? Double.parseDouble(min) : 0;
! return new Asset(core, repository, signer, logger, receiver, pub, decimal, minimum);
}
--- 150,173 ----
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws InvalidNamedObjectException {
! if (!elem.getNamespace().equals(AssetGlobals.NS_ASSET))
! throw new InvalidNamedObjectException(core.getName(),"Not in XML NameSpace: "+AssetGlobals.NS_ASSET.getURI());
! final String repository = elem.attributeValue(createNEUIDQName("repository"));
! final String signer = elem.attributeValue(createNEUIDQName("signer"));
! final String logger = elem.attributeValue(createNEUIDQName("logger"));
! final String receiver = elem.attributeValue(createNEUIDQName("receiver"));
! final Element allowElement = InvalidNamedObjectException.assertContainsElementQName(core,elem,createNEUIDQName("allow"));
! try {
! final KeyInfo ki = new KeyInfo(InvalidNamedObjectException.assertContainsElementQName(allowElement, XMLSecTools.createQName("KeyInfo")));
! final PublicKey pub = ki.getPublicKey();
! final String dec = elem.attributeValue("decimalpoints");
! final int decimal = (!Utility.isEmpty(dec)) ? Integer.parseInt(dec) : 0;
! final String min = elem.attributeValue("minimumxact");
! final double minimum = (!Utility.isEmpty(min)) ? Double.parseDouble(min) : 0;
! return new Asset(core, repository, signer, logger, receiver, pub, decimal, minimum);
! } catch (XMLSecurityException e) {
! throw new InvalidNamedObjectException(core.getName(),e);
! }
}
Index: AssetGlobals.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/AssetGlobals.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** AssetGlobals.java 22 Nov 2003 00:22:28 -0000 1.6
--- AssetGlobals.java 19 Dec 2003 18:02:35 -0000 1.7
***************
*** 24,27 ****
--- 24,35 ----
$Id$
$Log$
+ Revision 1.7 2003/12/19 18:02:35 pelle
+ Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ runtime exception.
+ - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ exceptions that can happen in that area.
+
Revision 1.6 2003/11/22 00:22:28 pelle
All unit tests in commons, id and xmlsec now work.
***************
*** 94,103 ****
}
! public static Namespace createNameSpace() {
return DocumentHelper.createNamespace(ASSET_NSPREFIX, XFER_ASSETS);
}
public static QName createQName(final String name) {
! return DocumentHelper.createQName(name, createNameSpace());
}
--- 102,111 ----
}
! private static Namespace createNameSpace() {
return DocumentHelper.createNamespace(ASSET_NSPREFIX, XFER_ASSETS);
}
public static QName createQName(final String name) {
! return DocumentHelper.createQName(name, NS_ASSET);
}
***************
*** 113,117 ****
public static final String XFER_ASSETS = "http://neuclear.org/neu/assets";
public static final String ASSET_NSPREFIX = "asset";
!
public static void registerReaders() {
VerifyingReader.getInstance().registerReader(AssetGlobals.ASSET_TAGNAME, new Asset.Reader());
--- 121,125 ----
public static final String XFER_ASSETS = "http://neuclear.org/neu/assets";
public static final String ASSET_NSPREFIX = "asset";
! public static final Namespace NS_ASSET=createNameSpace();
public static void registerReaders() {
VerifyingReader.getInstance().registerReader(AssetGlobals.ASSET_TAGNAME, new Asset.Reader());
Index: AssetTransactionContract.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/AssetTransactionContract.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** AssetTransactionContract.java 10 Dec 2003 23:52:39 -0000 1.9
--- AssetTransactionContract.java 19 Dec 2003 18:02:35 -0000 1.10
***************
*** 5,16 ****
import org.neuclear.commons.Utility;
import org.neuclear.commons.time.TimeTools;
! import org.neuclear.id.Identity;
! import org.neuclear.id.NamedObjectReader;
! import org.neuclear.id.SignedNamedCore;
! import org.neuclear.id.SignedNamedObject;
import org.neuclear.id.resolver.NSResolver;
import org.neuclear.receiver.UnsupportedTransaction;
import java.util.Date;
/**
--- 5,14 ----
import org.neuclear.commons.Utility;
import org.neuclear.commons.time.TimeTools;
! import org.neuclear.id.*;
import org.neuclear.id.resolver.NSResolver;
import org.neuclear.receiver.UnsupportedTransaction;
import java.util.Date;
+ import java.text.ParseException;
/**
***************
*** 21,24 ****
--- 19,30 ----
* $Id$
* $Log$
+ * Revision 1.10 2003/12/19 18:02:35 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.9 2003/12/10 23:52:39 pelle
* Did some cleaning up in the builders
***************
*** 73,77 ****
private final Asset asset;
! AssetTransactionContract(final SignedNamedCore core, final Asset asset) throws NeuClearException {
super(core);
this.asset = asset;
--- 79,83 ----
private final Asset asset;
! AssetTransactionContract(final SignedNamedCore core, final Asset asset) {
super(core);
this.asset = asset;
***************
*** 90,132 ****
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws NeuClearException {
! if (!elem.getNamespaceURI().equals(TransferGlobals.XFER_NSURI))
! throw new UnsupportedTransaction(core);
!
! final Asset asset = (Asset) NSResolver.resolveIdentity(elem.attributeValue("assetName"));
! final String holdid = elem.attributeValue("holdid");
! if (elem.getName().equals(TransferGlobals.CANCEL_TAGNAME))
! return new CancelHeldTransferRequest(core, asset, holdid);
! if (elem.getName().equals(TransferGlobals.CANCEL_RCPT_TAGNAME))
! return new CancelHeldTransferReceipt(core, asset, holdid);
! final double amount = Double.parseDouble(elem.attributeValue("amount"));
! final Date valuetime = TimeTools.parseTimeStamp(elem.attributeValue("valuetime"));
! final Identity to = NSResolver.resolveIdentity(elem.attributeValue("recipient"));
! final Element commentElement = elem.element(TransferGlobals.createQName("comment"));
! final String comment = (commentElement != null) ? commentElement.getText() : "";
! if (elem.getName().equals(TransferGlobals.XFER_TAGNAME))
! return new TransferRequest(core, asset, to, amount, valuetime, comment);
! Date helduntil = null;
! if (!Utility.isEmpty(elem.attributeValue("valuetime")))
! helduntil = TimeTools.parseTimeStamp(elem.attributeValue("valuetime"));
! if (elem.getName().equals(TransferGlobals.HELD_XFER_TAGNAME))
! return new HeldTransferRequest(core, asset, to, amount, valuetime, comment, helduntil);
! final Identity from = NSResolver.resolveIdentity(elem.attributeValue("sender"));
! final String reqid = elem.attributeValue("reqid");
! if (elem.getName().equals(TransferGlobals.XFER_RCPT_TAGNAME))
! return new TransferReceipt(core, asset, from, to, reqid, amount, valuetime, comment);
! if (elem.getName().equals(TransferGlobals.HELD_XFER_RCPT_TAGNAME))
! return new HeldTransferReceipt(core, asset, from, to, reqid, amount, valuetime, comment, helduntil);
! if (elem.getName().equals(TransferGlobals.COMPLETE_TAGNAME))
! return new CompleteHeldTransferRequest(core, asset, from, to, amount, valuetime, comment, holdid);
! throw new UnsupportedTransaction(core);
}
--- 96,144 ----
* @return
*/
! public final SignedNamedObject read(final SignedNamedCore core, final Element elem) throws InvalidNamedObjectException {
! if (!elem.getNamespace().equals(AssetGlobals.NS_ASSET))
! throw new InvalidNamedObjectException(core.getName(),"Not in XML NameSpace: "+AssetGlobals.NS_ASSET.getURI());
! try {
! //TODO Validate properly
! final Asset asset = (Asset) NSResolver.resolveIdentity(elem.attributeValue("assetName"));
! final String holdid = elem.attributeValue("holdid");
! if (elem.getName().equals(TransferGlobals.CANCEL_TAGNAME))
! return new CancelHeldTransferRequest(core, asset, holdid);
! if (elem.getName().equals(TransferGlobals.CANCEL_RCPT_TAGNAME))
! return new CancelHeldTransferReceipt(core, asset, holdid);
! final double amount = Double.parseDouble(elem.attributeValue("amount"));
! final Date valuetime = TimeTools.parseTimeStamp(elem.attributeValue("valuetime"));
! final Identity to = NSResolver.resolveIdentity(elem.attributeValue("recipient"));
! final Element commentElement = elem.element(TransferGlobals.createQName("comment"));
! final String comment = (commentElement != null) ? commentElement.getText() : "";
! if (elem.getName().equals(TransferGlobals.XFER_TAGNAME))
! return new TransferRequest(core, asset, to, amount, valuetime, comment);
! Date helduntil = null;
! if (!Utility.isEmpty(elem.attributeValue("valuetime")))
! helduntil = TimeTools.parseTimeStamp(elem.attributeValue("valuetime"));
! if (elem.getName().equals(TransferGlobals.HELD_XFER_TAGNAME))
! return new HeldTransferRequest(core, asset, to, amount, valuetime, comment, helduntil);
! final Identity from = NSResolver.resolveIdentity(elem.attributeValue("sender"));
! final String reqid = elem.attributeValue("reqid");
! if (elem.getName().equals(TransferGlobals.XFER_RCPT_TAGNAME))
! return new TransferReceipt(core, asset, from, to, reqid, amount, valuetime, comment);
! if (elem.getName().equals(TransferGlobals.HELD_XFER_RCPT_TAGNAME))
! return new HeldTransferReceipt(core, asset, from, to, reqid, amount, valuetime, comment, helduntil);
! if (elem.getName().equals(TransferGlobals.COMPLETE_TAGNAME))
! return new CompleteHeldTransferRequest(core, asset, from, to, amount, valuetime, comment, holdid);
! } catch (ParseException e) {
! throw new InvalidNamedObjectException(core.getName(),e);
! } catch (NameResolutionException e) {
! throw new InvalidNamedObjectException(core.getName(),e);
! }
! throw new InvalidNamedObjectException(core.getName(),"Not Matched");
}
Index: CancelHeldTransferReceipt.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/CancelHeldTransferReceipt.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CancelHeldTransferReceipt.java 21 Nov 2003 04:43:04 -0000 1.3
--- CancelHeldTransferReceipt.java 19 Dec 2003 18:02:35 -0000 1.4
***************
*** 16,20 ****
public final class CancelHeldTransferReceipt extends AssetTransactionContract{
! CancelHeldTransferReceipt(final SignedNamedCore core, final Asset asset, final String holdid) throws NeuClearException {
super(core, asset);
this.holdid = holdid;
--- 16,20 ----
public final class CancelHeldTransferReceipt extends AssetTransactionContract{
! CancelHeldTransferReceipt(final SignedNamedCore core, final Asset asset, final String holdid) {
super(core, asset);
this.holdid = holdid;
Index: CancelHeldTransferRequest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/CancelHeldTransferRequest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CancelHeldTransferRequest.java 21 Nov 2003 04:43:04 -0000 1.3
--- CancelHeldTransferRequest.java 19 Dec 2003 18:02:35 -0000 1.4
***************
*** 16,20 ****
public final class CancelHeldTransferRequest extends AssetTransactionContract{
! CancelHeldTransferRequest(final SignedNamedCore core, final Asset asset, final String holdid) throws NeuClearException {
super(core, asset);
this.holdid = holdid;
--- 16,20 ----
public final class CancelHeldTransferRequest extends AssetTransactionContract{
! CancelHeldTransferRequest(final SignedNamedCore core, final Asset asset, final String holdid) {
super(core, asset);
this.holdid = holdid;
Index: CompleteHeldTransferRequest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/CompleteHeldTransferRequest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CompleteHeldTransferRequest.java 21 Nov 2003 04:43:04 -0000 1.3
--- CompleteHeldTransferRequest.java 19 Dec 2003 18:02:35 -0000 1.4
***************
*** 14,18 ****
*/
public final class CompleteHeldTransferRequest extends TransferContract {
! CompleteHeldTransferRequest(final SignedNamedCore core, final Asset asset, final Identity from, final Identity to, final double amount, final Date valuetime, final String comment, final String holdid) throws NeuClearException {
super(core, asset, to, amount, valuetime, comment);
this.from = from;
--- 14,18 ----
*/
public final class CompleteHeldTransferRequest extends TransferContract {
! CompleteHeldTransferRequest(final SignedNamedCore core, final Asset asset, final Identity from, final Identity to, final double amount, final Date valuetime, final String comment, final String holdid) {
super(core, asset, to, amount, valuetime, comment);
this.from = from;
Index: HeldTransferReceipt.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/HeldTransferReceipt.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** HeldTransferReceipt.java 21 Nov 2003 13:57:19 -0000 1.5
--- HeldTransferReceipt.java 19 Dec 2003 18:02:35 -0000 1.6
***************
*** 15,19 ****
public final class HeldTransferReceipt extends TransferReceipt implements Held {
! HeldTransferReceipt(final SignedNamedCore core, final Asset asset, final Identity from, final Identity to, final String reqid, final double amount, final Date valuetime, final String comment, final Date helduntil) throws NeuClearException {
super(core, asset, from, to, reqid, amount, valuetime, comment);
this.helduntil = helduntil.getTime();
--- 15,19 ----
public final class HeldTransferReceipt extends TransferReceipt implements Held {
! HeldTransferReceipt(final SignedNamedCore core, final Asset asset, final Identity from, final Identity to, final String reqid, final double amount, final Date valuetime, final String comment, final Date helduntil) {
super(core, asset, from, to, reqid, amount, valuetime, comment);
this.helduntil = helduntil.getTime();
Index: HeldTransferRequest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/HeldTransferRequest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** HeldTransferRequest.java 21 Nov 2003 13:57:19 -0000 1.4
--- HeldTransferRequest.java 19 Dec 2003 18:02:35 -0000 1.5
***************
*** 14,18 ****
*/
public final class HeldTransferRequest extends TransferRequest implements Held {
! HeldTransferRequest(final SignedNamedCore core, final Asset asset, final Identity to, final double amount, final Date valuetime, final String comment, final Date helduntil) throws NeuClearException {
super(core, asset, to, amount, valuetime, comment);
this.helduntil = helduntil.getTime();
--- 14,18 ----
*/
public final class HeldTransferRequest extends TransferRequest implements Held {
! HeldTransferRequest(final SignedNamedCore core, final Asset asset, final Identity to, final double amount, final Date valuetime, final String comment, final Date helduntil) {
super(core, asset, to, amount, valuetime, comment);
this.helduntil = helduntil.getTime();
Index: TransferContract.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/TransferContract.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** TransferContract.java 21 Nov 2003 13:57:19 -0000 1.6
--- TransferContract.java 19 Dec 2003 18:02:35 -0000 1.7
***************
*** 45,49 ****
*/
public abstract class TransferContract extends AssetTransactionContract {
! TransferContract(final SignedNamedCore core, final Asset asset, final Identity to, final double amount, final Date valuetime, final String comment) throws NeuClearException {
super(core, asset);
this.amount = amount;
--- 45,49 ----
*/
public abstract class TransferContract extends AssetTransactionContract {
! TransferContract(final SignedNamedCore core, final Asset asset, final Identity to, final double amount, final Date valuetime, final String comment) {
super(core, asset);
this.amount = amount;
Index: TransferReceipt.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/TransferReceipt.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** TransferReceipt.java 21 Nov 2003 04:43:04 -0000 1.4
--- TransferReceipt.java 19 Dec 2003 18:02:35 -0000 1.5
***************
*** 17,21 ****
private final String reqid;
! TransferReceipt(final SignedNamedCore core, final Asset asset, final Identity from, final Identity to, final String reqid, final double amount, final Date valuetime, final String comment) throws NeuClearException {
super(core, asset, to, amount, valuetime, comment);
this.from = from;
--- 17,21 ----
private final String reqid;
! TransferReceipt(final SignedNamedCore core, final Asset asset, final Identity from, final Identity to, final String reqid, final double amount, final Date valuetime, final String comment) {
super(core, asset, to, amount, valuetime, comment);
this.from = from;
Index: TransferRequest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/contracts/TransferRequest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** TransferRequest.java 21 Nov 2003 04:43:04 -0000 1.4
--- TransferRequest.java 19 Dec 2003 18:02:35 -0000 1.5
***************
*** 15,19 ****
public class TransferRequest extends TransferContract {
! TransferRequest(final SignedNamedCore core, final Asset asset, final Identity to, final double amount, final Date valuetime, final String comment) throws NeuClearException {
super(core, asset, to, amount, valuetime, comment);
}
--- 15,19 ----
public class TransferRequest extends TransferContract {
! TransferRequest(final SignedNamedCore core, final Asset asset, final Identity to, final double amount, final Date valuetime, final String comment) {
super(core, asset, to, amount, valuetime, comment);
}
|