Author: tchemit Date: 2010-06-05 09:50:06 +0200 (Sat, 05 Jun 2010) New Revision: 1947 Url: http://nuiton.org/repositories/revision/jaxx/1947 Log: add usefull method invokeConstructor Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-06-04 03:53:17 UTC (rev 1946) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-06-05 07:50:06 UTC (rev 1947) @@ -26,10 +26,11 @@ import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.context.JAXXInitialContext; +import org.apache.commons.beanutils.ConstructorUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.awt.*; +import java.awt.Component; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListenerProxy; import java.beans.PropertyChangeSupport; @@ -39,8 +40,14 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.EventListener; import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; public class JAXXUtil { @@ -110,8 +117,8 @@ } public static <O> JAXXContextEntryDef<O> newContextEntryDef( - String name, Class<O> klass) { - return new JAXXContextEntryDef<O>(name, klass); + String name, Class<?> klass) { + return new JAXXContextEntryDef<O>(name, (Class<O>) klass); } public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() { @@ -134,7 +141,7 @@ } @SuppressWarnings({"unchecked"}) - protected static<K, V> Class<Map<K, V>> castMap() { + protected static <K, V> Class<Map<K, V>> castMap() { return (Class<Map<K, V>>) Collections.emptyMap().getClass(); } @@ -335,7 +342,7 @@ component.removePropertyChangeListener(l); } } - + public static boolean assignment(boolean value, String name, JAXXObject src) { @@ -408,7 +415,7 @@ * @throws IllegalArgumentException if the entry is not found in context. */ public static void checkJAXXContextEntries(JAXXContext context, - JAXXContextEntryDef<?>... defs) + JAXXContextEntryDef<?>... defs) throws IllegalArgumentException { for (JAXXContextEntryDef<?> def : defs) { @@ -542,4 +549,26 @@ return toRemove.toArray(new PropertyChangeListener[toRemove.size()]); } + /** + * Overrides the commons method to have generict cast fiex. + * + * @param type the type of objet to instanciate + * @param prototype prototype of the constructor + * @param parms params to pass to constructor + * @param <O> type of object to create + * @return the new object + * @throws Exception if something wrong + * @since 2.1 + */ + @SuppressWarnings({"unchecked"}) + public static <O> O invokeConstructor(Class<O> type, + Class<?>[] prototype, + Object... parms) throws Exception { + O o = (O) ConstructorUtils.invokeConstructor(type, + parms, + prototype + ); + return o; + } + }