/*
 *  RPGeneration - A role playing utility generate interesting things
 *  Copyright (C) 2002 Devon D Jones
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  The author of this program grants you the ability to use this code
 *  in conjunction with code that is covered under the Open Gaming License
 *
 * TableCheck.java
 *
 * Created on November 4, 2002, 5:52 PM
 */

package org.evilsoft.gaming.RPGeneration;

import org.jdom.*;
import java.util.*;
/**
 *
 * @author  devon
 */
public class TableCheck {
    private VariableHashMap allVars;
    private String tableName = "";
    private ArrayList information = new ArrayList();
    private ArrayList operations = new ArrayList();

    /** Creates a new instance of TableCheck */
    public TableCheck(Element tableElement, VariableHashMap allVars) {
        this.allVars = allVars;
        try {
            if(tableElement.getAttribute("Name") != null) {
                tableName = tableElement.getAttribute("Name").getValue();
            }
            List informationList = tableElement.getChildren("Information");
            ListIterator informationIterator = informationList.listIterator();
            while(informationIterator.hasNext()) {
                Element informationElement = (Element)informationIterator.next();
                information.add(new Information(informationElement, allVars));
            }

            List varMods = tableElement.getChildren("VarMod");
            ListIterator varModsIterator = varMods.listIterator();
            while(varModsIterator.hasNext()) {
                Element varModElement = (Element)varModsIterator.next();
                operations.add(new Operation(varModElement));
            }
        }
        catch(Exception e) {
            System.out.println("XML ERROR");
            e.printStackTrace();
        }
    }

    public Detail getDetail() {
        Detail retDetail = allVars.getTableDetail(allVars.parse(tableName));
		if(retDetail != null) {
			retDetail.addInformation(information);
		}
        return retDetail;
    }

    public ArrayList getInformation() {
        Detail retDetail = allVars.getTableDetail(allVars.parse(tableName));
		if(retDetail != null) {
			retDetail.addInformation(information);
		}
        return retDetail.getInformation(true);
    }

    public ArrayList getOperations() {
        return operations;
    }
}
