package p2.pao.custom;

import baseclass.PaoCust;
import baseclass.PaoSetCust;
import p2.pao.Pao;
import p2.pao.PaoServer;
import p2.pao.PaoSet;
import p2.util.P2Exception;

import java.lang.reflect.Constructor;

public class SimplePaoSet extends PaoSetCust {

    public SimplePaoSet(PaoServer paramPaoServer) throws P2Exception {
        super(paramPaoServer);
    }

    @Override
    protected Pao getPaoInstance(PaoSet arg0) throws P2Exception {
        PaoCust basic = null;
        String tablename = arg0.getName().toLowerCase();
        try {
            Class<?> clazz = Class.forName("p2.application." + tablename + "." + tablename);// 具体执行的类
            Constructor<?> c = clazz
                    .getDeclaredConstructor(new Class[]{PaoSet.class});
            c.setAccessible(true);
            basic = (PaoCust) c.newInstance(arg0);// 获取执行类的父级类
        } catch (Exception e) {
            return new SimplePao(arg0);
        }
        return basic;
    }
}