< prev index next >

src/java.base/share/classes/sun/misc/ExtensionInfo.java

Print this page




  28 import java.util.StringTokenizer;
  29 import java.util.jar.Attributes;
  30 import java.util.jar.Attributes.Name;
  31 import java.util.ResourceBundle;
  32 import java.util.MissingResourceException;
  33 import java.text.MessageFormat;
  34 import java.lang.Character.*;
  35 
  36 
  37 /**
  38  * This class holds all necessary information to install or
  39  * upgrade a extension on the user's disk
  40  *
  41  * @deprecated this class will be removed in a future release.
  42  * @author  Jerome Dochez
  43  */
  44 @Deprecated
  45 public class ExtensionInfo {
  46 
  47     /**
  48      * <p>
  49      * public static values returned by the isCompatible method
  50      * </p>
  51      */
  52     public static final int COMPATIBLE = 0;
  53     public static final int REQUIRE_SPECIFICATION_UPGRADE = 1;
  54     public static final int REQUIRE_IMPLEMENTATION_UPGRADE = 2;
  55     public static final int REQUIRE_VENDOR_SWITCH = 3;
  56     public static final int INCOMPATIBLE = 4;
  57 
  58     /**
  59      * <p>
  60      * attributes fully describer an extension. The underlying described
  61      * extension may be installed and requested.
  62      * <p>
  63      */
  64     public String title;
  65     public String name;
  66     public String specVersion;
  67     public String specVendor;
  68     public String implementationVersion;
  69     public String vendor;
  70     public String vendorId;
  71     public String url;
  72 
  73     // For I18N support
  74     private static final ResourceBundle rb =
  75         ResourceBundle.getBundle("sun.misc.resources.Messages");
  76 
  77 
  78     /**
  79      * <p>
  80      * Create a new uninitialized extension information object
  81      * </p>
  82      */
  83     public ExtensionInfo() {
  84     }
  85 
  86     /**
  87      * <p>
  88      * Create and initialize an extension information object.
  89      * The initialization uses the attributes passed as being
  90      * the content of a manifest file to load the extension
  91      * information from.
  92      * Since manifest file may contain information on several
  93      * extension they may depend on, the extension key parameter
  94      * is prepanded to the attribute name to make the key used
  95      * to retrieve the attribute from the manifest file
  96      * <p>
  97      * @param extensionKey unique extension key in the manifest
  98      * @param attr Attributes of a manifest file
  99      */
 100     public ExtensionInfo(String extensionKey, Attributes attr)
 101         throws NullPointerException
 102     {
 103         String s;
 104         if (extensionKey!=null) {
 105             s = extensionKey + "-";
 106         } else {
 107             s ="";
 108         }
 109 
 110         String attrKey = s + Name.EXTENSION_NAME.toString();
 111         name = attr.getValue(attrKey);
 112         if (name != null)
 113             name = name.trim();
 114 
 115         attrKey = s + Name.SPECIFICATION_TITLE.toString();
 116         title = attr.getValue(attrKey);


 132         if (implementationVersion != null)
 133             implementationVersion = implementationVersion.trim();
 134 
 135         attrKey = s + Name.IMPLEMENTATION_VENDOR.toString();
 136         vendor = attr.getValue(attrKey);
 137         if (vendor != null)
 138             vendor = vendor.trim();
 139 
 140         attrKey = s + Name.IMPLEMENTATION_VENDOR_ID.toString();
 141         vendorId = attr.getValue(attrKey);
 142         if (vendorId != null)
 143             vendorId = vendorId.trim();
 144 
 145         attrKey =s + Name.IMPLEMENTATION_URL.toString();
 146         url = attr.getValue(attrKey);
 147         if (url != null)
 148             url = url.trim();
 149     }
 150 
 151     /**
 152      * <p>
 153      * @return true if the extension described by this extension information
 154      * is compatible with the extension described by the extension
 155      * information passed as a parameter
 156      * </p>
 157      *
 158      * @param the requested extension information to compare to
 159      */
 160     public int isCompatibleWith(ExtensionInfo ei) {
 161 
 162         if (name == null || ei.name == null)
 163             return INCOMPATIBLE;
 164         if (name.compareTo(ei.name)==0) {
 165             // is this true, if not spec version is specified, we consider
 166             // the value as being "any".
 167             if (specVersion == null || ei.specVersion == null)
 168                 return COMPATIBLE;
 169 
 170             int version = compareExtensionVersion(specVersion, ei.specVersion);
 171             if (version<0) {
 172                 // this extension specification is "older"
 173                 if (vendorId != null && ei.vendorId !=null) {
 174                     if (vendorId.compareTo(ei.vendorId)!=0) {
 175                         return REQUIRE_VENDOR_SWITCH;
 176                     }
 177                 }
 178                 return REQUIRE_SPECIFICATION_UPGRADE;


 187                     } else {
 188                         // Vendor matches, let's see the implementation version
 189                         if (implementationVersion != null && ei.implementationVersion != null) {
 190                             // they care about the implementation version
 191                             version = compareExtensionVersion(implementationVersion, ei.implementationVersion);
 192                             if (version<0) {
 193                                 // This extension is an older implementation
 194                                 return REQUIRE_IMPLEMENTATION_UPGRADE;
 195                             }
 196                         }
 197                     }
 198                 }
 199                 // All othe cases, we consider the extensions to be compatible
 200                 return COMPATIBLE;
 201             }
 202         }
 203         return INCOMPATIBLE;
 204     }
 205 
 206     /**
 207      * <p>
 208      * helper method to print sensible information on the undelying described
 209      * extension
 210      * </p>
 211      */
 212     public String toString() {
 213         return "Extension : title(" + title + "), name(" + name + "), spec vendor(" +
 214             specVendor + "), spec version(" + specVersion + "), impl vendor(" +
 215             vendor + "), impl vendor id(" + vendorId + "), impl version(" +
 216             implementationVersion + "), impl url(" + url + ")";
 217     }
 218 
 219     /*
 220      * <p>
 221      * helper method to compare two versions.
 222      * version are in the x.y.z.t pattern.
 223      * </p>
 224      * @param source version to compare to
 225      * @param target version used to compare against
 226      * @return < 0 if source < version

 227      *         > 0 if source > version
 228      *         = 0 if source = version
 229      */
 230     private int compareExtensionVersion(String source, String target)
 231         throws NumberFormatException
 232     {
 233         source = source.toLowerCase();
 234         target = target.toLowerCase();
 235 
 236         return strictCompareExtensionVersion(source, target);
 237     }
 238 
 239 
 240     /*
 241      * <p>
 242      * helper method to compare two versions.
 243      * version are in the x.y.z.t pattern.
 244      * </p>
 245      * @param source version to compare to
 246      * @param target version used to compare against
 247      * @return < 0 if source < version

 248      *         > 0 if source > version
 249      *         = 0 if source = version
 250      */
 251     private int strictCompareExtensionVersion(String source, String target)
 252         throws NumberFormatException
 253     {
 254         if (source.equals(target))
 255             return 0;
 256 
 257         StringTokenizer stk = new StringTokenizer(source, ".,");
 258         StringTokenizer ttk = new StringTokenizer(target, ".,");
 259 
 260         // Compare number
 261         int n = 0, m = 0, result = 0;
 262 
 263         // Convert token into meaning number for comparision
 264         if (stk.hasMoreTokens())
 265             n = convertToken(stk.nextToken().toString());
 266 
 267         // Convert token into meaning number for comparision
 268         if (ttk.hasMoreTokens())
 269             m = convertToken(ttk.nextToken().toString());




  28 import java.util.StringTokenizer;
  29 import java.util.jar.Attributes;
  30 import java.util.jar.Attributes.Name;
  31 import java.util.ResourceBundle;
  32 import java.util.MissingResourceException;
  33 import java.text.MessageFormat;
  34 import java.lang.Character.*;
  35 
  36 
  37 /**
  38  * This class holds all necessary information to install or
  39  * upgrade a extension on the user's disk
  40  *
  41  * @deprecated this class will be removed in a future release.
  42  * @author  Jerome Dochez
  43  */
  44 @Deprecated
  45 public class ExtensionInfo {
  46 
  47     /**

  48      * public static values returned by the isCompatible method

  49      */
  50     public static final int COMPATIBLE = 0;
  51     public static final int REQUIRE_SPECIFICATION_UPGRADE = 1;
  52     public static final int REQUIRE_IMPLEMENTATION_UPGRADE = 2;
  53     public static final int REQUIRE_VENDOR_SWITCH = 3;
  54     public static final int INCOMPATIBLE = 4;
  55 
  56     /**

  57      * attributes fully describer an extension. The underlying described
  58      * extension may be installed and requested.

  59      */
  60     public String title;
  61     public String name;
  62     public String specVersion;
  63     public String specVendor;
  64     public String implementationVersion;
  65     public String vendor;
  66     public String vendorId;
  67     public String url;
  68 
  69     // For I18N support
  70     private static final ResourceBundle rb =
  71         ResourceBundle.getBundle("sun.misc.resources.Messages");
  72 
  73 
  74     /**

  75      * Create a new uninitialized extension information object

  76      */
  77     public ExtensionInfo() {
  78     }
  79 
  80     /**

  81      * Create and initialize an extension information object.
  82      * The initialization uses the attributes passed as being
  83      * the content of a manifest file to load the extension
  84      * information from.
  85      * Since manifest file may contain information on several
  86      * extension they may depend on, the extension key parameter
  87      * is prepanded to the attribute name to make the key used
  88      * to retrieve the attribute from the manifest file
  89      *
  90      * @param extensionKey unique extension key in the manifest
  91      * @param attr Attributes of a manifest file
  92      */
  93     public ExtensionInfo(String extensionKey, Attributes attr)
  94         throws NullPointerException
  95     {
  96         String s;
  97         if (extensionKey!=null) {
  98             s = extensionKey + "-";
  99         } else {
 100             s ="";
 101         }
 102 
 103         String attrKey = s + Name.EXTENSION_NAME.toString();
 104         name = attr.getValue(attrKey);
 105         if (name != null)
 106             name = name.trim();
 107 
 108         attrKey = s + Name.SPECIFICATION_TITLE.toString();
 109         title = attr.getValue(attrKey);


 125         if (implementationVersion != null)
 126             implementationVersion = implementationVersion.trim();
 127 
 128         attrKey = s + Name.IMPLEMENTATION_VENDOR.toString();
 129         vendor = attr.getValue(attrKey);
 130         if (vendor != null)
 131             vendor = vendor.trim();
 132 
 133         attrKey = s + Name.IMPLEMENTATION_VENDOR_ID.toString();
 134         vendorId = attr.getValue(attrKey);
 135         if (vendorId != null)
 136             vendorId = vendorId.trim();
 137 
 138         attrKey =s + Name.IMPLEMENTATION_URL.toString();
 139         url = attr.getValue(attrKey);
 140         if (url != null)
 141             url = url.trim();
 142     }
 143 
 144     /**

 145      * @return true if the extension described by this extension information
 146      * is compatible with the extension described by the extension
 147      * information passed as a parameter

 148      *
 149      * @param ei the requested extension information to compare to
 150      */
 151     public int isCompatibleWith(ExtensionInfo ei) {
 152 
 153         if (name == null || ei.name == null)
 154             return INCOMPATIBLE;
 155         if (name.compareTo(ei.name)==0) {
 156             // is this true, if not spec version is specified, we consider
 157             // the value as being "any".
 158             if (specVersion == null || ei.specVersion == null)
 159                 return COMPATIBLE;
 160 
 161             int version = compareExtensionVersion(specVersion, ei.specVersion);
 162             if (version<0) {
 163                 // this extension specification is "older"
 164                 if (vendorId != null && ei.vendorId !=null) {
 165                     if (vendorId.compareTo(ei.vendorId)!=0) {
 166                         return REQUIRE_VENDOR_SWITCH;
 167                     }
 168                 }
 169                 return REQUIRE_SPECIFICATION_UPGRADE;


 178                     } else {
 179                         // Vendor matches, let's see the implementation version
 180                         if (implementationVersion != null && ei.implementationVersion != null) {
 181                             // they care about the implementation version
 182                             version = compareExtensionVersion(implementationVersion, ei.implementationVersion);
 183                             if (version<0) {
 184                                 // This extension is an older implementation
 185                                 return REQUIRE_IMPLEMENTATION_UPGRADE;
 186                             }
 187                         }
 188                     }
 189                 }
 190                 // All othe cases, we consider the extensions to be compatible
 191                 return COMPATIBLE;
 192             }
 193         }
 194         return INCOMPATIBLE;
 195     }
 196 
 197     /**

 198      * helper method to print sensible information on the undelying described
 199      * extension

 200      */
 201     public String toString() {
 202         return "Extension : title(" + title + "), name(" + name + "), spec vendor(" +
 203             specVendor + "), spec version(" + specVersion + "), impl vendor(" +
 204             vendor + "), impl vendor id(" + vendorId + "), impl version(" +
 205             implementationVersion + "), impl url(" + url + ")";
 206     }
 207 
 208     /*

 209      * helper method to compare two versions.
 210      * version are in the x.y.z.t pattern.
 211      *
 212      * @param source version to compare to
 213      * @param target version used to compare against
 214      * @return <pre>{@code
 215      *   < 0 if source < version
 216      *   > 0 if source > version
 217      *   = 0 if source = version}</pre>
 218      */
 219     private int compareExtensionVersion(String source, String target)
 220         throws NumberFormatException
 221     {
 222         source = source.toLowerCase();
 223         target = target.toLowerCase();
 224 
 225         return strictCompareExtensionVersion(source, target);
 226     }
 227 
 228 
 229     /*

 230      * helper method to compare two versions.
 231      * version are in the x.y.z.t pattern.
 232      *
 233      * @param source version to compare to
 234      * @param target version used to compare against
 235      * @return <pre>{@code
 236      *   < 0 if source < version
 237      *   > 0 if source > version
 238      *   = 0 if source = version}</pre>
 239      */
 240     private int strictCompareExtensionVersion(String source, String target)
 241         throws NumberFormatException
 242     {
 243         if (source.equals(target))
 244             return 0;
 245 
 246         StringTokenizer stk = new StringTokenizer(source, ".,");
 247         StringTokenizer ttk = new StringTokenizer(target, ".,");
 248 
 249         // Compare number
 250         int n = 0, m = 0, result = 0;
 251 
 252         // Convert token into meaning number for comparision
 253         if (stk.hasMoreTokens())
 254             n = convertToken(stk.nextToken().toString());
 255 
 256         // Convert token into meaning number for comparision
 257         if (ttk.hasMoreTokens())
 258             m = convertToken(ttk.nextToken().toString());


< prev index next >