struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject svn commit: r369992 - in /struts/shale/trunk/tiger: nbproject/private/ src/java/org/apache/shale/tiger/faces/ src/test/org/apache/shale/tiger/config/ src/test/org/apache/shale/tiger/faces/
Date Wed, 18 Jan 2006 00:58:17 GMT
Author: craigmcc
Date: Tue Jan 17 16:58:12 2006
New Revision: 369992

URL: http://svn.apache.org/viewcvs?rev=369992&view=rev
Log:
In VariableResolverImpl, remove direct dependency on Commons BeanUtils by
using the new helper methods for property access and conversion.  As a side
effect of this change, also change the unit tests that specified properties
of type java.sql.Date, since JSF does not supply a standard converter for this,
while BeanUtils did.

Modified:
    struts/shale/trunk/tiger/nbproject/private/private.xml
    struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/VariableResolverImpl.java
    struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/FacesConfigParserTestCase.java
    struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-4.xml
    struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-5.xml
    struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl4TestCase.java
    struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl5TestCase.java

Modified: struts/shale/trunk/tiger/nbproject/private/private.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/nbproject/private/private.xml?rev=369992&r1=369991&r2=369992&view=diff
==============================================================================
--- struts/shale/trunk/tiger/nbproject/private/private.xml (original)
+++ struts/shale/trunk/tiger/nbproject/private/private.xml Tue Jan 17 16:58:12 2006
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
-    <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
-</project-private>
+<?xml version="1.0" encoding="UTF-8"?>
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+    <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
+</project-private>

Modified: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/VariableResolverImpl.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/VariableResolverImpl.java?rev=369992&r1=369991&r2=369992&view=diff
==============================================================================
--- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/VariableResolverImpl.java
(original)
+++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/faces/VariableResolverImpl.java
Tue Jan 17 16:58:12 2006
@@ -23,12 +23,9 @@
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
 import javax.faces.el.ValueBinding;
 import javax.faces.el.VariableResolver;
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.ConversionException;
-import org.apache.commons.beanutils.ConvertUtils;
-import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.shale.tiger.config.FacesConfigConfig;
@@ -40,7 +37,9 @@
 import org.apache.shale.tiger.managed.config.ManagedPropertyConfig;
 import org.apache.shale.tiger.managed.config.MapEntriesConfig;
 import org.apache.shale.tiger.managed.config.MapEntryConfig;
+import org.apache.shale.util.ConverterHelper;
 import org.apache.shale.util.Messages;
+import org.apache.shale.util.PropertyHelper;
 
 /**
  * <p>Implementation of <code>VariableResolver</code> that delegates
@@ -101,6 +100,12 @@
 
 
     /**
+     * <p>Helper bean for performing conversions.</p>
+     */
+    private ConverterHelper convHelper = new ConverterHelper();
+
+
+    /**
      * <p>Log instance for this class.</p>
      */
     private transient Log log = null;
@@ -119,6 +124,13 @@
     private VariableResolver original = null;
 
 
+    /**
+     * <p>Helper bean for accessing properties.</p>
+     */
+    private PropertyHelper propHelper = new PropertyHelper();
+
+
+
     // ----------------------------------------------- VariableResolver Methods
 
 
@@ -193,60 +205,6 @@
 
 
     /**
-     * <p>Convert the specified value to the specified type.</p>
-     *
-     * @param context <code>FacesContext</code> for the current request
-     * @param type Type to which the value should be converted, or
-     *  <code>null</code> to leave it as a string
-     * @param value Value to be converted
-     *
-     * @exception EvaluationException if an evaluation error occurs
-     */
-    private Object convert(FacesContext context, Class type, String value) {
-
-        // If the type is not specified, return the value unchanged
-        if (type == null) {
-            return value;
-        }
-
-        // Handle primitive type conversions explicitly
-        try {
-            if ((type == Boolean.TYPE) || (type == Boolean.class)) {
-                return Boolean.valueOf(value);
-            } else if ((type == Byte.TYPE) || (type == Byte.class)) {
-                return Byte.valueOf(value);
-            } else if ((type == Double.TYPE) || (type == Double.class)) {
-                return Double.valueOf(value);
-            } else if ((type == Float.TYPE) || (type == Float.class)) {
-                return Float.valueOf(value);
-            } else if ((type == Integer.TYPE) || (type == Integer.class)) {
-                return Integer.valueOf(value);
-            } else if ((type == Long.TYPE) || (type == Long.class)) {
-                return Long.valueOf(value);
-            } else if ((type == Short.TYPE) || (type == Short.class)) {
-                return Short.valueOf(value);
-            }
-        } catch (NumberFormatException e) {
-            throw new EvaluationException(messages().
-                getMessage("convert.format",
-                           context.getViewRoot().getLocale(),
-                           new Object[] { value, type.getName() }), e);
-        }
-
-        // For all other cases, use the conversion utility
-        try {
-            return ConvertUtils.convert(value, type);
-        } catch (ConversionException e) {
-            throw new EvaluationException(messages().
-                getMessage("convert.exception",
-                           context.getViewRoot().getLocale(),
-                           new Object[] { value, type.getName() }), e);
-        }
-
-    }
-
-
-    /**
      * <p>Create, configure, and return a new instance based on the
      * specified managed bean, after storing it in the configured
      * scope (if any).</p>
@@ -390,7 +348,11 @@
                     context.getApplication().createValueBinding(entry.getValue());
                 list.add(vb.getValue(context));
             } else {
-                list.add(convert(context, type, entry.getValue()));
+                if (type != null) {
+                    list.add(convHelper.asObject(context, type, entry.getValue()));
+                } else {
+                    list.add(entry.getValue());
+                }
             }
         }
 
@@ -455,7 +417,12 @@
 
         // Add a map key/value pair for each configuration element that is present
         for (MapEntryConfig entry : config.getEntries()) {
-            Object key = convert(context, keyClass, entry.getKey());
+            Object key = null;
+            if (keyClass != null) {
+                key = convHelper.asObject(context, keyClass, entry.getKey());
+            } else {
+                key = entry.getKey();
+            }
             if (entry.isNullValue()) {
                 map.put(key, null);
             } else if (entry.isExpression()) {
@@ -464,7 +431,11 @@
                     context.getApplication().createValueBinding(entry.getValue());
                 map.put(key, vb.getValue(context));
             } else {
-                map.put(key, convert(context, valueClass, entry.getValue()));
+                if (valueClass != null) {
+                    map.put(key, convHelper.asObject(context, valueClass, entry.getValue()));
+                } else {
+                    map.put(key, entry.getValue());
+                }
             }
         }
 
@@ -509,8 +480,9 @@
             // specified instance, if it exists
             Object property = null;
             try {
-                property = PropertyUtils.getProperty(instance, mp.getName());
-            } catch (NoSuchMethodException e) {
+                property = propHelper.getValue(instance, mp.getName());
+//                property = PropertyUtils.getProperty(instance, mp.getName());
+            } catch (PropertyNotFoundException e) {
                 ; // Fall through to creating our own list
             } catch (Exception e) {
                 throw new EvaluationException(messages().
@@ -535,7 +507,8 @@
 
             // Store the value of the property
             try {
-                BeanUtils.setProperty(instance, mp.getName(), property);
+                propHelper.setValue(instance, mp.getName(), property);
+//                BeanUtils.setProperty(instance, mp.getName(), property);
             } catch (Exception e) {
                 throw new EvaluationException(messages().
                     getMessage("list.set",
@@ -556,8 +529,9 @@
             // specified instance, if it exists
             Object property = null;
             try {
-                property = PropertyUtils.getProperty(instance, mp.getName());
-            } catch (NoSuchMethodException e) {
+                property = propHelper.getValue(instance, mp.getName());
+//                property = PropertyUtils.getProperty(instance, mp.getName());
+            } catch (PropertyNotFoundException e) {
                 ; // Fall through to creating our own map
             } catch (Exception e) {
                 throw new EvaluationException(messages().
@@ -581,7 +555,8 @@
 
             // Store the value of the property
             try {
-                BeanUtils.setProperty(instance, mp.getName(), property);
+                propHelper.setValue(instance, mp.getName(), property);
+//                BeanUtils.setProperty(instance, mp.getName(), property);
             } catch (Exception e) {
                 throw new EvaluationException(messages().
                     getMessage("map.set",
@@ -615,7 +590,11 @@
 
         // Assign the acquired value to the specified bean property
         try {
-            BeanUtils.setProperty(instance, mp.getName(), value);
+            Class type = propHelper.getType(instance, mp.getName());
+            if ((value != null) && (value instanceof String)) {
+                value = convHelper.asObject(context, type, (String) value);
+            }
+            propHelper.setValue(instance, mp.getName(), value);
         } catch (Exception e) {
             throw new EvaluationException(messages().
                 getMessage("variable.evaluate",

Modified: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/FacesConfigParserTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/FacesConfigParserTestCase.java?rev=369992&r1=369991&r2=369992&view=diff
==============================================================================
--- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/FacesConfigParserTestCase.java
(original)
+++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/FacesConfigParserTestCase.java
Tue Jan 17 16:58:12 2006
@@ -106,9 +106,9 @@
         assertEquals(4, facesConfig.getManagedBeans().size());
 
         // Validate bean "explicitSqlDateList"
-        mb = facesConfig.getManagedBean("explicitSqlDateList");
+        mb = facesConfig.getManagedBean("explicitIntegerList");
         assertNotNull(mb);
-        assertEquals("explicitSqlDateList", mb.getName());
+        assertEquals("explicitIntegerList", mb.getName());
         assertEquals("none", mb.getScope());
         assertEquals("java.util.Vector", mb.getType());
         assertNotNull(mb.getListEntries());
@@ -116,18 +116,18 @@
         assertEquals(0, mb.getProperties().size());
 
         entries = mb.getListEntries();
-        assertEquals("java.sql.Date", entries.getValueType());
+        assertEquals("java.lang.Integer", entries.getValueType());
         assertEquals(4, entries.getEntries().size());
         entry = entries.getEntries().get(0);
         assertNotNull(entry);
         assertTrue(!entry.isExpression());
         assertTrue(!entry.isNullValue());
-        assertEquals("2006-01-02", entry.getValue());
+        assertEquals("123", entry.getValue());
         entry = entries.getEntries().get(1);
         assertNotNull(entry);
         assertTrue(!entry.isExpression());
         assertTrue(!entry.isNullValue());
-        assertEquals("2006-03-04", entry.getValue());
+        assertEquals("234", entry.getValue());
         entry = entries.getEntries().get(2);
         assertNotNull(entry);
         assertTrue(!entry.isExpression());
@@ -137,7 +137,7 @@
         assertNotNull(entry);
         assertTrue(!entry.isExpression());
         assertTrue(!entry.isNullValue());
-        assertEquals("2006-05-06", entry.getValue());
+        assertEquals("345", entry.getValue());
 
         // Validate bean "explicitStringList"
         mb = facesConfig.getManagedBean("explicitStringList");
@@ -272,9 +272,9 @@
         assertEquals(2, facesConfig.getManagedBeans().size());
 
         // Validate bean "stringDateMap"
-        mb = facesConfig.getManagedBean("stringDateMap");
+        mb = facesConfig.getManagedBean("stringIntegerMap");
         assertNotNull(mb);
-        assertEquals("stringDateMap", mb.getName());
+        assertEquals("stringIntegerMap", mb.getName());
         assertEquals("none", mb.getScope());
         assertEquals("java.util.TreeMap", mb.getType());
         assertNull(mb.getListEntries());
@@ -283,18 +283,18 @@
 
         entries = mb.getMapEntries();
         assertEquals("java.lang.String", entries.getKeyType());
-        assertEquals("java.sql.Date", entries.getValueType());
+        assertEquals("java.lang.Integer", entries.getValueType());
         assertEquals(4, entries.getEntries().size());
 
         entry = entries.getEntries().get(0);
         assertEquals("First", entry.getKey());
-        assertEquals("2006-01-02", entry.getValue());
+        assertEquals("123", entry.getValue());
         assertTrue(!entry.isExpression());
         assertTrue(!entry.isNullValue());
 
         entry = entries.getEntries().get(1);
         assertEquals("Second", entry.getKey());
-        assertEquals("2006-03-04", entry.getValue());
+        assertEquals("234", entry.getValue());
         assertTrue(!entry.isExpression());
         assertTrue(!entry.isNullValue());
 
@@ -306,7 +306,7 @@
 
         entry = entries.getEntries().get(3);
         assertEquals("Fourth", entry.getKey());
-        assertEquals("2006-05-06", entry.getValue());
+        assertEquals("345", entry.getValue());
         assertTrue(!entry.isExpression());
         assertTrue(!entry.isNullValue());
 

Modified: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-4.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-4.xml?rev=369992&r1=369991&r2=369992&view=diff
==============================================================================
--- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-4.xml (original)
+++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-4.xml Tue
Jan 17 16:58:12 2006
@@ -29,15 +29,15 @@
     <!-- Configure a variety of managed beans that are actually lists -->
 
     <managed-bean>
-        <managed-bean-name>explicitSqlDateList</managed-bean-name>
+        <managed-bean-name>explicitIntegerList</managed-bean-name>
         <managed-bean-class>java.util.Vector</managed-bean-class>
         <managed-bean-scope>none</managed-bean-scope>
         <list-entries>
-            <value-class>java.sql.Date</value-class>
-            <value>2006-01-02</value>
-            <value>2006-03-04</value>
+            <value-class>java.lang.Integer</value-class>
+            <value>123</value>
+            <value>234</value>
             <null-value/>
-            <value>2006-05-06</value>
+            <value>345</value>
         </list-entries>
     </managed-bean>
 

Modified: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-5.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-5.xml?rev=369992&r1=369991&r2=369992&view=diff
==============================================================================
--- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-5.xml (original)
+++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/config/test-config-5.xml Tue
Jan 17 16:58:12 2006
@@ -29,19 +29,19 @@
     <!-- Configure a managed bean that is actually a map -->
 
     <managed-bean>
-        <managed-bean-name>stringDateMap</managed-bean-name>
+        <managed-bean-name>stringIntegerMap</managed-bean-name>
         <managed-bean-class>java.util.TreeMap</managed-bean-class>
         <managed-bean-scope>none</managed-bean-scope>
         <map-entries>
             <key-class>java.lang.String</key-class>
-            <value-class>java.sql.Date</value-class>
+            <value-class>java.lang.Integer</value-class>
             <map-entry>
                 <key>First</key>
-                <value>2006-01-02</value>
+                <value>123</value>
             </map-entry>
             <map-entry>
                 <key>Second</key>
-                <value>2006-03-04</value>
+                <value>234</value>
             </map-entry>
             <map-entry>
                 <key>Third</key>
@@ -49,7 +49,7 @@
             </map-entry>
             <map-entry>
                 <key>Fourth</key>
-                <value>2006-05-06</value>
+                <value>345</value>
             </map-entry>
         </map-entries>
     </managed-bean>

Modified: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl4TestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl4TestCase.java?rev=369992&r1=369991&r2=369992&view=diff
==============================================================================
--- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl4TestCase.java
(original)
+++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl4TestCase.java
Tue Jan 17 16:58:12 2006
@@ -110,19 +110,19 @@
     // ------------------------------------------------------------ Test Methods
 
 
-    // Test creating bean "explicitSqlDateList"
-    public void testExplicitSqlDateList() {
+    // Test creating bean "explicitIntegerList"
+    public void testExplicitIntegerList() {
 
-        Object instance = resolver.resolveVariable(facesContext, "explicitSqlDateList");
+        Object instance = resolver.resolveVariable(facesContext, "explicitIntegerList");
         assertNotNull(instance);
         assertTrue(instance instanceof Vector);
         List list = (List) instance;
         assertEquals(4, list.size());
 
-        assertEquals(new Date(106, 0, 2), list.get(0));
-        assertEquals(new Date(106, 2, 4), list.get(1));
+        assertEquals(new Integer(123), list.get(0));
+        assertEquals(new Integer(234), list.get(1));
         assertNull(list.get(2));
-        assertEquals(new Date(106, 4, 6), list.get(3));
+        assertEquals(new Integer(345), list.get(3));
 
     }
 

Modified: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl5TestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl5TestCase.java?rev=369992&r1=369991&r2=369992&view=diff
==============================================================================
--- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl5TestCase.java
(original)
+++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/faces/VariableResolverImpl5TestCase.java
Tue Jan 17 16:58:12 2006
@@ -111,19 +111,19 @@
     // ------------------------------------------------------------ Test Methods
 
 
-    // Test creating bean "stringDateMap"
-    public void testStringDateMap() {
+    // Test creating bean "stringIntegerMap"
+    public void testStringIntegerMap() {
 
-        Object instance = resolver.resolveVariable(facesContext, "stringDateMap");
+        Object instance = resolver.resolveVariable(facesContext, "stringIntegerMap");
         assertNotNull(instance);
         assertTrue(instance instanceof TreeMap);
         Map map = (Map) instance;
         assertEquals(4, map.size());
 
-        assertEquals(new Date(106, 0, 2), map.get("First"));
-        assertEquals(new Date(106, 2, 4), map.get("Second"));
+        assertEquals(new Integer(123), map.get("First"));
+        assertEquals(new Integer(234), map.get("Second"));
         assertNull(map.get("Third"));
-        assertEquals(new Date(106, 4, 6), map.get("Fourth"));
+        assertEquals(new Integer(345), map.get("Fourth"));
 
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message