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

Michael Youngstrom youngm at gmail.com
Sat Mar 10 17:05:47 EST 2007


  User: myoungstrom
  Date: 07/03/10 17:05:47

  Added:       src/ioc/org/jboss/seam/ioc/spring   ContextLoader.java
                        package-info.java
  Log:
  Some initial work on JBSEAM-995
  
  Revision  Changes    Path
  1.1      date: 2007/03/10 22:05:47;  author: myoungstrom;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/spring/ContextLoader.java
  
  Index: ContextLoader.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.lang.reflect.Proxy;
  
  import javax.servlet.ServletContext;
  
  import org.jboss.kernel.plugins.bootstrap.standalone.StandaloneBootstrap;
  import static org.springframework.web.context.ContextLoader.*;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Create;
  import org.jboss.seam.annotations.Destroy;
  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.springframework.context.ApplicationContext;
  import org.springframework.web.context.ConfigurableWebApplicationContext;
  import org.springframework.web.context.WebApplicationContext;
  import org.springframework.web.context.support.XmlWebApplicationContext;
  
  /**
   * A seam component that acts as an adaptor for Spring's ContextLoader
   * 
   * @author Gavin King
   */
  @Scope(ScopeType.APPLICATION)
  @Intercept(NEVER)
  @Startup
  @Name("org.jboss.seam.ioc.spring.contextLoader")
  @Install(value = false, precedence = BUILT_IN)
  public class ContextLoader
  {
     private WebApplicationContext webApplicationContext;
     private String[] configLocations;
     
     @Create 
     public void create() throws Exception
     {
        ServletContext servletContext = Lifecycle.getServletContext();
        try {
           webApplicationContext = createContextLoader(servletContext);
           servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
        } catch (Exception e) {
           servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, e);
           throw e;
        }
     }
     
     protected WebApplicationContext createContextLoader(ServletContext servletContext) {
        XmlWebApplicationContext xmlWebApplicationContext = new XmlWebApplicationContext();
        xmlWebApplicationContext.setServletContext(servletContext);
        xmlWebApplicationContext.setConfigLocations(getConfigLocations());
        xmlWebApplicationContext.refresh();
        return xmlWebApplicationContext;
     }
  
     @Destroy
     public void destroy() {
        if(webApplicationContext != null && webApplicationContext instanceof ConfigurableWebApplicationContext) {
           ((ConfigurableWebApplicationContext)webApplicationContext).close();
        }
     }
     
     public String[] getConfigLocations()
     {
        return configLocations;
     }
     
     public void setConfigLocations(String[] configLocations)
     {
        this.configLocations = configLocations;
     }
  }
  
  
  
  1.1      date: 2007/03/10 22:05:47;  author: myoungstrom;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/spring/package-info.java
  
  Index: package-info.java
  ===================================================================
  @Namespace(value="http://jboss.com/products/seam/spring", prefix="org.jboss.seam.ioc.spring")
  package org.jboss.seam.ioc.spring;
  
  import org.jboss.seam.annotations.*;
  
  
  



More information about the jboss-cvs-commits mailing list