public static Class loadClass ( String className , Class defaultValue ) { className = className . trim ( ) ; CFMLEngine engine = CFMLEngineFactory . getInstance ( ) ; BundleCollection bc = engine . getBundleCollection ( ) ; // first we try to load the class from the Lucee core try { // load from core return bc . core . loadClass ( className ) ; } catch ( Throwable t ) { ExceptionUtil . rethrowIfNecessary ( t ) ; } // class is not visible to the Lucee core // now we check all started bundled (not only bundles used by core) Bundle [ ] bundles = bc . getBundleContext ( ) . getBundles ( ) ; for ( Bundle b : bundles ) { if ( b == bc . core ) continue ; try { return b . loadClass ( className ) ; } catch ( Throwable t ) { ExceptionUtil . rethrowIfNecessary ( t ) ; } // class is not visible to that bundle } // now we check lucee loader (SystemClassLoader?) CFMLEngineFactory factory = engine . getCFMLEngineFactory ( ) ; try { // print.e("loader:"); return factory . getClass ( ) . getClassLoader ( ) . loadClass ( className ) ; } catch ( Throwable t ) { ExceptionUtil . rethrowIfNecessary ( t ) ; } /* * try { return Class.forName(className); } catch (Throwable t3) { * * } */ // now we check bundles not loaded Set < String > loaded = new HashSet < String > ( ) ; for ( Bundle b : bundles ) { loaded . add ( b . getSymbolicName ( ) + "|" + b . getVersion ( ) ) ; } try { File dir = factory . getBundleDirectory ( ) ; File [ ] children = dir . listFiles ( JAR_EXT_FILTER ) ; BundleFile bf ; for ( int i = 0 ; i < children . length ; i ++ ) { try { bf = new BundleFile ( children [ i ] ) ; if ( bf . isBundle ( ) && ! loaded . contains ( bf . getSymbolicName ( ) + "|" + bf . getVersion ( ) ) && bf . hasClass ( className ) ) { Bundle b = null ; try { b = _loadBundle ( bc . getBundleContext ( ) , bf . getFile ( ) ) ; } catch ( IOException e ) { } if ( b != null ) { startIfNecessary ( b ) ; return b . loadClass ( className ) ; } } } catch ( Throwable t2 ) { ExceptionUtil . rethrowIfNecessary ( t2 ) ; } } } catch ( Throwable t1 ) { ExceptionUtil . rethrowIfNecessary ( t1 ) ; } return defaultValue ; }
tries to load a class with ni bundle definition