home *** CD-ROM | disk | FTP | other *** search
/ Chip Special: HTML & Java / Chip-Special_1997-01_HTML-a-Java.bin / javasdk / sdk-java.exe / SDKJava.cab / Samples / Version / VersionManager.java < prev    next >
Encoding:
Java Source  |  1996-10-10  |  3.4 KB  |  134 lines

  1. // VersionManager.java
  2. //
  3. // Created 09/24/96
  4. //
  5. // (C)Copyright 1996 Microsoft Corporation, All rights reserved.
  6. //
  7.  
  8. import com.ms.util.SystemVersionManager;
  9. import java.util.*;
  10.  
  11.  
  12. public final
  13. class VersionManager
  14. {
  15.     private VersionManager () {}
  16.  
  17.  
  18.     // Determines if vm is Microsoft's.
  19.  
  20.     public static boolean isMicrosoftVM () 
  21.     { 
  22.         return System.getProperty("java.vendor").equals("Microsoft Corp."); 
  23.     }
  24.  
  25.  
  26.     // Helper to simplify creation of a version object.
  27.  
  28.     public static Properties createVersion (int major, int minor, int buildnum, int buildinc, String description)
  29.     {
  30.         Properties info = new Properties();
  31.  
  32.         // These properties should be present on all version objects.
  33.         
  34.         info.put("MajorVersion", Integer.toString(major));
  35.         info.put("MinorVersion", Integer.toString(minor));
  36.         info.put("BuildNumber", Integer.toString(buildnum));
  37.         info.put("BuildIncrement", Integer.toString(buildinc));
  38.         info.put("Description", new String(description));
  39.         
  40.         return info;
  41.     }
  42.  
  43.  
  44.     // Find version information for the specified package.
  45.  
  46.     public static Properties getPackageVersion (String pkgname)
  47.     {
  48.         Properties info = null;
  49.         
  50.         try
  51.         {
  52.             info = SystemVersionManager.getPackageVersion(pkgname);
  53.  
  54.             if (info != null)
  55.                 return info;
  56.         }
  57.         catch (Throwable e)
  58.         {
  59.             // No system version manager installed.
  60.         }
  61.  
  62.  
  63.         if (pkgname == null)
  64.             return null;
  65.             
  66.     
  67.         // Attempt to locate a 'Version' class within the specified package.
  68.         // If not found, try the parent package.
  69.         
  70.         try
  71.         {
  72.             Class c = Class.forName((pkgname.length() > 0) ? (pkgname+".Version") : "Version");
  73.             Object o = c.newInstance();
  74.             info = (Properties)o;
  75.         }
  76.         catch (ClassNotFoundException e)
  77.         {
  78.             int i = pkgname.lastIndexOf('.');
  79.  
  80.             if (i != -1)
  81.                info = getPackageVersion(pkgname.substring(0,i));
  82.         }
  83.         catch (Throwable e)
  84.         {
  85.         }
  86.  
  87.         return info;
  88.     }
  89.  
  90.  
  91.     // Find version information for a system component.  System components
  92.     // can be enumerated via SystemVersionManager.enumerate.
  93.  
  94.     public static Properties getSystemComponentVersion (String compname)
  95.     {
  96.         try
  97.         {
  98.             return SystemVersionManager.getSystemComponentVersion(compname);
  99.         }
  100.         catch (Throwable e)
  101.         {
  102.             // No system version manager installed.
  103.         }
  104.  
  105.  
  106.         if (compname == null)
  107.             return null;
  108.  
  109.     
  110.         Properties info = null;
  111.  
  112.         if (isMicrosoftVM())
  113.         {
  114.             // If all else fails, default to information for the 3.0 release.
  115.         
  116.             if (compname.equals("VM"))
  117.             {
  118.                 info = createVersion(4,79,0,1158,"Microsoft (R) VM for Java (tm), 3.0 Release");
  119.             }
  120.             else if (compname.equals("Classes"))
  121.             {
  122.                 info = createVersion(4,79,0,1155,"Microsoft (R) System Classes, 3.0 Release");
  123.             }
  124.             else if (compname.equals("TrustedClasses"))
  125.             {
  126.                 info = createVersion(4,79,0,1155,"Microsoft (R) Trusted Classes, 3.0 Release");
  127.             }
  128.         }
  129.  
  130.         return info;
  131.     }
  132. }
  133.  
  134.