empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/app/FacesConfiguration.java [74:271]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class FacesConfiguration
{
    protected static final Logger log = LoggerFactory.getLogger(FacesConfiguration.class);

    public final static String EMPIRE_COMPONENT_FAMILY = "org.apache.empire.component";
    
    /*
     * Initialized
     */
    private static boolean initialized = false;
    public static boolean isInitialized()
    {
        return initialized; 
    }

    /*
     * Project Stage
     * see org.apache.myfaces.application.ApplicationImpl
     * How to set:
     *   set JVM-Parameter:     "org.apache.myfaces.PROJECT_STAGE"
     *   set JNDI-Parameter:    "java:comp/env/jsf/ProjectStage"
     *   set in web.inf:        
     *      <context-param>
     *          <param-name>jakarta.faces.PROJECT_STAGE</param-name>
     *          <param-value>Development</param-value>
     *      </context-param>
     */
    private static ProjectStage projectStage;
    public static ProjectStage getProjectStage()
    {
        if (projectStage==null)
            throw new ObjectNotValidException(FacesConfiguration.class, "Not Initialized");
        return projectStage;
    }
    
    /**
     * Static Initializer
     * @param configClass the configuration class
     * @param startupContext the startupContext
     * @param facesImpl the Faces implementation
     */
    public static <T extends FacesConfiguration> void initialize(Class<T> configClass, FacesContext startupContext, FacesImplementation facesImpl)
    {
        // crate and initialize
        FacesConfiguration fConfig = ClassUtils.newInstance(configClass, FacesImplementation.class, facesImpl);
        fConfig.initialize(startupContext);
    }

    /*
     * Inject
     */
    protected final FacesImplementation facesImpl;
    /*
     * Temp Variables
     */
    protected ExternalContext externalContext;
    protected Application application;
    /*
     * Lazy
     */
    private BeanStorageProvider beanStorage; // call getBeanStorageProvider() 

    public FacesConfiguration(FacesImplementation facesImpl)
    {
        this.facesImpl = facesImpl;
    }

    public final void initialize(FacesContext startupContext)
    {
        if (initialized)
            throw new InvalidOperationException("FacesConfiguration already initialized!"); 
        try
        {   // Set temporary variables
            this.externalContext = startupContext.getExternalContext();
            this.application = startupContext.getApplication();
            this.beanStorage = null;

            projectStage = application.getProjectStage();
            log.info("Initializing Faces Configuration for ProjectStage {}", projectStage.name());
            
            // Init everything
            initAll(startupContext);

            // done
            log.info("Faces Configuration complete.");
        }
        finally
        {   // cleanup
            this.beanStorage = null;
            this.application = null;
            this.externalContext = null;
            this.facesImpl.configComplete();
            // set initialized (even if Exception has been thrown)
            initialized = true;
        }
    }
    
    /*
     * Overrideable methods
     */
    
    protected void initAll(FacesContext context)
    {
        log.debug("Init FacesParams...");
        initFacesParams();
        
        log.debug("Init Factories...");
        initFactories();

        log.debug("Init NavigationHandler...");
        initNavigationHandler();
        
        log.debug("Init ResourceHandler...");
        initResourceHandler();

        log.debug("Registrating Converters...");
        initConverters();

        log.debug("Registrating EL-Resolvers...");
        initElResolvers();
        
        log.debug("Registrating Lifecycle...");
        initLifecycle(new LifecycleUpdater());

        log.debug("Registrating Search Expression Resolvers...");
        initSearchExpressionResolvers();

        log.debug("Registrating Components...");
        initComponents();

        log.debug("Registrating Renderers...");
        initRenderers(new RenderKitUpdater(getApplicationRenderKit(context)));

        log.debug("Registrating Managed Beans...");
        initManagedBeans();            

        log.debug("Registrating Controls...");
        initControls();
    }

    protected void initFacesParams()
    {   // set params
        setFacesInitParam(ViewHandler.FACELETS_SKIP_COMMENTS_PARAM_NAME, true);
    }

    protected void initFactories()
    {
        // Noting yet
        /* example
         *  log.info("Setting Factory {}", FactoryFinder.TAG_HANDLER_DELEGATE_FACTORY);
            FactoryFinder.setFactory(FactoryFinder.TAG_HANDLER_DELEGATE_FACTORY, CustomTagHandlerDelegateFactory.class.getName());
            // (check)
            // TagHandlerDelegateFactory tagHandlerFactory = (TagHandlerDelegateFactory)FactoryFinder.getFactory(FactoryFinder.TAG_HANDLER_DELEGATE_FACTORY);
            // log.info(tagHandlerFactory.getClass().getName());
         */
    }
    
    protected void initNavigationHandler()
    {
        NavigationHandler wrapped = application.getNavigationHandler();
        if (wrapped instanceof PageNavigationHandler)
            return; // Already set
        // replace
        log.info("Setting NavigationHandler to {}", PageNavigationHandler.class.getName());
        application.setNavigationHandler(new PageNavigationHandler(wrapped));
    }
    
    protected void initResourceHandler()
    {
        // Not implemented
        // application.setResourceHandler(new MyResourceHandler(wrapped));
    }

    protected void initConverters()
    {
        // Noting
    }

    protected void initElResolvers()
    {
        // add
        addELResolver(DBELResolver.class);
        addELResolver(PagesELResolver.class);
    }
    
    protected void initLifecycle(LifecycleUpdater lcu)
    {
        lcu.addPhaseListener(FacesRequestPhaseListener.class);
        lcu.addPhaseListener(PagePhaseListener.class);
    }

    protected void initSearchExpressionResolvers()
    {
        // Nothing
        // SearchExpressionResolverFactory.registerResolver("@fragment", new FragmentExpressionResolver());
    }

    protected void initComponents()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesConfiguration.java [74:271]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class FacesConfiguration
{
    protected static final Logger log = LoggerFactory.getLogger(FacesConfiguration.class);

    public final static String EMPIRE_COMPONENT_FAMILY = "org.apache.empire.component";
    
    /*
     * Initialized
     */
    private static boolean initialized = false;
    public static boolean isInitialized()
    {
        return initialized; 
    }

    /*
     * Project Stage
     * see org.apache.myfaces.application.ApplicationImpl
     * How to set:
     *   set JVM-Parameter:     "org.apache.myfaces.PROJECT_STAGE"
     *   set JNDI-Parameter:    "java:comp/env/jsf/ProjectStage"
     *   set in web.inf:        
     *      <context-param>
     *          <param-name>javax.faces.PROJECT_STAGE</param-name>
     *          <param-value>Development</param-value>
     *      </context-param>
     */
    private static ProjectStage projectStage;
    public static ProjectStage getProjectStage()
    {
        if (projectStage==null)
            throw new ObjectNotValidException(FacesConfiguration.class, "Not Initialized");
        return projectStage;
    }
    
    /**
     * Static Initializer
     * @param configClass the configuration class
     * @param startupContext the startupContext
     * @param facesImpl the Faces implementation
     */
    public static <T extends FacesConfiguration> void initialize(Class<T> configClass, FacesContext startupContext, FacesImplementation facesImpl)
    {
        // crate and initialize
        FacesConfiguration fConfig = ClassUtils.newInstance(configClass, FacesImplementation.class, facesImpl);
        fConfig.initialize(startupContext);
    }

    /*
     * Inject
     */
    protected final FacesImplementation facesImpl;
    /*
     * Temp Variables
     */
    protected ExternalContext externalContext;
    protected Application application;
    /*
     * Lazy
     */
    private BeanStorageProvider beanStorage; // call getBeanStorageProvider() 

    public FacesConfiguration(FacesImplementation facesImpl)
    {
        this.facesImpl = facesImpl;
    }

    public final void initialize(FacesContext startupContext)
    {
        if (initialized)
            throw new InvalidOperationException("FacesConfiguration already initialized!"); 
        try
        {   // Set temporary variables
            this.externalContext = startupContext.getExternalContext();
            this.application = startupContext.getApplication();
            this.beanStorage = null;

            projectStage = application.getProjectStage();
            log.info("Initializing Faces Configuration for ProjectStage {}", projectStage.name());
            
            // Init everything
            initAll(startupContext);

            // done
            log.info("Faces Configuration complete.");
        }
        finally
        {   // cleanup
            this.beanStorage = null;
            this.application = null;
            this.externalContext = null;
            this.facesImpl.configComplete();
            // set initialized (even if Exception has been thrown)
            initialized = true;
        }
    }
    
    /*
     * Overrideable methods
     */
    
    protected void initAll(FacesContext context)
    {
        log.debug("Init FacesParams...");
        initFacesParams();
        
        log.debug("Init Factories...");
        initFactories();

        log.debug("Init NavigationHandler...");
        initNavigationHandler();
        
        log.debug("Init ResourceHandler...");
        initResourceHandler();

        log.debug("Registrating Converters...");
        initConverters();

        log.debug("Registrating EL-Resolvers...");
        initElResolvers();
        
        log.debug("Registrating Lifecycle...");
        initLifecycle(new LifecycleUpdater());

        log.debug("Registrating Search Expression Resolvers...");
        initSearchExpressionResolvers();

        log.debug("Registrating Components...");
        initComponents();

        log.debug("Registrating Renderers...");
        initRenderers(new RenderKitUpdater(getApplicationRenderKit(context)));

        log.debug("Registrating Managed Beans...");
        initManagedBeans();            

        log.debug("Registrating Controls...");
        initControls();
    }

    protected void initFacesParams()
    {   // set params
        setFacesInitParam(ViewHandler.FACELETS_SKIP_COMMENTS_PARAM_NAME, true);
    }

    protected void initFactories()
    {
        // Noting yet
        /* example
         *  log.info("Setting Factory {}", FactoryFinder.TAG_HANDLER_DELEGATE_FACTORY);
            FactoryFinder.setFactory(FactoryFinder.TAG_HANDLER_DELEGATE_FACTORY, CustomTagHandlerDelegateFactory.class.getName());
            // (check)
            // TagHandlerDelegateFactory tagHandlerFactory = (TagHandlerDelegateFactory)FactoryFinder.getFactory(FactoryFinder.TAG_HANDLER_DELEGATE_FACTORY);
            // log.info(tagHandlerFactory.getClass().getName());
         */
    }
    
    protected void initNavigationHandler()
    {
        NavigationHandler wrapped = application.getNavigationHandler();
        if (wrapped instanceof PageNavigationHandler)
            return; // Already set
        // replace
        log.info("Setting NavigationHandler to {}", PageNavigationHandler.class.getName());
        application.setNavigationHandler(new PageNavigationHandler(wrapped));
    }
    
    protected void initResourceHandler()
    {
        // Not implemented
        // application.setResourceHandler(new MyResourceHandler(wrapped));
    }

    protected void initConverters()
    {
        // Noting
    }

    protected void initElResolvers()
    {
        // add
        addELResolver(DBELResolver.class);
        addELResolver(PagesELResolver.class);
    }
    
    protected void initLifecycle(LifecycleUpdater lcu)
    {
        lcu.addPhaseListener(FacesRequestPhaseListener.class);
        lcu.addPhaseListener(PagePhaseListener.class);
    }

    protected void initSearchExpressionResolvers()
    {
        // Nothing
        // SearchExpressionResolverFactory.registerResolver("@fragment", new FragmentExpressionResolver());
    }

    protected void initComponents()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



