/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.PrintStream
 *  java.io.Serializable
 *  java.lang.Class
 *  java.lang.Exception
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.lang.System
 *  java.util.ArrayList
 *  java.util.HashMap
 *  java.util.Iterator
 *  java.util.List
 *  java.util.Map
 *  org.jaxen.VariableContext
 */
package org.dom4j.swing;

import java.io.PrintStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.swing.XMLTableColumnDefinition;
import org.jaxen.VariableContext;

public class XMLTableDefinition
implements Serializable,
VariableContext {
    private XMLTableColumnDefinition[] columnArray;
    private Map columnNameIndex;
    private List columns = new ArrayList();
    private Object rowValue;
    private XPath rowXPath;
    private VariableContext variableContext;

    public static XMLTableDefinition load(Document document) {
        return XMLTableDefinition.load(document.getRootElement());
    }

    public static XMLTableDefinition load(Element element) {
        XMLTableDefinition xMLTableDefinition = new XMLTableDefinition();
        xMLTableDefinition.setRowExpression(element.attributeValue("select"));
        Iterator iterator = element.elementIterator("column");
        while (iterator.hasNext()) {
            Element element2 = (Element)iterator.next();
            String string2 = element2.attributeValue("select");
            String string3 = element2.getText();
            String string4 = element2.attributeValue("type", "string");
            String string5 = element2.attributeValue("columnNameXPath");
            int n = XMLTableColumnDefinition.parseType(string4);
            if (string5 != null) {
                xMLTableDefinition.addColumnWithXPathName(string5, string2, n);
                continue;
            }
            xMLTableDefinition.addColumn(string3, string2, n);
        }
        return xMLTableDefinition;
    }

    public void addColumn(String string2, String string3) {
        this.addColumn(string2, string3, 0);
    }

    public void addColumn(String string2, String string3, int n) {
        this.addColumn(new XMLTableColumnDefinition(string2, this.createColumnXPath(string3), n));
    }

    public void addColumn(XMLTableColumnDefinition xMLTableColumnDefinition) {
        this.clearCaches();
        this.columns.add((Object)xMLTableColumnDefinition);
    }

    public void addColumnWithXPathName(String string2, String string3, int n) {
        this.addColumn(new XMLTableColumnDefinition(this.createColumnXPath(string2), this.createColumnXPath(string3), n));
    }

    public void addNumberColumn(String string2, String string3) {
        this.addColumn(string2, string3, 2);
    }

    public void addStringColumn(String string2, String string3) {
        this.addColumn(string2, string3, 1);
    }

    public void clear() {
        this.clearCaches();
        this.columns.clear();
    }

    protected void clearCaches() {
        this.columnArray = null;
        this.columnNameIndex = null;
    }

    protected XPath createColumnXPath(String string2) {
        XPath xPath = this.createXPath(string2);
        xPath.setVariableContext((VariableContext)this);
        return xPath;
    }

    protected XPath createXPath(String string2) {
        return DocumentHelper.createXPath(string2);
    }

    public XMLTableColumnDefinition getColumn(int n) {
        if (this.columnArray == null) {
            this.columnArray = new XMLTableColumnDefinition[this.columns.size()];
            this.columns.toArray(this.columnArray);
        }
        return this.columnArray[n];
    }

    public XMLTableColumnDefinition getColumn(String string2) {
        if (this.columnNameIndex == null) {
            this.columnNameIndex = new HashMap();
            for (XMLTableColumnDefinition xMLTableColumnDefinition : this.columns) {
                this.columnNameIndex.put((Object)xMLTableColumnDefinition.getName(), (Object)xMLTableColumnDefinition);
            }
        }
        return (XMLTableColumnDefinition)this.columnNameIndex.get((Object)string2);
    }

    public Class getColumnClass(int n) {
        return this.getColumn(n).getColumnClass();
    }

    public int getColumnCount() {
        return this.columns.size();
    }

    public String getColumnName(int n) {
        return this.getColumn(n).getName();
    }

    public XPath getColumnNameXPath(int n) {
        return this.getColumn(n).getColumnNameXPath();
    }

    public XPath getColumnXPath(int n) {
        return this.getColumn(n).getXPath();
    }

    public XPath getRowXPath() {
        return this.rowXPath;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     * Converted monitor instructions to comments
     * Lifted jumps to return sites
     */
    public Object getValueAt(Object object, int n) {
        void var7_3 = this;
        // MONITORENTER : var7_3
        XMLTableColumnDefinition xMLTableColumnDefinition = this.getColumn(n);
        var7_3 = this;
        // MONITORENTER : var7_3
        this.rowValue = object;
        Object object2 = xMLTableColumnDefinition.getValue(object);
        this.rowValue = null;
        // MONITOREXIT : var7_3
        // MONITOREXIT : var7_3
        return object2;
    }

    public Object getVariableValue(String string2, String string3, String string4) {
        XMLTableColumnDefinition xMLTableColumnDefinition = this.getColumn(string4);
        if (xMLTableColumnDefinition != null) {
            return xMLTableColumnDefinition.getValue(this.rowValue);
        }
        return null;
    }

    protected void handleException(Exception exception) {
        System.out.println(new StringBuffer().append("Caught: ").append((Object)exception).toString());
    }

    public void removeColumn(XMLTableColumnDefinition xMLTableColumnDefinition) {
        this.clearCaches();
        this.columns.remove((Object)xMLTableColumnDefinition);
    }

    public void setRowExpression(String string2) {
        this.setRowXPath(this.createXPath(string2));
    }

    public void setRowXPath(XPath xPath) {
        this.rowXPath = xPath;
    }
}

