KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > env > EnvironmentDetector


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.env;
5
6 import java.io.PrintStream JavaDoc;
7 import java.lang.reflect.Method JavaDoc;
8
9 public class EnvironmentDetector {
10
11   private final PrintStream JavaDoc m_stream;
12
13   public EnvironmentDetector(PrintStream JavaDoc s) {
14     m_stream = s;
15   }
16
17   public void printTomcatInfo() {
18     String JavaDoc info;
19     try {
20       // TODO check if this class and method exists for all Tomcat versions - I have only looked at 5.x
21
Class JavaDoc serverInfo = Class.forName(
22           "org.apache.catalina.util.ServerInfo",
23           true,
24           EnvironmentDetector.class.getClassLoader()
25       );
26       Method JavaDoc getServerInfo = serverInfo.getMethod("getServerInfo", new Class JavaDoc[]{});
27       info = (String JavaDoc)getServerInfo.invoke(null, new Object JavaDoc[]{});
28     } catch (Throwable JavaDoc e) {
29       // ignore - not Tomcat
30
return;
31     }
32     m_stream.println("Tomcat Version:\t" + info);
33   }
34
35   public void printJavaInfo() {
36     m_stream.println("JVM Vendor:\t\t" + System.getProperty("java.vendor").toUpperCase());
37     m_stream.println("JVM Version:\t\tto" + System.getProperty("java.version").toUpperCase());
38   }
39
40   public void printOSInfo() {
41     m_stream.println("OS Arch:\t\t" + System.getProperty("os.arch").toUpperCase());
42     m_stream.println("OS Name:\t\t" + System.getProperty("os.name").toUpperCase());
43     m_stream.println("OS Version:\t\t" + System.getProperty("os.version").toUpperCase());
44   }
45
46   public void printEnv() {
47     EnvironmentDetector detector = new EnvironmentDetector(m_stream);
48     m_stream.println("----------------------------------");
49     detector.printOSInfo();
50     detector.printJavaInfo();
51     detector.printTomcatInfo();
52   }
53
54   public static void main(String JavaDoc[] args) {
55     new EnvironmentDetector(System.out).printEnv();
56   }
57 }
Popular Tags