You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/11/10 03:39:51 UTC

cvs commit: jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test ConfigurableRoleManagerTestCase.java ExcaliburRoleManagerTestCase.java

donaldp     2002/11/09 18:39:51

  Modified:    fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing
                        SwingContainer.xinfo
               fortress/src/java/org/apache/excalibur/fortress/container
                        AbstractContainer.java
               fortress/src/java/org/apache/excalibur/fortress/util
                        ContextBuilder.java ContextManager.java
               fortress/src/test/org/apache/excalibur/fortress/util/test
                        ConfigurableRoleManagerTestCase.java
                        ExcaliburRoleManagerTestCase.java
  Added:       fortress/src/java/org/apache/excalibur/fortress/role
                        AbstractRoleManager.java
                        ConfigurableRoleManager.java
                        ExcaliburRoleManager.java RoleManager.java
  Removed:     fortress/src/java/org/apache/excalibur/fortress/util
                        AbstractRoleManager.java
                        ConfigurableRoleManager.java
                        ExcaliburRoleManager.java RoleManager.java
  Log:
  Migrate all role related classes into a new package named "role"
  
  Revision  Changes    Path
  1.3       +9 -9      jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/SwingContainer.xinfo
  
  Index: SwingContainer.xinfo
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/SwingContainer.xinfo,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SwingContainer.xinfo	22 Jul 2002 12:51:32 -0000	1.2
  +++ SwingContainer.xinfo	10 Nov 2002 02:39:50 -0000	1.3
  @@ -8,7 +8,7 @@
     <component>
       <name>fortress-swing</name>
     </component>
  -  
  +
     <context>
   
       <!--
  @@ -17,22 +17,22 @@
   
       <entry key="container.logManager" type="org.apache.avalon.excalibur.logger.LoggerManager"/>
       <entry key="container.poolManager" type="org.apache.excalibur.mpool.PoolManager"/>
  -    <entry key="container.roleManager" type="org.apache.excalibur.fortress.util.RoleManager"/>
  +    <entry key="container.roleManager" type="org.apache.excalibur.fortress.role.RoleManager"/>
   
       <!--
       Optional context.
       -->
   
       <entry key="container.classloader" type="java.lang.ClassLoader" option="true"/>
  -    <entry key="container.extensionManager" 
  +    <entry key="container.extensionManager"
         type="org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager" optional="true"/>
  -    <entry key="container.commandQueue" 
  +    <entry key="container.commandQueue"
         type="org.apache.excalibur.event.Queue" optional="true"/>
  -    <entry key="context-root" 
  +    <entry key="context-root"
         type="java.lang.String" optional="true"/>
  -    <entry key="container.workDir" 
  +    <entry key="container.workDir"
         type="java.lang.String" optional="true"/>
  -    
  +
     </context>
   
     <dependencies>
  @@ -44,9 +44,9 @@
   
   
     <services>
  -    <service> 
  +    <service>
         <service-ref type="org.apache.excalibur.fortress.Container"/>
  -    </service> 
  +    </service>
     </services>
   
   </component-info>
  
  
  
  1.11      +3 -3      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/AbstractContainer.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractContainer.java	9 Nov 2002 23:25:44 -0000	1.10
  +++ AbstractContainer.java	10 Nov 2002 02:39:50 -0000	1.11
  @@ -79,8 +79,8 @@
   import org.apache.excalibur.fortress.handler.ProxyObjectFactory;
   import org.apache.excalibur.fortress.lookup.FortressServiceManager;
   import org.apache.excalibur.fortress.lookup.FortressServiceSelector;
  -import org.apache.excalibur.fortress.util.ExcaliburRoleManager;
  -import org.apache.excalibur.fortress.util.RoleManager;
  +import org.apache.excalibur.fortress.role.ExcaliburRoleManager;
  +import org.apache.excalibur.fortress.role.RoleManager;
   import org.apache.excalibur.instrument.InstrumentManager;
   import org.apache.excalibur.instrument.Instrumentable;
   import org.apache.excalibur.mpool.ObjectFactory;
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/AbstractRoleManager.java
  
  Index: AbstractRoleManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ 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 "Jakarta", "Avalon", "Excalibur" 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. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.fortress.role;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.excalibur.fortress.role.RoleManager;
  
  /**
   * The Excalibur Role Manager is used for Excalibur Role Mappings.  All of
   * the information is hard-coded.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/11/10 02:39:50 $
   * @since 4.1
   */
  public abstract class AbstractRoleManager
      extends AbstractLogEnabled
      implements RoleManager
  {
      protected static final String EMPTY_STRING = "";
  
      protected final ClassLoader m_loader;
  
      /** Map for shorthand to class mapping */
      protected Map m_shorthands;
  
      /** Map for role to classname mapping */
      protected Map m_classNames;
  
      /** Map for role to handler classname mapping */
      protected Map m_handlerNames;
  
      /** Parent <code>RoleManager</code> for nested resolution */
      protected final RoleManager m_parent;
  
      /**
       * Default constructor--this RoleManager has no parent.
       */
      public AbstractRoleManager()
      {
          this( null );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * parent.
       *
       * @param parent  The parent <code>RoleManager</code>.
       */
      public AbstractRoleManager( RoleManager parent )
      {
          this( parent, Thread.currentThread().getContextClassLoader() );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * parent.
       *
       * @param parent  The parent <code>RoleManager</code>.
       */
      public AbstractRoleManager( RoleManager parent, ClassLoader loader )
      {
          ClassLoader thisLoader = loader;
  
          if( null == thisLoader )
          {
              thisLoader = Thread.currentThread().getContextClassLoader();
          }
  
          m_loader = thisLoader;
          m_parent = parent;
      }
  
      protected void setup( Map shorts, Map classes, Map handlers,
                            String shortName, String role, String className,
                            String handlerClassName )
      {
          final Class klass;
          Class handlerKlass;
  
          if( getLogger().isDebugEnabled() )
          {
              getLogger().debug( "setup role: name='" + shortName + "', role='" + role + "', "
                                 + "class='" + className + "', handler='" + handlerClassName + "'" );
          }
  
          try
          {
              klass = m_loader.loadClass( className );
          }
          catch( Exception e )
          {
              // Do not store reference if class does not exist.
              return;
          }
          catch( NoClassDefFoundError e )
          {
              // Do not store reference if class does not exist.
              return;
          }
  
          try
          {
              handlerKlass = m_loader.loadClass( handlerClassName );
          }
          catch( Exception e )
          {
              handlerKlass = org.apache.excalibur.fortress.handler.PerThreadComponentHandler.class;
          }
  
          shorts.put( shortName, klass );
          shorts.put( klass, shortName );
          classes.put( klass,
                       role );
  
          List classList = (List)classes.get( role );
  
          if( null == classList )
          {
              classList = new ArrayList( 5 );
          }
  
          classList.add( klass );
          classes.put( role, classList );
  
          handlers.put( klass, handlerKlass );
      }
  
      /**
       * Find the Class for the given shorthand name.  If there is no
       * correspondence between the class and the shorthand name, the method
       * returns <code>null</code>.  If this RoleManager does not have the
       * match, and there is a parent RoleManager, the parent will be asked to
       * resolve the request.
       */
      public final Class getClassForName( final String shorthandName )
      {
          if( shorthandName == null ) return null;
  
          Class component = (Class)m_shorthands.get( shorthandName );
  
          if( null == component && null != m_parent )
          {
              component = m_parent.getClassForName( shorthandName );
          }
  
          if( getLogger().isDebugEnabled() )
          {
              if( component == null )
              {
                  getLogger().debug( "looking up class with shorthand '" + shorthandName
                                     + "' but a class was not found." );
              }
              else
              {
                  getLogger().debug( "looking up class with shorthand '" + shorthandName
                                     + "' returning '" + component.getName() + "'" );
              }
          }
  
          return component;
      }
  
      /**
       * Retrieves the real role name from a shorthand name.  Usually
       * the shorthand name refers to a configuration element name.  If
       * this RoleManager does not have the match, and there is a parent
       * RoleManager, the parent will be asked to resolve the role.
       *
       * @param klass The class whose role is being requested.
       * @return the official role name.
       */
      public final String getNameForClass( final Class klass )
      {
          String shorthandName = (String)m_shorthands.get( klass );
  
          if( null == shorthandName && null != m_parent )
          {
              shorthandName = m_parent.getNameForClass( klass );
          }
  
          if( getLogger().isDebugEnabled() )
          {
              if( shorthandName == null )
              {
                  getLogger().debug( "looking up shorthand with class '" + klass.getName()
                                     + "' but a shorthand was not found." );
              }
              else
              {
                  getLogger().debug( "looking up shorthand with class '" + klass.getName()
                                     + "' returning '" + shorthandName + "'" );
              }
          }
  
          return shorthandName;
      }
  
      /**
       * Retrieves the handler class name for the specified class name.  This
       * is called for every ComponentImplementation.  If this RoleManager does
       * not have the match, and there is a parent RoleManager, the parent will
       * be asked to resolve the handler's class name.
       *
       * @param klass  The role that has a default implementation.
       * @return the Fully Qualified Class Name (FQCN) for the role.
       */
      public final Class getHandlerClassForClass( final Class klass )
      {
          Class handler = (Class)m_handlerNames.get( klass );
  
          if( null == handler && null != m_parent )
          {
              handler = m_parent.getHandlerClassForClass( klass );
          }
  
          if( getLogger().isDebugEnabled() )
          {
              if( handler == null )
              {
                  getLogger().debug( "looking up handler class with class '" + klass.getName()
                                     + "' but a handler was not found." );
              }
              else
              {
                  getLogger().debug( "looking up handler class with class '" + klass.getName()
                                     + "' returning '" + handler.getName() + "'" );
              }
          }
  
          return handler;
      }
  
      /**
       * Retrieves the default class name for the specified role.  This
       * is only called when the configuration does not specify the
       * class explicitly.  If this RoleManager does not have the match,
       * and there is a parent RoleManager, the parent will be asked
       * to resolve the class name.
       *
       * @param role  The role that has a default implementation.
       * @return the Fully Qualified Class Name (FQCN) for the role.
       */
      public final Class[] getClassesForRole( final String role )
      {
          List classes = (List)m_classNames.get( role );
  
          Class[] classAry;
          if( null == classes && null != m_parent )
          {
              classAry = m_parent.getClassesForRole( role );
          }
          else
          {
              // Convert the list into an array
              if( classes == null )
              {
                  classAry = new Class[ 0 ];
              }
              else
              {
                  classAry = new Class[ classes.size() ];
                  classes.toArray( classAry );
              }
          }
  
          if( getLogger().isDebugEnabled() )
          {
              if( classes == null )
              {
                  getLogger().debug( "looking up classes with role '" + role
                                     + "' but no classes were found." );
              }
              else
              {
                  StringBuffer sb = new StringBuffer();
                  for( int i = 0; i < classAry.length; i++ )
                  {
                      if( i > 0 )
                      {
                          sb.append( ", " );
                      }
                      sb.append( "'" );
                      sb.append( classAry[ i ].getName() );
                      sb.append( "'" );
                  }
                  getLogger().debug( "looking up classes with role '" + role
                                     + "' returning [" + sb + "]" );
              }
          }
  
          return classAry;
      }
  
      /**
       * Retrieves a default class name for a role/hint combination.
       * This is only called when a role is mapped to a
       * DefaultComponentSelector, and the configuration elements use
       * shorthand names for the type of component.  If this RoleManager
       * does not have the match, and there is a parent RoleManager, the
       * parent will be asked to resolve the class name.
       *
       * @param klass The class to get rolename for
       * @return the FQCN for the role/hint combination.
       */
      public final String getRoleForClass( final Class klass )
      {
          String role = (String)m_classNames.get( klass );
  
          if( null == role )
          {
              if( null != m_parent )
              {
                  role = m_parent.getRoleForClass( klass );
              }
              else
              {
                  role = EMPTY_STRING;
              }
          }
  
          if( getLogger().isDebugEnabled() )
          {
              getLogger().debug( "looking up role with class '" + klass.getName()
                                 + "' returning '" + role + "'" );
          }
  
          return role;
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/ConfigurableRoleManager.java
  
  Index: ConfigurableRoleManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ 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 "Jakarta", "Avalon", "Excalibur" 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. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.fortress.role;
  
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Map;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.excalibur.fortress.role.RoleManager;
  
  /**
   * Configurable RoleManager implementation.  It populates the RoleManager
   * from a configuration hierarchy.  This is based on the DefaultRoleManager
   * in the org.apache.avalon.component package.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/11/10 02:39:50 $
   * @since 4.1
   */
  public class ConfigurableRoleManager
      extends AbstractRoleManager
      implements Configurable
  {
      /**
       * Default constructor--this RoleManager has no parent.
       */
      public ConfigurableRoleManager()
      {
          super( null );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * parent.
       *
       * @param parent  The parent <code>RoleManager</code>.
       */
      public ConfigurableRoleManager( RoleManager parent )
      {
          super( parent, null );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * parent and a classloader.
       *
       * @param parent  The parent <code>RoleManager</code>.
       */
      public ConfigurableRoleManager( RoleManager parent, ClassLoader loader )
      {
          super( parent, loader );
      }
  
      /**
       * Reads a configuration object and creates the role, shorthand,
       * and class name mapping.
       *
       * @param configuration  The configuration object.
       * @throws org.apache.avalon.framework.configuration.ConfigurationException if the configuration is malformed
       */
      public final void configure( final Configuration configuration )
          throws ConfigurationException
      {
          final Map shorts = new HashMap();
          final Map classes = new HashMap();
          final Map handlers = new HashMap();
  
          final Configuration[] roles = configuration.getChildren( "role" );
  
          for( int i = 0; i < roles.length; i++ )
          {
              final String role = roles[ i ].getAttribute( "name" );
              Configuration[] components = roles[ i ].getChildren( "component" );
  
              for( int j = 0; j < components.length; j++ )
              {
                  final String shorthand = components[ j ].getAttribute( "shorthand" );
                  final String className =
                      components[ j ].getAttribute( "class", null );
                  final String handlerClassName =
                      components[ j ].getAttribute( "handler",
                                                    "org.apache.excalibur.fortress.handler.PerThreadComponentHandler" );
  
                  setup( shorts, classes, handlers, shorthand, role, className, handlerClassName );
              }
          }
  
          m_shorthands = Collections.unmodifiableMap( shorts );
          m_classNames = Collections.unmodifiableMap( classes );
          m_handlerNames = Collections.unmodifiableMap( handlers );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/ExcaliburRoleManager.java
  
  Index: ExcaliburRoleManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ 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 "Jakarta", "Avalon", "Excalibur" 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. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.fortress.role;
  
  import java.util.Collections;
  import java.util.HashMap;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.excalibur.fortress.role.RoleManager;
  
  /**
   * The Excalibur Role Manager is used for Excalibur Role Mappings.  All of
   * the information is hard-coded.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/11/10 02:39:50 $
   * @since 4.1
   */
  public class ExcaliburRoleManager
      extends AbstractRoleManager
      implements Initializable
  {
      /**
       * Default constructor--this RoleManager has no parent.
       */
      public ExcaliburRoleManager()
      {
          this( null );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * parent.
       *
       * @param parent  The parent <code>RoleManager</code>.
       */
      public ExcaliburRoleManager( RoleManager parent )
      {
          this( parent, null );
      }
  
      /**
       * Alternate constructor--this RoleManager has the specified
       * parent and a classloader.
       *
       * @param parent  The parent <code>RoleManager</code>.
       */
      public ExcaliburRoleManager( RoleManager parent, ClassLoader loader )
      {
          super( parent, loader );
      }
  
      /**
       * Initialize the role manager.
       */
      public void initialize()
      {
          HashMap shorts = new HashMap( 10 );
          HashMap classes = new HashMap( 10 );
          HashMap handlers = new HashMap( 10 );
  
          /* Set up Cache relations */
          setup( shorts, classes, handlers, "cache",
                 "org.apache.excalibur.cache.Cache",
                 "org.apache.excalibur.cache.impl.DefaultCache",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          setup( shorts, classes, handlers, "lru-cache",
                 "org.apache.excalibur.cache.Cache",
                 "org.apache.excalibur.cache.impl.LRUCache",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
  
          /* Set up DataSource relations */
          setup( shorts, classes, handlers, "jdbc-datasource",
                 "org.apache.avalon.excalibur.datasource.DataSourceComponent",
                 "org.apache.avalon.excalibur.datasource.JdbcDataSource",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          setup( shorts, classes, handlers, "j2ee-datasource",
                 "org.apache.avalon.excalibur.datasource.DataSourceComponent",
                 "org.apache.avalon.excalibur.datasource.J2eeDataSource",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          setup( shorts, classes, handlers, "informix-datasource",
                 "org.apache.avalon.excalibur.datasource.DataSourceComponent",
                 "org.apache.avalon.excalibur.datasource.InformixDataSource",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
  
          /* Set up i18n relations */
          setup( shorts, classes, handlers, "i18n",
                 "org.apache.excalibur.xmlbundle.BundleSelector",
                 "org.apache.excalibur.xmlbundle.BundleSelector",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
  
          /* Set up Monitor relations */
          setup( shorts, classes, handlers, "monitor",
                 "org.apache.avalon.excalibur.monitor.Monitor",
                 "org.apache.avalon.excalibur.monitor.ActiveMonitor",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          setup( shorts, classes, handlers, "passive-monitor",
                 "org.apache.avalon.excalibur.monitor.Monitor",
                 "org.apache.avalon.excalibur.monitor.PassiveMonitor",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
  
          /* Set up XPath relations */
          setup( shorts, classes, handlers, "xalan-xpath",
                 "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
                 "org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          setup( shorts, classes, handlers, "jaxpath",
                 "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
                 "org.apache.avalon.excalibur.xml.xpath.JaxenProcessorImpl",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
  
          /* Set up SourceResolver relations */
          setup( shorts, classes, handlers, "resolver",
                 "org.apache.excalibur.source.SourceResolver",
                 "org.apache.excalibur.source.impl.SourceResolverImpl",
                 "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
  
          /* Set up XML parser relations */
          setup( shorts, classes, handlers, "parser",
                 "org.apache.avalon.excalibur.xml.Parser",
                 "org.apache.avalon.excalibur.xml.JaxpParser",
                 "org.apache.excalibur.fortress.handler.PerThreadComponentHandler" );
          setup( shorts, classes, handlers, "xerces-parser",
                 "org.apache.avalon.excalibur.xml.Parser",
                 "org.apache.avalon.excalibur.xml.XercesParser",
                 "org.apache.excalibur.fortress.handler.FactoryComponentHandler" );
  
          m_shorthands = Collections.unmodifiableMap( shorts );
          m_classNames = Collections.unmodifiableMap( classes );
          m_handlerNames = Collections.unmodifiableMap( handlers );
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/RoleManager.java
  
  Index: RoleManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ 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 "Jakarta", "Avalon", "Excalibur" 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. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.fortress.role;
  
  /**
   * RoleManager Interface, use this to specify the Components and how they
   * correspond to easy shorthand names. The RoleManager assumes a flat
   * relationship of shorthand names to classes, and classes to roles.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/11/10 02:39:50 $
   * @since 4.1
   */
  public interface RoleManager
  {
      /**
       * Find the Class for the given shorthand name.  If there is no
       * correspondence between the class and the shorthand name, the method
       * returns <code>null</code>.  If this RoleManager does not have the
       * match, and there is a parent RoleManager, the parent will be asked to
       * resolve the request.
       */
      Class getClassForName( String shorthandName );
  
      /**
       * This method is merely a hint for serialization.  If this RoleManager
       * does not have the match, and there is a parent RoleManager, the parent
       * will be asked to resolve the request.
       */
      String getNameForClass( Class component );
  
      /**
       * Get the Role name for a specific class.  If the class does not belong
       * to a Component, or the Role is not easily determinable, this method
       * will return <code>null</code>.  If this RoleManager does not have the
       * match, and there is a parent RoleManager, the parent will be asked to
       * resolve the request.
       */
      String getRoleForClass( Class component );
  
      /**
       * Get an array of classes registered with the role manager that
       * implement a role.  If this RoleManager does not have the match, and
       * there is a parent RoleManager, the parent will be asked to resolve the
       * request.
       */
      Class[] getClassesForRole( String role );
  
      /**
       * Retrieves the handler class name for the specified class.  This
       * is called for every Component Implementation.  If this RoleManager
       * does not have the match, and there is a parent RoleManager, the parent
       * will be asked to resolve the handler's class name.
       *
       * @param clazz The class of the Component in question.
       * @return the Class instance of the ComponentHandler.
       */
      Class getHandlerClassForClass( Class clazz );
  }
  
  
  1.26      +1 -0      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextBuilder.java
  
  Index: ContextBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextBuilder.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ContextBuilder.java	2 Oct 2002 01:52:21 -0000	1.25
  +++ ContextBuilder.java	10 Nov 2002 02:39:51 -0000	1.26
  @@ -59,6 +59,7 @@
   import org.apache.excalibur.event.Queue;
   import org.apache.excalibur.instrument.InstrumentManager;
   import org.apache.excalibur.mpool.PoolManager;
  +import org.apache.excalibur.fortress.role.RoleManager;
   
   /**
    * Helper class to create a context for the ContextManager.
  
  
  
  1.49      +3 -1      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextManager.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- ContextManager.java	9 Nov 2002 07:20:41 -0000	1.48
  +++ ContextManager.java	10 Nov 2002 02:39:51 -0000	1.49
  @@ -80,6 +80,8 @@
   import org.apache.excalibur.source.SourceResolver;
   import org.apache.excalibur.source.impl.ResourceSourceFactory;
   import org.apache.excalibur.source.impl.SourceResolverImpl;
  +import org.apache.excalibur.fortress.role.ExcaliburRoleManager;
  +import org.apache.excalibur.fortress.role.ConfigurableRoleManager;
   import org.apache.log.Hierarchy;
   import org.apache.log.Priority;
   
  
  
  
  1.15      +2 -2      jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test/ConfigurableRoleManagerTestCase.java
  
  Index: ConfigurableRoleManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test/ConfigurableRoleManagerTestCase.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ConfigurableRoleManagerTestCase.java	13 Aug 2002 07:57:27 -0000	1.14
  +++ ConfigurableRoleManagerTestCase.java	10 Nov 2002 02:39:51 -0000	1.15
  @@ -54,7 +54,7 @@
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.avalon.framework.logger.ConsoleLogger;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.excalibur.fortress.util.ConfigurableRoleManager;
  +import org.apache.excalibur.fortress.role.ConfigurableRoleManager;
   
   /**
    * Configurable RoleManager implementation.  It populates the RoleManager
  
  
  
  1.18      +2 -2      jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test/ExcaliburRoleManagerTestCase.java
  
  Index: ExcaliburRoleManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test/ExcaliburRoleManagerTestCase.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ExcaliburRoleManagerTestCase.java	8 Nov 2002 06:28:10 -0000	1.17
  +++ ExcaliburRoleManagerTestCase.java	10 Nov 2002 02:39:51 -0000	1.18
  @@ -53,7 +53,7 @@
   
   import org.apache.avalon.framework.logger.ConsoleLogger;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.excalibur.fortress.util.ExcaliburRoleManager;
  +import org.apache.excalibur.fortress.role.ExcaliburRoleManager;
   
   /**
    * Configurable RoleManager implementation.  It populates the RoleManager
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>