avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl DefaultECMContainer.java
Date Mon, 05 Apr 2004 08:46:06 GMT
cziegeler    2004/04/05 01:46:06

  Modified:    fortress/container-impl/src/java/org/apache/avalon/fortress/impl/role
                        AbstractRoleManager.java ECMRoleManager.java
  Added:       fortress/container-impl/src/java/org/apache/avalon/fortress/impl
                        DefaultECMContainer.java
  Log:
  Add ECM compatible container implementation
  
  Revision  Changes    Path
  1.14      +2 -2      avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl/role/AbstractRoleManager.java
  
  Index: AbstractRoleManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl/role/AbstractRoleManager.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AbstractRoleManager.java	28 Feb 2004 15:16:25 -0000	1.13
  +++ AbstractRoleManager.java	5 Apr 2004 08:46:06 -0000	1.14
  @@ -98,7 +98,7 @@
   
       /**
        * Addition of a role to the role manager.
  -     * @param shortName the shor name for the role
  +     * @param shortName the short name for the role
        * @param role the role
        * @param className the class name
        * @param handlerClassName the handler classname
  
  
  
  1.2       +49 -6     avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl/role/ECMRoleManager.java
  
  Index: ECMRoleManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl/role/ECMRoleManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ECMRoleManager.java	3 Apr 2004 18:10:35 -0000	1.1
  +++ ECMRoleManager.java	5 Apr 2004 08:46:06 -0000	1.2
  @@ -17,11 +17,17 @@
   
   package org.apache.avalon.fortress.impl.role;
   
  +import org.apache.avalon.excalibur.pool.Poolable;
   import org.apache.avalon.fortress.RoleManager;
  +import org.apache.avalon.fortress.impl.handler.FactoryComponentHandler;
  +import org.apache.avalon.fortress.impl.handler.PerThreadComponentHandler;
  +import org.apache.avalon.fortress.impl.handler.PoolableComponentHandler;
   import org.apache.avalon.fortress.impl.role.AbstractRoleManager;
   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.thread.SingleThreaded;
  +import org.apache.avalon.framework.thread.ThreadSafe;
   
   /**
    * This role manager implementation is able to read ECM based role files. 
  @@ -93,17 +99,54 @@
           {
               final String role = roles[i].getAttribute( "name" );
               final String shorthand = roles[i].getAttribute( "shorthand" );
  -            final String className = roles[i].getAttribute( "default-class", null );
  -            
  -            if ( ! addRole( shorthand, role, className, null ) ) 
  +            final String defaultClassName = roles[i].getAttribute( "default-class", null
);
  +                        
  +            if ( ! addRole( shorthand, role, defaultClassName,  getComponentHandlerClassName(defaultClassName))
) 
               {
  -                
  +                    
                   final String message = "Configuration error on invalid entry:\n\tRole:
" + role +
                           "\n\tShorthand: " + shorthand +
  -                        "\n\tDefault Class: " + className;
  +                        "\n\tDefault Class: " + defaultClassName;
   
                   getLogger().warn(message);
               }
  +            
  +        }
  +    }
  +    
  +    protected String getComponentHandlerClassName(final String defaultClassName) 
  +    {
  +        if ( defaultClassName == null )
  +        {
  +            return null;
  +        }
  +        Class clazz;
  +        try
  +        {
  +            clazz = getLoader().loadClass( defaultClassName );
  +        }
  +        catch ( final Exception e )
  +        {
  +            final String message =
  +                "Unable to load class " + defaultClassName + ". Using dfault component
handler.";
  +            getLogger().warn( message );
  +            return null;
  +        }
  +        
  +        if ( ThreadSafe.class.isAssignableFrom( clazz ) )
  +        {
  +            return PerThreadComponentHandler.class.getName();
  +        }
  +        else if ( Poolable.class.isAssignableFrom( clazz ) )
  +        {
  +            return PoolableComponentHandler.class.getName();
  +        }
  +        else if ( SingleThreaded.class.isAssignableFrom( clazz) )
  +        {            
  +            return FactoryComponentHandler.class.getName();
           }
  +        
  +        // Don't know, use default
  +        return null ;
       }
   }
  
  
  
  1.1                  avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java
  
  Index: DefaultECMContainer.java
  ===================================================================
  /*
   * Copyright 1999-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.fortress.impl;
  
  import org.apache.avalon.fortress.MetaInfoEntry;
  import org.apache.avalon.fortress.RoleManager;
  import org.apache.avalon.fortress.impl.ComponentHandlerMetaData;
  import org.apache.avalon.fortress.impl.DefaultContainer;
  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.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  
  /**
   * Customize the Fortress container to handle ECM compatibility
   *
   * @author <a href="mailto:dev@avalon.apache.org">The Avalon Team</a>
   * @version CVS $ Revision: 1.1 $
   */
  public class DefaultECMContainer extends DefaultContainer {
      
      protected RoleManager m_roleManager;
      
      /**
       * Retrieve the classname for component configuration.
       *
       * @param config the component configuration
       * @return the class name
       */
      private String getClassname( final Configuration config )
      throws ConfigurationException {
          final String className;
  
          if ( "component".equals( config.getName() ) ) {
              className = config.getAttribute( "class" );
          } else {
              final MetaInfoEntry roleEntry = m_metaManager.getMetaInfoForShortName( config.getName()
);
              if ( null == roleEntry )
              {
                  
                  final String message = "No class found matching configuration name " +
                      "[name: " + config.getName() + ", location: " + config.getLocation()
+ "]";
                  throw new ConfigurationException( message );
              }
  
              className = roleEntry.getComponentClass().getName();
          }
  
          if ( getLogger().isDebugEnabled() ) {
              getLogger().debug( "Configuration processed for: " + className );
          }
  
          return className;
      }
  
      /**
       * Provide some validation for the core Cocoon components
       *
       * @param conf The configuration
       * @throws ConfigurationException if the coniguration is invalid
       */
      public void configure( Configuration conf ) 
      throws ConfigurationException {
          this.interpretProxy( conf.getAttribute("proxy-type", "none") );
  
          final Configuration[] elements = conf.getChildren();
          for ( int i = 0; i < elements.length; i++ )
          {
              final Configuration element = elements[i];
              String hint = element.getAttribute( "id", null );
              if ( null == hint ) {
                  // Fortress requires a hint, so we just give it one :)
                  hint = element.getLocation();
              }
              final String classname = getClassname( element );
              final int activation = ComponentHandlerMetaData.ACTIVATION_BACKGROUND;
              final ComponentHandlerMetaData metaData =
                  new ComponentHandlerMetaData( hint, classname, element, activation );
  
              try {
                  addComponent( metaData );
              } catch ( Exception e ) {
                  throw new ConfigurationException( "Could not add component", e );
              }
          }
      }
      
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message