package org.ovirt.engine.core.bll.utils;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Singleton;

import org.ovirt.engine.core.dal.dbbroker.DbFacade;
import org.ovirt.engine.core.dao.PermissionDAO;
import org.ovirt.engine.core.dao.HostDeviceDao;
import org.ovirt.engine.core.dao.StoragePoolDAO;
import org.ovirt.engine.core.dao.VdsDAO;
import org.ovirt.engine.core.dao.VdsGroupDAO;
import org.ovirt.engine.core.dao.VmDeviceDAO;
import org.ovirt.engine.core.dao.VmDynamicDAO;
import org.ovirt.engine.core.dao.network.HostNetworkQosDao;
import org.ovirt.engine.core.dao.network.InterfaceDao;
import org.ovirt.engine.core.dao.network.NetworkClusterDao;
import org.ovirt.engine.core.dao.network.NetworkDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class is made to keep all producers of bll dependencies, generally singletons from other jars in one place for the
 * dependency scanner to identify. except for producers like for Log (see produceLogger),
 * this class will bridge the dependency resolution limitation we have between non-ejb module jars which contains
 * dependencies to the bll ejb-jar. NOTE: future jboss version should solve that so we could have beans dependencies
 * scanned from other non-ejb module jars such as org.ovirt.engine.core:dal
 *
 * Producers could be declared either by a field or by a method, to get more control on the production of an instance
 *
 * There is no need to instantiate this class and there is no visible usage to it but to the dependency scanner
 *
 *
 */
@ApplicationScoped
public class BllCDIAdapter {

    /**
     * this producer enables injection of Logger instance. Its not intended to be used as protected instance as the
     * runtime instance is the declaring class so use directly as a private member.
     * <code>
     * @Inject private Logger log; </code>
     * @param injectionPoint
     */
    @Produces
    public Logger produceLogger(InjectionPoint injectionPoint) {
        return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass());
    }

    @Produces
    private NetworkDao produceNetworkDao(DbFacade dbFacade) {
        return dbFacade.getNetworkDao();
    }

    @Produces
    private NetworkClusterDao produceNetworkClusterDao(DbFacade dbFacade) {
        return dbFacade.getNetworkClusterDao();
    }

    @Produces
    private VdsGroupDAO produceVdsGroupDao(DbFacade dbFacade) {
        return dbFacade.getVdsGroupDao();
    }

    @Produces
    private StoragePoolDAO produceStoragePoolDAO(DbFacade dbFacade) {
        return dbFacade.getStoragePoolDao();
    }

    @Produces
    private VmDynamicDAO produceVmDynamicDAO(DbFacade dbFacade) {
        return dbFacade.getVmDynamicDao();
    }

    @Produces
    private InterfaceDao produceInterfaceDao(DbFacade dbFacade) {
        return dbFacade.getInterfaceDao();
    }

    @Produces
    private HostNetworkQosDao produceHostNetworkQosDao(DbFacade dbFacade) {
        return dbFacade.getHostNetworkQosDao();
    }

    @Produces
    @Singleton
    private PermissionDAO producePermissionDao(DbFacade dbFacade) {
        return dbFacade.getPermissionDao();
    }

    @Produces
    private VmDeviceDAO produceVmDeviceDao(DbFacade dbFacade) {
        return dbFacade.getVmDeviceDao();
    }

    @Produces
    private HostDeviceDao produceHostDeviceDao(DbFacade dbFacade) {
        return dbFacade.getHostDeviceDao();
    }

    @Produces
    private VdsDAO produceVdsDao(DbFacade dbFacade) {
        return dbFacade.getVdsDao();
    }

    protected BllCDIAdapter() {
        // hide me
    }
}

@@ -63,125 +63,23 @@
 ise.
-context.ApplicationScoped;%0Aimport javax.enterprise.inject.Produces;%0Aimport javax.enterprise.inject.spi.InjectionPoint
+inject.Produces
 ;%0Aim
@@ -716,65 +716,8 @@
 Dao;
-%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0A/*
@@ -1480,34 +1480,20 @@
 r%0A *
-%0A *%0A */%0A@ApplicationScoped
+/%0A@Singleton
 %0Apub
@@ -1523,484 +1523,8 @@
  %7B%0A%0A
-    /**%0A     * this producer enables injection of Logger instance. Its not intended to be used as protected instance as the%0A     * runtime instance is the declaring class so use directly as a private member.%0A     * %3Ccode%3E%0A     * @Inject private Logger log; %3C/code%3E%0A     * @param injectionPoint%0A     */%0A    @Produces%0A    public Logger produceLogger(InjectionPoint injectionPoint) %7B%0A        return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass());%0A    %7D%0A%0A
     
@@ -2986,15 +2986,13 @@
   pr
-otec
+iva
 te
-d
  Bll

remove produceLogger method (take 2)