1 6 7 package com.hp.hpl.jena.util; 8 9 import java.io.InputStream ; 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 14 15 public class LocatorClassLoader implements Locator 16 { 17 static Log log = LogFactory.getLog(LocatorClassLoader.class) ; 18 19 ClassLoader classLoader = null ; 20 LocatorClassLoader(ClassLoader _classLoader) 21 { 22 classLoader =_classLoader ; 23 } 24 25 public InputStream open(String filenameOrURI) 26 { 27 if ( classLoader == null ) 28 return null ; 29 30 String fn = FileUtils.toFilename(filenameOrURI) ; 31 if ( fn == null ) 32 { 33 if ( FileManager.logAllLookups && log.isTraceEnabled() ) 34 log.trace("Not found: "+filenameOrURI) ; 35 return null ; 36 } 37 InputStream in = classLoader.getResourceAsStream(fn) ; 38 if ( in == null ) 39 { 40 if ( FileManager.logAllLookups && log.isTraceEnabled() ) 41 log.trace("Failed to open: "+filenameOrURI) ; 42 return in ; 43 } 44 45 if ( FileManager.logAllLookups && log.isTraceEnabled() ) 46 log.trace("Found: "+filenameOrURI) ; 47 48 return in ; 50 } 51 public String getName() { return "ClassLoaderLocator" ; } 52 } 53 | Popular Tags |