cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl DefaultEventManager.java
Date Fri, 23 May 2003 09:18:48 GMT
cziegeler    2003/05/23 02:18:48

  Modified:    .        status.xml
               src/java/org/apache/cocoon Cocoon.java Constants.java
               src/blocks/portal/java/org/apache/cocoon/portal/event/impl
                        DefaultEventManager.java
  Added:       src/java/org/apache/cocoon/components ContextHelper.java
                        ComponentContext.java
  Log:
  Make the object model (and friends) accessible using the context of a component
  
  Revision  Changes    Path
  1.43      +4 -0      cocoon-2.1/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/status.xml,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- status.xml	22 May 2003 21:26:26 -0000	1.42
  +++ status.xml	23 May 2003 09:18:47 -0000	1.43
  @@ -180,6 +180,10 @@
     <changes>
   
    <release version="@version@" date="@date@">
  +  <action dev="CZ" type="add">
  +    The object model and the components stored in the object model are now available
  +    via the component context.
  +  </action>
     <action dev="VG" type="fix" fixes-bug="20159" due-to="Hugh Leather" due-to-email="hughleat@hotmail.com">
      Logicsheets:
      Changed scope of and renamed temporary 'soap:call' XScript variable in &lt;soap:call&gt;.
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/components/ContextHelper.java
  
  Index: ContextHelper.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 Cocoon" and  "Apache Software Foundation" 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", 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.CascadingRuntimeException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.Response;
  
  /**
   * A set of constants and methods to access the content of the context
   * object. Some of the constants are defined in {@link Constants}.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: ContextHelper.java,v 1.1 2003/05/23 09:18:48 cziegeler Exp $
   */
  
  public final class ContextHelper {
  
      /** Application <code>Context</code> Key for the current object model */
      public static final String CONTEXT_OBJECT_MODEL = "object-model";
  
      /** Application <code>Context</code> Key for the current request object
*/
      public static final String CONTEXT_REQUEST_OBJECT = CONTEXT_OBJECT_MODEL + '/' + ObjectModelHelper.REQUEST_OBJECT;
  
      /** Application <code>Context</code> Key for the current response object
*/
      public static final String CONTEXT_RESPONSE_OBJECT = CONTEXT_OBJECT_MODEL + '/' + ObjectModelHelper.RESPONSE_OBJECT;
  
      private ContextHelper() {
          // Forbid instantiation
      }
  
      public static final Request getRequest(Context context) {
          // the request object is always present
          try {
              return (Request)context.get(CONTEXT_REQUEST_OBJECT);
          } catch (ContextException ce) {
              throw new CascadingRuntimeException("Unable to get the request object from the
context.", ce);
          }
      }
  
      public static final Response getResponse(Context context) {
          // the response object is always present
          try {
              return (Response)context.get(CONTEXT_RESPONSE_OBJECT);
          } catch (ContextException ce) {
              throw new CascadingRuntimeException("Unable to get the response object from
the context.", ce);
          }
      }
  
      public static final Map getObjectModel(Context context) {
          // the object model is always present
          try {
              return (Map)context.get(CONTEXT_OBJECT_MODEL);
          } catch (ContextException ce) {
              throw new CascadingRuntimeException("Unable to get the object model from the
context.", ce);
          }
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/components/ComponentContext.java
  
  Index: ComponentContext.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 Cocoon" and  "Apache Software Foundation" 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", 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.DefaultContext;
  
  /**
   * This is the {@link Context} implementation for Cocoon components.
   * It extends the {@link DefaultContext} by a special handling for
   * getting objects from the object model.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: ComponentContext.java,v 1.1 2003/05/23 09:18:48 cziegeler Exp $
   */
  
  public class ComponentContext 
      extends DefaultContext {
  
      protected static final String OBJECT_MODEL_KEY_PREFIX = ContextHelper.CONTEXT_OBJECT_MODEL
+ '/';
      
      /**
       * Create a Context with specified data and parent.
       *
       * @param contextData the context data
       * @param parent the parent Context (may be null)
       */
      public ComponentContext(final Map contextData, final Context parent) {
          super( contextData, parent );
      }
  
      /**
       * Create a Context with specified data.
       *
       * @param contextData the context data
       */
      public ComponentContext(final Map contextData) {
          super( contextData );
      }
  
      /**
       * Create a Context with specified parent.
       *
       * @param parent the parent Context (may be null)
       */
      public ComponentContext(final Context parent) {
          super( parent );
      }
  
      /**
       * Create a Context with no parent.
       *
       */
      public ComponentContext() {
          super();
      }
  
      /**
       * Retrieve an item from the Context.
       *
       * @param key the key of item
       * @return the item stored in context
       * @throws ContextException if item not present
       */
      public Object get( final Object key )
      throws ContextException {
          if ( key.equals(ContextHelper.CONTEXT_OBJECT_MODEL)) {
              return CocoonComponentManager.getCurrentEnvironment().getObjectModel();
          }
          if ( key instanceof String ) {
              String stringKey = (String)key;
              if ( stringKey.startsWith(OBJECT_MODEL_KEY_PREFIX) ) {
                  final Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel();
                  String objectKey = stringKey.substring(OBJECT_MODEL_KEY_PREFIX.length());
                  
                  Object o = objectModel.get( objectKey );
                  if ( o == null ) {
                      final String message = "Unable to locate " + key;
                      throw new ContextException( message );
                  }
                  return o;
              }
          }
          return super.get( key );
      }
  
  }
  
  
  
  1.7       +15 -16    cocoon-2.1/src/java/org/apache/cocoon/Cocoon.java
  
  Index: Cocoon.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/Cocoon.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Cocoon.java	16 May 2003 07:04:56 -0000	1.6
  +++ Cocoon.java	23 May 2003 09:18:48 -0000	1.7
  @@ -50,6 +50,15 @@
   */
   package org.apache.cocoon;
   
  +import java.io.BufferedInputStream;
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.net.URL;
  +import java.util.Collections;
  +import java.util.Enumeration;
  +import java.util.Map;
  +
   import org.apache.avalon.excalibur.component.DefaultRoleManager;
   import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
   import org.apache.avalon.excalibur.logger.LogKitManageable;
  @@ -71,6 +80,7 @@
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.components.CocoonComponentManager;
  +import org.apache.cocoon.components.ComponentContext;
   import org.apache.cocoon.components.EnvironmentStack;
   import org.apache.cocoon.components.language.generator.CompiledComponent;
   import org.apache.cocoon.components.language.generator.ProgramGenerator;
  @@ -94,15 +104,6 @@
   import org.apache.excalibur.xml.sax.SAXParser;
   import org.xml.sax.InputSource;
   
  -import java.io.BufferedInputStream;
  -import java.io.File;
  -import java.io.IOException;
  -import java.io.InputStream;
  -import java.net.URL;
  -import java.util.Collections;
  -import java.util.Enumeration;
  -import java.util.Map;
  -
   /**
    * The Cocoon Object is the main Kernel for the entire Cocoon system.
    *
  @@ -190,10 +191,9 @@
        */
       public void contextualize(Context context) throws ContextException {
           if (this.context == null) {
  -            this.context = new DefaultContext(context);
  +            this.context = new ComponentContext(context);
               
  -            try
  -            {
  +            try {
                   DefaultContext setup = (DefaultContext)this.context;
                   threads = new TPCThreadManager();
                   CommandManager commands = new CommandManager();
  @@ -214,9 +214,7 @@
                   setup.put(Queue.ROLE, commands.getCommandSink());
                   
                   setup.makeReadOnly();
  -            }
  -            catch (Exception e)
  -            {
  +            } catch (Exception e) {
                   getLogger().error("Could not set up the Command Manager", e);
               }
               
  @@ -761,3 +759,4 @@
           return activeRequestCount;
       }
   }
  +
  
  
  
  1.4       +3 -3      cocoon-2.1/src/java/org/apache/cocoon/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/Constants.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Constants.java	18 Mar 2003 15:23:30 -0000	1.3
  +++ Constants.java	23 May 2003 09:18:48 -0000	1.4
  @@ -323,8 +323,8 @@
       /** Application <code>Context</code> Key for the upload directory path
*/
       public static final String CONTEXT_UPLOAD_DIR = "upload-directory";
   
  -    public static final /** Application <code>Context</code> Key for the cache
directory path */
  -    String CONTEXT_CACHE_DIR = "cache-directory";
  +    /** Application <code>Context</code> Key for the cache directory path */
  +    public static final String CONTEXT_CACHE_DIR = "cache-directory";
   
       /** Application <code>Context</code> Key for the current classpath */
       public static final String CONTEXT_CLASSPATH = "classpath";
  
  
  
  1.5       +22 -3     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java
  
  Index: DefaultEventManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultEventManager.java	22 May 2003 15:19:43 -0000	1.4
  +++ DefaultEventManager.java	23 May 2003 09:18:48 -0000	1.5
  @@ -53,6 +53,7 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
   
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
  @@ -63,10 +64,13 @@
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.components.CocoonComponentManager;
  +import org.apache.cocoon.components.ContextHelper;
   import org.apache.cocoon.portal.PortalService;
   import org.apache.cocoon.portal.event.Event;
   import org.apache.cocoon.portal.event.EventConverter;
  @@ -94,6 +98,7 @@
                   ThreadSafe,
                   Configurable,
                   Disposable,
  +                Contextualizable,
                   Publisher, Register {
                       
       private final String rootEventType = Event.class.getName();
  @@ -106,6 +111,8 @@
       
       protected ComponentSelector aspectSelector;
   
  +    protected Context context;
  +    
       public Publisher getPublisher() {
           return this;
       }
  @@ -113,6 +120,10 @@
       public Register getRegister() {
           return this;
       }
  +    
  +    protected Map getObjectModel() {
  +        return ContextHelper.getObjectModel( this.context );
  +    }
   
       /* (non-Javadoc)
        * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
  @@ -240,7 +251,7 @@
               
               // Invoke aspects
               context.setEventPublisher( publisher );
  -            context.setObjectModel(CocoonComponentManager.getCurrentEnvironment().getObjectModel());
  +            context.setObjectModel(this.getObjectModel());
               context.setEventConverter(converter);
               context.invokeNext( service );
   
  @@ -253,6 +264,14 @@
               this.manager.release(service);
           }
   
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
  +     */
  +    public void contextualize(Context context) 
  +    throws ContextException {
  +        this.context = context;
       }
   
   }
  
  
  

Mime
View raw message