/** Load the specified class by name, taking into account added classpath and reloaded classes, etc. Note: Again, this is just a trivial implementation. See bsh.classpath.ClassManagerImpl for the fully functional class management package. @return the class or null */ public Class classForName( String name ) { if ( isClassBeingDefined( name ) ) throw new InterpreterError( "Attempting to load class in the process of being defined: " +name ); Class clas = null; try { clas = plainClassForName( name ); } catch ( ClassNotFoundException e ) { /*ignore*/ } return clas; }
protected Class<?> loadSourceClass( final String name ) { final String fileName = '/' + name.replace('.', '/') + ".java"; final URL url = getResource( fileName ); if ( url == null ) return null; try (FileReader reader = new FileReader((InputStream) url.getContent())) { Interpreter.debug("Loading class from source file: " + fileName); declaringInterpreter.eval( reader ); } catch ( IOException | EvalError e ) { if (Interpreter.DEBUG.get()) e.printStackTrace(); } try { return plainClassForName( name ); } catch ( final ClassNotFoundException e ) { Interpreter.debug("Class not found in source file: " + name); return null; } }
/** Load the specified class by name, taking into account added classpath and reloaded classes, etc. Note: Again, this is just a trivial implementation. See bsh.classpath.ClassManagerImpl for the fully functional class management package. @return the class or null */ public Class<?> classForName( String name ) { if ( isClassBeingDefined( name ) ) throw new InterpreterError( "Attempting to load class in the process of being defined: " +name ); Class<?> clas = null; try { clas = plainClassForName( name ); } catch ( ClassNotFoundException e ) { /*ignore*/ } // try scripted class if ( clas == null && declaringInterpreter.getCompatibility() ) clas = loadSourceClass( name ); return clas; }