package uk.org.sappho.kmymoney.data;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;

import uk.org.sappho.kmymoney.rawdata.DataNode;
import uk.org.sappho.kmymoney.rawdata.DataNodeException;
import uk.org.sappho.kmymoney.rawdata.Value;

public class KMyMoneyData extends AbstractItem {

    private final AccountGroup accounts;
    private final PayeeGroup payees;
    private final TransactionGroup transactions;
    private final CurrencyGroup currencies;
    private final PriceGroup prices;
    private final Value lastUpdated;
    private final long version;
    private final long fixVersion;

    public KMyMoneyData(DataNode node) throws DataNodeException, IllegalArgumentException,
            SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException,
            NoSuchMethodException {

        super(node);
        accounts = new AccountGroup(node.getChildNode(AccountGroup.tag));
        payees = new PayeeGroup(node.getChildNode(PayeeGroup.tag));
        transactions = new TransactionGroup(node.getChildNode(TransactionGroup.tag));
        currencies = new CurrencyGroup(node.getChildNode(CurrencyGroup.tag));
        prices = new PriceGroup(node.getChildNode(PriceGroup.tag));
        DataNode infoNode = node.getChildNode("FILEINFO");
        lastUpdated = infoNode.getChildNode("LAST_MODIFIED_DATE").getAttribute("date");
        version = infoNode.getChildNode("VERSION").getAttribute("id").getLong();
        fixVersion = infoNode.getChildNode("FIXVERSION").getAttribute("id").getLong();
    }

    public AccountGroup getAccounts() {

        return accounts;
    }

    public PayeeGroup getPayees() {

        return payees;
    }

    public TransactionGroup getTransactions() {

        return transactions;
    }

    public CurrencyGroup getCurrencies() {

        return currencies;
    }

    public PriceGroup getPrices() {

        return prices;
    }

    public Date getLastUpdated() throws DataNodeException {

        return lastUpdated.getDate();
    }

    public long getVersion() throws DataNodeException {

        return version;
    }

    public long getFixVersion() throws DataNodeException {

        return fixVersion;
    }

    public void setLastUpdated(Date date) {

        lastUpdated.setDate(date);
    }

    @Override
    protected String getTag() {

        return "KMYMONEY-FILE";
    }
}

@@ -619,16 +619,55 @@
 Version;
+%0A    private final String baseCurrency;
 %0A%0A    pu
@@ -1600,24 +1600,618 @@
 .getLong();%0A
+        DataNode keyValuePairsNode = node.getChildNode(%22KEYVALUEPAIRS%22);%0A        String baseCurrency = null;%0A        for (DataNode keyValuePairNode : keyValuePairsNode.getChildNodes())%0A            if (keyValuePairNode.getTag().equals(%22PAIR%22)%0A                    && keyValuePairNode.getAttribute(%22key%22).getValue().equals(%22kmm-baseCurrency%22))%0A                baseCurrency = keyValuePairNode.getAttribute(%22value%22).getValue();%0A        if (baseCurrency == null)%0A            throw new DataNodeException(%22Base currency is missing from key/value pair table%22);%0A        this.baseCurrency = baseCurrency;%0A
     %7D%0A%0A    p
@@ -2821,32 +2821,32 @@
 odeException %7B%0A%0A
-
         return f
@@ -2855,32 +2855,106 @@
 Version;%0A    %7D%0A%0A
+    public String getBaseCurrency() %7B%0A        return baseCurrency;%0A    %7D%0A%0A
     public void 

Set up basics of kmymoney4j.