portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggol...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager JetspeedStateManagerService.java SessionState.java StateManagerService.java
Date Fri, 03 May 2002 15:04:39 GMT
ggolden     02/05/03 08:04:39

  Added:       src/java/org/apache/jetspeed/services/statemanager
                        JetspeedStateManagerService.java SessionState.java
                        StateManagerService.java
  Log:
  First checkin of the StateManagerService.
  See the proposals/StateManager.txt for details.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/JetspeedStateManagerService.java
  
  Index: JetspeedStateManagerService.java
  ===================================================================
  /**********************************************************************************
  *
  * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/JetspeedStateManagerService.java,v
1.1 2002/05/03 15:04:38 ggolden Exp $
  *
  * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  // package
  package org.apache.jetspeed.services.statemanager;
  
  // imports
  import java.util.Iterator;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Set;
  import javax.servlet.ServletConfig;
  
  import org.apache.jetspeed.services.statemanager.StateManagerService;
  import org.apache.turbine.services.TurbineBaseService;
  import org.apache.turbine.services.InitializationException;
  import org.apache.turbine.util.RunData;
  
  /**
  * <p>JetspeedStateManagerService is a Turbine Service implementation of the
  * StateManagerService.</p>
  * <p>SessionState is stored in a HashMap, keyed by state key.  In the HashMap, each
  * SessionState has another HashMap, storing the names and values of the state info. </p>
  * <p>See the proposal: jakarta-jetspeed/proposals/StateManager.txt for more details.</p>
  * @version $Revision: 1.1 $
  * @see org.apache.jetspeed.services.statemanager.StateManagerService
  * @see org.apache.jetspeed.services.statemanager.SessionState
  * @author <a href="mailto:ggolden@apache.org">Glenn R. Golden</a>
  * @todo attach to the HTTP session somehow to auto-retire when the session expires
  */
  public class JetspeedStateManagerService
      extends TurbineBaseService
      implements StateManagerService
  {
      /** Store each set of state parameters by state key
          (each is a HashMap keyed by parameter name) */
      private HashMap m_states = null;
  
      /**
      * Performs early initialization.
      *
      * @param config A ServletConfing to use for initialization
      * activities.
      * @exception InitializationException, if initialization of this
      * class was not successful.
      */
      public void init( ServletConfig config )
          throws InitializationException
      {
          super.init(config);
  
      }   // init
  
      /**
      * Performs early initialization.
      *
      * @param data An RunData to use for initialization activities.
      * @exception InitializationException, if initialization of this
      * class was not successful.
      */
      public void init( RunData data )
          throws InitializationException
      {
          super.init(data);
  
      }   // init
  
      /**
      * Performs late initialization.
      *
      * If your class relies on early initialization, and the object it
      * expects was not received, you can use late initialization to
      * throw an exception and complain.
      *
      * @exception InitializationException, if initialization of this
      * class was not successful.
      */
      public void init()
          throws InitializationException
      {
          super.init();
          m_states = new HashMap();
  
      }   // init
  
      /**
      * Returns to uninitialized state.
      *
      * You can use this method to release resources thet your Service
      * allocated when Turbine shuts down.
      */
      public void shutdown()
      {
          m_states.clear();
          m_states = null;
  
          super.shutdown();
  
      }   // shutdown
  
      /**
      * Access the named attribute of the keyed state.
      * @param key The state key.
      * @param name The attribute name.
      * @return The named attribute value of the keyed state.
      */
      public Object getAttribute ( String key, String name )
      {
          Map map = (Map) m_states.get(key);
          if (map == null) return null;
          return map.get(name);
  
      }   // getAttribute
  
      /**
      * Set the named state attribute of the keyed state with the provided object.
      * @param key The state key.
      * @param name The attribute name.
      * @param value The new value of the attribute (any object type).
      */
      public void setAttribute( String key, String name, Object value )
      {
          Map map = (Map) m_states.get(key);
          if (map == null)
          {
              map = new HashMap();
              m_states.put(key, map);
          }
          map.put(name, value);
  
      }   // setAttribute
  
      /**
      * Remove the named state attribute of the keyed state, if it exists.
      * @param key The state key.
      * @param name The attribute name.
      */
      public void removeAttribute( String key, String name )
      {
          Map map = (Map) m_states.get(key);
          if (map == null) return;
          map.remove(name);
  
      }   // removeAttribute
  
      /**
      * Remove all state attribute of the keyed state.
      * @param key The state key.
      */
      public void clear( String key )
      {
          Map map = (Map) m_states.get(key);
          if (map != null)
          {
              // remove all attributes
              map.clear();
              
              // and forget about it
              m_states.remove(key);
          }
  
      }   // clear
  
      /**
      * Access an iterator on all names of attributes stored in the keyed state.
      * @param key The state key.
      * @return An iterator on all names of attributes stored in the keyed state.
      */
      public Iterator getAttributeNames( String key )
      {
          Map map = (Map) m_states.get(key);
          if (map == null) return null;
          Set keys = map.keySet();
          return keys.iterator();
  
      }   // getAttributeNames
  
      /**
      * Access an SessionState object with the given key.
      * @param key The SessionState key.
      * @return an SessionState object with the given key.
      */
      public SessionState getSessionState( String key )
      {
          return new MySessionState(key, this);
  
      }   // getSessionState
  
      /**
      * Retire, forget about and clean up all states that start with the given key.
      * @param keyStart The beginning of the key of the states to clean up.
      */
      public synchronized void retireState( String keyStart )
      {
          // get the current state keys into an array
          String keys[] = (String[]) m_states.keySet().toArray(new String[m_states.size()]);
          
          // clear all those that begin with keyStart
          for (int i = 0; i < keys.length; i++)
          {
              if (keys[i].startsWith(keyStart))
              {
                  clear(keys[i]);
              }
          }
  
      }   // retireState
  
      /**
      * An SessionState implementation, as covers to this service, storing the key.
      */
      private class MySessionState
          implements SessionState
      {
          /** The state key. */
          private String m_key = null;
  
          /** The JetspeedStateManagerService object. */
          private JetspeedStateManagerService m_service = null;
  
          /**
          * Construct.
          * @param key The state key.
          * @param service The JetspeedStateManagerService instance.
          */
          public MySessionState( String key,
                                  JetspeedStateManagerService service)
          {
              m_key = key;
              m_service = service;
  
          }   // MySessionState
  
          /**
          * Access the named attribute.
          * @param name The attribute name.
          * @return The named attribute value.
          */
          public Object getAttribute( String name )
          {
              return m_service.getAttribute(m_key, name);
  
          }   // getAttribute
  
          /**
          * Set the named attribute value to the provided object.
          * @param name The attribute name.
          * @param value The value of the attribute (any object type).
          */
          public void setAttribute( String name, Object value )
          {
              m_service.setAttribute(m_key, name, value);
  
          }   // setAttribute
  
          /**
          * Remove the named attribute, if it exists.
          * @param name The attribute name.
          */
          public void removeAttribute( String name )
          {
              m_service.removeAttribute(m_key, name);
  
          }   // removeAttribute
  
          /**
          * Remove all attributes.
          */
          public void clear()
          {
              m_service.clear(m_key);
  
          }   // clear
  
          /**
          * Access an iterator on all names of attributes stored in the SessionState.
          * @return An iterator on all names of attribute stored in the SessionState.
          */
          public Iterator getAttributeNames()
          {
              return m_service.getAttributeNames(m_key);
  
          }   // getAttributeNames
  
          /**
          * Access the full unique StateManager key for the SessionState.
          * @return the full unique StateManager key for the SessionState.
          */
          public String getKey()
          {
              return m_key;
  
          }   // getKey
  
      }   // class MySessionState
  
  }   // JetspeedStateManagerService
  
  /**********************************************************************************
  *
  * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/JetspeedStateManagerService.java,v
1.1 2002/05/03 15:04:38 ggolden Exp $
  *
  **********************************************************************************/
  
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/SessionState.java
  
  Index: SessionState.java
  ===================================================================
  /**********************************************************************************
  *
  * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/SessionState.java,v
1.1 2002/05/03 15:04:38 ggolden Exp $
  *
  * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  // package
  package org.apache.jetspeed.services.statemanager;
  
  // imports
  import java.util.Iterator;
  
  /**
  * <p>SessionState is an interface for objects that provide name - value information
sets
  * with a unique key that can be used in the StateManager service</p>
  * <p>See the proposal: jakarta-jetspeed/proposals/StateManager.txt for more details.</p>
  * @version $Revision: 1.1 $
  * @see org.apache.jetspeed.services.statemanager.StateManagerService
  * @author <a href="mailto:ggolden@apache.org">Glenn R. Golden</a>
  */
  public interface SessionState
  {
      /**
      * Access the named attribute.
      * @param name The attribute name.
      * @return The named attribute value.
      */
      public Object getAttribute( String name );
  
      /**
      * Set the named attribute value to the provided object.
      * @param name The attribute name.
      * @param value The value of the attribute (any object type).
      */
      public void setAttribute( String name, Object value );
  
      /**
      * Remove the named attribute, if it exists.
      * @param name The attribute name.
      */
      public void removeAttribute( String name );
  
      /**
      * Remove all attributes.
      */
      public void clear();
  
      /**
      * Access an iterator on all names of attributes stored in the SessionState.
      * @return An iterator on all names of attribute stored in the SessionState.
      */
      public Iterator getAttributeNames();
  
      /**
      * Access the unique StateManager key for the SessionState.
      * @return the unique StateManager key for the SessionState.
      */
      public String getKey();
  
  }   // interface SessionState
  
  /**********************************************************************************
  *
  * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/SessionState.java,v
1.1 2002/05/03 15:04:38 ggolden Exp $
  *
  **********************************************************************************/
  
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/StateManagerService.java
  
  Index: StateManagerService.java
  ===================================================================
  /**********************************************************************************
  *
  * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/StateManagerService.java,v
1.1 2002/05/03 15:04:38 ggolden Exp $
  *
  * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  // package
  package org.apache.jetspeed.services.statemanager;
  
  // imports
  import java.util.Iterator;
  
  /**
  * <p>The StateManagerService is a service that manages SessionState information.
  * Each SessionState is identified by a unique key in this service.  The SessionState
  * is composed of name - value sets of information, stored under the key by the service.</p>
  * <p>See the proposal: jakarta-jetspeed/proposals/StateManager.txt for more details.</p>
  * @version $Revision: 1.1 $
  * @see org.apache.jetspeed.services.statemanager.SessionState
  * @author <a href="mailto:ggolden@apache.org">Glenn R. Golden</a>
  */
  public interface StateManagerService
  {
      /** The name used to find the service in the service manager. */
      public String SERVICE_NAME = "StateManagerService";
  
      /**
      * Access the named attribute of the keyed state.
      * @param key The state key.
      * @param name The attribute name.
      * @return The named attribute value of the keyed state.
      */
      public Object getAttribute ( String key, String name );
  
      /**
      * Set the named state attribute of the keyed state with the provided object.
      * @param key The state key.
      * @param name The attribute name.
      * @param value The new value of the attribute (any object type).
      */
      public void setAttribute( String key, String name, Object value );
  
      /**
      * Remove the named state attribute of the keyed state, if it exists.
      * @param key The state key.
      * @param name The attribute name.
      */
      public void removeAttribute( String key, String name );
  
      /**
      * Remove all state attribute of the keyed state.
      * @param key The state key.
      */
      public void clear( String key );
  
      /**
      * Access an iterator on all names of attributes stored in the keyed state.
      * @param key The state key.
      * @return An iterator on all names of attributes stored in the keyed state.
      */
      public Iterator getAttributeNames( String key );
  
      /**
      * Access an SessionState object with the given key.
      * @param key The SessionState key.
      * @return an SessionState object with the given key.
      */
      public SessionState getSessionState( String key );
  
      /**
      * Retire, forget about and clean up all states that start with the given key.
      * @param keyStart The beginning of the key of the states to clean up.
      */
      public void retireState( String keyStart );
  
  }   // interface StateManagerService
  
  /**********************************************************************************
  *
  * $Header: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/StateManagerService.java,v
1.1 2002/05/03 15:04:38 ggolden Exp $
  *
  **********************************************************************************/
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message