// Force longOpt if output option is specified
if (outputOpts != null) {
longOpt = true;
}
List<ColumnInfo> cols = null;
ColumnFormatter colfm = null;
if (longOpt) {
cols = getColumnInfo(targetType);
if (!isOutputOptsValid(cols, outputOpts)) {
String collist = arrayToString(getColumnHeadings(cols));
String msg = localStrings.getLocalString(GenericCrudCommand.class,
"GenericListCommand.invalidOutputOpts",
"Invalid output option. Choose from the following columns: {0}",
collist);
report.failure(logger, msg);
return;
}
cols = filterColumns(cols, outputOpts);
// sort the columns based on column ordering
Collections.sort(cols, new Comparator<ColumnInfo>() {
@Override
public int compare(ColumnInfo o1, ColumnInfo o2) {
return Integer.valueOf(o1.order).compareTo(Integer.valueOf(o2.order));
}
});
colfm = headerOpt ? new ColumnFormatter(getColumnHeadings(cols)) : new ColumnFormatter();
}
List<Map> list = new ArrayList<Map>();
Properties props = report.getExtraProperties();
if (props == null) {
props = new Properties();
report.setExtraProperties(props);
}
try {
List<ConfigBeanProxy> children = (List<ConfigBeanProxy>) targetMethod.invoke(parentBean);
for (ConfigBeanProxy child : children) {
if (name != null && !name.equals(Dom.unwrap(child).getKey())) {
continue;
}
Map<String,String> map = new HashMap<String,String>();
if (longOpt) {
String data[] = getColumnData(child, cols);
colfm.addRow(data);
for (int i = 0; i < data.length; i++) {
map.put(cols.get(i).xmlName, data[i]);
}
} else {
Dom childDom = Dom.unwrap(child);
String key = childDom.getKey();
if (key==null) {
String msg = localStrings.getLocalString(GenericCrudCommand.class,
"GenericListCommand.element_has_no_key",
"The element {0} has no key attribute",
targetType);
report.failure(logger, msg);
return;
}
report.addSubActionsReport().setMessage(key);
map.put("key", key);
}
list.add(map);
}
if (longOpt) {
report.appendMessage(colfm.toString());
}
if (!list.isEmpty()) {
props.put(elementName(Dom.unwrap(parentBean).document, parentType, targetType), list);
}
} catch (Exception e) {