--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Fri Dec 20 23:50:21 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sat Dec 21 20:38:50 2013 +0100
@@ -17,7 +17,9 @@
*/
package info.globalcode.sql.dk;
+import info.globalcode.sql.dk.configuration.ConfigurationProvider;
import info.globalcode.sql.dk.CLIOptions.MODE;
+import info.globalcode.sql.dk.configuration.Configuration;
import java.util.logging.Level;
import java.util.logging.Logger;
--- a/java/sql-dk/src/info/globalcode/sql/dk/Configuration.java Fri Dec 20 23:50:21 2013 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/**
- * SQL-DK
- * Copyright © 2013 František Kučera (frantovo.cz)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package info.globalcode.sql.dk;
-
-/**
- *
- * @author Ing. František Kučera (frantovo.cz)
- */
-public class Configuration {
- /** TODO: Databases */
- /** TODO: Formatters */
-}
--- a/java/sql-dk/src/info/globalcode/sql/dk/ConfigurationProvider.java Fri Dec 20 23:50:21 2013 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/**
- * SQL-DK
- * Copyright © 2013 František Kučera (frantovo.cz)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package info.globalcode.sql.dk;
-
-/**
- *
- * @author Ing. František Kučera (frantovo.cz)
- */
-public interface ConfigurationProvider {
-
- public Configuration getConfiguration();
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/DKException.java Sat Dec 21 20:38:50 2013 +0100
@@ -0,0 +1,41 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk;
+
+/**
+ * TODO: GEC
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class DKException extends Exception {
+
+ public DKException() {
+ }
+
+ public DKException(String message) {
+ super(message);
+ }
+
+ public DKException(Throwable cause) {
+ super(cause);
+ }
+
+ public DKException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
--- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Fri Dec 20 23:50:21 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Dec 21 20:38:50 2013 +0100
@@ -17,6 +17,7 @@
*/
package info.globalcode.sql.dk;
+import info.globalcode.sql.dk.configuration.ConfigurationProvider;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java Sat Dec 21 20:38:50 2013 +0100
@@ -0,0 +1,49 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+@XmlRootElement
+public class Configuration {
+
+ private List<DatabaseDefinition> databases = new ArrayList<>();
+ private List<FormatterDefinition> formatters = new ArrayList<>();
+
+ public List<DatabaseDefinition> getDatabases() {
+ return databases;
+ }
+
+ public void setDatabases(List<DatabaseDefinition> databases) {
+ this.databases = databases;
+ }
+
+ public List<FormatterDefinition> getFormatters() {
+ return formatters;
+ }
+
+ public void setFormatters(List<FormatterDefinition> formatters) {
+ this.formatters = formatters;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/ConfigurationProvider.java Sat Dec 21 20:38:50 2013 +0100
@@ -0,0 +1,27 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.configuration;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public interface ConfigurationProvider {
+
+ public Configuration getConfiguration();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseConnection.java Sat Dec 21 20:38:50 2013 +0100
@@ -0,0 +1,31 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.configuration;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class DatabaseConnection {
+
+ private DatabaseDefinition databaseDefinition;
+
+ public DatabaseConnection(DatabaseDefinition databaseDefinition) {
+ this.databaseDefinition = databaseDefinition;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java Sat Dec 21 20:38:50 2013 +0100
@@ -0,0 +1,75 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.configuration;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class DatabaseDefinition implements NameIdentified {
+
+ private String name;
+ private String url;
+ private String userName;
+ private String password;
+
+ @XmlElement(name = "name")
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlElement(name = "url")
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @XmlElement(name = "userName")
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ @XmlElement(name = "password")
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ @XmlTransient
+ public DatabaseConnection connect() {
+ return new DatabaseConnection(this);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/FormatterDefinition.java Sat Dec 21 20:38:50 2013 +0100
@@ -0,0 +1,90 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.configuration;
+
+import info.globalcode.sql.dk.DKException;
+import info.globalcode.sql.dk.formatting.Formatter;
+import info.globalcode.sql.dk.formatting.FormatterContext;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class FormatterDefinition implements NameIdentified {
+
+ private String name;
+ private String className;
+
+ @XmlElement(name = "name")
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Filter's class. Must implement the
+ * <code>info.globalcode.sql.dk.formatting.Formatter</code> interface.
+ * Subclassing the
+ * <code>info.globalcode.sql.dk.formatting.AbstractFormatter</code> is strongly recommended.
+ * The constructor must accept one parameter:
+ * <code>info.globalcode.sql.dk.formatting.FormatterContext</code>
+ *
+ * @return fully qualified class name
+ */
+ @XmlElement(name = "class")
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ /**
+ * @param context
+ * @return
+ * @throws DKException
+ */
+ @XmlTransient
+ public Formatter getInstance(FormatterContext context) throws DKException {
+ try {
+ Constructor constructor = Class.forName(className).getConstructor(context.getClass());
+
+ Object instance = constructor.newInstance(context);
+ if (instance instanceof Formatter) {
+ return (Formatter) instance;
+ } else {
+ throw new DKException("Formatter " + instance + " does not implement the " + Formatter.class.getName() + " interface");
+ }
+ } catch (ClassNotFoundException e) {
+ throw new DKException("No formatter class with name: " + className, e);
+ } catch (NoSuchMethodException e) {
+ throw new DKException("Formatter class with no valid constructor: " + className, e);
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
+ throw new DKException("Formatter's constructor caused an error: " + className, e);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/NameIdentified.java Sat Dec 21 20:38:50 2013 +0100
@@ -0,0 +1,27 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.configuration;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public interface NameIdentified {
+
+ public String getName();
+}