webwork/src/main/webwork/util BeanUtil.java,1.40,1.41

[email protected] Tue, 10 Aug 2004 07:57:30 -0700
Newsgroups gmane.comp.java.open-symphony.cvs
Message-ID <[email protected]>
Update of /cvsroot/opensymphony/webwork/src/main/webwork/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24512/src/main/webwork/util

Modified Files:
	BeanUtil.java 
Log Message:
More helpful error when failing to set properties, and static methods should be private, since the class is final

Index: BeanUtil.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/util/BeanUtil.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- BeanUtil.java	4 Jun 2004 07:57:24 -0000	1.40
+++ BeanUtil.java	10 Aug 2004 14:57:27 -0000	1.41
@@ -161,7 +161,8 @@
    public static void setProperties(Map from, Object to) throws IllegalArgumentException
    {
       String key = null;
-
+      Object value = null;
+     
       try
       {
          Iterator keys = from.keySet().iterator();
@@ -174,7 +175,8 @@
             key = (String) keys.next();
             try
             {
-               setProperty(key, from.get(key), to, fieldMap);
+               value = from.get(key);
+               setProperty(key, value, to, fieldMap);
             } catch (IllegalArgumentException e)
             {
                // Handle IEA's on actions specially
@@ -189,7 +191,7 @@
          }
       } catch (Throwable e)
       {
-         log.warn("Could not set parameter \"" + key + "\":" + e, e);
+         log.warn("Could not set parameter \"" + key + "\" with value \"" + value + "\" on class " + to.getClass()+ ":" + e, e);
          throw new IllegalArgumentException("Could not set parameter \"" + key + "\":" + e);
       }
    }
@@ -228,7 +230,7 @@
     * @param   fieldMap      Map with the PropertyDescriptors of the obj
     * @exception   IllegalArgumentException
     */
-   static protected void setProperty(String propertyName, Object val, Object obj, Map fieldMap) throws IllegalArgumentException
+   private static void setProperty(String propertyName, Object val, Object obj, Map fieldMap) throws IllegalArgumentException
    {
       Query query = Query.getQuery(propertyName);
       QuerySegment[] segments = query.getSegments();
@@ -276,7 +278,7 @@
             // Resource Bundle
             else if (ResourceBundle.class.isAssignableFrom(curObject.getClass()))
             {
-               curObject = ((ResourceBundle) curObject).getObject(key.toString());
+               curObject = ((ResourceBundle) curObject).getObject(key);
             }
             // Array
             else if (curObject.getClass().isArray())
@@ -533,7 +535,7 @@
     *
     * @exception   IllegalArgumentException
     */
-   static protected boolean setValue(Object obj, PropertyDescriptor descriptor, Object val) throws IllegalArgumentException
+   private static boolean setValue(Object obj, PropertyDescriptor descriptor, Object val) throws IllegalArgumentException
    {
       if (descriptor == null || descriptor.getWriteMethod() == null)
       {
@@ -605,7 +607,7 @@
     *
     * @exception   IllegalArgumentException
     */
-   static protected boolean setIndexedValue(Object obj, IndexedPropertyDescriptor descriptor, Object val, Integer index)
+   private static boolean setIndexedValue(Object obj, IndexedPropertyDescriptor descriptor, Object val, Integer index)
    {
       if (descriptor == null)
       {
@@ -757,7 +759,7 @@
     *
     * @exception   IllegalArgumentException
     */
-   static protected boolean setStringValueDirectly(Object obj, PropertyDescriptor descriptor, String[] values) throws IllegalArgumentException
+   private static boolean setStringValueDirectly(Object obj, PropertyDescriptor descriptor, String[] values) throws IllegalArgumentException
    {
       try
       {
@@ -797,7 +799,7 @@
     *
     * @exception   IllegalArgumentException
     */
-   static protected void setStringValueWithPropertyEditor(Object obj, PropertyDescriptor descriptor, String[] values, Class paramClass) throws IllegalArgumentException
+   private static void setStringValueWithPropertyEditor(Object obj, PropertyDescriptor descriptor, String[] values, Class paramClass) throws IllegalArgumentException
    {
       try
       {
@@ -866,7 +868,7 @@
     *
     * @exception   IllegalArgumentException
     */
-   static protected void setIndexedStringValueWithPropertyEditor(Object obj, IndexedPropertyDescriptor descriptor, String[] values, Integer index) throws IllegalArgumentException
+   private static void setIndexedStringValueWithPropertyEditor(Object obj, IndexedPropertyDescriptor descriptor, String[] values, Integer index) throws IllegalArgumentException
    {
       try
       {
@@ -905,12 +907,12 @@
     *
     * @exception   IllegalArgumentException
     */
-   static protected boolean setIndexedStringValueDirectly(Object obj, IndexedPropertyDescriptor descriptor, String[] values, Integer index) throws IllegalArgumentException
+   private static boolean setIndexedStringValueDirectly(Object obj, IndexedPropertyDescriptor descriptor, String[] values, Integer index) throws IllegalArgumentException
    {
       try
       {
          Method m = descriptor.getIndexedWriteMethod();
-         if ((descriptor.getIndexedPropertyType().equals(String.class)) || (descriptor.getIndexedPropertyType().equals(Object.class)))
+         if (descriptor.getIndexedPropertyType().equals(String.class) || descriptor.getIndexedPropertyType().equals(Object.class))
          {
             InjectionUtils.invoke(m, obj, new Object[]{index, values[0]});
             return true;
@@ -949,7 +951,7 @@
     * @param   property        the property that we are interested in
     * @param   obj             the object we want the property descriptor for
     */
-   static protected PropertyDescriptor getPropertyDescriptor(String property, Object obj)
+   private static PropertyDescriptor getPropertyDescriptor(String property, Object obj)
    {
       Map fieldMap = getFieldMapForClass(obj.getClass());
       return (PropertyDescriptor) fieldMap.get(property);
@@ -961,7 +963,7 @@
     *
     * @param   objClass          the object we want to build the field map for
     */
-   static protected Map getFieldMapForClass(Class objClass)
+   private static Map getFieldMapForClass(Class objClass)
    {
       Map fieldMap = (Map) objectMap.get(objClass);
       if (fieldMap == null)
@@ -981,7 +983,7 @@
     * @param   objClass        the object we want to build the field map for
     * @return  a Map with the keys being property names and values being PropertyDescriptors
     */
-   static protected Map buildFieldMap(Class objClass)
+   private static Map buildFieldMap(Class objClass)
    {
       Map fieldMap = new WeakHashMap();
       PropertyDescriptor[] descriptors = getPropertyDescriptors(objClass);
@@ -1002,7 +1004,7 @@
     * @param   descriptor          PropertyDescriptor
     * @return  the PropertyEditor
     */
-   static protected PropertyEditor getPropertyEditor(PropertyDescriptor descriptor)
+   private static PropertyEditor getPropertyEditor(PropertyDescriptor descriptor)
    {
       Class peClass = descriptor.getPropertyEditorClass();
       try
@@ -1034,7 +1036,7 @@
     * @param      objClass
     * @return     array of property descriptors
     */
-   protected synchronized static PropertyDescriptor[] getPropertyDescriptors(Class objClass)
+   private static synchronized PropertyDescriptor[] getPropertyDescriptors(Class objClass)
    {
       PropertyDescriptor[] descriptors = (PropertyDescriptor[]) propertyDescriptors.get(objClass);
 



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285