diff --git a/framework/base/src/org/ofbiz/base/conversion/ConverterCreater.java b/framework/base/src/org/ofbiz/base/conversion/ConverterCreater.java
new file mode 100644
index 0000000000..090bd1131f
--- /dev/null
+++ b/framework/base/src/org/ofbiz/base/conversion/ConverterCreater.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.base.conversion;
+
+/** ConverterCreater interface. Classes implement this interface to create a
+ * converter that can convert one Java object type to another.
+ */
+public interface ConverterCreater {
+ /** Creates a Converter that can convert the sourceClass to
+ * the targetClass. Returns null if this creater
+ * doesn't support the class pair.
+ *
+ * @param sourceClass The source Class to convert
+ * @param targetClass The target Class to convert to
+ * @return a converter that can convert Objects
+ */
+ public Converter createConverter(Class sourceClass, Class targetClass);
+}
diff --git a/framework/base/src/org/ofbiz/base/conversion/Converters.java b/framework/base/src/org/ofbiz/base/conversion/Converters.java
index f0b7ea889a..7a61a2af27 100644
--- a/framework/base/src/org/ofbiz/base/conversion/Converters.java
+++ b/framework/base/src/org/ofbiz/base/conversion/Converters.java
@@ -38,6 +38,7 @@ public class Converters {
protected static final String module = Converters.class.getName();
protected static final String DELIMITER = "->";
protected static final FastMap> converterMap = FastMap.newInstance();
+ protected static final FastSet creaters = FastSet.newInstance();
protected static final FastSet noConversions = FastSet.newInstance();
/** Null converter used when the source and target java object
* types are the same. The convert method returns the
@@ -48,6 +49,7 @@ public class Converters {
static {
converterMap.setShared(true);
+ registerCreater(new PassThruConverterCreater());
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Iterator converterLoaders = ServiceRegistry.lookupProviders(ConverterLoader.class, loader);
while (converterLoaders.hasNext()) {
@@ -97,11 +99,12 @@ OUTER:
continue OUTER;
}
}
- // Null converter must be checked last
- if (nullConverter.canConvert(sourceClass, targetClass)) {
- Converter passThruConverter = new PassThruConverter(sourceClass);
- converterMap.putIfAbsent(key, passThruConverter);
- continue;
+ for (ConverterCreater value : creaters) {
+ result = createConverter(value, sourceClass, targetClass);
+ if (result != null) {
+ converterMap.putIfAbsent(key, result);
+ continue OUTER;
+ }
}
if (noConversions.add(key)) {
Debug.logWarning("*** No converter found, converting from " +
@@ -113,6 +116,10 @@ OUTER:
} while (true);
}
+ private static Converter createConverter(ConverterCreater creater, Class sourceClass, Class targetClass) {
+ return creater.createConverter(sourceClass, targetClass);
+ }
+
/** Load all classes that implement Converter and are
* contained in containerClass.
*
@@ -143,6 +150,18 @@ OUTER:
}
}
+ /** Registers a ConverterCreater instance to be used by the
+ * {@link org.ofbiz.base.conversion.Converters#getConverter(Class, Class)}
+ * method, when a converter can't be found.
+ *
+ * @param The source object type
+ * @param The target object type
+ * @param creater The ConverterCreater instance to register
+ */
+ public static void registerCreater(ConverterCreater creater) {
+ creaters.add(creater);
+ }
+
/** Registers a Converter instance to be used by the
* {@link org.ofbiz.base.conversion.Converters#getConverter(Class, Class)}
* method.
@@ -209,6 +228,19 @@ OUTER:
}
}
+ protected static class PassThruConverterCreater implements ConverterCreater{
+ protected PassThruConverterCreater() {
+ }
+
+ public Converter createConverter(Class sourceClass, Class targetClass) {
+ if (sourceClass == targetClass) {
+ return UtilGenerics.cast(new PassThruConverter(targetClass));
+ } else {
+ return null;
+ }
+ }
+ }
+
/** Pass thru converter used when the source and target java object
* types are the same. The convert method returns the
* source object.