01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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 com.jeta.swingbuilder.app;
20:
21: import java.io.InputStream;
22: import java.net.URL;
23:
24: import com.jeta.open.registry.JETARegistry;
25: import com.jeta.swingbuilder.interfaces.resources.ResourceLoader;
26:
27: public class AppClassLoader extends ClassLoader {
28: String m_altPath;
29:
30: public AppClassLoader() {
31:
32: }
33:
34: public AppClassLoader(String path) {
35: m_altPath = path;
36: }
37:
38: public URL getResource(String name) {
39: if (m_altPath == null) {
40: return super .getResource(name);
41: } else {
42: String urlstring = "file://localhost/" + m_altPath + "/"
43: + name;
44: try {
45: return new URL(urlstring);
46: } catch (Exception e) {
47: return super .getResource(name);
48: }
49: }
50: }
51:
52: public InputStream getResourceAsStream(String name) {
53: try {
54: if (m_altPath == null) {
55: ResourceLoader loader = (ResourceLoader) JETARegistry
56: .lookup(ResourceLoader.COMPONENT_ID);
57: return loader.getInputStream(name);
58: } else {
59: URL url = getResource(name);
60: return url.openStream();
61: }
62:
63: } catch (Exception e) {
64: return super.getResourceAsStream(name);
65: }
66: }
67: }
|