}
});
m.put(RythmEvents.ON_BUILD_JAVA_SOURCE, new IEventHandler<Void, CodeBuilder>() {
@Override
public Void handleEvent(RythmEngine engine, CodeBuilder cb) {
ISourceCodeEnhancer ce = sourceCodeEnhancer;
if (null == ce) return null;
if (cb.basicTemplate()) {
// basic template do not have common codes
return null;
}
// add common render args
Map<String, ?> defArgs = ce.getRenderArgDescriptions();
for (String name : defArgs.keySet()) {
Object o = defArgs.get(name);
String type = (o instanceof Class<?>) ? ((Class<?>) o).getName() : o.toString();
cb.addRenderArgs(-1, type, name);
}
// add common imports
for (String s : ce.imports()) {
cb.addImport(s, -1);
}
return null;
}
});
m.put(RythmEvents.COMPILED, new IEventHandler<byte[], byte[]>() {
@Override
public byte[] handleEvent(RythmEngine engine, byte[] bytes) {
TemplateResourceManager.commitTmpBlackList();
return bytes;
}
});
m.put(RythmEvents.COMPILE_FAILED, new IEventHandler<Void, TemplateClass>() {
@Override
public Void handleEvent(RythmEngine engine, TemplateClass tc) {
TemplateResourceManager.rollbackTmpBlackList();
return null;
}
});
m.put(RythmEvents.ON_CLOSING_JAVA_CLASS, new IEventHandler<Void, CodeBuilder>() {
@Override
public Void handleEvent(RythmEngine engine, CodeBuilder cb) {
// add common source code
ISourceCodeEnhancer ce = sourceCodeEnhancer;
if (null == ce) {
return null;
}
if (cb.basicTemplate()) {
// basic template do not have common codes
return null;
}
cb.np(ce.sourceCode());
cb.pn();
return null;
}
});
m.put(RythmEvents.ON_RENDER, new IEventHandler<Void, ITemplate>() {
@Override
public Void handleEvent(RythmEngine engine, ITemplate template) {
ISourceCodeEnhancer ce = engine.conf().sourceEnhancer();
if (null != ce) {
ce.setRenderArgs(template);
}
renderListener.onRender(template);
return null;
}
});