[jboss-cvs] jboss-seam/src/ioc/org/jboss/seam/ioc/spring ...

Michael Youngstrom youngm at gmail.com
Tue Mar 20 17:33:02 EDT 2007


  User: myoungstrom
  Date: 07/03/20 17:33:02

  Modified:    src/ioc/org/jboss/seam/ioc/spring   ContextLoader.java
  Added:       src/ioc/org/jboss/seam/ioc/spring   SpringELResolver.java
  Log:
  Committ for issue: JBSEAM-1074
  
  Revision  Changes    Path
  1.4       +8 -2      jboss-seam/src/ioc/org/jboss/seam/ioc/spring/ContextLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ContextLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/ContextLoader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ContextLoader.java	19 Mar 2007 21:28:30 -0000	1.3
  +++ ContextLoader.java	20 Mar 2007 21:33:02 -0000	1.4
  @@ -25,7 +25,7 @@
    */
   @Scope(ScopeType.APPLICATION)
   @Intercept(NEVER)
  - at Startup
  + at Startup(depends="org.jboss.seam.ioc.spring.springELResolver")
   @Name("org.jboss.seam.ioc.spring.contextLoader")
   @Install(value = false, precedence = BUILT_IN)
   public class ContextLoader
  @@ -40,6 +40,7 @@
         try {
            webApplicationContext = createContextLoader(servletContext);
            servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
  +         startupContextLoader(webApplicationContext);
         } catch (Exception e) {
            servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, e);
            throw e;
  @@ -50,10 +51,15 @@
         XmlWebApplicationContext xmlWebApplicationContext = new XmlWebApplicationContext();
         xmlWebApplicationContext.setServletContext(servletContext);
         xmlWebApplicationContext.setConfigLocations(getConfigLocations());
  -      xmlWebApplicationContext.refresh();
         return xmlWebApplicationContext;
      }
   
  +   protected void startupContextLoader(WebApplicationContext webApplicationContext) {
  +      if(webApplicationContext instanceof ConfigurableWebApplicationContext) {
  +         ((ConfigurableWebApplicationContext)webApplicationContext).refresh();
  +      }
  +   }
  +
      @Destroy
      public void destroy() {
         if(webApplicationContext != null && webApplicationContext instanceof ConfigurableWebApplicationContext) {
  
  
  
  1.1      date: 2007/03/20 21:33:02;  author: myoungstrom;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SpringELResolver.java
  
  Index: SpringELResolver.java
  ===================================================================
  package org.jboss.seam.ioc.spring;
  
  import static org.jboss.seam.InterceptionType.NEVER;
  import static org.jboss.seam.annotations.Install.BUILT_IN;
  
  import java.beans.FeatureDescriptor;
  import java.util.Iterator;
  
  import javax.el.CompositeELResolver;
  import javax.el.ELContext;
  import javax.el.ELResolver;
  import javax.servlet.ServletContext;
  
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Create;
  import org.jboss.seam.annotations.Install;
  import org.jboss.seam.annotations.Intercept;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.annotations.Startup;
  import org.jboss.seam.contexts.Lifecycle;
  import org.jboss.seam.log.LogProvider;
  import org.jboss.seam.log.Logging;
  import org.jboss.seam.util.EL;
  import org.springframework.beans.factory.BeanFactory;
  import org.springframework.web.context.support.WebApplicationContextUtils;
  
  /**
   * Resolver patterned after the Spring DelegatingVariableResolver providing el access
   * to Spring beans in non Faces Requests.
   * @author youngstrommj
   *
   */
  @Scope(ScopeType.APPLICATION)
  @Name("org.jboss.seam.ioc.spring.springELResolver")
  @Install(precedence = Install.FRAMEWORK)
  @Startup
  @Intercept(NEVER)
  public class SpringELResolver extends ELResolver
  {
     private static final LogProvider log = Logging.getLogProvider(SpringELResolver.class);
  
     @Create
     public void initialize()
     {
        ELResolver resolver = EL.EL_CONTEXT.getELResolver();
        if (resolver == null || !(resolver instanceof CompositeELResolver))
        {
           throw new IllegalStateException("Could not add Spring ELResolver to Resolver Chain.  "
                    + "Seam resolver was not an instance of CompositeELResolver.");
        }
        ((CompositeELResolver) resolver).add(this);
     }
  
     @Override
     public Class<?> getCommonPropertyType(ELContext context, Object base)
     {
        return null;
     }
  
     @Override
     public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
     {
        return null;
     }
  
     @Override
     public Class<?> getType(ELContext context, Object base, Object property)
     {
        return null;
     }
  
     @Override
     public Object getValue(ELContext context, Object base, Object property)
     {
        if (base != null)
        {
           // We only resolve root variable.
           return null;
        }
        ServletContext servletContext = Lifecycle.getServletContext();
        if (servletContext == null)
        {
           log.debug("Could not locate seam stored servletContext.  Skipping.");
           return null;
        }
        BeanFactory bf = getBeanFactory(servletContext);
        if (bf == null)
        {
           log.debug("No Spring BeanFactory found.  Skipping.");
           return null;
        }
        if (!(property instanceof String))
        {
           log.debug("Property not a string.  Skipping");
           return null;
        }
  
        if (bf.containsBean((String) property))
        {
           if (log.isDebugEnabled())
           {
              log.debug("Successfully resolved property '" + property
                       + "' in root WebApplicationContext");
           }
           context.setPropertyResolved(true);
           return bf.getBean((String) property);
        }
        if (log.isDebugEnabled())
        {
           log.debug("Could not resolve property of name '" + property + "'");
        }
        return null;
  
     }
  
     @Override
     public boolean isReadOnly(ELContext context, Object base, Object property)
     {
        return true;
     }
  
     @Override
     public void setValue(ELContext context, Object base, Object property, Object value)
     {
     }
  
     /**
      * Obtain the BeanFactory using
      * WebApplicationContextxUtils.getWebApplicationContext
      */
     protected BeanFactory getBeanFactory(ServletContext servletContext)
     {
        return WebApplicationContextUtils.getWebApplicationContext(servletContext);
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list