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/role ECMRoleManager.java
Date Sat, 03 Apr 2004 18:10:35 GMT
cziegeler    2004/04/03 10:10:35

  Modified:    fortress/container-impl/src/java/org/apache/avalon/fortress/util
                        ContextManager.java FortressConfig.java
                        ContextManagerConstants.java
  Added:       fortress/container-impl/src/java/org/apache/avalon/fortress/impl/role
                        ECMRoleManager.java
  Log:
  ECMRoleManager for better compatibility with ECM
  Make RoleManager class configurable
  
  Revision  Changes    Path
  1.53      +26 -5     avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/util/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/util/ContextManager.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- ContextManager.java	28 Mar 2004 18:56:42 -0000	1.52
  +++ ContextManager.java	3 Apr 2004 18:10:34 -0000	1.53
  @@ -57,6 +57,7 @@
   import org.apache.excalibur.source.impl.SourceResolverImpl;
   import org.apache.excalibur.source.impl.URLSourceFactory;
   
  +import java.lang.reflect.Constructor;
   import java.util.ArrayList;
   import java.util.Collections;
   import java.util.Comparator;
  @@ -593,11 +594,31 @@
           frm.enableLogging( rmLogger.getChildLogger( "defaults" ) );
           frm.initialize();
   
  -        // Create a role manager with the configured roles
  -        final ConfigurableRoleManager rm = new ConfigurableRoleManager( frm );
  -        rm.enableLogging( rmLogger );
  -        rm.configure( roleConfig );
  +        RoleManager rm;
  +        if ( entryPresent( m_rootContext, ROLE_MANAGER_CLASS ) )
  +        {
  +            Class clazz = (Class)m_rootContext.get( ROLE_MANAGER_CLASS );
  +            // Test if the class implements a constructor to pass into the parent
  +            try 
  +            {
  +                Constructor parentAwareConstructor = clazz.getConstructor(new Class[] {RoleManager.class});
  +                rm = (RoleManager)parentAwareConstructor.newInstance(new Object[] {frm});
  +            }
  +            catch (NoSuchMethodException ignore )
  +            {
  +                rm = (RoleManager)clazz.newInstance();
  +            }
  +        } 
  +        else
  +        {
  +            // Create a role manager with the configured roles
  +            rm = new ConfigurableRoleManager( frm );
  +        } 
   
  +        ContainerUtil.enableLogging(rm, rmLogger );
  +        ContainerUtil.configure( rm, roleConfig );
  +        ContainerUtil.initialize( rm );
  +        
           assumeOwnership( rm );
           return rm;
       }
  
  
  
  1.23      +22 -1     avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/util/FortressConfig.java
  
  Index: FortressConfig.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/util/FortressConfig.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- FortressConfig.java	28 Feb 2004 15:16:26 -0000	1.22
  +++ FortressConfig.java	3 Apr 2004 18:10:35 -0000	1.23
  @@ -287,6 +287,27 @@
           m_context.put( ContextManagerConstants.ROLE_MANAGER_CONFIGURATION_URI, null );
       }
   
  +    public void setRoleManagerClass( final String containerClass )
  +    throws ClassNotFoundException
  +    {
  +        ClassLoader classLoader;
  +        try
  +        {
  +            classLoader = (ClassLoader) m_context.get( ClassLoader.class.getName() );
  +        }
  +        catch ( ContextException ce )
  +        {
  +            classLoader = Thread.currentThread().getContextClassLoader();
  +        }
  +
  +        setRoleManagerClass( classLoader.loadClass( containerClass ) );
  +    }   
  +
  +    public void setRoleManagerClass( final Class clazz )
  +    {
  +        m_context.put( ContextManagerConstants.ROLE_MANAGER_CLASS, clazz );
  +    }
  +    
       public void setRoleManagerConfiguration( final String location )
       {
           m_context.put( ContextManagerConstants.ROLE_MANAGER_CONFIGURATION_URI, location
);
  
  
  
  1.10      +3 -2      avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/util/ContextManagerConstants.java
  
  Index: ContextManagerConstants.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/util/ContextManagerConstants.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ContextManagerConstants.java	28 Feb 2004 15:16:26 -0000	1.9
  +++ ContextManagerConstants.java	3 Apr 2004 18:10:35 -0000	1.10
  @@ -37,6 +37,7 @@
   
       String ROLE_MANAGER_CONFIGURATION = "impl.roleManager.config";
       String ROLE_MANAGER_CONFIGURATION_URI = "impl.roleManager.config.uri";
  -
  +    String ROLE_MANAGER_CLASS = "impl.roleManager.class";
  +    
       String CONFIGURATION_URI = "impl.configuration.uri";
   }
  
  
  
  1.1                  avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl/role/ECMRoleManager.java
  
  Index: ECMRoleManager.java
  ===================================================================
  /* 
   * Copyright 2003-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.role;
  
  import org.apache.avalon.fortress.RoleManager;
  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;
  
  /**
   * This role manager implementation is able to read ECM based role files. 
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version CVS $Revision: 1.1 $ $Date: 2004/04/03 18:10:35 $
   */
  public class ECMRoleManager
          extends AbstractRoleManager
          implements Configurable
  {
      
      /**
       * Default constructor--this RoleManager has no parent.
       */
      public ECMRoleManager() 
      {
          super( null, null );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * classloader.
       *
       * @param loader  The <code>ClassLoader</code> used to resolve class names.
       */
      public ECMRoleManager( final ClassLoader loader ) 
      {
          super( null, loader );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * parent.
       *
       * @param parent  The parent <code>RoleManager</code>.
       */
      public ECMRoleManager( final RoleManager parent ) 
      {
          super( parent, null );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * parent and a classloader.
       *
       * @param parent The parent <code>RoleManager</code>.
       * @param loader the classloader
       */
      public ECMRoleManager( final RoleManager parent, 
                              final ClassLoader loader ) 
      {
          super( parent, loader );
      }
  
      /**
       * Reads a configuration object and creates the role, shorthand,
       * and class name mapping.
       *
       * @param configuration  The configuration object.
       * @throws ConfigurationException if the configuration is malformed
       */
      public final void configure( final Configuration configuration )
      throws ConfigurationException 
      {
          final Configuration[] roles = configuration.getChildren( "role" );
  
          for ( int i = 0; i < roles.length; i++ ) 
          {
              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 message = "Configuration error on invalid entry:\n\tRole: "
+ role +
                          "\n\tShorthand: " + shorthand +
                          "\n\tDefault Class: " + className;
  
                  getLogger().warn(message);
              }
          }
      }
  }
  
  
  

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


Mime
View raw message