Author: chatellier Date: 2009-06-03 07:12:54 +0000 (Wed, 03 Jun 2009) New Revision: 2312 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/util/UtilsUI.java Log: Refactor util sensitivity util class. Load properties file only once. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/util/UtilsUI.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/util/UtilsUI.java 2009-06-02 15:48:34 UTC (rev 2311) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/util/UtilsUI.java 2009-06-03 07:12:54 UTC (rev 2312) @@ -1,7 +1,21 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ +/* *##% + * Copyright (C) 2002-2009 Code Lutin, Benjamin Poussin + * + * 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 fr.ifremer.isisfish.ui.util; @@ -12,36 +26,69 @@ import org.apache.commons.logging.LogFactory; /** + * Utility class to parse Sensitivity properties file. + * + * @author letellier + * @version $Revision$ * - * @author letellier + * Last update: $Date$ + * by : $Author$ */ public class UtilsUI { + /** Log. */ private static final Log log = LogFactory.getLog(UtilsUI.class); - static final String propertiesPath = "/sensitivity.properties"; - static public boolean isSensitivity(String sens){ + /** Properties file resource path. */ + private final static String PROPERTIES_PATH = "/sensitivity.properties"; + + /** Cached properties. */ + private static Properties sensitivityProperties; + + /** + * Is field sensitivity enabled. + * + * Return true, if field name is present in properties file. + * + * @param sensitivityFactorName name + * @return <tt>true</tt> if factor name is sensitivity enabled + */ + public static boolean isSensitivity(String sensitivityFactorName) { Properties data = loadProperties(); - return data.getProperty(sens) != null; + return data.getProperty(sensitivityFactorName) != null; } - private static Properties loadProperties(){ - InputStream stream = null; - Properties data = null; - try { - stream = UtilsUI.class.getResourceAsStream(propertiesPath); - data = new Properties(); - data.load(stream); - } catch (IOException ex) { - log.error(ex); - } finally{ + /** + * Return cached properties file. + * Load it at first call. + * + * @return properties + */ + private static Properties loadProperties() { + + if (sensitivityProperties == null) { + sensitivityProperties = new Properties(); + InputStream stream = null; try { - stream.close(); + stream = UtilsUI.class.getResourceAsStream(PROPERTIES_PATH); + sensitivityProperties.load(stream); } catch (IOException ex) { - log.error(ex); + if (log.isErrorEnabled()) { + log.error("Can't load sensitivity properties file", ex); + } + } finally { + try { + if (stream != null) { + stream.close(); + } + } catch (IOException ex) { + if (log.isErrorEnabled()) { + log.error("Can't load sensitivity properties file", ex); + } + } } } - return data; + return sensitivityProperties; } } Property changes on: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/util/UtilsUI.java ___________________________________________________________________ Name: svn:keywords + Author Date Revision
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org