home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / afc11 / AFCDetect / src / AFCVersionManager.java < prev   
Encoding:
Java Source  |  2000-05-04  |  4.5 KB  |  174 lines

  1. //
  2. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. //
  4.  
  5. import com.ms.util.SystemVersionManager;
  6. import java.util.Properties;
  7.  
  8. /**
  9.  *    Version Mananger class for AFC. This class will obtain version information
  10.  *    about AFC through the getAFCVersion() method.
  11.  *
  12.  *    @version    1.0, 8/19/97
  13.  */
  14.  
  15. public final class AFCVersionManager
  16. {
  17.     /**
  18.      *    Creates a new Properties object with the keys necessary for extracting
  19.      *    version information. Uses the passed values as the version number.
  20.      *
  21.      *    @param    major    Major version number    
  22.      *    @param    minor    Minor version number    
  23.      *    @param    buildnum    Build number
  24.      *    @param    buildinc    Build increment number
  25.      *    @param    description    Description of the version         
  26.      *    @returns    A Properties object which holds the version information
  27.      */
  28.     public static Properties createVersion (int major, int minor, int buildnum, int buildinc, String description)
  29.         {
  30.             // from the VersionManager sample from SDK 1.5 Samples.
  31.  
  32.             Properties info = new Properties();
  33.  
  34.             // These properties should be present on all version objects.
  35.         
  36.             info.put("MajorVersion", Integer.toString(major));
  37.             info.put("MinorVersion", Integer.toString(minor));
  38.             info.put("Description", new String(description));
  39.                     
  40.             return info;
  41.         }
  42.  
  43.     /**
  44.      *    Find version information for the specified package. Returns this
  45.      *    information in a Properties object. See the com.util.SystemVersionManager
  46.      *    class for the keys to expect in the returned Properties object.
  47.      *
  48.      *    @param    pkgname    Name of package to retrieve version information
  49.      *    @returns    A Properties object which holds the version information
  50.      */
  51.     public static Properties getPackageVersion (String pkgname)
  52.         {
  53.             // from the VersionManager sample from SDK 1.5 Samples.
  54.  
  55.             Properties info = null;
  56.         
  57.             try
  58.                 {
  59.                     info = SystemVersionManager.getPackageVersion(pkgname);
  60.  
  61.                     if (info != null)
  62.                         return info;
  63.                 }
  64.             catch (Throwable e)
  65.                 {
  66.                     // No system version manager installed.
  67.                 }
  68.             
  69.             if (pkgname == null)
  70.                 return null;
  71.             
  72.     
  73.             // Attempt to locate a 'Version' class within the specified package.
  74.             // If not found, try the parent package.
  75.         
  76.             try
  77.                 {
  78.                     Class c = Class.forName((pkgname.length() > 0) ? (pkgname+".Version") : "Version");
  79.                     Object o = c.newInstance();
  80.                     //info = ((Version)o).getVersion();                        
  81.                     info = (Properties)o;
  82.                 }
  83.             catch (ClassNotFoundException e)
  84.                 {
  85.                     int i = pkgname.lastIndexOf('.');
  86.         
  87.                     if (i != -1)
  88.                         info = getPackageVersion(pkgname.substring(0,i));
  89.                 }
  90.             catch (Throwable e)
  91.                 {                    
  92.                 }
  93.                 
  94.             return info;
  95.         }
  96.  
  97.     /**
  98.      *    Retrieves the full dot-separated version number (major, minor, build number, build increment) of the package
  99.      *    
  100.      *    @param    pkgname    Name of package to retrieve version information
  101.      *    @returns    A string which holds the version information
  102.      */
  103.     static public String getPackageVersionFull(String packageName)
  104.         {
  105.             Properties prop = AFCVersionManager.getPackageVersion(packageName);
  106.  
  107.             if (prop == null)
  108.                 {
  109.                     return null;
  110.                 }
  111.  
  112.             return    (String)prop.get("MajorVersion")+"."+
  113.                     (String)prop.get("MinorVersion");                    
  114.         }
  115.     
  116.     /**
  117.      *    Retrieves the major version number of the package.
  118.      *    
  119.      *    @param    pkgname    Name of package to retrieve version information
  120.      *    @returns    The major version number of the package
  121.      */
  122.     static public int getPackageVersionMajor(String packageName)
  123.         {
  124.             Properties prop = getPackageVersion(packageName);
  125.             
  126.             if (prop == null)
  127.                 {
  128.                     return -1;
  129.                 }
  130.  
  131.             return Integer.parseInt((String)prop.get("MajorVersion"));
  132.         }
  133.  
  134.     /**
  135.      *    Retrieves the minor version number of the package.
  136.      *    
  137.      *    @param    pkgname    Name of package to retrieve version information
  138.      *    @returns    The minor version number of the package
  139.      */    
  140.     static public int getPackageVersionMinor(String packageName)
  141.         {
  142.             Properties prop = getPackageVersion(packageName);
  143.  
  144.             if (prop == null)
  145.                 {
  146.                     return -1;
  147.                 }
  148.  
  149.             return Integer.parseInt((String)prop.get("MinorVersion"));
  150.         }
  151.         
  152.     /**
  153.      *    Retrieves the version description string from package.
  154.      *    
  155.      *    @param    pkgname    Name of package to retrieve version information
  156.      *    @returns    The description string of the package
  157.      */        
  158.     
  159.     static public String getPackageVersionDescription(String packageName)
  160.         {
  161.             Properties prop = getPackageVersion(packageName);
  162.  
  163.             if (prop == null)
  164.                 {
  165.                     return null;
  166.                 }
  167.  
  168.             return (String)prop.get("Description");
  169.         }    
  170. }    
  171.  
  172.  
  173.  
  174.