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.StoragePoolDAO;
import org.ovirt.engine.core.dao.VdsGroupDAO;
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();
    }

    protected BllCDIAdapter() {
        // hide me
    }
}

@@ -306,24 +306,72 @@
 missionDAO;%0A
+import org.ovirt.engine.core.dao.HostDeviceDao;%0A
 import org.o
@@ -443,21 +443,108 @@
 .dao.Vds
-Group
+DAO;%0Aimport org.ovirt.engine.core.dao.VdsGroupDAO;%0Aimport org.ovirt.engine.core.dao.VmDevice
 DAO;%0Aimp
@@ -3249,24 +3249,396 @@
 o();%0A    %7D%0A%0A
+    @Produces%0A    private VmDeviceDAO produceVmDeviceDao(DbFacade dbFacade) %7B%0A        return dbFacade.getVmDeviceDao();%0A    %7D%0A%0A    @Produces%0A    private HostDeviceDao produceHostDeviceDao(DbFacade dbFacade) %7B%0A        return dbFacade.getHostDeviceDao();%0A    %7D%0A%0A    @Produces%0A    private VdsDAO produceVdsDao(DbFacade dbFacade) %7B%0A        return dbFacade.getVdsDao();%0A    %7D%0A%0A
     protecte

Enable injection of VmDevice, HostDevice and Vds DAOs