diff -r b5148f646278 -r d154d6012cbe java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Aug 15 11:07:50 2015 +0200 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Aug 15 11:52:38 2015 +0200 @@ -25,8 +25,11 @@ import info.globalcode.sql.dk.configuration.FormatterDefinition; import info.globalcode.sql.dk.configuration.Properties; import info.globalcode.sql.dk.configuration.Property; +import info.globalcode.sql.dk.configuration.PropertyDeclaration; +import info.globalcode.sql.dk.configuration.PropertyDeclarations; import info.globalcode.sql.dk.configuration.TunnelDefinition; import info.globalcode.sql.dk.formatting.ColumnsHeader; +import info.globalcode.sql.dk.formatting.CommonProperties; import info.globalcode.sql.dk.formatting.FakeSqlArray; import info.globalcode.sql.dk.formatting.Formatter; import info.globalcode.sql.dk.formatting.FormatterContext; @@ -184,23 +187,52 @@ } private void listFormatterProperties(String formatterName) throws FormatterException, ConfigurationException { - ColumnsHeader header = constructHeader( - new HeaderField("name", SQLType.VARCHAR), - new HeaderField("type", SQLType.VARCHAR), - new HeaderField("default", SQLType.VARCHAR), - new HeaderField("description", SQLType.VARCHAR) - ); - List data = new ArrayList<>(); + FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName); + try { - data.add(new Object[]{"TODO", "a", "b", "c"}); - data.add(new Object[]{"TODO", "a", "b", "c"}); - data.add(new Object[]{"TODO", "a", "b", "c"}); - data.add(new Object[]{"TODO", "a", "b", "c"}); + ColumnsHeader header = constructHeader( + new HeaderField("name", SQLType.VARCHAR), + new HeaderField("type", SQLType.VARCHAR), + new HeaderField("default", SQLType.VARCHAR), + new HeaderField("description", SQLType.VARCHAR) + ); + List data = new ArrayList<>(); - List parameters = new ArrayList<>(); - parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR)); + Class formatterClass = (Class) Class.forName(fd.getClassName()); - printTable(formatter, header, "-- formatter properties", parameters, data); + // TOOD: formatterClass.getDeclaredAnnotation(PropertyDeclarations.class); and separate inherited properties + // Repeated PropertyDeclaration wrapped in PropertyDeclarations + PropertyDeclarations properties = formatterClass.getAnnotation(PropertyDeclarations.class); + if (properties == null) { + log.log(Level.WARNING, "Formatter „{0}“ has no declared properties", formatterName); + } else { + for (PropertyDeclaration p : properties.value()) { + data.add(propertyDeclarationToRow(p)); + } + } + + // Single PropertyDeclaration + PropertyDeclaration property = formatterClass.getAnnotation(PropertyDeclaration.class); + if (property != null) { + data.add(propertyDeclarationToRow(property)); + } + + List parameters = new ArrayList<>(); + parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR)); + + printTable(formatter, header, "-- formatter properties", parameters, data); + } catch (ClassNotFoundException e) { + throw new ConfigurationException("Unable to find class " + fd.getClassName() + " of formatter" + fd.getName(), e); + } + } + + private static Object[] propertyDeclarationToRow(PropertyDeclaration p) { + return new Object[]{ + p.name(), + CommonProperties.getSimpleTypeName(p.type()), + p.defaultValue(), + p.description() + }; } private void listTypes() throws FormatterException, ConfigurationException {