KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > util > RepositoryProperties


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 /*
24  * RepositoryProperties.java
25  *
26  * Created on 6 novembre 2000, 11:33
27  */

28
29 package org.xquark.mapper.util;
30
31 import java.io.IOException JavaDoc;
32 import java.io.InputStream JavaDoc;
33 import java.util.Properties JavaDoc;
34
35 import org.xquark.mapper.AccessManager;
36 import org.xquark.mapper.metadata.RepositoryConstants;
37
38 /** This class manages repository configuration information.
39  *
40  * <p>The property file is intended to be found in the CLASSPATH, either
41  * at the root or in org.xquark.mapper package. Its name is
42  * </p>
43  */

44 public class RepositoryProperties implements RepositoryConstants
45 {
46     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
47     private static final String JavaDoc RCSName = "$Name: $";
48     
49     private static Properties JavaDoc properties = null;
50     
51     static
52     {
53         load();
54     }
55
56     /* Singleton */
57     private RepositoryProperties() {}
58
59     public static String JavaDoc getStringProperty(String JavaDoc prop)
60     {
61         if (properties == null)
62             return null;
63         return properties.getProperty(prop);
64     }
65     public static int getIntProperty(String JavaDoc prop)
66     {
67         if (properties == null)
68             return -1;
69         return Integer.parseInt(properties.getProperty(prop));
70     }
71
72     public static boolean getBooleanProperty(String JavaDoc prop)
73     {
74         if (properties == null)
75             return false;
76         return Boolean.valueOf(properties.getProperty(prop)).booleanValue();
77     }
78
79     public static void load()
80     {
81         Properties JavaDoc defaultProperties = null;
82         if (properties != null)
83             return;
84         try {
85             defaultProperties = new Properties JavaDoc();
86             defaultProperties.load(AccessManager.class.getResourceAsStream(
87                 RESOURCES_FOLDER + DEFAULT_CONF_FILE));
88             properties = new Properties JavaDoc(defaultProperties);
89         }
90         catch (IOException JavaDoc e) {
91             throw new RuntimeException JavaDoc("Default configuration file couldn't be opened:" + e.getMessage());
92         }
93         try {
94             InputStream JavaDoc inStream = AccessManager.class.getResourceAsStream("/" + CONF_FILE); // look first in CLASSPATH root
95
if (inStream == null) // look then in xquark package
96
inStream = AccessManager.class.getResourceAsStream(CONF_PACKAGE + CONF_FILE); // SR 09/01/2001 GetSystemResource -> getResource
97
if (inStream == null) // look eventually in the AccessManager package
98
inStream = AccessManager.class.getResourceAsStream(RESOURCES_FOLDER + DEFAULT_CONF_FILE);
99             if (inStream == null)
100                 properties = defaultProperties;
101             else
102                 properties.load(inStream);
103         }
104         catch (IOException JavaDoc e) {
105             throw new RuntimeException JavaDoc("Default configuration file couldn't be opened:" + e.getMessage());
106         }
107     }
108 }
109
Popular Tags