View Javadoc
1 /*** 2 * DefaultPropertiesReader.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 20.02.2003 pko creation 9 * 10 * Copyright 2003 ELCA Informatique SA 11 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 12 * www.elca.ch 13 * 14 * This library is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU Lesser General Public License 16 * as published by the Free Software Foundation; either version 2.1 of 17 * the License, or (at your option) any later version. 18 * 19 * This library is distributed in the hope that it will be useful, but 20 * WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 * Lesser General Public License for more details. 23 * 24 * You should have received a copy of the GNU Lesser General Public 25 * License along with this library; if not, write to the Free Software 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 27 * USA 28 */ 29 30 package ch.elca.dependency.util; 31 32 import java.io.File; 33 import java.io.InputStream; 34 import java.net.URL; 35 import java.util.Properties; 36 37 /*** 38 * The class <code>DefaultPropertiesReader</code> is used to read the 39 * default properties. Such "default" properties are store in files 40 * and packed together with the Dependency Tool in one jar file. 41 * 42 * @author Pawel Kowalski 43 * @version 1.0-beta 44 */ 45 public class DefaultPropertiesReader implements PropertiesReader { 46 47 //****************************************************************************************/ 48 // singleton part 49 //****************************************************************************************/ 50 51 /*** 52 * The only instance of the DefaultPropertiesReader. 53 */ 54 private static DefaultPropertiesReader m_instance = null; 55 56 /*** 57 * Get the one and only instance of this class. 58 * 59 * @return a <code>DefaultPropertiesReader</code> value 60 */ 61 public static synchronized DefaultPropertiesReader singleton() { 62 if (m_instance == null) { 63 m_instance = new DefaultPropertiesReader(); 64 } 65 return m_instance; 66 } 67 68 //****************************************************************************************/ 69 // instance variables 70 //****************************************************************************************/ 71 72 /*** 73 * The ClassLoader used to load resources. 74 */ 75 private static final ClassLoader m_classLoader = ClassLoader.getSystemClassLoader(); 76 77 //****************************************************************************************/ 78 // public methods 79 //****************************************************************************************/ 80 81 /*** 82 * Get the named properties as a Stream. 83 * 84 * @param propertiesName a <code>String</code> value 85 * @return an <code>InputStream</code> value 86 */ 87 public InputStream getPropertiesAsStream(String propertiesName) { 88 return m_classLoader.getResourceAsStream(propertiesName); 89 } 90 91 /*** 92 * Get the named Properties. 93 * 94 * @param propertiesName a <code>String</code> value 95 * @return a <code>Properties</code> value 96 */ 97 public Properties getProperties(String propertiesName) { 98 Properties properties = new Properties(); 99 InputStream propertiesStream = getPropertiesAsStream(propertiesName); 100 if (propertiesStream != null) { 101 try { 102 properties.load(getPropertiesAsStream(propertiesName)); 103 } catch (Exception e){ 104 ; 105 } 106 } 107 return properties; 108 } 109 110 /*** 111 * Get the URL of a resource. 112 * 113 * @param name a <code>String</code> value 114 * @return an <code>URL</code> value 115 */ 116 public URL getResource(String name) { 117 return m_classLoader.getResource(name); 118 } 119 }

This page was automatically generated by Maven