avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: avalon-excalibur/fortress/src/tools/org/apache/avalon/fortress/tools ComponentMetaInfoCollector.java Service.java
Date Fri, 11 Apr 2003 20:39:39 GMT
bloritsch    2003/04/11 13:39:39

  Modified:    fortress/src/java/org/apache/avalon/fortress/impl/role
                        ServiceRoleManager.java
               fortress/src/java/org/apache/avalon/fortress/util
                        FortressConfig.java
               fortress/src/test/org/apache/avalon/fortress/test
                        HandlersTestCase.java
               fortress/src/test/org/apache/avalon/fortress/test/data
                        Component1.java Component2.java Component3.java
                        Component4.java Role3.java Role4.java test1.xlog
               fortress/src/tools/org/apache/avalon/fortress/tools
                        ComponentMetaInfoCollector.java Service.java
  Log:
  remove need for classloaders in build
  
  Revision  Changes    Path
  1.7       +349 -349  avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/role/ServiceRoleManager.java
  
  Index: ServiceRoleManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/role/ServiceRoleManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ServiceRoleManager.java	25 Mar 2003 21:34:01 -0000	1.6
  +++ ServiceRoleManager.java	11 Apr 2003 20:39:38 -0000	1.7
  @@ -1,349 +1,349 @@
  -/*
  -
  - ============================================================================
  -                   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.avalon.fortress.impl.role;
  -
  -import java.io.BufferedReader;
  -import java.io.IOException;
  -import java.io.InputStreamReader;
  -import java.net.URL;
  -import java.util.Collections;
  -import java.util.Enumeration;
  -import java.util.HashMap;
  -import java.util.HashSet;
  -import java.util.Iterator;
  -import java.util.Map;
  -import java.util.Properties;
  -import java.util.Set;
  -import java.util.regex.Matcher;
  -import java.util.regex.Pattern;
  -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.handler.ThreadSafeComponentHandler;
  -import org.apache.avalon.fortress.util.Service;
  -import org.apache.avalon.framework.activity.Initializable;
  -
  -/**
  - * ServiceRoleManager follows some simple rules to dynamically gather all
  - * services and the meta-information into one role manager.  This really gets
  - * rid of the need of multiple role managers.  It uses a set of entries in your
  - * JARs to do its magic.
  - *
  - * <p><code><b>/services.list</b></code></p>
  - *
  - * <p>
  - *   This lists all the services that are <em>defined</em> in this jar.
  - * </p>
  - *
  - * <p><code><b>/META-INF/services/</b><i>my.class.Name</i></code></p>
  - *
  - * <p>
  - *   One entry for each service where there are implementations for a role.  This
  - *   follows the JAR services mechanism.
  - * </p>
  - *
  - * <p><code><i>/my/class/Implementation.meta</i></code></p>
  - *
  - * <p>
  - *   There is one entry sitting right beside every implementation class.  This
  - *   holds all the meta information for the associated class.  It is a simple
  - *   properties file.
  - * </p>
  - *
  - * <h3>ANT Tasks available</h3>
  - * <p>
  - *   We have a couple of ANT tasks to make this really easy.  If you add this
  - *   to your ANT build script (customizing it to make it work in your environment),
  - *   it will make your life alot easier:
  - * </p>
  - *
  - * <pre>
  - *   &lt;taskdef name="collect-metainfo" classname="org.d_haven.guiapp.tools.ComponentMetaInfoCollector"&gt;
  - *     &lt;classpath&gt;
  - *       &lt;path refid="project.class.path"/&gt;
  - *       &lt;pathelement path="${tools.dir}/guiapp-tools.jar"/&gt;
  - *     &lt;/classpath&gt;
  - *   &lt;/taskdef&gt;
  - *
  - *   &lt;taskdef name="collect-services" classname="org.d_haven.guiapp.tools.ServiceCollector"&gt;
  - *     &lt;classpath&gt;
  - *       &lt;path refid="project.class.path"/&gt;
  - *       &lt;pathelement path="${tools.dir}/guiapp-tools.jar"/&gt;
  - *     &lt;/classpath&gt;
  - *   &lt;/taskdef&gt;
  - *
  - *   &lt;collect-metainfo destdir="${build.classes}"&gt;
  - *      &lt;fileset dir="${src.dir}"/&gt;
  - *   &lt;/collect-metainfo&gt;
  - *
  - *   &lt;collect-services inputjar="${build.dir}/${name}-core.jar"
  - *                     outputjar="${lib.dir}/${name}.jar"/&gt;
  - * </pre>
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - */
  -public class ServiceRoleManager extends AbstractRoleManager implements Initializable
  -{
  -    /** Translate from scope to component handler */
  -    private static final Map m_lifecycleMap;
  -    /** Used to split words in class names */
  -    private static final Pattern upperCase = Pattern.compile( "([A-Z]+)" );
  -
  -    // Initialize the scope map
  -    static
  -    {
  -        Map lifecycleMap = new HashMap();
  -        lifecycleMap.put( "singleton", ThreadSafeComponentHandler.class.getName() );
  -        lifecycleMap.put( "thread", PerThreadComponentHandler.class.getName() );
  -        lifecycleMap.put( "pooled", PoolableComponentHandler.class.getName() );
  -        lifecycleMap.put( "transient", FactoryComponentHandler.class.getName() );
  -
  -        m_lifecycleMap = Collections.unmodifiableMap( lifecycleMap );
  -    }
  -
  -    /**
  -     * Create a ServiceRoleManager.
  -     */
  -    public ServiceRoleManager()
  -    {
  -        super( null );
  -    }
  -
  -    /**
  -     * Create a ServiceRoleManager with a parent RoleManager.
  -     *
  -     * @param parent
  -     */
  -    public ServiceRoleManager( RoleManager parent )
  -    {
  -        super( parent, null );
  -    }
  -
  -    /**
  -     * Create a ServiceRoleManager with the supplied classloader and
  -     * parent RoleManager.
  -     *
  -     * @param parent
  -     * @param loader
  -     */
  -    public ServiceRoleManager( RoleManager parent, ClassLoader loader )
  -    {
  -        super( parent, loader );
  -    }
  -
  -    /**
  -     * Convert a Component implmentation classname into a shorthand
  -     * name.  It assumes all classnames for a particular component is
  -     * unique.
  -     *
  -     * @param string  The classname of a component
  -     * @return String the short name
  -     */
  -    public static final String createShortName( String className )
  -    {
  -        Matcher matcher = upperCase.matcher( className.substring( className.lastIndexOf(
'.' ) + 1 ) );
  -        StringBuffer shortName = new StringBuffer();
  -
  -        while( matcher.find() )
  -        {
  -            if( shortName.length() == 0 )
  -            {
  -                matcher.appendReplacement( shortName, "$1" );
  -            }
  -            else
  -            {
  -                matcher.appendReplacement( shortName, "-$1" );
  -            }
  -        }
  -
  -        matcher.appendTail( shortName );
  -
  -        return shortName.toString().toLowerCase();
  -    }
  -
  -    /**
  -     * Initialize the ServiceRoleManager by looking at all the services and
  -     * classes available in the system.
  -     */
  -    public void initialize() throws Exception
  -    {
  -        Set services = new HashSet();
  -
  -        Enumeration enum = getLoader().getResources( "services.list" );
  -        while( enum.hasMoreElements() )
  -        {
  -            readEntries( services, (URL)enum.nextElement() );
  -        }
  -
  -        Iterator it = services.iterator();
  -        while( it.hasNext() )
  -        {
  -            String role = (String)it.next();
  -            getLogger().debug( "Adding service: " + role );
  -            try
  -            {
  -                setupImplementations( role );
  -            }
  -            catch( Exception e )
  -            {
  -                getLogger().debug( "Specified service '" + role + "' is not available",
e );
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Get all the implementations of a service and set up their meta
  -     * information.
  -     *
  -     * @param role
  -     */
  -    private void setupImplementations( String role )
  -        throws IOException, ClassNotFoundException
  -    {
  -        Iterator it = Service.providers( getLoader().loadClass( role ) );
  -
  -        while( it.hasNext() )
  -        {
  -            String impl = ( (Class)it.next() ).getName();
  -            getLogger().debug( "Reading meta info for " + impl );
  -            readMeta( role, impl );
  -        }
  -    }
  -
  -    /**
  -     * Read the meta information in and actually add the role.
  -     *
  -     * @param role
  -     * @param implementation
  -     */
  -    private void readMeta( String role, String implementation )
  -    {
  -        Properties meta = new Properties();
  -
  -        try
  -        {
  -            meta.load( getLoader().getResourceAsStream( translate( implementation ) ) );
  -        }
  -        catch( IOException ioe )
  -        {
  -            getLogger().error( "Could not load meta information for " +
  -                               implementation + ", skipping this class." );
  -            return;
  -        }
  -
  -        String shortName = meta.getProperty( "x-avalon.name", createShortName( implementation
) );
  -        String handler = getHandler( meta );
  -
  -        addRole( shortName, role, implementation, handler );
  -    }
  -
  -    /**
  -     * Get the name of the requested component handler.
  -     *
  -     * @param meta
  -     * @return String
  -     */
  -    private String getHandler( Properties meta )
  -    {
  -        String lifecycle = meta.getProperty( "x-avalon.lifecycle", null );
  -        String handler = null;
  -
  -        if( null != lifecycle )
  -        {
  -            handler = (String)m_lifecycleMap.get( lifecycle );
  -        }
  -        else
  -        {
  -            handler = meta.getProperty( "fortress.handler" );
  -        }
  -
  -        if( null == handler )
  -        {
  -            handler = PerThreadComponentHandler.class.getName();
  -        }
  -
  -        return handler;
  -    }
  -
  -    /**
  -     * Translate a class name into the meta file name.
  -     *
  -     * @param implementation
  -     * @return String
  -     */
  -    private String translate( String implementation )
  -    {
  -        String entry = implementation.replace( '.', '/' );
  -        entry += ".meta";
  -        return entry;
  -    }
  -
  -    /**
  -     * Read entries in a list file and add them all to the provided Set.
  -     *
  -     * @param services
  -     * @param url
  -     */
  -    private void readEntries( Set entries, URL url )
  -        throws IOException
  -    {
  -        BufferedReader reader = new BufferedReader( new InputStreamReader( url.openStream()
) );
  -
  -        String entry = reader.readLine();
  -        while( entry != null )
  -        {
  -            entries.add( entry );
  -            entry = reader.readLine();
  -        }
  -
  -        reader.close();
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   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.avalon.fortress.impl.role;
  +
  +import java.io.BufferedReader;
  +import java.io.IOException;
  +import java.io.InputStreamReader;
  +import java.net.URL;
  +import java.util.Collections;
  +import java.util.Enumeration;
  +import java.util.HashMap;
  +import java.util.HashSet;
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Properties;
  +import java.util.Set;
  +import java.util.regex.Matcher;
  +import java.util.regex.Pattern;
  +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.handler.ThreadSafeComponentHandler;
  +import org.apache.avalon.fortress.util.Service;
  +import org.apache.avalon.framework.activity.Initializable;
  +
  +/**
  + * ServiceRoleManager follows some simple rules to dynamically gather all
  + * services and the meta-information into one role manager.  This really gets
  + * rid of the need of multiple role managers.  It uses a set of entries in your
  + * JARs to do its magic.
  + *
  + * <p><code><b>/services.list</b></code></p>
  + *
  + * <p>
  + *   This lists all the services that are <em>defined</em> in this jar.
  + * </p>
  + *
  + * <p><code><b>/META-INF/services/</b><i>my.class.Name</i></code></p>
  + *
  + * <p>
  + *   One entry for each service where there are implementations for a role.  This
  + *   follows the JAR services mechanism.
  + * </p>
  + *
  + * <p><code><i>/my/class/Implementation.meta</i></code></p>
  + *
  + * <p>
  + *   There is one entry sitting right beside every implementation class.  This
  + *   holds all the meta information for the associated class.  It is a simple
  + *   properties file.
  + * </p>
  + *
  + * <h3>ANT Tasks available</h3>
  + * <p>
  + *   We have a couple of ANT tasks to make this really easy.  If you add this
  + *   to your ANT build script (customizing it to make it work in your environment),
  + *   it will make your life alot easier:
  + * </p>
  + *
  + * <pre>
  + *   &lt;taskdef name="collect-metainfo" classname="org.d_haven.guiapp.tools.ComponentMetaInfoCollector"&gt;
  + *     &lt;classpath&gt;
  + *       &lt;path refid="project.class.path"/&gt;
  + *       &lt;pathelement path="${tools.dir}/guiapp-tools.jar"/&gt;
  + *     &lt;/classpath&gt;
  + *   &lt;/taskdef&gt;
  + *
  + *   &lt;taskdef name="collect-services" classname="org.d_haven.guiapp.tools.ServiceCollector"&gt;
  + *     &lt;classpath&gt;
  + *       &lt;path refid="project.class.path"/&gt;
  + *       &lt;pathelement path="${tools.dir}/guiapp-tools.jar"/&gt;
  + *     &lt;/classpath&gt;
  + *   &lt;/taskdef&gt;
  + *
  + *   &lt;collect-metainfo destdir="${build.classes}"&gt;
  + *      &lt;fileset dir="${src.dir}"/&gt;
  + *   &lt;/collect-metainfo&gt;
  + *
  + *   &lt;collect-services inputjar="${build.dir}/${name}-core.jar"
  + *                     outputjar="${lib.dir}/${name}.jar"/&gt;
  + * </pre>
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + */
  +public class ServiceRoleManager extends AbstractRoleManager implements Initializable
  +{
  +    /** Translate from scope to component handler */
  +    private static final Map m_lifecycleMap;
  +    /** Used to split words in class names */
  +    private static final Pattern upperCase = Pattern.compile( "([A-Z]+)" );
  +
  +    // Initialize the scope map
  +    static
  +    {
  +        Map lifecycleMap = new HashMap();
  +        lifecycleMap.put( "singleton", ThreadSafeComponentHandler.class.getName() );
  +        lifecycleMap.put( "thread", PerThreadComponentHandler.class.getName() );
  +        lifecycleMap.put( "pooled", PoolableComponentHandler.class.getName() );
  +        lifecycleMap.put( "transient", FactoryComponentHandler.class.getName() );
  +
  +        m_lifecycleMap = Collections.unmodifiableMap( lifecycleMap );
  +    }
  +
  +    /**
  +     * Create a ServiceRoleManager.
  +     */
  +    public ServiceRoleManager()
  +    {
  +        super( null );
  +    }
  +
  +    /**
  +     * Create a ServiceRoleManager with a parent RoleManager.
  +     *
  +     * @param parent
  +     */
  +    public ServiceRoleManager( RoleManager parent )
  +    {
  +        super( parent, null );
  +    }
  +
  +    /**
  +     * Create a ServiceRoleManager with the supplied classloader and
  +     * parent RoleManager.
  +     *
  +     * @param parent
  +     * @param loader
  +     */
  +    public ServiceRoleManager( RoleManager parent, ClassLoader loader )
  +    {
  +        super( parent, loader );
  +    }
  +
  +    /**
  +     * Convert a Component implmentation classname into a shorthand
  +     * name.  It assumes all classnames for a particular component is
  +     * unique.
  +     *
  +     * @param className  The classname of a component
  +     * @return String the short name
  +     */
  +    public static final String createShortName( String className )
  +    {
  +        Matcher matcher = upperCase.matcher( className.substring( className.lastIndexOf(
'.' ) + 1 ) );
  +        StringBuffer shortName = new StringBuffer();
  +
  +        while( matcher.find() )
  +        {
  +            if( shortName.length() == 0 )
  +            {
  +                matcher.appendReplacement( shortName, "$1" );
  +            }
  +            else
  +            {
  +                matcher.appendReplacement( shortName, "-$1" );
  +            }
  +        }
  +
  +        matcher.appendTail( shortName );
  +
  +        return shortName.toString().toLowerCase();
  +    }
  +
  +    /**
  +     * Initialize the ServiceRoleManager by looking at all the services and
  +     * classes available in the system.
  +     */
  +    public void initialize() throws Exception
  +    {
  +        Set services = new HashSet();
  +
  +        Enumeration enum = getLoader().getResources( "services.list" );
  +        while( enum.hasMoreElements() )
  +        {
  +            readEntries( services, (URL)enum.nextElement() );
  +        }
  +
  +        Iterator it = services.iterator();
  +        while( it.hasNext() )
  +        {
  +            String role = (String)it.next();
  +            getLogger().debug( "Adding service: " + role );
  +            try
  +            {
  +                setupImplementations( role );
  +            }
  +            catch( Exception e )
  +            {
  +                getLogger().debug( "Specified service '" + role + "' is not available",
e );
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Get all the implementations of a service and set up their meta
  +     * information.
  +     *
  +     * @param role
  +     */
  +    private void setupImplementations( String role )
  +        throws ClassNotFoundException
  +    {
  +        Iterator it = Service.providers( getLoader().loadClass( role ) );
  +
  +        while( it.hasNext() )
  +        {
  +            String impl = ( (Class)it.next() ).getName();
  +            getLogger().debug( "Reading meta info for " + impl );
  +            readMeta( role, impl );
  +        }
  +    }
  +
  +    /**
  +     * Read the meta information in and actually add the role.
  +     *
  +     * @param role
  +     * @param implementation
  +     */
  +    private void readMeta( String role, String implementation )
  +    {
  +        Properties meta = new Properties();
  +
  +        try
  +        {
  +            meta.load( getLoader().getResourceAsStream( translate( implementation ) ) );
  +        }
  +        catch( IOException ioe )
  +        {
  +            getLogger().error( "Could not load meta information for " +
  +                               implementation + ", skipping this class." );
  +            return;
  +        }
  +
  +        String shortName = meta.getProperty( "x-avalon.name", createShortName( implementation
) );
  +        String handler = getHandler( meta );
  +
  +        addRole( shortName, role, implementation, handler );
  +    }
  +
  +    /**
  +     * Get the name of the requested component handler.
  +     *
  +     * @param meta
  +     * @return String
  +     */
  +    private String getHandler( Properties meta )
  +    {
  +        String lifecycle = meta.getProperty( "x-avalon.lifestyle", null );
  +        String handler = null;
  +
  +        if( null != lifecycle )
  +        {
  +            handler = (String)m_lifecycleMap.get( lifecycle );
  +        }
  +        else
  +        {
  +            handler = meta.getProperty( "fortress.handler" );
  +        }
  +
  +        if( null == handler )
  +        {
  +            handler = PerThreadComponentHandler.class.getName();
  +        }
  +
  +        return handler;
  +    }
  +
  +    /**
  +     * Translate a class name into the meta file name.
  +     *
  +     * @param implementation
  +     * @return String
  +     */
  +    private String translate( String implementation )
  +    {
  +        String entry = implementation.replace( '.', '/' );
  +        entry += ".meta";
  +        return entry;
  +    }
  +
  +    /**
  +     * Read entries in a list file and add them all to the provided Set.
  +     *
  +     * @param entries
  +     * @param url
  +     */
  +    private void readEntries( Set entries, URL url )
  +        throws IOException
  +    {
  +        BufferedReader reader = new BufferedReader( new InputStreamReader( url.openStream()
) );
  +
  +        String entry = reader.readLine();
  +        while( entry != null )
  +        {
  +            entries.add( entry );
  +            entry = reader.readLine();
  +        }
  +
  +        reader.close();
  +    }
  +}
  
  
  
  1.13      +2 -2      avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/util/FortressConfig.java
  
  Index: FortressConfig.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/util/FortressConfig.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FortressConfig.java	11 Apr 2003 07:38:30 -0000	1.12
  +++ FortressConfig.java	11 Apr 2003 20:39:38 -0000	1.13
  @@ -134,7 +134,7 @@
           defaultContext.put( ClassLoader.class.getName(), classLoader );
           defaultContext.put( ContextManagerConstants.CONFIGURATION_URI, "conf/system.xconf"
);
           defaultContext.put( ContextManagerConstants.LOGGER_MANAGER_CONFIGURATION_URI, "conf/logkit.xconf"
);
  -        defaultContext.put( ContextManagerConstants.ROLE_MANAGER_CONFIGURATION_URI, "resource://ext/system.roles"
);
  +        //defaultContext.put( ContextManagerConstants.ROLE_MANAGER_CONFIGURATION_URI, "resource://ext/system.roles"
);
           defaultContext.put( ContextManagerConstants.ASSEMBLY_CONFIGURATION_URI, "resource://ext/assembly.xml"
);
   
           defaultContext.makeReadOnly();
  
  
  
  1.11      +1 -2      avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/HandlersTestCase.java
  
  Index: HandlersTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/HandlersTestCase.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HandlersTestCase.java	11 Apr 2003 07:37:57 -0000	1.10
  +++ HandlersTestCase.java	11 Apr 2003 20:39:38 -0000	1.11
  @@ -223,7 +223,6 @@
           final String BASE = "resource://org/apache/avalon/fortress/test/data/";
           config.setContainerConfiguration( BASE + "test1.xconf" );
           config.setLoggerManagerConfiguration( BASE + "test1.xlog" );
  -        //config.setRoleManagerConfiguration( BASE + "test1.roles" );
   
           final ContainerManager cm = new DefaultContainerManager( config.getContext() );
           ContainerUtil.initialize( cm );
  
  
  
  1.9       +2 -2      avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component1.java
  
  Index: Component1.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component1.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Component1.java	11 Apr 2003 07:37:57 -0000	1.8
  +++ Component1.java	11 Apr 2003 20:39:38 -0000	1.9
  @@ -52,7 +52,7 @@
   /**
    * @avalon.component
    * @avalon.service type=Role1
  - * @x-avalon.lifecycle type=singleton
  + * @x-avalon.lifestyle type=singleton
    * @x-avalon.info name=component1
    *
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
  
  
  
  1.9       +2 -2      avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component2.java
  
  Index: Component2.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component2.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Component2.java	11 Apr 2003 07:37:57 -0000	1.8
  +++ Component2.java	11 Apr 2003 20:39:38 -0000	1.9
  @@ -52,7 +52,7 @@
   /**
    * @avalon.component
    * @avalon.service type=org.apache.avalon.fortress.test.data.Role2
  - * @x-avalon.lifecycle type=pooled
  + * @x-avalon.lifestyle type=pooled
    * @x-avalon.info name=component2
    *
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
  
  
  
  1.9       +3 -2      avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component3.java
  
  Index: Component3.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component3.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Component3.java	11 Apr 2003 07:37:57 -0000	1.8
  +++ Component3.java	11 Apr 2003 20:39:38 -0000	1.9
  @@ -51,7 +51,8 @@
   
   /**
    * @avalon.component
  - * @x-avalon.lifecycle type=thread
  + * @avalon.service type=Role3
  + * @x-avalon.lifestyle type=thread
    * @x-avalon.info name=component3
    *
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
  
  
  
  1.9       +4 -2      avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component4.java
  
  Index: Component4.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component4.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Component4.java	11 Apr 2003 07:37:58 -0000	1.8
  +++ Component4.java	11 Apr 2003 20:39:38 -0000	1.9
  @@ -51,7 +51,9 @@
   
   /**
    * @avalon.component
  - * @x-avalon.lifecycle type=transient
  + *
  + * @avalon.service type=Role4
  + * @x-avalon.lifestyle type=transient
    * @x-avalon.info name=component4
    *
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
  
  
  
  1.8       +1 -3      avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Role3.java
  
  Index: Role3.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Role3.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Role3.java	11 Apr 2003 07:37:58 -0000	1.7
  +++ Role3.java	11 Apr 2003 20:39:38 -0000	1.8
  @@ -50,8 +50,6 @@
   package org.apache.avalon.fortress.test.data;
   
   /**
  - * @x-avalon.role
  - *
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
    * @version $Revision$ $Date$
    */
  
  
  
  1.8       +1 -3      avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Role4.java
  
  Index: Role4.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Role4.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Role4.java	11 Apr 2003 07:37:58 -0000	1.7
  +++ Role4.java	11 Apr 2003 20:39:38 -0000	1.8
  @@ -50,8 +50,6 @@
   package org.apache.avalon.fortress.test.data;
   
   /**
  - * @x-avalon.role
  - *
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
    * @version $Revision$ $Date$
    */
  
  
  
  1.2       +2 -2      avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/test1.xlog
  
  Index: test1.xlog
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/test1.xlog,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- test1.xlog	27 Jan 2003 17:04:48 -0000	1.1
  +++ test1.xlog	11 Apr 2003 20:39:38 -0000	1.2
  @@ -13,10 +13,10 @@
       </targets>
   
       <categories>
  -        <category name="test" log-level="INFO">
  +        <category name="fortress" log-level="DEBUG">
               <log-target id-ref="root"/>
           </category>
  -        <category name="" log-level="INFO">
  +        <category name="" log-level="DEBUG">
               <log-target id-ref="root"/>
           </category>
       </categories>
  
  
  
  1.14      +15 -88    avalon-excalibur/fortress/src/tools/org/apache/avalon/fortress/tools/ComponentMetaInfoCollector.java
  
  Index: ComponentMetaInfoCollector.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/tools/org/apache/avalon/fortress/tools/ComponentMetaInfoCollector.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ComponentMetaInfoCollector.java	11 Apr 2003 07:37:00 -0000	1.13
  +++ ComponentMetaInfoCollector.java	11 Apr 2003 20:39:39 -0000	1.14
  @@ -58,16 +58,13 @@
   import com.thoughtworks.qdox.model.DocletTag;
   import com.thoughtworks.qdox.model.JavaClass;
   import com.thoughtworks.qdox.model.Type;
  -import java.io.BufferedReader;
   import java.io.File;
   import java.io.FileWriter;
   import java.io.IOException;
  -import java.io.InputStreamReader;
   import java.io.PrintWriter;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.net.URLClassLoader;
  -import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  @@ -123,19 +120,13 @@
   
           try
           {
  -            ClassLoader loader = Thread.currentThread().getContextClassLoader();
  -            Thread.currentThread().setContextClassLoader( getClassLoader() );
  -
               collectInfoMetaData();
               writeComponents();
   
               writeServiceList( m_services.values().iterator() );
   
               log( "Collecting service information." );
  -            collectClassLoaderServices( loader );
               writeServices();
  -
  -            Thread.currentThread().setContextClassLoader( loader );
           }
           catch( final Exception e )
           {
  @@ -213,14 +204,8 @@
           while( it.hasNext() )
           {
               final JavaClass javaClass = (JavaClass)it.next();
  -            DocletTag tag = javaClass.getTagByName( "x-avalon.role" );
  -            if( null != tag )
  -            {
  -                Service service = new Service( javaClass.getFullyQualifiedName(), true
);
  -                m_services.put( service.getType(), service );
  -            }
  +            DocletTag tag = javaClass.getTagByName( "avalon.component" );
   
  -            tag = javaClass.getTagByName( "avalon.component" );
               if( null != tag )
               {
                   Component comp = new Component( javaClass.getFullyQualifiedName() );
  @@ -233,7 +218,7 @@
                       service.addComponent( comp );
                   }
   
  -                DocletTag avalonLifecycle = javaClass.getTagByName( "x-avalon.lifecycle"
);
  +                DocletTag avalonLifecycle = javaClass.getTagByName( "x-avalon.lifestyle"
);
                   DocletTag fortressHandler = javaClass.getTagByName( "fortress.handler"
);
                   String lifecycle = null;
                   String handler = null;
  @@ -268,7 +253,7 @@
                       handler = ( null == fortressHandler ) ? PerThreadComponentHandler.class.getName()
: fortressHandler.getNamedParameter( "type" );
                   }
   
  -                if( null != lifecycle ) comp.setAttribute( "x-avalon.lifecycle", lifecycle
);
  +                if( null != lifecycle ) comp.setAttribute( "x-avalon.lifestyle", lifecycle
);
                   if( null != handler ) comp.setAttribute( "fortress.handler", handler );
   
                   DocletTag avalonConfigName = javaClass.getTagByName( "x-avalon.info" );
  @@ -290,37 +275,21 @@
               if( className.indexOf( '.' ) < 0 )
               {
                   int classLen = className.length();
  -                className = resolveDeepClassName( javaClass, className, classLen );
  -            }
  -        }
  -
  -        return className;
  -    }
  -
  -    private String resolveDeepClassName( final JavaClass javaClass, final String className,
final int classLen )
  -    {
  -        // Stop at java.lang.Object
  -        if( javaClass.getFullyQualifiedName().equals( "java.lang.Object" ) ) return className;
  -
  -        String serviceClass = null;
  -        Type[] types = javaClass.getImplements();
  -        for( int t = 0; t < types.length; t++ )
  -        {
  -            String type = types[ t ].getValue();
  -            int typeLen = type.length();
  +                Type[] types = javaClass.getImplements();
  +                for( int t = 0; t < types.length; t++ )
  +                {
  +                    String type = types[ t ].getValue();
  +                    int index = type.lastIndexOf('.') + 1;
   
  -            if( type.substring( typeLen - classLen ).equals( className ) )
  -            {
  -                serviceClass = type;
  +                    if( type.substring( index ).equals( className ) )
  +                    {
  +                        className = type;
  +                    }
  +                }
               }
           }
   
  -        if( serviceClass == null )
  -        {
  -            serviceClass = resolveDeepClassName( javaClass.getSuperJavaClass(), className,
classLen );
  -        }
  -
  -        return serviceClass;
  +        return className;
       }
   
       private Service getService( final String type ) throws ClassNotFoundException
  @@ -329,7 +298,7 @@
   
           if( null == service )
           {
  -            service = new Service( type, false );
  +            service = new Service( type );
               m_services.put( service.getType(), service );
           }
   
  @@ -337,17 +306,6 @@
       }
   
       /**
  -     * Return the classloader used to determine the services info.
  -     *
  -     * @return URLClassLoader
  -     */
  -    private ClassLoader getClassLoader() throws MalformedURLException
  -    {
  -        final URL[] urls = new URL[]{m_destDir.toURL()};
  -        return new URLClassLoader( urls, getClass().getClassLoader() );
  -    }
  -
  -    /**
        * Collect all the services and write out the implementations.
        */
       private void writeServices()
  @@ -368,37 +326,6 @@
               catch( Exception e )
               {
                   log( "Could not save information for service " + service.getType(), Project.MSG_WARN
);
  -            }
  -        }
  -    }
  -
  -    /**
  -     *
  -     */
  -    private void collectClassLoaderServices( ClassLoader loader )
  -        throws IOException
  -    {
  -        Enumeration enum = loader.getResources( "services.list" );
  -        while( enum.hasMoreElements() )
  -        {
  -            URL entry = (URL)enum.nextElement();
  -            BufferedReader reader = new BufferedReader(
  -                new InputStreamReader( entry.openStream() ) );
  -            String line;
  -
  -            while( ( line = reader.readLine() ) != null )
  -            {
  -                if( line.trim().length() > 0 )
  -                {
  -                    try
  -                    {
  -                        m_services.put( line, new Service( line, true ) );
  -                    }
  -                    catch( ClassNotFoundException cnfe )
  -                    {
  -                        log( "Could not collect components for service " + line, Project.MSG_WARN
);
  -                    }
  -                }
               }
           }
       }
  
  
  
  1.4       +4 -34     avalon-excalibur/fortress/src/tools/org/apache/avalon/fortress/tools/Service.java
  
  Index: Service.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/tools/org/apache/avalon/fortress/tools/Service.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Service.java	11 Apr 2003 07:37:08 -0000	1.3
  +++ Service.java	11 Apr 2003 20:39:39 -0000	1.4
  @@ -68,34 +68,26 @@
    */
   final class Service
   {
  -    private ClassLoader m_loader;
  -
       private final Set m_components;
   
  -    private final Class m_type;
  -
  -    private boolean m_isRole;
  -    private boolean m_areRolesCollected;
  +    private final String m_type;
   
       /**
        * Initialize a service with the type name.
        *
        * @param type
        */
  -    public Service( final String type, boolean isRole ) throws ClassNotFoundException
  +    public Service( final String type ) throws ClassNotFoundException
       {
           if( type == null ) throw new NullPointerException( "type" );
   
  -        m_loader = Thread.currentThread().getContextClassLoader();
  -        m_type = m_loader.loadClass( type );
  +        m_type = type;
           m_components = new HashSet();
  -        m_isRole = isRole;
  -        m_areRolesCollected = false;
       }
   
       public String getType()
       {
  -        return m_type.getName();
  +        return m_type;
       }
   
       public void addComponent( final Component type )
  @@ -113,8 +105,6 @@
        */
       public void serialize( final File rootDir ) throws IOException, ClassNotFoundException
       {
  -        collectComponents();
  -
           if( m_components.isEmpty() ) return;
   
           File serviceFile = new File( rootDir, "META-INF/services/" + getType() );
  @@ -136,26 +126,6 @@
               if( null != writer )
               {
                   writer.close();
  -            }
  -        }
  -    }
  -
  -    /**
  -     *
  -     */
  -    private void collectComponents() throws ClassNotFoundException
  -    {
  -        if( ( !m_isRole ) || m_areRolesCollected ) return;
  -
  -        Iterator it = Component.m_repository.iterator();
  -        while( it.hasNext() )
  -        {
  -            Component comp = (Component)it.next();
  -            Class component = m_loader.loadClass( comp.getType() );
  -
  -            if( m_type.isAssignableFrom( component ) )
  -            {
  -                addComponent( comp );
               }
           }
       }
  
  
  

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


Mime
View raw message