property annotations: default values v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 15 Aug 2015 10:34:18 +0200
branchv_0
changeset 207 2bba68ef47c1
parent 206 e2f24eea8543
child 208 1a511d321ade
property annotations: default values
java/sql-dk/src/info/globalcode/sql/dk/configuration/PropertyDeclaration.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractXmlFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleRecordFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/TeXFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java
--- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/PropertyDeclaration.java	Sat Aug 15 10:20:39 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/PropertyDeclaration.java	Sat Aug 15 10:34:18 2015 +0200
@@ -24,6 +24,9 @@
 import java.lang.annotation.Target;
 
 /**
+ * Declaration of the (formatter) properties – for documentation purposes.
+ *
+ * TODO: automatically inject properties (configured, ad-hoc, default ones) to the formatters
  *
  * @author Ing. František Kučera (frantovo.cz)
  */
@@ -46,4 +49,9 @@
 	 * @return documentation for the users
 	 */
 	String description();
+
+	/**
+	 * @return default value of this property
+	 */
+	String defaultValue();
 }
--- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractXmlFormatter.java	Sat Aug 15 10:20:39 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractXmlFormatter.java	Sat Aug 15 10:34:18 2015 +0200
@@ -47,17 +47,14 @@
  *
  * @author Ing. František Kučera (frantovo.cz)
  */
-@PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
-@PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT, type = String.class, description = "tab or sequence of spaces used for indentation of nested elements")
-@PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT_TEXT, type = Boolean.class, description = "whether to indent text nodes")
+@PropertyDeclaration(name = COLORFUL, defaultValue = "false", type = Boolean.class, description = COLORFUL_DESCRIPTION)
+@PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT, defaultValue = AbstractXmlFormatter.PROPERTY_INDENT_DEFAULT, type = String.class, description = "tab or sequence of spaces used for indentation of nested elements")
+@PropertyDeclaration(name = AbstractXmlFormatter.PROPERTY_INDENT_TEXT, defaultValue = "true", type = Boolean.class, description = "whether text with line breaks should be indented; if not original whitespace will be preserved.")
 public abstract class AbstractXmlFormatter extends AbstractFormatter {
 
 	private static final Logger log = Logger.getLogger(AbstractXmlFormatter.class.getName());
 	public static final String PROPERTY_INDENT = "indent";
-	/**
-	 * Whether text with line breaks should be indented (default). Otherwise original whitespace
-	 * will be preserved.
-	 */
+	protected static final String PROPERTY_INDENT_DEFAULT = "\t";
 	public static final String PROPERTY_INDENT_TEXT = "indentText";
 	private static final TerminalColor ELEMENT_COLOR = TerminalColor.Magenta;
 	private static final TerminalColor ATTRIBUTE_NAME_COLOR = TerminalColor.Green;
@@ -73,7 +70,7 @@
 		super(formatterContext);
 		boolean colorful = formatterContext.getProperties().getBoolean(COLORFUL, false);
 		out = new ColorfulPrintWriter(formatterContext.getOutputStream(), false, colorful);
-		indent = formatterContext.getProperties().getString(PROPERTY_INDENT, "\t");
+		indent = formatterContext.getProperties().getString(PROPERTY_INDENT, PROPERTY_INDENT_DEFAULT);
 		indentText = formatterContext.getProperties().getBoolean(PROPERTY_INDENT_TEXT, true);
 
 		if (!indent.matches("\\s*")) {
--- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleRecordFormatter.java	Sat Aug 15 10:20:39 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleRecordFormatter.java	Sat Aug 15 10:34:18 2015 +0200
@@ -28,7 +28,7 @@
  *
  * @author Ing. František Kučera (frantovo.cz)
  */
-@PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
+@PropertyDeclaration(name = COLORFUL, defaultValue = "true", type = Boolean.class, description = COLORFUL_DESCRIPTION)
 public class SingleRecordFormatter extends AbstractFormatter {
 
 	public static final String NAME = "record"; // bash-completion:formatter
--- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Sat Aug 15 10:20:39 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Sat Aug 15 10:34:18 2015 +0200
@@ -43,9 +43,9 @@
  * @see TabularPrefetchingFormatter
  * @see TabularWrappingFormatter
  */
-@PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
-@PropertyDeclaration(name = TabularFormatter.PROPERTY_ASCII, type = Boolean.class, description = "whether to use ASCII table borders instead of unicode ones")
-@PropertyDeclaration(name = TabularFormatter.PROPERTY_TRIM, type = Boolean.class, description = "whether to trim the values to fit the column width")
+@PropertyDeclaration(name = COLORFUL, defaultValue = "true", type = Boolean.class, description = COLORFUL_DESCRIPTION)
+@PropertyDeclaration(name = TabularFormatter.PROPERTY_ASCII, defaultValue = "false", type = Boolean.class, description = "whether to use ASCII table borders instead of unicode ones")
+@PropertyDeclaration(name = TabularFormatter.PROPERTY_TRIM, defaultValue = "false", type = Boolean.class, description = "whether to trim the values to fit the column width")
 public class TabularFormatter extends AbstractFormatter {
 
 	public static final String NAME = "tabular"; // bash-completion:formatter
--- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TeXFormatter.java	Sat Aug 15 10:20:39 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TeXFormatter.java	Sat Aug 15 10:34:18 2015 +0200
@@ -32,7 +32,7 @@
  *
  * @author Ing. František Kučera (frantovo.cz)
  */
-@PropertyDeclaration(name = COLORFUL, type = Boolean.class, description = COLORFUL_DESCRIPTION)
+@PropertyDeclaration(name = COLORFUL, defaultValue = "false", type = Boolean.class, description = COLORFUL_DESCRIPTION)
 public class TeXFormatter extends AbstractFormatter {
 
 	public static final String NAME = "tex"; // bash-completion:formatter
--- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java	Sat Aug 15 10:20:39 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java	Sat Aug 15 10:34:18 2015 +0200
@@ -43,7 +43,7 @@
  *
  * @author Ing. František Kučera (frantovo.cz)
  */
-@PropertyDeclaration(name = XmlFormatter.PROPERTY_LABELED_COLUMNS, type = Boolean.class, description = "whether to add 'label' attribute to each 'column' element")
+@PropertyDeclaration(name = XmlFormatter.PROPERTY_LABELED_COLUMNS, defaultValue = "false", type = Boolean.class, description = "whether to add 'label' attribute to each 'column' element")
 public class XmlFormatter extends AbstractXmlFormatter {
 
 	public static final String NAME = "xml"; // bash-completion:formatter