struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject svn commit: r369703 - /struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockApplication.java
Date Tue, 17 Jan 2006 07:07:49 GMT
Author: craigmcc
Date: Mon Jan 16 23:07:46 2006
New Revision: 369703

URL: http://svn.apache.org/viewcvs?rev=369703&view=rev
Log:
Implement support for by-type converters (as well as by-id).

Preregister all the standard by-type and by-id converters that a standard
JSF implementation does.

Modified:
    struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockApplication.java

Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockApplication.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockApplication.java?rev=369703&r1=369702&r2=369703&view=diff
==============================================================================
--- struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockApplication.java
(original)
+++ struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockApplication.java
Mon Jan 16 23:07:46 2006
@@ -58,6 +58,7 @@
         setActionListener(new MockActionListener());
         components = new HashMap();
         converters = new HashMap();
+        converters1 = new HashMap();
         setDefaultLocale(Locale.getDefault());
         setDefaultRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
         setNavigationHandler(new MockNavigationHandler());
@@ -68,6 +69,37 @@
         setVariableResolver(new MockVariableResolver());
         setViewHandler(new MockViewHandler());
 
+        // Register the standard by-id converters
+        addConverter("javax.faces.BigDecimal", "javax.faces.convert.BigDecimalConverter");
+        addConverter("javax.faces.BigInteger", "javax.faces.convert.BigIntegerConverter");
+        addConverter("javax.faces.Boolean",    "javax.faces.convert.BooleanConverter");
+        addConverter("javax.faces.Byte",       "javax.faces.convert.ByteConverter");
+        addConverter("javax.faces.Character",  "javax.faces.convert.CharacterConverter");
+        addConverter("javax.faces.DateTime",   "javax.faces.convert.DateTimeConverter");
+        addConverter("javax.faces.Double",     "javax.faces.convert.DoubleConverter");
+        addConverter("javax.faces.Float",      "javax.faces.convert.FloatConverter");
+        addConverter("javax.faces.Integer",    "javax.faces.Convert.IntegerConverter");
+        addConverter("javax.faces.Long",       "javax.faces.convert.LongConverter");
+        addConverter("javax.faces.Number",     "javax.faces.convert.NumberConverter");
+        addConverter("javax.faces.Short",      "javax.faces.convert.ShortConverter");
+
+        // Register the standard by-type converters
+        addConverter(Boolean.class,            "javax.faces.convert.BooleanConverter");
+        addConverter(Boolean.TYPE,             "javax.faces.convert.BooleanConverter");
+        addConverter(Byte.class,               "javax.faces.convert.ByteConverter");
+        addConverter(Byte.TYPE,                "javax.faces.convert.ByteConverter");
+        addConverter(Character.class,          "javax.faces.convert.CharacterConverter");
+        addConverter(Character.TYPE,           "javax.faces.convert.CharacterConverter");
+        addConverter(Double.class,             "javax.faces.convert.DoubleConverter");
+        addConverter(Double.TYPE,              "javax.faces.convert.DoubleConverter");
+        addConverter(Float.class,              "javax.faces.convert.FloatConverter");
+        addConverter(Float.TYPE,               "javax.faces.convert.FloatConverter");
+        addConverter(Integer.class,            "javax.faces.convert.IntegerConverter");
+        addConverter(Integer.TYPE,             "javax.faces.convert.IntegerConverter");
+        addConverter(Long.class,               "javax.faces.convert.LongConverter");
+        addConverter(Long.TYPE,                "javax.faces.convert.LongConverter");
+        addConverter(Short.class,              "javax.faces.convert.ShortConverter");
+        addConverter(Short.TYPE,               "javax.faces.convert.ShortConverter");
     }
 
 
@@ -79,7 +111,8 @@
 
     private ActionListener actionListener = null;
     private Map components = null;
-    private Map converters = null;
+    private Map converters = null; // By id
+    private Map converters1 = null; // By type
     private Locale defaultLocale = null;
     private String defaultRenderKitId = null;
     private String messageBundle = null;
@@ -275,7 +308,7 @@
 
     public void addConverter(Class targetClass, String converterClass) {
 
-        throw new UnsupportedOperationException();
+        converters1.put(targetClass, converterClass);
 
     }
 
@@ -295,7 +328,13 @@
 
     public Converter createConverter(Class targetClass) {
 
-        throw new UnsupportedOperationException();
+        String converterClass = (String) converters1.get(targetClass);
+        try {
+            Class clazz = Class.forName(converterClass);
+            return ((Converter) clazz.newInstance());
+        } catch (Exception e) {
+            throw new FacesException(e);
+        }
 
     }
 
@@ -309,7 +348,7 @@
 
     public Iterator getConverterTypes() {
 
-        throw new UnsupportedOperationException();
+        return (converters1.keySet().iterator());
 
     }
     



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


Mime
View raw message