[jboss-cvs] jboss-seam/src/main/org/jboss/seam/servlet ...

Gavin King gavin.king at jboss.com
Sun Jun 10 15:25:59 EDT 2007


  User: gavin   
  Date: 07/06/10 15:25:59

  Modified:    src/main/org/jboss/seam/servlet         ResourceServlet.java
                        SeamListener.java
  Added:       src/main/org/jboss/seam/servlet        
                        ServletApplicationMap.java ServletRequestMap.java
                        ServletRequestSessionMap.java
                        ServletSessionMap.java
  Removed:     src/main/org/jboss/seam/servlet        
                        ServletRequestImpl.java ServletSessionImpl.java
  Log:
  major refactor of contexts impl
  JBSEAM-953
  
  Revision  Changes    Path
  1.9       +3 -2      jboss-seam/src/main/org/jboss/seam/servlet/ResourceServlet.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ResourceServlet.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/servlet/ResourceServlet.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- ResourceServlet.java	9 Mar 2007 07:05:12 -0000	1.8
  +++ ResourceServlet.java	10 Jun 2007 19:25:59 -0000	1.9
  @@ -11,8 +11,9 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   
  +import org.jboss.seam.ScopeType;
  +import org.jboss.seam.contexts.BasicContext;
   import org.jboss.seam.contexts.Context;
  -import org.jboss.seam.contexts.WebApplicationContext;
   import org.jboss.seam.core.Init;
   
   /**
  @@ -36,7 +37,7 @@
   
      protected void loadResourceProviders()
      {
  -      Context tempApplicationContext = new WebApplicationContext(context);
  +      Context tempApplicationContext = new BasicContext(ScopeType.APPLICATION, new ServletApplicationMap(context));
   
         Init init = (Init) tempApplicationContext.get(Init.class);
         for (String name : init.getResourceProviders())
  
  
  
  1.30      +20 -8     jboss-seam/src/main/org/jboss/seam/servlet/SeamListener.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamListener.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/servlet/SeamListener.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -b -r1.29 -r1.30
  --- SeamListener.java	8 May 2007 01:34:31 -0000	1.29
  +++ SeamListener.java	10 Jun 2007 19:25:59 -0000	1.30
  @@ -5,15 +5,18 @@
    * See terms of license at gnu.org.
    */
   package org.jboss.seam.servlet;
  +
   import javax.servlet.ServletContextEvent;
   import javax.servlet.ServletContextListener;
   import javax.servlet.http.HttpSessionEvent;
   import javax.servlet.http.HttpSessionListener;
  +
   import org.jboss.seam.Seam;
  -import org.jboss.seam.log.LogProvider;
  -import org.jboss.seam.log.Logging;
   import org.jboss.seam.contexts.Lifecycle;
   import org.jboss.seam.init.Initialization;
  +import org.jboss.seam.log.LogProvider;
  +import org.jboss.seam.log.Logging;
  +
   /**
    * Drives certain Seam functionality such as initialization and cleanup
    * of application and session contexts from the web application lifecycle.
  @@ -23,18 +26,27 @@
   public class SeamListener implements ServletContextListener, HttpSessionListener
   {
      private static final LogProvider log = Logging.getLogProvider(ServletContextListener.class);
  -   public void contextInitialized(ServletContextEvent event) {
  +   
  +   public void contextInitialized(ServletContextEvent event) 
  +   {
         log.info("Welcome to Seam " + Seam.getVersion());
         Lifecycle.setServletContext( event.getServletContext() );
         new Initialization( event.getServletContext() ).create().init();
      }
  -   public void contextDestroyed(ServletContextEvent event) {
  +   
  +   public void contextDestroyed(ServletContextEvent event) 
  +   {
         Lifecycle.endApplication( event.getServletContext() );
      }
  -   public void sessionCreated(HttpSessionEvent event) {
  -      Lifecycle.beginSession( event.getSession().getServletContext(), new ServletSessionImpl( event.getSession() ) );
  +   
  +   public void sessionCreated(HttpSessionEvent event) 
  +   {
  +      Lifecycle.beginSession( event.getSession().getServletContext(), new ServletSessionMap( event.getSession() ) );
      }
  -   public void sessionDestroyed(HttpSessionEvent event) {
  -      Lifecycle.endSession( event.getSession().getServletContext(), new ServletSessionImpl( event.getSession() ) );
  +   
  +   public void sessionDestroyed(HttpSessionEvent event) 
  +   {
  +      Lifecycle.endSession( event.getSession().getServletContext(), new ServletSessionMap( event.getSession() ) );
      }
  +   
   }
  
  
  
  1.1      date: 2007/06/10 19:25:59;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/servlet/ServletApplicationMap.java
  
  Index: ServletApplicationMap.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.servlet;
  
  import java.util.Collection;
  import java.util.Enumeration;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  
  import javax.servlet.ServletContext;
  
  /**
   * @author Gavin King
   */
  public class ServletApplicationMap implements Map<String, Object>
  {
     private ServletContext servletContext;
  
     public ServletApplicationMap(ServletContext servletContext)
     {
        this.servletContext = servletContext;
     }
  
     public void clear()
     {
        throw new UnsupportedOperationException(); 
     }
  
     public boolean containsKey(Object key)
     {
        return servletContext.getAttribute( (String) key )!=null;
     }
  
     public boolean containsValue(Object value)
     {
        throw new UnsupportedOperationException();
     }
  
     public Set<java.util.Map.Entry<String, Object>> entrySet()
     {
        throw new UnsupportedOperationException();
     }
  
     public Object get(Object key)
     {
        return servletContext.getAttribute( (String) key );
     }
  
     public boolean isEmpty()
     {
        throw new UnsupportedOperationException();
     }
  
     public Set<String> keySet()
     {
        Set<String> keys = new HashSet<String>();
        Enumeration<String> names = servletContext.getAttributeNames();
        while ( names.hasMoreElements() )
        {
           keys.add( names.nextElement() );
        }
        return keys;
     }
  
     public Object put(String key, Object value)
     {
        Object result = servletContext.getAttribute(key);
        servletContext.setAttribute(key, value);
        return result;
     }
  
     public void putAll(Map<? extends String, ? extends Object> t)
     {
        throw new UnsupportedOperationException();
     }
  
     public Object remove(Object key)
     {
        Object result = servletContext.getAttribute( (String) key );
        servletContext.removeAttribute( (String) key );
        return result;
     }
  
     public int size()
     {
        throw new UnsupportedOperationException();
     }
  
     public Collection<Object> values()
     {
        throw new UnsupportedOperationException();
     }
  
  }
  
  
  
  1.1      date: 2007/06/10 19:25:59;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/servlet/ServletRequestMap.java
  
  Index: ServletRequestMap.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.servlet;
  
  import java.util.Collection;
  import java.util.Enumeration;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  
  import javax.servlet.ServletRequest;
  
  /**
   * @author Gavin King
   */
  public class ServletRequestMap implements Map<String, Object>
  {
     
     private ServletRequest request;
  
     public ServletRequestMap(ServletRequest request)
     {
        this.request = request;
     }
  
     public void clear()
     {
        throw new UnsupportedOperationException(); 
     }
  
     public boolean containsKey(Object key)
     {
        return request.getAttribute( (String) key )!=null;
     }
  
     public boolean containsValue(Object value)
     {
        throw new UnsupportedOperationException();
     }
  
     public Set<java.util.Map.Entry<String, Object>> entrySet()
     {
        throw new UnsupportedOperationException();
     }
  
     public Object get(Object key)
     {
        return request.getAttribute( (String) key );
     }
  
     public boolean isEmpty()
     {
        throw new UnsupportedOperationException();
     }
  
     public Set<String> keySet()
     {
        Set<String> keys = new HashSet<String>();
        Enumeration<String> names = request.getAttributeNames();
        while ( names.hasMoreElements() )
        {
           keys.add( names.nextElement() );
        }
        return keys;
     }
  
     public Object put(String key, Object value)
     {
        Object result = request.getAttribute(key);
        request.setAttribute(key, value);
        return result;
     }
  
     public void putAll(Map<? extends String, ? extends Object> t)
     {
        throw new UnsupportedOperationException();
     }
  
     public Object remove(Object key)
     {
        Object result = request.getAttribute( (String) key );
        request.removeAttribute( (String) key );
        return result;
     }
  
     public int size()
     {
        throw new UnsupportedOperationException();
     }
  
     public Collection<Object> values()
     {
        throw new UnsupportedOperationException();
     }
  
  }
  
  
  
  1.1      date: 2007/06/10 19:25:59;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/servlet/ServletRequestSessionMap.java
  
  Index: ServletRequestSessionMap.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.servlet;
  
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Enumeration;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  
  /**
   * @author Gavin King
   */
  public class ServletRequestSessionMap implements Map<String, Object>
  {
     private HttpServletRequest request;
  
     public ServletRequestSessionMap(HttpServletRequest request)
     {
        this.request = request;
     }
  
     public void clear()
     {
        throw new UnsupportedOperationException(); 
     }
  
     public boolean containsKey(Object key)
     {
        HttpSession session = request.getSession(false);
        return session==null ? false : session.getAttribute( (String) key )!=null;
     }
  
     public boolean containsValue(Object value)
     {
        throw new UnsupportedOperationException();
     }
  
     public Set<java.util.Map.Entry<String, Object>> entrySet()
     {
        throw new UnsupportedOperationException();
     }
  
     public Object get(Object key)
     {
        HttpSession session = request.getSession(false);
        return session==null ? null : session.getAttribute( (String) key );
     }
  
     public boolean isEmpty()
     {
        throw new UnsupportedOperationException();
     }
  
     public Set<String> keySet()
     {
        HttpSession session = request.getSession(false);
        if (session==null)
        {
           return Collections.EMPTY_SET;
        }
        else
        {
           Set<String> keys = new HashSet<String>();
           Enumeration<String> names = session.getAttributeNames();
           while ( names.hasMoreElements() )
           {
              keys.add( names.nextElement() );
           }
           return keys;
        }
     }
  
     public Object put(String key, Object value)
     {
        HttpSession session = request.getSession(true);
        Object result = session.getAttribute(key);
        session.setAttribute(key, value);
        return result;
     }
  
     public void putAll(Map<? extends String, ? extends Object> t)
     {
        throw new UnsupportedOperationException();
     }
  
     public Object remove(Object key)
     {
        HttpSession session = request.getSession(false);
        if (session==null)
        {
           return null;
        }
        else
        {
           Object result = session.getAttribute( (String) key );
           session.removeAttribute( (String) key );
           return result;
        }
     }
  
     public int size()
     {
        throw new UnsupportedOperationException();
     }
  
     public Collection<Object> values()
     {
        throw new UnsupportedOperationException();
     }
  
  }
  
  
  
  1.1      date: 2007/06/10 19:25:59;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/servlet/ServletSessionMap.java
  
  Index: ServletSessionMap.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.servlet;
  
  import java.util.Collection;
  import java.util.Enumeration;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  
  import javax.servlet.http.HttpSession;
  
  /**
   * @author Gavin King
   */
  public class ServletSessionMap implements Map<String, Object>
  {
     private HttpSession session;
  
     public ServletSessionMap(HttpSession session)
     {
        this.session = session;
     }
  
     public void clear()
     {
        throw new UnsupportedOperationException(); 
     }
  
     public boolean containsKey(Object key)
     {
        return session.getAttribute( (String) key )!=null;
     }
  
     public boolean containsValue(Object value)
     {
        throw new UnsupportedOperationException();
     }
  
     public Set<java.util.Map.Entry<String, Object>> entrySet()
     {
        throw new UnsupportedOperationException();
     }
  
     public Object get(Object key)
     {
        return session.getAttribute( (String) key );
     }
  
     public boolean isEmpty()
     {
        throw new UnsupportedOperationException();
     }
  
     public Set<String> keySet()
     {
        Set<String> keys = new HashSet<String>();
        Enumeration<String> names = session.getAttributeNames();
        while ( names.hasMoreElements() )
        {
           keys.add( names.nextElement() );
        }
        return keys;
     }
  
     public Object put(String key, Object value)
     {
        Object result = session.getAttribute(key);
        session.setAttribute(key, value);
        return result;
     }
  
     public void putAll(Map<? extends String, ? extends Object> t)
     {
        throw new UnsupportedOperationException();
     }
  
     public Object remove(Object key)
     {
        Object result = session.getAttribute( (String) key );
        session.removeAttribute( (String) key );
        return result;
     }
  
     public int size()
     {
        throw new UnsupportedOperationException();
     }
  
     public Collection<Object> values()
     {
        throw new UnsupportedOperationException();
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list