anon.pay
Class PayAccountsFile

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

public class PayAccountsFile
extends java.util.Observable
implements IXMLEncodable, IBIConnectionListener, IMessageListener

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.AccountAlreadyExistingException
          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
static java.lang.Integer CHANGED_AUTO_UPDATE
           
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 static boolean m_bIsInitialized
           
private  DSAKeyPool m_keyPool
           
private  java.util.Vector m_messageListeners
           
private  PayAccountsFile.MyAccountListener m_MyAccountListener
           
private  java.util.Vector m_paymentListeners
           
private static PayAccountsFile ms_AccountsFile
          the one and only accountsfile
private static int ms_keyPoolSize
           
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_LANGUAGE, XML_ATTR_VERSION
 
Constructor Summary
private PayAccountsFile()
          At this time, the implementation supports only one single BI.
 
Method Summary
 void addAccount(PayAccount newAccount)
          Adds a new account
 void addMessageListener(IMessageListener listener)
           
 void addPaymentListener(IPaymentListener listener)
           
 PayAccount createAccount(PaymentInstanceDBEntry a_bi, AsymmetricCryptoKeyPair a_keyPair, XMLGenericText a_terms)
          Creates a new Account.
 PayAccount createAccount(PaymentInstanceDBEntry a_bi, XMLGenericText a_terms)
           
 AsymmetricCryptoKeyPair createAccountKeyPair()
           
 void deleteAccount(PayAccount a_account)
          Deletes the account from the accountsfile and saves the file to disk.
static void fireKnownMessages()
          iterates over all accounts, and whenever there is a message it is sent to all MessageListeners reason for existence: JapNewView needs to load all messages at start-up (PayAccountsFile does already fire all message when it loads the accounts from the file, but that possibly happens before a MessageListener is initialized and added as a listener to PayAccountsFile)
private  void fireMessageReceived(PayMessage message)
           
private  void fireMessageRemoved(PayMessage message)
           
 PayAccount getAccount(long accountNumber, java.lang.String a_piid)
          Liefert PayAccount zur angegebenen Kontonummer.
 PayAccount getAccountAt(int rowIndex)
          getAccountAt
 java.util.Enumeration getAccounts()
          Returns an enumeration of all accounts
 java.util.Vector getAccounts(java.lang.String a_piid)
           
 PayAccount getActiveAccount()
           
 long getActiveAccountNumber()
           
 PayAccount getAlternativeChargedAccount(java.lang.String a_piid)
           
 PaymentInstanceDBEntry getBI(java.lang.String a_piID)
           
 PayAccount getChargedAccount(java.lang.String a_piid)
           
 PayAccount getChargedAccount(java.lang.String a_piid, PayAccount a_excludeAccount)
           
static PayAccountsFile getInstance()
          returns the one and only accountsfile.
 int getNumAccounts()
          getNumAccounts
 java.util.Vector getPaymentInstances()
           
 void gotCaptcha(ICaptchaSender a_source, IImageEncodedCaptcha a_captcha)
          This method is called whenever a captcha has been received from the Payment Instance.
 boolean hasActiveAccount()
           
 boolean importAccounts(org.w3c.dom.Element elemAccountsFile, IMiscPasswordReader a_passwordReader)
           
static boolean init(org.w3c.dom.Element elemAccountsFile, IMiscPasswordReader a_passwordReader, boolean a_bForceAIErrors, int a_keyPoolSize)
          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 messageReceived(PayMessage message)
          just passes through a received message to the PayAccountsFile's MessageListeners
 void messageRemoved(PayMessage message)
           
 void removePaymentListener(IPaymentListener a_listener)
           
 void setActiveAccount(PayAccount a_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
 int signalAccountRequest(MixCascade a_connectedCascade)
          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.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
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

CHANGED_AUTO_UPDATE

public static final java.lang.Integer CHANGED_AUTO_UPDATE

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 static 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_messageListeners

private java.util.Vector m_messageListeners

m_MyAccountListener

private PayAccountsFile.MyAccountListener m_MyAccountListener

m_keyPool

private DSAKeyPool m_keyPool

ms_keyPoolSize

private static int ms_keyPoolSize
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.


createAccountKeyPair

public AsymmetricCryptoKeyPair createAccountKeyPair()

setIgnoreAIAccountError

public void setIgnoreAIAccountError(boolean a_bIgnore)
Defined if error messages from the AI should be ignored. The connection might be 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

importAccounts

public boolean importAccounts(org.w3c.dom.Element elemAccountsFile,
                              IMiscPasswordReader a_passwordReader)
                       throws XMLParseException,
                              java.lang.Exception
Throws:
XMLParseException
java.lang.Exception

init

public static boolean init(org.w3c.dom.Element elemAccountsFile,
                           IMiscPasswordReader a_passwordReader,
                           boolean a_bForceAIErrors,
                           int a_keyPoolSize)
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(PayAccount a_account)

getActiveAccountNumber

public long getActiveAccountNumber()

getAccount

public PayAccount getAccount(long accountNumber,
                             java.lang.String a_piid)
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(PayAccount a_account)
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:
PayAccountsFile.AccountAlreadyExistingException - Wenn ein Fehler bei Dateizugriff auftrat

getAccounts

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

Returns:
Enumeration of PayAccount

fireKnownMessages

public static void fireKnownMessages()
iterates over all accounts, and whenever there is a message it is sent to all MessageListeners reason for existence: JapNewView needs to load all messages at start-up (PayAccountsFile does already fire all message when it loads the accounts from the file, but that possibly happens before a MessageListener is initialized and added as a listener to PayAccountsFile)


getAlternativeChargedAccount

public PayAccount getAlternativeChargedAccount(java.lang.String a_piid)

getChargedAccount

public PayAccount getChargedAccount(java.lang.String a_piid)

getChargedAccount

public PayAccount getChargedAccount(java.lang.String a_piid,
                                    PayAccount a_excludeAccount)

getAccounts

public java.util.Vector getAccounts(java.lang.String a_piid)

addAccount

public void addAccount(PayAccount newAccount)
                throws PayAccountsFile.AccountAlreadyExistingException
Adds a new account

Parameters:
account - new account
Throws:
PayAccountsFile.AccountAlreadyExistingException - 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)

addMessageListener

public void addMessageListener(IMessageListener listener)

fireMessageReceived

private void fireMessageReceived(PayMessage message)

fireMessageRemoved

private void fireMessageRemoved(PayMessage message)

createAccount

public PayAccount createAccount(PaymentInstanceDBEntry a_bi,
                                XMLGenericText a_terms)
                         throws java.lang.Exception
Throws:
java.lang.Exception

createAccount

public PayAccount createAccount(PaymentInstanceDBEntry a_bi,
                                AsymmetricCryptoKeyPair a_keyPair,
                                XMLGenericText a_terms)
                         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 int signalAccountRequest(MixCascade a_connectedCascade)
signalAccountRequest


signalAccountError

public void signalAccountError(XMLErrorMessage msg)
signalAccountError

Parameters:
msg - XMLErrorMessage

getPaymentInstances

public java.util.Vector getPaymentInstances()

getBI

public PaymentInstanceDBEntry getBI(java.lang.String a_piID)

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

messageReceived

public void messageReceived(PayMessage message)
just passes through a received message to the PayAccountsFile's MessageListeners

Specified by:
messageReceived in interface IMessageListener

messageRemoved

public void messageRemoved(PayMessage message)
Specified by:
messageRemoved in interface IMessageListener