try{
List<String> factoryCandidates=this.getAllEngineFactoryCandidates();
for (String candidate: factoryCandidates){
System.out.println("Candidate: "+candidate);
Class factoryClazz=this.getClass().getClassLoader().loadClass(candidate);
ScriptEngineFactory factory=(ScriptEngineFactory) factoryClazz.newInstance();
ScriptEngine engine=factory.getScriptEngine();
try {
engine.eval("puts 'Hello world'");
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(manager.getEngineByName(factory.getLanguageName())!=null){
System.out.println("Engine already existing. Continuing");
continue; //This means that there already is a factory for that language
}
//Now we register the factory for all its names, extensions and mime types
for(String name: factory.getNames()){
System.out.println("registering "+name);
manager.registerEngineName(name, factory);
}
for (String type: factory.getMimeTypes()){
manager.registerEngineMimeType(type, factory);
System.out.println(manager.getEngineByMimeType(type).equals(factory));
}
for (String extension: factory.getExtensions()){
manager.registerEngineExtension(extension, factory);
System.out.println(manager.getEngineByExtension(extension).equals(factory));
}
}