1 23 24 25 package com.sun.enterprise.tools.verifier.apiscan.classfile; 26 27 import java.io.IOException ; 28 import java.util.HashSet ; 29 import java.util.Iterator ; 30 import java.util.Collection ; 31 import java.util.logging.Level ; 32 import java.util.logging.Logger ; 33 34 42 public abstract class ClosureCompilerImplBase implements ClosureCompiler { 43 44 protected ClassFileLoader loader; 45 46 protected HashSet <String > excludedClasses = new HashSet <String >(); 47 48 protected HashSet <String > excludedPackages = new HashSet <String >(); 49 50 protected HashSet <String > excludedPatterns = new HashSet <String >(); 51 52 protected HashSet <String > visitedClasses = new HashSet <String >(); 53 54 private static String resourceBundleName = "com.sun.enterprise.tools.verifier.apiscan.LocalStrings"; 55 protected static Logger logger = Logger.getLogger("apiscan.classfile", resourceBundleName); 57 private static final String myClassName = "ClosureCompilerImplBase"; 60 64 protected ClosureCompilerImplBase(ClassFileLoader loader) { 65 this.loader = loader; 66 } 67 68 78 public void addExcludedClass(String className) { 79 excludedClasses.add(className); 80 } 81 82 92 public void addExcludedPackage(String pkgName) { 93 excludedPackages.add(pkgName); 94 } 95 96 107 public void addExcludedPattern(String pattern) { 108 excludedPatterns.add(pattern); 109 } 110 111 116 public boolean buildClosure(java.util.jar.JarFile jar) throws IOException { 117 boolean result = true; 118 for (java.util.Enumeration entries = jar.entries(); 119 entries.hasMoreElements();) { 120 String clsName = ((java.util.jar.JarEntry ) entries.nextElement()).getName(); 121 if (clsName.endsWith(".class")) { String externalClsName = clsName.substring(0, 123 clsName.lastIndexOf(".class")) .replace('/', '.'); 125 boolean newresult = this.buildClosure(externalClsName); 126 result = newresult && result; 127 } 128 } return result; 130 } 131 132 public Collection <String > getNativeMethods() { 133 throw new UnsupportedOperationException (); 134 } 135 136 140 protected boolean needToBuildClosure(String className) { 141 boolean result = true; 142 if (visitedClasses.contains(className)) 143 result = false; 144 else if (excludedClasses.contains(className)) { 145 result = false; 146 } else if (excludedPackages.contains(getPackageName(className))) { 147 result = false; 148 } else { 149 for (Iterator i = excludedPatterns.iterator(); i.hasNext();) { 150 String pattern = (String ) i.next(); 151 if (className.startsWith(pattern)) { 152 result = false; 153 break; 154 } 155 } 156 } 157 logger.logp(Level.FINEST, myClassName, "needToBuildClosure", className + " " + result); return result; 160 } 161 162 166 protected static String getPackageName(String className) { 167 int idx = className.lastIndexOf('.'); 168 if (idx != -1) { 169 return className.substring(0, idx); 170 } else 171 return ""; 172 } 173 174 } 175 | Popular Tags |