org.homeunix.thecave.buddi.model.impl
Class DocumentImpl

java.lang.Object
  extended by org.homeunix.thecave.moss.model.AbstractDocument
      extended by org.homeunix.thecave.buddi.model.impl.DocumentImpl
All Implemented Interfaces:
java.lang.Comparable<ModelObject>, Document, ModelObject, StandardDocument

public class DocumentImpl
extends AbstractDocument
implements ModelObject, Document

The main container class for the new data model, to be implemented in Buddi version 3.0. This contains all the data, most of it in list form. This object is the root of the XML file as serialized by XMLEncoder. You should *not* create this class by calling its constructor - you must create it using one of the ModelFactory.createDocument methods. The factory will correctly initialize the default types and budget categories. The only reason we did not make the default constructor for this class to be non-public was because the XMLDecoder needs public consructors to create objects at load time.

Author:
wyatt

Field Summary
 
Fields inherited from interface org.homeunix.thecave.buddi.model.Document
CHANGE_PASSWORD, RESET_PASSWORD
 
Constructor Summary
DocumentImpl()
          By default, we start with one batch change enabled.
 
Method Summary
 void addAccount(Account account)
           
 void addAccountType(AccountType type)
           
 void addBudgetCategory(BudgetCategory budgetCategory)
           
 void addScheduledTransaction(ScheduledTransaction scheduledTransaction)
           
 void addTransaction(Transaction transaction)
           
 Document clone()
          Performs a deep clone of the Document model.
 int compareTo(ModelObject o)
           
 boolean equals(java.lang.Object obj)
           
 Account getAccount(java.lang.String name)
           
 java.util.List<Account> getAccounts()
           
 AccountType getAccountType(java.lang.String name)
           
 java.util.List<AccountType> getAccountTypes()
           
 java.util.List<BudgetCategory> getBudgetCategories()
           
 BudgetCategory getBudgetCategory(java.lang.String fullName)
           
 Document getDocument()
          Returns the document associated with this model object, or null if there is no document.
 Time getModified()
          Gets the last modified date of the object
 java.util.Date getModifiedDate()
           
 long getNetWorth(java.util.Date date)
           
 ModelObject getObjectByUid(java.lang.String uid)
           
 java.util.List<ScheduledTransaction> getScheduledTransactions()
           
 java.util.List<Source> getSources()
           
 java.util.List<Transaction> getTransactions()
           
 java.util.List<Transaction> getTransactions(java.util.Date startDate, java.util.Date endDate)
           
 java.util.List<Transaction> getTransactions(Source source)
           
 java.util.List<Transaction> getTransactions(Source source, java.util.Date startDate, java.util.Date endDate)
           
 java.lang.String getUid()
          Returns the UID string for this object.
 void refreshUidMap()
          Refreshes the UID map.
 void removeAccount(Account account)
           
 void removeAccountType(AccountType type)
           
 void removeBudgetCategory(BudgetCategory budgetCategory)
           
 void removeScheduledTransaction(ScheduledTransaction scheduledTransaction)
           
 void removeTransaction(Transaction transaction)
           
 void save()
          Saves the data file to the current file.
 void saveAs(java.io.File file)
          Saves the data file to the specified file.
 void saveAuto(java.io.File file)
           
 void saveToStream(java.io.OutputStream os)
          Very simple save method.
 void setAccounts(java.util.List<Account> accounts)
           
 void setAccountTypes(java.util.List<AccountType> types)
           
 void setBudgetCategories(java.util.List<BudgetCategory> budgetCategories)
           
 void setChanged()
          Indicates that the document has changed.
 void setDocument(Document document)
          Sets the document.
 void setFlag(int flag, boolean set)
           
 void setModified(java.util.Date modifiedDate)
           
 void setModified(Time modifiedTime)
           
 void setPassword(char[] password)
           
 void setScheduledTransactions(java.util.List<ScheduledTransaction> scheduledTransactions)
           
 void setTransactions(java.util.List<Transaction> transactions)
           
 void setUid(java.lang.String uid)
           
 java.lang.String toString()
           
 void updateAllBalances()
          Updates the balances of all accounts.
 void updateScheduledTransactions()
          Runs through the list of scheduled transactions, and adds any which show be executed to the apropriate transacactions list.
 
Methods inherited from class org.homeunix.thecave.moss.model.AbstractDocument
addDocumentChangeListener, finishBatchChange, fireDocumentChangeEvent, getFile, getGeneratedUid, getMinimumChangeEventPeriod, isBatchChange, isChanged, removeDocumentChangeListener, resetChanged, setFile, setMinimumChangeEventPeriod, startBatchChange
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.homeunix.thecave.moss.model.StandardDocument
addDocumentChangeListener, finishBatchChange, getFile, isChanged, removeDocumentChangeListener, resetChanged, setFile, startBatchChange
 

Constructor Detail

DocumentImpl

public DocumentImpl()
By default, we start with one batch change enabled. This is because, otherwise, the XMLDecoder will cause many model change events to be fired, which will result in much longer load times. You must call finishBatchChange() before any change events will be sent! ModelFactory does this for you automatically; as such, you are much better off to use that to create Document objects. (In fact, this constructor would be private, except for XMLDecoder's need for a public constructor. Don't use this unless you know exactly what you are doing!)

Method Detail

getAccounts

public java.util.List<Account> getAccounts()
Specified by:
getAccounts in interface Document

setAccounts

public void setAccounts(java.util.List<Account> accounts)

getBudgetCategories

public java.util.List<BudgetCategory> getBudgetCategories()
Specified by:
getBudgetCategories in interface Document

setBudgetCategories

public void setBudgetCategories(java.util.List<BudgetCategory> budgetCategories)

getScheduledTransactions

public java.util.List<ScheduledTransaction> getScheduledTransactions()
Specified by:
getScheduledTransactions in interface Document

setScheduledTransactions

public void setScheduledTransactions(java.util.List<ScheduledTransaction> scheduledTransactions)

getTransactions

public java.util.List<Transaction> getTransactions()
Specified by:
getTransactions in interface Document

setTransactions

public void setTransactions(java.util.List<Transaction> transactions)

getAccountTypes

public java.util.List<AccountType> getAccountTypes()
Specified by:
getAccountTypes in interface Document

setAccountTypes

public void setAccountTypes(java.util.List<AccountType> types)

setFlag

public void setFlag(int flag,
                    boolean set)
Specified by:
setFlag in interface Document

addAccount

public void addAccount(Account account)
                throws ModelException
Specified by:
addAccount in interface Document
Throws:
ModelException

addAccountType

public void addAccountType(AccountType type)
                    throws ModelException
Specified by:
addAccountType in interface Document
Throws:
ModelException

addBudgetCategory

public void addBudgetCategory(BudgetCategory budgetCategory)
                       throws ModelException
Specified by:
addBudgetCategory in interface Document
Throws:
ModelException

addScheduledTransaction

public void addScheduledTransaction(ScheduledTransaction scheduledTransaction)
                             throws ModelException
Specified by:
addScheduledTransaction in interface Document
Throws:
ModelException

addTransaction

public void addTransaction(Transaction transaction)
                    throws ModelException
Specified by:
addTransaction in interface Document
Throws:
ModelException

getAccount

public Account getAccount(java.lang.String name)
Specified by:
getAccount in interface Document

getAccountType

public AccountType getAccountType(java.lang.String name)
Specified by:
getAccountType in interface Document

getBudgetCategory

public BudgetCategory getBudgetCategory(java.lang.String fullName)
Specified by:
getBudgetCategory in interface Document

getObjectByUid

public ModelObject getObjectByUid(java.lang.String uid)
Specified by:
getObjectByUid in interface Document

getSources

public java.util.List<Source> getSources()
Specified by:
getSources in interface Document

getTransactions

public java.util.List<Transaction> getTransactions(java.util.Date startDate,
                                                   java.util.Date endDate)
Specified by:
getTransactions in interface Document

getTransactions

public java.util.List<Transaction> getTransactions(Source source,
                                                   java.util.Date startDate,
                                                   java.util.Date endDate)
Specified by:
getTransactions in interface Document

getTransactions

public java.util.List<Transaction> getTransactions(Source source)
Specified by:
getTransactions in interface Document

removeAccount

public void removeAccount(Account account)
                   throws ModelException
Specified by:
removeAccount in interface Document
Throws:
ModelException

removeAccountType

public void removeAccountType(AccountType type)
                       throws ModelException
Specified by:
removeAccountType in interface Document
Throws:
ModelException

removeBudgetCategory

public void removeBudgetCategory(BudgetCategory budgetCategory)
                          throws ModelException
Specified by:
removeBudgetCategory in interface Document
Throws:
ModelException

removeScheduledTransaction

public void removeScheduledTransaction(ScheduledTransaction scheduledTransaction)
                                throws ModelException
Specified by:
removeScheduledTransaction in interface Document
Throws:
ModelException

removeTransaction

public void removeTransaction(Transaction transaction)
                       throws ModelException
Specified by:
removeTransaction in interface Document
Throws:
ModelException

save

public void save()
          throws DocumentSaveException
Saves the data file to the current file. If the file has not yet been set, this method silently returns.

Specified by:
save in interface Document
Specified by:
save in interface StandardDocument
Throws:
SaveModelException
DocumentSaveException

saveAs

public void saveAs(java.io.File file)
            throws DocumentSaveException
Saves the data file to the specified file. If the specified file is null, silently return without error and without saving.

Specified by:
saveAs in interface Document
Specified by:
saveAs in interface StandardDocument
Parameters:
file -
flags. - Flags to set for saving. AND together for multiple flags.
Throws:
SaveModelException
DocumentSaveException

saveAuto

public void saveAuto(java.io.File file)
              throws DocumentSaveException
Throws:
DocumentSaveException

saveToStream

public void saveToStream(java.io.OutputStream os)
                  throws DocumentSaveException
Very simple save method. Streams the document to XML using the XMLEncoder, optionally using an encrypted output stream if the password is set.

Specified by:
saveToStream in interface Document
Parameters:
file -
flags -
Throws:
DocumentSaveException

updateAllBalances

public void updateAllBalances()
Updates the balances of all accounts. Iterates through all accounts, and calls the updateBalance() method for each.

Specified by:
updateAllBalances in interface Document

getModifiedDate

public java.util.Date getModifiedDate()

setModified

public void setModified(java.util.Date modifiedDate)

setModified

public void setModified(Time modifiedTime)

setChanged

public void setChanged()
Description copied from class: AbstractDocument
Indicates that the document has changed.

Specified by:
setChanged in interface ModelObject
Specified by:
setChanged in interface StandardDocument
Overrides:
setChanged in class AbstractDocument

getUid

public java.lang.String getUid()
Description copied from interface: ModelObject
Returns the UID string for this object.

Specified by:
getUid in interface ModelObject
Returns:

setUid

public void setUid(java.lang.String uid)

getDocument

public Document getDocument()
Description copied from interface: ModelObject
Returns the document associated with this model object, or null if there is no document.

Specified by:
getDocument in interface ModelObject
Returns:

setDocument

public void setDocument(Document document)
Description copied from interface: ModelObject
Sets the document.

Specified by:
setDocument in interface ModelObject

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(ModelObject o)
Specified by:
compareTo in interface java.lang.Comparable<ModelObject>
Specified by:
compareTo in interface ModelObject

refreshUidMap

public void refreshUidMap()
                   throws ModelException
Refreshes the UID map. This is a relatively expensive operation, and as such is generally only done at file load time. We iterate through all objects for each data type, and add them to the UID map. This will associate the object with their UID as the key in the Map.

Specified by:
refreshUidMap in interface Document
Throws:
ModelException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getModified

public Time getModified()
Description copied from interface: ModelObject
Gets the last modified date of the object

Specified by:
getModified in interface ModelObject
Returns:

updateScheduledTransactions

public void updateScheduledTransactions()
Runs through the list of scheduled transactions, and adds any which show be executed to the apropriate transacactions list. + * Checks for the frequency type and based on it finds if a transaction is scheduled for a date + * that has gone past.

Specified by:
updateScheduledTransactions in interface Document

setPassword

public void setPassword(char[] password)

getNetWorth

public long getNetWorth(java.util.Date date)
Specified by:
getNetWorth in interface Document

clone

public Document clone()
               throws java.lang.CloneNotSupportedException
Performs a deep clone of the Document model. This will result in a completely different object, with all component objects different, but with all the same values. Immutable objects (such as Strings) and primitives may be identical between cloned and source objects, but all immutable objects will not be identical.

Specified by:
clone in interface Document
Overrides:
clone in class java.lang.Object
Parameters:
source -
Returns:
Throws:
java.lang.CloneNotSupportedException