bloritsch    2002/12/24 11:44:58

  Added:       datasource .cvsignore WARNING.txt ant.properties.sample
                        build.xml default.properties
               datasource/lib DO-NOT-DELETE.txt
               datasource/src/java/org/apache/excalibur/datasource
                        DataSourceManager.java
               datasource/src/java/org/apache/excalibur/datasource/impl
                        ApacheConnectionPoolDataSource.java
                        SimpleDataSourceManager.java
               datasource/src/java/org/apache/excalibur/datasource/util
                        BeanUtil.java
               datasource/src/test/org/apache/excalibur/datasource/impl/test
                        SimpleDataSourceManagerTest.java
               datasource/src/test/org/apache/excalibur/datasource/util/test
                        BeanUtilTest.java
               datasource/src/xdocs index.xml menu.xml
  Log:
  add initial cut at new DataSource component.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/datasource/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  ant.properties
  build
  checkstyle.cache
  distributions
  dist
  excalibur-*
  velocity.log*
  *.el
  *.ipr
  
  
  
  1.1                  avalon-sandbox/datasource/WARNING.txt
  
  Index: WARNING.txt
  ===================================================================
  *****************************  W A R N I N G  **********************************
  
    All user accessible points in this software package are to be considered
    "alpha". This means that the developer team is not investing _any_ effort
    in providing back compatibility between alpha releases.
    
    This software will continue to be released as "alpha" until both code, 
    schemas and APIs will be considered stable.
    
    Until then, there will be no warranty that newer versions will maintain back
    compatibility even in the most simple cases.
    
    On the other hand, once "beta" status is reached, back incompatible changes
    will be made only if absolutely necessary to reach "final" status.
    
    The Avalon development team understands the importance of reliable
    software as well as the importance of protecting user investiments by the
    creation of a solid development platform that doesn't change.
  
    On the other hand, being the Avalon project a pioneer in many fields, this
    cannot be guaranteed before a final status is reached for the software.
    
    Until then, no effort will be provided to guarantee back compatibility.
    
    You have been warned.
  
  *****************************  W A R N I N G  **********************************
  
  
  
  
  1.1                  avalon-sandbox/datasource/ant.properties.sample
  
  Index: ant.properties.sample
  ===================================================================
  # -----------------------------------------------------------------------------
  # Component ant.properties.sample
  #
  # This is an example "ant.properties" file, used to customize the building of
  # the component for your local environment.  It defines the location of all
  # external modules that this component depend on.  Copy this file to
  # "ant.properties" in the source directory, and customize it as needed.
  #
  # The ant.properties values in this directory apply only to this component.
  # It is overridden by ../ant.properties and ~/build.properties
  # It overrides all default.properties files and ~/.ant.properties
  #
  # $Id: ant.properties.sample,v 1.1 2002/12/24 19:44:57 bloritsch Exp $
  # -----------------------------------------------------------------------------
  
  # ----- Compile Control Flags -----
  build.debug=on
  build.optimize=off
  build.deprecation=off
  #build.compiler=jikes
  
  # ----- Base Directory in which all the packages are stored -----
  base.path=${basedir}/../..
  
  # --------------------------------------------------
  #                REQUIRED LIBRARIES
  # --------------------------------------------------
  
  
  
  # --------------------------------------------------
  #                OPTIONAL LIBRARIES
  # --------------------------------------------------
  
  # ----- JUnit Unit Test Suite, version 3.7 or later. -----
  #  Not needed if junit.jar is in $ANT_HOME/lib 
  junit.home=${base.path}/junit3.7
  junit.lib=${junit.home}
  junit.jar=${junit.lib}/junit.jar
  
  
  # ----- Checkstyle, version 2.1 or later -----
  # Uncomment the 'do.checkstyle' flag property to enable checkstyle
  # do.checkstyle=
  checkstyle.home=${base.path}/checkstyle-2.1
  checkstyle.lib=${checkstyle.home}
  checkstyle.jar=${checkstyle.lib}/checkstyle-all-2.1.jar
  
  
  
  1.1                  avalon-sandbox/datasource/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <project name="Excalibur Info" default="main" basedir=".">
  
      <property file="${user.home}/build.properties"/>
      <property file="${basedir}/../ant.properties"/>
      <property file="${basedir}/ant.properties"/>
      <property file="${user.home}/.ant.properties"/>
      <property file="${basedir}/../default.properties"/>
      <property file="${basedir}/default.properties"/>
  
      <!-- Classpath for product -->
      <path id="project.class.path">
          <pathelement location="${build.classes}"/>
          <pathelement location="${avalon-framework.jar}"/>
          <pathelement location="${excalibur-i18n.jar}"/>
          <pathelement location="${checkstyle.jar}"/>
          <pathelement location="${xml-apis.jar}"/>
          <pathelement path="${java.class.path}"/>
          <fileset dir="lib" includes="**/*.jar"/>
      </path>
  
      <path id="tools.class.path">
          <pathelement location="${junit.jar}"/>
          <fileset dir="${jakarta-site.dir}/lib"/>
      </path>
  
      <path id="test.class.path">
          <pathelement location="${build.testclasses}"/>
          <pathelement location="${junit.jar}"/>
          <path refid="project.class.path"/>
      </path>
      <property name="cp" refid="test.class.path"/>
  
      <target name="main" depends="jar" description="Build the project"/>
      <target name="rebuild" depends="clean,main" description="Rebuild the project"/>
  
      <target name="dependencies" description="Check dependencies" 
unless="skip.dependencies">
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkCommon"/>
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkFramework"/>
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkI18N"/>
      </target>
  
      <target name="dependencies-test" depends="dist-jar, dependencies"
          description="Check unit test dependencies" unless="skip.dependencies">
          <!-- Need the jar to prevent recursive deps. -->
  
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkJUnit"/>
      </target>
  
  
      <!-- Compiles the source code -->
      <target name="compile" depends="dependencies" description="Compiles the source 
code">
  
          <mkdir dir="${build.classes}"/>
  
          <!-- Compile all classes excluding the tests. -->
          <javac srcdir="${java.dir}"
              destdir="${build.classes}"
              debug="${build.debug}"
              optimize="${build.optimize}"
              deprecation="${build.deprecation}"
              target="1.2">
              <classpath refid="project.class.path" />
              <include name="**/*.java"/>
          </javac>
  
          <!-- copy resources to same location as .class files -->
          <copy todir="${build.classes}">
              <fileset dir="${java.dir}">
                  <exclude name="**/*.java"/>
                  <exclude name="**/package.html"/>
              </fileset>
          </copy>
  
      </target>
  
      <!-- Compiles the unit test source code -->
      <target name="compile-test" depends="compile, dependencies-test" 
description="Compiles the source code">
          <mkdir dir="${build.testsrc}"/>
  
          <!-- Copy over all of the tests applying test filters -->
          <copy todir="${build.testsrc}">
              <fileset dir="${test.dir}"/>
          </copy>
  
          <mkdir dir="${build.testclasses}"/>
  
          <!-- Compile all test classes. -->
          <javac srcdir="${build.testsrc}"
              destdir="${build.testclasses}"
              debug="${build.debug}"
              optimize="${build.optimize}"
              deprecation="${build.deprecation}"
              target="1.2">
              <classpath refid="test.class.path" />
              <include name="**/*.java"/>
          </javac>
  
          <!-- copy the java source files across so we can read them in for tests -->
          <copy todir="${build.testclasses}">
              <fileset dir="${test.dir}">
                  <include name="**/data/**/*.java"/>
              </fileset>
          </copy>
  
          <copy todir="${build.testclasses}">
              <fileset dir="${test.dir}">
                  <exclude name="**/*.java"/>
                  <exclude name="**/package.html"/>
              </fileset>
          </copy>
  
      </target>
  
      <!-- Copies and filters the license. Used by jar and dist -->
      <target name="prepare-conf">
          <mkdir dir="${build.conf}"/>
          <copy todir="${build.conf}" flatten="true">
              <fileset dir="../" includes="LICENSE.txt"/>
              <filterset>
                  <filter token="year" value="${year}"/>
              </filterset>
          </copy>
      </target>
  
      <!-- Creates all the .jar file -->
      <target name="jar" depends="compile, prepare-conf" description="Generates the 
jar files">
  
          <mkdir dir="${build.lib}"/>
  
          <jar jarfile="${build.lib}/${jar.name}"
              basedir="${build.classes}"
              compress="${build.compress}">
              <manifest>
                  <attribute name="Extension-Name" value="${name}"/>
                  <attribute name="Specification-Vendor" value="Apache Software 
Foundation"/>
                  <attribute name="Specification-Version" value="1.0"/>
                  <attribute name="Implementation-Vendor" value="Apache Software 
Foundation"/>
                  <attribute name="Implementation-Version" value="${package-version}"/>
              </manifest>
              <exclude name="**/test/**"/>
              <zipfileset dir="${build.conf}" prefix="META-INF/">
                  <include name="LICENSE.txt"/>
              </zipfileset>
          </jar>
      </target>
  
      <!-- Creates all the Javadocs -->
      <target name="javadocs" depends="compile" description="Generates the javadocs" 
unless="skip.javadocs">
  
          <mkdir dir="${dist.javadocs}"/>
          <javadoc packagenames="org.apache.*"
              sourcepath="${java.dir}"
              destdir="${dist.javadocs}">
              <classpath refid="project.class.path" />
              <group title="Info API" packages="org.apache.avalon.framework.info.*" />
              <group title="Info Tools API" 
packages="org.apache.avalon.framework.tools.*" />
              <tag name="todo" description="To do:" scope="all" />
              <tag name="avalon.component" enabled="false" description="Component:" 
scope="types" />
              <tag name="avalon.service" enabled="false" description="Service:" 
scope="types" />
              <tag name="avalon.context" enabled="false" description="Context:" 
scope="methods" />
              <tag name="avalon.entry" enabled="false" description="Context:" 
scope="methods" />
              <tag name="avalon.dependency" enabled="false" description="Context:" 
scope="methods" />
              <doclet name="com.sun.tools.doclets.standard.Standard">
                  <param name="-author"/>
                  <param name="-version"/>
                  <param name="-doctitle" value="${Name}"/>
                  <param name="-windowtitle" value="${Name} API"/>
                  <param name="-link" value="http://java.sun.com/j2se/1.4/docs/api/"/>
                  <param name="-link" 
value="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/"/>
                  <param name="-link" value="http://jakarta.apache.org/avalon/api/"/>
                  <param name="-bottom"
                      value="&quot;Copyright &#169; ${year} Apache Jakarta Project. 
All Rights Reserved.&quot;"/>
              </doclet>
  
          </javadoc>
      </target>
  
      <target name="test" depends="compile-test" description="Perform the unit tests" 
unless="skip.tests">
  
          <echo message="Performing Unit Tests" />
  
          <mkdir dir="${build.tests}"/>
  
          <junit fork="true"
              haltonfailure="${junit.failonerror}"
              printsummary="yes"
              dir="${build.tests}">
              <classpath refid="test.class.path"/>
  
              <formatter type="xml"/>    <!-- xml reports for junitreport -->
              <formatter type="plain" usefile="false"/>  <!-- text reports for humans  
   -->
  
              <batchtest todir="${build.tests}">
                  <fileset dir="${build.testclasses}">
                      <include name="**/test/*TestCase.class"/>
                      <exclude name="**/Abstract*"/>
                  </fileset>
              </batchtest>
          </junit>
  
      </target>
  
      <target name="test-reports" depends="test" description="Generate Reports for the 
unit tests">
  
          <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkBSF"/>
  
          <mkdir dir="${build.reports}/junit"/>
  
          <junitreport todir="${build.reports}/junit">
              <fileset dir="${build.tests}">
                  <include name="TEST-*.xml"/>
              </fileset>
              <report format="frames" todir="${build.reports}/junit"/>
          </junitreport>
  
          <!-- Clean up the xml reports used by the junitreport task -->
          <!--
          <delete>
              <fileset dir="${build.tests}" includes="TEST-*.xml"/>
              <fileset dir="${build.tests}" includes="TESTS-*.xml"/>
          </delete>
          -->
  
      </target>
  
      <target name="checkstyle" if="do.checkstyle" description="Checkstyle">
  
          <!-- this invocation of checkstyle requires that checkstyle be downloaded 
and setup -->
          <!-- thats why you are required to define do.checkstyle property to generate 
the report -->
          <taskdef name="checkstyle"
              classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
              <classpath refid="project.class.path"/>
          </taskdef>
          <checkstyle
              lcurlyType="nl"
              lcurlyMethod="nl"
              lcurlyOther="nl"
              rcurly="ignore"
              allowProtected="false"
              allowPackage="false"
              allowNoAuthor="false"
              maxLineLen="100"
              maxMethodLen="100"
              maxConstructorLen="100"
              memberPattern="^m_[a-z][a-zA-Z0-9]*$"
              staticPattern="^c_[a-z][a-zA-Z0-9]*$"
              constPattern="(^c_[a-z][a-zA-Z0-9]*$)|([A-Z_]*$)"
              ignoreImportLen="true"
              allowTabs="false"
              javadocScope="protected"
              ignoreWhitespace="true"
              cacheFile="checkstyle.cache"
              failOnViolation="false"
              ignoreCastWhitespace="true">
              <fileset dir="${java.dir}">
                  <include name="**/*.java"/>
              </fileset>
              <formatter type="plain"/>
              <formatter type="xml" toFile="${build.dir}/checkstyle-results.xml"/>
          </checkstyle>
      </target>
  
      <target name="checkstyle-report"
          depends="checkstyle"
          if="do.checkstyle"
          description="Generate Checkstyle Report">
  
          <mkdir dir="${build.reports}/checkstyle"/>
          <property name="checkstyle.pathhack" location="."/>
          <style style="${tools.dir}/etc/checkstyle-frames.xsl" 
in="${build.dir}/checkstyle-results.xml"
              out="${build.reports}/checkstyle/delete-me.html">
              <param name="pathhack" expression="${checkstyle.pathhack}"/>
          </style>
  
      </target>
  
      <target name="xdoclet" depends="main" description="Generates the XML 
descriptors">
          <taskdef name="avalon-info"
              classname="org.apache.avalon.framework.tools.ant.MetaGenerateTask">
              <classpath>
                  <path refid="project.class.path"/>
                  <pathelement location="${build.classes}"/>
              </classpath>
          </taskdef>
  
          <mkdir dir="gen"/>
          <avalon-info force="true" destdir="gen" >
              <fileset dir="${test.dir}">
                  <include name="**/data/*.java" />
              </fileset>
          </avalon-info>
      </target>
  
      <!-- Creates the distribution -->
      <target name="dist"
          depends="dist-jar, test-reports, checkstyle-report, docs, javadocs"
          description="Generates a distribution (jar + docs + javadocs + unit tests + 
checkstyle reports)">
  
          <copy file="${build.conf}/LICENSE.txt" todir="${dist.dir}"/>
          <copy file="../KEYS" todir="${dist.dir}"/>
          <copy file="README.txt" todir="${dist.dir}"/>
  
          <zip zipfile="${dist.dir}/src.zip" compress="false">
              <zipfileset dir="src/java"/>
          </zip>
  
          <mkdir dir="${dist.base}"/>
  
          <zip zipfile="${dist.base}/${dist.name}.zip" compress="true">
              <zipfileset dir="${dist.dir}" prefix="${dist.name}"/>
              <zipfileset dir="${docs.dir}" prefix="${dist.name}/docs"/>
          </zip>
      </target>
  
      <!-- Creates a mini jar-only distribution -->
      <target name="dist-jar" depends="jar">
          <mkdir dir="${dist.dir}"/>
          <copy todir="${dist.dir}">
              <fileset dir="${build.lib}">
                  <include name="*.jar"/>
              </fileset>
          </copy>
      </target>
  
      <!-- Creates a minimal distribution -->
      <target name="dist.lite"
          depends="dist-jar, test, javadocs"
          description="Generates a minimal distribution (jar + javadocs)">
  
          <copy file="../LICENSE.txt" todir="${dist.dir}"/>
          <copy file="../KEYS" todir="${dist.dir}"/>
          <copy file="README.txt" todir="${dist.dir}"/>
  
      </target>
  
  
      <target name="anakia-avail">
          <available classname="org.apache.velocity.anakia.AnakiaTask"
              property="AnakiaTask.present">
              <classpath refid="tools.class.path"/>
          </available>
      </target>
  
      <target name="anakia-check" depends="anakia-avail" unless="AnakiaTask.present">
          <echo>
              AnakiaTask is not present! Please check to make sure that
              velocity.jar is in your classpath. The easiest way to build
              the documentation is to checkout jakarta-site CVS and specify
              jakarta-site.dir property.
          </echo>
      </target>
  
      <target name="docs" depends="anakia-check" description="Generate documentation 
and website">
          <taskdef name="anakia"
              classname="org.apache.velocity.anakia.AnakiaTask">
              <classpath refid="tools.class.path"/>
          </taskdef>
  
          <anakia basedir="${xdocs.dir}"
              destdir="${docs.dir}"
              style="docs.vsl"
              projectfile="menu.xml"
              includes="**/*.xml"
              excludes="menu.xml"
              velocitypropertiesfile="../site/src/stylesheets/velocity.properties"
              />
  
       <copy
           
file="src/java/org/apache/avalon/framework/tools/infobuilder/componentinfo.dtd"
           tofile="${docs.dir}/componentinfo.dtd.txt"/>
       <copy todir="${docs.dir}" filtering="off">
        <fileset dir="../site/src" includes="css/*.css" />
        <fileset dir="${xdocs.dir}">
          <include name="**/images/**"/>
          <include name="**/*.gif"/>
          <include name="**/*.txt"/>
          <include name="**/*.jpg"/>
          <include name="**/*.png"/>
          <include name="**/*.css"/>
          <include name="**/*.js"/>
        </fileset>
      </copy>
      </target>
  
      <target name="site" depends="javadocs, docs" description=" Places Docs ready for 
hosting on website">
  
          <mkdir dir="../site/dist/docs/${dir-name}"/>
          <copy todir="../site/dist/docs/${dir-name}">
              <fileset dir="${docs.dir}">
                  <include name="**"/>
              </fileset>
          </copy>
  
      </target>
  
      <!-- Cleans up build and distribution directories -->
      <target name="clean" description="Cleans up the project">
          <delete file="checkstyle.cache"/>
          <delete dir="${build.dir}" />
          <delete dir="${dist.dir}" />
          <delete dir="${docs.dir}" />
          <delete dir="test" /> <!-- unit testing output directory -->
          <delete>
              <fileset dir="." includes="velocity.*"/>
              <fileset dir="." includes="**/*~" defaultexcludes="no"/>
          </delete>
      </target>
  
      <target name="real-clean" depends="clean" description="Cleans up the project, 
including distributions">
          <delete dir="${dist.base}" />
      </target>
  
  </project>
  
  
  
  1.1                  avalon-sandbox/datasource/default.properties
  
  Index: default.properties
  ===================================================================
  # -------------------------------------------------------------------
  # B U I L D  P R O P E R T I E S
  # -------------------------------------------------------------------
  # Specifies default property values
  # Overridden by ../default.properties and all ant.properties
  # Not user-editable; use ant.properties files instead
  
  name=excalibur-info
  Name=Excalibur Info
  dir-name=info
  version=1.0a
  package-version=0.99
  year=2000-2002
  
  # --------------------------------------------------
  #                REQUIRED LIBRARIES
  # --------------------------------------------------
  
  # ----- Avalon Framework, version 4.1 or later -----
  avalon-framework.home=${basedir}/../../jakarta-avalon
  avalon-framework.lib=${avalon-framework.home}/target/lib
  avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
  
  # ----- Excalibur i18n, version 1.0 or later -----
  excalibur-i18n.home=${basedir}/../i18n/dist
  excalibur-i18n.lib=${excalibur-i18n.home}
  excalibur-i18n.jar=${excalibur-i18n.lib}/excalibur-i18n-1.0.jar
  
  # ----- jakarta-site CVS module, latest version (Anakia) -----
  jakarta-site.dir=${basedir}/../../jakarta-site
  
  # --------------------------------------------------
  
  #  Settings used to configure compile environment
  build.debug = on
  build.optimize = off
  build.deprecation = off
  build.compress = false
  junit.failonerror = false
  
  #  location of intermediate products
  build.dir = build
  build.testsrc = ${build.dir}/testsrc
  build.testclasses = ${build.dir}/testclasses
  build.lib = ${build.dir}/lib
  build.conf = ${build.dir}/conf
  build.classes = ${build.dir}/classes
  build.tests = ${build.dir}/tests
  build.reports = ${build.dir}/reports
  docs.dir = ${build.dir}/docs
  
  #  Set the properties for source directories
  src.dir = src
  java.dir = ${src.dir}/java
  conf.dir = ${src.dir}/conf
  test.dir = ${src.dir}/test
  xdocs.dir = src/xdocs
  
  #  Set the properties for distribution directories
  dist.dir = dist
  dist.javadocs = ${docs.dir}/api
  
  #  name of .zip/.tar.gz/.bz2 files and their top-level directory
  dist.name = ${name}-${version}
  
  #  name of jar file
  jar.name = ${name}-${version}.jar
  
  #  property indicating directory where all distribution archives are placed
  dist.base = distributions
  
  depchecker.prefix=.
  
  
  
  
  1.1                  avalon-sandbox/datasource/lib/DO-NOT-DELETE.txt
  
  Index: DO-NOT-DELETE.txt
  ===================================================================
  This is a placeholder so that we can add libs
  as necessary--and CVS won't kill the directory.
  
  
  1.1                  
avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/DataSourceManager.java
  
  Index: DataSourceManager.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
      [EMAIL PROTECTED]
  
   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.datasource;
  
  import java.sql.Connection;
  import java.sql.SQLException;
  
  /**
   * The DataSourceManager is the abstraction we use for Avalon applications or
   * IOC based applications.  It allows us to choose any Connection from a set of
   * DataSource objects.  The mechanism used to register the conntection objects
   * is done behind the scenes--whether it is JNDI or not.
   *
   * <p>
   *   If your application only uses one database for the whole application, then
   *   use the {@link javax.sql.DataSource} interface for your connection.  This
   *   library also provides the framework you need to create your own connection
   *   pooling code--and it will work with any other driver's code.
   * </p>
   *
   * @see org.apache.excalibur.datasource.impl.ConnectionPoolDataSource
   */
  public interface DataSourceManager
  {
      /**
       * Get the named connection.  Please note that the DataSourceManager merely
       * looks up the connection by a name.  If the name does not exist, or there
       * is a problem creating your connection, you will receive an exception.
       * This variation is used when there are no credentials, or you will set up
       * the credentials at the server.
       *
       * @param dbname  The name of the database connection.
       *
       * @throws SQLException if there is a problem with the connection, or if
       *         there is no connection bound to that name.
       *
       * @return  The <code>java.sql.Connection</code> object.
       */
      Connection getConnection( String dbname ) throws SQLException;
  
      /**
       * Get the named connection using the credentials passed in.  Please note
       * that the DataSourceManager merely looks up the connection by a name.  If
       * the name does not exist, or there is a problem creating your connection,
       * you will receive an exception.  This variation is used when you are using
       * credentials supplied by the application.
       *
       * <p>
       *   <strong>TIP:</strong> If you obtain your username/password from the
       *   user of your application, you might want to encrypt the password while
       *   it is in memory.  The pasword is sent to this object in the clear--so
       *   do take pains to ensure that the container you use does not allow
       *   someone to intercept calls to your DataSourceManager.  If every client
       *   of the DataSourceManager receives its own proxy (like in Phoenix) of
       *   the component, then you are done.  Otherwise, throw a
       *   <code>UnsupportedOperationException</code>.
       * <p>
       *
       * @param dbname  The name of the database connection
       * @param user    The user name to connect with.
       * @param passwd  The password used to connect with.
       *
       * @throws SQLException if there is a problem with the connection, or if
       *         there is no connection bound to that name.
       * @throws UnsupportedOperationException if the implementation does not
       *         support client supplied credentials.
       *
       * @return  The <code>java.sql.Connection</code> object.
       */
      Connection getConnection( String dbname, String user, String passwd )
          throws SQLException;
  
      /**
       * Determines whether the implementation of this DataSourceManager supports
       * user supplied credentials.
       *
       * @return  <code>true</code> if it does, <code>false</code> if not.
       */
      boolean supportsClientCredentials();
  }
  
  
  
  1.1                  
avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/impl/ApacheConnectionPoolDataSource.java
  
  Index: ApacheConnectionPoolDataSource.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
      [EMAIL PROTECTED]
  
   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.datasource.impl;
  
  import javax.sql.ConnectionPoolDataSource;
  import javax.sql.PooledConnection;
  import java.sql.SQLException;
  import java.io.PrintWriter;
  
  /**
   * <p>Title: </p>
   * <p>Description: </p>
   * <p>Copyright: Copyright (c) 2002</p>
   * <p>Company: </p>
   * @author not attributable
   * @version 1.0
   */
  
  public class ApacheConnectionPoolDataSource implements ConnectionPoolDataSource
  {
      public ApacheConnectionPoolDataSource()
      {
      }
    public PooledConnection getPooledConnection() throws SQLException {
      /**@todo Implement this javax.sql.ConnectionPoolDataSource method*/
      throw new java.lang.UnsupportedOperationException("Method getPooledConnection() 
not yet implemented.");
    }
    public PooledConnection getPooledConnection(String user, String password) throws 
SQLException {
      /**@todo Implement this javax.sql.ConnectionPoolDataSource method*/
      throw new java.lang.UnsupportedOperationException("Method getPooledConnection() 
not yet implemented.");
    }
    public PrintWriter getLogWriter() throws SQLException {
      /**@todo Implement this javax.sql.ConnectionPoolDataSource method*/
      throw new java.lang.UnsupportedOperationException("Method getLogWriter() not yet 
implemented.");
    }
    public void setLogWriter(PrintWriter out) throws SQLException {
      /**@todo Implement this javax.sql.ConnectionPoolDataSource method*/
      throw new java.lang.UnsupportedOperationException("Method setLogWriter() not yet 
implemented.");
    }
    public void setLoginTimeout(int seconds) throws SQLException {
      /**@todo Implement this javax.sql.ConnectionPoolDataSource method*/
      throw new java.lang.UnsupportedOperationException("Method setLoginTimeout() not 
yet implemented.");
    }
    public int getLoginTimeout() throws SQLException {
      /**@todo Implement this javax.sql.ConnectionPoolDataSource method*/
      throw new java.lang.UnsupportedOperationException("Method getLoginTimeout() not 
yet implemented.");
    }
  
  }
  
  
  
  1.1                  
avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/impl/SimpleDataSourceManager.java
  
  Index: SimpleDataSourceManager.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
      [EMAIL PROTECTED]
  
   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.datasource.impl;
  
  import java.sql.*;
  import java.util.*;
  import javax.sql.*;
  
  import org.apache.avalon.framework.activity.*;
  import org.apache.avalon.framework.configuration.*;
  import org.apache.avalon.framework.parameters.*;
  import org.apache.excalibur.datasource.*;
  import org.apache.excalibur.datasource.util.*;
  
  /**
   * The <code>SimpleDataSourceManager</code> manages all the connections via
   * javax.sql.DataSource objects--so that it can leverage the work already done
   * by the database vendors.  The <code>ApacheConnectionPoolDataSource</code>
   * will be used to handle database vendors that don't provide a connection
   * pooling datasource.
   */
  public class SimpleDataSourceManager implements DataSourceManager, Initializable, 
Configurable
  {
      private Map m_datasources;
  
      /**
       * Create a new SimpleDataSourceManager
       */
      public SimpleDataSourceManager()
      {
          m_datasources = new HashMap();
      }
  
      /**
       * Get the requested datasource connection
       *
       * @param dbname  The database name
       * @return  the Connection
       *
       * @throws SQLException  If the connection could not be created for any reason.
       */
      public Connection getConnection(String dbname) throws SQLException
      {
          DataSource datasource = getDataSource( dbname );
  
          return datasource.getConnection();
      }
  
      /**
       * Get the requested datasource connection using the supplied credentials.
       *
       * @param dbname  The database name
       * @param user    The user name
       * @param passwd  The password
       * @return  the Connection
       *
       * @throws SQLException  If the connection could not be created for any reason.
       */
      public Connection getConnection(String dbname, String user, String passwd)
          throws SQLException
      {
          DataSource datasource = getDataSource( dbname );
  
          return datasource.getConnection( user, passwd );
      }
  
      /**
       * This does support Client Credentials.
       *
       * @return <code>true</code>
       */
      public boolean supportsClientCredentials()
      {
          return true;
      }
  
      /**
       * Get the javax.sql.DataSource for the connection name.
       *
       * @param dbname  the name of the connection
       * @return the javax.sql.DataSource
       * @throws SQLException  if there is no datasource by that name.
       */
      private DataSource getDataSource( String dbname )
          throws SQLException
      {
           DataSource datasource = (DataSource) m_datasources.get( dbname );
  
           if (null == datasource) throw new SQLException( "No datasource configured 
with that name" );
  
           return datasource;
      }
  
      /**
       * Initialize the databases the manager controls.
       *
       * @throws Exception  if there was a problem.
       */
      public void initialize() throws Exception
      {
          m_datasources = Collections.unmodifiableMap( m_datasources );
      }
  
      /**
       * Configure all the connections that the manager controls.  The configuration
       * scheme looks like this:
       *
       * <pre>
       * <![CDATA[
       *   <datasource-manager>
       *     <connection name="foo" class="com.dbvendor.driver.VendorDataSource">
       *       <parameter name="dbUrl" value="jdbc:dbvendor://server:port/foodb"/>
       *       <parameter name="user" value="example"/>
       *     </connection>
       *   </datasource-manager>
       * ]]>
       * </pre>
       *
       * @param config The configuration that follows the above standard.
       *
       * @throws ConfigurationException  If there is any parameter not bound to a
       *         valid DataSource object.
       */
      public void configure(Configuration config) throws ConfigurationException
      {
          Configuration[] dataSources = config.getChildren("connection");
  
          for ( int i = 0; i < dataSources.length; i++ )
          {
              Parameters props = Parameters.fromConfiguration(dataSources[i]);
              m_datasources.put( dataSources[i].getAttribute("name"),
                                 setupDataSource( dataSources[i].getAttribute("type"), 
props )
              );
          }
      }
  
      /**
       * Create and configure all the DataSource objects specified by the class
       * name and parameters.
       *
       * @param classname        The class name used for the connection
       * @param connectionProps  The parameters used to assign values to the 
datasource
       *
       * @return  the valid and configured DataSource
       *
       * @throws ConfigurationException  if there is a problem with the datasource
       *         at all.
       */
      private DataSource setupDataSource( String classname, Parameters connectionProps 
)
          throws ConfigurationException
      {
          if ( null == classname ) throw new NullPointerException("classname");
          if ( null == connectionProps ) throw new 
NullPointerException("connectionProps");
  
          DataSource datasource = null;
  
          try
          {
              datasource = 
(DataSource)Thread.currentThread().getContextClassLoader().loadClass(classname).newInstance();

              BeanUtil.setBeanParameters(datasource, connectionProps);
          }
          catch (Exception e)
          {
              throw new ConfigurationException( "The classname specified was not 
valid", e );
          }
  
          return datasource;
      }
  }
  
  
  
  1.1                  
avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/util/BeanUtil.java
  
  Index: BeanUtil.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
      [EMAIL PROTECTED]
  
   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.datasource.util;
  
  import java.beans.*;
  import java.lang.reflect.*;
  import java.util.*;
  
  import org.apache.avalon.framework.parameters.*;
  
  /**
   * <code>BeanUtil</code> is a convenience class used so that we can easily set
   * and retrieve properties from objects that conform to the JavaBeans
   * specification.  The DataSource library uses this to determine at runtime
   * what properties can and cannot be set for a DataSource object.  We do not
   * know which set of properties are exposed on an Oracle (TM) DataSource object
   * vs. a MySQL DataSource object until we examine it with introspection.
   */
  public final class BeanUtil
  {
      /** An unknown type, BeanUtil cannot set or get these properties */
      public static final int UNKNOWN_TYPE = 0x00;
      /** An <code>int</code> type */
      public static final int INT_TYPE = 0x01;
      /** An <code>long</code> type */
      public static final int LONG_TYPE = 0x02;
      /** An <code>float</code> type */
      public static final int FLOAT_TYPE = 0x03;
      /** An <code>double</code> type */
      public static final int DOUBLE_TYPE = 0x04;
      /** An <code>byte</code> type */
      public static final int BYTE_TYPE = 0x05;
      /** An <code>char</code> type */
      public static final int CHAR_TYPE = 0x06;
      /** An <code>short</code> type */
      public static final int SHORT_TYPE = 0x07;
      /** An <code>java.lang.String</code> type */
      public static final int STRING_TYPE = 0x08;
  
      private static final Object[] NO_ARGS = new Object[] {};
  
      private static Map m_propertyMap = new HashMap();
  
      private BeanUtil() {}
  
      /**
       * Get the <code>PropertyDescriptor</code> for the associated JavaBean and
       * property name.
       *
       * @param info          The {@link BeanInfo} for the JavaBean
       * @param propertyName  The property name
       *
       * @return the {@link PropertyDescriptor}
       *
       * @throws IntrospectionException if the property does not exist for the
       *         JavaBean
       */
      private static PropertyDescriptor getPropertyDescriptor( BeanInfo info, String 
propertyName )
          throws IntrospectionException
      {
          Map properties = (Map)m_propertyMap.get( info );
          PropertyDescriptor descriptor = null;
  
          if ( null == properties )
          {
              properties = initProperties(info);
          }
  
          descriptor = (PropertyDescriptor)properties.get( propertyName );
  
          if ( null == descriptor ) throw new IntrospectionException("Property does 
not exist" + propertyName);
  
          return descriptor;
      }
  
      /**
       * Set up the type cache for the supplied JavaBean
       *
       * @param info  The {@link BeanInfo} for JavaBean
       *
       * @return  Return the map instance we created.
       */
      private static Map initProperties(BeanInfo info) {
        PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
        Map properties = new HashMap( descriptors.length );
  
        for ( int i = 0; i < descriptors.length; i++ )
        {
            properties.put( descriptors[i].getName(), descriptors[i] );
        }
  
        m_propertyMap.put( info, Collections.unmodifiableMap(properties) );
        return properties;
      }
  
      /**
       * Get the type of the property value for a JavaBean.  This is used to
       * determine how to format the string value of a property so we can have
       * a standard and uniform interface.
       *
       * @param bean           The JavaBean we want the property from
       * @param propertyName   The name of the property we want
       *
       * @return The type enumeration
       *
       * @throws IntrospectionException  if the property does not exist, or the
       *         supplied object is not a JavaBean
       */
      public static int getPropertyType( Object bean, String propertyName )
          throws IntrospectionException
      {
          int propertyType = UNKNOWN_TYPE;
          PropertyDescriptor descriptor = getPropertyDescriptor( 
Introspector.getBeanInfo(bean.getClass()), propertyName );
          Class type = descriptor.getPropertyType();
  
          if ( type.equals(String.class) ) propertyType = STRING_TYPE;
          else if ( type.equals(int.class) ) propertyType = INT_TYPE;
          else if ( type.equals(long.class) ) propertyType = LONG_TYPE;
          else if ( type.equals(float.class) ) propertyType = FLOAT_TYPE;
          else if ( type.equals(double.class) ) propertyType = DOUBLE_TYPE;
          else if ( type.equals(byte.class) ) propertyType = BYTE_TYPE;
          else if ( type.equals(char.class) ) propertyType = CHAR_TYPE;
          else if ( type.equals(short.class) ) propertyType = SHORT_TYPE;
  
          return propertyType;
      }
  
      /**
       * Set the value of a specified property from the supplied JavaBean.
       *
       * @param bean           The JavaBean we want the property from
       * @param propertyName   The name of the property we want
       * @param propertyValue  The value of the propery
       *
       * @throws IntrospectionException  if the property does not exist, or the
       *         supplied object is not a JavaBean
       */
      public static void setProperty( Object bean, String propertyName, String 
propertyValue )
          throws IntrospectionException
      {
        PropertyDescriptor descriptor = getPropertyDescriptor( 
Introspector.getBeanInfo(bean.getClass()), propertyName );
        int type = getPropertyType( bean, propertyName );
        Method method = descriptor.getWriteMethod();
        Object[] args = new Object[1];
  
        switch( type )
        {
            case STRING_TYPE:
                args[0] = propertyValue;
                break;
  
            case INT_TYPE:
                args[0] = Integer.decode(propertyValue);
                break;
  
            case BYTE_TYPE:
                args[0] = Byte.decode(propertyValue);
                break;
  
            case CHAR_TYPE:
                args[0] = new Character( propertyValue.charAt(0) );
                break;
  
            case DOUBLE_TYPE:
                args[0] = Double.valueOf(propertyValue);
                break;
  
            case FLOAT_TYPE:
                args[0] = Float.valueOf(propertyValue);
                break;
  
            case LONG_TYPE:
                args[0] = Long.decode(propertyValue);
                break;
  
            case SHORT_TYPE:
                args[0] = Short.decode(propertyValue);
                break;
  
            default:
                throw new IntrospectionException("Unknown type for " + propertyName);
        }
  
        try
        {
            method.invoke(bean, args);
        }
        catch (Exception ex)
        {
            throw new IntrospectionException(ex.getMessage());
        }
      }
  
      /**
       * Get the value of a specified property from the supplied JavaBean.
       *
       * @param bean          The JavaBean we want the property from
       * @param propertyName  The name of the property we want
       *
       * @return  The {@link String} value of the property
       *
       * @throws IntrospectionException  if the property does not exist, or the
       *         supplied object is not a JavaBean
       */
      public static String getProperty( Object bean, String propertyName )
          throws IntrospectionException
      {
          PropertyDescriptor descriptor = getPropertyDescriptor( 
Introspector.getBeanInfo(bean.getClass()), propertyName );
          Method method = descriptor.getReadMethod();
          Object value = null;
  
          try
          {
              value = method.invoke(bean, NO_ARGS);
          }
          catch (Exception ex)
          {
              throw new IntrospectionException(ex.getMessage());
          }
  
          return String.valueOf(value);
      }
  
      /**
       * Get the set of property names associated with a JavaBean.
       *
       * @param bean  The bean we want to list the properties on.
       *
       * @return  a {@link Set} of property names
       */
      public static Set getPropertyNames( Object bean )
      {
          BeanInfo info = null;
  
          try
          {
              info = Introspector.getBeanInfo(bean.getClass());
          }
          catch (IntrospectionException ex)
          {
              // There was no info, therefore there are no property names
              return null;
          }
  
          Map properties = (Map)m_propertyMap.get( info );
          PropertyDescriptor descriptor = null;
  
          if ( null == properties )
          {
              properties = initProperties(info);
          }
  
          return properties.keySet();
      }
  
      /**
       * Gets all the properties of a bean.  The returned <code>Parameters</code>
       * object will have the full set of properties and their current values.
       *
       * @param bean    The bean we want to get properties from.
       *
       * @return The {@link Parameters} object with the name/value mappings
       *
       * @throws ParameterException  if any of the properties could not be retrieved.
       */
      public static Parameters getBeanParameters( Object bean )
          throws ParameterException
      {
          Parameters params = new Parameters();
          Set names = getPropertyNames( bean );
          if ( null == names || names.isEmpty() ) throw new ParameterException("There 
are no properties for your bean: " + bean.toString());
  
          Iterator it = names.iterator();
          while ( it.hasNext() )
          {
              String property = (String) it.next();
  
              try
              {
                  params.setParameter(property, getProperty(bean, property));
              }
              catch (IntrospectionException ie)
              {
                  throw new ParameterException( "Could not get the required property: 
" + property, ie );
              }
          }
  
          return params;
      }
  
      /**
       * Sets all the properties of a bean based on the properties supplied.  The
       * supplied <code>Parameters</code> object may have a subset of the properties
       * that are associated with a JavaBean.  If that is the case, then
       * <code>BeanUtil</code> will ignore all the properties not listed.  The
       * supplied <code>Parameters</code> may <strong>note</strong> have more
       * properties than exist in the JavaBean.
       *
       * @param bean    The bean we want to set properties on.
       * @param params  The {@link Parameters} object with the name/value mappings
       *
       * @throws ParameterException  if any of the properties could not be set.
       */
      public static void setBeanParameters( Object bean, Parameters params )
          throws ParameterException
      {
          String[] names = params.getNames();
  
          for ( int i = 0; i < names.length; i++ )
          {
              try
              {
                  setProperty(bean, names[i], params.getParameter(names[i]));
              }
              catch (IntrospectionException ie)
              {
                  throw new ParameterException( "Could not set the property: " + 
names[i], ie );
              }
          }
      }
  }
  
  
  
  1.1                  
avalon-sandbox/datasource/src/test/org/apache/excalibur/datasource/impl/test/SimpleDataSourceManagerTest.java
  
  Index: SimpleDataSourceManagerTest.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
      [EMAIL PROTECTED]
  
   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.datasource.impl.test;
  
  import java.io.*;
  import java.lang.reflect.*;
  import java.sql.*;
  
  import org.apache.avalon.framework.configuration.*;
  import org.apache.excalibur.datasource.*;
  import org.apache.excalibur.datasource.impl.*;
  import junit.framework.*;
  
  public class SimpleDataSourceManagerTest
      extends TestCase {
    private SimpleDataSourceManager simpleDataSourceManager = null;
  
    public SimpleDataSourceManagerTest(String name) {
      super(name);
    }
  
    protected void setUp() throws Exception {
      super.setUp();
      simpleDataSourceManager = new SimpleDataSourceManager();
      simpleDataSourceManager.configure(getConfiguration());
      simpleDataSourceManager.initialize();
    }
  
    protected void tearDown() throws Exception {
      simpleDataSourceManager = null;
      super.tearDown();
    }
  
    public void testGetConnection() throws SQLException {
      try {
        Connection bar = simpleDataSourceManager.getConnection("bar");
        fail("Should have thrown an exception");
      } catch( Exception e ) {
        // ignore
      }
  
      Connection foo = simpleDataSourceManager.getConnection("foo");
      assertNotNull( foo );
  
      assertEquals( "testor", ((UserPassword) foo).getUser() );
      assertEquals( "passwd", ((UserPassword) foo).getPassword() );
    }
  
    public void testGetConnection1() throws SQLException {
      try {
        Connection bar = simpleDataSourceManager.getConnection("bar", null, null);
        fail("Should have thrown an exception");
      } catch( Exception e ) {
        // ignore
      }
  
      try {
        Connection foo = simpleDataSourceManager.getConnection("foo", null, null);
        fail("Should have thrown an exception");
      } catch( Exception e ) {
        // ignore
      }
  
      try {
        Connection foo = simpleDataSourceManager.getConnection("foo", "testor", null);
        fail("Should have thrown an exception");
      } catch( Exception e ) {
        // ignore
      }
  
      try {
        Connection foo = simpleDataSourceManager.getConnection("foo", null, "passwd");
        fail("Should have thrown an exception");
      } catch( Exception e ) {
        // ignore
      }
  
      Connection foo = simpleDataSourceManager.getConnection("foo", "testor", 
"passwd");
      assertNotNull( foo );
  
      assertEquals( "testor", ((UserPassword) foo).getUser() );
      assertEquals( "passwd", ((UserPassword) foo).getPassword() );
    }
  
    public void testSupportsClientCredentials() {
      assertEquals(true, simpleDataSourceManager.supportsClientCredentials());
      assertFalse( false == simpleDataSourceManager.supportsClientCredentials() );
    }
  
    private Configuration getConfiguration() {
      DefaultConfiguration config = new DefaultConfiguration("manager", 
this.toString(), DataSourceManager.class.
          getName(), "datasource");
      DefaultConfiguration connection = new DefaultConfiguration("connection", 
this.toString(),
          DataSourceManager.class.getName(), "datasource" );
      connection.setAttribute("name", "foo");
      connection.setAttribute("type", MockDataSource.class.getName());
  
      DefaultConfiguration dbParam = new DefaultConfiguration("parameter", 
this.toString(), DataSourceManager.class.
          getName(), "datasource");
      dbParam.setAttribute("name", "databaseName");
      dbParam.setAttribute("value", "test");
      connection.addChild(dbParam);
  
      DefaultConfiguration user = new DefaultConfiguration("parameter", 
this.toString(), DataSourceManager.class.
          getName(), "datasource");
      user.setAttribute("name", "user");
      user.setAttribute("value", "testor");
      connection.addChild(user);
  
      DefaultConfiguration passwd = new DefaultConfiguration("parameter", 
this.toString(), DataSourceManager.class.
          getName(), "datasource");
      passwd.setAttribute("name", "password");
      passwd.setAttribute("value", "passwd");
      connection.addChild(passwd);
  
      config.addChild(connection);
      return config;
    }
  
    public interface UserPassword
    {
      String getUser();
      String getPassword();
    }
  
    public static class MockDataSource
        implements javax.sql.DataSource, InvocationHandler, UserPassword {
      private String m_dbName = "";
      private String m_user = "";
      private String m_passwd = "";
      private int m_loginTimeout = 1000;
      private PrintWriter m_logWriter = new PrintWriter(new OutputStreamWriter(
          System.err));
  
      public String getDatabaseName() {
        return m_dbName;
      }
  
      public void setDatabaseName(String name) {
        m_dbName = name;
      }
  
      public String getUser() {
        return m_user;
      }
  
      public void setUser(String name) {
        m_user = name;
      }
  
      public String getPassword() {
        return m_passwd;
      }
  
      public void setPassword(String passwd) {
        m_passwd = passwd;
      }
  
      public int getLoginTimeout() {
        return m_loginTimeout;
      }
  
      public void setLoginTimeout(int timeout) {
        m_loginTimeout = timeout;
      }
  
      public PrintWriter getLogWriter() {
        return m_logWriter;
      }
  
      public void setLogWriter(PrintWriter pw) {
        m_logWriter = pw;
      }
  
      public Connection getConnection() throws SQLException {
        return getConnection(getUser(), getPassword());
      }
  
      public Connection getConnection(String username, String password) throws 
SQLException {
        if ( ! username.equals(getUser() )) throw new SQLException( "Bad User Name" );
        if ( ! password.equals(getPassword() )) throw new SQLException( "Bad Password" 
);
        return (Connection) Proxy.newProxyInstance(Thread.currentThread().
                                                   getContextClassLoader(),
                                                   new Class[] 
{Connection.class,UserPassword.class}
                                                   , this);
      }
  
      public Object invoke(Object obj, Method m, Object[] args) throws Throwable {
        Object retVal = null;
        if ( m.getName().equals("getUser") || m.getName().equals("getPassword") ) {
          retVal = m.invoke(this, args);
        }
        return retVal;
      }
    }
  }
  
  
  
  1.1                  
avalon-sandbox/datasource/src/test/org/apache/excalibur/datasource/util/test/BeanUtilTest.java
  
  Index: BeanUtilTest.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
      [EMAIL PROTECTED]
  
   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.datasource.util.test;
  
  import junit.framework.*;
  import org.apache.excalibur.datasource.util.*;
  import java.beans.*;
  import java.util.Date;
  import java.util.Set;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.parameters.ParameterException;
  
  public class BeanUtilTest
      extends TestCase {
  
    public BeanUtilTest(String name) {
      super(name);
    }
  
    protected void setUp() throws Exception {
      super.setUp();
      /**@todo verify the constructors*/
    }
  
    protected void tearDown() throws Exception {
      super.tearDown();
    }
  
    public void testMockBean()
    {
        MockBean bean = new MockBean();
        assertEquals( "", bean.getString() );
        assertEquals( 0, bean.getByte() );
        assertEquals( '\0', bean.getChar() );
        assertEquals( 0, bean.getShort() );
        assertEquals( 0, bean.getInt() );
        assertEquals( 0, bean.getLong() );
        assertEquals( 0.0f, bean.getFloat(), 0.0 );
        assertEquals( 0.0, bean.getDouble(), 0.0 );
  
        bean.setString( "test" );
        bean.setByte((byte)1);
        bean.setChar('a');
        bean.setShort((short)2);
        bean.setInt(3);
        bean.setLong(4);
        bean.setFloat(1.0f);
        bean.setDouble(0.5f);
  
        assertEquals( "test", bean.getString() );
        assertEquals( 1, bean.getByte() );
        assertEquals( 'a', bean.getChar() );
        assertEquals( 2, bean.getShort() );
        assertEquals( 3, bean.getInt() );
        assertEquals( 4, bean.getLong() );
        assertEquals( 1.0f, bean.getFloat(), 0.0 );
        assertEquals( 0.5, bean.getDouble(), 0.0 );
    }
  
    public void testGetProperty() throws IntrospectionException {
      MockBean bean = new MockBean();
  
      assertEquals( "", BeanUtil.getProperty(bean, "string") );
      assertEquals( "0", BeanUtil.getProperty(bean, "byte") );
      assertEquals( "\0", BeanUtil.getProperty(bean, "char") );
      assertEquals( "0", BeanUtil.getProperty(bean, "short") );
      assertEquals( "0", BeanUtil.getProperty(bean, "int") );
      assertEquals( "0", BeanUtil.getProperty(bean, "long") );
      assertEquals( "0.0", BeanUtil.getProperty(bean, "float") );
      assertEquals( "0.0", BeanUtil.getProperty(bean, "double") );
  
      bean.setString( "test" );
      bean.setByte((byte)1);
      bean.setChar('a');
      bean.setShort((short)2);
      bean.setInt(3);
      bean.setLong(4);
      bean.setFloat(1.0f);
      bean.setDouble(0.5f);
  
      assertEquals( "test",  BeanUtil.getProperty(bean, "string") );
      assertEquals( "1",  BeanUtil.getProperty(bean, "byte") );
      assertEquals( "a", BeanUtil.getProperty(bean, "char") );
      assertEquals( "2", BeanUtil.getProperty(bean, "short") );
      assertEquals( "3", BeanUtil.getProperty(bean, "int") );
      assertEquals( "4", BeanUtil.getProperty(bean, "long") );
      assertEquals( "1.0", BeanUtil.getProperty(bean, "float") );
      assertEquals( "0.5", BeanUtil.getProperty(bean, "double") );
    }
  
    public void testGetPropertyType() throws IntrospectionException {
      MockBean bean = new MockBean();
      assertEquals( BeanUtil.STRING_TYPE,  BeanUtil.getPropertyType(bean, "string") );
      assertEquals( BeanUtil.BYTE_TYPE,  BeanUtil.getPropertyType(bean, "byte") );
      assertEquals( BeanUtil.CHAR_TYPE, BeanUtil.getPropertyType(bean, "char") );
      assertEquals( BeanUtil.SHORT_TYPE, BeanUtil.getPropertyType(bean, "short") );
      assertEquals( BeanUtil.INT_TYPE, BeanUtil.getPropertyType(bean, "int") );
      assertEquals( BeanUtil.LONG_TYPE, BeanUtil.getPropertyType(bean, "long") );
      assertEquals( BeanUtil.FLOAT_TYPE, BeanUtil.getPropertyType(bean, "float") );
      assertEquals( BeanUtil.DOUBLE_TYPE, BeanUtil.getPropertyType(bean, "double") );
    }
  
    public void testSetProperty() throws IntrospectionException {
      MockBean bean = new MockBean();
      assertEquals( "", bean.getString() );
      assertEquals( 0, bean.getByte() );
      assertEquals( '\0', bean.getChar() );
      assertEquals( 0, bean.getShort() );
      assertEquals( 0, bean.getInt() );
      assertEquals( 0, bean.getLong() );
      assertEquals( 0.0f, bean.getFloat(), 0.0 );
      assertEquals( 0.0, bean.getDouble(), 0.0 );
  
      BeanUtil.setProperty(bean, "string", "test");
      BeanUtil.setProperty(bean, "byte", "1");
      BeanUtil.setProperty(bean, "char", "a");
      BeanUtil.setProperty(bean, "short", "2");
      BeanUtil.setProperty(bean, "int", "3");
      BeanUtil.setProperty(bean, "long", "4");
      BeanUtil.setProperty(bean, "float", "1.0");
      BeanUtil.setProperty(bean, "double", "0.5");
  
      assertEquals( "test", bean.getString() );
      assertEquals( 1, bean.getByte() );
      assertEquals( 'a', bean.getChar() );
      assertEquals( 2, bean.getShort() );
      assertEquals( 3, bean.getInt() );
      assertEquals( 4, bean.getLong() );
      assertEquals( 1.0f, bean.getFloat(), 0.0 );
      assertEquals( 0.5, bean.getDouble(), 0.0 );
    }
  
    public void testFullCycle() throws IntrospectionException {
      MockBean bean = new MockBean();
  
      assertEquals( "", BeanUtil.getProperty(bean, "string") );
      assertEquals( "0", BeanUtil.getProperty(bean, "byte") );
      assertEquals( "\0", BeanUtil.getProperty(bean, "char") );
      assertEquals( "0", BeanUtil.getProperty(bean, "short") );
      assertEquals( "0", BeanUtil.getProperty(bean, "int") );
      assertEquals( "0", BeanUtil.getProperty(bean, "long") );
      assertEquals( "0.0", BeanUtil.getProperty(bean, "float") );
      assertEquals( "0.0", BeanUtil.getProperty(bean, "double") );
  
      BeanUtil.setProperty(bean, "string", "test");
      BeanUtil.setProperty(bean, "byte", "1");
      BeanUtil.setProperty(bean, "char", "a");
      BeanUtil.setProperty(bean, "short", "2");
      BeanUtil.setProperty(bean, "int", "3");
      BeanUtil.setProperty(bean, "long", "4");
      BeanUtil.setProperty(bean, "float", "1.0");
      BeanUtil.setProperty(bean, "double", "0.5");
  
      assertEquals( "test",  BeanUtil.getProperty(bean, "string") );
      assertEquals( "1",  BeanUtil.getProperty(bean, "byte") );
      assertEquals( "a", BeanUtil.getProperty(bean, "char") );
      assertEquals( "2", BeanUtil.getProperty(bean, "short") );
      assertEquals( "3", BeanUtil.getProperty(bean, "int") );
      assertEquals( "4", BeanUtil.getProperty(bean, "long") );
      assertEquals( "1.0", BeanUtil.getProperty(bean, "float") );
      assertEquals( "0.5", BeanUtil.getProperty(bean, "double") );
    }
  
    public void testPropertyNames() {
      MockBean bean = new MockBean();
  
      Set propNames = BeanUtil.getPropertyNames(bean);
  
      assertTrue( propNames.contains("string") );
      assertTrue( propNames.contains("byte") );
      assertTrue( propNames.contains("char") );
      assertTrue( propNames.contains("short") );
      assertTrue( propNames.contains("int") );
      assertTrue( propNames.contains("long") );
      assertTrue( propNames.contains("float") );
      assertTrue( propNames.contains("double") );
    }
  
    public void testToParameters() throws ParameterException {
      MockBean bean = new MockBean();
  
      Parameters params = BeanUtil.getBeanParameters( bean );
  
      assertEquals( "", params.getParameter("string") );
      assertEquals( "0", params.getParameter("byte") );
      assertEquals( "\0", params.getParameter("char") );
      assertEquals( "0", params.getParameter("short") );
      assertEquals( "0", params.getParameter("int") );
      assertEquals( "0", params.getParameter("long") );
      assertEquals( "0.0", params.getParameter("float") );
      assertEquals( "0.0", params.getParameter("double") );
  
      bean.setString( "test" );
      bean.setByte( (byte) 1);
      bean.setChar('a');
      bean.setShort( (short) 2);
      bean.setInt(3);
      bean.setLong(4);
      bean.setFloat(1.0f);
      bean.setDouble(0.5f);
  
      params = BeanUtil.getBeanParameters( bean );
  
      assertEquals( "test", params.getParameter("string") );
      assertEquals( "1", params.getParameter("byte") );
      assertEquals( "a", params.getParameter("char") );
      assertEquals( "2", params.getParameter("short") );
      assertEquals( "3", params.getParameter("int") );
      assertEquals( "4", params.getParameter("long") );
      assertEquals( "1.0", params.getParameter("float") );
      assertEquals( "0.5", params.getParameter("double") );
    }
  
    public void testFromParameters() throws ParameterException {
      MockBean bean = new MockBean();
  
      Parameters params = new Parameters();
  
      params.setParameter("string", "test");
      params.setParameter("byte", "1");
      params.setParameter("char", "a");
      params.setParameter("short", "2");
      params.setParameter("int", "3");
      params.setParameter("long", "4");
      params.setParameter("float", "1.0");
      params.setParameter("double", "0.5");
  
      BeanUtil.setBeanParameters( bean, params );
  
      assertEquals( "test", bean.getString() );
      assertEquals( 1, bean.getByte() );
      assertEquals( 'a', bean.getChar() );
      assertEquals( 2, bean.getShort() );
      assertEquals( 3, bean.getInt() );
      assertEquals( 4, bean.getLong() );
      assertEquals( 1.0f, bean.getFloat(), 0.0 );
      assertEquals( 0.5, bean.getDouble(), 0.0 );
    }
  
    public void testOverhead() throws IntrospectionException {
         MockBean bean = new MockBean();
  
         long noOverheadStart = System.currentTimeMillis();
         for ( int i = 0; i < 2000; i++ ) {
           bean.setString("test");
           bean.setByte( (byte) 1);
           bean.setChar('a');
           bean.setShort( (short) 2);
           bean.setInt(3);
           bean.setLong(4);
           bean.setFloat(1.0f);
           bean.setDouble(0.5f);
  
           assertEquals("test", bean.getString());
           assertEquals(1, bean.getByte());
           assertEquals('a', bean.getChar());
           assertEquals(2, bean.getShort());
           assertEquals(3, bean.getInt());
           assertEquals(4, bean.getLong());
           assertEquals(1.0f, bean.getFloat(), 0.0);
           assertEquals(0.5, bean.getDouble(), 0.0);
         }
         long noOverheadStop = System.currentTimeMillis();
  
         long overheadStart = System.currentTimeMillis();
         for ( int i = 0; i < 2000; i++ ) {
           BeanUtil.setProperty(bean, "string", "test");
           BeanUtil.setProperty(bean, "byte", "1");
           BeanUtil.setProperty(bean, "char", "a");
           BeanUtil.setProperty(bean, "short", "2");
           BeanUtil.setProperty(bean, "int", "3");
           BeanUtil.setProperty(bean, "long", "4");
           BeanUtil.setProperty(bean, "float", "1.0");
           BeanUtil.setProperty(bean, "double", "0.5");
  
           assertEquals("test", BeanUtil.getProperty(bean, "string"));
           assertEquals("1", BeanUtil.getProperty(bean, "byte"));
           assertEquals("a", BeanUtil.getProperty(bean, "char"));
           assertEquals("2", BeanUtil.getProperty(bean, "short"));
           assertEquals("3", BeanUtil.getProperty(bean, "int"));
           assertEquals("4", BeanUtil.getProperty(bean, "long"));
           assertEquals("1.0", BeanUtil.getProperty(bean, "float"));
           assertEquals("0.5", BeanUtil.getProperty(bean, "double"));
         }
         long overheadStop = System.currentTimeMillis();
  
         long noOverheadDuration = noOverheadStop - noOverheadStart;
         long overheadDuration = overheadStop - overheadStart;
  
         System.out.println("Without overhead, the raw time was: " + 
formatTime(noOverheadDuration));
         System.out.println("With overhead, the raw time was: " + 
formatTime(overheadDuration));
         System.out.println("That is " + ( (overheadDuration / noOverheadDuration) * 
100) + "% overhead.");
    }
  
    private static final String formatTime( long time ) {
      StringBuffer buffer = new StringBuffer();
      long curTime = time;
      long hours = curTime / (60*60*1000); // hours
      if ( hours > 0 ) {
        buffer.append( hours ).append(" hours");
        curTime -= hours * 60*60*1000;
      }
      long minutes = curTime / (60*1000);
      if ( minutes > 0 ) {
        buffer.append( minutes ).append(" minutes" );
        curTime -= minutes * 60*1000;
      }
      long seconds = curTime / 1000;
      if ( seconds > 0 ) {
        buffer.append( seconds ).append(" seconds");
        curTime -= seconds * 1000;
      }
      if ( curTime > 0 ) {
        buffer.append( curTime ).append(" millis");
      }
      return buffer.toString();
    }
  
    public static final class MockBean
    {
          private String m_str = new String();
          private int m_int;
          private long m_long;
          private byte m_byte;
          private char m_char = '\0';
          private short m_short;
          private float m_float;
          private double m_double;
  
          public String getString() { return m_str; }
          public void setString( String newVal ) { m_str = newVal; }
  
          public int getInt() { return m_int; }
          public void setInt( int newVal ) { m_int = newVal; }
  
          public long getLong() { return m_long; }
          public void setLong( long newVal ) { m_long = newVal; }
  
          public byte getByte() { return m_byte; }
          public void setByte( byte newVal ) { m_byte = newVal; }
  
          public char getChar() { return m_char; }
          public void setChar( char newVal ) { m_char = newVal; }
  
          public short getShort() { return m_short; }
          public void setShort( short newVal ) { m_short = newVal; }
  
          public float getFloat() { return m_float; }
          public void setFloat( float newVal ) { m_float = newVal; }
  
          public double getDouble() { return m_double; }
          public void setDouble( double newVal ) { m_double = newVal; }
    }
  
  }
  
  
  
  1.1                  avalon-sandbox/datasource/src/xdocs/index.xml
  
  Index: index.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <document>
    <properties>
      <title>Overview</title>
      <author email="bloritsch at apache.org">Berin Loritsch</author>
    </properties>
    <body>
      <section name="Introduction">
        <p>
          This is the next generation of the DataSource pooling
          code in Excalibur.  The new version takes all the lessons
          learned in the old version, as well as implementing some
          new functionality.
        </p>
      </section>
      <section name="The Plan">
        <p>
          Excalibur DataSource is functional, but it can use some
          improvements in performance, as well as pooling of prepared
          statements, and possibly even result sets.  This version
          will allow us to grab one of several connections.  Below
          is the list of features for the next version:
        </p>
        <ul>
          <li>Full Implementation of javax.sql.DataSource and PooledDataSource
          <li>Pooling of Connections.</li>
          <li>Cross DB connection polling technique.</li>
          <li>Pooling of majority of java.sql.* objects.</li>
          <li>Proper resource cleanup when a connection is removed.</li>
          <li>Use of proxies for statements/resultsets/connections/etc.
            <ul>
              <li>JDK 1.3 to get started--its easier to deal with</li>
              <li>BCEL for the next step--its faster to work with</li>
            </ul>
          </li>
        </ul>
      </section>
    </body>
  </document>
  
  
  
  1.1                  avalon-sandbox/datasource/src/xdocs/menu.xml
  
  Index: menu.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <project
        href="http://jakarta.apache.org/avalon/excalibur/datasource/";
        name="Avalon DataSource">
  
      <title>Avalon DataSource</title>
      <body>
          <menu name="About">
              <item name="Overview" href="/index.html"/>
              <item name="Excalibur Home" 
href="http://jakarta.apache.org/avalon/excalibur/index.html"/>
              <item name="Download" 
href="http://jakarta.apache.org/builds/jakarta-avalon-excalibur/release"/>
              <item name="API Docs" href="/api/"/>
          </menu>
      </body>
  </project>
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to