cn.featherfly.hammer.tpl.TemplateDirectives Maven / Gradle / Ivy
package cn.featherfly.hammer.tpl;
import java.util.HashMap;
import java.util.Map;
import cn.featherfly.hammer.HammerException;
/**
*
* TemplateDirectives
*
*
* @author zhongj
*/
public class TemplateDirectives {
public static final String WHERE_DIRECTIVE_KEY = "where";
public static final String AND_DIRECTIVE_KEY = "and";
public static final String OR_DIRECTIVE_KEY = "or";
public static final String PROPERTIES_DIRECTIVE_KEY = "prop";
public static final String TEMPLATE_INCLUDE_DIRECTIVE_KEY = "tpl";
public static final String WRAP_DIRECTIVE_KEY = "wrap";
private static final String[] REQUIRED_KEYS = { WHERE_DIRECTIVE_KEY,
AND_DIRECTIVE_KEY, OR_DIRECTIVE_KEY, PROPERTIES_DIRECTIVE_KEY,
TEMPLATE_INCLUDE_DIRECTIVE_KEY, WRAP_DIRECTIVE_KEY };
protected Map directiveMap = new HashMap<>();
public void addDirective(String key, D directive) {
directiveMap.put(key, directive);
}
public Map getDirectiveMap() {
return directiveMap;
}
public Map getDirectiveMapAfterCheck() {
for (String key : REQUIRED_KEYS) {
if (!directiveMap.containsKey(key)) {
throw new HammerException(
"directive with key " + key + " is null");
}
}
return directiveMap;
}
public void addWhereDirective(D directive) {
directiveMap.put(WHERE_DIRECTIVE_KEY, directive);
}
public void addAndDirective(D directive) {
directiveMap.put(AND_DIRECTIVE_KEY, directive);
}
public void addOrDirective(D directive) {
directiveMap.put(OR_DIRECTIVE_KEY, directive);
}
public void addPropertiesDirective(D directive) {
directiveMap.put(PROPERTIES_DIRECTIVE_KEY, directive);
}
public void addTemplateIncludeDirective(D directive) {
directiveMap.put(TEMPLATE_INCLUDE_DIRECTIVE_KEY, directive);
}
public void addWrapDirective(D directive) {
directiveMap.put(WRAP_DIRECTIVE_KEY, directive);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy