You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sa...@apache.org on 2002/01/23 23:32:53 UTC

cvs commit: jakarta-commons/beanutils/src/java/org/apache/commons/beanutils BeanUtils.java MappedPropertyDescriptor.java MethodUtils.java package.html

sanders     02/01/23 14:32:53

  Modified:    beanutils RELEASE-NOTES.txt STATUS.html build.xml
               beanutils/src/java/org/apache/commons/beanutils
                        BeanUtils.java MappedPropertyDescriptor.java
                        MethodUtils.java package.html
  Log:
  BeanUtils now uses logging.  Added to build.xml, removed any
  System.out.println(), made some exception messages more informative.
  
  Revision  Changes    Path
  1.3       +4 -1      jakarta-commons/beanutils/RELEASE-NOTES.txt
  
  Index: RELEASE-NOTES.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/RELEASE-NOTES.txt,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RELEASE-NOTES.txt	4 Jan 2002 21:24:37 -0000	1.2
  +++ RELEASE-NOTES.txt	23 Jan 2002 22:32:53 -0000	1.3
  @@ -1,4 +1,4 @@
  -$Id: RELEASE-NOTES.txt,v 1.2 2002/01/04 21:24:37 sanders Exp $
  +$Id: RELEASE-NOTES.txt,v 1.3 2002/01/23 22:32:53 sanders Exp $
   
                             Commons BeanUtils Package
                                   Version 1.3
  @@ -25,6 +25,9 @@
     located at http://java.sun.com/products/javabeans/docs/beans.101.pdf and we
     violating section 8.3.3 ;-)  We hope that eventually the JavaBeans spec might
     be updated to include this feature.
  +
  +* Logging - BeanUtils now uses the commons-logging API to do any logging.
  +  System.out.println() has been deprecated ;-)
   
   
   BUG FIXES:
  
  
  
  1.6       +9 -1      jakarta-commons/beanutils/STATUS.html
  
  Index: STATUS.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/STATUS.html,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- STATUS.html	4 Jan 2002 21:24:37 -0000	1.5
  +++ STATUS.html	23 Jan 2002 22:32:53 -0000	1.6
  @@ -7,7 +7,7 @@
   
   <div align="center">
   <h1>The Jakarta Commons <em>BeanUtils</em> Component</h1>
  -$Id: STATUS.html,v 1.5 2002/01/04 21:24:37 sanders Exp $<br>
  +$Id: STATUS.html,v 1.6 2002/01/23 22:32:53 sanders Exp $<br>
   <a href="#Introduction">[Introduction]</a>
   <a href="#Dependencies">[Dependencies]</a>
   <a href="#Release Info">[Release Info]</a>
  @@ -53,6 +53,8 @@
       (Version 1.2 or later)</li>
   <li><a href="http://jakarta.apache.org/commons">Collections Classes</a>
       from the Jakarta Commons Subproject</li>
  +<li><a href="http://jakarta.apache.org/commons">Logging Classes</a>
  +    from the Jakarta Commons Subproject</li>
   <li><a href="http://www.junit.org">JUnit Testing Framework</a>
       (Version 3.7 or later) - for unit tests only, not required
       for deployment</li>
  @@ -107,6 +109,12 @@
       <td><strong>Install / Use Documentation</strong>.  Create simple
           installation and User's Guide documentation for this component.</td>
       <td align="center">Craig</td>
  +  </tr>
  +
  +  <tr>
  +    <td><strong>Logging</strong>.  Use the commons-logging API to ease logging
  +        integration woes.</td>
  +    <td align="center">Scott</td>
     </tr>
   
   </table>
  
  
  
  1.29      +10 -2     jakarta-commons/beanutils/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/build.xml,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- build.xml	21 Jan 2002 00:44:39 -0000	1.28
  +++ build.xml	23 Jan 2002 22:32:53 -0000	1.29
  @@ -3,7 +3,7 @@
   
   <!--
           "Bean Utilities" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.28 2002/01/21 00:44:39 craigmcc Exp $
  +        $Id: build.xml,v 1.29 2002/01/23 22:32:53 sanders Exp $
   -->
   
   
  @@ -21,6 +21,9 @@
     <!-- The home directory for the Commons collection classes distribution -->
     <property name="commons-collections.home" value="../collections/dist"/>
   
  +  <!-- The home directory for the Commons collection classes distribution -->
  +  <property name="commons-logging.home" value="../logging/dist"/>
  +
     <!-- The directory containing your binary distribution of JUnit,
          version 3.7 or later -->
     <property name="junit.home"              value="/usr/local/junit3.7"/>
  @@ -32,6 +35,9 @@
     <!-- The pathname of the collections classes JAR file -->
     <property name="commons-collections.jar" value="${commons-collections.home}/commons-collections.jar"/>
   
  +  <!-- The pathname of the logging classes JAR file -->
  +  <property name="commons-logging.jar" value="${commons-logging.home}/commons-logging.jar"/>
  +
     <!-- The pathname of the "junit.jar" JAR file -->
     <property name="junit.jar"               value="${junit.home}/junit.jar"/>
   
  @@ -83,6 +89,7 @@
     <path id="compile.classpath">
       <pathelement location="${build.home}/classes"/>
       <pathelement location="${commons-collections.jar}"/>
  +    <pathelement location="${commons-logging.jar}"/>
     </path>
   
   
  @@ -94,6 +101,7 @@
       <pathelement location="${build.home}/classes"/>
       <pathelement location="${build.home}/tests"/>
       <pathelement location="${commons-collections.jar}"/>
  +    <pathelement location="${commons-logging.jar}"/>
       <pathelement location="${junit.jar}"/>
     </path>
   
  @@ -190,7 +198,7 @@
               windowtitle="${component.title} (Version ${component.version})"
                    bottom="Copyright (c) 2001-2002 - Apache Software Foundation">
         <classpath refid="compile.classpath"/>
  -    </javadoc> 
  +    </javadoc>
     </target>
   
   
  
  
  
  1.9       +65 -54    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtils.java
  
  Index: BeanUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtils.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BeanUtils.java	21 Jan 2002 00:44:39 -0000	1.8
  +++ BeanUtils.java	23 Jan 2002 22:32:53 -0000	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtils.java,v 1.8 2002/01/21 00:44:39 craigmcc Exp $
  - * $Revision: 1.8 $
  - * $Date: 2002/01/21 00:44:39 $
  + * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtils.java,v 1.9 2002/01/23 22:32:53 sanders Exp $
  + * $Revision: 1.9 $
  + * $Date: 2002/01/23 22:32:53 $
    *
    * ====================================================================
    *
  @@ -78,6 +78,9 @@
   import java.util.Iterator;
   import java.util.Map;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogSource;
  +
   
   /**
    * Utility methods for populating JavaBeans properties via reflection.
  @@ -87,7 +90,7 @@
    * @author Chris Audley
    * @author Rey Fran�ois
    * @author Gregor Ra�man
  - * @version $Revision: 1.8 $ $Date: 2002/01/21 00:44:39 $
  + * @version $Revision: 1.9 $ $Date: 2002/01/23 22:32:53 $
    */
   
   public class BeanUtils {
  @@ -95,16 +98,31 @@
   
       // ------------------------------------------------------ Private Variables
   
  +    /**
  +     * All logging goes through this logger
  +     */
  +    private static Log log = LogSource.getInstance(BeanUtils.class);
   
       /**
        * The debugging detail level for this component.
  +     * Deprecated: use the log variable
        */
       private static int debug = 0;
   
  +    /**
  +     * @deprecated BeanUtils now uses commons-logging for all log messages.
  +     *             Use your favorite logging tool to configure logging for
  +     *             this class.
  +     */
       public static int getDebug() {
           return (debug);
       }
   
  +    /**
  +     * @deprecated BeanUtils now uses commons-logging for all log messages.
  +     *             Use your favorite logging tool to configure logging for
  +     *             this class.
  +     */
       public static void setDebug(int newDebug) {
           debug = newDebug;
       }
  @@ -132,6 +150,9 @@
           throws IllegalAccessException, InstantiationException,
                  InvocationTargetException, NoSuchMethodException {
   
  +        if (log.isDebugEnabled()) {
  +            log.debug("Cloning bean: " + bean.getClass().getName());
  +        }
           Class clazz = bean.getClass();
           Object newBean = clazz.newInstance();
           PropertyUtils.copyProperties(newBean, bean);
  @@ -160,6 +181,9 @@
           throws IllegalAccessException, InvocationTargetException,
                  NoSuchMethodException {
   
  +        if (log.isDebugEnabled()) {
  +            log.debug("Describing bean: " + bean.getClass().getName());
  +        }
           if (bean == null)
               //            return (Collections.EMPTY_MAP);
               return (new java.util.HashMap());
  @@ -447,11 +471,10 @@
           if ((bean == null) || (properties == null))
               return;
   
  -        /*
  -        if (debug >= 1)
  -            System.out.println("BeanUtils.populate(" + bean + ", " +
  +        if (log.isDebugEnabled()) {
  +            log.debug("BeanUtils.populate(" + bean + ", " +
                                  properties + ")");
  -        */
  +        }
   
           // Loop through the property name/value pairs to be set
           Iterator names = properties.keySet().iterator();
  @@ -463,12 +486,11 @@
                   continue;
               Object value = properties.get(name);	// String or String[]
   
  -            /*
  -            if (debug >= 1)
  -                System.out.println("  name='" + name + "', value.class='" +
  +            if (log.isDebugEnabled()) {
  +                log.debug("  name='" + name + "', value.class='" +
                                      (value == null ? "NONE" :
                                      value.getClass().getName()) + "'");
  -            */
  +            }
   
               // Get the property descriptor of the requested property (if any)
               PropertyDescriptor descriptor = null;
  @@ -482,25 +504,27 @@
                           PropertyUtils.getPropertyDescriptor(bean, name);
                   }
               } catch (Throwable t) {
  -                /*
  -                if (debug >= 1)
  -                    System.out.println("    getPropertyDescriptor: " + t);
  -                */
  +
  +                if (log.isDebugEnabled()) {
  +                    log.debug("    getPropertyDescriptor: " + t);
  +                }
  +
                   descriptor = null;
                   dynaProperty = null;
               }
               if ((descriptor == null) && (dynaProperty == null)) {
  -                /*
  -                if (debug >= 1)
  -                    System.out.println("    No such property, skipping");
  -                */
  +
  +                if (log.isDebugEnabled()) {
  +                    log.debug("    No such property, skipping");
  +                }
  +
                   continue;
               }
  -            /*
  -            if (debug >= 1)
  -                System.out.println("    Property descriptor is '" +
  +
  +            if (log.isDebugEnabled())
  +                log.debug("    Property descriptor is '" +
                                      descriptor + "'");
  -            */
  +
   
               // Process differently for JavaBeans and DynaBeans
               if (descriptor != null) {
  @@ -516,22 +540,24 @@
                   if (setter == null)
                       setter = descriptor.getWriteMethod();
                   if (setter == null) {
  -                    /*
  -                      if (debug >= 1)
  -                      System.out.println("    No setter method, skipping");
  -                    */
  +
  +                    if (log.isDebugEnabled()) {
  +                        System.out.println("    No setter method, skipping");
  +                    }
  +
                       continue;
                   }
                   Class parameterTypes[] = setter.getParameterTypes();
  -                /*
  -                  if (debug >= 1)
  -                  System.out.println("    Setter method is '" +
  -                  setter.getName() + "(" +
  -                  parameterTypes[0].getName() +
  -                  (parameterTypes.length > 1 ?
  -                  ", " + parameterTypes[1].getName() : "" )
  -                  + ")'");
  -                */
  +
  +                if (log.isDebugEnabled()) {
  +                    log.debug("    Setter method is '" +
  +                        setter.getName() + "(" +
  +                        parameterTypes[0].getName() +
  +                        (parameterTypes.length > 1 ?
  +                        ", " + parameterTypes[1].getName() : "" )
  +                        + ")'");
  +                }
  +
                   Class parameterType = parameterTypes[0];
                   if (parameterTypes.length > 1)
                       parameterType = parameterTypes[1];      // Indexed or mapped setter
  @@ -566,12 +592,7 @@
                   try {
                       PropertyUtils.setProperty(bean, name, parameters[0]);
                   } catch (NoSuchMethodException e) {
  -                    /*
  -                      if (debug >= 1) {
  -                      System.out.println("    CANNOT HAPPEN: " + e);
  -                      e.printStackTrace(System.out);
  -                      }
  -                    */
  +                    log.error("  CANNOT HAPPEN (setProperty()): ", e);
                   }
   
               } else {
  @@ -607,23 +628,13 @@
                   try {
                       PropertyUtils.setProperty(bean, name, newValue);
                   } catch (NoSuchMethodException e) {
  -                    /*
  -                      if (debug >= 1) {
  -                      System.out.println("    CANNOT HAPPEN: " + e);
  -                      e.printStackTrace(System.out);
  -                      }
  -                    */
  +                    log.error("    CANNOT HAPPEN (setProperty())", e);
                   }
   
   
               }
   
           }
  -
  -        /*
  -        if (debug >= 1)
  -            System.out.println("============================================");
  -        */
   
       }
   
  
  
  
  1.6       +11 -8     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
  
  Index: MappedPropertyDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MappedPropertyDescriptor.java	21 Jan 2002 00:44:39 -0000	1.5
  +++ MappedPropertyDescriptor.java	23 Jan 2002 22:32:53 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java,v 1.5 2002/01/21 00:44:39 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/01/21 00:44:39 $
  + * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java,v 1.6 2002/01/23 22:32:53 sanders Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/01/23 22:32:53 $
    *
    * ====================================================================
    *
  @@ -83,7 +83,7 @@
    *
    * @author Rey Fran�ois
    * @author Gregor Ra�man
  - * @version $Revision: 1.5 $ $Date: 2002/01/21 00:44:39 $
  + * @version $Revision: 1.6 $ $Date: 2002/01/23 22:32:53 $
    */
   
   public class MappedPropertyDescriptor extends PropertyDescriptor {
  @@ -143,7 +143,8 @@
   
           super(propertyName, null, null);
           if (propertyName == null || propertyName.length() == 0) {
  -            throw new IntrospectionException("bad property name");
  +            throw new IntrospectionException("bad property name: " +
  +                    propertyName + " on class: " + beanClass.getClass().getName());
           }
           setName(propertyName);
           String base = capitalize(propertyName);
  @@ -191,7 +192,8 @@
   
           super(propertyName, null, null);
           if (propertyName == null || propertyName.length() == 0) {
  -            throw new IntrospectionException("bad property name");
  +            throw new IntrospectionException("bad property name: " +
  +                propertyName);
           }
           setName(propertyName);
   
  @@ -232,7 +234,8 @@
   
           super(propertyName, mappedGetter, mappedSetter);
           if (propertyName == null || propertyName.length() == 0) {
  -            throw new IntrospectionException("bad property name");
  +            throw new IntrospectionException("bad property name: " +
  +                propertyName);
           }
           setName(propertyName);
           mappedReadMethod = mappedGetter;
  @@ -518,7 +521,7 @@
                   return m;
               }
           }
  -        
  +
           return null;
   
       }
  
  
  
  1.4       +25 -24    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MethodUtils.java
  
  Index: MethodUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MethodUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MethodUtils.java	21 Jan 2002 00:44:39 -0000	1.3
  +++ MethodUtils.java	23 Jan 2002 22:32:53 -0000	1.4
  @@ -86,10 +86,10 @@
        * <p>Invoke a method whose parameter type matches exactly the object
        * type.</p>
        *
  -     * <p> This is a convenient wrapper for 
  +     * <p> This is a convenient wrapper for
        * {@link #invokeExactMethod(Object object,String methodName,Object [] args)}.
        * </p>
  -     *     
  +     *
        * @param object invoke method on this object
        * @param methodName get method with this name
        * @param arg use this argument
  @@ -112,7 +112,7 @@
   
           Object [] args = {arg};
           return invokeExactMethod(object, methodName, args);
  -        
  +
       }
   
   
  @@ -120,13 +120,13 @@
        * <p>Invoke a method whose parameter types match exactly the object
        * types.</p>
        *
  -     * <p> This uses reflection to invoke the method obtained from a call to 
  +     * <p> This uses reflection to invoke the method obtained from a call to
        * {@link #getAccessibleMethod}.</p>
  -     *     
  +     *
        * @param object invoke method on this object
        * @param methodName get method with this name
        * @param args use these arguments
  -     * 
  +     *
        * @throw NoSuchMethodException if there is no such accessible method
        * @throw InvocationTargetException wraps an exception thrown by the
        *  method invoked
  @@ -148,7 +148,7 @@
           for (int i=0; i<arguments ;i++)
           {
               parameterTypes[i] = args[i].getClass();
  -        }       
  +        }
           return invokeExactMethod(object, methodName, args, parameterTypes);
   
       }
  @@ -158,14 +158,14 @@
        * <p>Invoke a method whose parameter types match exactly the parameter
        * types given.</p>
        *
  -     * <p>This uses reflection to invoke the method obtained from a call to 
  +     * <p>This uses reflection to invoke the method obtained from a call to
        * {@link #getAccessibleMethod}.</p>
  -     *     
  +     *
        * @param object invoke method on this object
        * @param methodName get method with this name
        * @param args use these arguments
        * @param parameterTypes match these parameters
  -     * 
  +     *
        * @throw NoSuchMethodException if there is no such accessible method
        * @throw InvocationTargetException wraps an exception thrown by the
        *  method invoked
  @@ -181,14 +181,15 @@
                           NoSuchMethodException,
                           IllegalAccessException,
                           InvocationTargetException
  -    {      
  +    {
   
           Method method = getAccessibleMethod(
                                           object.getClass(),
                                           methodName,
                                           parameterTypes);
           if (method == null)
  -            throw new NoSuchMethodException("No such accessible method.");
  +            throw new NoSuchMethodException("No such accessible method: " +
  +                    methodName + "() on object: " + object.getClass().getName());
           return method.invoke(object, args);
   
       }
  @@ -197,30 +198,30 @@
       /**
        * <p>Return an accessible method (that is, one that can be invoked via
        * reflection) with given name and a single parameter.  If no such method
  -     * can be found, return <code>null</code>. 
  +     * can be found, return <code>null</code>.
        * Basically, a convenience wrapper that constructs a <code>Class</code>
        * array for you.</p>
        *
        * @param clazz get method from this class
        * @param methodName get method with this name
  -     * @param parameterType taking this type of parameter 
  +     * @param parameterType taking this type of parameter
        */
       public static Method getAccessibleMethod(
  -                Class clazz, 
  -                String methodName, 
  -                Class parameterType) 
  +                Class clazz,
  +                String methodName,
  +                Class parameterType)
       {
   
           Class [] parameterTypes = {parameterType};
           return getAccessibleMethod(clazz, methodName, parameterTypes);
   
  -    } 
  -    
  - 
  +    }
  +
  +
       /**
        * <p>Return an accessible method (that is, one that can be invoked via
        * reflection) with given name and parameters.  If no such method
  -     * can be found, return <code>null</code>. 
  +     * can be found, return <code>null</code>.
        * This is just a convenient wrapper for
        * {@link #getAccessibleMethod(Method method)}.</p>
        *
  @@ -229,9 +230,9 @@
        * @param parameterTypes with these parameters types
        */
       public static Method getAccessibleMethod(
  -                Class clazz, 
  -                String methodName, 
  -                Class[] parameterTypes) 
  +                Class clazz,
  +                String methodName,
  +                Class[] parameterTypes)
       {
   
           try {
  
  
  
  1.5       +2 -0      jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/package.html
  
  Index: package.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/package.html,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- package.html	21 Jan 2002 20:03:43 -0000	1.4
  +++ package.html	23 Jan 2002 22:32:53 -0000	1.5
  @@ -142,6 +142,8 @@
   <ul>
   <li><a href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-collections">
   Collections Package (Jakarta Commons)</a>, version 1.0 or later</li>
  +<li><a href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-logging">
  +Logging Package (Jakarta Commons)</a>, version 1.0 or later</li>
   </ul>
   
   
  
  
  

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