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/java/org/apache/cocoon/components ContextHelper.java ComponentContext.java
Date Tue, 24 Feb 2004 09:54:56 GMT
cziegeler    2004/02/24 01:54:56

  Modified:    .        status.xml
               src/java/org/apache/cocoon/components ContextHelper.java
                        ComponentContext.java
  Log:
  Making sitemap service manager available through the context
  
  Revision  Changes    Path
  1.247     +4 -1      cocoon-2.1/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/status.xml,v
  retrieving revision 1.246
  retrieving revision 1.247
  diff -u -r1.246 -r1.247
  --- status.xml	23 Feb 2004 15:14:05 -0000	1.246
  +++ status.xml	24 Feb 2004 09:54:56 -0000	1.247
  @@ -197,6 +197,9 @@
   
    <release version="@version@" date="@date@">
      <action dev="CZ" type="update">
  +     Make the current sitemap service manager available through the component context.
  +   </action>
  +   <action dev="CZ" type="update">
        Moving portlet environment to portal block.
      </action>
      <action dev="CZ" type="update">
  
  
  
  1.5       +4 -1      cocoon-2.1/src/java/org/apache/cocoon/components/ContextHelper.java
  
  Index: ContextHelper.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/ContextHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ContextHelper.java	1 Jun 2003 15:55:35 -0000	1.4
  +++ ContextHelper.java	24 Feb 2004 09:54:56 -0000	1.5
  @@ -78,6 +78,9 @@
       /** Application <code>Context</code> Key for the current response object
*/
       public static final String CONTEXT_RESPONSE_OBJECT = CONTEXT_OBJECT_MODEL + '.' + ObjectModelHelper.RESPONSE_OBJECT;
   
  +    /** Application <code>Context</code> Key for the current sitemap service
manager */
  +    public static final String CONTEXT_SITEMAP_SERVICE_MANAGER = "sitemap-service-manager";
  +    
       private ContextHelper() {
           // Forbid instantiation
       }
  
  
  
  1.4       +49 -4     cocoon-2.1/src/java/org/apache/cocoon/components/ComponentContext.java
  
  Index: ComponentContext.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/ComponentContext.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ComponentContext.java	19 Jan 2004 10:33:23 -0000	1.3
  +++ ComponentContext.java	24 Feb 2004 09:54:56 -0000	1.4
  @@ -52,16 +52,22 @@
   
   import java.util.Map;
   
  +import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.DefaultContext;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.environment.Environment;
   
   /**
    * 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.
  - *
  + * getting objects from the object model and other application information.
  + * 
  + * @see org.apache.cocoon.components.ContextHelper
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
    */
  @@ -116,12 +122,18 @@
        */
       public Object get( final Object key )
       throws ContextException {
  -        if ( key.equals(ContextHelper.CONTEXT_OBJECT_MODEL)) {
  +        if ( ContextHelper.CONTEXT_OBJECT_MODEL.equals(key)) {
               final Environment env = CocoonComponentManager.getCurrentEnvironment();
               if ( env == null ) {
                   throw new ContextException("Unable to locate " + key + " (No environment
available)");
               }
               return env.getObjectModel();
  +        } else if ( ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER.equals(key)) {
  +            final ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();
  +            if ( manager == null ) {
  +                throw new ContextException("Unable to locate " + key + " (No environment
available)");
  +            }
  +            return new ComponentManagerWrapper(manager);
           }
           if ( key instanceof String ) {
               String stringKey = (String)key;
  @@ -144,4 +156,37 @@
           return super.get( key );
       }
   
  +    public static final class ComponentManagerWrapper implements ServiceManager {
  +        
  +        protected final ComponentManager manager;
  +        
  +        public ComponentManagerWrapper(ComponentManager m) {
  +            this.manager = m;
  +        }
  +        
  +        /* (non-Javadoc)
  +         * @see org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String)
  +         */
  +        public boolean hasService(String role) {
  +            return this.manager.hasComponent(role);
  +        }
  +
  +        /* (non-Javadoc)
  +         * @see org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String)
  +         */
  +        public Object lookup(String role) throws ServiceException {
  +            try {
  +                return this.manager.lookup(role);
  +            } catch (ComponentException ce) {
  +                throw new ServiceException("ComponentManagerWrapper", "Unable to lookup
component: " + role, ce);
  +            }
  +        }
  +        
  +        /* (non-Javadoc)
  +         * @see org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object)
  +         */
  +        public void release(Object c) {
  +            this.manager.release((Component)c);
  +        }
  +    }
   }
  
  
  

Mime
View raw message