01: package org.objectweb.celtix.resource;
02:
03: import java.io.InputStream;
04: import java.net.URL;
05:
06: public class ClassLoaderResolver implements ResourceResolver {
07:
08: private final ClassLoader loader;
09:
10: public ClassLoaderResolver() {
11: this (ClassLoaderResolver.class.getClassLoader());
12: }
13:
14: public ClassLoaderResolver(ClassLoader l) {
15: loader = l;
16: }
17:
18: public <T> T resolve(String resourceName, Class<T> resourceType) {
19: if (resourceType == null) {
20: return null;
21: }
22: URL url = loader.getResource(resourceName);
23: if (resourceType.isInstance(url)) {
24: return resourceType.cast(url);
25: }
26: return null;
27: }
28:
29: public InputStream getAsStream(String name) {
30: return loader.getResourceAsStream(name);
31: }
32:
33: }
|