java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
branchv_0
changeset 212 d154d6012cbe
parent 211 b5148f646278
child 214 1fb3c7953d8a
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sat Aug 15 11:07:50 2015 +0200
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sat Aug 15 11:52:38 2015 +0200
     1.3 @@ -25,8 +25,11 @@
     1.4  import info.globalcode.sql.dk.configuration.FormatterDefinition;
     1.5  import info.globalcode.sql.dk.configuration.Properties;
     1.6  import info.globalcode.sql.dk.configuration.Property;
     1.7 +import info.globalcode.sql.dk.configuration.PropertyDeclaration;
     1.8 +import info.globalcode.sql.dk.configuration.PropertyDeclarations;
     1.9  import info.globalcode.sql.dk.configuration.TunnelDefinition;
    1.10  import info.globalcode.sql.dk.formatting.ColumnsHeader;
    1.11 +import info.globalcode.sql.dk.formatting.CommonProperties;
    1.12  import info.globalcode.sql.dk.formatting.FakeSqlArray;
    1.13  import info.globalcode.sql.dk.formatting.Formatter;
    1.14  import info.globalcode.sql.dk.formatting.FormatterContext;
    1.15 @@ -184,23 +187,52 @@
    1.16  	}
    1.17  
    1.18  	private void listFormatterProperties(String formatterName) throws FormatterException, ConfigurationException {
    1.19 -		ColumnsHeader header = constructHeader(
    1.20 -				new HeaderField("name", SQLType.VARCHAR),
    1.21 -				new HeaderField("type", SQLType.VARCHAR),
    1.22 -				new HeaderField("default", SQLType.VARCHAR),
    1.23 -				new HeaderField("description", SQLType.VARCHAR)
    1.24 -		);
    1.25 -		List<Object[]> data = new ArrayList<>();
    1.26 +		FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName);
    1.27 +		try {
    1.28  
    1.29 -		data.add(new Object[]{"TODO", "a", "b", "c"});
    1.30 -		data.add(new Object[]{"TODO", "a", "b", "c"});
    1.31 -		data.add(new Object[]{"TODO", "a", "b", "c"});
    1.32 -		data.add(new Object[]{"TODO", "a", "b", "c"});
    1.33 +			ColumnsHeader header = constructHeader(
    1.34 +					new HeaderField("name", SQLType.VARCHAR),
    1.35 +					new HeaderField("type", SQLType.VARCHAR),
    1.36 +					new HeaderField("default", SQLType.VARCHAR),
    1.37 +					new HeaderField("description", SQLType.VARCHAR)
    1.38 +			);
    1.39 +			List<Object[]> data = new ArrayList<>();
    1.40  
    1.41 -		List<Parameter> parameters = new ArrayList<>();
    1.42 -		parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR));
    1.43 +			Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName());
    1.44  
    1.45 -		printTable(formatter, header, "-- formatter properties", parameters, data);
    1.46 +			// TOOD: formatterClass.getDeclaredAnnotation(PropertyDeclarations.class); and separate inherited properties
    1.47 +			// Repeated PropertyDeclaration wrapped in PropertyDeclarations
    1.48 +			PropertyDeclarations properties = formatterClass.getAnnotation(PropertyDeclarations.class);
    1.49 +			if (properties == null) {
    1.50 +				log.log(Level.WARNING, "Formatter „{0}“  has no declared properties", formatterName);
    1.51 +			} else {
    1.52 +				for (PropertyDeclaration p : properties.value()) {
    1.53 +					data.add(propertyDeclarationToRow(p));
    1.54 +				}
    1.55 +			}
    1.56 +
    1.57 +			// Single PropertyDeclaration
    1.58 +			PropertyDeclaration property = formatterClass.getAnnotation(PropertyDeclaration.class);
    1.59 +			if (property != null) {
    1.60 +				data.add(propertyDeclarationToRow(property));
    1.61 +			}
    1.62 +
    1.63 +			List<Parameter> parameters = new ArrayList<>();
    1.64 +			parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR));
    1.65 +
    1.66 +			printTable(formatter, header, "-- formatter properties", parameters, data);
    1.67 +		} catch (ClassNotFoundException e) {
    1.68 +			throw new ConfigurationException("Unable to find class " + fd.getClassName() + " of formatter" + fd.getName(), e);
    1.69 +		}
    1.70 +	}
    1.71 +
    1.72 +	private static Object[] propertyDeclarationToRow(PropertyDeclaration p) {
    1.73 +		return new Object[]{
    1.74 +			p.name(),
    1.75 +			CommonProperties.getSimpleTypeName(p.type()),
    1.76 +			p.defaultValue(),
    1.77 +			p.description()
    1.78 +		};
    1.79  	}
    1.80  
    1.81  	private void listTypes() throws FormatterException, ConfigurationException {