Index: lutinutil/src/java/org/codelutin/util/ConverterUtil.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/ConverterUtil.java:1.1 --- /dev/null Sun Dec 30 22:17:31 2007 +++ lutinutil/src/java/org/codelutin/util/ConverterUtil.java Sun Dec 30 22:17:25 2007 @@ -0,0 +1,49 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package org.codelutin.util; + +import org.apache.commons.beanutils.ConvertUtils; +import org.apache.commons.beanutils.Converter; + +/** + * Une classe contenant des méthodes utiles sur les converters + * + * @author tony + */ +public class ConverterUtil { + /** + * Cherche un converter pour un type donné. + *

+ * Si le type est une énum et qu'aucun converter, n'a été trouvé, on + * enregistre un nouveau convert d'enum. + * + * @param type le type à convertir + * @return le converter trouvé, ou null si non trouvé + * @see Converter + * @see EnumConverter + */ + public static Converter getConverter(Class type) { + Converter converter = ConvertUtils.lookup(type); + if (type.isEnum() && converter == null) { + EnumConverter.registerEnumConverter(type); + converter = ConvertUtils.lookup(type); + } + return converter; + } +}