Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2008, Red Hat Middleware LLC, and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.environment.servlet.jsf;
 
 import  javax.faces.application.Application;
 import  javax.faces.context.FacesContext;
 import  javax.servlet.ServletContext;
 

Author(s):
Pete Muir
Dan Allen
Ales Justin
 
 public class WeldApplication extends ForwardingApplication {
    
The BeanManager may not have been initialized at the time JSF is initializing. Therefore, we stick in a ForwardingELResolver that delegates to the BeanManager ELResolver, which will be plugged in when it's available. If the ELResolver is invoked before the BeanManager is available, the resolver will perform no action (and thus produce no result).
 
     private static class LazyBeanManagerIntegrationELResolver extends ForwardingELResolver {
         private ELResolver delegate;
 
         public LazyBeanManagerIntegrationELResolver() {
              = new TransparentELResolver();
         }
 
         public void beanManagerReady(BeanManager beanManager) {
             this. = beanManager.getELResolver();
         }
 
         @Override
         protected ELResolver delegate() {
             return ;
         }
     }
 
     private final Application application;
     private BeanManager beanManager;
 
     public WeldApplication(Application application) {
         this. = application;
         // QUESTION should the context listener be registered in init() instead?
         application.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.weld.el.WeldELContextListener"));
         application.addELResolver();
     }
 
     private void init() {
         ExpressionFactory expressionFactory = this.;
         BeanManager beanManager = null;
         if (expressionFactory == null && (expressionFactory = .getExpressionFactory()) != null && (beanManager = beanManager()) != null) {
             .beanManagerReady(beanManager);
             this. = beanManager.wrapExpressionFactory(expressionFactory);
         }
     }
 
     @Override
     protected Application delegate() {
         init();
         return ;
     }
 
     @Override
         init();
         if ( == null) {
             return .getExpressionFactory();
         } else {
             return ;
         }
     }
    private BeanManager beanManager() {
        FacesContext facesContext;
        if ( == null && (facesContext = FacesContext.getCurrentInstance()) != null) {
            Object obj = facesContext.getExternalContext().getContext();
            boolean notFound = false;
            try {
                if (obj instanceof ServletContext) {
                    final ServletContext ctx = (ServletContext) obj;
                    final BeanManager tmp = (BeanManagerctx.getAttribute(.);
                    if (tmp == null) {
                        return null;
                    }
                    this. = tmp;
                } else if (PortletSupport.isPortletEnvSupported() && PortletSupport.isPortletContext(obj)) {
                    final BeanManager tmp = PortletSupport.getBeanManager(obj);
                    if (tmp == null) {
                        return null;
                    }
                    this. = tmp;
                } else {
                    notFound = true;
                }
            } catch (Throwable t) {
                throw ..exceptionFetchingBeanManager(t);
            }
            if (notFound) {
                throw ..notInAServletOrPortlet();
            }
        }
        return ;
    }
New to GrepCode? Check out our FAQ X