DynamicClassLoader.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.utils.resources;

  21. import java.net.URL;
  22. import java.net.URLClassLoader;

  23. /**
  24.  * DynamicClassLoader
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class DynamicClassLoader extends URLClassLoader {

  31.     public DynamicClassLoader(URL[] urls) {
  32.         super(urls);
  33.     }

  34.    
  35.     @Override
  36.     protected Class<?> findClass(String name) throws ClassNotFoundException {
  37.        
  38.         //System.out.println("FIND CLASS ["+name+"] ...");
  39.        
  40.         try{
  41.             return super.findClass(name);
  42.         }catch(ClassNotFoundException cnf){
  43.             //System.out.println("FIND CLASS ["+name+"] error: "+cnf.getMessage());
  44.         }
  45.        
  46.         Class<?> c = null;
  47.         try{
  48.             c = Class.forName(name);
  49.             //System.out.println("FIND CLASS ["+name+"] ok");
  50.         }catch(ClassNotFoundException cnf){
  51.             //System.out.println("FIND CLASS ["+name+"] error2: "+cnf.getMessage());
  52.             throw cnf;
  53.         }
  54.        
  55.         return c;
  56.     }
  57.    
  58.    
  59.     @Override
  60.     public void addURL(URL url) {
  61.         super.addURL(url);
  62.     }
  63.    
  64.    
  65. }