1 19 20 package edu.umd.cs.findbugs.classfile.impl; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 25 import edu.umd.cs.findbugs.classfile.IAnalysisCache; 26 import edu.umd.cs.findbugs.classfile.IClassFactory; 27 import edu.umd.cs.findbugs.classfile.IClassPath; 28 import edu.umd.cs.findbugs.classfile.IClassPathBuilder; 29 import edu.umd.cs.findbugs.classfile.ICodeBase; 30 import edu.umd.cs.findbugs.classfile.ICodeBaseLocator; 31 import edu.umd.cs.findbugs.classfile.IErrorLogger; 32 import edu.umd.cs.findbugs.classfile.IScannableCodeBase; 33 import edu.umd.cs.findbugs.classfile.ResourceNotFoundException; 34 35 40 public class ClassFactory implements IClassFactory { 41 private static IClassFactory theInstance = new ClassFactory(); 42 43 private ClassFactory() { 44 } 45 46 public static IClassFactory instance() { 47 return theInstance; 48 } 49 50 53 public IClassPath createClassPath() { 54 return new ClassPathImpl(); 55 } 56 57 60 public IClassPathBuilder createClassPathBuilder(IErrorLogger errorLogger) { 61 return new ClassPathBuilder(this, errorLogger); 62 } 63 64 67 public ICodeBaseLocator createFilesystemCodeBaseLocator(String pathName) { 68 try { 71 pathName = new File (pathName).getCanonicalPath(); 72 } catch (IOException e) { 73 } 75 76 return new FilesystemCodeBaseLocator(pathName); 77 } 78 79 82 public ICodeBaseLocator createNestedArchiveCodeBaseLocator(ICodeBase parentCodeBase, String path) { 83 return new NestedZipFileCodeBaseLocator(parentCodeBase, path); 84 } 85 86 static IScannableCodeBase createFilesystemCodeBase(FilesystemCodeBaseLocator codeBaseLocator) throws IOException { 87 String fileName = codeBaseLocator.getPathName(); 88 89 File file = new File (fileName); 90 91 if (file.isDirectory()) { 92 return new DirectoryCodeBase(codeBaseLocator, file); 93 } else if (fileName.endsWith(".class")) { 94 return new SingleFileCodeBase(codeBaseLocator, fileName); 95 } else { 96 return new ZipFileCodeBase(codeBaseLocator, file); 97 } 98 } 99 100 static IScannableCodeBase createNestedZipFileCodeBase( 101 NestedZipFileCodeBaseLocator codeBaseLocator) 102 throws ResourceNotFoundException, IOException { 103 return new NestedZipFileCodeBase(codeBaseLocator); 104 } 105 106 109 public IAnalysisCache createAnalysisCache(IClassPath classPath, IErrorLogger errorLogger) { 110 IAnalysisCache analysisCache = new AnalysisCache(classPath, errorLogger); 111 return analysisCache; 112 } 113 } 114 | Popular Tags |