KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > MondrianServerImpl


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/MondrianServerImpl.java#3 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2006-2007 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.olap;
11
12 import mondrian.rolap.RolapSchema;
13
14 import java.net.URL JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.util.regex.Pattern JavaDoc;
17 import java.util.regex.Matcher JavaDoc;
18
19 /**
20  * Implementation of {@link MondrianServer}.
21  *
22  * @author jhyde
23  * @version $Id: //open/mondrian/src/main/mondrian/olap/MondrianServerImpl.java#3 $
24  * @since Jun 25, 2006
25  */

26 class MondrianServerImpl extends MondrianServer {
27     private static MondrianVersion version = null;
28
29     public void flushSchemaCache() {
30         RolapSchema.clearCache();
31     }
32
33     public void flushDataCache() {
34         // not implemented
35
}
36
37     public MondrianVersion getVersion() {
38         return getVersionStatic();
39     }
40
41     private static synchronized MondrianVersion getVersionStatic() {
42         if (version == null) {
43             final String JavaDoc versionString = loadVersionFile();
44             version = new MondrianVersion() {
45                 public String JavaDoc getVersionString() {
46                     return versionString;
47                 }
48             };
49         }
50         return version;
51     }
52
53     private static String JavaDoc loadVersionFile() {
54         // First, try to read the version info from the package. If the classes
55
// came from a jar, this info will be set from manifest.mf.
56
Package JavaDoc pakkage = MondrianServerImpl.class.getPackage();
57         String JavaDoc implementationVersion = pakkage.getImplementationVersion();
58         if (implementationVersion != null) {
59             return implementationVersion;
60         }
61
62         // Second, try to read VERSION.txt.
63
URL JavaDoc resource =
64             MondrianServerImpl.class.getClassLoader()
65                 .getResource("DefaultRules.xml");
66         if (resource != null) {
67             try {
68                 String JavaDoc path = resource.getPath();
69                 String JavaDoc path2 =
70                     Util.replace(
71                         path, "classes/DefaultRules.xml", "VERSION.txt");
72                 URL JavaDoc resource2 =
73                     new URL JavaDoc(
74                         resource.getProtocol(),
75                         resource.getHost(),
76                         path2);
77                 String JavaDoc versionString = Util.readURL(resource2);
78                 Pattern JavaDoc pattern =
79                     Pattern.compile(
80                         "(?s)Title: (.*)\nVersion: (.*)\nVendor: (.*)\n.*");
81                 Matcher JavaDoc matcher = pattern.matcher(versionString);
82                 if (matcher.matches()) {
83                     int groupCount = matcher.groupCount();
84                     String JavaDoc title = matcher.group(1);
85                     String JavaDoc version = matcher.group(2);
86                     String JavaDoc vendor = matcher.group(3);
87                     return version;
88                 }
89             } catch (IOException JavaDoc e) {
90                 e.printStackTrace();
91             }
92         }
93         return "Unknown version";
94     }
95 }
96
97 // End MondrianServerImpl.java
98
Popular Tags