Agent System POND 1.2 (28.2.2002)

FIM.payment
Class AnonymousInvoice

java.lang.Object
  |
  +--FIM.payment.AnonymousInvoice
All Implemented Interfaces:
Invoice, Serializable, XMLEncodeable
Direct Known Subclasses:
NamedInvoice

public class AnonymousInvoice
extends Object
implements Invoice

An invoice for an anonymous recipient.

Version:
1.0
Author:
Michael Sonntag
See Also:
Serialized Form

Constructor Summary
protected AnonymousInvoice()
          Creates a new empty invoice.
  AnonymousInvoice(Element elem)
          Create a new anonymous invoice from an XML element.
  AnonymousInvoice(String issuer, Certificate issuerCert, Date date, String title, InvoiceItem[] items)
          Create a new anonymous invoice.
 
Method Summary
 void decodeXMLElement(Element elem)
          Parse back the invoice from an XML element.
 Serializable getAsSerializable()
          Retrieve the invoice as a serializable (just returns this as this object is directly serializable).
 Element getAsXMLElement(Document doc)
          Retrieve the invoice as an XML element (name: AnonymousInvoice).
 Certificate getCertificate()
          Retrieve the certificate passed in upon signing.
 Date getDate()
          Retrieve the date of the invoice.
 byte[] getEncoded()
          Retrieve the invoice in encoded form to be used for signing.
 String getIssuer()
          Retrieve the issuer of the invoice as a string.
 Certificate getIssuerCertificate()
          Retrieve the issuer of the invoice as a certificate (might be null).
 InvoiceItem[] getItems()
          Retrieve the items contained within the invoice (items or lines).
 String getTitle()
          Retrieve the title of the invoice.
 Price getTotalPrice()
          Retrieve the total value of all items in the invoice.
 boolean isSigned()
          Check whether this invoice is signed or not.
 void sign(String signAlgorithm, PrivateKey pk, Certificate cert)
          Sign the invoice.
 String toString()
          Retrieve the invoice as a string, suitable for presenting to the user in a very simple form.
 void verifySignature(String provider)
          Verify the signature of the invoice based on the certificate contained.
 void verifySignature(String provider, PublicKey pk)
          Verify the signature of the invoice based on the public key passed in.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AnonymousInvoice

public AnonymousInvoice(String issuer,
                        Certificate issuerCert,
                        Date date,
                        String title,
                        InvoiceItem[] items)
Create a new anonymous invoice. The currencies of the items must all be the same. Not both issuer and issuerCert may be null.
Parameters:
issuer - the issuer of the invoice
issuerCert - the certificate of the issuer of the invoice
data - the date for the invoice
title - the title of the invoice
item - an array of items for the invoice. At least one required

AnonymousInvoice

protected AnonymousInvoice()
Creates a new empty invoice. Necessary so subclasses can create an empty object and then parse in the values from XML. Subclasses doing this must call decodeXMLElement.

AnonymousInvoice

public AnonymousInvoice(Element elem)
Create a new anonymous invoice from an XML element.
Parameters:
elem - the XML element containing the encoded form
Method Detail

getIssuer

public String getIssuer()
Retrieve the issuer of the invoice as a string.
Specified by:
getIssuer in interface Invoice
Returns:
the issuer of the invoice

getIssuerCertificate

public Certificate getIssuerCertificate()
Retrieve the issuer of the invoice as a certificate (might be null).
Specified by:
getIssuerCertificate in interface Invoice
Returns:
the issuer of the invoice or null

getDate

public Date getDate()
Retrieve the date of the invoice.
Specified by:
getDate in interface Invoice
Returns:
the date of the invoice

getTotalPrice

public Price getTotalPrice()
Retrieve the total value of all items in the invoice.
Specified by:
getTotalPrice in interface Invoice
Returns:
the total price

getTitle

public String getTitle()
Retrieve the title of the invoice.
Specified by:
getTitle in interface Invoice
Returns:
the title of the invoice

getItems

public InvoiceItem[] getItems()
Retrieve the items contained within the invoice (items or lines).
Specified by:
getItems in interface Invoice
Returns:
the items of the invoice

isSigned

public boolean isSigned()
Check whether this invoice is signed or not.
Specified by:
isSigned in interface Invoice
Returns:
true if the invoice is signed

sign

public void sign(String signAlgorithm,
                 PrivateKey pk,
                 Certificate cert)
          throws InvalidKeyException,
                 NoSuchAlgorithmException
Sign the invoice.
Specified by:
sign in interface Invoice
Parameters:
signAlgorithm - the algorithm to be used for signing
pk - the private key to be used for signing
cert - the certificate of the public key associated with the private key (can be null)
Throws:
InvalidKeyException - if the private key is invalid
NoSuchAlgorithmException - if the algorithm is not supported

getCertificate

public Certificate getCertificate()
Retrieve the certificate passed in upon signing. Is null if non provided then.
Specified by:
getCertificate in interface Invoice
Returns:
the certificate of the signer or null

verifySignature

public void verifySignature(String provider)
                     throws NoSuchAlgorithmException,
                            InvalidKeyException,
                            NoSuchProviderException,
                            SignatureException
Verify the signature of the invoice based on the certificate contained. Will fail if not signed or if no certificate is present.
Specified by:
verifySignature in interface Invoice
Parameters:
provider - the security provider to be used for checking. if null, the standard provider is used
Throws:
InvalidKeyException - if the public key is invalid
NoSuchAlgorithmException - if the algorithm used for signing is not supported
InvalidKeyException - if the key in the certificate is erroneous
NoSuchProviderException - if the security provider could not be found
SignatureException - if the signature is invalid

verifySignature

public void verifySignature(String provider,
                            PublicKey pk)
                     throws NoSuchAlgorithmException,
                            InvalidKeyException,
                            NoSuchProviderException,
                            SignatureException
Verify the signature of the invoice based on the public key passed in. Will fail if not signed. Teh certificate included is ignored.
Specified by:
verifySignature in interface Invoice
Parameters:
provider - the security provider to be used for checking. if null, the standard provider is used
pk - the public key to use for verification. If null, the key from the certificate is used (if no certificate in this case, verification fails)
Throws:
NoSuchAlgorithmException - if the algorithm used for signing is not supported
InvalidKeyException - if the public key (or the key in the certificate) is invalid
NoSuchProviderException - if the security provider could not be found
SignatureException - if the signature is invalid

getEncoded

public byte[] getEncoded()
Retrieve the invoice in encoded form to be used for signing. Does NOT include the signing information itself (which will be created based on the result!). Must be exactly the same on all calls and if the content is the same.
Specified by:
getEncoded in interface Invoice
Returns:
the invoice in encoded form

toString

public String toString()
Retrieve the invoice as a string, suitable for presenting to the user in a very simple form.
Specified by:
toString in interface Invoice
Overrides:
toString in class Object
Returns:
the invoice encoded as a string

getAsSerializable

public Serializable getAsSerializable()
Retrieve the invoice as a serializable (just returns this as this object is directly serializable).
Specified by:
getAsSerializable in interface XMLEncodeable
Returns:
the price object as a serializable

getAsXMLElement

public Element getAsXMLElement(Document doc)
Retrieve the invoice as an XML element (name: AnonymousInvoice).
Specified by:
getAsXMLElement in interface XMLEncodeable
Parameters:
doc - the document within which to create the element
Returns:
the price as an element

decodeXMLElement

public void decodeXMLElement(Element elem)
                      throws IllegalArgumentException
Parse back the invoice from an XML element.
Specified by:
decodeXMLElement in interface XMLEncodeable
Parameters:
elem - the element containing the price to parse back
Throws:
IllegalArgumentException - if the element is incorrect (e. g. wrong tag name)

Agent System POND 1.2 (28.2.2002)

Submit a bug

Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.