自定义EclipsePlugin ClassLoader (2)
来源:互联网 发布:中文域名whois查询 编辑:程序博客网 时间:2024/05/23 15:28
前一遍文章讲的是自定义一个在那里都能用的ClassLoader ,而在Eclipse内部其实每一个Plugin都有自己的ClassLoader,所以说我们没有必要再重新定义自己的ClassLoader .现实的代码如下:
public class AllPluginsClassLoader {
private static Loader instance;
public static synchronized ClassLoader getInstance() {
if (instance == null) {
instance = new Loader();
}
return instance;
}
public static ClassLoader getInstance(URL[] classPath, ClassLoader parent) {
return new Loader(classPath, parent);
}
private static class Loader extends URLClassLoader {
private static ClassLoader[] pluginClassLoaders;
public Loader() {
this(new URL[0], null);
}
public Loader(URL[] path, ClassLoader parent) {
super(path, parent);
IPluginDescriptor[] plugins = Platform.getPluginRegistry().getPluginDescriptors();
pluginClassLoaders = new ClassLoader[plugins.length];
for (int i = 0; i < plugins.length; i++) {
pluginClassLoaders[i] = plugins[i].getPluginClassLoader();
}
}
protected Class findClass(String name) throws ClassNotFoundException {
try {
return super.findClass(name);
} catch (ClassNotFoundException ex) {
for (int i = 0; i < pluginClassLoaders.length; i++) {
try {
Class clazz = pluginClassLoaders[i].loadClass(name);
return clazz;
} catch (ClassNotFoundException ex2) {
}
}
throw new ClassNotFoundException(name);
}
}
}
}
private static Loader instance;
public static synchronized ClassLoader getInstance() {
if (instance == null) {
instance = new Loader();
}
return instance;
}
public static ClassLoader getInstance(URL[] classPath, ClassLoader parent) {
return new Loader(classPath, parent);
}
private static class Loader extends URLClassLoader {
private static ClassLoader[] pluginClassLoaders;
public Loader() {
this(new URL[0], null);
}
public Loader(URL[] path, ClassLoader parent) {
super(path, parent);
IPluginDescriptor[] plugins = Platform.getPluginRegistry().getPluginDescriptors();
pluginClassLoaders = new ClassLoader[plugins.length];
for (int i = 0; i < plugins.length; i++) {
pluginClassLoaders[i] = plugins[i].getPluginClassLoader();
}
}
protected Class findClass(String name) throws ClassNotFoundException {
try {
return super.findClass(name);
} catch (ClassNotFoundException ex) {
for (int i = 0; i < pluginClassLoaders.length; i++) {
try {
Class clazz = pluginClassLoaders[i].loadClass(name);
return clazz;
} catch (ClassNotFoundException ex2) {
}
}
throw new ClassNotFoundException(name);
}
}
}
}
- 自定义EclipsePlugin ClassLoader (2)
- 自定义ClassLoader
- 自定义ClassLoader
- 自定义ClassLoader
- 自定义ClassLoader
- 自定义ClassLoader
- 自定义ClassLoader
- 自定义ClassLoader
- 自定义ClassLoader
- 自定义ClassLoader
- Java_ClassLoader(ClassLoader / 自定义ClassLoader / DexClassLoader)
- 自定义一个ClassLoader.
- 自定义classloader的实现
- 自定义ClassLoader 简单例子
- java 自定义ClassLoader
- 自定义ClassLoader类
- 自定义 Java ClassLoader
- 自定义ClassLoader解析
- 通过WebServices 访问 服务器文件 (delphi6上编译通过)
- .NET 中的对象序列化
- 第一篇文章
- asp .net推荐学习站点
- 软件开发中的审美疲劳-surstar
- 自定义EclipsePlugin ClassLoader (2)
- 常用SQL语句
- 程序员必读的安全技术资源
- 精武鸭脖”做法
- 软件测试的常识
- 鸭子的逃生选择
- 工作流挖掘:相关问题和方法的研究(10)
- Delphi下实现StatusBar捕捉双击哪个分栏
- 让flash直接运行.不论IE限制的问题(转csdn bbs)