Update of /cvsroot/neuclear/neuclear-pay/src/java/org/neuclear/asset/orders
In directory sc8-pr-cvs1:/tmp/cvs-serv15193/src/java/org/neuclear/asset/orders
Added Files:
AssetTransactionContract.java TransferContract.java
TransferGlobals.java TransferOrder.java TransferReceipt.java
Log Message:
Create new Document classification "order", which is really just inherint in the new
package layout.
Got rid of much of the inheritance that was lying around and thought a bit further about the format of the exchange orders.
--- NEW FILE: AssetTransactionContract.java ---
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;
/**
* (C) 2003 Antilles Software Ventures SA
* User: pelleb
* Date: Nov 10, 2003
* Time: 11:06:37 AM
* $Id: AssetTransactionContract.java,v 1.1 2004/01/05 23:47:09 pelle Exp $
* $Log: AssetTransactionContract.java,v $
* Revision 1.1 2004/01/05 23:47:09 pelle
* Create new Document classification "order", which is really just inherint in the new
* package layout.
* Got rid of much of the inheritance that was lying around and thought a bit further about the format of the exchange orders.
*
* Revision 1.11 2004/01/03 20:36:25 pelle
* Renamed HeldTransfer to Exchange
* Dropped valuetime from the request objects.
* Doesnt yet compile. New commit to follow soon.
*
* 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
* Fixed some stuff in IdentityCreator
* New maven goal to create executable jarapp
* We are close to 0.8 final of ID, 0.11 final of XMLSIG and 0.5 of commons.
* Will release shortly.
*
* Revision 1.8 2003/11/28 00:11:50 pelle
* Getting the NeuClear web transactions working.
* <p/>
* Revision 1.7 2003/11/22 00:22:28 pelle
* All unit tests in commons, id and xmlsec now work.
* AssetController now successfully processes payments in the unit test.
* Payment Web App has working form that creates a TransferOrder presents it to the signer
* and forwards it to AssetControlServlet. (Which throws an XML Parser Exception) I think the XMLReaderServlet is bust.
* <p/>
* Revision 1.6 2003/11/21 04:43:04 pelle
* EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
* Otherwise You will Finaliate.
* Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
* This should hopefully make everything more stable (and secure).
* <p/>
* Revision 1.5 2003/11/20 16:01:59 pelle
* Updated all the Contracts to use the new security model.
* <p/>
* Revision 1.4 2003/11/19 23:32:20 pelle
* Signers now can generatekeys via the generateKey() method.
* Refactored the relationship between SignedNamedObject and NamedObjectBuilder a bit.
* SignedNamedObject now contains the full xml which is returned with getEncoded()
* This means that it is now possible to further receive on or process a SignedNamedObject, leaving
* NamedObjectBuilder for its original purposes of purely generating new Contracts.
* NamedObjectBuilder.sign() now returns a SignedNamedObject which is the prefered way of processing it.
* Updated all major interfaces that used the old model to use the new model.
* <p/>
* Revision 1.3 2003/11/12 23:47:04 pelle
* Much work done in creating good test environment.
* PaymentReceiverTest works, but needs a abit more work in its environment to succeed testing.
* <p/>
* Revision 1.2 2003/11/11 21:17:19 pelle
* Further vital reshuffling.
* org.neudist.crypto.* and org.neudist.utils.* have been moved to respective areas under org.neuclear.commons
* org.neuclear.signers.* as well as org.neuclear.passphraseagents have been moved under org.neuclear.commons.crypto as well.
* Did a bit of work on the Canonicalizer and changed a few other minor bits.
* <p/>
* Revision 1.1 2003/11/10 17:42:07 pelle
* The AssetController interface has been more or less finalized.
* CurrencyController fully implemented
* AssetControlClient implementes a remote client for communicating with AssetControllers
*/
public abstract class AssetTransactionContract extends SignedNamedObject {
private final Asset asset;
protected AssetTransactionContract(final SignedNamedCore core, final Asset asset) {
super(core);
this.asset = asset;
}
public final Asset getAsset() {
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");
}
}
}
--- NEW FILE: TransferContract.java ---
package org.neuclear.asset.orders;
import org.dom4j.Element;
import org.neuclear.id.Identity;
import org.neuclear.id.NamedObjectReader;
import org.neuclear.id.SignedNamedObject;
import org.neuclear.id.SignedNamedCore;
import org.neuclear.id.resolver.NSResolver;
import org.neuclear.receiver.UnsupportedTransaction;
import org.neuclear.commons.NeuClearException;
import org.neuclear.asset.NegativeTransferException;
import org.neuclear.asset.InvalidTransferException;
import org.neuclear.asset.contracts.Asset;
import org.neuclear.asset.orders.AssetTransactionContract;
import org.neuclear.commons.time.TimeTools;
import org.neuclear.commons.Utility;
import org.neuclear.xml.XMLTools;
import java.sql.Timestamp;
import java.util.Date;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
*
* User: pelleb
* Date: Sep 23, 2003
* Time: 3:07:54 PM
*/
public abstract class TransferContract extends AssetTransactionContract {
TransferContract(final SignedNamedCore core, final Asset asset, final double amount, final String comment) {
super(core, asset);
this.amount = amount;
this.comment = (comment != null) ? comment : "";
}
public final double getAmount() {
return amount;
}
public final String getComment() {
return comment;
}
private final double amount;
private final String comment;
}
--- NEW FILE: TransferGlobals.java ---
package org.neuclear.asset.orders;
import org.dom4j.*;
import org.neuclear.id.verifier.VerifyingReader;
import org.neuclear.asset.orders.AssetTransactionContract;
import org.neuclear.asset.orders.AssetTransactionContract;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: TransferGlobals.java,v 1.1 2004/01/05 23:47:09 pelle Exp $
$Log: TransferGlobals.java,v $
Revision 1.1 2004/01/05 23:47:09 pelle
Create new Document classification "order", which is really just inherint in the new
package layout.
Got rid of much of the inheritance that was lying around and thought a bit further about the format of the exchange orders.
Revision 1.6 2004/01/03 20:36:25 pelle
Renamed HeldTransfer to Exchange
Dropped valuetime from the request objects.
Doesnt yet compile. New commit to follow soon.
Revision 1.5 2003/11/28 00:11:50 pelle
Getting the NeuClear web transactions working.
Revision 1.4 2003/11/22 00:22:28 pelle
All unit tests in commons, id and xmlsec now work.
AssetController now successfully processes payments in the unit test.
Payment Web App has working form that creates a TransferOrder presents it to the signer
and forwards it to AssetControlServlet. (Which throws an XML Parser Exception) I think the XMLReaderServlet is bust.
Revision 1.3 2003/11/21 04:43:04 pelle
EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
Otherwise You will Finaliate.
Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
This should hopefully make everything more stable (and secure).
Revision 1.2 2003/11/10 17:42:07 pelle
The AssetController interface has been more or less finalized.
CurrencyController fully implemented
AssetControlClient implementes a remote client for communicating with AssetControllers
Revision 1.1 2003/11/09 03:32:56 pelle
More missing files from earlier commits. IDEA is acting strangly.
Revision 1.3 2003/11/06 23:47:43 pelle
Major Refactoring of CurrencyController.
Factored out AssetController to be new abstract parent class together with most of its support classes.
Created (Half way) AssetControlClient, which can perform transactions on external AssetControllers via NeuClear.
Created the first attempt at the ExchangeAgent. This will need use of the AssetControlClient.
SOAPTools was changed to return a stream. This is required by the VerifyingReader in NeuClear.
Revision 1.2 2003/10/25 00:38:43 pelle
Fixed SmtpSender it now sends the messages.
Refactored CommandLineSigner. Now it simply signs files read from command line. However new class IdentityCreator
is subclassed and creates new Identities. You can subclass CommandLineSigner to create your own variants.
Several problems with configuration. Trying to solve at the moment. Updated PicoContainer to beta-2
Revision 1.1 2003/10/03 23:48:29 pelle
Did various security related updates in the pay package with regards to immutability of fields etc.
PaymentReceiver should now be operational. Real testing needs to be done including in particular setting the
private key of the Receiver.
A new class TransferGlobals contains usefull settings for making life easier in the other contract based classes.
TransferContract the signed contract is functional and has a matching TransferRequestBuilder class for programmatically creating
TransferRequests for signing.
TransferReceiptBuilder has been created for use by Transfer processors. It is used in the PaymentReceiver.
*/
/**
* User: pelleb
* Date: Oct 3, 2003
* Time: 3:55:06 PM
*/
public final class TransferGlobals {
private TransferGlobals() {
// Instantiation is not allowed
}
public static Namespace createNameSpace() {
return DocumentHelper.createNamespace(XFER_NSPREFIX, XFER_NSURI);
}
public static QName createQName(final String name) {
return DocumentHelper.createQName(name, createNameSpace());
}
public static Attribute createAttribute(final Element elem, final String name, final String value) {
return DocumentHelper.createAttribute(elem, createQName(name), value);
}
public static Element createElement(final String name, final String value) {
Element elem = createElement(name);
elem.setText(value);
return elem;
}
public static Element createElement(final String name) {
return DocumentHelper.createElement(createQName(name));
}
public static void registerReaders() {
VerifyingReader.getInstance().registerReader(TransferGlobals.CANCEL_RCPT_TAGNAME, new AssetTransactionContract.Reader());
VerifyingReader.getInstance().registerReader(TransferGlobals.CANCEL_TAGNAME, new AssetTransactionContract.Reader());
VerifyingReader.getInstance().registerReader(TransferGlobals.XFER_TAGNAME, new AssetTransactionContract.Reader());
VerifyingReader.getInstance().registerReader(TransferGlobals.HELD_XFER_TAGNAME, new AssetTransactionContract.Reader());
VerifyingReader.getInstance().registerReader(TransferGlobals.XFER_RCPT_TAGNAME, new AssetTransactionContract.Reader());
VerifyingReader.getInstance().registerReader(TransferGlobals.HELD_XFER_RCPT_TAGNAME, new AssetTransactionContract.Reader());
VerifyingReader.getInstance().registerReader(TransferGlobals.COMPLETE_TAGNAME, new AssetTransactionContract.Reader());
}
static {
registerReaders();
}
public static final String XFER_TAGNAME = "TransferOrder";
public static final String XFER_RCPT_TAGNAME = "TransferReceipt";
public static final String HELD_XFER_TAGNAME = "ExchangeOrder";
public static final String HELD_XFER_RCPT_TAGNAME = "ExchangeOrderReceipt";
public static final String COMPLETE_TAGNAME = "CompleteHoldRequest";
public static final String CANCEL_TAGNAME = "CancelHoldRequest";
public static final String CANCEL_RCPT_TAGNAME = "CancelHoldReceipt";
public static final String XFER_NSPREFIX = "xfer";
public static final String XFER_NSURI = "http://neuclear.org/neu/xfer";
}
--- NEW FILE: TransferOrder.java ---
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;
/**
* User: pelleb
* Date: Jul 21, 2003
* Time: 5:35:26 PM
*/
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() {
return amount;
}
public final String getComment() {
return comment;
}
private final Identity to;
private final double amount;
private final String comment;
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(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 String comment = (commentElement != null) ? commentElement.getText() : "";
return new TransferOrder(core, asset, to, amount, comment);
} catch (NameResolutionException e) {
throw new InvalidNamedObjectException(core.getName(),e);
}
}
}
}
--- NEW FILE: TransferReceipt.java ---
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;
/**
* User: pelleb
* Date: Jul 21, 2003
* Time: 5:37:10 PM
*/
public class TransferReceipt extends AssetTransactionContract {
private 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);
this.from = from;
this.reqid = reqid;
this.to=to;
this.valuetime=valuetime.getTime();
this.amount = amount;
this.comment = (comment != null) ? comment : "";
}
public final Identity getFrom() {
return from;
}
public final String getRequestId() {
return reqid;
}
public final Identity getTo() {
return to;
}
public final Date getValueTime() {
return new Timestamp(valuetime);
}
public final double getAmount() {
return amount;
}
public final String getComment() {
return comment;
}
private final double amount;
private final String comment;
private final long valuetime;
private final Identity from;
private final String reqid;
private final Identity to;
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(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);
}
}
}
}
|