1 23 24 29 30 package com.sun.enterprise.tools.verifier.apiscan.packaging; 31 32 import java.io.IOException ; 33 import java.util.jar.Attributes ; 34 import java.util.jar.Manifest ; 35 import java.util.logging.Level ; 36 import java.util.logging.Logger ; 37 38 47 public class ExtensionRef { 48 private static String resourceBundleName = "com.sun.enterprise.tools.verifier.apiscan.LocalStrings"; 49 public static Logger logger = Logger.getLogger("apiscan.packaging", resourceBundleName); private static final String myClassName = "ExtensionRef"; private String name, implVendorId = ""; 53 private String implVer; private DeweyDecimal specVer; 55 56 61 public ExtensionRef(Manifest manifest, String extName) { 62 Attributes attrs = manifest.getMainAttributes(); 63 name = attrs.getValue(extName + "-" + Attributes.Name.EXTENSION_NAME); String s = attrs.getValue( 65 extName + "-" + Attributes.Name.SPECIFICATION_VERSION); if (s != null) { 67 try { 68 specVer = new DeweyDecimal(s); 69 } catch (NumberFormatException e) { 70 logger.log(Level.SEVERE, getClass().getName() + ".exception1", new Object []{e.getMessage()}); 71 logger.log(Level.SEVERE, "", e); 72 throw e; 73 } 74 } 75 implVendorId = 76 attrs.getValue( 77 extName + "-" + Attributes.Name.IMPLEMENTATION_VENDOR_ID); implVer = 79 attrs.getValue( 80 extName + "-" + Attributes.Name.IMPLEMENTATION_VERSION); validate(); 82 } 83 84 private void validate() { 85 if (name == null || name.length() <= 0) { 86 throw new IllegalArgumentException ("Extension-Name can not be empty."); 87 } 88 } 89 90 95 public boolean isSatisfiedBy(Archive another) throws IOException { 96 logger.entering(myClassName, "isSatisfiedBy", another); Attributes attrs = another.getManifest().getMainAttributes(); 98 String name = attrs.getValue(Attributes.Name.EXTENSION_NAME); 99 String s = attrs.getValue(Attributes.Name.SPECIFICATION_VERSION); 100 DeweyDecimal specVer = null; 101 try { 102 specVer = s != null ? new DeweyDecimal(s) : null; 103 } catch (NumberFormatException e) { 104 logger.log(Level.WARNING, getClass().getName() + ".warning1", new Object []{e.getMessage(), another.toString()}); 105 return false; 106 } 107 String implVendorId = attrs.getValue( 108 Attributes.Name.IMPLEMENTATION_VENDOR_ID); 109 String implVer = attrs.getValue(Attributes.Name.IMPLEMENTATION_VERSION); 110 return this.name.equals(name) && 118 (this.specVer == null || this.specVer.isCompatible(specVer)) && 119 (this.implVendorId == null || 120 this.implVendorId.equals(implVendorId)) && 121 (this.implVer == null || this.implVer.equals(implVer)); 122 } 123 124 127 public String toString() { 128 return "Extension-Name: " + name + "\n" + (specVer != null ? "Specification-Version: " + specVer + "\n" : "") + (implVendorId != null ? 131 "Implementation-Vendor-Id: " + implVendorId + "\n" : "") + (implVer != null ? "Implementation-Version: " + implVer + "\n" : ""); } 134 } 135 | Popular Tags |