// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2009 BiGCaT Bioinformatics
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
//
package org.pathvisio.plugin;

import java.net.URL;
import java.net.URLClassLoader;

import org.pathvisio.debug.Logger;

/**
 * A class loader for loading classes from a plugin jar files.
 * 
 * inspired by CDK PluginClassLoader 
 */
public class PluginClassLoader extends URLClassLoader 
{    
    public PluginClassLoader(URL url) 
    {
        super (new URL[] { url });
    }
    
    /**
     * This class loading method overwrites the default behaviour and tries
     * to look in the plugin jar first. This allows that users put
     * plugins in their local plugin dir that come with the program by default
     * too. The newest plugin is then loaded.
     *
     * @param name the name of the main class
     * @exception ClassNotFoundException if the specified class could not
     *            be found
     */
    @Override public Class<?> loadClass(String name) throws ClassNotFoundException 
    {
        Logger.log.debug("Loading from plugin jar: " + name);
        Class<?> aClass = null;
        try 
        {
            aClass = super.findClass(name);
            Logger.log.debug("  found: " + aClass);
            return aClass;
        } 
        catch (ClassNotFoundException ex) 
        {
            Logger.log.debug("  not found in plugin jar");
        }
        
        try 
        {
            aClass = super.loadClass(name);
            Logger.log.debug("  found: " + aClass);
        } 
        catch (ClassNotFoundException ex) 
        {
            Logger.log.error("  not found in elsewhere", ex);
            throw ex;
        }
        return aClass;
    }

}

@@ -1516,16 +1516,18 @@
      */%0A
+//
     @Ove
@@ -1602,22 +1602,26 @@
 eption %0A
+//
     %7B%0A
+//
         
@@ -1670,24 +1670,26 @@
  %22 + name);%0A
+//
         Clas
@@ -1708,16 +1708,18 @@
 = null;%0A
+//
         
@@ -1715,32 +1715,34 @@
 %0A//        try %0A
+//
         %7B%0A      
@@ -1727,32 +1727,34 @@
 ry %0A//        %7B%0A
+//
             aCla
@@ -1773,32 +1773,34 @@
 indClass(name);%0A
+//
             Logg
@@ -1827,32 +1827,34 @@
 d: %22 + aClass);%0A
+//
             retu
@@ -1860,24 +1860,26 @@
 urn aClass;%0A
+//
         %7D %0A 
@@ -1869,32 +1869,34 @@
 s;%0A//        %7D %0A
+//
         catch (C
@@ -1914,32 +1914,34 @@
 dException ex) %0A
+//
         %7B%0A      
@@ -1926,32 +1926,34 @@
 x) %0A//        %7B%0A
+//
             Logg
@@ -1995,16 +1995,18 @@
  jar%22);%0A
+//
         
@@ -1999,32 +1999,34 @@
 %22);%0A//        %7D%0A
+//
         %0A       
@@ -2014,24 +2014,26 @@
 %0A//        %0A
+//
         try 
@@ -2033,16 +2033,18 @@
    try %0A
+//
         
@@ -2037,32 +2037,34 @@
 ry %0A//        %7B%0A
+//
             aCla
@@ -2091,16 +2091,18 @@
 (name);%0A
+//
         
@@ -2145,16 +2145,18 @@
 Class);%0A
+//
         
@@ -2158,16 +2158,18 @@
      %7D %0A
+//
         
@@ -2203,16 +2203,18 @@
 on ex) %0A
+//
         
@@ -2211,24 +2211,26 @@
 //        %7B%0A
+//
             
@@ -2279,16 +2279,18 @@
 %22, ex);%0A
+//
         
@@ -2303,16 +2303,18 @@
 row ex;%0A
+//
         
@@ -2311,24 +2311,26 @@
 //        %7D%0A
+//
         retu
@@ -2340,16 +2340,18 @@
 aClass;%0A
+//
     %7D%0A%0A%7D

Stop plugin class loader from preferring jar above classPath