DurchflusstabelleFactory - GroovyClassLoader-Demo
0
A GroovyClassLoader demonstration. The given domain is a german water flow meter system; I think, you shouldn't be able to understand the domain, but you should be able to understand, how to load a Groovy class in Java via a GroovyClassLoader.
import groovy.lang.GroovyClassLoader;
public class DurchflusstabelleFactory
{
private static final String DURCHFLUSSTABELLE_GROOVY = "durchflusstabelle.groovy";
public static Durchflusstabelle createDurchflusstabelle()
{
Class clazz = DurchflusstabelleFactory.class;
ClassLoader parent = clazz.getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
Class groovyClass = loader.parseClass(clazz.getResourceAsStream(DURCHFLUSSTABELLE_GROOVY));
try
{
return (Durchflusstabelle) groovyClass.newInstance();
}
catch (Exception programmierfehler)
{
throw new RuntimeException("Konnte Klasse " +
DURCHFLUSSTABELLE_GROOVY + " nicht laden!",
programmierfehler);
}
}
}






There are currently no comments for this snippet.