anon.pay
Class PayAccountsFile

java.lang.Object
  extended by anon.pay.PayAccountsFile
All Implemented Interfaces:
IBIConnectionListener, IXMLEncodable

public class PayAccountsFile
extends java.lang.Object
implements IXMLEncodable, IBIConnectionListener

This class encapsulates a collection of accounts. One of the accounts in the collection is always active, except when the collection is empty. GUI classes can register a IPaymentListener with this class to be informed about all payment specific events. The class can be initialized from an XML structure and can also save all internal information in an XML structure before shutdown. For saving the accounts information, the following XML structure is used:

 <PayAccountsFile version="1.0">
    <MainAccountNumber>123465</MainAccountNumber>
    <Accounts>
       <Account version="1.0">
                    <AccountCertificate>...</AccountCertificate> // Kontozertiufkat von der BI unterschrieben
                    <RSAPrivateKey>...</RSAPrivateKey> //der geheime Schl?ssel zum Zugriff auf das Konto
                    <TransferCertificates> //offenen Transaktionsummern
                            ....
                    </TransferCertifcates>
                    <AccountInfo>...</AccountInfo> //Kontostand (siehe XMLAccountInfo)
       </Account>
        .
        .
        .
    </Accounts>
 </PayAccountsFile>
 

Version:
1.0
Author:
Bastian Voigt, Tobias Bayer

Nested Class Summary
static class PayAccountsFile.AccountAlreadyExisting
          Thrown if an account with same account number was already existing when trying to add it.
private  class PayAccountsFile.MyAccountListener
          Listens to changes inside the accounts and forwards the events to our paymentListeners
 
Field Summary
private  java.util.Vector m_Accounts
          contains a vector of PayAccount objects, one for each account
private  PayAccount m_ActiveAccount
          the active account
private  boolean m_bEnableBalanceAutoUpdate
           
private  boolean m_bIgnoreAIAccountErrorMessages
           
private  boolean m_bIsInitialized
           
private  java.util.Vector m_knownPIs
           
private  PayAccountsFile.MyAccountListener m_MyAccountListener
           
private  java.util.Vector m_paymentListeners
           
private static PayAccountsFile ms_AccountsFile
          the one and only accountsfile
private static java.lang.String XML_ATTR_ENABLE_BALANCE_AUTO_UPDATE
           
private static java.lang.String XML_ATTR_IGNORE_AI_ERRORS
           
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
private PayAccountsFile()
          At this time, the implementation supports only one single BI.
 
Method Summary
 void addAccount(PayAccount account)
          Adds a new account
 void addKnownPI(BI a_bi)
          Adds a payment instance to the list of known payment instances
 void addKnownPI(org.w3c.dom.Element a_elemPI)
          Adds a payment instance to the list of known payment instances
 void addPaymentListener(IPaymentListener listener)
           
 PayAccount createAccount(BI a_bi, IMutableProxyInterface a_proxys, AsymmetricCryptoKeyPair a_keyPair)
          Creates a new Account.
 void deleteAccount(long accountNumber)
          Deletes the account from the accountsfile and saves the file to disk.
 PayAccount getAccount(long accountNumber)
          Liefert PayAccount zur angegebenen Kontonummer.
 PayAccount getAccountAt(int rowIndex)
          getAccountAt
 java.util.Enumeration getAccounts()
          Returns an enumeration of all accounts
 PayAccount getActiveAccount()
           
 long getActiveAccountNumber()
           
 BI getBI(java.lang.String a_piID)
           
static PayAccountsFile getInstance()
          returns the one and only accountsfile.
 java.util.Enumeration getKnownPIs()
          Gets the list of known Payment Instances
 int getNumAccounts()
          getNumAccounts
 void gotCaptcha(ICaptchaSender a_source, IImageEncodedCaptcha a_captcha)
          This method is called whenever a captcha has been received from the Payment Instance.
 boolean hasActiveAccount()
           
static boolean init(org.w3c.dom.Element elemAccountsFile, IMiscPasswordReader a_passwordReader, boolean a_bForceAIErrors)
          Performs the initialization.
 boolean isAIAccountErrorIgnored()
          Returns if error messages from the AI should be ignored.
 boolean isBalanceAutoUpdateEnabled()
          Returns if account balances are automatically updated.
 boolean isInitialized()
          isInitialized
 void removePaymentListener(IPaymentListener a_listener)
           
 void setActiveAccount(long accountNumber)
           
 void setActiveAccount(PayAccount account)
           
 void setBalanceAutoUpdateEnabled(boolean a_bEnable)
           
 void setIgnoreAIAccountError(boolean a_bIgnore)
          Defined if error messages from the AI should be ignored.
 void signalAccountError(XMLErrorMessage msg)
          signalAccountError
 boolean signalAccountRequest()
          signalAccountRequest
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
          constructs the xml structure
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc, java.lang.String a_password)
           
 
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_IGNORE_AI_ERRORS

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

XML_ATTR_ENABLE_BALANCE_AUTO_UPDATE

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

m_bIsInitialized

private boolean m_bIsInitialized

m_bIgnoreAIAccountErrorMessages

private boolean m_bIgnoreAIAccountErrorMessages

m_bEnableBalanceAutoUpdate

private boolean m_bEnableBalanceAutoUpdate

m_Accounts

private java.util.Vector m_Accounts
contains a vector of PayAccount objects, one for each account


m_ActiveAccount

private PayAccount m_ActiveAccount
the active account


ms_AccountsFile

private static PayAccountsFile ms_AccountsFile
the one and only accountsfile


m_paymentListeners

private java.util.Vector m_paymentListeners

m_knownPIs

private java.util.Vector m_knownPIs

m_MyAccountListener

private PayAccountsFile.MyAccountListener m_MyAccountListener
Constructor Detail

PayAccountsFile

private PayAccountsFile()
At this time, the implementation supports only one single BI. In the future a feature should be added to have support for multiple BIs, so that the AccountCertificate also contains a BIName. The infoservice should then publish information about the known BIs and also which MixCascade works with which BI. However, at the moment there is only one static BI which is used for all cascades and all accounts. This is the reason why we have this field in the singleton class.

Method Detail

getInstance

public static PayAccountsFile getInstance()
returns the one and only accountsfile. Note: If init(BI, Element) was not yet called, you get an empty instance which is not really useful.


setIgnoreAIAccountError

public void setIgnoreAIAccountError(boolean a_bIgnore)
Defined if error messages from the AI should be ignored. The connection mightbe closed, but the listeners will not get informed about the problem.

Parameters:
a_bIgnore - boolean

isBalanceAutoUpdateEnabled

public boolean isBalanceAutoUpdateEnabled()
Returns if account balances are automatically updated.

Returns:
if account balances are automatically updated

setBalanceAutoUpdateEnabled

public void setBalanceAutoUpdateEnabled(boolean a_bEnable)

isAIAccountErrorIgnored

public boolean isAIAccountErrorIgnored()
Returns if error messages from the AI should be ignored.

Returns:
boolean

init

public static boolean init(org.w3c.dom.Element elemAccountsFile,
                           IMiscPasswordReader a_passwordReader,
                           boolean a_bForceAIErrors)
Performs the initialization.

Parameters:
a_passwordReader - a password reader for encrypted account files; message: AccountNumber
Returns:
boolean succeeded?

toXmlElement

public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
constructs the xml structure

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

toXmlElement

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

hasActiveAccount

public boolean hasActiveAccount()

getActiveAccount

public PayAccount getActiveAccount()

setActiveAccount

public void setActiveAccount(long accountNumber)

setActiveAccount

public void setActiveAccount(PayAccount account)

getActiveAccountNumber

public long getActiveAccountNumber()

getAccount

public PayAccount getAccount(long accountNumber)
Liefert PayAccount zur angegebenen Kontonummer.

Parameters:
accountNumber - Kontonummer
Returns:
PayAccount oder null, wenn kein Konto unter der angebenen Kontonummer vorhanden ist

deleteAccount

public void deleteAccount(long accountNumber)
Deletes the account from the accountsfile and saves the file to disk. If the deleted account was the active account, the first remaining account will become the active account.

Parameters:
accountNumber - account number
Throws:
java.lang.Exception - Wenn ein Fehler bei Dateizugriff auftrat

getAccounts

public java.util.Enumeration getAccounts()
Returns an enumeration of all accounts

Returns:
Enumeration of PayAccount

addAccount

public void addAccount(PayAccount account)
                throws java.lang.Exception
Adds a new account

Parameters:
account - new account
Throws:
java.lang.Exception - If the same account was already added

getNumAccounts

public int getNumAccounts()
getNumAccounts

Returns:
int

getAccountAt

public PayAccount getAccountAt(int rowIndex)
getAccountAt

Parameters:
rowIndex - int
Returns:
PayAccount

isInitialized

public boolean isInitialized()
isInitialized

Returns:
boolean

addPaymentListener

public void addPaymentListener(IPaymentListener listener)

removePaymentListener

public void removePaymentListener(IPaymentListener a_listener)

createAccount

public PayAccount createAccount(BI a_bi,
                                IMutableProxyInterface a_proxys,
                                AsymmetricCryptoKeyPair a_keyPair)
                         throws java.lang.Exception
Creates a new Account. Generates an RSA or DSA key pair and then registers a new account with the BI. This can take a while, so the user should be notified before calling this. At the moment, only DSA should be used, because RSA is not supported by the AI implementation

Parameters:
a_keyPair - RSA should not be used at the moment
Throws:
java.lang.Exception

signalAccountRequest

public boolean signalAccountRequest()
signalAccountRequest


signalAccountError

public void signalAccountError(XMLErrorMessage msg)
signalAccountError

Parameters:
msg - XMLErrorMessage

getKnownPIs

public java.util.Enumeration getKnownPIs()
Gets the list of known Payment Instances

Returns:
Enumeration

addKnownPI

public void addKnownPI(BI a_bi)
Adds a payment instance to the list of known payment instances


addKnownPI

public void addKnownPI(org.w3c.dom.Element a_elemPI)
Adds a payment instance to the list of known payment instances


getBI

public BI getBI(java.lang.String a_piID)
         throws java.lang.Exception
Throws:
java.lang.Exception

gotCaptcha

public void gotCaptcha(ICaptchaSender a_source,
                       IImageEncodedCaptcha a_captcha)
This method is called whenever a captcha has been received from the Payment Instance.

Specified by:
gotCaptcha in interface IBIConnectionListener
Parameters:
a_source - Object
a_captcha - IImageEncodedCaptcha