KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > util > LocatorClassLoader


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  */

6
7 package com.hp.hpl.jena.util;
8
9 import java.io.InputStream JavaDoc;
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 JavaDoc classLoader = null ;
20     LocatorClassLoader(ClassLoader JavaDoc _classLoader)
21     {
22         classLoader =_classLoader ;
23     }
24     
25     public InputStream JavaDoc open(String JavaDoc filenameOrURI)
26     {
27         if ( classLoader == null )
28             return null ;
29             
30         String JavaDoc 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 JavaDoc 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         // base = classLoader.getResource(fn).toExternalForm ;
49
return in ;
50     }
51     public String JavaDoc getName() { return "ClassLoaderLocator" ; }
52 }
53 /*
54  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
55  * All rights reserved.
56  *
57  * Redistribution and use in source and binary forms, with or without
58  * modification, are permitted provided that the following conditions
59  * are met:
60  * 1. Redistributions of source code must retain the above copyright
61  * notice, this list of conditions and the following disclaimer.
62  * 2. Redistributions in binary form must reproduce the above copyright
63  * notice, this list of conditions and the following disclaimer in the
64  * documentation and/or other materials provided with the distribution.
65  * 3. The name of the author may not be used to endorse or promote products
66  * derived from this software without specific prior written permission.
67  *
68  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
69  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
70  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
71  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
72  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
73  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
74  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
75  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
77  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78  */
Popular Tags