Package org.apache.myfaces.context

Examples of org.apache.myfaces.context.RequestViewContext


    {
        // This and only this method handles @ResourceDependency and @ResourceDependencies annotations
        // The source of these annotations is Class<?> inspectedClass.
        // Because Class<?> and its annotations cannot change
        // during request/response, it is sufficient to process Class<?> only once per view.
        RequestViewContext rvc = RequestViewContext.getCurrentInstance(context);
        if (rvc.isClassAlreadyProcessed(inspectedClass))
        {
            return;
        }
        boolean classAlreadyProcessed = false;

       
        List<ResourceDependency> dependencyList = null;
        boolean isCachedList = false;
       
        if(isProduction && _classToResourceDependencyMap.containsKey(inspectedClass))
        {
            dependencyList = _classToResourceDependencyMap.get(inspectedClass);
            if(dependencyList == null)
            {
                return; //class has been inspected and did not contain any resource dependency annotations
            }
            else if (dependencyList.isEmpty())
            {
                return;
            }
           
            isCachedList = true;    // else annotations were found in the cache
        }
       
        if(dependencyList == null//not in production or the class hasn't been inspected yet
        {  
            ResourceDependency dependency = inspectedClass.getAnnotation(ResourceDependency.class);
            ResourceDependencies dependencies = inspectedClass.getAnnotation(ResourceDependencies.class);
            if(dependency != null || dependencies != null)
            {
                //resource dependencies were found using one or both annotations, create and build a new list
                dependencyList = new ArrayList<ResourceDependency>();
               
                if(dependency != null)
                {
                    dependencyList.add(dependency);
                }
               
                if(dependencies != null)
                {
                    dependencyList.addAll(Arrays.asList(dependencies.value()));
                }
            }
            else
            {
                dependencyList = Collections.emptyList();
            }
        }       
        // resource dependencies were found through inspection or from cache, handle them
        if (dependencyList != null && !dependencyList.isEmpty())
        {
            for (int i = 0, size = dependencyList.size(); i < size; i++)
            {
                ResourceDependency dependency = dependencyList.get(i);
                if (!rvc.isResourceDependencyAlreadyProcessed(dependency))
                {
                    _handleResourceDependency(context, component, dependency);
                    rvc.setResourceDependencyAsProcessed(dependency);
                }
            }
        }
       
        if(isProduction && !isCachedList)   //if we're in production and the list is not yet cached, store it
        {
            // Note at this point listenerForList cannot be null, but just let this
            // as a sanity check.
            if (dependencyList != null)
            {
                _classToResourceDependencyMap.put(inspectedClass, dependencyList);
            }
        }
       
        if (!classAlreadyProcessed)
        {
            rvc.setClassProcessed(inspectedClass);
        }
    }
View Full Code Here


    private void _handleResourceDependencyAnnotations(FacesContext context, Class<?> inspectedClass, UIComponent component, boolean isProduction)
    {
        // This and only this method handles @ResourceDependency and @ResourceDependencies annotations
        // The source of these annotations is Class<?> inspectedClass. Because Class<?> and its annotations cannot change
        // during request/response, it is sufficient to process Class<?> only once per view.
        RequestViewContext rvc = RequestViewContext.getCurrentInstance(context);
        if (rvc.isClassAlreadyProcessed(inspectedClass))
        {
            return;
        }
        boolean classAlreadyProcessed = false;

       
        List<ResourceDependency> dependencyList = null;
        boolean isCachedList = false;
       
        if(isProduction && _classToResourceDependencyMap.containsKey(inspectedClass))
        {
            dependencyList = _classToResourceDependencyMap.get(inspectedClass);
            if(dependencyList == null)
                return; //class has been inspected and did not contain any resource dependency annotations
           
            isCachedList = true;    // else annotations were found in the cache
        }
       
        if(dependencyList == null//not in production or the class hasn't been inspected yet
        {  
            ResourceDependency dependency = inspectedClass.getAnnotation(ResourceDependency.class);
            ResourceDependencies dependencies = inspectedClass.getAnnotation(ResourceDependencies.class);
            if(dependency != null || dependencies != null)
            {
                //resource dependencies were found using one or both annotations, create and build a new list
                dependencyList = new ArrayList<ResourceDependency>();
               
                if(dependency != null)
                    dependencyList.add(dependency);
               
                if(dependencies != null)
                    dependencyList.addAll(Arrays.asList(dependencies.value()));
            }
        }       
        if (dependencyList != null) //resource dependencies were found through inspection or from cache, handle them
        {
            for (ResourceDependency dependency : dependencyList)
            {
                if (!rvc.isResourceDependencyAlreadyProcessed(dependency))
                {
                    _handleResourceDependency(context, component, dependency);
                    rvc.setResourceDependencyAsProcessed(dependency);
                }
            }
        }
       
        if(isProduction && !isCachedList)   //if we're in production and the list is not yet cached, store it
            _classToResourceDependencyMap.put(inspectedClass, dependencyList)//null value stored for dependencyList means no annotations were found
       
        if (!classAlreadyProcessed) {
            rvc.setClassProcessed(inspectedClass);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.context.RequestViewContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.