001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy 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 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 020package icy.plugin.classloader; 021 022import java.io.IOException; 023import java.io.InputStream; 024import java.net.URL; 025import java.util.Enumeration; 026 027/** 028 * @author Kamran Zafar 029 */ 030public abstract class ProxyClassLoader implements Comparable<ProxyClassLoader> 031{ 032 protected int order; 033 protected boolean enabled; 034 035 public ProxyClassLoader(int order) 036 { 037 super(); 038 039 // Default order 040 this.order = order; 041 // Enabled by default 042 enabled = true; 043 } 044 045 public int getOrder() 046 { 047 return order; 048 } 049 050 /** 051 * Returns the internal {@link ClassLoader} object used to load class. 052 */ 053 public abstract ClassLoader getLoader(); 054 055 /** 056 * Loads the class and returns it. 057 * 058 * @throws ClassNotFoundException 059 */ 060 public abstract Class loadClass(String className, boolean resolveIt) throws ClassNotFoundException; 061 062 /** 063 * Loads the resource and returns an input stream for reading it. 064 */ 065 public abstract InputStream getResourceAsStream(String name); 066 067 /** 068 * Find the resource and returns it as a URL (if it exists). 069 */ 070 public abstract URL getResource(String name); 071 072 /** 073 * Finds all resources with the given name and returns them as a URL Enumeration. 074 */ 075 public abstract Enumeration<URL> getResources(String name) throws IOException; 076 077 public boolean isEnabled() 078 { 079 return enabled; 080 } 081 082 public void setEnabled(boolean enabled) 083 { 084 this.enabled = enabled; 085 } 086 087 @Override 088 public int compareTo(ProxyClassLoader o) 089 { 090 return order - o.getOrder(); 091 } 092}