1 17 package org.apache.geronimo.kernel.classloader; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.IOException ; 22 import java.net.MalformedURLException ; 23 import java.util.jar.Manifest ; 24 25 28 public class DirectoryResourceLocation extends AbstractUrlResourceLocation { 29 private final File baseDir; 30 private boolean manifestLoaded = false; 31 private Manifest manifest; 32 33 public DirectoryResourceLocation(File baseDir) throws MalformedURLException { 34 super(baseDir.toURL()); 35 this.baseDir = baseDir; 36 } 37 38 public ResourceHandle getResourceHandle(String resourceName) { 39 File file = new File (baseDir, resourceName); 40 if (!file.exists()) { 41 return null; 42 } 43 44 try { 45 ResourceHandle resourceHandle = new DirectoryResourceHandle(resourceName, file, baseDir, getManifestSafe()); 46 return resourceHandle; 47 } catch (MalformedURLException e) { 48 return null; 49 } 50 } 51 52 public Manifest getManifest() throws IOException { 53 if (!manifestLoaded) { 54 File manifestFile = new File (baseDir, "META-INF/MANIFEST.MF"); 55 56 if (manifestFile.isFile() && manifestFile.canRead()) { 57 FileInputStream in = null; 58 try { 59 in = new FileInputStream (manifestFile); 60 manifest = new Manifest (in); 61 } finally { 62 IoUtil.close(in); 63 } 64 } 65 manifestLoaded = true; 66 } 67 return manifest; 68 } 69 70 private Manifest getManifestSafe() { 71 Manifest manifest = null; 72 try { 73 manifest = getManifest(); 74 } catch (IOException e) { 75 } 77 return manifest; 78 } 79 } 80 | Popular Tags |