001: /*
002: * Javux - Java Component Set
003: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004: * e-mail: ksadlocha@programics.com
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: package com.javujavu.javux.app.compat;
022:
023: public class PlugLoader {
024: private static PlugLoader the;
025:
026: private static PlugLoader the() {
027: if (the == null) {
028: try {
029: if (System.getProperty("java.version", "0").compareTo(
030: "1.2") >= 0) {
031: the = (PlugLoader) Class
032: .forName(
033: "com.javujavu.javux.app.compat.PlugLoader12")
034: .newInstance();
035: }
036: } catch (Exception e) {
037: }
038:
039: if (the == null)
040: the = new PlugLoader();
041: }
042: return the;
043: }
044:
045: public static ClassLoader createLoader(ClassLoader parent) {
046: return the().createLoaderImpl(parent);
047: }
048:
049: public static ClassLoader getJarLoader(ClassLoader cl, String file) {
050: return the().getJarLoaderImpl(cl, file);
051: }
052:
053: public static ClassLoader loadJar(ClassLoader cl, String file) {
054: return the().loadJarImpl(cl, file);
055: }
056:
057: public static void unloadJar(ClassLoader cl, String file) {
058: the().unloadJarImpl(cl, file);
059: }
060:
061: public static void unloadAllJars(ClassLoader cl) {
062: the().unloadAllJarsImpl(cl);
063: }
064:
065: public static ClassLoader[] listPluginLoaders(ClassLoader cl,
066: String key) {
067: return the().listPluginLoadersImpl(cl, key);
068: }
069:
070: public static ClassLoader[] listResourceLoaders(ClassLoader cl,
071: String name) {
072: return the().listResourceLoadersImpl(cl, name);
073: }
074:
075: ///////////////////////////////////////////////////
076:
077: public static String getFileName(ClassLoader cl) {
078: return the().getFileNameImpl(cl);
079: }
080:
081: public static ClassLoader getPlugLoader(ClassLoader cl) {
082: return the().getPlugLoaderImpl(cl);
083: }
084:
085: public static Class getPluginClass(ClassLoader cl, String key) {
086: return the().getPluginClassImpl(cl, key);
087: }
088:
089: public static Object createPlugin(ClassLoader cl, String key,
090: Class requiredClass) {
091: return the().createPluginImpl(cl, key, requiredClass);
092: }
093:
094: ///////////////////////////////////////////////////
095: // implementation
096:
097: protected ClassLoader createLoaderImpl(ClassLoader parent) {
098: return new JavuPlugClassLoader1();
099: }
100:
101: protected ClassLoader getJarLoaderImpl(ClassLoader cl, String file) {
102: return ((JavuPlugClassLoader1) cl).getJarLoader(file);
103: }
104:
105: protected ClassLoader loadJarImpl(ClassLoader cl, String file) {
106: return ((JavuPlugClassLoader1) cl).loadJar(file);
107: }
108:
109: protected void unloadJarImpl(ClassLoader cl, String file) {
110: ((JavuPlugClassLoader1) cl).unloadJar(file);
111: }
112:
113: protected void unloadAllJarsImpl(ClassLoader cl) {
114: ((JavuPlugClassLoader1) cl).unloadAllJars();
115: }
116:
117: protected ClassLoader[] listPluginLoadersImpl(ClassLoader cl,
118: String key) {
119: return ((JavuPlugClassLoader1) cl).listPluginLoaders(key);
120: }
121:
122: protected ClassLoader[] listResourceLoadersImpl(ClassLoader cl,
123: String name) {
124: return ((JavuPlugClassLoader1) cl).listResourceLoaders(name);
125: }
126:
127: ///////////////////////////////////////////////////
128:
129: protected String getFileNameImpl(ClassLoader cl) {
130: return ((JavuPlugJarClassLoader1) cl).getFileName();
131: }
132:
133: protected ClassLoader getPlugLoaderImpl(ClassLoader cl) {
134: return ((JavuPlugJarClassLoader1) cl).getPlugLoader();
135: }
136:
137: protected Class getPluginClassImpl(ClassLoader cl, String key) {
138: return ((JavuPlugJarClassLoader1) cl).getPluginClass(key);
139: }
140:
141: protected Object createPluginImpl(ClassLoader cl, String key,
142: Class requiredClass) {
143: return ((JavuPlugJarClassLoader1) cl).createPlugin(key,
144: requiredClass);
145: }
146: }
|