cziegeler    2004/01/05 04:41:49

  Modified:    src/java/org/apache/cocoon/components/source/impl
                        SitemapSource.java
               src/java/org/apache/cocoon/environment
                        EnvironmentContext.java EnvironmentHelper.java
               src/java/org/apache/cocoon/components
                        RequestLifecycleHelper.java ComponentContext.java
  Removed:     src/java/org/apache/cocoon/components EnvironmentStack.java
  Log:
  Further polishing of the env handling
  
  Revision  Changes    Path
  1.19      +2 -2      
cocoon-2.2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
  
  Index: SitemapSource.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SitemapSource.java        5 Jan 2004 08:16:00 -0000       1.18
  +++ SitemapSource.java        5 Jan 2004 12:41:48 -0000       1.19
  @@ -155,7 +155,7 @@
                            Logger         logger)
       throws MalformedURLException {
   
  -        Environment env = 
EnvironmentHelper.getCurrentContext().getEnvironment();
  +        Environment env = 
EnvironmentHelper.getCurrentEnvironmentContext().getEnvironment();
           if ( env == null ) {
               throw new MalformedURLException("The cocoon protocol can not be 
used outside an environment.");
           }
  
  
  
  1.2       +38 -4     
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentContext.java
  
  Index: EnvironmentContext.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EnvironmentContext.java   29 Oct 2003 18:58:06 -0000      1.1
  +++ EnvironmentContext.java   5 Jan 2004 12:41:48 -0000       1.2
  @@ -59,6 +59,13 @@
   
   /**
    * Experimental code for cleaning up the environment handling
  + * The environment context can store any additional objects for an 
environment.
  + * This is an alternative to using the attributes of an environment and
  + * can be used to store internal objects/information wihtout exposing
  + * it to clients of the environment object.
  + * Each object added to the environment context is disposed when the
  + * processing of the environment is finished. If you don't want to
  + * dispose an object, use a key that starts with "global:"!
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @version CVS $Id$
  @@ -67,34 +74,61 @@
   public class EnvironmentContext 
   implements Disposable {
       
  +    /** The corresponding environment */
       protected Environment environment;
       
  +    /** The attributes */
       protected Map attributes;
       
  +    /**
  +     * Constructor
  +     */
       public EnvironmentContext(Environment environment) {
           this.attributes = new HashMap();
           this.environment = environment;
       }
       
  +    /**
  +     * Return the corresponding environment
  +     * @return The environment
  +     */
       public Environment getEnvironment() {
           return this.environment;
       }
       
  +    /**
  +     * Add an object to the environment.
  +     * If an object with the same key is already stored, this is overwritten.
  +     * Each object is disposed when the environment is finished. However,
  +     * if you add an object with a key that starts with "global:", then
  +     * the object is not disposed!
  +     * 
  +     * @param key   The key for the object
  +     * @param value The object itself
  +     */
       public void addAttribute(String key, Object value) {
           this.attributes.put(key, value);
       }
       
  +    /**
  +     * Return the object associated with the key
  +     * @param key The unique key
  +     * @return The object or null
  +     */
       public Object getAttribute(String key) {
           return this.attributes.get(key);
       }
  +    
       /* (non-Javadoc)
        * @see org.apache.avalon.framework.activity.Disposable#dispose()
        */
       public void dispose() {
  -        final Iterator iter = this.attributes.values().iterator();
  +        final Iterator iter = this.attributes.entrySet().iterator();
           while ( iter.hasNext() ) {
  -            final Object o = iter.next();
  -            ContainerUtil.dispose(o);
  +            Map.Entry entry = (Map.Entry)iter.next();
  +            if ( !((String) entry.getKey()).startsWith("global:") ) {
  +                ContainerUtil.dispose(entry.getValue());
  +            }
           }
           this.attributes.clear();
       }
  
  
  
  1.15      +12 -8     
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java
  
  Index: EnvironmentHelper.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- EnvironmentHelper.java    5 Jan 2004 11:28:24 -0000       1.14
  +++ EnvironmentHelper.java    5 Jan 2004 12:41:48 -0000       1.15
  @@ -79,10 +79,15 @@
   
       /** The key used to store the current environment context
        * in the object model */
  -    static final String PROCESS_KEY = EnvironmentHelper.class.getName();
  +    static protected final String PROCESS_KEY = 
EnvironmentHelper.class.getName();
   
  +    /** The key used to store the last processor information
  +     * in the environment context
  +     */
  +    static protected final String LAST_PROCESSOR_KEY = "global:" + 
PROCESS_KEY + "/processor";
  +    
       /** The environment information */
  -    static protected InheritableThreadLocal environmentStack = new 
CloningInheritableThreadLocal();
  +    static protected final InheritableThreadLocal environmentStack = new 
CloningInheritableThreadLocal();
       
       /** The real source resolver */
       protected org.apache.excalibur.source.SourceResolver resolver;
  @@ -388,8 +393,7 @@
           }
           stack.pushInfo(new EnvironmentInfo(processor, stack.getOffset(), 
manager, env));
           stack.setOffset(stack.size()-1);
  -        // FIXME - Put it somewhere else
  -        env.setAttribute("EnvironmentHelper.processor", processor);
  +        
((EnvironmentContext)env.getObjectModel().get(PROCESS_KEY)).addAttribute(LAST_PROCESSOR_KEY,
 processor);
       }
   
       /**
  @@ -436,7 +440,7 @@
       /**
        * Return the environment context
        */
  -    public static EnvironmentContext getCurrentContext() {
  +    public static EnvironmentContext getCurrentEnvironmentContext() {
           final EnvironmentStack stack = 
(EnvironmentStack)environmentStack.get();
           final EnvironmentInfo info = stack.getCurrentInfo();
           final Map objectModel = info.environment.getObjectModel();
  @@ -488,8 +492,8 @@
        * Return the processor that is actually processing the request
        */
       public static Processor getLastProcessor(Environment env) {
  -        // FIXME - Put it somewhere else
  -        return (Processor)env.getAttribute("EnvironmentHelper.processor");
  +        EnvironmentContext context = (EnvironmentContext) 
env.getObjectModel().get(PROCESS_KEY);
  +        return (Processor)env.getAttribute(LAST_PROCESSOR_KEY);
       }
   
       /**
  
  
  
  1.7       +1 -1      
cocoon-2.2/src/java/org/apache/cocoon/components/RequestLifecycleHelper.java
  
  Index: RequestLifecycleHelper.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/RequestLifecycleHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RequestLifecycleHelper.java       5 Nov 2003 21:29:08 -0000       1.6
  +++ RequestLifecycleHelper.java       5 Jan 2004 12:41:48 -0000       1.7
  @@ -78,7 +78,7 @@
   
       static EnvironmentDescription getEnvironmentDescription() {
           final EnvironmentContext context =
  -            EnvironmentHelper.getCurrentContext();
  +            EnvironmentHelper.getCurrentEnvironmentContext();
           EnvironmentDescription desc =
               (EnvironmentDescription) context.getAttribute(KEY);
           if (desc == null) {
  
  
  
  1.7       +3 -3      
cocoon-2.2/src/java/org/apache/cocoon/components/ComponentContext.java
  
  Index: ComponentContext.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/ComponentContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ComponentContext.java     29 Oct 2003 18:58:05 -0000      1.6
  +++ ComponentContext.java     5 Jan 2004 12:41:48 -0000       1.7
  @@ -117,12 +117,12 @@
       public Object get( final Object key )
       throws ContextException {
           if ( key.equals(ContextHelper.CONTEXT_OBJECT_MODEL)) {
  -            return 
EnvironmentHelper.getCurrentContext().getEnvironment().getObjectModel();
  +            return 
EnvironmentHelper.getCurrentEnvironmentContext().getEnvironment().getObjectModel();
           }
           if ( key instanceof String ) {
               String stringKey = (String)key;
               if ( stringKey.startsWith(OBJECT_MODEL_KEY_PREFIX) ) {
  -                final Map objectModel = 
EnvironmentHelper.getCurrentContext().getEnvironment().getObjectModel();
  +                final Map objectModel = 
EnvironmentHelper.getCurrentEnvironmentContext().getEnvironment().getObjectModel();
                   String objectKey = 
stringKey.substring(OBJECT_MODEL_KEY_PREFIX.length());
   
                   Object o = objectModel.get( objectKey );
  
  
  

Reply via email to