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.propagators.reconciliation;
024:
025: import net.sf.jmoney.model2.ScalarPropertyAccessor;
026: import net.sf.jmoney.qif.QIFEntry;
027: import net.sf.jmoney.reconciliation.ReconciliationEntry;
028:
029: /**
030: * This class connects the reconcilation field added by the reconciliation extension
031: * plugin and the field that the QIF extension imports and exports.
032: *
033: * The reconciliation plugin and the QIF plugin are independent. They could have been
034: * written by two different developers who did not know about the other's work.
035: * One chose to store the state as an integer (0, 1, or 2) and the other chose to store
036: * the state as a character (' ', '*', or 'C'). An propagator like this one must then be
037: * written by a developer who is aware of the two plugins. This propagator connects the two
038: * properties so when one plugin makes a change to its property, the value of the other
039: * plugin's property is changed to match.
040: *
041: * In any propagator class any number of propertyChange methods may be declared.
042: *
043: * @author Nigel
044: */
045: public class ReconciliationPropagator {
046:
047: public static void propertyChange(ScalarPropertyAccessor property,
048: ReconciliationEntry sourceReconciliationEntry,
049: QIFEntry destinationQifEntry) {
050: if (property.getLocalName().equals("status")) {
051: if (sourceReconciliationEntry.getStatement() == null) {
052: if (destinationQifEntry.getReconcilingState() == 'C') {
053: destinationQifEntry.setReconcilingState(' ');
054: }
055: } else {
056: destinationQifEntry.setReconcilingState('C');
057: }
058: }
059: }
060:
061: public static void propertyChange(ScalarPropertyAccessor property,
062: QIFEntry sourceQifEntry,
063: ReconciliationEntry destinationReconciliationEntry) {
064: if (property.getLocalName().equals("reconcilingState")) {
065: switch (sourceQifEntry.getReconcilingState()) {
066: case ' ':
067: destinationReconciliationEntry
068: .setStatus(ReconciliationEntry.UNCLEARED);
069: destinationReconciliationEntry.setStatement(null);
070: break;
071: case '*':
072: destinationReconciliationEntry
073: .setStatus(ReconciliationEntry.RECONCILING);
074: // Don't change the statement.
075: break;
076: case 'C':
077: destinationReconciliationEntry
078: .setStatus(ReconciliationEntry.CLEARED);
079: /*
080: * We have no way of knowing what statement this entry should
081: * be reconciled to, so we leave it as not yet reconciled to
082: * any statement.
083: */
084: break;
085: }
086: }
087: }
088:
089: /**
090: * This is an alternative form. This form avoids the need to switch on the
091: * property name. For a given source and destination pair, there can be either a
092: * propertyChange method or there can be methods of the 'change...' pattern but
093: * there cannot be both. Note also that not all properties need a 'change...' method
094: * or need to be processed by the propertyChange method.
095: *
096: public static void changeStatus(ReconciliationEntry source, QIFEntryExtension destination) {
097: switch (sourceReconciliationEntry.getStatus()) {
098: case ReconciliationEntry.UNCLEARED:
099: destinationQifEntry.setReconcilingState(' ');
100: break;
101: case ReconciliationEntry.RECONCILING:
102: destinationQifEntry.setReconcilingState('*');
103: break;
104: case ReconciliationEntry.CLEARED:
105: destinationQifEntry.setReconcilingState('C');
106: break;
107: }
108: }
109: */
110: }
|