KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > util > PropertyLoader


1 /*
2  * Created on 05-May-2005
3  *
4  */

5 package com.jofti.util;
6
7 import java.io.InputStream JavaDoc;
8 import java.util.Properties JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 import com.jofti.exception.JoftiException;
14
15 /**
16  * @author Steve Woodcock (steve@jofti.com)
17  *
18  * TODO To change the template for this generated type comment go to
19  * Window - Preferences - Java - Code Style - Code Templates
20  */

21 public class PropertyLoader {
22
23     private static Log log = LogFactory.getLog(PropertyLoader.class);
24     
25     public static Properties JavaDoc loadProperties(String JavaDoc fileName) throws JoftiException{
26         
27         InputStream JavaDoc in =null;
28         Properties JavaDoc props =new Properties JavaDoc();
29         try {
30             if(log.isDebugEnabled())
31                 log.debug("Getting Config");
32             log.info("Getting stream for " + fileName);
33             in = PropertyLoader.class.getResourceAsStream(fileName);
34             if (in ==null){
35                 throw new JoftiException("Unable to find "+ fileName+ " ensure file is on classpath ");
36             }
37             log.info("Got stream for " + fileName);
38             
39             props.load(in);
40             
41         } catch(Exception JavaDoc e){
42              log.error("Error loading "+ fileName+ " ensure file is on classpath " + e);
43              throw new JoftiException(e);
44         } finally{
45             try
46             {
47                 if (in != null){
48                     in.close();
49                 }
50             } catch (Exception JavaDoc e){
51                 log.error("Error closing input stream for property load " + e);
52             }
53         }
54         return props;
55     }
56 }
57
Popular Tags