/********************************************************* begin of preamble
**
** Copyright (C) 2003-2010 Software- und Organisations-Service GmbH.
** All rights reserved.
**
** This file may be used under the terms of either the
**
** GNU General Public License version 2.0 (GPL)
**
** as published by the Free Software Foundation
** http://www.gnu.org/licenses/gpl-2.0.txt and appearing in the file
** LICENSE.GPL included in the packaging of this file.
**
** or the
**
** Agreement for Purchase and Licensing
**
** as offered by Software- und Organisations-Service GmbH
** in the respective terms of supply that ship with this file.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
********************************************************** end of preamble*/
/**
*
*/
package sos.configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import sos.connection.SOSConnection;
import sos.settings.SOSConnectionSettings;
import sos.settings.SOSProfileSettings;
import sos.settings.SOSSettings;
import sos.settings.SOSXMLSettings;
import sos.util.SOSArguments;
import sos.util.SOSLogger;
import sos.util.SOSString;
/**
*
* Klasse Configuration
*
* In dieser Klassen werden Parametern - entspricht ConfigurationItem Objekte - gemergt.
*
* Der Herkunft der ConfigurationItem's sind:
* - Programmargumente
* - Scheduler Parameter
* - Konfigurationsdateien
* - Datenbank
*
* Es existiert eine Meta Datei, in dem folgen Information beiinhaltet sind:
*
* 1. g�ltige Parametername
* 2. �berpr�ft ob die Parameterwerte zu den Parametername g�ltig sind
* 3. Abh�ngigkeiten der Parameternamen untereinander
* 4. �berpr�fen der Abh�ngigkeiten mit Hilfe der boolean Operationen wie and und or
*
*
* @author mueruevet.oeksuez@sos-berlin.com
*
*/
public class SOSConfiguration {
/**
* SOSConfigurationItem Objekte
*/
private SOSConfigurationItem[] sosConfigurationItem = new SOSConfigurationItem[] {};
private SOSConfigurationItem[] originParameterFromRequiredDefaults = new SOSConfigurationItem[] {};
private SOSConfigurationItem[] originParameterFromSettings = new SOSConfigurationItem[] {};
private SOSConfigurationItem[] originParameterFromScheduler = new SOSConfigurationItem[] {};
private SOSConfigurationItem[] originParameterFromArguments = new SOSConfigurationItem[] {};
private SOSString sosString = new SOSString();
private SOSLogger sosLogger = null;
/** Programargumente k�nnen entweder als String[] oder als Poperties �bergeben werden */
private String[] arguments = null;
private Properties argumentsAsProperties = null;
/** Scheduler Parameter*/
private Properties schedulerParams = null;
private String settingsFile = null; //f�r SOSXMLSettings und SOSProfilesettings
private String settingsTablename = null; //f�r SOSConnectionSettings
private String settingsApplicationname = null; //f�r SOSConnectionSettings
private String settingsProfilename = null;
/** SOSConnection Objekt wird verwendet in SOSConnectionSettings */
private SOSConnection sosConnection = null;
private String requiredDefaultFile = null;
private SOSConfigurationRequiredItem ri = null;
public SOSConfiguration(String[] arguments_, Properties schedulerParams_, String settingsFile_, String settingsProfilename_, String requiredDefaultFile_,
SOSLogger sosLogger_) throws Exception {
try {
sosLogger = sosLogger_;
arguments = arguments_;
schedulerParams = schedulerParams_;
settingsFile = settingsFile_;
settingsProfilename = settingsProfilename_;
requiredDefaultFile = requiredDefaultFile_;
init();
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public SOSConfiguration(String[] arguments_, Properties schedulerParams_, String settingsFile_, String settingsApplicationname_,
String settingsProfilename_, String requiredDefaultFile_, SOSLogger sosLogger_) throws Exception {
try {
sosLogger = sosLogger_;
arguments = arguments_;
schedulerParams = schedulerParams_;
settingsFile = settingsFile_;
settingsApplicationname = settingsApplicationname_;
settingsProfilename = settingsProfilename_;
requiredDefaultFile = requiredDefaultFile_;
init();
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public SOSConfiguration(String[] arguments_, String settingsFile_, String settingsProfilename_, SOSLogger sosLogger_) throws Exception {
try {
sosLogger = sosLogger_;
arguments = arguments_;
settingsFile = settingsFile_;
settingsProfilename = settingsProfilename_;
init();
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public SOSConfiguration(String[] arguments_, SOSConnection sosConnection_, String settingsTablename_, String settingsApplicationname_,
String settingsProfilename_, SOSLogger sosLogger_) throws Exception {
try {
sosLogger = sosLogger_;
arguments = arguments_;
sosConnection = sosConnection_;
settingsTablename = settingsTablename_;
settingsApplicationname = settingsApplicationname_;
settingsProfilename = settingsProfilename_;
init();
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public SOSConfiguration(Properties arguments_, String settingsFile_, String settingsProfilename_, SOSLogger sosLogger_) throws Exception {
try {
sosLogger = sosLogger_;
argumentsAsProperties = arguments_;
settingsFile = settingsFile_;
settingsProfilename = settingsProfilename_;
init();
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public SOSConfiguration(String settingsFile_, String settingsProfilename_, SOSLogger sosLogger_) throws Exception {
try {
sosLogger = sosLogger_;
settingsFile = settingsFile_;
settingsProfilename = settingsProfilename_;
init();
}
catch (Exception e) {
e.printStackTrace();
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public SOSConfiguration(String[] arguments_, Properties schedulerParams_, String settingsFile_, String settingsProfilename_, SOSLogger sosLogger_)
throws Exception {
try {
sosLogger = sosLogger_;
arguments = arguments_;
schedulerParams = schedulerParams_;
settingsFile = settingsFile_;
settingsProfilename = settingsProfilename_;
init();
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
private void init() throws Exception {
//Programm Arguments k�nnen vom Typ String[] oder Properties sein
if (arguments != null)
readProgramArguments(arguments);
else
readProgramArguments(argumentsAsProperties);
//scheduler Parameter
readSchedulerParams(schedulerParams);
//SOSSettings bestimmen
readSettings();
//merged die Parameter
mergeConfigurationItem();
//liese die Configurations.xml datei
//checkConfigurationItems(requiredDefaultFile);
}
private void readSettings() throws Exception {
try {
if (sosConnection != null && sosString.parseToString(settingsProfilename).length() > 0) {
readConnectionSettings();
}
else
if (sosString.parseToString(settingsFile).length() > 0 && sosString.parseToString(settingsProfilename).length() > 0) {
readProfileSettings();
}
else {
originParameterFromSettings = new SOSConfigurationItem[] {};
}
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
// throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
/**
* Liest Einstellungen aus der Datenbank
* @throws Exception
*/
private void readConnectionSettings() throws Exception {
try {
if (sosConnection != null && sosString.parseToString(settingsProfilename).length() > 0) {
SOSConnectionSettings settings = new SOSConnectionSettings(sosConnection, settingsTablename, settingsApplicationname, settingsProfilename,
sosLogger);
Properties p = settings.getSection();
originParameterFromSettings = new SOSConfigurationItem[p.size()];
Iterator it = p.keySet().iterator();
int i = 0;
while (it.hasNext()) {
String key = sosString.parseToString(it.next());
originParameterFromSettings[i] = new SOSConfigurationItem();
originParameterFromSettings[i].setName(key);
originParameterFromSettings[i].setValue(p.getProperty(key));
i++;
}
}
else {
originParameterFromSettings = new SOSConfigurationItem[] {};
}
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
/**
* Liest Einstellungen aus der Konfigurationsdatei (*.ini oder *.xml)
* @throws Exception
*/
private void readProfileSettings() throws Exception {
try {
if (sosString.parseToString(settingsFile).length() > 0 && sosString.parseToString(settingsProfilename).length() > 0) {
SOSSettings settings = null;
Properties p = null;
if (new java.io.File(settingsFile).getName().endsWith(".xml")) {
settings = new SOSXMLSettings(settingsFile, settingsProfilename, sosLogger);
p = settings.getSection(settingsApplicationname, settingsProfilename);
}
else {
settings = new SOSProfileSettings(settingsFile, settingsProfilename, sosLogger);
p = settings.getSection();
}
originParameterFromSettings = new SOSConfigurationItem[p.size()];
Iterator it = p.keySet().iterator();
int i = 0;
while (it.hasNext()) {
String key = sosString.parseToString(it.next());
originParameterFromSettings[i] = new SOSConfigurationItem();
originParameterFromSettings[i].setName(key);
originParameterFromSettings[i].setValue(p.getProperty(key));
i++;
}
}
else {
originParameterFromSettings = new SOSConfigurationItem[] {};
}
}
catch (Exception e) {
e.printStackTrace();
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
private void readSchedulerParams(Properties schedulerParams_) throws Exception {
try {
originParameterFromScheduler = new SOSConfigurationItem[] {};
if (schedulerParams_ != null) {
originParameterFromScheduler = new SOSConfigurationItem[schedulerParams_.size()];
java.util.Iterator keys = schedulerParams_.keySet().iterator();
int i = 0;
while (keys.hasNext()) {
String key = sosString.parseToString(keys.next());
sosLogger.debug("..scheduler param = " + key);
originParameterFromScheduler[i] = new SOSConfigurationItem();
originParameterFromScheduler[i].setName(key);
originParameterFromScheduler[i].setValue(schedulerParams_.getProperty(key));
i++;
}
}
else {
originParameterFromScheduler = new SOSConfigurationItem[] {};
}
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
private void readProgramArguments(String[] arguments) throws Exception {
try {
if (arguments != null) {
originParameterFromArguments = new SOSConfigurationItem[arguments.length];
SOSArguments arguments_ = new SOSArguments(arguments, true);
java.util.Iterator keys = arguments_.get_arguments().keySet().iterator();
int i = 0;
while (keys.hasNext()) {
String key = sosString.parseToString(keys.next());
String newKey = (key.trim().startsWith("-") && key.trim().endsWith("=") & key.length() > 0 ? key.substring(1, key.length() - 1) : key);
originParameterFromArguments[i] = new SOSConfigurationItem();
originParameterFromArguments[i].setName(newKey);
originParameterFromArguments[i].setValue(arguments_.as_string(key.toString()));
i++;
}
}
else {
originParameterFromArguments = new SOSConfigurationItem[] {};
}
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
private void readProgramArguments(Properties arguments) throws Exception {
try {
if (arguments != null) {
originParameterFromArguments = new SOSConfigurationItem[arguments.size()];
java.util.Iterator keys = arguments.keySet().iterator();
int i = 0;
while (keys.hasNext()) {
String key = sosString.parseToString(keys.next());
originParameterFromArguments[i] = new SOSConfigurationItem();
originParameterFromArguments[i].setName(key);
originParameterFromArguments[i].setValue(sosString.parseToString(arguments.get(key)));
i++;
}
}
else {
originParameterFromArguments = new SOSConfigurationItem[] {};
}
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public SOSConfigurationItem[] mergeConfigurationItem() throws Exception {
sosConfigurationItem = merge(new SOSConfigurationItem[0], originParameterFromSettings);
sosConfigurationItem = merge(sosConfigurationItem, originParameterFromScheduler);
sosConfigurationItem = merge(sosConfigurationItem, originParameterFromArguments);
return sosConfigurationItem;
}
/**
* @return the parameter
*/
public SOSConfigurationItem[] getParameter() throws Exception {
return sosConfigurationItem;
}
/**
*
* @return
* @throws Exception
*/
public Properties getParameterAsProperties() throws Exception {
Properties p = new Properties();
for (int i = 0; i < sosConfigurationItem.length; i++) {
SOSConfigurationItem item = sosConfigurationItem[i];
if (item.getName() != null && item.getName().length() > 0)
p.put(item.getName(), item.getValue());
}
return p;
}
/**
* @param parameter the parameter to set
*/
public void setParameter(SOSConfigurationItem[] parameter) {
this.sosConfigurationItem = parameter;
}
/**
*
* p2 �berschreibt die Werte von p1
* @param p1
* @param p2
* @return
*/
public SOSConfigurationItem[] merge(SOSConfigurationItem[] p1, SOSConfigurationItem[] p2) throws Exception {
SOSConfigurationItem[] retVal = null;
HashMap hp = new HashMap();
for (int i = 0; i < p1.length; i++) {
String name = sosString.parseToString(p1[i].getName());
hp.put(name, p1[i]);
}
for (int i = 0; i < p2.length; i++) {
String name = sosString.parseToString(p2[i].getName());
hp.put(name, p2[i]);
}
Iterator it = hp.keySet().iterator();
retVal = new SOSConfigurationItem[hp.keySet().size()];
for (int i = 0; it.hasNext(); i++) {
Object key = it.next();
retVal[i] = ((SOSConfigurationItem) hp.get(key));
}
return retVal;
}
public SOSConfigurationItem[] checkConfigurationItems() throws Exception {
return checkConfigurationItems(requiredDefaultFile);
}
public SOSConfigurationItem[] checkConfigurationItems(String requiredDefaultFile) throws Exception {
try {
if (requiredDefaultFile == null) {
ri = new SOSConfigurationRequiredItem(sosLogger);
}
else {
ri = new SOSConfigurationRequiredItem(requiredDefaultFile, sosLogger);
}
sosConfigurationItem = ri.check(sosConfigurationItem);
return sosConfigurationItem;
}
catch (Exception e) {
e.printStackTrace();
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public SOSConfigurationItem getConfigurationItemByName(String name) throws Exception {
try {
SOSConfigurationItem item = null;
if (ri != null && ri.getQuickConfigurationsItem() != null && ri.getQuickConfigurationsItem().containsKey(name)) {
//das �berpr�fte ConfigurationItem wird hier �bergeben
item = (SOSConfigurationItem) ri.getQuickConfigurationsItem().get(name);
}
if (item == null)
item = new SOSConfigurationItem();
return item;
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public HashMap getConfigurationsItems() {
if (ri != null && ri.getQuickConfigurationsItem() != null) {
//das �berpr�fte ConfigurationItem wird hier �bergeben
return ri.getQuickConfigurationsItem();
}
else {
return new HashMap();
}
}
public ArrayList getPasswordnames() {
if (ri != null && ri.getPasswordNames() != null) {
//alle Passwortnamen werden �bergeben
return ri.getPasswordNames();
}
else {
return new ArrayList();
}
}
/**
* @return the originParameterFromRequiredDefaults
*/
public SOSConfigurationItem[] getOriginParameterFromRequiredDefaults() {
return originParameterFromRequiredDefaults;
}
/**
* @param originParameterFromRequiredDefaults the originParameterFromRequiredDefaults to set
*/
public void setOriginParameterFromRequiredDefaults(SOSConfigurationItem[] originParameterFromRequiredDefaults) {
this.originParameterFromRequiredDefaults = originParameterFromRequiredDefaults;
}
/**
* @return the originParameterFromSettings
*/
public SOSConfigurationItem[] getOriginParameterFromSettings() {
return originParameterFromSettings;
}
/**
* @param originParameterFromSettings the originParameterFromSettings to set
*/
public void setOriginParameterFromSettings(SOSConfigurationItem[] originParameterFromSettings) {
this.originParameterFromSettings = originParameterFromSettings;
}
/**
* @return the originParameterFromScheduler
*/
public SOSConfigurationItem[] getOriginParameterFromScheduler() {
return originParameterFromScheduler;
}
/**
* @param originParameterFromScheduler the originParameterFromScheduler to set
*/
public void setOriginParameterFromScheduler(SOSConfigurationItem[] originParameterFromScheduler) {
this.originParameterFromScheduler = originParameterFromScheduler;
}
/**
* @return the originParameterFromArguments
*/
public SOSConfigurationItem[] getOriginParameterFromArguments() {
return originParameterFromArguments;
}
/**
* @param originParameterFromArguments the originParameterFromArguments to set
*/
public void setOriginParameterFromArguments(SOSConfigurationItem[] originParameterFromArguments) {
this.originParameterFromArguments = originParameterFromArguments;
}
/**
* @param configurationItem the configurationItem to set
*/
public void setConfigurationItem(SOSConfigurationItem[] configurationItem) {
this.sosConfigurationItem = configurationItem;
}
/**
* @param sosLogger the sosLogger to set
*/
public void setLogger(SOSLogger sosLogger) {
this.sosLogger = sosLogger;
}
/**
* @param arguments the arguments to set
*/
public void setArguments(String[] arguments) throws Exception {
this.arguments = arguments;
try {
readProgramArguments(arguments);
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public void setArguments(Properties arguments) throws Exception {
this.argumentsAsProperties = arguments;
try {
readProgramArguments(argumentsAsProperties);
}
catch (Exception e) {
throw new Exception("error in " + sos.util.SOSClassUtil.getMethodName() + ": cause: " + e.toString());
}
}
public void setSchedulerParams(Properties schedulerParams_) {
this.schedulerParams = schedulerParams_;
}
/**
* @param settingsFile the settingsFile to set
*/
public void setSettingsFile(String settingsFile) {
this.settingsFile = settingsFile;
}
/**
* @param settingsProfilename the settingsProfilename to set
*/
public void setSettingsProfilename(String settingsProfilename) {
this.settingsProfilename = settingsProfilename;
}
/**
* @param requiredDefaultFile the requiredDefaultFile to set
*/
public void setRequiredDefaultFile(String requiredDefaultFile) {
this.requiredDefaultFile = requiredDefaultFile;
}
/**
* test SOSProfileSettings
* @param args
* @param requiredDefaultFile
* @param sosLogger
*/
public static void test1(String[] args, String requiredDefaultFile, sos.util.SOSLogger sosLogger) {
try {
System.out.println("~~~~~~~~~~~~~~~~~~ testen von SOSProfileSettings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
String settingsFile = "./testDateien/ftp_settings.ini";
String profile = "remote_wilma";
SOSConfiguration con = new SOSConfiguration(args, null, settingsFile, profile, sosLogger);
SOSConfigurationItem[] p2 = con.getParameter();//Hier sind die gemergte Parameter ohne Defaults und �berpr�fung
System.out.println("*************************** Hier sind die Parameter ohne Defaults und �berpr�fung ***************************");
for (int i = 0; i < p2.length; i++) {
System.out.println(i + "'te Parameter \n\tname=" + p2[i].getName() + "\n\tvalue=" + p2[i].getValue() + "\n\tdefault=" + p2[i].getDefaults()
+ "\n\titemId=" + p2[i].getItemId() + "\n\tpassword=" + p2[i].isPassword());
}
System.out.println("*************************** Start configuration Item nachdem �berpr�fung und ggf. mit Defaults ************************");
SOSConfigurationItem[] p1 = con.checkConfigurationItems(requiredDefaultFile);
for (int i = 0; i < p1.length; i++) {
System.out.println(i + "'te Parameter \n\tname=" + p1[i].getName() + "\n\tvalue=" + p1[i].getValue() + "\n\tdefault=" + p1[i].getDefaults()
+ "\n\titemId=" + p1[i].getItemId() + "\n\tpassword=" + p1[i].isPassword());
}
System.out.println("**********************************************************************************");
}
catch (Exception e) {
System.err.println(e);
}
}
/**
* test SOSXMLSettings
* @param args
* @param requiredDefaultFile
* @param sosLogger
*/
public static void test2(String[] args, String requiredDefaultFile, sos.util.SOSLogger sosLogger) {
try {
System.out.println("~~~~~~~~~~~~~~~~~~ testen von SOSXMLSettings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
String settingsFile = "./testDateien/test_settings.xml";
String settingsApplication = "defaults";
String profile = "remote_wilma";
SOSConfiguration con = new SOSConfiguration(args, null, settingsFile, settingsApplication, profile, requiredDefaultFile, sosLogger);
SOSConfigurationItem[] p2 = con.getParameter();//Hier sind die gemergte Parameter ohne Defaults und �berpr�fung
System.out.println("*************************** Hier sind die Parameter ohne Defaults und �berpr�fung ***************************");
for (int i = 0; i < p2.length; i++) {
System.out.println(i + "'te Parameter \n\tname=" + p2[i].getName() + "\n\tvalue=" + p2[i].getValue() + "\n\tdefault=" + p2[i].getDefaults()
+ "\n\titemId=" + p2[i].getItemId() + "\n\tpassword=" + p2[i].isPassword());
}
System.out.println("*************************** Start configuration Item nachdem �berpr�fung und ggf. mit Defaults ************************");
SOSConfigurationItem[] p1 = con.checkConfigurationItems(requiredDefaultFile);
for (int i = 0; i < p1.length; i++) {
System.out.println(i + "'te Parameter \n\tname=" + p1[i].getName() + "\n\tvalue=" + p1[i].getValue() + "\n\tdefault=" + p1[i].getDefaults()
+ "\n\titemId=" + p1[i].getItemId() + "\n\tpassword=" + p1[i].isPassword());
}
System.out.println("**********************************************************************************");
}
catch (Exception e) {
System.err.println(e);
}
}
/**
* test SOSConnectionSettings
* @param args
* @param iniSOSConnectionFile
* @param requiredDefaultFile
* @param sosLogger
*/
public static void test3(String[] args, String iniSOSConnectionFile, String requiredDefaultFile, sos.util.SOSLogger sosLogger) {
try {
System.out.println("~~~~~~~~~~~~~~~~~~ testen von SOSConnectionSettings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//Connection erstellen
SOSConnection sosConnection = null;
try {
System.out.println("DB Connecting.. .");
sosConnection = SOSConnection.createInstance(iniSOSConnectionFile, sosLogger);
sosConnection.connect();
System.out.println("DB Connected");
}
catch (Exception e) {
System.out.print(e.toString());
}
String settingsTablename = "SETTINGS";
String settingsApplication = "test_sosftp";
String settingsProfilename = "test";
SOSConfiguration con = new SOSConfiguration(args, sosConnection, settingsTablename, settingsApplication, settingsProfilename, sosLogger);
SOSConfigurationItem[] p2 = con.getParameter();//Hier sind die gemergte Parameter ohne Defaults und �berpr�fung
System.out.println("*************************** Hier sind die Parameter ohne Defaults und �berpr�fung ***************************");
for (int i = 0; i < p2.length; i++) {
System.out.println(i + "'te Parameter \n\tname=" + p2[i].getName() + "\n\tvalue=" + p2[i].getValue() + "\n\tdefault=" + p2[i].getDefaults()
+ "\n\titemId=" + p2[i].getItemId() + "\n\tpassword=" + p2[i].isPassword());
}
SOSConfigurationItem[] p1 = con.checkConfigurationItems(requiredDefaultFile);
System.out.println("*************************** Start configuration Item nachdem �berpr�fung und ggf. mit Defaults ************************");
for (int i = 0; i < p1.length; i++) {
System.out.println(i + "'te Parameter \n\tname=" + p1[i].getName() + "\n\tvalue=" + p1[i].getValue() + "\n\tdefault=" + p1[i].getDefaults()
+ "\n\titemId=" + p1[i].getItemId() + "\n\tpassword=" + p1[i].isPassword());
}
System.out.println("**********************************************************************************");
}
catch (Exception e) {
System.err.println(e);
}
}
/**
* @param args
*/
public static void main(String[] args) throws Exception {
try {
//Folgende dateien werden zum Testen ben�tigt:
// 1. ./testDateien/Configuration.xml
// 2. ./testDateien/sos_settings.ini
// 3. ./testDateien/ftp_settings.ini
// 4. ./testDateien/test_settings.xml
// 5. sos.util.configuration.TestJob.java --> liegt tempor�r da
// 6. ./testDateien/TestParams.job.xml -> job f�r 5.
//manuell erzeugte programmargumente soll zum Test dienen
if (args == null || args.length == 0)
//args = new String[]{"-operation=receive", "-remove_files=true", "-host=blabla", "-user=1234"};
args = new String[] { "-operation=receive", "-remove_files=true", "-user=1234" };
if (args != null && args.length > 0) {
System.out.print("~~~~~~~~~ Programm argumente sind: ");
for (int i = 0; i < args.length; i++) {
System.out.print(args[i] + ";");
}
System.out.println("~~~~~~~~~~~~~~~");
}
String requiredDefaultFile = "./testDateien/Configuration.xml";
sos.util.SOSLogger sosLogger = new sos.util.SOSStandardLogger(10);
//1- Testen von Programmargumente und SOSProfileSettings mit Configuration.xml
test1(args, requiredDefaultFile, sosLogger);
//2- Testen von Programmargumente und SOSXMLSettings mit Configuration.xml
test2(args, requiredDefaultFile, sosLogger);
//3- Testen von Programmargumente und SOSConnectionSettings mit Configuration.xml
test3(args, "./testDateien/sos_settings.ini", requiredDefaultFile, sosLogger);
//4- Testen mit Scheduler Parameter. Siehe dazu Beispiel sos.util.configuration.TestJob
}
catch (Exception e) {
System.out.println("error : " + e.toString());
}
}
}