You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by pr...@apache.org on 2002/08/08 16:21:16 UTC

cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress AbstractContainer.java

proyal      2002/08/08 07:21:16

  Modified:    fortress/src/java/org/apache/excalibur/fortress/container
                        DefaultContainer.java
               fortress/src/java/org/apache/excalibur/fortress
                        AbstractContainer.java
  Log:
  Added getServiceManager() to DefaultContainer
  
  Revision  Changes    Path
  1.5       +195 -190  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/DefaultContainer.java
  
  Index: DefaultContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/DefaultContainer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultContainer.java	7 Aug 2002 19:20:36 -0000	1.4
  +++ DefaultContainer.java	8 Aug 2002 14:21:16 -0000	1.5
  @@ -1,190 +1,195 @@
  -/*
  -
  - ============================================================================
  -                   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.container;
  -
  -import org.apache.excalibur.fortress.AbstractContainer;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.configuration.DefaultConfiguration;
  -import org.apache.avalon.framework.component.ComponentManager;
  -
  -/**
  - * This is the default container, and it marks the default markup for
  - * configurations.
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
  - * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
  - * @version CVS $Revision$ $Date$
  - */
  -public class DefaultContainer
  -    extends AbstractContainer
  -    implements Configurable
  -{
  -    /**
  -     * <p>Process the configuration and set up the components and their
  -     * mappings. At this point, all components are prepared and all mappings
  -     * are made. However, nothing is initialized.</p>
  -     *
  -     * <p>The native Configuration format follows a specific convention.  If
  -     * you use a RoleManager to map roles and implementations to more helpful
  -     * names, we will internally rewrite the configuration to match this
  -     * format.  Please note: If a configuration element does
  -     * <strong>not</strong> have a unique id, it will not be treated as a
  -     * Component.  That ID is used as the hint when there is more than one
  -     * implementation of a role.</p>
  -     *
  -     * <pre>
  -     *   &lt;component role="org.apache.avalon.excalibur.datasource.DataSourceComponent"
  -     *                 id="default-connection"
  -     *                 class="org.apache.avalon.excalibur.datasource.JdbcDataSourceComponent"
  -     *                 handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler"&gt;
  -     *
  -     *    &lt;!-- Component specific configuration --&gt;
  -     *
  -     *  &lt;/component&gt;
  -     * </pre>
  -     *
  -     * @param configElement  The configuration element to translate into the
  -     *                       list of components this container managers.
  -     *
  -     * @throws ConfigurationException if the configuration is not valid
  -     */
  -    public void configure( Configuration configElement )
  -        throws ConfigurationException
  -    {
  -        m_configuration = configElement;
  -
  -        Configuration elements[] = configElement.getChildren();
  -
  -        for( int i = 0; i < elements.length; i++ )
  -        {
  -            Configuration component = null;
  -            Object hint = elements[ i ].getAttribute( "id", null );
  -
  -            if( null != hint )
  -            {
  -                if( "component".equals( elements[ i ].getName() ) )
  -                {
  -                    component = elements[ i ];
  -                }
  -                else
  -                {
  -                    component = rewriteConfiguration( elements[ i ] );
  -                }
  -
  -                addComponent( component, hint );
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Handles when a configuration name is used that is not "component", so
  -     * it makes it easier to handle ComponentSelector hierarchies.  It is
  -     * meant to either return a ComponentHandler or a ServiceSelector.
  -     *
  -     * @param configItem  The configuration snippet to translate into the
  -     *                    standard format.
  -     *
  -     * @return <code>Configuration</code> representing the native format.
  -     *
  -     * @throws ConfigurationException  if the configuration is invalid
  -     */
  -    protected Configuration rewriteConfiguration( final Configuration configItem )
  -        throws ConfigurationException
  -    {
  -        DefaultConfiguration temp =
  -          new DefaultConfiguration( "component",
  -                                    "AbstractContainer-rewrite [name: " + configItem.getName()
  -                                    + ", location: " + configItem.getLocation() + "]" );
  -
  -        Class klass = m_roleManager.getClassForName( configItem.getName() );
  -        Class handlerKlass = m_roleManager.getHandlerClassForClass( klass );
  -        String role = m_roleManager.getRoleForClass( klass );
  -
  -        if( null == klass )
  -        {
  -            throw new ConfigurationException( "No class found matching configuration name "
  -                                              + "[name: " + configItem.getName()
  -                                              + ", location: " + configItem.getLocation() + "]" );
  -        }
  -
  -        //We set these before copying all other attributes so the class / handler can be overriden if needed if
  -        //the shorthand name is used
  -        temp.setAttribute( "role", role );
  -        temp.setAttribute( "class", klass.getName() );
  -        temp.setAttribute( "handler", handlerKlass.getName() );
  -
  -        temp.setValue( configItem.getValue( null ) );
  -
  -        String[] attributes = configItem.getAttributeNames();
  -        for( int i = 0; i < attributes.length; i++ )
  -        {
  -            temp.setAttribute( attributes[i], configItem.getAttribute( attributes[i] ) );
  -        }
  -
  -        Configuration[] children = configItem.getChildren();
  -        for( int i = 0; i < children.length; i++ )
  -        {
  -            temp.addChild( children[ i ] );
  -        }
  -
  -        temp.makeReadOnly();
  -
  -        return temp;
  -    }
  -
  -    public ComponentManager getComponentManager()
  -    {
  -        return super.getComponentManager();
  -    }
  -}
  -
  +/*
  +
  + ============================================================================
  +                   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.container;
  +
  +import org.apache.excalibur.fortress.AbstractContainer;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.configuration.DefaultConfiguration;
  +import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.service.ServiceManager;
  +
  +/**
  + * This is the default container, and it marks the default markup for
  + * configurations.
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
  + * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
  + * @version CVS $Revision$ $Date$
  + */
  +public class DefaultContainer
  +    extends AbstractContainer
  +    implements Configurable
  +{
  +    /**
  +     * <p>Process the configuration and set up the components and their
  +     * mappings. At this point, all components are prepared and all mappings
  +     * are made. However, nothing is initialized.</p>
  +     *
  +     * <p>The native Configuration format follows a specific convention.  If
  +     * you use a RoleManager to map roles and implementations to more helpful
  +     * names, we will internally rewrite the configuration to match this
  +     * format.  Please note: If a configuration element does
  +     * <strong>not</strong> have a unique id, it will not be treated as a
  +     * Component.  That ID is used as the hint when there is more than one
  +     * implementation of a role.</p>
  +     *
  +     * <pre>
  +     *   &lt;component role="org.apache.avalon.excalibur.datasource.DataSourceComponent"
  +     *                 id="default-connection"
  +     *                 class="org.apache.avalon.excalibur.datasource.JdbcDataSourceComponent"
  +     *                 handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler"&gt;
  +     *
  +     *    &lt;!-- Component specific configuration --&gt;
  +     *
  +     *  &lt;/component&gt;
  +     * </pre>
  +     *
  +     * @param configElement  The configuration element to translate into the
  +     *                       list of components this container managers.
  +     *
  +     * @throws ConfigurationException if the configuration is not valid
  +     */
  +    public void configure( Configuration configElement )
  +        throws ConfigurationException
  +    {
  +        m_configuration = configElement;
  +
  +        Configuration elements[] = configElement.getChildren();
  +
  +        for( int i = 0; i < elements.length; i++ )
  +        {
  +            Configuration component = null;
  +            Object hint = elements[ i ].getAttribute( "id", null );
  +
  +            if( null != hint )
  +            {
  +                if( "component".equals( elements[ i ].getName() ) )
  +                {
  +                    component = elements[ i ];
  +                }
  +                else
  +                {
  +                    component = rewriteConfiguration( elements[ i ] );
  +                }
  +
  +                addComponent( component, hint );
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Handles when a configuration name is used that is not "component", so
  +     * it makes it easier to handle ComponentSelector hierarchies.  It is
  +     * meant to either return a ComponentHandler or a ServiceSelector.
  +     *
  +     * @param configItem  The configuration snippet to translate into the
  +     *                    standard format.
  +     *
  +     * @return <code>Configuration</code> representing the native format.
  +     *
  +     * @throws ConfigurationException  if the configuration is invalid
  +     */
  +    protected Configuration rewriteConfiguration( final Configuration configItem )
  +        throws ConfigurationException
  +    {
  +        DefaultConfiguration temp =
  +          new DefaultConfiguration( "component",
  +                                    "AbstractContainer-rewrite [name: " + configItem.getName()
  +                                    + ", location: " + configItem.getLocation() + "]" );
  +
  +        Class klass = m_roleManager.getClassForName( configItem.getName() );
  +        Class handlerKlass = m_roleManager.getHandlerClassForClass( klass );
  +        String role = m_roleManager.getRoleForClass( klass );
  +
  +        if( null == klass )
  +        {
  +            throw new ConfigurationException( "No class found matching configuration name "
  +                                              + "[name: " + configItem.getName()
  +                                              + ", location: " + configItem.getLocation() + "]" );
  +        }
  +
  +        //We set these before copying all other attributes so the class / handler can be overriden if needed if
  +        //the shorthand name is used
  +        temp.setAttribute( "role", role );
  +        temp.setAttribute( "class", klass.getName() );
  +        temp.setAttribute( "handler", handlerKlass.getName() );
  +
  +        temp.setValue( configItem.getValue( null ) );
  +
  +        String[] attributes = configItem.getAttributeNames();
  +        for( int i = 0; i < attributes.length; i++ )
  +        {
  +            temp.setAttribute( attributes[i], configItem.getAttribute( attributes[i] ) );
  +        }
  +
  +        Configuration[] children = configItem.getChildren();
  +        for( int i = 0; i < children.length; i++ )
  +        {
  +            temp.addChild( children[ i ] );
  +        }
  +
  +        temp.makeReadOnly();
  +
  +        return temp;
  +    }
  +
  +    public ComponentManager getComponentManager()
  +    {
  +        return super.getComponentManager();
  +    }
  +
  +    public ServiceManager getServiceManager()
  +    {
  +        return super.getServiceManager();
  +    }
  +}
  
  
  
  1.55      +2 -2      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- AbstractContainer.java	7 Aug 2002 04:55:55 -0000	1.54
  +++ AbstractContainer.java	8 Aug 2002 14:21:16 -0000	1.55
  @@ -534,7 +534,7 @@
        *
        * @return the child component manager
        */
  -    protected final ServiceManager getServiceManager()
  +    protected ServiceManager getServiceManager()
       {
           return m_serviceManager;
       }
  
  
  

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