use of org.jaffa.rules.RulesEngineException in project jaffa-framework by jaffa-projects.
the class DomainModelDocService method createTree.
/**
* @return JSONArray.
*/
private JSONArray createTree() {
JSONArray array = new JSONArray();
Map<String, TreeNode> rootNodeCache = new HashMap<String, TreeNode>();
Map<String, TreeNode> child1NodeCache = new HashMap<String, TreeNode>();
try {
Properties props = new Properties();
String[] classNames = RulesEngineFactory.getRulesEngine().getClassNamesByRuleName("domain-info");
if (classNames != null) {
for (String className : classNames) {
IObjectRuleIntrospector introspector = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(className, null);
List<Properties> propList = introspector.getMetaDataByRule("domain-info");
for (Properties p : propList) {
if (p != null && p.size() > 0) {
StringBuilder sb = new StringBuilder();
String module = (String) p.get("module");
String subModule = (String) p.get("sub-module");
String domainName = (String) p.get("name");
String dbTable = (String) p.get("db-table");
if ((module != null && subModule != null) && (!"null".equals(module) && !"null".equals(subModule))) {
sb.append(module).append(".").append(subModule).append(".").append(domainName);
if (!props.containsKey(sb.toString())) {
if (dbTable != null && !"null".equals(dbTable)) {
StringBuilder value = new StringBuilder();
value.append(className).append("~").append(dbTable);
props.put(sb.toString(), value.toString());
} else {
props.put(sb.toString(), className);
}
}
}
if (log.isDebugEnabled()) {
log.debug("key :" + sb.toString());
log.debug("className :" + className);
}
}
}
}
}
Enumeration<String> enumeration = (Enumeration<String>) props.propertyNames();
int rootNodeCounter = 1;
TreeNode globalRoot = new TreeNode(0, "API Documentation");
globalRoot.setLeaf(false);
globalRoot.setIconCls("icon-docs");
while (enumeration.hasMoreElements()) {
String serviceName = enumeration.nextElement();
String[] treeNodeName = serviceName.split("\\.");
TreeNode root = null;
TreeNode child1 = null;
boolean hasRoot = false;
for (int i = 0; i < treeNodeName.length; i++) {
boolean hasChild1 = false;
if (i == 0) {
if (!rootNodeCache.containsKey(treeNodeName[i])) {
root = new TreeNode(rootNodeCounter, treeNodeName[i]);
root.setLeaf(false);
root.setIconCls("icon-pkg");
rootNodeCache.put(treeNodeName[i], root);
} else {
root = rootNodeCache.get(treeNodeName[i]);
hasRoot = true;
}
} else if (i == 1) {
if (!child1NodeCache.containsKey(treeNodeName[i - 1] + treeNodeName[i])) {
child1 = new TreeNode(Integer.parseInt(rootNodeCounter + "" + i), treeNodeName[i]);
child1.setLeaf(false);
child1.setIconCls("icon-pkg");
child1NodeCache.put(treeNodeName[i - 1] + treeNodeName[i], child1);
} else {
child1 = child1NodeCache.get(treeNodeName[i - 1] + treeNodeName[i]);
root.setIconCls("icon-pkg");
hasChild1 = true;
}
if (!hasChild1) {
root.addChild(child1);
}
} else if (i == 2) {
String[] nodeAtt = props.getProperty(serviceName).split("~");
String className = nodeAtt.length > 0 ? nodeAtt[0] : null;
String dbTable = nodeAtt.length > 1 ? nodeAtt[1] : null;
TreeNode child2 = new TreeNode(Integer.parseInt(rootNodeCounter + "" + i), treeNodeName[i]);
child2.setLeaf(true);
child2.setIconCls("icon-cls");
child2.setIsClass(true);
child2.setClassName(className);
child2.setServiceName(serviceName);
child2.setDbTableName(dbTable);
child1.addChild(child2);
}
}
if (!hasRoot) {
globalRoot.addChild(root);
}
rootNodeCounter++;
}
array.add(globalRoot.toJson());
} catch (RulesEngineException ex) {
log.error(ex);
ex.printStackTrace(System.out);
}
return array;
}
Aggregations