Update of /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/orders
In directory sc8-pr-cvs1:/tmp/cvs-serv22932/src/java/org/neuclear/asset/orders
Modified Files:
AssetTransactionContract.java TransferGlobals.java
TransferOrder.java TransferReceipt.java
Log Message:
Implemented new Schema for Transfer*
Working on it for Exchange*, so far all Receipts are implemented.
Added SignedNamedDocument which is a generic SignedNamedObject that works with all Signed XML.
Changed SignedNamedObject.getDigest() from byte array to String.
The whole malarchy in neuclear-pay does not build yet. The refactoring is a big job, but getting there.
Index: AssetTransactionContract.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/orders/AssetTransactionContract.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AssetTransactionContract.java 5 Jan 2004 23:47:09 -0000 1.1
--- AssetTransactionContract.java 10 Jan 2004 00:00:45 -0000 1.2
***************
*** 1,21 ****
package org.neuclear.asset.orders;
- import org.dom4j.Element;
- import org.neuclear.commons.NeuClearException;
- 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 org.neuclear.asset.orders.exchanges.*;
import org.neuclear.asset.contracts.Asset;
! import org.neuclear.asset.contracts.AssetGlobals;
! import org.neuclear.exchange.orders.CancelExchangeOrder;
! import org.neuclear.exchange.orders.CancelExchangeReceipt;
! import org.neuclear.exchange.orders.ExchangeCompletionOrder;
! import org.neuclear.exchange.orders.ExchangeOrderReceipt;
!
! import java.util.Date;
! import java.text.ParseException;
/**
--- 1,7 ----
package org.neuclear.asset.orders;
import org.neuclear.asset.contracts.Asset;
! import org.neuclear.id.SignedNamedCore;
! import org.neuclear.id.SignedNamedObject;
/**
***************
*** 26,29 ****
--- 12,22 ----
* $Id$
* $Log$
+ * Revision 1.2 2004/01/10 00:00:45 pelle
+ * Implemented new Schema for Transfer*
+ * Working on it for Exchange*, so far all Receipts are implemented.
+ * Added SignedNamedDocument which is a generic SignedNamedObject that works with all Signed XML.
+ * Changed SignedNamedObject.getDigest() from byte array to String.
+ * The whole malarchy in neuclear-pay does not build yet. The refactoring is a big job, but getting there.
+ *
* Revision 1.1 2004/01/05 23:47:09 pelle
* Create new Document classification "order", which is really just inherint in the new
***************
*** 105,165 ****
return asset;
}
-
- public static final class Reader implements NamedObjectReader {
- /**
- * Read object from Element and fill in its details
- *
- * @param elem
- * @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 CancelExchangeOrder(core, asset, holdid);
- if (elem.getName().equals(TransferGlobals.CANCEL_RCPT_TAGNAME))
- return new CancelExchangeReceipt(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 TransferOrder(core, asset, to, amount, 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 ExchangeOrder(core, asset, to, amount, 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 ExchangeOrderReceipt(core, asset, from, to, reqid, amount, valuetime, comment, helduntil);
-
- if (elem.getName().equals(TransferGlobals.COMPLETE_TAGNAME))
- return new ExchangeCompletionOrder(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");
- }
-
- }
-
}
--- 98,101 ----
Index: TransferGlobals.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/orders/TransferGlobals.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TransferGlobals.java 6 Jan 2004 23:26:48 -0000 1.2
--- TransferGlobals.java 10 Jan 2004 00:00:45 -0000 1.3
***************
*** 2,8 ****
import org.dom4j.*;
import org.neuclear.id.verifier.VerifyingReader;
! import org.neuclear.asset.orders.AssetTransactionContract;
! import org.neuclear.asset.orders.AssetTransactionContract;
/*
--- 2,17 ----
import org.dom4j.*;
+ import org.neuclear.asset.contracts.Asset;
+ import org.neuclear.commons.Utility;
+ import org.neuclear.commons.time.TimeTools;
+ import org.neuclear.id.Identity;
+ import org.neuclear.id.InvalidNamedObjectException;
+ import org.neuclear.id.NameResolutionException;
+ import org.neuclear.id.SignedNamedObject;
+ import org.neuclear.id.resolver.NSResolver;
import org.neuclear.id.verifier.VerifyingReader;
!
! import java.sql.Timestamp;
! import java.text.ParseException;
/*
***************
*** 26,29 ****
--- 35,45 ----
$Id$
$Log$
+ Revision 1.3 2004/01/10 00:00:45 pelle
+ Implemented new Schema for Transfer*
+ Working on it for Exchange*, so far all Receipts are implemented.
+ Added SignedNamedDocument which is a generic SignedNamedObject that works with all Signed XML.
+ Changed SignedNamedObject.getDigest() from byte array to String.
+ The whole malarchy in neuclear-pay does not build yet. The refactoring is a big job, but getting there.
+
Revision 1.2 2004/01/06 23:26:48 pelle
Started restructuring the original xml schemas.
***************
*** 114,117 ****
--- 130,154 ----
return elem;
}
+ public static String getElementValue(final Element element, final String name) throws InvalidNamedObjectException {
+ return getElementValue(element,createQName(name));
+ }
+
+ public static String getElementValue(final Element element, final QName name) throws InvalidNamedObjectException {
+ final Element value=element.element(name);
+ if (value==null)
+ throw new InvalidNamedObjectException("Missing required element: "+name);
+ final String text=value.getTextTrim();
+ if (Utility.isEmpty(text))
+ throw new InvalidNamedObjectException("Required element: "+name+" is empty");
+ return text;
+ }
+
+ public static String getCommentElement(final Element element) {
+ final Element value=element.element(createQName(COMMENT_TAG));
+ if (value==null)
+ return "";
+ final String text=value.getTextTrim();
+ return Utility.denullString(text);
+ }
public static Element createElement(final String name) {
***************
*** 124,127 ****
--- 161,226 ----
}
+ public static final Timestamp parseValueTimeElement(final Element elem) throws InvalidNamedObjectException {
+ return parseTimeStampElement(elem,createQName(VALUE_TIME_TAG));
+ }
+
+ public static final Timestamp parseTimeStampElement(final Element elem,final String name) throws InvalidNamedObjectException {
+ return parseTimeStampElement(elem,createQName(name));
+ }
+ public static final Timestamp parseTimeStampElement(final Element elem,final QName qn) throws InvalidNamedObjectException {
+ try {
+ final Element telem=elem.element(qn);
+ if (telem==null)
+ throw new InvalidNamedObjectException("missing time stamp element");
+ final String value=telem.getTextTrim();
+ if (Utility.isEmpty(value))
+ throw new InvalidNamedObjectException("missing time stamp");
+
+ return TimeTools.parseTimeStamp(value);
+ } catch (ParseException e) {
+ throw new InvalidNamedObjectException("missing or invalid time stamp");
+ }
+
+ }
+
+ public static final Asset parseAssetTag(Element elem) throws InvalidNamedObjectException {
+ final String name = getElementValue(elem,ASSET_TAG);
+ try {
+ return (Asset) NSResolver.resolveIdentity(name);
+ } catch (ClassCastException e) {
+ throw new InvalidNamedObjectException(name,e);
+ } catch (NameResolutionException e) {
+ throw new InvalidNamedObjectException(name,e);
+ }
+
+ }
+ public static final Identity parseRecipientTag(Element elem) throws InvalidNamedObjectException {
+ final String name = getElementValue(elem,RECIPIENT_TAG);
+ try {
+ return NSResolver.resolveIdentity(name);
+ } catch (NameResolutionException e) {
+ throw new InvalidNamedObjectException(name,e);
+ }
+
+ }
+
+ public static final double parseAmountTag(Element elem) throws InvalidNamedObjectException {
+ final String amount=getElementValue(elem,AMOUNT_TAG);
+ try {
+ return Double.parseDouble(amount);
+ } catch (NumberFormatException e) {
+ throw new InvalidNamedObjectException("Badly formatted number",e);
+ }
+ }
+ public static final SignedNamedObject parseEmbedded(Element elem,QName name) throws InvalidNamedObjectException {
+ Element embedded=elem.element(name);
+ if (embedded==null)
+ throw new InvalidNamedObjectException("Element: "+elem.getName()+" doesnt contain a "+name.getQualifiedName());
+ try {
+ return VerifyingReader.getInstance().read(embedded);
+ } catch (NameResolutionException e) {
+ throw new InvalidNamedObjectException("Element: "+elem.getName()+" had a problem identifying signer",e);
+ }
+ }
static {
registerReaders();
***************
*** 132,134 ****
--- 231,238 ----
public static final String XFER_NSPREFIX = "xfer";
public static final String XFER_NSURI = "http://neuclear.org/neu/xfer.xsd";
+ public static final String VALUE_TIME_TAG="ValueTime";
+ public static final String COMMENT_TAG="Comment";
+ public static final String ASSET_TAG="Asset";
+ public static final String AMOUNT_TAG="Amount";
+ private static final String RECIPIENT_TAG = "Recipient";
}
Index: TransferOrder.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/orders/TransferOrder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TransferOrder.java 5 Jan 2004 23:47:09 -0000 1.1
--- TransferOrder.java 10 Jan 2004 00:00:45 -0000 1.2
***************
*** 1,19 ****
package org.neuclear.asset.orders;
! import org.neuclear.commons.NeuClearException;
! import org.neuclear.commons.Utility;
! import org.neuclear.commons.time.TimeTools;
! import org.neuclear.id.*;
! import org.neuclear.id.resolver.NSResolver;
! import org.neuclear.asset.orders.TransferContract;
! import org.neuclear.asset.orders.exchanges.*;
! import org.neuclear.asset.orders.AssetTransactionContract;
import org.neuclear.asset.contracts.Asset;
import org.neuclear.asset.contracts.AssetGlobals;
! import org.dom4j.Element;
!
! import java.sql.Timestamp;
! import java.util.Date;
! import java.text.ParseException;
/**
--- 1,8 ----
package org.neuclear.asset.orders;
! import org.dom4j.Element;
import org.neuclear.asset.contracts.Asset;
import org.neuclear.asset.contracts.AssetGlobals;
! import org.neuclear.id.*;
/**
***************
*** 24,40 ****
public class TransferOrder extends AssetTransactionContract {
! private TransferOrder(final SignedNamedCore core, final Asset asset, final Identity to, final double amount, final String comment) {
super(core, asset);
this.amount = amount;
! this.comment = (comment != null) ? comment : "";
! this.to=to;
! }
!
! public final Identity getFrom() {
! return getSignatory();
}
! public final Identity getTo() {
! return to;
}
public final double getAmount() {
--- 13,25 ----
public class TransferOrder extends AssetTransactionContract {
! private TransferOrder(final SignedNamedCore core, final Asset asset, final Identity recipient, final double amount, final String comment) {
super(core, asset);
this.amount = amount;
! this.comment = comment;
! this.recipient=recipient;
}
! public final Identity getRecipient() {
! return recipient;
}
public final double getAmount() {
***************
*** 46,50 ****
}
! private final Identity to;
private final double amount;
--- 31,35 ----
}
! private final Identity recipient;
private final double amount;
***************
*** 64,81 ****
throw new InvalidNamedObjectException(core.getName(),"Incorrect XML Tagname for reader: "+TransferGlobals.XFER_TAGNAME);
! try {
! //TODO Validate properly
! final Asset asset = (Asset) NSResolver.resolveIdentity(elem.attributeValue("assetName"));
!
!
! final double amount = Double.parseDouble(elem.attributeValue("amount"));
! final Identity to = NSResolver.resolveIdentity(elem.attributeValue("recipient"));
! final Element commentElement = elem.element(TransferGlobals.createQName("comment"));
!
! final String comment = (commentElement != null) ? commentElement.getText() : "";
! return new TransferOrder(core, asset, to, amount, comment);
! } catch (NameResolutionException e) {
! throw new InvalidNamedObjectException(core.getName(),e);
! }
}
}
--- 49,58 ----
throw new InvalidNamedObjectException(core.getName(),"Incorrect XML Tagname for reader: "+TransferGlobals.XFER_TAGNAME);
! return new TransferOrder(core,
! TransferGlobals.parseAssetTag(elem),
! TransferGlobals.parseRecipientTag(elem),
! TransferGlobals.parseAmountTag(elem),
! TransferGlobals.getCommentElement(elem)
! );
}
}
Index: TransferReceipt.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/orders/TransferReceipt.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TransferReceipt.java 6 Jan 2004 23:26:48 -0000 1.2
--- TransferReceipt.java 10 Jan 2004 00:00:45 -0000 1.3
***************
*** 1,17 ****
package org.neuclear.asset.orders;
- import org.neuclear.commons.NeuClearException;
- import org.neuclear.commons.time.TimeTools;
- import org.neuclear.id.*;
- import org.neuclear.id.resolver.NSResolver;
- import org.neuclear.asset.orders.TransferContract;
- import org.neuclear.asset.orders.AssetTransactionContract;
- import org.neuclear.asset.contracts.Asset;
- import org.neuclear.asset.contracts.AssetGlobals;
import org.dom4j.Element;
import java.sql.Timestamp;
import java.util.Date;
- import java.text.ParseException;
/**
--- 1,13 ----
package org.neuclear.asset.orders;
import org.dom4j.Element;
+ import org.neuclear.asset.contracts.AssetGlobals;
+ import org.neuclear.id.InvalidNamedObjectException;
+ import org.neuclear.id.NamedObjectReader;
+ import org.neuclear.id.SignedNamedCore;
+ import org.neuclear.id.SignedNamedObject;
import java.sql.Timestamp;
import java.util.Date;
/**
***************
*** 48,74 ****
if (!elem.getNamespace().equals(AssetGlobals.NS_ASSET))
throw new InvalidNamedObjectException(core.getName(),"Not in XML NameSpace: "+AssetGlobals.NS_ASSET.getURI());
! if (elem.getName().equals(TransferGlobals.XFER_TAGNAME))
throw new InvalidNamedObjectException(core.getName(),"Incorrect XML Tagname for reader: "+TransferGlobals.XFER_TAGNAME);
! try {
! //TODO Validate properly
! final Asset asset = (Asset) NSResolver.resolveIdentity(elem.attributeValue("assetName"));
!
!
! final double amount = Double.parseDouble(elem.attributeValue("amount"));
! final Identity to = NSResolver.resolveIdentity(elem.attributeValue("recipient"));
! final Element commentElement = elem.element(TransferGlobals.createQName("comment"));
! final Date valuetime = TimeTools.parseTimeStamp(elem.attributeValue("valuetime"));
! final Identity from = NSResolver.resolveIdentity(elem.attributeValue("sender"));
! final String reqid = elem.attributeValue("reqid");
!
! final String comment = (commentElement != null) ? commentElement.getText() : "";
! return new TransferReceipt(core, asset, from, to, reqid, amount, valuetime, comment);
- } catch (NameResolutionException e) {
- throw new InvalidNamedObjectException(core.getName(),e);
- } catch (ParseException e) {
- throw new InvalidNamedObjectException(core.getName(),e);
- }
}
}
--- 44,54 ----
if (!elem.getNamespace().equals(AssetGlobals.NS_ASSET))
throw new InvalidNamedObjectException(core.getName(),"Not in XML NameSpace: "+AssetGlobals.NS_ASSET.getURI());
! if (!elem.getName().equals(TransferGlobals.XFER_RCPT_TAGNAME))
throw new InvalidNamedObjectException(core.getName(),"Incorrect XML Tagname for reader: "+TransferGlobals.XFER_TAGNAME);
! return new TransferReceipt(core,
! (TransferOrder) TransferGlobals.parseEmbedded(elem,TransferGlobals.createQName(TransferGlobals.XFER_TAGNAME)),
! TransferGlobals.parseValueTimeElement(elem));
}
}
|