Created
May 14, 2012 16:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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