Refactoring creation of the lesson moving it towards the plugin

This commit is contained in:
nbaars
2015-03-01 15:59:42 +01:00
parent 4865a4b606
commit 3e9331d46e
3 changed files with 14 additions and 9 deletions

View File

@ -124,9 +124,12 @@ public class Plugin {
}
}
public Class<AbstractLesson> getLesson() {
return lesson;
public AbstractLesson getLesson() {
try {
return lesson.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new PluginLoadingFailure("Unable to instantiate the lesson " + lesson.getName(), e);
}
}
public Optional<File> getLessonSolution(String language) {

View File

@ -1,15 +1,21 @@
package org.owasp.webgoat.plugins;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PluginClassLoader extends ClassLoader {
private final Logger logger = LoggerFactory.getLogger(Plugin.class);
private final byte[] classFile;
public PluginClassLoader(ClassLoader parent, byte[] classFile) {
public PluginClassLoader(ClassLoader parent, String nameOfClass, byte[] classFile) {
super(parent);
logger.debug("Creating class loader for {}", nameOfClass);
this.classFile = classFile;
}
public Class findClass(String name) {
logger.debug("Finding class " + name);
return defineClass(name, classFile, 0, classFile.length);
}