1 22 package org.objectweb.petals.util; 23 24 import java.net.URL ; 25 import java.util.Properties ; 26 27 import org.objectweb.petals.PetalsException; 28 29 37 public final class PropertyUtil { 38 39 42 public final static String SERVER_PROPS = "/server.properties"; 43 44 private PropertyUtil() { 45 } 47 48 59 public static String getProperty(String propertiesFile, String key) 60 throws PetalsException { 61 try { 62 URL url = PropertyUtil.class.getResource(propertiesFile); 63 Properties properties = new Properties (); 64 properties.load(url.openStream()); 65 return properties.getProperty(key); 66 } catch (Exception e) { 67 throw new PetalsException("Problem while trying to get property " 68 + key + " of " + propertiesFile, e); 69 } 70 } 71 72 80 public static Properties retreiveJNDIProperties(String propertiesFile) 81 throws PetalsException { 82 try { 83 URL url = PropertyUtil.class.getResource(propertiesFile); 84 Properties properties = new Properties (); 85 properties.load(url.openStream()); 86 Properties outProperties = new Properties (); 87 outProperties.setProperty("java.naming.factory.host", properties 88 .getProperty("java.naming.factory.host")); 89 outProperties.setProperty("java.naming.factory.port", properties 90 .getProperty("java.naming.factory.port")); 91 outProperties.setProperty("java.naming.factory.initial", properties 92 .getProperty("java.naming.factory.initial")); 93 return outProperties; 94 } catch (Exception e) { 95 throw new PetalsException( 96 "Problem while trying to get JNDI properties of " 97 + propertiesFile, e); 98 } 99 } 100 } 101
| Popular Tags
|