01: /*
02: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: */
06:
07: package com.hp.hpl.jena.util;
08:
09: import java.io.InputStream;
10: import org.apache.commons.logging.Log;
11: import org.apache.commons.logging.LogFactory;
12:
13: public class LocatorClassLoader implements Locator {
14: static Log log = LogFactory.getLog(LocatorClassLoader.class);
15:
16: ClassLoader classLoader = null;
17:
18: public LocatorClassLoader(ClassLoader _classLoader) {
19: classLoader = _classLoader;
20: }
21:
22: public boolean equals(Object other) {
23: return other instanceof LocatorClassLoader
24: && classLoader == ((LocatorClassLoader) other).classLoader;
25: }
26:
27: public int hashCode() {
28: return classLoader.hashCode();
29: }
30:
31: public TypedStream open(String filenameOrURI) {
32: if (classLoader == null)
33: return null;
34:
35: String fn = FileUtils.toFilename(filenameOrURI);
36: if (fn == null) {
37: if (FileManager.logAllLookups && log.isTraceEnabled())
38: log.trace("Not found: " + filenameOrURI);
39: return null;
40: }
41: InputStream in = classLoader.getResourceAsStream(fn);
42: if (in == null) {
43: if (FileManager.logAllLookups && log.isTraceEnabled())
44: log.trace("Failed to open: " + filenameOrURI);
45: return null;
46: }
47:
48: if (FileManager.logAllLookups && log.isTraceEnabled())
49: log.trace("Found: " + filenameOrURI);
50:
51: // base = classLoader.getResource(fn).toExternalForm ;
52: return new TypedStream(in);
53: }
54:
55: public String getName() {
56: return "ClassLoaderLocator";
57: }
58: }
59: /*
60: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
61: * All rights reserved.
62: *
63: * Redistribution and use in source and binary forms, with or without
64: * modification, are permitted provided that the following conditions
65: * are met:
66: * 1. Redistributions of source code must retain the above copyright
67: * notice, this list of conditions and the following disclaimer.
68: * 2. Redistributions in binary form must reproduce the above copyright
69: * notice, this list of conditions and the following disclaimer in the
70: * documentation and/or other materials provided with the distribution.
71: * 3. The name of the author may not be used to endorse or promote products
72: * derived from this software without specific prior written permission.
73: *
74: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
75: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
78: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
79: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
83: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84: */
|