KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > configuration > condition > JavaVariable


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

17 package org.apache.geronimo.system.configuration.condition;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 /**
23  * Provides access to Java version details for use in condition expressions.
24  *
25  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
26  */

27 public class JavaVariable
28 {
29     private static final Log log = LogFactory.getLog(JavaVariable.class);
30     
31     public String JavaDoc getVendor() {
32         return SystemUtils.JAVA_VENDOR;
33     }
34
35     public String JavaDoc getVresion() {
36         return SystemUtils.JAVA_VERSION;
37     }
38
39     public String JavaDoc getVmVendor() {
40         return SystemUtils.JAVA_VM_VENDOR;
41     }
42     
43     public String JavaDoc getVmVersion() {
44         return SystemUtils.JAVA_VM_VERSION;
45     }
46
47     public boolean getIs1_1() {
48         return SystemUtils.IS_JAVA_1_1;
49     }
50
51     public boolean getIs1_2() {
52         return SystemUtils.IS_JAVA_1_2;
53     }
54
55     public boolean getIs1_3() {
56         return SystemUtils.IS_JAVA_1_3;
57     }
58
59     public boolean getIs1_4() {
60         return SystemUtils.IS_JAVA_1_4;
61     }
62
63     public boolean getIs1_5() {
64         return SystemUtils.IS_JAVA_1_5;
65     }
66
67     public boolean getIs1_6() {
68         return SystemUtils.IS_JAVA_1_6;
69     }
70
71     public boolean getIsVersionAtLeast(final float requiredVersion) {
72         return SystemUtils.isJavaVersionAtLeast(requiredVersion);
73     }
74
75     public boolean getIsVersionAtLeast(final int requiredVersion) {
76         return SystemUtils.isJavaVersionAtLeast(requiredVersion);
77     }
78     
79     public boolean getVersionMatches(String JavaDoc version) {
80         version = version.trim();
81         
82         boolean debug = log.isDebugEnabled();
83         boolean result = false;
84         
85         if (version.endsWith("*")) {
86             version = version.substring(0, version.length() - 1).trim();
87             
88             if (debug) {
89                 log.debug("Checking Java version is in the same group as: " + version);
90             }
91             
92             String JavaDoc tmp = SystemUtils.JAVA_VERSION_TRIMMED;
93             
94             if (debug) {
95                 log.debug("Requested version: " + tmp);
96                 log.debug("JVM version: " + SystemUtils.JAVA_VERSION_FLOAT);
97             }
98             
99             result = tmp.startsWith(version);
100         }
101         else if (version.endsWith("+")) {
102             version = version.substring(0, version.length() - 1).trim();
103             
104             if (debug) {
105                 log.debug("Checking Java version is greater than: " + version);
106             }
107             
108             float tmp = Float.parseFloat(version);
109             
110             if (debug) {
111                 log.debug("Requested version: " + tmp);
112                 log.debug("JVM version: " + SystemUtils.JAVA_VERSION_FLOAT);
113             }
114             
115             result = tmp <= SystemUtils.JAVA_VERSION_FLOAT;
116         }
117         else {
118             if (debug) {
119                 log.debug("Checking Java version is equal to: " + version);
120             }
121             
122             float tmp = Float.parseFloat(version);
123             
124             if (debug) {
125                 log.debug("Requested version: " + tmp);
126                 log.debug("JVM version: " + SystemUtils.JAVA_VERSION_FLOAT);
127             }
128             
129             result = tmp == SystemUtils.JAVA_VERSION_FLOAT;
130         }
131         
132         return result;
133     }
134 }
135
Popular Tags