/** Use direct Class.forName() to test for the existence of a class. We should not use BshClassManager here because: a) the systems using these tests would probably not load the classes through it anyway. b) bshclassmanager is heavy and touches other class files. this capabilities code must be light enough to be used by any system **including the remote applet**. */ public static boolean classExists( String name ) { if ( !classes.containsKey(name) ) try { /* Note: do *not* change this to BshClassManager plainClassForName() or equivalent. This class must not touch any other bsh classes. */ classes.put(name, Class.forName( name )); } catch ( ClassNotFoundException e ) { classes.put(name, null); } return getExisting( name ) != null; }
/** Create a new instance of the class manager. Class manager instnaces are now associated with the interpreter. @see bsh.Interpreter.getClassManager() @see bsh.Interpreter.setClassLoader( ClassLoader ) */ public static BshClassManager createClassManager( Interpreter interpreter ) { BshClassManager manager; // Do we have the optional package? if ( Capabilities.classExists("bsh.classpath.ClassManagerImpl") ) try { // Try to load the module // don't refer to it directly here or we're dependent upon it Class<?> clazz = Capabilities.getExisting("bsh.classpath.ClassManagerImpl"); manager = (BshClassManager) clazz.getConstructor().newInstance(); } catch ( IllegalArgumentException | ReflectiveOperationException | SecurityException e) { throw new InterpreterError("Error loading classmanager", e); } else manager = new BshClassManager(); manager.declaringInterpreter = interpreter; return manager; }