Author: pete.muir(a)jboss.org
Date: 2008-05-21 14:02:12 -0400 (Wed, 21 May 2008)
New Revision: 8258
Modified:
trunk/src/main/org/jboss/seam/jsf/SeamApplication.java
Log:
JBSEAM-3013
Modified: trunk/src/main/org/jboss/seam/jsf/SeamApplication.java
===================================================================
--- trunk/src/main/org/jboss/seam/jsf/SeamApplication.java 2008-05-21 16:08:28 UTC (rev
8257)
+++ trunk/src/main/org/jboss/seam/jsf/SeamApplication.java 2008-05-21 18:02:12 UTC (rev
8258)
@@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
+import java.util.Map;
import java.util.ResourceBundle;
import javax.el.ELContextListener;
@@ -115,15 +116,81 @@
@Override
public Converter createConverter(Class targetClass)
{
+ Converter converter = null;
if ( Contexts.isApplicationContextActive() )
{
- String name = Init.instance().getConvertersByClass().get(targetClass);
- if (name!=null)
+ converter = new ConverterLocator(targetClass).getConverter();
+ }
+ if (converter == null)
+ {
+ converter = application.createConverter(targetClass);
+ }
+ return converter;
+ }
+
+ private class ConverterLocator
+ {
+
+ private Map<Class, String> converters;
+ private Class targetClass;
+ private Converter converter;
+
+ public ConverterLocator(Class targetClass)
+ {
+ converters = Init.instance().getConvertersByClass();
+ this.targetClass = targetClass;
+ }
+
+ public Converter getConverter()
+ {
+ if (converter == null)
{
- return (Converter) Component.getInstance(name);
+ locateConverter(targetClass);
}
+ return converter;
}
- return application.createConverter(targetClass);
+
+ private Converter createConverter(Class clazz)
+ {
+ return (Converter) Component.getInstance(converters.get(clazz));
+ }
+
+ private void locateConverter(Class clazz)
+ {
+ if (converters.containsKey(clazz))
+ {
+ converter = createConverter(clazz);
+ return;
+ }
+
+ for (Class _interface: clazz.getInterfaces())
+ {
+ if (converters.containsKey(_interface))
+ {
+ converter = createConverter(_interface);
+ return;
+ }
+ else
+ {
+ locateConverter(_interface);
+ if (converter != null)
+ {
+ return;
+ }
+ }
+ }
+
+ Class superClass = clazz.getSuperclass();
+ if (converters.containsKey(superClass))
+ {
+ converter = createConverter(superClass);
+ return;
+ }
+ else if (superClass != null)
+ {
+ locateConverter(superClass);
+ }
+ }
}
@Override
Show replies by date