// potentially, allowed and default values
// SimpleTable attrTable = attrDescriptions == null ? null :
// new SimpleTable(new String[]{"ATTR NAME", "VALUE", "TYPE", "NILLABLE", "REQUIRED", "ACCESS", "EXPR", "RESTART", "STORAGE"});
// SimpleTable childrenTable = childDescriptions == null ? null :
// new SimpleTable(new String[]{"CHILD NAME", "MIN-OCCURS", "MAX-OCCURS"});
StrictSizeTable attrTable = attrDescriptions == null ? null : new StrictSizeTable(attrDescriptions.keys().size());
StrictSizeTable childrenTable = childDescriptions == null ? null : new StrictSizeTable(childDescriptions.keys().size());
if(typeNames == null && attrTable == null && childrenTable == null) {
typeNames = new ArrayList<String>();
}
for (Property prop : props) {
final StringBuilder buf = new StringBuilder();
if(typeNames == null || !typeNames.contains(prop.getName())) {
if(attrDescriptions == null) {
buf.append(prop.getName());
buf.append('=');
buf.append(prop.getValue().asString());
// TODO the value should be formatted nicer but the current fomatter uses new lines for complex value which doesn't work here
// final ModelNode value = prop.getValue();
// ModelNodeFormatter.Factory.forType(value.getType()).format(buf, 0, value);
typeNames.add(buf.toString());
buf.setLength(0);
} else {
if(attrDescriptions.hasDefined(prop.getName())) {
final ModelNode attrDescr = attrDescriptions.get(prop.getName());
/* attrTable.addLine(new String[]{prop.getName(),
prop.getValue().asString(),
getAsString(attrDescr, Util.TYPE),
getAsString(attrDescr, Util.NILLABLE),
getAsString(attrDescr, Util.REQUIRED),
getAsString(attrDescr, Util.ACCESS_TYPE),
getAsString(attrDescr, Util.EXPRESSIONS_ALLOWED),
getAsString(attrDescr, Util.RESTART_REQUIRED),
getAsString(attrDescr, Util.STORAGE)
});
*/
attrTable.addCell("ATTRIBUTE", prop.getName());
attrTable.addCell(Util.VALUE, prop.getValue().asString());
for(String name : attrDescr.keys()) {
if(!Util.DESCRIPTION.equals(name) &&
!Util.HEAD_COMMENT_ALLOWED.equals(name) &&
!Util.TAIL_COMMENT_ALLOWED.equals(name)) {
attrTable.addCell(name, attrDescr.get(name).asString());
}
}
} else {
/* attrTable.addLine(new String[]{prop.getName(),
prop.getValue().asString(),
"n/a", "n/a", "n/a", "n/a", "n/a", "n/a"
});
*/
attrTable.addCell("ATTRIBUTE", prop.getName());
attrTable.addCell(Util.VALUE, prop.getValue().asString());
}
if(!attrTable.isAtLastRow()) {
attrTable.nextRow();
}
}
} else if(childDescriptions != null) {
if(childDescriptions.hasDefined(prop.getName())) {
final ModelNode childDescr = childDescriptions.get(prop.getName());
/* childrenTable.addLine(new String[]{prop.getName(),
getAsString(childDescr, Util.MIN_OCCURS),
getAsString(childDescr, Util.MAX_OCCURS)
});
*/
childrenTable.addCell("CHILD", prop.getName());
for(String name : childDescr.keys()) {
if(!Util.DESCRIPTION.equals(name) &&
!Util.HEAD_COMMENT_ALLOWED.equals(name) &&
!Util.TAIL_COMMENT_ALLOWED.equals(name)) {
childrenTable.addCell(name, childDescr.get(name).asString());
}
}
} else {
// attrTable.addLine(new String[]{prop.getName(), "n/a", "n/a"});
childrenTable.addCell("CHILD", prop.getName());
}
if(!childrenTable.isAtLastRow()) {
childrenTable.nextRow();
}
}
}
if(childrenTable != null && !childrenTable.isEmpty()) {
ctx.printLine(childrenTable.toString());
}
if(attrTable != null && !attrTable.isEmpty()) {
ctx.printLine(attrTable.toString());
}
}