201 |
201 |
202 private void listFormatterProperties(String formatterName) throws FormatterException, ConfigurationException { |
202 private void listFormatterProperties(String formatterName) throws FormatterException, ConfigurationException { |
203 FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName); |
203 FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName); |
204 try { |
204 try { |
205 |
205 |
206 ColumnsHeader header = constructHeader( |
206 // currently only for debugging purposes |
207 new HeaderField("name", SQLType.VARCHAR), |
207 // TODO: introduce --info-lister-property or generic filtering capability in printTable() ? |
208 new HeaderField("type", SQLType.VARCHAR), |
208 boolean printDeclaredIn = options.getFormatterProperties().getBoolean("InfoLister:print:declared_in", false); |
209 new HeaderField("default", SQLType.VARCHAR), |
209 |
210 new HeaderField("description", SQLType.VARCHAR), |
210 List<HeaderField> headerFields = new ArrayList<>(); |
211 new HeaderField("declared_in", SQLType.VARCHAR) |
211 headerFields.add(new HeaderField("name", SQLType.VARCHAR)); |
212 ); |
212 headerFields.add(new HeaderField("type", SQLType.VARCHAR)); |
|
213 headerFields.add(new HeaderField("default", SQLType.VARCHAR)); |
|
214 headerFields.add(new HeaderField("description", SQLType.VARCHAR)); |
|
215 if (printDeclaredIn) { |
|
216 headerFields.add(new HeaderField("declared_in", SQLType.VARCHAR)); |
|
217 } |
|
218 |
|
219 ColumnsHeader header = constructHeader(headerFields.toArray(new HeaderField[0])); |
213 |
220 |
214 Map<String, Object[]> data = new HashMap<>(); |
221 Map<String, Object[]> data = new HashMap<>(); |
215 Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName()); |
222 Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName()); |
216 List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class); |
223 List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class); |
217 Collections.reverse(hierarchy); |
224 Collections.reverse(hierarchy); |
218 hierarchy.stream().forEach((c) -> { |
225 hierarchy.stream().forEach((c) -> { |
219 for (PropertyDeclaration p : getPropertyDeclarations(c)) { |
226 for (PropertyDeclaration p : getPropertyDeclarations(c)) { |
220 data.put(p.name(), propertyDeclarationToRow(p, c)); |
227 data.put(p.name(), propertyDeclarationToRow(p, c, printDeclaredIn)); |
221 } |
228 } |
222 }); |
229 }); |
223 |
230 |
224 List<Parameter> parameters = new ArrayList<>(); |
231 List<Parameter> parameters = new ArrayList<>(); |
225 parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR)); |
232 parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR)); |
228 } catch (ClassNotFoundException e) { |
235 } catch (ClassNotFoundException e) { |
229 throw new ConfigurationException("Unable to find class " + fd.getClassName() + " of formatter" + fd.getName(), e); |
236 throw new ConfigurationException("Unable to find class " + fd.getClassName() + " of formatter" + fd.getName(), e); |
230 } |
237 } |
231 } |
238 } |
232 |
239 |
233 private static Object[] propertyDeclarationToRow(PropertyDeclaration p, Class formatterClass) { |
240 private static Object[] propertyDeclarationToRow(PropertyDeclaration p, Class formatterClass, boolean printDeclaredIn) { |
234 return new Object[]{ |
241 List list = new ArrayList(); |
235 p.name(), |
242 |
236 CommonProperties.getSimpleTypeName(p.type()), |
243 list.add(p.name()); |
237 p.defaultValue(), |
244 list.add(CommonProperties.getSimpleTypeName(p.type())); |
238 p.description(), |
245 list.add(p.defaultValue()); |
239 formatterClass.getName() |
246 list.add(p.description()); |
240 }; |
247 if (printDeclaredIn) { |
|
248 list.add(formatterClass.getName()); |
|
249 } |
|
250 |
|
251 return list.toArray(); |
241 } |
252 } |
242 |
253 |
243 private void listTypes() throws FormatterException, ConfigurationException { |
254 private void listTypes() throws FormatterException, ConfigurationException { |
244 ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER)); |
255 ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER)); |
245 List<Object[]> data = new ArrayList<>(); |
256 List<Object[]> data = new ArrayList<>(); |