KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > version > Version


1 package org.objectweb.celtix.version;
2
3 import java.io.*;
4 import java.util.*;
5
6 public final class Version {
7
8     private static String JavaDoc version;
9     
10     private static final String JavaDoc VERSION_BASE = "/org/objectweb/celtix/version/";
11
12     private Version() {
13         // utility class - never constructed
14
}
15
16     private static InputStream getResourceAsStream(String JavaDoc resource) {
17         ClassLoader JavaDoc cl = Version.class.getClassLoader();
18         InputStream ins = cl.getResourceAsStream(resource);
19         if (ins == null && resource.startsWith("/")) {
20             ins = cl.getResourceAsStream(resource.substring(1));
21         }
22         return ins;
23     }
24     
25     private static synchronized void loadProperties() {
26         if (version == null) {
27             Properties p = new Properties();
28
29             try {
30                 InputStream ins = getResourceAsStream(VERSION_BASE + "version.properties");
31
32                 p.load(ins);
33                 ins.close();
34             } catch (IOException ex) {
35                 // ignore, will end up with defaults
36
}
37
38             version = p.getProperty("product.version");
39         }
40     }
41
42     public static String JavaDoc getCurrentVersion() {
43         loadProperties();
44         return version;
45     }
46
47
48     /**
49      * Returns version string as normally used in print, such as 3.2.4
50      *
51      */

52     public static String JavaDoc getCompleteVersionString() {
53         return getCurrentVersion();
54     }
55 }
56
Popular Tags