home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-10 | 3.4 KB | 134 lines |
- // VersionManager.java
- //
- // Created 09/24/96
- //
- // (C)Copyright 1996 Microsoft Corporation, All rights reserved.
- //
-
- import com.ms.util.SystemVersionManager;
- import java.util.*;
-
-
- public final
- class VersionManager
- {
- private VersionManager () {}
-
-
- // Determines if vm is Microsoft's.
-
- public static boolean isMicrosoftVM ()
- {
- return System.getProperty("java.vendor").equals("Microsoft Corp.");
- }
-
-
- // Helper to simplify creation of a version object.
-
- public static Properties createVersion (int major, int minor, int buildnum, int buildinc, String description)
- {
- Properties info = new Properties();
-
- // These properties should be present on all version objects.
-
- info.put("MajorVersion", Integer.toString(major));
- info.put("MinorVersion", Integer.toString(minor));
- info.put("BuildNumber", Integer.toString(buildnum));
- info.put("BuildIncrement", Integer.toString(buildinc));
- info.put("Description", new String(description));
-
- return info;
- }
-
-
- // Find version information for the specified package.
-
- public static Properties getPackageVersion (String pkgname)
- {
- Properties info = null;
-
- try
- {
- info = SystemVersionManager.getPackageVersion(pkgname);
-
- if (info != null)
- return info;
- }
- catch (Throwable e)
- {
- // No system version manager installed.
- }
-
-
- if (pkgname == null)
- return null;
-
-
- // Attempt to locate a 'Version' class within the specified package.
- // If not found, try the parent package.
-
- try
- {
- Class c = Class.forName((pkgname.length() > 0) ? (pkgname+".Version") : "Version");
- Object o = c.newInstance();
- info = (Properties)o;
- }
- catch (ClassNotFoundException e)
- {
- int i = pkgname.lastIndexOf('.');
-
- if (i != -1)
- info = getPackageVersion(pkgname.substring(0,i));
- }
- catch (Throwable e)
- {
- }
-
- return info;
- }
-
-
- // Find version information for a system component. System components
- // can be enumerated via SystemVersionManager.enumerate.
-
- public static Properties getSystemComponentVersion (String compname)
- {
- try
- {
- return SystemVersionManager.getSystemComponentVersion(compname);
- }
- catch (Throwable e)
- {
- // No system version manager installed.
- }
-
-
- if (compname == null)
- return null;
-
-
- Properties info = null;
-
- if (isMicrosoftVM())
- {
- // If all else fails, default to information for the 3.0 release.
-
- if (compname.equals("VM"))
- {
- info = createVersion(4,79,0,1158,"Microsoft (R) VM for Java (tm), 3.0 Release");
- }
- else if (compname.equals("Classes"))
- {
- info = createVersion(4,79,0,1155,"Microsoft (R) System Classes, 3.0 Release");
- }
- else if (compname.equals("TrustedClasses"))
- {
- info = createVersion(4,79,0,1155,"Microsoft (R) Trusted Classes, 3.0 Release");
- }
- }
-
- return info;
- }
- }
-
-