package com.neusoft.smart.pos.order.service;

public class ServiceFactory {

    /**
     * 获得订单管理服务实例的方法
     * @param packageName 订单管理扩展类包名
     * @param implClassName 订单管理扩展类类名
     * @return
     */
    public static OrderService getOrderServiceInstance(String packageName, String implClassName){
        OrderService orderService = null;
        if(implClassName == null || implClassName.equals("")){
            orderService = new OrderService();
        }else{
            Object terminalObj = null;
            if(packageName == null || packageName.equals("")){
                packageName = "com.neusoft.smart.pos.order.service";
            }
            try {
                Class<?> clazz = Class.forName(packageName + implClassName);
                terminalObj = clazz.newInstance();
                if (terminalObj instanceof OrderService) {
                    orderService = (OrderService) terminalObj;
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return orderService;
    }

    /**
     * 获得退款订单管理服务实例的方法
     * @param packageName 退款订单管理扩展类包名
     * @param implClassName 退款订单管理扩展类类名
     * @return
     */
    public static RefundOrderService getRefundOrderServiceInstance(String packageName, String implClassName){
        RefundOrderService refundOrderService = null;
        if(implClassName == null || implClassName.equals("")){
            refundOrderService = new RefundOrderService();
        }else{
            Object terminalObj = null;
            if(packageName == null || packageName.equals("")){
                packageName = "com.neusoft.smart.pos.order.service";
            }
            try {
                Class<?> clazz = Class.forName(packageName + implClassName);
                terminalObj = clazz.newInstance();
                if (terminalObj instanceof RefundOrderService) {
                    refundOrderService = (RefundOrderService) terminalObj;
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return refundOrderService;
    }
}
