anon.pay
Class PayAccount

java.lang.Object
  extended by anon.pay.PayAccount
All Implemented Interfaces:
IXMLEncodable

public class PayAccount
extends java.lang.Object
implements IXMLEncodable

This class encapsulates one account and all additional data associated to one account. This includes the key pair, the account number, the transfer certificates for charging the account, cost confirmations and a balance certificate. For storing the account data in a file the toXmlElement() method is provided. It is recommended to encrypt the output of this method before storing it to disk, because it includes the secret private key. The XML structure is as follows: ... // see anon.pay.xml.XMLAccountCertificate ... // the secret key. this can be either RSA or DSA ... // see anon.pay.xml.XMLTransCert .... ... // see anon.pay.xml.XMLAccountInfo

Author:
Andreas Mueller, Grischan Glänzel, Bastian Voigt, Tobias Bayer

Field Summary
private  XMLAccountCertificate m_accountCertificate
          contains the account certificate
private  XMLAccountInfo m_accountInfo
          contains the current account info (balance and cost confirmations)
private  java.util.Vector m_accountListeners
           
private  boolean m_bBackupDone
           
private  long m_currentBytes
          the number of bytes which have been used bot not confirmed yet
private  org.w3c.dom.Document m_encryptedPrivateKey
           
private  long m_mySpent
          internal value for spent bytes.
private  IMyPrivateKey m_privateKey
          contains the private key associated with this account
private  java.lang.String m_strBiID
           
private  BI m_theBI
           
private  java.util.Vector m_transCerts
          contains zero or more xml transfer certificates as XMLTransCert
private static java.lang.String VERSION
           
private static java.lang.String XML_ATTR_ACTIVE
           
private static java.lang.String XML_BACKUP_DONE
           
static java.lang.String XML_ELEMENT_NAME
           
 
Fields inherited from interface anon.util.IXMLEncodable
FIELD_XML_ELEMENT_CONTAINER_NAME, FIELD_XML_ELEMENT_NAME, XML_ATTR_ID, XML_ATTR_VERSION
 
Constructor Summary
PayAccount(org.w3c.dom.Element elemRoot, IMiscPasswordReader a_passwordReader)
           
PayAccount(XMLAccountCertificate certificate, IMyPrivateKey privateKey, BI theBI)
          Creates a PayAccount Objekt from the account certificate and the private key.
 
Method Summary
 void addAccountListener(IAccountListener listener)
           
 void addCostConfirmation(XMLEasyCC cc)
          addCostConfirmation
 void addTransCert(XMLTransCert cert)
           
 XMLTransCert charge(IMutableProxyInterface a_proxys)
          Request a transfer certificate from the BI
private  void deactivate(org.w3c.dom.Element elemKey)
           
 void decryptPrivateKey(IMiscPasswordReader a_passwordReader)
           
private  void decryptPrivateKey(org.w3c.dom.Node a_elemRoot, IMiscPasswordReader a_passwordReader, boolean a_bDeactivated)
           
 XMLAccountInfo fetchAccountInfo(IMutableProxyInterface a_proxys, boolean a_bForce)
          Requests an AccountInfo XML structure from the BI.
private  void fireChangeEvent()
           
 XMLAccountCertificate getAccountCertificate()
           
 XMLAccountInfo getAccountInfo()
           
 long getAccountNumber()
          Returns the account's accountnumber
 XMLBalance getBalance()
          getBalance
 java.sql.Timestamp getBalanceValidTime()
          liefert zurueck, wann das Guthaben ungueltig wird (bei flatrate modellen)
 BI getBI()
           
 long getCertifiedCredit()
          Returns the current credit (i.
 java.sql.Timestamp getCreationTime()
          Liefert das Erstellungsdatum des Kontos.
 long getCurrentCredit()
          Returns the current credit (i.
 long getDeposit()
          Returns the initial amount of the account (i.
 IMyPrivateKey getPrivateKey()
          Returns the private key or null if the account is encrypted and not usable.
 IMyPublicKey getPublicKey()
           
 long getSpent()
          Returns the amount already spent.
 java.util.Vector getTransCerts()
          Returns a vector with all transfer certificates
 boolean hasAccountInfo()
          Returns true when an accountInfo object exists.
 boolean isBackupDone()
           
 void setAccountInfo(XMLAccountInfo info)
          This is not just a setter method.
 void setBackupDone(boolean a_bDone)
           
private  void setValues(org.w3c.dom.Element elemRoot, IMiscPasswordReader a_passwordReader)
           
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
          Returns the xml representation of the account
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc, java.lang.String a_password)
           
 long updateCurrentBytes(PacketCounter a_packetCounter)
          Asks the PacketCounter for the current number of transferred bytes and updates the internal value.
 void updated()
          Marks the account as updated so a ChangeEvent gets fired
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_ELEMENT_NAME

public static final java.lang.String XML_ELEMENT_NAME
See Also:
Constant Field Values

XML_ATTR_ACTIVE

private static final java.lang.String XML_ATTR_ACTIVE
See Also:
Constant Field Values

XML_BACKUP_DONE

private static final java.lang.String XML_BACKUP_DONE
See Also:
Constant Field Values

VERSION

private static final java.lang.String VERSION
See Also:
Constant Field Values

m_transCerts

private java.util.Vector m_transCerts
contains zero or more xml transfer certificates as XMLTransCert


m_accountCertificate

private XMLAccountCertificate m_accountCertificate
contains the account certificate


m_accountInfo

private XMLAccountInfo m_accountInfo
contains the current account info (balance and cost confirmations)


m_privateKey

private IMyPrivateKey m_privateKey
contains the private key associated with this account


m_encryptedPrivateKey

private org.w3c.dom.Document m_encryptedPrivateKey

m_currentBytes

private long m_currentBytes
the number of bytes which have been used bot not confirmed yet


m_accountListeners

private java.util.Vector m_accountListeners

m_bBackupDone

private boolean m_bBackupDone

m_mySpent

private long m_mySpent
internal value for spent bytes. Basically this is the same as spent in XMLBalance, but the value in XMLBalance is calculated by the BI while this here is calculated by the Jap. So the value here might be more up to date in case the XMLBalance certificate is old.


m_theBI

private BI m_theBI

m_strBiID

private java.lang.String m_strBiID
Constructor Detail

PayAccount

public PayAccount(org.w3c.dom.Element elemRoot,
                  IMiscPasswordReader a_passwordReader)
           throws java.lang.Exception
Throws:
java.lang.Exception

PayAccount

public PayAccount(XMLAccountCertificate certificate,
                  IMyPrivateKey privateKey,
                  BI theBI)
           throws java.lang.Exception
Creates a PayAccount Objekt from the account certificate and the private key.

Parameters:
certificate - account certificate issued by the BI
privateKey - the private key
Throws:
java.lang.Exception
Method Detail

setValues

private void setValues(org.w3c.dom.Element elemRoot,
                       IMiscPasswordReader a_passwordReader)
                throws java.lang.Exception
Parameters:
elemRoot - Element
a_passwordReader - a password reader; this method adds the account number as message object
Throws:
java.lang.Exception

toXmlElement

public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
Returns the xml representation of the account

Specified by:
toXmlElement in interface IXMLEncodable
Parameters:
a_doc - a document
Returns:
XML-Document

toXmlElement

public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc,
                                        java.lang.String a_password)

addTransCert

public void addTransCert(XMLTransCert cert)
                  throws java.lang.Exception
Throws:
java.lang.Exception

setAccountInfo

public void setAccountInfo(XMLAccountInfo info)
                    throws java.lang.Exception
This is not just a setter method. If an accountInfo is already present, only older information is overwritten with newer information.

Parameters:
info - XMLAccountInfo
Throws:
java.lang.Exception

getAccountNumber

public long getAccountNumber()
Returns the account's accountnumber

Returns:
accountnumber

isBackupDone

public boolean isBackupDone()

setBackupDone

public void setBackupDone(boolean a_bDone)

hasAccountInfo

public boolean hasAccountInfo()
Returns true when an accountInfo object exists. New accounts don't have this, it is created when we first fetch a balance certificate or sign the first CC.


getAccountCertificate

public XMLAccountCertificate getAccountCertificate()

getCreationTime

public java.sql.Timestamp getCreationTime()
Liefert das Erstellungsdatum des Kontos.

Returns:
Erstellungsdatum

getBalanceValidTime

public java.sql.Timestamp getBalanceValidTime()
liefert zurueck, wann das Guthaben ungueltig wird (bei flatrate modellen)

Returns:
Date Gueltigkeitsdatum

getPrivateKey

public IMyPrivateKey getPrivateKey()
Returns the private key or null if the account is encrypted and not usable.

Returns:
the private key or null if the account is encrypted and not usable

getPublicKey

public IMyPublicKey getPublicKey()

getSpent

public long getSpent()
Returns the amount already spent.

Returns:
Gesamtsumme

getDeposit

public long getDeposit()
Returns the initial amount of the account (i. e. the sum of all incoming payment)

Returns:
Gesamtsumme

getCertifiedCredit

public long getCertifiedCredit()
Returns the current credit (i. e. deposit - spent) as certified by the BI. It is possible that this value is outdated, so it may be a good idea to call Pay.fetchAccountInfo(long) first.

Returns:
Guthaben

getCurrentCredit

public long getCurrentCredit()
Returns the current credit (i. e. deposit - spent) as counted by the Jap itself. It is possible that this value is outdated, so it may be a good idea to call updateCurrentBytes() first.

Returns:
long

getAccountInfo

public XMLAccountInfo getAccountInfo()

getTransCerts

public java.util.Vector getTransCerts()
Returns a vector with all transfer certificates

Returns:
Vector von XMLTransCert

updateCurrentBytes

public long updateCurrentBytes(PacketCounter a_packetCounter)
                        throws java.lang.Exception
Asks the PacketCounter for the current number of transferred bytes and updates the internal value.

Returns:
the updated currentBytes value
Throws:
java.lang.Exception

addCostConfirmation

public void addCostConfirmation(XMLEasyCC cc)
                         throws java.lang.Exception
addCostConfirmation

Throws:
java.lang.Exception

addAccountListener

public void addAccountListener(IAccountListener listener)

fireChangeEvent

private void fireChangeEvent()

getBalance

public XMLBalance getBalance()
getBalance

Returns:
XMLBalance

fetchAccountInfo

public XMLAccountInfo fetchAccountInfo(IMutableProxyInterface a_proxys,
                                       boolean a_bForce)
                                throws java.lang.SecurityException,
                                       java.lang.Exception
Requests an AccountInfo XML structure from the BI.

Parameters:
a_bForce - if the update is forced; if not, it might be prevented by PayAccountsFile.isBalanceAutoUpdateEnabled()
Returns:
XMLAccountInfo
Throws:
java.lang.Exception
java.lang.SecurityException - if the account is encrypted an not usable

charge

public XMLTransCert charge(IMutableProxyInterface a_proxys)
                    throws java.lang.SecurityException,
                           java.lang.Exception
Request a transfer certificate from the BI

Parameters:
accountNumber - account number
Returns:
xml transfer certificate
Throws:
java.lang.Exception
java.lang.SecurityException - if the account is encrypted an not usable

updated

public void updated()
Marks the account as updated so a ChangeEvent gets fired


getBI

public BI getBI()

decryptPrivateKey

public void decryptPrivateKey(IMiscPasswordReader a_passwordReader)
                       throws java.lang.Exception
Throws:
java.lang.Exception

decryptPrivateKey

private void decryptPrivateKey(org.w3c.dom.Node a_elemRoot,
                               IMiscPasswordReader a_passwordReader,
                               boolean a_bDeactivated)
                        throws java.lang.Exception
Throws:
java.lang.Exception

deactivate

private void deactivate(org.w3c.dom.Element elemKey)
                 throws java.lang.Exception
Throws:
java.lang.Exception