KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > repository > ClassLoaderResourceLoader


1 /**
2  * Copyright (C) 2002 Kelua SA
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package org.objectweb.kilim.repository;
20
21 import java.io.InputStream JavaDoc;
22
23 import org.objectweb.kilim.KilimLoggerFactory;
24 import org.objectweb.util.monolog.api.BasicLevel;
25 import org.objectweb.util.monolog.api.Logger;
26
27 /**
28  * Implementation of {@link ResourceLoader} using a ClassLoader
29  * @author dutoo
30  */

31 public class ClassLoaderResourceLoader implements ResourceLoader {
32    
33    private static boolean DEBUG_ON = false;
34    private static Logger logger = KilimLoggerFactory.getSingleton().getLogger("org.objectweb.kilim.repository");
35    
36    /**
37     * Creates a new ClassLoaderResourceLoader using the provided class loader.
38     * @param resourceLoader the class loader to be used
39     */

40    public ClassLoaderResourceLoader(ClassLoader JavaDoc resourceLoader) {
41       this.resourceLoader = resourceLoader;
42    }
43    
44    /**
45     * @see org.objectweb.kilim.repository.ResourceLoader#getResource(String)
46     */

47    public InputStream JavaDoc getResource(String JavaDoc resourceName) throws ResourceNotFoundException {
48       if (DEBUG_ON && logger.isLoggable(BasicLevel.DEBUG)) {
49         logger.log(BasicLevel.DEBUG, "Getting resource \"" + resourceName + "\".");
50       }
51       InputStream JavaDoc res = resourceLoader.getResourceAsStream(resourceName);
52       
53       if (res == null) {
54          throw new ResourceNotFoundException(resourceName);
55       }
56       
57       return res;
58    }
59
60    private ClassLoader JavaDoc resourceLoader;
61
62 }
63
Popular Tags