@return the class or null
( String name )
| 139 | @return the class or null |
| 140 | */ |
| 141 | @Override |
| 142 | public Class classForName( String name ) |
| 143 | { |
| 144 | // check positive cache |
| 145 | Class c = (Class)absoluteClassCache.get(name); |
| 146 | if (c != null ) |
| 147 | return c; |
| 148 | |
| 149 | // check negative cache |
| 150 | if ( absoluteNonClasses.contains(name) ) { |
| 151 | if ( Interpreter.DEBUG ) Interpreter.debug("absoluteNonClass list hit: "+name); |
| 152 | return null; |
| 153 | } |
| 154 | |
| 155 | if ( Interpreter.DEBUG ) Interpreter.debug("Trying to load class: "+name); |
| 156 | |
| 157 | // Check explicitly mapped (reloaded) class... |
| 158 | final ClassLoader overlayLoader = getLoaderForClass( name ); |
| 159 | if ( overlayLoader != null ) { |
| 160 | try { |
| 161 | c = overlayLoader.loadClass(name); |
| 162 | } catch ( Exception e ) { |
| 163 | if ( Interpreter.DEBUG ) Interpreter.debug("overlay loader failed for '" + name + "' - " + e); |
| 164 | } |
| 165 | // Should be there since it was explicitly mapped |
| 166 | // throw an error if c == null)? |
| 167 | } |
| 168 | |
| 169 | // insure that core classes are loaded from the same loader |
| 170 | if ((c == null) && name.startsWith(BSH_PACKAGE)) { |
| 171 | final ClassLoader myClassLoader = Interpreter.class.getClassLoader(); // is null if located in bootclasspath |
| 172 | if (myClassLoader != null) { |
| 173 | try { |
| 174 | c = myClassLoader.loadClass(name); |
| 175 | } catch (ClassNotFoundException e) { |
| 176 | // fall through |
| 177 | } catch (NoClassDefFoundError e) { |
| 178 | // fall through |
| 179 | } |
| 180 | } else { |
| 181 | try { |
| 182 | c = Class.forName( name ); |
| 183 | } catch ( ClassNotFoundException e ) { |
| 184 | // fall through |
| 185 | } catch ( NoClassDefFoundError e ) { |
| 186 | // fall through |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // Check classpath extension / reloaded classes |
| 192 | if ((c == null) && (baseLoader != null)) { |
| 193 | try { |
| 194 | c = baseLoader.loadClass(name); |
| 195 | } catch (ClassNotFoundException e) { |
| 196 | // fall through |
| 197 | } |
| 198 | } |
no test coverage detected