Author: tchemit Date: 2010-07-09 11:16:28 +0200 (Fri, 09 Jul 2010) New Revision: 1899 Url: http://nuiton.org/repositories/revision/nuiton-utils/1899 Log: Evolution #759: Remove deprecated api Converter clean i18n Removed: trunk/src/main/java/org/nuiton/util/ConverterUtil.java trunk/src/main/java/org/nuiton/util/EnumConverter.java trunk/src/main/java/org/nuiton/util/FormatConverter.java trunk/src/main/java/org/nuiton/util/FormatConverterFactory.java trunk/src/main/java/org/nuiton/util/FormatMap.java trunk/src/main/java/org/nuiton/util/URIConverter.java trunk/src/main/java/org/nuiton/util/URLConverter.java trunk/src/main/java/org/nuiton/util/VersionConverter.java trunk/src/test/java/org/nuiton/util/ConverterUtilTest.java trunk/src/test/java/org/nuiton/util/UnregistreableConverter.java trunk/src/test/java/org/nuiton/util/VersionConverterTest.java Modified: trunk/src/main/java/org/nuiton/util/ApplicationConfig.java trunk/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties trunk/src/test/resources/META-INF/services/org.apache.commons.beanutils.Converter Modified: trunk/src/main/java/org/nuiton/util/ApplicationConfig.java =================================================================== --- trunk/src/main/java/org/nuiton/util/ApplicationConfig.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/ApplicationConfig.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1618,7 +1618,7 @@ File homeConfig) throws IOException { if (log.isInfoEnabled()) { - log.info(_("Moving old configuration file from %s to %s", + log.info(_("nuitonutil.config.moving.conf", oldHomeConfig.getPath(), homeConfig.getPath())); } Deleted: trunk/src/main/java/org/nuiton/util/ConverterUtil.java =================================================================== --- trunk/src/main/java/org/nuiton/util/ConverterUtil.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/ConverterUtil.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,207 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import java.lang.reflect.Method; -import java.util.ServiceLoader; -import org.apache.commons.beanutils.ConvertUtils; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Une classe contenant des méthodes utiles sur les converters et les conversions - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.3, use now the {@link org.nuiton.util.converter.ConverterUtil} class. - */ -@Deprecated -public class ConverterUtil { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(ConverterUtil.class); - - /** - * le paquetage où chercher les implentations de Converter, si non présents - * dans le système - */ - protected static final String CONVERTER_PACKAGE = "org.nuiton.util"; - - /** un drapeau pour savoir si on doit charger les converters specifiques */ - protected static Boolean WAS_INIT = Boolean.FALSE; - - /** - * Cherche un converter pour un <code>type</code> donné. - * <p/> - * Recherche dans un premier temps dans les converteurs déjà connus. - * <p/> - * Si le type est une énum et qu'aucun converter, n'a été trouvé, on - * enregistre un nouveau convert d'enum. - * <p/> - * Sinon on tente d'instancier un converteur dans le paquetage dédié aux - * converteurs {@link #CONVERTER_PACKAGE}. - * - * @param <T> le type a convertir - * @param type le type a convertir - * @return le converter trouvé, ou null si non trouvé - */ - public static <T> Converter getConverter(Class<T> type) { - if (!WAS_INIT) { - initConverters(); - } - Converter converter = ConvertUtils.lookup(type); - if (converter != null) { - return converter; - } - if (type.isEnum()) { - registerEnumConverter(type); - return ConvertUtils.lookup(type); - } - // on essaye de trouver un converter dans le paquetage des converters - try { - registerConverter0(type); - converter = ConvertUtils.lookup(type); - } catch (Exception e) { - throw new RuntimeException(e); - } - return converter; - } - - /** - * Convertir une valeur! - * - * @param <T> le type de donnee recherchee - * @param type le type de donnee recherchee - * @param toConvert l'object a convertir - * @return la nouvelle instance de l'objet converti type ou null - */ - @SuppressWarnings({"unchecked"}) - public static <T> T convert(Class<T> type, Object toConvert) { - if (!WAS_INIT) { - initConverters(); - } - T result = null; - Converter converter = getConverter(type); - if (converter != null) { - return (T) converter.convert(type, toConvert); - } - return result; - } - - public static void registerConverter(Class<?> type) - throws IllegalAccessException, - InstantiationException, - ClassNotFoundException { - if (ConvertUtils.lookup(type) == null) { - registerConverter0(type); - } - } - - protected static void registerConverter0(Class<?> type) - throws IllegalAccessException, - InstantiationException, - ClassNotFoundException { - Class<?> aClass = Class.forName( - CONVERTER_PACKAGE + "." + type.getSimpleName() + "Converter"); - Converter converter = (Converter) aClass.newInstance(); - log.info("for type : " + type + " : " + converter); - ConvertUtils.register(converter, type); - } - - /** - * Enregistre un nouveau converter pour un type d'enum donné, avec une - * valeur par defaut. - * - * @param type le type d'enum à convertir - * @param defaultValue la valeur par defaut. - */ - public static void registerEnumConverter(Class<?> type, - Object defaultValue) { - if (EnumConverter.isEnabled(type, type) && - ConvertUtils.lookup(type) == null) { - Converter converter = new EnumConverter(type, defaultValue); - log.info("for type : " + type + " : " + converter); - ConvertUtils.register(converter, type); - } - } - - /** - * Enregistre un nouveau converter pour un type d'enum donné, sans utiliser - * de valeur par defaut. - * - * @param type le type d'enum à convertir - */ - public static void registerEnumConverter(Class<?> type) { - registerEnumConverter(type, null); - } - - public static byte[] convert(char[] chars) { - byte[] bytes = new byte[chars.length]; - for (int i = 0; i < chars.length; i++) { - bytes[i] = (byte) (chars[i] & 0xff); - } - return bytes; - } - - public static synchronized void deregister() { - ConvertUtils.deregister(); - WAS_INIT = false; - } - - public static synchronized void initConverters() { - if (WAS_INIT != null && WAS_INIT) { - return; - } - ServiceLoader<Converter> converters = - ServiceLoader.load(Converter.class); - for (Converter converter : converters) { - if (log.isDebugEnabled()) { - log.debug("discovered converter " + converter); - } - try { - Method m = converter.getClass().getDeclaredMethod("getType"); - m.setAccessible(true); - try { - Class<?> returnType = (Class<?>) m.invoke(converter); - log.info("register converter " + converter); - ConvertUtils.register(converter, returnType); - } catch (Exception ex) { - log.warn("could not obtain type of converter " + - converter + " for reason : " + ex.getMessage(), - ex); - } - } catch (NoSuchMethodException ex) { - log.warn("could not find method getType on converter " + - converter + ", will not be registred..."); - } catch (SecurityException ex) { - log.warn("could not find method getType on converter " + - converter + ", will not be registred..."); - } - - } - WAS_INIT = true; - } -} Deleted: trunk/src/main/java/org/nuiton/util/EnumConverter.java =================================================================== --- trunk/src/main/java/org/nuiton/util/EnumConverter.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/EnumConverter.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,154 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.beanutils.ConversionException; -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n._; - -import java.util.EnumSet; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; - -/** - * classe pour convertir une chaine en un objet Enum type-safe en - * connaissant le type d'enumération utilisée {@link #enumType}. - * <p/> - * Il est possible aussi de convertir une Enum à partir de sa valeur ordinal. - * <p/> - * Pour enregister un nouveau convertissemnt pour un type d'Enum utiliser les - * méthodes {@link ConverterUtil#registerEnumConverter(Class)}, et - * {@link ConverterUtil#registerEnumConverter(Class,Object)}. - * - * @author tchemit <chemit@codelutin.com> - * @see Enum - * @see Enum#ordinal() - * @deprecated since 1.3, use now the {@link org.nuiton.util.converter.EnumConverter} class. - */ -@Deprecated -public class EnumConverter implements Converter { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static Log log = getLog(EnumConverter.class); - - /** valeur par default à utiliser, si pas non trouvée et {@link #useDefault} actif. */ - protected Object defaultValue; - - /** flag pour utiliser la valeur par defaut {@link #defaultValue} si non trouvé. */ - protected boolean useDefault; - - /** le type de l'énumération à convertir */ - protected Class<?> enumType; - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - if (useDefault) { - return defaultValue; - } - throw new ConversionException( - _("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass, enumType)) { - Object result; - if (isEnabled(value.getClass(), enumType)) { - result = value; - return result; - } - if (value instanceof String) { - try { - result = valueOf(aClass, value); - } catch (IllegalArgumentException e) { - // try an ordinal conversion - result = convertFromOrdinal(aClass, value); - } - return result; - } - if (value instanceof Integer) { - // try a ordinal conversion - result = convertFromOrdinal(aClass, value); - return result; - } - } - throw new ConversionException( - _("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - public EnumConverter(Class<?> enumType, Object defaultValue) { - this.enumType = enumType; - this.defaultValue = defaultValue; - useDefault = defaultValue != null; - if (log.isDebugEnabled()) { - log.debug(toString() + '<' + enumType + '>'); - } - } - - public EnumConverter(Class<?> enumType) { - this(enumType, null); - } - - protected static boolean isEnabled(Class<?> aClass, Class<?> enumType) { - return aClass != null && aClass.isEnum() && aClass == enumType; - } - - protected Object convertFromOrdinal(Class<?> aClass, Object value) { - Object result = null; - try { - int ordinal = Integer.valueOf(value + ""); - EnumSet<?> vals = allOf(aClass); - if (ordinal > -1 && ordinal < vals.size()) { - for (Enum<?> val : vals) { - if (val.ordinal() == ordinal) { - result = val; - break; - } - } - } - } catch (NumberFormatException e1) { - // quiet conversion - result = null; - } - return result; - } - - protected Object valueOf(Class<?> aClass, Object value) { - Object result; - result = Enum.valueOf((Class<Enum>) aClass, (String) value); - return result; - } - - protected EnumSet<?> allOf(Class<?> aClass) { - EnumSet<?> vals; - vals = EnumSet.allOf((Class<Enum>) aClass); - return vals; - } - - public Class<?> getType() { - return enumType; - } - - -} Deleted: trunk/src/main/java/org/nuiton/util/FormatConverter.java =================================================================== --- trunk/src/main/java/org/nuiton/util/FormatConverter.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/FormatConverter.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,106 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/* * - * FormatConverter.java - * - * Created: 14 septembre 2005 00:55:19 CEST - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : */ - -package org.nuiton.util; - -import org.nuiton.util.FormatMap.Format; - -/** - * Un converter est un objet qui permet de passé d'une representation d'un - * objet vers une autre representation. Le mininum que converter doit savoir - * faire, est de converter une representation Java vers le format qu'il - * gère et inversement. Pour des raisons d'optimisation, il est possible - * qu'un converter sache passé d'un autre type que java vers sa representation - * pour eviter une conversion supplémentaire qui pourrait-etre couteuse. - * - * @param <A> le type de l'objet a convertir - * - * @deprecated since 1.3, use the class {@link org.nuiton.util.converter.FormatConverter}. - */ -@Deprecated -public interface FormatConverter<A> { // FormatConverter - - Format FORMAT_JAVA = new Format("Format Java"); - - /** - * Convertie une valeur vers la representation FORMAT géré par cette classe - * - * @param factory la factory utilisable pour rechercher d'autre converter - * si la representation Java n'est pas presente dans values et que l'on - * en a besoin - * @param format le format souhaité en sortie - * @param values une map contenant les différentes representation de la - * meme valeur. Les cles de la map sont les valeurs retournés par la - * methode getFormat(). - * @param args des arguments qui peuvent-être utile pour la conversion. - * par exemple si dans une application on a construit son propre - * converter et que pour la conversion, on a besoin d'un Context applicatif - * il peut-etre passé dans les args. Si le converter a besoin d'autre - * converter les memes args lui seront passé. - * @return l'objet dans la representation demandés par type - * @throws IllegalArgumentException si auncun moyen n'est trouve pour - * convertir une des valeurs de values dans le format géré par cette classe. - * Ou s'il manque dans les args des objets utils pour la conversion. - */ - A convert(FormatConverterFactory factory, - Format format, FormatMap values, Object... args); - - /** - * Convertie une valeur vers le Java - * - * @param factory la factory utilisable pour rechercher d'autre converter - * si la representation Java n'est pas presente dans values et que l'on - * en a besoin - * @param format le format à utiliser comme valeur d'entré - * @param values une map contenant les différentes representation de la - * meme valeur. La valeur interessante dans la map pour cette methode - * est celle retournée par values.get(getFormat()) si cet appel, ne - * retourne pas quelque chose de valid, la methode doit lever une exception - * @param args des arguments qui peuvent-être utile pour la conversion. - * par exemple si dans une application on a construit son propre - * converter et que pour la conversion, on a besoin d'un Context applicatif - * il peut-etre passé dans les args. Si le converter a besoin d'autre - * converter les memes args lui seront passé. - * @return la valeur java - * @throws IllegalArgumentException si le format géré par cette classe n'est - * pas trouvé dans les values. Ou s'il manque dans les args des objets utils - * pour la conversion. - */ - Object unconvert(FormatConverterFactory factory, - Format format, FormatMap values, Object... args); - -} // FormatConverter - Deleted: trunk/src/main/java/org/nuiton/util/FormatConverterFactory.java =================================================================== --- trunk/src/main/java/org/nuiton/util/FormatConverterFactory.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/FormatConverterFactory.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,203 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/* * - * FormatConverterFactory.java - * - * Created: 14 septembre 2005 00:19:51 CEST - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : */ - -package org.nuiton.util; - -import org.apache.commons.collections.map.MultiKeyMap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.FormatMap.Format; - -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; - -/** - * Factory permet d'enregistrer des objets de changement de format, et de - * les recupérer pour les utiliser. - * Les objets converter doivent au moins savoir convertir les objets depuis - * une representation Java. Pour des raisons d'optimisation, il est possible - * qu'il sache aussi convertir a partir d'autre representation, qui si elle - * existe sont moins couteuse a convertir. - * Il faut aussi que les converter sache convertir de leur representation vers - * un objet Java. - * par exemple si on enregistre les converiseurs suivant: - * <pre> - * addConverter(new MatrixToXMLFormatConverter()); - * addConverter(new MatrixToSQLFormatConverter()); - * FormatConverterFactory.convert(Matrix.class, MatrixToXMLFormatConverter.TYPE, - * values, AppContext); - * </pre> - * Dans ce cas pour des raisons d'optimisation - * - * @deprecated since 1.3, use the class {@link org.nuiton.util.converter.FormatConverterFactory}. - */ -@Deprecated -public class FormatConverterFactory { // FormatConverterFactory - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(FormatConverterFactory.class); - - static protected FormatConverterFactory instance; - /** <Class, from, to -> FormatConverter> */ - protected MultiKeyMap converters = new MultiKeyMap(); - - synchronized static public FormatConverterFactory getInstance() { - if (instance == null) { - instance = new FormatConverterFactory(); - } - return instance; - } - - /** - * Permet d'enregitrer un converter pour permettre la convertion d'une - * certain type Java d'une representation vers une autre. - * par exemple le type String d'un objet Java vers une chaine XML - * - * @param clazz la class de la representation Java de l'objet - * @param format le format géré par le FormatConverter - * @param c le converter a enregistrer - */ - public void addConverter(Class<?> clazz, Format format, FormatConverter<?> c) { - converters.put(clazz, format, c); - } - - /** - * permet de recupere le converter pour la classe souhaitée. - * - * @param clazz la classe de l'objet dont on souhaite le converter - * @param format qui doit être géré par le converter - * @param defaultConverter si aucun converter trouvé, ce converter est - * retourné - * @return le converter souhaité ou defaultConverter - */ - public FormatConverter<?> getConverter(Class<?> clazz, Format format, - FormatConverter<?> defaultConverter) { - FormatConverter<?> result = (FormatConverter<?>) converters.get(clazz, format); - if (result == null) { - result = defaultConverter; - } - return result; - } - - /** - * @param clazz - * @param format - * @return retourne null si aucun converter trouvé - * @see #getConverter(Class, Format, FormatConverter) - */ - public FormatConverter<?> getConverter(Class<?> clazz, Format format) { - return getConverter(clazz, format, null); - } - - /** - * Permet de retrouver le meilleur converter disponible pour l'argument - * clazz - * - * @param clazz la classe de l'objet dont on souhaite le converter - * @param format qui doit être géré par le converter - * @param defaultConverter si aucun converter trouvé, ce converter est - * retourné - * @return le converter souhaité ou defaultConverter - */ - public FormatConverter<?> findConverter(Class<?> clazz, Format format, - FormatConverter<?> defaultConverter) { - FormatConverter<?> result = null; - - LinkedList<Class<?>> interfaces = new LinkedList<Class<?>>(); - // On recherche la le transformer le plus spécifique sur les Class - Class<?> parent = clazz; - while (result == null && parent != null) { - Collections.addAll(interfaces, parent.getInterfaces()); - result = getConverter(parent, format); - parent = parent.getSuperclass(); - } - - // Si on a pas encore trouve de transformer on recherche - // un encodeur/decodeur pour les interfaces - for (Iterator<Class<?>> i = interfaces.iterator(); result == null && i.hasNext();) { - result = getConverter(i.next(), format); - } - - if (result == null) { - log.warn("Aucun converter trouvé pour le type: " + clazz); - result = defaultConverter; - } - log.debug("converter " + result + " utilisé pour le type: " + clazz); - - return result; - } - - /** - * @param clazz - * @param format - * @return retourne null si aucun converter trouvé - * @see #findConverter(Class, Format, FormatConverter) - */ - public FormatConverter<?> findConverter(Class<?> clazz, Format format) { - return findConverter(clazz, format, null); - } - - public Object convert(Format format, FormatMap values, Object... args) { - FormatConverter<?> c = findConverter(values.getType(), format); - if (c == null) { - throw new IllegalArgumentException("Aucun converter utilisable pour les arguments donnés class: " + values.getType().getName() + " format: " + format); - } - return c.convert(this, format, values, args); - } - - public Object unconvert(Format format, FormatMap values, Object... args) { - FormatConverter<?> c = findConverter(values.getType(), format); - if (c == null) { - throw new IllegalArgumentException("Aucun converter utilisable pour les arguments donnés"); - } - return c.unconvert(this, format, values, args); - } - - public Object convert(FormatConverter<?> defaultConverter, - Format format, FormatMap values, Object... args) { - FormatConverter<?> c = findConverter(values.getType(), format, defaultConverter); - return c.convert(this, format, values, args); - } - - public Object unconvert(FormatConverter<?> defaultConverter, - Format format, FormatMap values, Object... args) { - FormatConverter<?> c = findConverter(values.getType(), format, defaultConverter); - return c.unconvert(this, format, values, args); - } - -} // FormatConverterFactory - Deleted: trunk/src/main/java/org/nuiton/util/FormatMap.java =================================================================== --- trunk/src/main/java/org/nuiton/util/FormatMap.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/FormatMap.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,200 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/* * - * FormatMap.java - * - * Created: 16 septembre 2005 10:41:58 CEST - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : */ -package org.nuiton.util; - -import org.nuiton.util.FormatMap.Format; - -import java.util.HashMap; -import java.util.Map; - -/** - * Classe servant de conteneur pour les différentes representation d'un objet - * Les representations doivents être des instances de {@link Format}. Le mieux - * est lors de l'ecriture des convertisseurs pour un nouveau format est de - * créer une instance final static de {@link Format} Format pour representer - * ce format - * <p/> - * <h2>Utilisation</h2> - * <pre> - * FormatMap values = new FormatMap(MonObject.class); - * values.put(FormatConverter.FORMAT_JAVA, monInstance); - * Element xml = (Element)values.convert(XMLConverter.FORMAT_XML); - * Object sql = values.convert(SQLConverter.FORMAT_SQL); - * </pre> - * <pre> - * FormatMap values = new FormatMap(MonObject.class); - * values.put(FormatConverter.FORMAT_XML, monInstanceEnXML); - * Object sql = values.convert(SQLConverter.FORMAT_SQL); - * </pre> - * Dans ce second cas, la demande de la version SQL, transforme automatiquement - * la representation XML qui est la seul presente en Java, puis a partir de - * cette representation Java, on recupere la representation SQL. Bien sur - * Si le convertisseur SQL, peut directement convertir le XML en SQL, alors - * la conversion Java ne sera pas faite. - * <p/> - * Il est souvent plus simple de faire une petite classe avec les methodes - * getSQL() et getXML(), qui retourne les valeurs directement dans le bon type - * et qui n'ont pas besoin d'argument. - * - * @deprecated since 1.3, use the class {@link org.nuiton.util.converter.FormatMap}. - */ -@Deprecated -public class FormatMap extends HashMap<Format, Object> { // FormatMap - - /** */ - private static final long serialVersionUID = -3386611811885092898L; - - static public class Format { - - protected String name; - - public Format(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - } - protected Class<?> clazz; - - public FormatMap(Class<?> clazz) { - this.clazz = clazz; - } - - public Class<?> getType() { - return clazz; - } - - /** - * Met a jour la valeur de l'objet. Toutes les autres valeurs calculées - * sont oubliées et seront recalculé en fonction de cette nouvelle valeur - * - * @param format le format a utiliser - * @param value - */ - public void setValue(Format format, Object value) { - clear(); - put(format, value); - } - - /** - * Utilise le FormatConverterFactory par defaut pour la conversion - * - * @param format le format a utiliser - * @param args les arguments - * @return l'objet converti - */ - public Object convert(Format format, Object... args) { - return convert(FormatConverterFactory.getInstance(), format, args); - } - - /** - * Recupere la valeur dans le format demandé - * - * @param factory la FormatConverterFactory a utiliser - * @param format le format souhaité - * @param args des arguments facultatifs en fonction du context d'utilisation - * @return l'objet converti - */ - public Object convert(FormatConverterFactory factory, Format format, - Object... args) { - Object result = null; - Map<Format, Object> values = this; - //if (!values.containsKey(format) || - // !format.equals(FormatConverter.FORMAT_JAVA)) { - // throw new IllegalArgumentException("Aucun valeur disponible"); - //} - - if (values.containsKey(format)) { - result = values.get(format); - } else if (format.equals(FormatConverter.FORMAT_JAVA)) { - // on recherche une representation, que l'on convertie en Java - if (values.isEmpty()) { - throw new IllegalArgumentException("Aucun valeur disponible"); - } - Format otherFormat = values.keySet().iterator().next(); - result = unconvert(factory, otherFormat, args); - values.put(format, result); - } else { - result = factory.convert(format, this, args); - // on stocke la valeur trouver pour les prochaines fois - values.put(format, result); - } - - return result; - } - - /** Utilise le FormatConverterFactory par defaut pour la conversion - * @param format le format utilise - * @param args - * @return l'objet java - */ - public Object unconvert(Format format, Object... args) { - return unconvert(FormatConverterFactory.getInstance(), format, args); - } - - /** - * Donne la representation Java de l'objet en essayant de partir de la - * representation passé en parametre. - * - * @param factory la factory a utiliser - * @param format le format de départ souhaité - * @param args des arguments facultatifs en fonction du context d'utilisation - * @return l'objet java - */ - public Object unconvert(FormatConverterFactory factory, Format format, - Object... args) { - Object result = null; - Map<Format, Object> values = this; - if (!values.containsKey(format) && - !values.containsKey(FormatConverter.FORMAT_JAVA)) { - throw new IllegalArgumentException("Aucun valeur disponible"); - } - - // si on a deja la representation Java on la retourne tout de suite - if (values.containsKey(FormatConverter.FORMAT_JAVA)) { - result = values.get(FormatConverter.FORMAT_JAVA); - } else if (values.containsKey(format)) { - result = factory.unconvert(format, this, args); - values.put(FormatConverter.FORMAT_JAVA, result); - } - - return result; - } -} // FormatMap - Deleted: trunk/src/main/java/org/nuiton/util/URIConverter.java =================================================================== --- trunk/src/main/java/org/nuiton/util/URIConverter.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/URIConverter.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,94 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.beanutils.ConversionException; -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n._; - -import java.net.URI; -import java.net.URISyntaxException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; - -/** - * classe pour convertir une chaine en un objet URI. - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.3, use now the {@link org.nuiton.util.converter.URIConverter} class. - */ -@Deprecated -public class URIConverter implements Converter { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static Log log = getLog(URIConverter.class); - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - throw new ConversionException( - _("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return result; - } - if (value instanceof String) { - result = valueOf((String) value); - return result; - } - } - throw new ConversionException( - _("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - protected URI valueOf(String value) { - try { - URI result; - result = new URI(value); - return result; - } catch (URISyntaxException e) { - throw new ConversionException( - _("nuitonutil.error.url.convertor", value, this, e.getMessage())); - } - } - - public URIConverter() { - if (log.isDebugEnabled()) { - log.debug(this); - } - } - - protected boolean isEnabled(Class<?> aClass) { - return URI.class.equals(aClass); - } - - public Class<?> getType() { - return URI.class; - } -} Deleted: trunk/src/main/java/org/nuiton/util/URLConverter.java =================================================================== --- trunk/src/main/java/org/nuiton/util/URLConverter.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/URLConverter.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,94 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.beanutils.ConversionException; -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n._; - -import java.net.MalformedURLException; -import java.net.URL; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; - -/** - * classe pour convertir une chaine en un objet URL. - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.3, use now the {@link org.nuiton.util.converter.URLConverter} class. - */ -@Deprecated -public class URLConverter implements Converter { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static Log log = getLog(URLConverter.class); - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - throw new ConversionException( - _("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return result; - } - if (value instanceof String) { - result = valueOf((String) value); - return result; - } - } - throw new ConversionException( - _("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - protected URL valueOf(String value) { - try { - URL result; - result = new URL(value); - return result; - } catch (MalformedURLException e) { - throw new ConversionException( - _("nuitonutil.error.url.convertor", value, this, e.getMessage())); - } - } - - public URLConverter() { - log.info(this); - } - - protected boolean isEnabled(Class<?> aClass) { - return URL.class.equals(aClass); - } - - public Class<?> getType() { - return URL.class; - } - - -} Deleted: trunk/src/main/java/org/nuiton/util/VersionConverter.java =================================================================== --- trunk/src/main/java/org/nuiton/util/VersionConverter.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/java/org/nuiton/util/VersionConverter.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,86 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import static org.nuiton.i18n.I18n._; - -/** - * classe pour convertir une chaine en un objet Version. - * - * @author tchemit <chemit@codelutin.com> - * @see Version - * @deprecated since 1.3, use now the {@link org.nuiton.util.converter.VersionConverter} class. - */ -@Deprecated -public class VersionConverter implements Converter { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static final Log log = LogFactory.getLog(VersionConverter.class); - - public VersionConverter() { - if (log.isDebugEnabled()) { - log.debug(this); - } - } - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - throw new ConversionException( - _("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return result; - } - if (value instanceof String) { - try { - result = VersionUtil.valueOf((String) value); - return result; - } catch (IllegalArgumentException e) { - throw new ConversionException( - _("nuitonutil.error.version.convertor", value, this, e.getMessage()), e); - } - } - } - throw new ConversionException( - _("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - protected boolean isEnabled(Class<?> aClass) { - return Version.class.equals(aClass); - } - - public Class<?> getType() { - return Version.class; - } -} Modified: trunk/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter =================================================================== --- trunk/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,4 +1,4 @@ -org.nuiton.util.URLConverter -org.nuiton.util.URIConverter -org.nuiton.util.VersionConverter +org.nuiton.util.converter.URLConverter +org.nuiton.util.converter.URIConverter +org.nuiton.util.converter.VersionConverter Modified: trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties =================================================================== --- trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,5 +1,4 @@ -Moving\ old\ configuration\ file\ from\ %s\ to\ %s= -hello\ you\ \!=hello you \! +nuitonutil.config.moving.conf=Moving old configuration file from %s to %s nuitonutil.debug.objectutil.create=Try to create %s with %s nuitonutil.debug.objectutil.instantiate=Can't instantiate %s with params %s nuitonutil.debug.objectutil.invoke=Invoke %s with %s @@ -8,8 +7,6 @@ nuitonutil.error.convert.file.to.url=Can't convert %s for reason %s nuitonutil.error.convertor.noValue=No value specified for converter %s nuitonutil.error.get.url.from.zip=Error while reading %s \: %s -nuitonutil.error.i18n.unformated.message=Message can't be formatted\: '%s' with arguments %s -nuitonutil.error.i18n.untranslated.message=Message can't be translated\: '%s' nuitonutil.error.no.convertor=no convertor found for type %2$s and objet '%1$s' nuitonutil.error.not.an.enum=The type %1$s ins not an Enum type nuitonutil.error.null.parameter=The parameter %1$s is null\! Modified: trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties =================================================================== --- trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,5 +1,4 @@ -Moving\ old\ configuration\ file\ from\ %s\ to\ %s= -hello\ you\ \!=Salut toi\! +nuitonutil.config.moving.conf=D\u00E9placement du fichier de configuration depuis %s vers %s nuitonutil.debug.objectutil.create=Essaye de cr\u00E9er %s avec %s nuitonutil.debug.objectutil.instantiate=Ne peut pas instancier %s avec les param\u00EAtres %s nuitonutil.debug.objectutil.invoke=Invocation de %s avec %s @@ -8,8 +7,6 @@ nuitonutil.error.convert.file.to.url=Le fichier '%1$s' n'a pas pu \u00EAtre converti en URL pour la raison suivante \: %2$S nuitonutil.error.convertor.noValue=Aucune valeur \u00E0 convertir pour le convertisseur %s nuitonutil.error.get.url.from.zip=Erreur lors de la lecture du fichier compress\u00E9 %1$s \: %2$s -nuitonutil.error.i18n.unformated.message=Le message suivant n''a pas pu \u00EAtre format\u00E9 \: '%s' avec les arguments %s -nuitonutil.error.i18n.untranslated.message=Le message suivant n'a pas pu \u00EAtre traduit \: '%s' nuitonutil.error.no.convertor=Aucun convertisseur trouv\u00E9 pour le type %2$s et l''objet '%1$s' nuitonutil.error.not.an.enum=Le type %1$s n'est pas une enumeration java nuitonutil.error.null.parameter=Le param\u00E8tre '%1$s' est null\! Deleted: trunk/src/test/java/org/nuiton/util/ConverterUtilTest.java =================================================================== --- trunk/src/test/java/org/nuiton/util/ConverterUtilTest.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/test/java/org/nuiton/util/ConverterUtilTest.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,84 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.beanutils.ConvertUtils; -import org.apache.commons.beanutils.Converter; -import org.junit.Assert; -import org.junit.Test; - -/** - * ConverterUtil Tester. - * - * @author tchemit <chemit@codelutin.com> - * @version 1.0 - * @since <pre>02/13/2008</pre> - * @deprecated since 1.3, use now the {@link org.nuiton.util.converter.ConverterUtilTest} class. - */ -@Deprecated -public class ConverterUtilTest { - - @Test - public void testInitConverters() { - - ConverterUtil.deregister(); - - Converter t = ConvertUtils.lookup(Version.class); - Assert.assertNull(t); - ConverterUtil.initConverters(); - t = ConvertUtils.lookup(Version.class); - Assert.assertNotNull(t); - } - - @Test - public void testConvert() throws Exception { - String s; - s = ""; - Assert.assertEquals( - new String(s.getBytes()), - new String(ConverterUtil.convert(s.toCharArray()))); - - s = "a"; - Assert.assertEquals( - new String(s.getBytes()), - new String(ConverterUtil.convert(s.toCharArray()))); - - s = "kZZFIOFEIOFEfdskdfmldsfjklsfjldfldfjdsfiosabcd4567'''`~teAZEst"; - Assert.assertEquals( - new String(s.getBytes()), - new String(ConverterUtil.convert(s.toCharArray()))); - - s = "]{}{}{{[#{[{#[#]{][{^#][^]#{^[]{#][#]{]@[{#][^#{][^]#{teAZEst"; - Assert.assertEquals( - new String(s.getBytes()), - new String(ConverterUtil.convert(s.toCharArray()))); - - // FIXME following test won't pass - //s = "éééééé]{}{}{{[#{[{#[#]{][{^#][^]#{^[]{#][#]{]@[{#][^#{][^]#{teAZEst"; - //assertEquals(new String(s.getBytes()), new String(ConverterUtil.convert(s.toCharArray()))); - - } -} Deleted: trunk/src/test/java/org/nuiton/util/UnregistreableConverter.java =================================================================== --- trunk/src/test/java/org/nuiton/util/UnregistreableConverter.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/test/java/org/nuiton/util/UnregistreableConverter.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,44 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.beanutils.Converter; - -/** - * A converter with no getType method, so not registreable via {@link ConverterUtil#initConverters()} - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.3, use now {@link org.nuiton.util.converter.UnregistreableConverter}. - */ -@Deprecated -public class UnregistreableConverter implements Converter{ - - @Override - public Object convert(Class type, Object value) { - return value; - } - -} Deleted: trunk/src/test/java/org/nuiton/util/VersionConverterTest.java =================================================================== --- trunk/src/test/java/org/nuiton/util/VersionConverterTest.java 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/test/java/org/nuiton/util/VersionConverterTest.java 2010-07-09 09:16:28 UTC (rev 1899) @@ -1,102 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.3, use now the {@link org.nuiton.util.converter.VersionConverterTest} class. - */ -@Deprecated -public class VersionConverterTest { - - VersionConverter converter; - - @BeforeClass - public static void setUpClass() throws Exception { - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() { - converter = new VersionConverter(); - } - - @After - public void tearDown() { - } - - /** - * Test of convert method, of class VersionConverter. - */ - @Test - public void testConvert() { - Object value; - Object expResult; - Object result; - - value = ""; - expResult = new Version(); - result = converter.convert(Version.class, value); - assertEquals(expResult, result); - - value = "0"; - expResult = new Version(); - result = converter.convert(Version.class, value); - assertEquals(expResult, result); - - value = "1.2.3.4"; - expResult = new Version(1, 2, 3, 4); - result = converter.convert(Version.class, value); - assertEquals(expResult, result); - - value = "1.2.3.4-alpha-11"; - expResult = new Version("alpha", 11, 1, 2, 3, 4); - result = converter.convert(Version.class, value); - assertEquals(expResult, result); - } - - /** - * Test of isEnabled method, of class VersionConverter. - */ - @Test - public void testIsEnabled() { - - boolean expResult = true; - boolean result = converter.isEnabled(Version.class); - assertEquals(expResult, result); - } -} Modified: trunk/src/test/resources/META-INF/services/org.apache.commons.beanutils.Converter =================================================================== --- trunk/src/test/resources/META-INF/services/org.apache.commons.beanutils.Converter 2010-07-01 13:16:12 UTC (rev 1898) +++ trunk/src/test/resources/META-INF/services/org.apache.commons.beanutils.Converter 2010-07-09 09:16:28 UTC (rev 1899) @@ -1 +1 @@ -org.nuiton.util.UnregistreableConverter \ No newline at end of file +org.nuiton.util.converter.UnregistreableConverter \ No newline at end of file