ips1ap101.lib.core.web.app.EJBL.java Source code

Java tutorial

Introduction

Here is the source code for ips1ap101.lib.core.web.app.EJBL.java

Source

/*
 * Este programa es software libre; usted puede redistribuirlo y/o modificarlo bajo los terminos
 * de la licencia "GNU General Public License" publicada por la Fundacion "Free Software Foundation".
 * Este programa se distribuye con la esperanza de que pueda ser util, pero SIN NINGUNA GARANTIA;
 * vea la licencia "GNU General Public License" para obtener mas informacion.
 */
package ips1ap101.lib.core.web.app;

import java.text.MessageFormat;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import ips1ap101.lib.base.persistence.facade.ClaseRecursoFacadeBase;
import ips1ap101.lib.base.persistence.facade.ConjuntoSegmentoFacadeBase;
import ips1ap101.lib.base.persistence.facade.DominioFacadeBase;
import ips1ap101.lib.base.persistence.facade.FiltroFuncionFacadeBase;
import ips1ap101.lib.base.persistence.facade.FuncionFacadeBase;
import ips1ap101.lib.base.persistence.facade.FuncionParametroFacadeBase;
import ips1ap101.lib.base.persistence.facade.RolFacadeBase;
import ips1ap101.lib.base.persistence.facade.UsuarioFacadeBase;
import ips1ap101.lib.base.persistence.facade.VistaFuncionFacadeBase;
import ips1ap101.lib.core.app.Bitacora;
import ips1ap101.lib.core.constant.EAC;
import ips1ap101.lib.core.util.EA;
import org.apache.commons.lang.StringUtils;

/**
 * @author Jorge Campins
 */
public class EJBL {

    /**
     * @see ips1ap101.lib.core.db.xdp.ListaRecursoCachedRowSetDataProvider
     */
    public static ClaseRecursoFacadeBase getClaseRecursoFacade() {
        return (ClaseRecursoFacadeBase) lookup(ClaseRecursoFacadeBase.class);
    }

    /**
     * @see ips1ap101.lib.core.control.UsuarioAutenticado
     */
    public static ConjuntoSegmentoFacadeBase getConjuntoSegmentoFacade() {
        return (ConjuntoSegmentoFacadeBase) lookup(ConjuntoSegmentoFacadeBase.class);
    }

    /**
     * @see ips1ap101.lib.core.db.xdp.ListaRecursoCachedRowSetDataProvider
     */
    public static DominioFacadeBase getDominioFacade() {
        return (DominioFacadeBase) lookup(DominioFacadeBase.class);
    }

    /**
     * @see ips1ap101.lib.core.app.FiltroBusqueda
     */
    public static FiltroFuncionFacadeBase getFiltroFuncionFacade() {
        return (FiltroFuncionFacadeBase) lookup(FiltroFuncionFacadeBase.class);
    }

    /**
     * @see ips1ap101.lib.core.control.Controlador
     * @see ips1ap101.lib.core.db.xdp.ListaRecursoCachedRowSetDataProvider
     */
    public static FuncionFacadeBase getFuncionFacade() {
        return (FuncionFacadeBase) lookup(FuncionFacadeBase.class);
    }

    /**
     * @see ips1ap101.web.commons.assistants.ext.AsistentePaginaActualizacionFiltroFuncionParX
     * @see ips1ap101.web.commons.assistants.ext.AsistentePaginaActualizacionRolFuncionParX
     * @see ips1ap101.web.commons.assistants.ext.AsistentePaginaActualizacionVistaFuncionColX
     */
    public static FuncionParametroFacadeBase getFuncionParametroFacade() {
        return (FuncionParametroFacadeBase) lookup(FuncionParametroFacadeBase.class);
    }

    /**
     * @see ips1ap101.lib.core.control.UsuarioAutenticado
     */
    public static RolFacadeBase getRolFacade() {
        return (RolFacadeBase) lookup(RolFacadeBase.class);
    }

    /**
     * @see ips1ap101.lib.core.control.UsuarioAutenticado
     */
    public static UsuarioFacadeBase getUsuarioFacade() {
        return (UsuarioFacadeBase) lookup(UsuarioFacadeBase.class);
    }

    /**
     * @see ips1ap101.lib.core.db.util.VistaFuncionWrapper
     */
    public static VistaFuncionFacadeBase getVistaFuncionFacade() {
        return (VistaFuncionFacadeBase) lookup(VistaFuncionFacadeBase.class);
    }

    public static Object lookup(Class<?> interfaz) {
        Bitacora.trace(EJBL.class, "lookup", interfaz);
        String key = EAC.JNDI_EJB_LOOKUP_PATTERN;
        String pattern = EA.getString(key);
        String base = interfaz.getSimpleName();
        String bean = StringUtils.removeEnd(base, "Base") + "Bean";
        String jndi = MessageFormat.format(pattern, bean, interfaz.getName());
        Bitacora.trace(key + "=" + pattern);
        Bitacora.trace(key + "=" + jndi);
        try {
            Object facade = InitialContext.doLookup(jndi);
            boolean assignable = facade != null && interfaz.isAssignableFrom(facade.getClass());
            Bitacora.trace(bean + "=" + facade);
            Bitacora.trace(base + "=" + assignable);
            return facade;
        } catch (NamingException ex) {
            throw new RuntimeException(ex);
        }
    }

}