avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/datasource DefaultDataSourceSelector-schema.xml DefaultDataSourceSelector.java
Date Tue, 10 Sep 2002 10:24:28 GMT
donaldp     2002/09/10 03:24:28

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/datasource
                        DefaultDataSourceSelector-schema.xml
                        DefaultDataSourceSelector.java
  Log:
  Removed one layer from configuration so it is easier to use.
  
  Submitted by: Greg Steuck <greg-avalon-apps@nest.cx>
  
  Revision  Changes    Path
  1.3       +3 -0      jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/datasource/DefaultDataSourceSelector-schema.xml
  
  Index: DefaultDataSourceSelector-schema.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/datasource/DefaultDataSourceSelector-schema.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultDataSourceSelector-schema.xml	16 Jul 2002 18:09:40 -0000	1.2
  +++ DefaultDataSourceSelector-schema.xml	10 Sep 2002 10:24:28 -0000	1.3
  @@ -11,6 +11,9 @@
                       <ref name="datasource"/>
                   </oneOrMore>
               </element>
  +            <oneOrMore>
  +                <ref name="datasource"/>
  +            </oneOrMore>
           </element>
       </start>
   
  
  
  
  1.24      +37 -6     jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/datasource/DefaultDataSourceSelector.java
  
  Index: DefaultDataSourceSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/datasource/DefaultDataSourceSelector.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- DefaultDataSourceSelector.java	17 Aug 2002 02:24:24 -0000	1.23
  +++ DefaultDataSourceSelector.java	10 Sep 2002 10:24:28 -0000	1.24
  @@ -20,13 +20,17 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.logger.LogEnabled;
  +import org.apache.avalon.framework.context.Contextualizable;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.phoenix.BlockContext;
   
   /**
    * The Default implementation for DataSourceSelector.
    * The Configuration is like this:
    *
    * <pre>
  - * &lt;data-sources&gt;
  + * &lt;myBlock&gt;
    *   &lt;data-source name="<i>default</i>"
    *     class="<i>org.apache.avalon.excalibur.datasource.JdbcDataSource</i>"&gt;
    *     &lt;!-- configuration for JdbcDataSource --&gt;
  @@ -38,7 +42,7 @@
    *     &lt;user&gt;<i>username</i>&lt;/user&gt;
    *     &lt;password&gt;<i>password</i>&lt;/password&gt;
    *   &lt;/data-source&gt;
  - * &lt;/data-sources&gt;
  + * &lt;/myBlock&gt;
    * </pre>
    *
    * @phoenix:block
  @@ -48,10 +52,17 @@
    */
   public class DefaultDataSourceSelector
       extends AbstractLogEnabled
  -    implements DataSourceSelector, Configurable, Initializable, Disposable
  +    implements DataSourceSelector, Contextualizable, Configurable, Initializable, Disposable
   {
       private Configuration m_configuration;
       private Map m_dataSources;
  +    private BlockContext m_context;
  +
  +    public void contextualize( final Context context )
  +        throws ContextException
  +    {
  +        m_context = (BlockContext)context;
  +    }
   
       /**
        * @phoenix:configuration-schema type="relax-ng"
  @@ -66,8 +77,7 @@
       {
           m_dataSources = new HashMap();
   
  -        final Configuration[] dataSourceConfs =
  -            m_configuration.getChild( "data-sources" ).getChildren( "data-source" );
  +        Configuration[] dataSourceConfs = getDataSourceConfig();
   
           for( int i = 0; i < dataSourceConfs.length; i++ )
           {
  @@ -114,6 +124,27 @@
           }
       }
   
  +    private Configuration[] getDataSourceConfig()
  +    {
  +        final Configuration head =
  +            m_configuration.getChild( "data-sources" );
  +        if( 0 != head.getChildren().length )
  +        {
  +            final String message =
  +                "WARNING: Child node <data-sources/> in " +
  +                "configuration of component named " + m_context.getName() +
  +                " has been deprecated. Please put <data-source/> elements" +
  +                " in root configuration element";
  +            getLogger().warn( message );
  +            System.out.println( message );
  +            return head.getChildren( "data-source" );
  +        }
  +        else
  +        {
  +            return m_configuration.getChildren( "data-source" );
  +        }
  +    }
  +
       public void dispose()
       {
           final Iterator keys = m_dataSources.keySet().iterator();
  @@ -123,7 +154,7 @@
                   (DataSourceComponent)m_dataSources.get( keys.next() );
               if( dsc instanceof Disposable )
               {
  -                ( (Disposable)dsc ).dispose();
  +                ((Disposable)dsc).dispose();
               }
           }
       }
  
  
  

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


Mime
View raw message