Author: tchemit Date: 2011-05-13 11:07:31 +0200 (Fri, 13 May 2011) New Revision: 2137 Url: http://nuiton.org/repositories/revision/nuiton-utils/2137 Log: clean some codes, and more... Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java trunk/nuiton-utils/src/main/java/org/nuiton/util/CallAnalyse.java trunk/nuiton-utils/src/main/java/org/nuiton/util/CategorisedListenerSet.java trunk/nuiton-utils/src/main/java/org/nuiton/util/ClassLoaderUtil.java trunk/nuiton-utils/src/main/java/org/nuiton/util/FileUtil.java trunk/nuiton-utils/src/main/java/org/nuiton/util/ObjectUtil.java trunk/nuiton-utils/src/main/java/org/nuiton/util/Resource.java trunk/nuiton-utils/src/main/java/org/nuiton/util/StringUtil.java trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeLog.java trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeTrace.java trunk/nuiton-utils/src/main/java/org/nuiton/util/ZipStreamEncoder.java trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ConverterUtil.java trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/EnumConverter.java trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/URIConverter.java trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/URLConverter.java trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/VersionConverter.java trunk/nuiton-utils/src/test/java/org/nuiton/util/CallAnalyseTest.java trunk/nuiton-utils/src/test/java/org/nuiton/util/ZipUtilTest.java trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -291,7 +291,7 @@ * Last update $Date$ by */ public class ApplicationConfig { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(ApplicationConfig.class); /** Used to know what is separator between class and method on command line. */ Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/CallAnalyse.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/CallAnalyse.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/CallAnalyse.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -63,7 +63,7 @@ */ public class CallAnalyse { // CallAnalyse - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(CallAnalyse.class); static private List<ThreadStatistics> listThreadStatistics = Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/CategorisedListenerSet.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/CategorisedListenerSet.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/CategorisedListenerSet.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -67,7 +67,7 @@ */ public class CategorisedListenerSet<L> { // CategorisedListenerSet - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ private static Log log = LogFactory.getLog(CategorisedListenerSet.class); /** Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ClassLoaderUtil.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ClassLoaderUtil.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ClassLoaderUtil.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -44,7 +44,7 @@ public class ClassLoaderUtil { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ private static final Log log = LogFactory.getLog(ClassLoaderUtil.class); /** Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/FileUtil.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/FileUtil.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/FileUtil.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -86,7 +86,7 @@ */ public class FileUtil { // FileUtil - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(FileUtil.class); /** Encoding utilisé (peut être redéfini) */ Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ObjectUtil.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ObjectUtil.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ObjectUtil.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -36,6 +36,12 @@ package org.nuiton.util; +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.beanutils.ConvertUtils; +import org.apache.commons.beanutils.MethodUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; @@ -43,22 +49,15 @@ import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; - -import org.apache.commons.beanutils.MethodUtils; -import static org.nuiton.i18n.I18n._; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.beanutils.ConvertUtils; +import static org.nuiton.i18n.I18n._; + /** * Outils pour manipuler des objets. Création d'un objet à partir d'une chaîne * le décrivant, conversion d'un objet en Object, récupération de méthodes @@ -71,7 +70,7 @@ */ public class ObjectUtil { // ObjectUtil - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(ObjectUtil.class); protected static final Integer ZERO = 0; @@ -106,10 +105,10 @@ } // copy collection into modifiable list to add new object - List container = new LinkedList(args); + List<?> container = new LinkedList(args); Constructor<E> constructor = constructors[0]; - Class[] paramTypes = constructor.getParameterTypes(); + Class<?>[] paramTypes = constructor.getParameterTypes(); Object[] params = new Object[paramTypes.length]; for (int i=0; i<paramTypes.length; i++) { @@ -137,14 +136,14 @@ * @param nullIfMissing * @return */ - static protected Object choiceArgument(Class clazz, List args, boolean nullIfMissing) { + static protected Object choiceArgument(Class<?> clazz, List args, boolean nullIfMissing) { Object result = null; boolean addResult = false; for (Object o : args) { if (o != null) { - if ((o instanceof Class) && clazz.isAssignableFrom((Class) o)) { + if (o instanceof Class<?> && clazz.isAssignableFrom((Class<?>) o)) { // cas on l'on trouve une class dans arg qui une fois instancier convient - result = newInstance((Class) o, args, nullIfMissing); + result = newInstance((Class<?>) o, args, nullIfMissing); addResult = true; break; } else if (clazz.isInstance(o)) { @@ -267,13 +266,20 @@ try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(e); - oos.close(); + try { + oos.writeObject(e); + } finally { + oos.close(); + } ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + E result; ObjectInputStream ois = new ObjectInputStream(bis); - E result = (E) ois.readObject(); - ois.close(); + try { + result = (E) ois.readObject(); + } finally { + ois.close(); + } return result; } catch (Exception eee) { @@ -390,7 +396,7 @@ public static <T> T newInstance(Class<T> clazz, String ... params) throws IllegalArgumentException { if (params == null) { - params = new String[0]; + params = StringUtil.EMPTY_STRING_ARRAY; } List<Constructor<T>> constructors = getConstructor(clazz, params.length); @@ -670,5 +676,59 @@ return value == ZEROD; } + /** + * Verifie si la classe est de type primitif. + * + * @param clazz nom de la classe a tester + * @return vrai si le classe est de type primitif faux sinon + */ + public static boolean isPrimitive(Class<?> clazz) { + return clazz.isPrimitive() || clazz == Boolean.class + || clazz == Byte.class || clazz == Character.class + || clazz == Short.class || clazz == Integer.class + || clazz == Long.class || clazz == Float.class + || clazz == Double.class; + } + + /** + * Retourne la classe du type primitf associé avec la classe de de l'objet + * passé en parametre. Par exemple si la classe passée en paramètre est + * Integer alors le resultat sera la classe de int. + * + * @param clazz la classe dont on souhaite le type primitf + * @return le type primitif associé a la classe en paramètre, ou null s'il + * n'y a pas de type primitif associé. + */ + public static Class<?> getPrimitiveClass(Class<?> clazz) { + if (clazz == Boolean.class) { + return Boolean.TYPE; + } + if (clazz == Byte.class) { + return Byte.TYPE; + } + if (clazz == Character.class) { + return Character.TYPE; + } + if (clazz == Short.class) { + return Short.TYPE; + } + if (clazz == Integer.class) { + return Integer.TYPE; + } + if (clazz == Long.class) { + return Long.TYPE; + } + if (clazz == Float.class) { + return Float.TYPE; + } + if (clazz == Double.class) { + return Double.TYPE; + } + if (clazz == Void.class) { + return Void.TYPE; + } + return null; + } + } // ObjectUtil Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/Resource.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/Resource.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/Resource.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -25,8 +25,10 @@ package org.nuiton.util; -import static org.nuiton.i18n.I18n._; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import javax.swing.ImageIcon; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -50,11 +52,8 @@ import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; -import javax.swing.ImageIcon; +import static org.nuiton.i18n.I18n._; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - /** * Cette class permet de rechercher un fichier en indiquant son nom avec son * chemin. Cette librairie ira ensuite chercher ce fichier sur le système de @@ -71,7 +70,7 @@ */ public class Resource { // Resource - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ private static final Log log = LogFactory.getLog(Resource.class); protected Resource() { @@ -84,7 +83,7 @@ * * @param url l'url a ajouter */ - static public void addDefaultClassLoader(URL url) { + public static void addDefaultClassLoader(URL url) { ClassLoader classLoader = ClassLoader.getSystemClassLoader(); addClassLoader(classLoader, url); } @@ -96,7 +95,7 @@ * @param classLoader le classloader a modifier * @param url l'url a ajouter */ - static public void addClassLoader(ClassLoader classLoader, URL url) { + public static void addClassLoader(ClassLoader classLoader, URL url) { try { Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class}); @@ -114,7 +113,7 @@ * @return l'url de la ressource * @throws ResourceNotFoundException si la resource n'a pas ete trouvee */ - static public URL getURL(String name) { + public static URL getURL(String name) { URL url = getURLOrNull(name); if (url != null) { return url; @@ -129,7 +128,7 @@ * @param name le nom de la ressource * @return l'url de la ressource ou null */ - static public URL getURLOrNull(String name) { + public static URL getURLOrNull(String name) { // on recherche d'abord sur le filesystem File file = new File(name); if (file.exists()) { @@ -164,7 +163,7 @@ * @param name le nom de l'icone * @return Retourne l'icon demande ou null s'il n'est pas trouvé */ - static public ImageIcon getIcon(String name) { + public static ImageIcon getIcon(String name) { try { return new ImageIcon(getURL(name)); } catch (Exception eee) { @@ -184,25 +183,11 @@ * compris). * @return la liste des urls correspondant au pattern */ - static public List<URL> getURLs(String pattern) { + public static List<URL> getURLs(String pattern) { return getURLs(pattern, (URLClassLoader) null); } /** - * Recupere la liste des urls d'un {@link URLClassLoader}. - * <p/> - * Note : Un cas particulier est positionné pour JBoss qui utilise la method getAllURLs. - * - * @param classLoader le class loader a scanner - * @return les urls du classloade. - * @deprecated should use now {@link ClassLoaderUtil#getURLs(URLClassLoader)} - */ - @Deprecated - static public URL[] getURLs(URLClassLoader classLoader) { - return ClassLoaderUtil.getURLs(classLoader); - } - - /** * Retourner la liste des fichiers du classLoader. Ces fichiers doivent * correspondre au pattern donne. * @@ -212,7 +197,7 @@ * compris). * @return la liste des urls correspondant au pattern */ - static public List<URL> getURLs(String pattern, URLClassLoader classLoader) { + public static List<URL> getURLs(String pattern, URLClassLoader classLoader) { if (classLoader == null) { classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); } @@ -226,14 +211,14 @@ * * @param arrayURL les urls ou chercher * @param pattern le nom du fichier a extraire du fichier compressé ou - * durepertoire doit correspondre au pattern (repertoire + nom + * dur epertoire doit correspondre au pattern (repertoire + nom * compris). * @return la liste des urls correspondant au pattern */ - static public List<URL> getURLs(String pattern, URL... arrayURL) { + public static List<URL> getURLs(String pattern, URL... arrayURL) { long t0 = System.nanoTime(); - HashList<URL> urlList = new HashList<URL>(); + List<URL> urlList = new HashList<URL>(); if (arrayURL.length == 1) { URL jarURL = arrayURL[0]; @@ -256,7 +241,7 @@ for (URL urlFile : arrayURL) { // EC-20100510 this cause wrong accent encoding //String fileName = urlFile.getFile(); - String fileName = null; + String fileName; try { fileName = urlFile.toURI().getPath(); } @@ -314,7 +299,7 @@ return urlList; } - static public URL[] getClassPathURLsFromJarManifest(URL jarURL) + public static URL[] getClassPathURLsFromJarManifest(URL jarURL) throws IOException, URISyntaxException { JarFile jar = null; URL[] result; @@ -335,7 +320,7 @@ if (classPath != null) { paths = classPath.split(" "); } else { - paths = new String[0]; + paths = StringUtil.EMPTY_STRING_ARRAY; } result = new URL[paths.length + 1]; result[0] = jarURL; @@ -368,7 +353,7 @@ return result; } - static public List<URL> getURLsFromZip(File zipFile, String pattern) { + public static List<URL> getURLsFromZip(File zipFile, String pattern) { try { if (log.isTraceEnabled()) { log.trace("search '" + pattern + "' in " + zipFile); @@ -409,13 +394,13 @@ } } - static public List<URL> getURLsFromJar(File jarfile, String pattern) { + public static List<URL> getURLsFromJar(File jarfile, String pattern) { try { if (log.isTraceEnabled()) { log.trace("search '" + pattern + "' in " + jarfile); } - ArrayList<URL> result = new ArrayList<URL>(); + List<URL> result = new ArrayList<URL>(); InputStream in = new FileInputStream(jarfile); ZipInputStream zis = new ZipInputStream(in); while (zis.available() != 0) { @@ -460,13 +445,13 @@ * pattern est null, tous les fichiers trouvé sont retourné. * @return la liste des urls correspondant au pattern */ - static public List<URL> getURLsFromDirectory(File repository, String pattern) { + public static List<URL> getURLsFromDirectory(File repository, String pattern) { try { if (log.isTraceEnabled()) { log.trace("search '" + pattern + "' in " + repository); } - HashList<URL> urlList = new HashList<URL>(); + List<URL> urlList = new HashList<URL>(); File[] filesList = repository.listFiles(); if (filesList != null) { @@ -512,7 +497,7 @@ * @param name nom du fichier a tester * @return vrai si le fichier se termine par .jar faux sinon */ - static public boolean isJar(String name) { + public static boolean isJar(String name) { if (name != null && name.length() > 4) { String ext = name.substring(name.length() - 4, name.length()); return ".jar".equalsIgnoreCase(ext); @@ -526,7 +511,7 @@ * @param name nom du fichier a tester * @return vrai si le fichier se termine par .zip faux sinon */ - static public boolean isZip(String name) { + public static boolean isZip(String name) { if (name != null && name.length() > 4) { String ext = name.substring(name.length() - 4, name.length()); return ".zip".equalsIgnoreCase(ext); @@ -539,13 +524,11 @@ * * @param clazz nom de la classe a tester * @return vrai si le classe est de type primitif faux sinon + * @deprecated since 2.2, use now the method {@link ObjectUtil#isPrimitive(Class)} */ - static public boolean isPrimitive(Class clazz) { - return clazz.isPrimitive() || clazz == Boolean.class - || clazz == Byte.class || clazz == Character.class - || clazz == Short.class || clazz == Integer.class - || clazz == Long.class || clazz == Float.class - || clazz == Double.class; + @Deprecated + public static boolean isPrimitive(Class clazz) { + return ObjectUtil.isPrimitive(clazz); } /** @@ -556,36 +539,11 @@ * @param clazz la classe dont on souhaite le type primitf * @return le type primitif associé a la classe en paramètre, ou null s'il * n'y a pas de type primitif associé. + * @deprecated since 2.2, use now the method {@link ObjectUtil#getPrimitiveClass(Class)} */ - static public Class getPrimitiveClass(Class clazz) { - if (clazz == Boolean.class) { - return Boolean.TYPE; - } - if (clazz == Byte.class) { - return Byte.TYPE; - } - if (clazz == Character.class) { - return Character.TYPE; - } - if (clazz == Short.class) { - return Short.TYPE; - } - if (clazz == Integer.class) { - return Integer.TYPE; - } - if (clazz == Long.class) { - return Long.TYPE; - } - if (clazz == Float.class) { - return Float.TYPE; - } - if (clazz == Double.class) { - return Double.TYPE; - } - if (clazz == Void.class) { - return Void.TYPE; - } - return null; + @Deprecated + public static Class getPrimitiveClass(Class clazz) { + return ObjectUtil.getPrimitiveClass(clazz); } @@ -626,12 +584,13 @@ } /** - * Return true is str is a pattern (contains * or ?). + * Return true if {@code str} is a pattern (contains * or ?). * * @param str str to test * @since 2.2 + * @return {@code true} if {@code str} is a pattern, {@code false} otherwise */ - static protected boolean isPattern(String str) { + protected static boolean isPattern(String str) { return str.indexOf('*') != -1 || str.indexOf('?') != -1; } @@ -643,7 +602,7 @@ * @throws IOException * @since 2.2 */ - static public List<URL> getResources(String pattern) throws IOException { + public static List<URL> getResources(String pattern) throws IOException { return getResources(pattern, null); } @@ -656,12 +615,13 @@ * @throws IOException * @since 2.2 */ - static public List<URL> getResources(String pattern, ClassLoader classLoader) throws IOException { + public static List<URL> getResources(String pattern, + ClassLoader classLoader) throws IOException { if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } - List<URL> urlList = null; + List<URL> urlList; if (isPattern(pattern)) { urlList = getPatternRessources(pattern, classLoader); @@ -686,7 +646,8 @@ * @throws IOException * @since 2.2 */ - static protected List<URL> getPatternRessources(String pattern, ClassLoader classLoader) throws IOException { + protected static List<URL> getPatternRessources(String pattern, + ClassLoader classLoader) throws IOException { List<URL> urlList = new HashList<URL>(); @@ -756,7 +717,8 @@ * @see JarURLConnection * @since 2.2 */ - protected static List<URL> doFindPathMatchingJarResources(URL rootDirResource, String subPattern) throws IOException { + protected static List<URL> doFindPathMatchingJarResources(URL rootDirResource, + String subPattern) throws IOException { URLConnection con = rootDirResource.openConnection(); JarFile jarFile; @@ -771,7 +733,7 @@ jarFile = jarCon.getJarFile(); jarFileUrl = jarCon.getJarFileURL().toExternalForm(); JarEntry jarEntry = jarCon.getJarEntry(); - rootEntryPath = (jarEntry != null ? jarEntry.getName() : ""); + rootEntryPath = jarEntry != null ? jarEntry.getName() : ""; } else { // No JarURLConnection -> need to resort to URL file parsing. @@ -809,7 +771,7 @@ rootEntryPath = rootEntryPath + "/"; } List<URL> result = new HashList<URL>(8); - for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) { + for (Enumeration<?> entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = (JarEntry) entries.nextElement(); String entryPath = entry.getName(); if (entryPath.startsWith(rootEntryPath)) { @@ -842,10 +804,11 @@ * @param subPattern the sub pattern to match (below the root directory) * @return the Set of matching Resource instances * @throws IOException in case of I/O errors - * @see #retrieveMatchingFiles + * @see #retrieveMatchingFiles(File, String) * @since 2.2 */ - protected static List<URL> doFindMatchingFileSystemResources(URL rootDirResource, String subPattern) + protected static List<URL> doFindMatchingFileSystemResources(URL rootDirResource, + String subPattern) throws IOException { File rootDir; @@ -873,7 +836,8 @@ * @throws IOException if directory contents could not be retrieved * @since 2.2 */ - protected static List<URL> retrieveMatchingFiles(File rootDir, String pattern) throws IOException { + protected static List<URL> retrieveMatchingFiles(File rootDir, + String pattern) throws IOException { if (!rootDir.exists()) { return Collections.emptyList(); } @@ -909,7 +873,9 @@ * @throws IOException if directory contents could not be retrieved * @since 2.2 */ - protected static void doRetrieveMatchingFiles(String fullPattern, File dir, List<URL> result) throws IOException { + protected static void doRetrieveMatchingFiles(String fullPattern, + File dir, + List<URL> result) throws IOException { if (log.isDebugEnabled()) { log.debug("Searching directory [" + dir.getAbsolutePath() + "] for files matching pattern [" + fullPattern + "]"); Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/StringUtil.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/StringUtil.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/StringUtil.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -58,11 +58,13 @@ * Created: 21 octobre 2003 * * @author bpoussin <poussin@codelutin.com> + * @author tchemit <chemit@codelutin.com> * $Id$ */ -public class StringUtil { - public static final String[] EMPTY_STRING_ARRAY = new String[0]; // StringUtil +public class StringUtil { // StringUtil + public static final String[] EMPTY_STRING_ARRAY = new String[0]; + /** Constructor for the StringUtil object */ protected StringUtil() { } Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeLog.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeLog.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeLog.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -24,14 +24,15 @@ */ package org.nuiton.util; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.HashMap; +import java.util.Map; + /** * Cette classe permet de facilement trace le temps d'execution entre deux points - * + * <p/> * usage * <pre> * final static private Log log = LogFactory.getLog(MyClass.class); @@ -51,63 +52,60 @@ * * System.out.println ("time: " + timeLog.getCallCount()); * </pre> - * + * <p/> * You can configure log level in configuration file with: * log4j.logger.org.codelutin.MyClass=DEBUG * log4j.logger.org.codelutin.MyClass.TimeLog=INFO * - * @see CallAnalyse * @author poussin * @version $Revision: 1985 $ + * @see CallAnalyse * @since 2.1 - * - * Last update: $Date: 2010-12-23 12:45:57 +0100 (jeu. 23 déc. 2010) $ - * by : $Author: sletellier $ + * <p/> + * Last update: $Date: 2010-12-23 12:45:57 +0100 (jeu. 23 déc. 2010) $ + * by : $Author: sletellier $ */ public class TimeLog { - /** to use log facility, just put in your code: log.info(\"...\"); */ - final static private Log log = LogFactory.getLog(TimeLog.class); - static public class CallStat { - long callNumber = 0; - long callTime = 0; + protected long callNumber; + + protected long callTime; + @Override public String toString() { String callTimeString = StringUtil.convertTime(callTime); String avgTimeString = - StringUtil.convertTime((callTime/ callNumber)); + StringUtil.convertTime(callTime / callNumber); return String.format("total call %s, total time %s, avg time %s", - callNumber, callTimeString, avgTimeString); + callNumber, callTimeString, avgTimeString); } } /** loggueur used to log time */ protected Log timeLog; + /** time to trigger log time in info level (ns) (default: 1s) */ protected long timeToLogInfo = 1000l * 1000000l; + /** time to trigger log time in warn level (ns) (default: 3s) */ protected long timeToLogWarn = 3000l * 1000000l; /** for each method of all proxies, keep number of call */ protected Map<String, CallStat> callCount = new HashMap<String, CallStat>(); - /** - * - * @param logTime log used to log time message. - */ + /** @param logTime log used to log time message. */ protected TimeLog(Log logTime) { - this.timeLog = logTime; + timeLog = logTime; } /** - * * @param logName log category used to log time message. This category must - * be category used to log message in classe that use this TimeLog - * (normaly class name). TimeLog is added at the end. + * be category used to log message in classe that use this TimeLog + * (normaly class name). TimeLog is added at the end. */ public TimeLog(String logName) { this(LogFactory.getLog(logName + ".TimeLog")); @@ -115,19 +113,18 @@ /** * @param logName log category used to log time message. This category must - * be category used to log message in classe that use this TimeLog - * (normaly class name) + * be category used to log message in classe that use this TimeLog + * (normaly class name) * @since 2.1 */ - public TimeLog(Class logName) { + public TimeLog(Class<?> logName) { this(logName.getName()); } /** - * - * @param logName log category used to log time message. This category must - * be category used to log message in classe that use this TimeLog - * (normaly class name) + * @param logName log category used to log time message. This category must + * be category used to log message in classe that use this TimeLog + * (normaly class name) * @param timeToLogInfo time in milliseconde after that we log info * @param timeToLogWarn time in milliseconde after that we log warn */ @@ -138,31 +135,24 @@ } /** - * - * @param logName log category used to log time message. This category must - * be category used to log message in classe that use this TimeLog - * (normaly class name) + * @param logName log category used to log time message. This category must + * be category used to log message in classe that use this TimeLog + * (normaly class name) * @param timeToLogInfo time in milliseconde after that we log info * @param timeToLogWarn time in milliseconde after that we log warn */ - public TimeLog(Class logName, long timeToLogInfo, long timeToLogWarn) { + public TimeLog(Class<?> logName, long timeToLogInfo, long timeToLogWarn) { this(logName.getName(), timeToLogInfo, timeToLogWarn); } - /** - * - * @param timeToLogInfoMs time in milliseconde after that we log info - */ + /** @param timeToLogInfoMs time in milliseconde after that we log info */ public void setTimeToLogInfo(long timeToLogInfoMs) { - this.timeToLogInfo = timeToLogInfoMs * 1000000l; // convert ms -> ns + timeToLogInfo = timeToLogInfoMs * 1000000l; // convert ms -> ns } - /** - * - * @param timeToLogWarnMs time in milliseconde after that we log warn - */ + /** @param timeToLogWarnMs time in milliseconde after that we log warn */ public void setTimeToLogWarn(long timeToLogWarnMs) { - this.timeToLogWarn = timeToLogWarnMs * 1000000l; // convert ms -> ns + timeToLogWarn = timeToLogWarnMs * 1000000l; // convert ms -> ns } public Map<String, CallStat> getCallCount() { @@ -170,18 +160,22 @@ } /** - * return time in format acceptable for {@link #add(timeToLogInfo, timeToLogInfo, null)} - * @return + * return time in format acceptable for + * {@link #log(long, long, String, String)} method. + * + * @return the current time in nanoseconds */ static public long getTime() { return System.nanoTime(); } /** - * add new trace, stop time is automaticaly computed + * add new trace, stop time is automaticaly computed. * - * @param startNs time returned by {@link #getTime()} method + * @param startNs time returned by {@link #getTime()} method * @param methodName key name to store this time + * @return time used as stop time, this permit to chain many add in same + * method to trace time. */ public long log(long startNs, String methodName) { long result = log(startNs, getTime(), methodName, ""); @@ -191,11 +185,11 @@ /** * add new trace, stop time is automaticaly computed * - * @param startNs time returned by {@link #getTime()} method + * @param startNs time returned by {@link #getTime()} method * @param methodName key name to store this time - * @param msg message to add to log + * @param msg message to add to log * @return time used as stop time, this permit to chain many add in same - * method to trace time. + * method to trace time. */ public long log(long startNs, String methodName, String msg) { long result = log(startNs, getTime(), methodName, msg); @@ -205,10 +199,10 @@ /** * add new trace * - * @param startNs time returned by {@link #getTime()} method - * @param stopNs time returned by {@link #getTime()} method + * @param startNs time returned by {@link #getTime()} method + * @param stopNs time returned by {@link #getTime()} method * @param methodName key name to store this time - * @param msg message to add to log + * @param msg message to add to log * @return time used as stop time (stopNs) */ public long log(long startNs, long stopNs, String methodName, String msg) { @@ -227,7 +221,7 @@ // affiche le temps de l'appel si necessaire String timeString = StringUtil.convertTime(time); String message = String.format("[%s] for method '%s', %s (%s)", - timeString, methodName, msg, calls); + timeString, methodName, msg, calls); if (time > timeToLogWarn && timeLog.isWarnEnabled()) { timeLog.warn(message); Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeTrace.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeTrace.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeTrace.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -58,7 +58,7 @@ @Deprecated public class TimeTrace { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ private Log log = LogFactory.getLog(TimeTrace.class); static public class CallStat { Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ZipStreamEncoder.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ZipStreamEncoder.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ZipStreamEncoder.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -41,7 +41,7 @@ */ public class ZipStreamEncoder extends Thread { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(ZipStreamEncoder.class); /** The Constant BUFFER. */ Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ConverterUtil.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ConverterUtil.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ConverterUtil.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -40,7 +40,7 @@ */ public class ConverterUtil { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(ConverterUtil.class); /** Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/EnumConverter.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/EnumConverter.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/EnumConverter.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -49,7 +49,7 @@ */ public class EnumConverter implements Converter { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static Log log = getLog(EnumConverter.class); /** valeur par default à utiliser, si pas non trouvée et {@link #useDefault} actif. */ Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -43,7 +43,7 @@ * 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: + * par exemple si on enregistre les convertiseurs suivant: * <pre> * addConverter(new MatrixToXMLFormatConverter()); * addConverter(new MatrixToSQLFormatConverter()); @@ -60,7 +60,7 @@ */ public class FormatConverterFactory { // FormatConverterFactory - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(FormatConverterFactory.class); static protected FormatConverterFactory instance; Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/URIConverter.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/URIConverter.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/URIConverter.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -26,14 +26,15 @@ package org.nuiton.util.converter; import org.apache.commons.beanutils.ConversionException; -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n._; +import org.apache.commons.beanutils.Converter; +import org.apache.commons.logging.Log; import java.net.URI; import java.net.URISyntaxException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; +import static org.apache.commons.logging.LogFactory.getLog; +import static org.nuiton.i18n.I18n._; + /** * classe pour convertir une chaine en un objet URI. * @@ -42,7 +43,7 @@ */ public class URIConverter implements Converter { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static Log log = getLog(URIConverter.class); @Override @@ -79,7 +80,7 @@ public URIConverter() { if (log.isDebugEnabled()) { - log.debug(this); + log.debug("init uri converter " + this); } } Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/URLConverter.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/URLConverter.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/URLConverter.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -26,14 +26,15 @@ package org.nuiton.util.converter; import org.apache.commons.beanutils.ConversionException; -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n._; +import org.apache.commons.beanutils.Converter; +import org.apache.commons.logging.Log; import java.net.MalformedURLException; import java.net.URL; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; +import static org.apache.commons.logging.LogFactory.getLog; +import static org.nuiton.i18n.I18n._; + /** * classe pour convertir une chaine en un objet URL. * @@ -42,7 +43,7 @@ */ public class URLConverter implements Converter { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static Log log = getLog(URLConverter.class); @Override @@ -63,7 +64,7 @@ } } throw new ConversionException( - _("nuitonutil.error.no.convertor", aClass.getName(), value)); + _("nuitonutil.error.no.convertor", aClass.getName(), value)); } protected URL valueOf(String value) { @@ -78,7 +79,9 @@ } public URLConverter() { - log.info(this); + if (log.isDebugEnabled()) { + log.debug("init url converter " + this); + } } protected boolean isEnabled(Class<?> aClass) { Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/VersionConverter.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/VersionConverter.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/VersionConverter.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -43,12 +43,12 @@ */ public class VersionConverter implements Converter { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ private static final Log log = LogFactory.getLog(VersionConverter.class); public VersionConverter() { if (log.isDebugEnabled()) { - log.debug(this); + log.debug("init version converter " + this); } } Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/CallAnalyseTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/CallAnalyseTest.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/CallAnalyseTest.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -45,7 +45,7 @@ public class CallAnalyseTest extends TestCase { // CallAnalyseTest - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(CallAnalyseTest.class); protected List<List<?>> memoryConsume = new ArrayList<List<?>>(); Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/ZipUtilTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/ZipUtilTest.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/ZipUtilTest.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -51,7 +51,7 @@ */ public class ZipUtilTest { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ private static Log log = LogFactory.getLog(ZipUtilTest.class); protected static final File DIR = new File(System.getProperty("java.home"), Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-05-10 08:12:36 UTC (rev 2136) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java 2011-05-13 09:07:31 UTC (rev 2137) @@ -38,7 +38,7 @@ */ public class RmiExporterAndProxyTest { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ static private Log log = LogFactory.getLog(RmiExporterAndProxyTest.class); @Test(expected = NullPointerException.class)