Skip to content

Instantly share code, notes, and snippets.

@itaifrenkel
Created May 14, 2012 16:24
Show Gist options
  • Save itaifrenkel/2694894 to your computer and use it in GitHub Desktop.
Save itaifrenkel/2694894 to your computer and use it in GitHub Desktop.
Pseuodo code for reading a Cloudify Service POJO from a Groovy DSL file
Service parse(
String recipeFile, List<String> classpath,
Map<String, Object> properties, ServiceContext context) {
// add POJO base class, and classpath
cc = new CompilerConfiguration();
cc.setScriptBaseClass( BaseDslScript.class.getName() );
cc.setClasspathList(classpath);
// inject default imports
ic = new ImportCustomizer();
ic.addImports( ServiceUtils.class.getName() );
cc.addCompilationCustomizers(ic);
// inject context and properties
Binding binding = new Binding();
binding.setVariable("context", context);
for (prop: properties.entrySet()) {
binding.setVariable( prop.getKey(), prop.getValue());
}
// parse the recipe text file
classloader = this.class.getClassLoader();
gs = new GroovyShell(classloader, binding, cc);
reader = new FileReader(dslFile);
try {
return (Service) gs.evaluate(reader);
} finally {
reader.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment