001: /*
002: *
003: * JMoney - A Personal Finance Manager
004: * Copyright (c) 2004 Nigel Westbury <westbury@users.sourceforge.net>
005: *
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: *
021: */
022:
023: package net.sf.jmoney.stocks;
024:
025: import java.util.Date;
026:
027: import net.sf.jmoney.model2.EntryExtension;
028: import net.sf.jmoney.model2.ExtendableObject;
029: import net.sf.jmoney.model2.IObjectKey;
030:
031: /**
032: * Property set implementation class for the properties added
033: * to each Entry object by this plug-in.
034: *
035: * @author Nigel Westbury
036: */
037: public class StockEntry extends EntryExtension {
038:
039: /**
040: * indicates if this entry represents stock going in or
041: * out of the account.
042: */
043: private boolean stockChange = false;
044:
045: /**
046: * The commodity (Stock or Bond) involved in this entry.
047: * <P>
048: * Do we use this field for dividend payments, where no change
049: * in stock amounts is involved but we do want to associate the
050: * cash amount with a stock?
051: */
052: protected IObjectKey stockKey = null;
053:
054: /**
055: * The date on which the deal was made. On some stock
056: * exchanges (for example, the London Stock Exchange)
057: * this is different from the settlement date on which
058: * the money and stock is paid or received.
059: * <P>
060: * This property is applicable only if stockChange is set
061: * to true.
062: */
063: private Date bargainDate = null;
064:
065: /**
066: * A default constructor is mandatory for all extension objects.
067: * The default constructor sets the extension properties to
068: * appropriate default values.
069: *
070: * @param extendedObject
071: */
072: public StockEntry(ExtendableObject extendedObject) {
073: super (extendedObject);
074: }
075:
076: /**
077: * A Full constructor is mandatory for all extension objects.
078: * This constructor is called by the datastore to construct
079: * the extension objects when loading data.
080: */
081: public StockEntry(ExtendableObject extendedObject,
082: boolean stockChange, IObjectKey stockKey, Date bargainDate) {
083: super (extendedObject);
084: this .stockChange = stockChange;
085: this .stockKey = stockKey;
086: this .bargainDate = bargainDate;
087: }
088:
089: /**
090: * @return true if this entry represents an addition of stock
091: * to the account or a removal of stock from the account,
092: * false if this entry represents anything else, such as
093: * cash dividends going into the account.
094: */
095: public boolean isStockChange() {
096: return stockChange;
097: }
098:
099: /**
100: * @param stockChange true if this entry represents an addition of stock
101: * to the account or a removal of stock from the account,
102: * false if this entry represents anything else, such as
103: * cash dividends going into the account.
104: */
105: public void setStockChange(boolean stockChange) {
106: this .stockChange = stockChange;
107: }
108:
109: /**
110: * Gets the stock involved in this entry.
111: *
112: * @return An object of type Stock or Bond.
113: * Null will be returned if no value has previously
114: * been set.
115: */
116: public Stock getStock() {
117: return stockKey == null ? null : (Stock) stockKey.getObject();
118: }
119:
120: /**
121: * Sets the stock involved in this entry.
122: *
123: * @param stock An object of type Stock or Bond.
124: */
125: public void setStock(Stock stock) {
126: Stock oldStock = getStock();
127: this .stockKey = (stock == null) ? null : stock.getObjectKey();
128:
129: // Notify the change manager.
130: processPropertyChange(StockEntryInfo.getStockAccessor(),
131: oldStock, stock);
132: }
133:
134: /**
135: * @return The date on which the deal was made.
136: */
137: public Date getBargainDate() {
138: return bargainDate;
139: }
140:
141: /**
142: * @param bargainDate The date on which the deal was made.
143: */
144: public void setBargainDate(Date bargainDate) {
145: Date oldBargainDate = this.bargainDate;
146: this.bargainDate = bargainDate;
147: processPropertyChange(StockEntryInfo.getBargainDateAccessor(),
148: oldBargainDate, bargainDate);
149: }
150: }
|