r2775 - trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils
Author: echatellier Date: 2009-09-09 15:48:11 +0200 (Wed, 09 Sep 2009) New Revision: 2775 Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java Log: Use a specifique properties file when using embedded war Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2009-09-09 10:45:06 UTC (rev 2774) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2009-09-09 13:48:11 UTC (rev 2775) @@ -18,6 +18,10 @@ import java.util.Properties; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.business.persistence.ChoiceTypeDAO; @@ -127,13 +131,43 @@ } /** + * Use to get properties filename in JNDI envirronement. + * + * Usefull to use un different war in embedded war context. + * + * @return properties filename found in JNDI (or a default one) + */ + protected String getPropertiesFileName() { + String filename = null; + + try { + Context context = new InitialContext(); + + filename = (String) context.lookup("configurationfilename"); + } catch (NamingException e) { + if (log.isErrorEnabled()) { + log.error("Can't get jndi", e); + } + } + + // .. if styll null, set default one + if (filename == null || filename.isEmpty()) { + filename = "pollen.properties"; + } + + return filename; + } + + /** * Constructeur. Construit le contexte global après avoir lu le fichier de * configuration de Pollen. */ private ContextUtil() { + String propertiesFilename = getPropertiesFileName(); + // Chargement du fichier de configuration - conf = PropertiesLoader.loadPropertiesFile("pollen.properties"); + conf = PropertiesLoader.loadPropertiesFile(propertiesFilename); conf.setProperty("topia.persistence.classes", PollenModelDAOHelper .getImplementationClassesAsString());
participants (1)
-
echatellier@users.chorem.org