KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > util > VersionUtil


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.directwebremoting.util;
17
18 import java.io.InputStream JavaDoc;
19 import java.util.Properties JavaDoc;
20
21 /**
22  * Interface to the system version info file
23  * @author Joe Walker [joe at getahead dot ltd dot uk]
24  */

25 public class VersionUtil
26 {
27     /**
28      * Fish the version number out of the dwr.properties file.
29      * @return The current version number.
30      */

31     public static String JavaDoc getSourceControlInfo()
32     {
33         synchronized (propLock)
34         {
35             if (props == null)
36             {
37                 loadProperties();
38             }
39
40             return props.getProperty(KEY_SCCINFO);
41         }
42     }
43
44     /**
45      * Fish the version number out of the dwr.properties file.
46      * @return The current version number.
47      */

48     public static String JavaDoc getVersion()
49     {
50         synchronized (propLock)
51         {
52             if (props == null)
53             {
54                 loadProperties();
55             }
56
57             return props.getProperty(KEY_VERSION);
58         }
59     }
60
61     /**
62      * Load the properties from the internal properties file.
63      */

64     private static void loadProperties()
65     {
66         synchronized (propLock)
67         {
68             props = new Properties JavaDoc();
69
70             try
71             {
72                 InputStream JavaDoc in = VersionUtil.class.getResourceAsStream(FILENAME_VERSION);
73                 props.load(in);
74             }
75             catch (Exception JavaDoc ex)
76             {
77                 props.put(KEY_VERSION, VALUE_UNKNOWN);
78                 props.put(KEY_SCCINFO, VALUE_UNKNOWN);
79                 props.put(KEY_ERROR, ex.toString());
80             }
81         }
82     }
83
84     private static Properties JavaDoc props = null;
85
86     private static final Object JavaDoc propLock = new Object JavaDoc();
87
88     private static final String JavaDoc FILENAME_VERSION = "/dwr-version.properties";
89
90     private static final String JavaDoc KEY_VERSION = "version";
91
92     private static final String JavaDoc KEY_SCCINFO = "scc-info";
93
94     private static final String JavaDoc KEY_ERROR = "error";
95
96     private static final String JavaDoc VALUE_UNKNOWN = "unknown";
97 }
98
Popular Tags