empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/impl/MyFacesImplementation.java [44:183]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class MyFacesImplementation implements FacesImplementation 
{
    // Logger
    private static final Logger log = LoggerFactory.getLogger(FacesImplementation.class);

    private final RuntimeConfig runtimeConfig;
    
    public MyFacesImplementation(ExternalContext externalContext)
    {
        log.debug("MyFacesImplementation created");
        this.runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
    }
    
    /*
	@Override
	public void initApplication(FacesApplication application)
	{
		ApplicationFactoryImpl applFactoryImpl = new ApplicationFactoryImpl();
        // set impl
        application.setImplementation(this, applFactoryImpl.getApplication());
        applFactoryImpl.setApplication(application);
	}
	*/

    @Override
    public boolean registerElResolver(Class<? extends ELResolver> resolverClass)
    {
        List<ELResolver> list = runtimeConfig.getFacesConfigElResolvers();
        if (list!=null) {
            for (ELResolver resolver : list)
            {
                if (resolver.getClass().equals(resolverClass))
                    return false; // already there
            }
        }
        // Check
        Application app = FacesContext.getCurrentInstance().getApplication();
        if ((app instanceof ApplicationImpl) && ClassUtils.getPrivateFieldValue(app, "elResolver")!=null)
        {   // Too late: ElResolver chain has already been built
            log.error("ElResolver chain has already been built. Please define in faces-config.xml");
            throw new NotSupportedException(this, "registerElResolver");
        }
        // create
        ELResolver elResolver = ClassUtils.newInstance(resolverClass);
        // Add to bean storage
        getBeanStorageProvider(null).injectBean(elResolver);
        // Add to RuntimeConfig
        runtimeConfig.addFacesConfigElResolver(elResolver);
        return true;
    }
    
	@Override
	public void registerManagedBean(final String beanName, final String beanClass, final String scope) 
	{	// check
        if (runtimeConfig.getManagedBeans().containsKey(beanName))
        {
            throw new ItemExistsException(beanName);
        }
        // register now
        // ManagedBean mbi = new ManagedBean();   --> Use this for Myfaces 2.1.x 
        ManagedBeanImpl mbi = new ManagedBeanImpl();  // new since Myfaces 2.2.x
        mbi.setName(beanName);
        mbi.setBeanClass(beanClass);
        mbi.setScope(scope);
        runtimeConfig.addManagedBean(beanName, mbi);
	}

	@Override
	public Object getManagedBean(final String beanName, final FacesContext fc)
	{
		// Find Bean
        final ELContext elcontext = fc.getELContext();
        final Application application = fc.getApplication();
        return application.getELResolver().getValue(elcontext, null, beanName);
	}

	/*
	 * Obsolete since 2025-01-08 with EMPIREDB-453
	 * 
	@Override
	public UIComponent getValueParentComponent(final ValueExpression ve)
	{
		return null;
	}

    @Override
    public ValueExpression unwrapValueExpression(ValueExpression ve)
    {
        return ValueExpressionUnwrapper.getInstance().unwrap(ve, "${");
    }
    */

    private BeanStorageProvider beanStorage = null;

    @Override
    public BeanStorageProvider getBeanStorageProvider(ExternalContext externalContext)
    {
        if (beanStorage==null) {
            if (externalContext==null)
                externalContext = FacesContext.getCurrentInstance().getExternalContext();
            beanStorage = new MyFacesBeanStorageProvider(externalContext); 
        }
        return beanStorage; 
    }

    @Override
    public void configComplete()
    {
        beanStorage = null;
    }
    
    /**
     * BeanStorageProvider
     */
    protected static class MyFacesBeanStorageProvider implements BeanStorageProvider
    {
        private final List<BeanEntry> injectedBeanStorage;
        private final InjectionProvider injectionProvider;

        @SuppressWarnings("unchecked")
        public MyFacesBeanStorageProvider(ExternalContext ec)
        {
           this.injectionProvider = InjectionProviderFactory.getInjectionProviderFactory(ec).getInjectionProvider(ec);
           final String INJECTED_BEAN_STORAGE_KEY = "org.apache.myfaces.spi.BEAN_ENTRY_STORAGE";
           this.injectedBeanStorage = (List<BeanEntry>)ec.getApplicationMap().get(INJECTED_BEAN_STORAGE_KEY);
           if (this.injectedBeanStorage==null)
               throw new ItemNotFoundException(INJECTED_BEAN_STORAGE_KEY);
        }
        
        @Override
        public void injectBean(Object bean)
        {   try
            {   // Add to bean storage
                Object creationMetaData = injectionProvider.inject(bean);
                injectedBeanStorage.add(new BeanEntry(bean, creationMetaData));
                injectionProvider.postConstruct(bean, creationMetaData);
            }
            catch (InjectionProviderException e)
            {
                throw new InternalException(e);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



empire-db-jsf2/src/main/java/org/apache/empire/jsf2/impl/MyFacesImplementation.java [44:183]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class MyFacesImplementation implements FacesImplementation 
{
    // Logger
    private static final Logger log = LoggerFactory.getLogger(FacesImplementation.class);

    private final RuntimeConfig runtimeConfig;
    
    public MyFacesImplementation(ExternalContext externalContext)
    {
        log.debug("MyFacesImplementation created");
        this.runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
    }
    
    /*
	@Override
	public void initApplication(FacesApplication application)
	{
		ApplicationFactoryImpl applFactoryImpl = new ApplicationFactoryImpl();
        // set impl
        application.setImplementation(this, applFactoryImpl.getApplication());
        applFactoryImpl.setApplication(application);
	}
	*/

    @Override
    public boolean registerElResolver(Class<? extends ELResolver> resolverClass)
    {
        List<ELResolver> list = runtimeConfig.getFacesConfigElResolvers();
        if (list!=null) {
            for (ELResolver resolver : list)
            {
                if (resolver.getClass().equals(resolverClass))
                    return false; // already there
            }
        }
        // Check
        Application app = FacesContext.getCurrentInstance().getApplication();
        if ((app instanceof ApplicationImpl) && ClassUtils.getPrivateFieldValue(app, "elResolver")!=null)
        {   // Too late: ElResolver chain has already been built
            log.error("ElResolver chain has already been built. Please define in faces-config.xml");
            throw new NotSupportedException(this, "registerElResolver");
        }
        // create
        ELResolver elResolver = ClassUtils.newInstance(resolverClass);
        // Add to bean storage
        getBeanStorageProvider(null).injectBean(elResolver);
        // Add to RuntimeConfig
        runtimeConfig.addFacesConfigElResolver(elResolver);
        return true;
    }
    
	@Override
	public void registerManagedBean(final String beanName, final String beanClass, final String scope) 
	{	// check
        if (runtimeConfig.getManagedBeans().containsKey(beanName))
        {
            throw new ItemExistsException(beanName);
        }
        // register now
        // ManagedBean mbi = new ManagedBean();   --> Use this for Myfaces 2.1.x 
        ManagedBeanImpl mbi = new ManagedBeanImpl();  // new since Myfaces 2.2.x
        mbi.setName(beanName);
        mbi.setBeanClass(beanClass);
        mbi.setScope(scope);
        runtimeConfig.addManagedBean(beanName, mbi);
	}

	@Override
	public Object getManagedBean(final String beanName, final FacesContext fc)
	{
		// Find Bean
        final ELContext elcontext = fc.getELContext();
        final Application application = fc.getApplication();
        return application.getELResolver().getValue(elcontext, null, beanName);
	}

	/*
	 * Obsolete since 2025-01-08 with EMPIREDB-453
	 * 
	@Override
	public UIComponent getValueParentComponent(final ValueExpression ve)
	{
		return null;
	}

    @Override
    public ValueExpression unwrapValueExpression(ValueExpression ve)
    {
        return ValueExpressionUnwrapper.getInstance().unwrap(ve, "${");
    }
    */

    private BeanStorageProvider beanStorage = null;

    @Override
    public BeanStorageProvider getBeanStorageProvider(ExternalContext externalContext)
    {
        if (beanStorage==null) {
            if (externalContext==null)
                externalContext = FacesContext.getCurrentInstance().getExternalContext();
            beanStorage = new MyFacesBeanStorageProvider(externalContext); 
        }
        return beanStorage; 
    }

    @Override
    public void configComplete()
    {
        beanStorage = null;
    }
    
    /**
     * BeanStorageProvider
     */
    protected static class MyFacesBeanStorageProvider implements BeanStorageProvider
    {
        private final List<BeanEntry> injectedBeanStorage;
        private final InjectionProvider injectionProvider;

        @SuppressWarnings("unchecked")
        public MyFacesBeanStorageProvider(ExternalContext ec)
        {
           this.injectionProvider = InjectionProviderFactory.getInjectionProviderFactory(ec).getInjectionProvider(ec);
           final String INJECTED_BEAN_STORAGE_KEY = "org.apache.myfaces.spi.BEAN_ENTRY_STORAGE";
           this.injectedBeanStorage = (List<BeanEntry>)ec.getApplicationMap().get(INJECTED_BEAN_STORAGE_KEY);
           if (this.injectedBeanStorage==null)
               throw new ItemNotFoundException(INJECTED_BEAN_STORAGE_KEY);
        }
        
        @Override
        public void injectBean(Object bean)
        {   try
            {   // Add to bean storage
                Object creationMetaData = injectionProvider.inject(bean);
                injectedBeanStorage.add(new BeanEntry(bean, creationMetaData));
                injectionProvider.postConstruct(bean, creationMetaData);
            }
            catch (InjectionProviderException e)
            {
                throw new InternalException(e);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



