View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
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.jdiagnose.library;
17  
18  import org.jdiagnose.DiagnosticUnit;
19  import org.jdiagnose.DiagnosticException;
20  
21  /***
22   * JDiagnose Diagnosic. Just checks the Java Version for now.
23   * User: jamie
24   * Date: May 31, 2004
25   * Time: 8:42:47 PM
26   */
27  public class DiagnoseDiagnostic extends DiagnosticUnit {
28  
29      /***
30       * Default Constructor
31       */
32      public DiagnoseDiagnostic() {
33          super();
34      }
35  
36      /***
37       * Construct with a new fully qualified name
38       * @param name the fqn of this diagnostic
39       */
40      public DiagnoseDiagnostic(String name) {
41          super(name);
42      }
43  
44      /***
45       * Check to see that the Java Version is 1.3 or higher
46       * @throws DiagnosticException if the Java Version isn't matched
47       */
48      public void diagnoseJavaVersion13OrGreater() throws DiagnosticException {
49          String javaClassVersion = System.getProperty("java.class.version");
50          assertNotNull("System property java.class.version should not be null", javaClassVersion);
51          try {
52              double version = Double.parseDouble(javaClassVersion);
53              assertTrue("Your Java version should be 1.3 or above", version >= 47.0);
54          } catch (NumberFormatException e) {
55              throw new DiagnosticException("System property java.class.version " +
56                      "should be a number but is " + javaClassVersion);
57          }
58      }
59  
60  }