KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > jdbclogger > core > config > Environment


1 package net.sourceforge.jdbclogger.core.config;
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 import net.sourceforge.jdbclogger.core.util.ConfigHelper;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 /**
27  * @author Catalin Kormos (latest modification by $Author: catalean $)
28  * @version $Revision: 83 $ $Date: 2007-07-08 00:00:58 +0300 (Sun, 08 Jul 2007) $
29  */

30 public class Environment
31 {
32     private static final Log log = LogFactory.getLog(Environment.class);
33     private static Properties JavaDoc GLOBAL_PROPERTIES = new Properties JavaDoc();
34     
35     static
36     {
37         InputStream JavaDoc stream = ConfigHelper.getResourceAsStream("/" + JdbcLoggerConstants.USER_CONFIG_FILE_NAME);
38         try
39         {
40             GLOBAL_PROPERTIES.load(stream);
41         }
42         catch (Exception JavaDoc exc)
43         {
44             log.error("problem loading properties from jdbclogger.properties", exc);
45         }
46         finally
47         {
48             try
49             {
50                 if (stream != null) stream.close();
51             }
52             catch (IOException JavaDoc exc)
53             {
54                 log.error("could not close stream on jdbclogger.properties", exc);
55             }
56         }
57         //system properties override properties from jdbclogger.properties file
58
GLOBAL_PROPERTIES.putAll(System.getProperties());
59     }
60     
61     /**
62      * Return the properties specified jdbclogger.properties
63      * @return Properties
64      */

65     public static Properties JavaDoc getProperties()
66     {
67         Properties JavaDoc copy = new Properties JavaDoc();
68         copy.putAll(GLOBAL_PROPERTIES);
69         return copy;
70     }
71 }
72
Popular Tags