use of org.walkmod.conf.entities.PropertyDefinition in project walkmod-core by walkmod.
the class ConfigurationImpl method getProperties.
private List<PropertyDefinition> getProperties(Object o) {
List<PropertyDefinition> result = new LinkedList<PropertyDefinition>();
PropertyDescriptor[] properties = BeanUtils.getPropertyDescriptors(o.getClass());
if (properties != null) {
for (PropertyDescriptor pd : properties) {
if (pd.getWriteMethod() != null) {
String name = pd.getDisplayName();
Class<?> clazz = pd.getPropertyType();
String type = clazz.getSimpleName();
String value = "";
if (String.class.isAssignableFrom(clazz) || Number.class.isAssignableFrom(clazz) || clazz.isPrimitive()) {
if (pd.getReadMethod() != null) {
try {
value = pd.getReadMethod().invoke(o).toString();
} catch (Exception e) {
}
} else {
Field[] fields = o.getClass().getDeclaredFields();
boolean found = false;
for (int i = 0; i < fields.length && !found; i++) {
if (fields[i].getName().equals(name)) {
found = true;
fields[i].setAccessible(true);
try {
value = fields[i].get(o).toString();
} catch (Exception e) {
}
}
}
}
}
PropertyDefinition item = new PropertyDefinitionImpl(type, name, value);
result.add(item);
}
}
}
return result;
}
use of org.walkmod.conf.entities.PropertyDefinition in project walkmod-core by walkmod.
the class InspectCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
command.usage("inspect");
} else {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options().offline(offline));
List<BeanDefinition> beans = facade.inspectPlugin(new PluginConfigImpl(pluginId.get(0)));
List<String> validTypesList = Arrays.asList("String", "JSONObject", "JSONArray");
if (beans != null) {
at = new V2_AsciiTable();
at.addRule();
at.addRow("TYPE NAME (ID)", "CATEGORY", "PROPERTIES", "DESCRIPTION");
at.addStrongRule();
for (BeanDefinition bean : beans) {
List<PropertyDefinition> properties = bean.getProperties();
if (properties == null || properties.isEmpty()) {
at.addRow(bean.getType(), bean.getCategory(), "", bean.getDescription());
} else {
int i = 0;
for (PropertyDefinition pd : properties) {
if (validTypesList.contains(pd.getType())) {
String label = pd.getName() + ":" + pd.getType();
if (pd.getDefaultValue() != null && pd.getDefaultValue().length() != 0) {
label = label + " (" + pd.getDefaultValue() + ")";
}
if (i == 0) {
at.addRow(bean.getType(), bean.getCategory(), label, bean.getDescription());
} else {
at.addRow("", "", label, "");
}
i++;
}
}
}
at.addRule();
}
}
}
}
Aggregations