import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import org.apache.logging.log4j.Logger;
import org.mxchange.jcore.application.Application;
import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.contact.Contact;
+import org.mxchange.jcore.database.backend.DatabaseBackend;
import org.mxchange.jcore.database.frontend.DatabaseFrontend;
import org.mxchange.jcore.manager.Manageable;
*/
public class BaseFrameworkSystem implements FrameworkInterface {
+ /**
+ * Bundle instance
+ */
+ private static ResourceBundle bundle;
+
/**
* Instance for own properties
*/
private static final Properties properties = new Properties(System.getProperties());
+ /**
+ * Self instance
+ */
+ private static FrameworkInterface selfInstance;
+
/**
* Class' logger
*/
private Application application;
/**
- * Bundle instance
+ * Instance for database backend
*/
- private static ResourceBundle bundle;
+ private DatabaseBackend backend;
/**
* Client instance
*/
private Client client;
+ /**
+ * Contact instance
+ */
+ private Contact contact;
+
/**
* Manager instance
*/
* No instances can be created of this class
*/
protected BaseFrameworkSystem () {
- // Init properties file
- this.initProperties();
+ // Set own instance
+ this.setSelfInstance();
}
/**
- * Initializes i18n bundles
+ * Getter for this application
+ *
+ * @return Instance from this application
*/
- protected void initBundle () {
- // Is the bundle set?
- if (bundle instanceof ResourceBundle) {
- // Is already set
- throw new IllegalStateException("called twice");
- }
-
- // Set instance
- bundle = ResourceBundle.getBundle(FrameworkInterface.I18N_BUNDLE_FILE); // NOI18N
+ public static final FrameworkInterface getInstance () {
+ // Return it
+ return selfInstance;
}
/**
return this.application;
}
+ /**
+ * Getter for logger
+ *
+ * @return Logger
+ */
+ @Override
+ public final Logger getLogger () {
+ return this.LOG;
+ }
+
+ /**
+ * Manager instance
+ *
+ * @return the contactManager
+ */
+ @Override
+ public final Manageable getManager () {
+ return this.manager;
+ }
+
+ /**
+ * Getter for human-readable string from given key
+ *
+ * @param key Key to return
+ * @return Human-readable message
+ */
+ @Override
+ public final String getMessageStringFromKey (final String key) {
+ // Return message
+ return this.getBundle().getString(key);
+ }
+
+ /**
+ * Some "getter for a value from given column name. This name will be
+ * translated into a method name and then this method is called.
+ *
+ * @param columnName Column name
+ * @return Value from field
+ * @throws IllegalArgumentException Some implementations may throw this.
+ * @throws NoSuchMethodException Some implementations may throw this.
+ * @throws java.lang.IllegalAccessException If the method cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Any other problems?
+ */
+ @Override
+ public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0}", columnName)); //NOI18N
+ }
+
+ /**
+ * Some "getter" for target class instance from given name.
+ *
+ * @param instance Instance to iterate on
+ * @param targetClass Class name to look for
+ * @return Class instance
+ */
+ @SuppressWarnings("unchecked")
+ private Class<? extends FrameworkInterface> getClassFromTarget (final FrameworkInterface instance, final String targetClass) {
+ // Trace message
+ this.getLogger().debug(MessageFormat.format("instance={0},targetClass={1}", instance, targetClass)); //NOI18N
+
+ // Instance reflaction of this class
+ Class<? extends FrameworkInterface> c = instance.getClass();
+
+ // Analyze class
+ while (!targetClass.equals(c.getSimpleName())) {
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("c={0}", c.getSimpleName())); //NOI18N
+
+ // Get super class (causes unchecked warning)
+ c = (Class<? extends FrameworkInterface>) c.getSuperclass();
+ }
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("c={0} - EXIT!", c)); //NOI18N
+
+ // Return it
+ return c;
+ }
+
+ /**
+ * Some "getter" for a Method instance from given method name
+ *
+ * @param instance Actual instance to call
+ * @param targetClass Target class name
+ * @param methodName Method name
+ * @return A Method instance
+ */
+ private Method getMethodFromName (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException {
+ // Trace messahe
+ this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
+
+ // Get target class instance
+ Class<? extends FrameworkInterface> c = this.getClassFromTarget(instance, targetClass);
+
+ // Init field instance
+ Method method = null;
+
+ // Use reflection to get all attributes
+ method = c.getDeclaredMethod(methodName, new Class<?>[0]);
+
+ // Assert on field
+ assert (method instanceof Method) : "method is not a Method instance"; //NOI18N
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("method={0} - EXIT!", method)); //NOI18N
+
+ // Return it
+ return method;
+ }
+
+ /**
+ * Setter for self instance
+ */
+ private void setSelfInstance () {
+ // Need to set it here
+ selfInstance = this;
+ }
+
+ /**
+ * Aborts program with given exception
+ *
+ * @param throwable Any type of Throwable
+ */
+ protected final void abortProgramWithException (final Throwable throwable) {
+ // Log exception ...
+ this.getLogger().catching(throwable);
+
+ // .. and exit
+ System.exit(1);
+ }
+
+ /**
+ * Application instance
+ *
+ * @param application the application to set
+ */
+ protected final void setApplication (final Application application) {
+ this.application = application;
+ }
+
/**
* Client instance
*
return this.client;
}
+ /**
+ * Getter for bundle instance
+ *
+ * @return Resource bundle
+ */
+ protected final ResourceBundle getBundle () {
+ return BaseFrameworkSystem.bundle;
+ }
+
+ /**
+ * Client instance
+ *
+ * @param client the client to set
+ */
+ protected final void setClient (final Client client) {
+ this.client = client;
+ }
+
+ /**
+ * Name of used database table, handled over to backend
+ *
+ * @return the tableName
+ */
+ public final String getTableName () {
+ return this.tableName;
+ }
+
/**
* Checks if given boolean field is available and set to same value
*
* @param columnName Column name to check
* @param bool Boolean value
* @return Whether all conditions are met
+ * @throws NoSuchMethodException May be thrown by some implementations
+ * @throws java.lang.IllegalAccessException If the method cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Any other problems?
*/
@Override
- public boolean isValueEqual (final String columnName, final boolean bool) {
+ public boolean isValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Not implemented
throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0},bool={1}", columnName, bool)); //NOI18N
}
this.getLogger().catching(exception);
}
- /**
- * Prepares all properties, the file is written if it is not found
- */
- private void initProperties () {
- // Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("{0} properties are loaded already.", BaseFrameworkSystem.properties.size())); //NOI18N
-
- // Are some properties loaded?
- if (!BaseFrameworkSystem.properties.isEmpty()) {
- // Some are already loaded, abort here
- return;
- }
-
- try {
- // Try to read it
- BaseFrameworkSystem.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("{0} properties has been loaded.", BaseFrameworkSystem.properties.size())); //NOI18N
- } catch (final FileNotFoundException ex) {
- // Debug message
- this.getLogger().debug(MessageFormat.format("Properties file {0} not found: {1}", FrameworkInterface.PROPERTIES_CONFIG_FILE, ex)); //NOI18N
-
- /*
- * The file is not found which is normal for first run, so
- * initialize default values.
- */
- this.initPropertiesWithDefault();
-
- // Write file
- this.writePropertiesFile();
- } catch (final IOException ex) {
- // Something else didn't work
- this.abortProgramWithException(ex);
- }
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
/**
* Initializes properties with default values
*/
// Init default values:
// Default database backend
- BaseFrameworkSystem.properties.put("org.mxchange.database.backendType", "base64csv"); //NOI18N
+ BaseFrameworkSystem.properties.put("org.mxchange.database.backend.class", "org.mxchange.jcore.database.backend.base64.Base64CsvDatabaseBackend"); //NOI18N
+ BaseFrameworkSystem.properties.put("database.backend.storagepath", "data/"); //NOI18N
// For MySQL backend
BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.host", "localhost"); //NOI18N
/**
* Writes the properties file to disk
*/
- private void writePropertiesFile () {
+ private void writePropertiesFile () throws IOException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
- try {
- // Write it
- BaseFrameworkSystem.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
- } catch (final IOException ex) {
- this.abortProgramWithException(ex);
- }
+ // Write it
+ BaseFrameworkSystem.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
* @param delimiter Delimiter
* @param size Size of array
* @return Array from tokenized string
+ * @todo Get rid of size parameter
*/
protected String[] getArrayFromString (final String str, final String delimiter, final int size) {
// Trace message
this.getLogger().trace(MessageFormat.format("str={0},delimiter={1},size={2} - CALLED!", str, delimiter, size)); //NOI18N
-
+
// Get tokenizer
StringTokenizer tokenizer = new StringTokenizer(str, delimiter);
-
+
// Init array and index
String[] tokens = new String[size];
int index = 0;
-
+
// Run through all tokens
while (tokenizer.hasMoreTokens()) {
// Get current token and add it
tokens[index] = tokenizer.nextToken();
-
+
// Debug message
this.getLogger().debug(MessageFormat.format("Token at index{0}: {1}", index, tokens[1])); //NOI18N
-
+
// Increment index
index++;
}
-
+
// Trace message
this.getLogger().trace(MessageFormat.format("tokens({0})={1} - EXIT!", tokens.length, Arrays.toString(tokens))); //NOI18N
}
/**
- * Returns boolean field value from given method call
+ * Returns boolean field value from given method name by invoking it
*
* @param instance The instance to call
* @param targetClass Target class to look in
* @param methodName Method name to look for
* @return Boolean value from field
+ * @throws java.lang.NoSuchMethodException If the method was not found
+ * @throws java.lang.IllegalAccessException If the method cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Some other problems?
*/
- protected boolean getBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName) {
+ protected boolean getBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace messahe
this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
// Get value from field
Boolean value = false;
- try {
- value = (Boolean) method.invoke(instance);
- } catch (final IllegalArgumentException ex) {
- // Other problem
- this.abortProgramWithException(ex);
- } catch (final IllegalAccessException ex) {
- // Other problem
- this.abortProgramWithException(ex);
- } catch (final InvocationTargetException ex) {
- // Other problem
- this.abortProgramWithException(ex);
- }
+ // Try to get the value by invoking the method
+ value = (Boolean) method.invoke(instance);
// Return value
return value;
}
/**
- * Client instance
+ * Manager instance
*
- * @param client the client to set
+ * @param manager the manager instance to set
*/
- protected final void setClient (final Client client) {
- this.client = client;
+ protected final void setContactManager (final Manageable manager) {
+ this.manager = manager;
}
/**
- * Application instance
+ * Returns any field value from given method name by invoking it
*
- * @param application the application to set
+ * @param instance The instance to call
+ * @param targetClass Target class to look in
+ * @param methodName Method name to look for
+ * @return Any value from field
+ * @throws java.lang.NoSuchMethodException If the method was not found
+ * @throws java.lang.IllegalAccessException If the method cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Some other problems?
*/
- protected final void setApplication (final Application application) {
- this.application = application;
- }
+ protected Object getField (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ // Trace messahe
+ this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
- /**
- * Getter for logger
- *
- * @return Logger
- */
- @Override
- public final Logger getLogger () {
- return this.LOG;
- }
+ // Get method to call
+ Method method = this.getMethodFromName(instance, targetClass, methodName);
- /**
- * Manager instance
- *
- * @return the contactManager
- */
- @Override
- public final Manageable getManager () {
- return this.manager;
+ // Get value from field
+ Object object = method.invoke(instance);
+
+ // Return value
+ return object;
}
/**
- * Getter for human-readable string from given key
+ * Getter for property which must exist
*
- * @param key Key to return
- * @return Human-readable message
+ * @param key Key to get
+ * @return Propety value
*/
- @Override
- public final String getMessageStringFromKey (final String key) {
- // Return message
- return this.getBundle().getString(key);
+ protected final String getProperty (final String key) {
+ return BaseFrameworkSystem.properties.getProperty(String.format("org.mxchange.%s", key)); //NOI18N
}
/**
- * Some "getter for a value from given column name. This name will be
- * translated into a method name and then this method is called.
+ * Name of used database table, handled over to backend
*
- * @param columnName Column name
- * @return Value from field
+ * @param tableName the tableName to set
*/
- @Override
- public Object getValueFromColumn (final String columnName) {
- throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0}", columnName)); //NOI18N
+ protected final void setTableName (final String tableName) {
+ this.tableName = tableName;
}
/**
- * Some "getter" for target class instance from given name.
+ * Converts null to empty string or leaves original string.
*
- * @param instance Instance to iterate on
- * @param targetClass Class name to look for
- * @return Class instance
+ * @param str Any string
+ * @return Empty string if null or original string
*/
- @SuppressWarnings ("unchecked")
- private Class<? extends FrameworkInterface> getClassFromTarget (final FrameworkInterface instance, final String targetClass) {
+ protected Object convertNullToEmpty (final Object str) {
// Trace message
- this.getLogger().debug(MessageFormat.format("instance={0},targetClass={1}", instance, targetClass)); //NOI18N
-
- // Instance reflaction of this class
- Class<? extends FrameworkInterface> c = instance.getClass();
-
- // Analyze class
- while (!targetClass.equals(c.getSimpleName())) {
- // Debug message
- this.getLogger().debug(MessageFormat.format("c={0}", c.getSimpleName())); //NOI18N
-
- // Get super class (causes unchecked warning)
- c = (Class<? extends FrameworkInterface>) c.getSuperclass();
+ this.getLogger().trace(MessageFormat.format("str={0}", str)); //NOI18N
+
+ // Is it null?
+ if (str == null) {
+ // Return empty string
+ return ""; //NOI18N
}
-
+
// Trace message
- this.getLogger().trace(MessageFormat.format("c={0} - EXIT!", c)); //NOI18N
-
+ this.getLogger().trace(MessageFormat.format("str={0} - EXIT!", str)); //NOI18N
+
// Return it
- return c;
+ return str;
}
/**
- * Some "getter" for a Method instance from given method name
+ * Creates an iterator from given instance and class name.
*
- * @param instance Actual instance to call
- * @param targetClass Target class name
- * @param methodName Method name
- * @return A Method instance
- */
- private Method getMethodFromName (final FrameworkInterface instance, final String targetClass, final String methodName) {
- // Trace messahe
- this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
-
- // Get target class instance
- Class<? extends FrameworkInterface> c = this.getClassFromTarget(instance, targetClass);
-
- // Init field instance
- Method method = null;
-
- // Use reflection to get all attributes
- try {
- method = c.getDeclaredMethod(methodName, new Class<?>[0]);
- } catch (final SecurityException ex) {
- // Security problem
- this.abortProgramWithException(ex);
- } catch (final NoSuchMethodException ex) {
- // Method not found
- this.abortProgramWithException(ex);
- }
-
- // Assert on field
- assert (method instanceof Method) : "method is not a Method instance"; //NOI18N
-
+ * @param instance Instance to run getter calls on
+ * @param className Class name to iterate over
+ * @return An iterator over all object's fields
+ * @throws java.lang.NoSuchMethodException If the called method does not exist
+ * @throws java.lang.IllegalAccessException If the method cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Any other problems?
+ */
+ protected Iterator<Map.Entry<Field, Object>> fieldIterator (final FrameworkInterface instance, final String className) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("method={0} - EXIT!", method)); //NOI18N
-
- // Return it
- return method;
- }
+ this.getLogger().trace(MessageFormat.format("instance={0},className={1} - CALLED!", instance, className)); //NOI18N
- /**
- * Aborts program with given exception
- *
- * @param throwable Any type of Throwable
- */
- protected final void abortProgramWithException (final Throwable throwable) {
- // Log exception ...
- this.getLogger().catching(throwable);
-
- // .. and exit
- System.exit(1);
-
- }
+ // Get all attributes from given instance
+ Field[] fields = this.getClassFromTarget(instance, className).getDeclaredFields();
- /**
- * Getter for bundle instance
- *
- * @return Resource bundle
- */
- protected final ResourceBundle getBundle () {
- return this.bundle;
- }
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Found {0} fields.", fields.length)); //NOI18N
- /**
- * Manager instance
- *
- * @param manager the manager instance to set
- */
- protected final void setContactManager (final Manageable manager) {
- this.manager = manager;
- }
+ // A simple map with K=fieldName and V=Value is fine
+ Map<Field, Object> map = new HashMap<>(fields.length);
- /**
- * Returns any field value from given method call
- *
- * @param instance The instance to call
- * @param targetClass Target class to look in
- * @param methodName Method name to look for
- * @return Any value from field
- */
- protected Object getField (final FrameworkInterface instance, final String targetClass, final String methodName) {
- // Trace messahe
- this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
+ // Walk through all
+ for (final Field field : fields) {
+ // Debug log
+ this.getLogger().debug(MessageFormat.format("field={0}", field.getName())); //NOI18N
- // Get method to call
- Method method = this.getMethodFromName(instance, targetClass, methodName);
+ // Does the field start with "$"?
+ if (field.getName().startsWith("$")) { //NOI18N
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Skipping field={0} as it starts with a dollar character.", field.getName())); //NOI18N
- // Get value from field
- Object object = null;
+ // Skip it silently
+ continue;
+ }
- try {
- object = method.invoke(instance);
- } catch (final IllegalArgumentException ex) {
- // Other problem
- this.abortProgramWithException(ex);
- } catch (final IllegalAccessException ex) {
- // Other problem
- this.abortProgramWithException(ex);
- } catch (final InvocationTargetException ex) {
- // Other problem
- this.abortProgramWithException(ex);
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Calling getValueFromColumn({0}) on instance {1} ...", field.getName(), instance)); //NOI18N
+
+ // Get value from it
+ Object value = instance.getValueFromColumn(field.getName());
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Adding field={0},value={1}", field.getName(), value)); //NOI18N
+
+ // Add it to list
+ map.put(field, value);
}
- // Return value
- return object;
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Returning iterator for {0} entries ...", map.size())); //NOI18N
+
+ // Return list iterator
+ return map.entrySet().iterator();
}
/**
- * Getter for property which must exist
+ * Instance for database backend
*
- * @param key Key to get
- * @return Propety value
+ * @return the backend
*/
- protected final String getProperty (final String key) {
- return BaseFrameworkSystem.properties.getProperty(String.format("org.mxchange.addressbook.%s", key)); //NOI18N
+ protected final DatabaseBackend getBackend () {
+ return this.backend;
}
/**
- * Name of used database table, handled over to backend
+ * Instance for database backend
*
- * @return the tableName
+ * @param backend the backend to set
*/
- protected final String getTableName () {
- return this.tableName;
+ protected final void setBackend (final DatabaseBackend backend) {
+ this.backend = backend;
}
/**
- * Name of used database table, handled over to backend
+ * Getter for Contact instance
*
- * @param tableName the tableName to set
+ * @return Contact instance
*/
- protected final void setTableName (final String tableName) {
- this.tableName = tableName;
+ protected final Contact getContact () {
+ return this.contact;
+ }
+
+ /**
+ * Setter for Contact instance
+ *
+ * @param contact A Contact instance
+ */
+ protected final void setContact (final Contact contact) {
+ this.contact = contact;
}
/**
*
* @return DatabaseFrontend instance
*/
- protected DatabaseFrontend getWrapper () {
+ protected final DatabaseFrontend getFrontend () {
return this.wrapper;
}
*
* @param wrapper A DatabaseFrontend instance
*/
- protected void setWrapper (final DatabaseFrontend wrapper) {
+ protected final void setFrontend (final DatabaseFrontend wrapper) {
this.wrapper = wrapper;
}
+ /**
+ * Initializes i18n bundles
+ */
+ protected void initBundle () {
+ // Trace message
+ this.getLogger().trace("CALLED!");
+
+ // Is the bundle set?
+ if (bundle instanceof ResourceBundle) {
+ // Is already set
+ throw new IllegalStateException("called twice"); //NOI18N
+ }
+
+ // Set instance
+ bundle = ResourceBundle.getBundle(FrameworkInterface.I18N_BUNDLE_FILE); // NOI18N
+
+ // Trace message
+ this.getLogger().trace("EXIT!");
+ }
+
+ /**
+ * Prepares all properties, the file is written if it is not found
+ *
+ * @throws java.io.IOException If any IO problem occurs
+ */
+ protected void initProperties () throws IOException {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("{0} properties are loaded already.", BaseFrameworkSystem.properties.size())); //NOI18N
+
+ // Are some properties loaded?
+ if (!BaseFrameworkSystem.properties.isEmpty()) {
+ // Some are already loaded, abort here
+ return;
+ }
+
+ try {
+ // Try to read it
+ BaseFrameworkSystem.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("{0} properties has been loaded.", BaseFrameworkSystem.properties.size())); //NOI18N
+ } catch (final FileNotFoundException ex) {
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Properties file {0} not found: {1}", FrameworkInterface.PROPERTIES_CONFIG_FILE, ex)); //NOI18N
+
+ /*
+ * The file is not found which is normal for first run, so
+ * initialize default values.
+ */
+ this.initPropertiesWithDefault();
+
+ // Write file
+ this.writePropertiesFile();
+ }
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
/**
* Checks whether the given field is a boolean field by probing it.
- *
+ *
* @param instance Instance to call
* @param targetClass Target class
* @param columnName Column name to check
// Not found
isBool = false;
- } catch (final SecurityException ex) {
- // Really bad?
- this.abortProgramWithException(ex);
}
// Trace message
// Return result
return isBool;
}
+
+ /**
+ * Sets value in properties instance.
+ *
+ * @param key Property key (part) to set
+ * @param value Property value to set
+ */
+ protected void setProperty (final String key, final String value) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N
+
+ // Both should not be null
+ if (key == null) {
+ // key is null
+ throw new NullPointerException("key is null");
+ } else if (value == null) {
+ // value is null
+ throw new NullPointerException("value is null");
+ }
+
+ // Set it
+ properties.setProperty(String.format("org.mxchange.%s", key), value); //NOI18N
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
+ /**
+ * Some getter for properties names (without org.mxchange)
+ *
+ * @return An array with property names
+ */
+ protected String[] getPropertyNames () {
+ // Init array
+ String[] names = {
+ "database.backend.class", //NOI18N
+ "database.backend.storagepath", //NOI18N
+ "database.mysql.login", //NOI18N
+ "database.mysql.host", //NOI18N
+ "database.mysql.password", //NOI18N
+ "database.mysql.dbname", //NOI18N
+ };
+
+ // Return it
+ return names;
+ }
}