55import org .osgi .framework .Bundle ;
66import org .osgi .framework .BundleContext ;
77
8+ import lucee .commons .io .log .Log ;
89import lucee .loader .engine .CFMLEngine ;
910import lucee .loader .engine .CFMLEngineFactory ;
1011import lucee .runtime .config .Config ;
11-
12- import lucee .commons .io .log .Log ;
13-
12+ import lucee .runtime .util .ClassUtil ;
1413
1514/**
16- * A special class loader that first attempts to load class from the Lucee Environment,
17- * but that can fail when RMI classes are requested via a spawned thread, so when
18- * the class cannot be located in the Lucee Environment, it searches all the Felix
19- * bundles for the requested class. This will prevent issues with issues trying
20- * to load classes like net.sf.ehcache.distribution.RMICachePeer_Stub.
15+ * A special class loader that first attempts to load class from the Lucee
16+ * Environment, but that can fail when RMI classes are requested via a spawned
17+ * thread, so when the class cannot be located in the Lucee Environment, it
18+ * searches all the Felix bundles for the requested class. This will prevent
19+ * issues with issues trying to load classes like
20+ * net.sf.ehcache.distribution.RMICachePeer_Stub.
2121 *
2222 * @author Dan G. Switzer, II
2323 * @version 1.0
@@ -32,24 +32,24 @@ public EHCacheClassLoader(Config config) {
3232 try {
3333 Method m = config .getClass ().getMethod ("getClassLoaderEnv" , new Class [0 ]);
3434 this .coreEnvClassLoader = (ClassLoader ) m .invoke (config , new Object [0 ]);
35- }
36- catch (Exception e ) {
35+ } catch (Exception e ) {
3736 // do nothing
3837 }
3938 }
4039
4140 /*
42- * We need to test if the class is a framework bundle and to do that, we need
43- * to use reflection to get access to the private OSGiUtil isFrameworkBundle()
41+ * We need to test if the class is a framework bundle and to do that, we need to
42+ * use reflection to get access to the private OSGiUtil isFrameworkBundle()
4443 * method.
4544 *
46- * IMPORTANT — If the method in the Lucee source code changes, this function will break.
45+ * IMPORTANT — If the method in the Lucee source code changes, this function
46+ * will break.
4747 */
48- public boolean isFrameworkBundle (Bundle b ){
48+ public boolean isFrameworkBundle (Bundle b ) {
4949 try {
50- Class <?> clazz = CFMLEngineFactory .getInstance ().getClassUtil (). loadClass ( "lucee.runtime.osgi.OSGiUtil" );
51- Method m = clazz . getMethod ( "isFrameworkBundle" , new Class [] { Bundle . class });
52- return ( boolean ) m . invoke ( null , b );
50+ ClassUtil util = CFMLEngineFactory .getInstance ().getClassUtil ();
51+ return ( boolean ) util . callStaticMethod ( util . loadClass ( "lucee.runtime.osgi.OSGiUtil" ), "isFrameworkBundle" ,
52+ new Object [] { b } );
5353 } catch (Exception e ) {
5454 return false ;
5555 }
@@ -61,6 +61,7 @@ private Log getLogger() {
6161 return logger ;
6262 }
6363
64+ @ Override
6465 public Class <?> loadClass (final String className ) throws ClassNotFoundException {
6566 Class <?> clazz = null ;
6667
@@ -69,30 +70,30 @@ public Class<?> loadClass(final String className) throws ClassNotFoundException
6970 log .debug ("ehcache" , "Loading class " + className );
7071
7172 // we should try the finding the class in the Lucee environmental class loader
72- if ( this .coreEnvClassLoader != null ) {
73+ if ( this .coreEnvClassLoader != null ) {
7374 try {
74- clazz = ( Class <?>) this .coreEnvClassLoader .loadClass (className );
75+ clazz = this .coreEnvClassLoader .loadClass (className );
7576 } catch (ClassNotFoundException ex ) {
7677 // ignore that we cannot find the class
7778 log .debug ("ehcache" , "Could not find " + className + " class in EnvClassLoader." );
7879 }
7980 }
80-
81+
8182 log .debug ("ehcache" , "Could not find " + className + " in normal class loader, searching Felix bundles..." );
8283 clazz = searchFelixBundleClasses (className );
8384
84- if ( clazz == null ) {
85+ if ( clazz == null ) {
8586 log .debug ("ehcache" , "Could not find " + className + " class in any class loader!" );
8687 throw new ClassNotFoundException ();
8788 }
8889
8990 return clazz ;
9091 }
9192
92- private Class <?> searchFelixBundleClasses (final String className ){
93+ private Class <?> searchFelixBundleClasses (final String className ) {
9394 Class <?> clazz = null ;
9495
95- synchronized (getClassLoadingLock (className )){
96+ synchronized (getClassLoadingLock (className )) {
9697 // try to find the class in the Felix bundles
9798 CFMLEngine engine = CFMLEngineFactory .getInstance ();
9899
@@ -107,12 +108,12 @@ private Class<?> searchFelixBundleClasses(final String className){
107108 if (b != null && !isFrameworkBundle (b )) {
108109 try {
109110 clazz = b .loadClass (className );
110- }
111- catch (Exception e ) {
111+ } catch (Exception e ) {
112112 clazz = null ;
113113 }
114- if ( clazz != null ){
115- getLogger ().debug ("ehcache" , "Found in " + className + " class in " + b .getSymbolicName () + " bundle." );
114+ if (clazz != null ) {
115+ getLogger ().debug ("ehcache" ,
116+ "Found in " + className + " class in " + b .getSymbolicName () + " bundle." );
116117 return clazz ;
117118 }
118119 }
@@ -123,7 +124,7 @@ private Class<?> searchFelixBundleClasses(final String className){
123124
124125 return clazz ;
125126 }
126-
127+
127128 public ClassLoader getClassLoader () {
128129 return EHCacheClassLoader .class .getClassLoader ();
129130 }
0 commit comments