Update of /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/exchange/orders
In directory sc8-pr-cvs1:/tmp/cvs-serv22387/src/java/org/neuclear/exchange/orders
Modified Files:
CancelExchangeOrder.java ExchangeCompletionOrder.java
ExchangeGlobals.java ExchangeOrder.java
Log Message:
Cleaned up the schemas even more they now all verifiy.
The Order/Receipt pairs for neuclear pay, should now work. They all have Readers using the latest
Schema.
The TransferBuilders are done and the ExchangeBuilders are nearly there.
The new EmbeddedSignedNamedObject builder is useful for creating new Receipts. The new ReceiptBuilder uses
this to create the embedded transaction.
ExchangeOrders now have the concept of BidItem's, you could create an ExchangeOrder bidding on various items at the same time, to be exchanged as one atomic multiparty exchange.
Still doesnt build yet, but very close now ;-)
Index: CancelExchangeOrder.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/exchange/orders/CancelExchangeOrder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CancelExchangeOrder.java 10 Jan 2004 00:00:46 -0000 1.3
--- CancelExchangeOrder.java 11 Jan 2004 00:39:06 -0000 1.4
***************
*** 18,35 ****
public final class CancelExchangeOrder extends ExchangeTransactionContract{
! private CancelExchangeOrder(final SignedNamedCore core, final Asset asset,final ExchangeAgent agent, final String exchangeid) {
! super(core, asset,agent);
! this.exchangeid = exchangeid;
}
public ExchangeOrderReceipt getExchangeReceipt(){
! //TODO Implement
! return null;
}
- public String getExchangeid() {
- return exchangeid;
- }
! private final String exchangeid;
public static final class Reader implements NamedObjectReader {
--- 18,31 ----
public final class CancelExchangeOrder extends ExchangeTransactionContract{
! private CancelExchangeOrder(final SignedNamedCore core, final ExchangeOrderReceipt receipt) {
! super(core, receipt.getAsset(), receipt.getAgent());
! this.receipt=receipt;
}
public ExchangeOrderReceipt getExchangeReceipt(){
! return receipt;
}
! private final ExchangeOrderReceipt receipt;
public static final class Reader implements NamedObjectReader {
***************
*** 46,52 ****
if (elem.getName().equals(ExchangeGlobals.CANCEL_TAGNAME))
return new CancelExchangeOrder(core,
! TransferGlobals.parseAssetTag(elem),
! ExchangeGlobals.parseAgentTag(elem),
! ExchangeGlobals.parseExchangeOrderId(elem));
throw new InvalidNamedObjectException(core.getName(),"Not Matched");
--- 42,47 ----
if (elem.getName().equals(ExchangeGlobals.CANCEL_TAGNAME))
return new CancelExchangeOrder(core,
! (ExchangeOrderReceipt) TransferGlobals.parseEmbedded(elem,ExchangeGlobals.createQName(ExchangeGlobals.EXCHANGE_RCPT_TAGNAME))
! );
throw new InvalidNamedObjectException(core.getName(),"Not Matched");
Index: ExchangeCompletionOrder.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/exchange/orders/ExchangeCompletionOrder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ExchangeCompletionOrder.java 10 Jan 2004 00:00:46 -0000 1.3
--- ExchangeCompletionOrder.java 11 Jan 2004 00:39:06 -0000 1.4
***************
*** 2,7 ****
import org.neuclear.asset.contracts.Asset;
import org.neuclear.exchange.contracts.ExchangeAgent;
! import org.neuclear.id.SignedNamedCore;
import java.sql.Timestamp;
--- 2,10 ----
import org.neuclear.asset.contracts.Asset;
+ import org.neuclear.asset.contracts.AssetGlobals;
+ import org.neuclear.asset.orders.TransferGlobals;
import org.neuclear.exchange.contracts.ExchangeAgent;
! import org.neuclear.id.*;
! import org.dom4j.Element;
import java.sql.Timestamp;
***************
*** 14,45 ****
*/
public final class ExchangeCompletionOrder extends ExchangeTransactionContract {
! private ExchangeCompletionOrder(final SignedNamedCore core, final Asset asset, final ExchangeAgent agent, final Date valuetime, final double amount, final String holdid, final String counterpartyid) {
! super(core, asset,agent);
! this.valuetime = valuetime.getTime();
this.amount = amount;
! this.holdid = holdid;
! this.counterpartyid = counterpartyid;
}
! public Timestamp getValuetime() {
! return new Timestamp(valuetime);
}
! public double getAmount() {
return amount;
}
! public String getHoldid() {
! return holdid;
! }
!
! public String getCounterpartyid() {
! return counterpartyid;
}
! private final long valuetime;
private final double amount;
! private final String holdid;
! private final String counterpartyid;
}
--- 17,65 ----
*/
public final class ExchangeCompletionOrder extends ExchangeTransactionContract {
! private ExchangeCompletionOrder(final SignedNamedCore core, final ExchangeOrderReceipt receipt, final Identity counterparty, final double amount, final Date exchangetime) {
! super(core,receipt.getAsset(), receipt.getAgent());
! this.exchangetime = exchangetime.getTime();
this.amount = amount;
! this.counterparty=counterparty;
}
! public final Timestamp getExchangeTime() {
! return new Timestamp(exchangetime);
}
! public final double getAmount() {
return amount;
}
! public final Identity getCounterparty() {
! return counterparty;
}
! private final long exchangetime;
private final double amount;
! private final Identity counterparty;
!
! 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());
!
! if (elem.getName().equals(ExchangeGlobals.COMPLETE_TAGNAME)){
! return new ExchangeCompletionOrder(core,
! (ExchangeOrderReceipt)TransferGlobals.parseEmbedded(elem,ExchangeGlobals.createQName(ExchangeGlobals.EXCHANGE_RCPT_TAGNAME)),
! TransferGlobals.parseRecipientTag(elem),
! TransferGlobals.parseAmountTag(elem),
! TransferGlobals.parseTimeStampElement(elem,ExchangeGlobals.createQName(ExchangeGlobals.EXCHANGE_TIME_TAGNAME))
! );
! }
! throw new InvalidNamedObjectException(core.getName(),"Not Matched");
! }
! }
}
Index: ExchangeGlobals.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/exchange/orders/ExchangeGlobals.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ExchangeGlobals.java 10 Jan 2004 00:00:46 -0000 1.2
--- ExchangeGlobals.java 11 Jan 2004 00:39:06 -0000 1.3
***************
*** 29,32 ****
--- 29,42 ----
$Id$
$Log$
+ Revision 1.3 2004/01/11 00:39:06 pelle
+ Cleaned up the schemas even more they now all verifiy.
+ The Order/Receipt pairs for neuclear pay, should now work. They all have Readers using the latest
+ Schema.
+ The TransferBuilders are done and the ExchangeBuilders are nearly there.
+ The new EmbeddedSignedNamedObject builder is useful for creating new Receipts. The new ReceiptBuilder uses
+ this to create the embedded transaction.
+ ExchangeOrders now have the concept of BidItem's, you could create an ExchangeOrder bidding on various items at the same time, to be exchanged as one atomic multiparty exchange.
+ Still doesnt build yet, but very close now ;-)
+
Revision 1.2 2004/01/10 00:00:46 pelle
Implemented new Schema for Transfer*
***************
*** 148,157 ****
}
- public static final Asset parseBidAssetTag(final Element elem) throws InvalidNamedObjectException {
- return parseAssetTag(elem,BID_ASSET_TAG);
- }
- public static final Asset parseSettlementAssetTag(final Element elem) throws InvalidNamedObjectException {
- return parseAssetTag(elem,SETTLEMENT_ASSET_TAG);
- }
public static final Asset parseAssetTag(final Element elem,final String tag) throws InvalidNamedObjectException {
final String name = getElementValue(elem,tag);
--- 158,161 ----
***************
*** 188,197 ****
public static final String CANCEL_TAGNAME = "CancelExchangeOrder";
public static final String CANCEL_RCPT_TAGNAME = "CancelExchangeReceipt";
public static final String EX_NSPREFIX = "ex";
public static final String EX_NSURI = "http://neuclear.org/neu/exch";
! public static final String EXCHANGE_REF_TAG = "ExchangeOrderRef";
! private static final String AGENT_TAG = "ExchangeAgent";
! public static final String SETTLEMENT_ASSET_TAG = "SettlementAsset";
! public static final String BID_ASSET_TAG = "BidAsset";
}
--- 192,203 ----
public static final String CANCEL_TAGNAME = "CancelExchangeOrder";
public static final String CANCEL_RCPT_TAGNAME = "CancelExchangeReceipt";
+ public static final String EXPIRY_TAG = "ExpiryDate";
+ public static final String EXCHANGE_REF_TAG = "ExchangeOrderRef";
+ public static final String EXCHANGE_TIME_TAGNAME = "ExchangeTime";
+ public static final String AGENT_TAG = "ExchangeAgent";
+ public static final String BID_ITEM_TAG = "BidItem";
public static final String EX_NSPREFIX = "ex";
public static final String EX_NSURI = "http://neuclear.org/neu/exch";
!
}
Index: ExchangeOrder.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/exchange/orders/ExchangeOrder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ExchangeOrder.java 10 Jan 2004 00:00:46 -0000 1.3
--- ExchangeOrder.java 11 Jan 2004 00:39:06 -0000 1.4
***************
*** 10,13 ****
--- 10,16 ----
import java.sql.Timestamp;
import java.util.Date;
+ import java.util.Iterator;
+ import java.util.ArrayList;
+ import java.util.List;
/**
***************
*** 19,30 ****
private ExchangeOrder(final SignedNamedCore core,
final Asset bidAsset, final ExchangeAgent agent, final double bid,
! final Asset neededAsset, final double neededAmount, final String comment, final Date expires) {
super(core, bidAsset,agent);
! this.neededAsset = neededAsset;
! this.neededAmount = neededAmount;
this.bidAmount = bid;
this.comment = (comment != null) ? comment : "";
this.expires = expires.getTime();
}
public final Date getExpiry() {
--- 22,38 ----
private ExchangeOrder(final SignedNamedCore core,
final Asset bidAsset, final ExchangeAgent agent, final double bid,
! BidItem items[], final String comment, final Date expires) {
super(core, bidAsset,agent);
! this.items =makeSafeCopy(items);
this.bidAmount = bid;
this.comment = (comment != null) ? comment : "";
this.expires = expires.getTime();
}
+ private static BidItem[] makeSafeCopy(final BidItem src[]) {
+ BidItem items[]= new BidItem[src.length];
+ for (int i=0;i<src.length;i++)
+ items[i]=src[i];
+ return items;
+ }
public final Date getExpiry() {
***************
*** 36,60 ****
}
- public Asset getNeededAsset() {
- return neededAsset;
- }
-
- public double getNeededAmount() {
- return neededAmount;
- }
! public double getBidAmount() {
return bidAmount;
}
! public String getComment() {
return comment;
}
! private final Asset neededAsset;
! private final double neededAmount;
private final double bidAmount;
private final String comment;
private final long expires;
public static final class Reader implements NamedObjectReader {
/**
--- 44,93 ----
}
! public final double getBidAmount() {
return bidAmount;
}
! public final String getComment() {
return comment;
}
! public final Iterator iterateBidItems(){
! return new Iterator(){
! private int i=0;
! public void remove() {
! }
!
! public boolean hasNext() {
! return i<items.length;
! }
!
! public Object next() {
! return items[i++];
! }
! };
! }
private final double bidAmount;
private final String comment;
private final long expires;
+ private final BidItem items[];
+
+ public static class BidItem {
+ private BidItem(Asset asset, double amount) {
+ this.asset = asset;
+ this.amount = amount;
+ }
+
+ public final Asset getAsset() {
+ return asset;
+ }
+
+ public final double getAmount() {
+ return amount;
+ }
+
+ private final Asset asset;
+ private final double amount;
+ }
public static final class Reader implements NamedObjectReader {
/**
***************
*** 70,82 ****
if (elem.getName().equals(ExchangeGlobals.EXCHANGE_TAGNAME))
return new ExchangeOrder(core,
! ExchangeGlobals.parseBidAssetTag(elem),
ExchangeGlobals.parseAgentTag(elem),
TransferGlobals.parseAmountTag(elem),
! ExchangeGlobals.parseSettlementAssetTag(elem),
! TransferGlobals.parseAmountTag(elem),
TransferGlobals.getCommentElement(elem),
! null//TODO getExpiryTime
);
throw new InvalidNamedObjectException(core.getName(),"Not Matched");
}
--- 103,129 ----
if (elem.getName().equals(ExchangeGlobals.EXCHANGE_TAGNAME))
return new ExchangeOrder(core,
! TransferGlobals.parseAssetTag(elem),
ExchangeGlobals.parseAgentTag(elem),
TransferGlobals.parseAmountTag(elem),
! parseBidItems(elem),
TransferGlobals.getCommentElement(elem),
! TransferGlobals.parseTimeStampElement(elem,ExchangeGlobals.createQName(ExchangeGlobals.EXPIRY_TAG))
);
throw new InvalidNamedObjectException(core.getName(),"Not Matched");
+ }
+
+ private BidItem[] parseBidItems(Element elem) throws InvalidNamedObjectException {
+ List list=elem.elements(ExchangeGlobals.createQName(ExchangeGlobals.BID_ITEM_TAG));
+ BidItem items[]=new BidItem[list.size()];
+ for (int i = 0; i < list.size(); i++)
+ items[i]= parseBidItem(elem);
+ return items;
+ }
+
+ private BidItem parseBidItem(Element element) throws InvalidNamedObjectException {
+ return new BidItem(
+ TransferGlobals.parseAssetTag(element),
+ TransferGlobals.parseAmountTag(element));
+
}
|