/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.beans.IntrospectionException
 *  java.beans.Introspector
 *  java.beans.PropertyDescriptor
 *  java.lang.Class
 *  java.lang.Exception
 *  java.lang.Integer
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.reflect.Method
 *  java.util.HashMap
 *  java.util.Map
 */
package org.dom4j.bean;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.dom4j.DocumentFactory;
import org.dom4j.QName;
import org.dom4j.bean.BeanAttributeList;
import org.dom4j.bean.BeanDocumentFactory;
import org.dom4j.bean.BeanElement;

public class BeanMetaData {
    private static final DocumentFactory DOCUMENT_FACTORY;
    protected static final Object[] NULL_ARGS;
    private static Map singletonCache;
    private Class beanClass;
    private Map nameMap = new HashMap();
    private PropertyDescriptor[] propertyDescriptors;
    private QName[] qNames;
    private Method[] readMethods;
    private Method[] writeMethods;

    static {
        NULL_ARGS = new Object[0];
        singletonCache = new HashMap();
        DOCUMENT_FACTORY = BeanDocumentFactory.getInstance();
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public BeanMetaData(Class class_) {
        this.beanClass = class_;
        if (class_ != null) {
            try {
                this.propertyDescriptors = Introspector.getBeanInfo((Class)class_).getPropertyDescriptors();
            }
            catch (IntrospectionException var10_2) {
                this.handleException((Exception)var10_2);
            }
        }
        if (this.propertyDescriptors == null) {
            this.propertyDescriptors = new PropertyDescriptor[0];
        }
        int n = this.propertyDescriptors.length;
        this.qNames = new QName[n];
        this.readMethods = new Method[n];
        this.writeMethods = new Method[n];
        int n2 = 0;
        while (n2 < n) {
            QName qName;
            PropertyDescriptor propertyDescriptor = this.propertyDescriptors[n2];
            String string2 = propertyDescriptor.getName();
            this.qNames[n2] = qName = DOCUMENT_FACTORY.createQName(string2);
            this.readMethods[n2] = propertyDescriptor.getReadMethod();
            this.writeMethods[n2] = propertyDescriptor.getWriteMethod();
            Integer n3 = new Integer(n2);
            this.nameMap.put((Object)string2, (Object)n3);
            this.nameMap.put((Object)qName, (Object)n3);
            ++n2;
        }
    }

    public static BeanMetaData get(Class class_) {
        BeanMetaData beanMetaData = (BeanMetaData)singletonCache.get((Object)class_);
        if (beanMetaData == null) {
            beanMetaData = new BeanMetaData(class_);
            singletonCache.put((Object)class_, (Object)beanMetaData);
        }
        return beanMetaData;
    }

    public int attributeCount() {
        return this.propertyDescriptors.length;
    }

    public BeanAttributeList createAttributeList(BeanElement beanElement) {
        return new BeanAttributeList(beanElement, (BeanMetaData)this);
    }

    public Object getData(int n, Object object) {
        try {
            Object object2 = this.readMethods[n].invoke(object, NULL_ARGS);
            return object2;
        }
        catch (Exception var3_4) {
            this.handleException(var3_4);
            return null;
        }
    }

    public int getIndex(String string2) {
        Integer n = (Integer)this.nameMap.get((Object)string2);
        if (n != null) {
            return n;
        }
        return -1;
    }

    public int getIndex(QName qName) {
        Integer n = (Integer)this.nameMap.get((Object)qName);
        if (n != null) {
            return n;
        }
        return -1;
    }

    public QName getQName(int n) {
        return this.qNames[n];
    }

    protected void handleException(Exception exception) {
    }

    public void setData(int n, Object object, Object object2) {
        try {
            this.writeMethods[n].invoke(object, new Object[]{object2});
            return;
        }
        catch (Exception var4_4) {
            this.handleException(var4_4);
            return;
        }
    }
}

