# HG changeset patch # User František Kučera # Date 1387654730 -3600 # Node ID 4ec8e5534eb9cc514d911584c328330b0ad0f9eb # Parent 4c118af3e855e1cd5bd65522ecf8d21972b2348b configuration basics diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java --- 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; diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/Configuration.java --- 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 . - */ -package info.globalcode.sql.dk; - -/** - * - * @author Ing. František Kučera (frantovo.cz) - */ -public class Configuration { - /** TODO: Databases */ - /** TODO: Formatters */ -} diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/ConfigurationProvider.java --- 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 . - */ -package info.globalcode.sql.dk; - -/** - * - * @author Ing. František Kučera (frantovo.cz) - */ -public interface ConfigurationProvider { - - public Configuration getConfiguration(); -} diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/DKException.java --- /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 . + */ +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); + } +} diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java --- 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; diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java --- /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 . + */ +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 databases = new ArrayList<>(); + private List formatters = new ArrayList<>(); + + public List getDatabases() { + return databases; + } + + public void setDatabases(List databases) { + this.databases = databases; + } + + public List getFormatters() { + return formatters; + } + + public void setFormatters(List formatters) { + this.formatters = formatters; + } +} diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/configuration/ConfigurationProvider.java --- /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 . + */ +package info.globalcode.sql.dk.configuration; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public interface ConfigurationProvider { + + public Configuration getConfiguration(); +} diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseConnection.java --- /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 . + */ +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; + } +} diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java --- /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 . + */ +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); + } +} diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/configuration/FormatterDefinition.java --- /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 . + */ +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 + * info.globalcode.sql.dk.formatting.Formatter interface. + * Subclassing the + * info.globalcode.sql.dk.formatting.AbstractFormatter is strongly recommended. + * The constructor must accept one parameter: + * info.globalcode.sql.dk.formatting.FormatterContext + * + * @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); + } + } +} diff -r 4c118af3e855 -r 4ec8e5534eb9 java/sql-dk/src/info/globalcode/sql/dk/configuration/NameIdentified.java --- /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 . + */ +package info.globalcode.sql.dk.configuration; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public interface NameIdentified { + + public String getName(); +}