private Contact contact;
/**
- * Manager instance
+ * DatabaseFrontend instance
*/
- private Manageable manager;
+ private DatabaseFrontend frontend;
/**
- * Name of used database table, handled over to backend
+ * Manager instance
*/
- private String tableName;
+ private Manageable manager;
/**
- * DatabaseFrontend instance
+ * Session id assigned with this basket, or any other unique identifier
*/
- private DatabaseFrontend frontend;
+ private String sessionId;
/**
- * Session id assigned with this basket, or any other unique identifier
+ * Name of used database table, handled over to backend
*/
- private String sessionId;
+ private String tableName;
/**
* Initialize object
*/
{
- LOG = LogManager.getLogger(this);
+ // Init logger
+ this.LOG = LogManager.getLogger(this);
+
+ // Need to set it here
+ selfInstance = this;
}
/**
* No instances can be created of this class
*/
protected BaseFrameworkSystem () {
- // Set own instance
- this.setSelfInstance();
}
/**
return selfInstance;
}
- /**
- * Application instance
- *
- * @return the application
- */
@Override
public final Application getApplication () {
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
* @param targetClass Class name to look for
* @return Class instance
*/
- @SuppressWarnings("unchecked")
+ @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
// Trace messahe
this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
-
// Init method instance
Method method = null;
return method;
}
- /**
- * Setter for self instance
- */
- private void setSelfInstance () {
- // Need to set it here
- selfInstance = this;
- }
-
/**
* Aborts program with given exception
*
this.application = application;
}
- /**
- * Client instance
- *
- * @return the client
- */
@Override
public final Client getClient () {
return this.client;
this.client = client;
}
+ /**
+ * Getter for session id
+ *
+ * @return Session id
+ */
+ @Override
+ public final String getSessionId () {
+ return this.sessionId;
+ }
+
+ /**
+ * Setter for session id
+ *
+ * @param sessionId Session id
+ */
+ @Override
+ public final void setSessionId (final String sessionId) {
+ this.sessionId = sessionId;
+ }
+
/**
* Name of used database table, handled over to backend
*
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 isFieldValueEqual (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
}
- /**
- * Log exception
- *
- * @param exception Exception to log
- */
@Override
public final void logException (final Throwable exception) {
// Log this exception
*
* @param str String to tokenize and get array from
* @param delimiter Delimiter
- * @return Array from tokenized string
- * TODO Get rid of size parameter
+ * @return Array from tokenized string TODO Get rid of size parameter
*/
protected String[] getArrayFromString (final String str, final String delimiter) {
// Trace message
return value;
}
- /**
- * Sets boolean field value with 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
- * @param columnName Column name
- * @param value 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 void setBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName, final String columnName, final Boolean value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- // Trace messahe
- this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
-
- // Get field type
- Class<?> type = this.getType(instance, targetClass, columnName);
-
- // Get method instance
- Method method = this.getMethodFromName(instance, targetClass, methodName, type);
-
- // Try to get the value by invoking the method
- method.invoke(instance, value);
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
/**
* Manager instance
*
}
/**
- * Sets any field value with given method name by invoking it
+ * Getter for property which must exist
*
- * @param instance The instance to call
- * @param targetClass Target class to look in
- * @param methodName Method name to look for
+ * @param key Key to get
+ * @return Propety value
+ */
+ protected final String getProperty (final String key) {
+ return BaseFrameworkSystem.properties.getProperty(String.format("org.mxchange.%s", key)); //NOI18N
+ }
+
+ /**
+ * Name of used database table, handled over to backend
+ *
+ * @param tableName the tableName to set
+ */
+ protected final void setTableName (final String tableName) {
+ this.tableName = tableName;
+ }
+
+ /**
+ * Some getter for type reflection of given column name
+ *
+ * @param instance The instance to check
+ * @param targetClass Target class to check
* @param columnName Column name
- * @param value 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?
+ * @return Type reflection of value
*/
- protected void setField (final FrameworkInterface instance, final String targetClass, final String methodName, final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- // Trace messahe
- this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},methodName={2},value={3}", instance, targetClass, methodName, value)); //NOI18N
+ private Class<?> getType (final FrameworkInterface instance, final String targetClass, final String columnName) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N
- // Get field type
- Class<?> type = this.getType(instance, targetClass, columnName);
+ // Init field tye
+ Class<?> type = null;
+
+ // Get super class fields
+ Field[] superFields = this.getClassFromTarget(instance, "BaseFrameworkSystem").getDeclaredFields(); //NOI18N
+
+ // Get all attributes from given instance
+ Field[] fields = ArrayUtils.addAll(superFields, this.getClassFromTarget(instance, targetClass).getDeclaredFields());
// Debug message
- this.getLogger().debug(MessageFormat.format("type={0}", type)); //NOI18N
+ this.getLogger().debug(MessageFormat.format("fields()={0}", fields.length)); //NOI18N
- // Init object
- Object object = value;
+ // Convert column_name to fieldName ;-)
+ String fieldName = this.convertColumnNameToFieldName(columnName);
- // Is the value null?
- if ("null".equals(value)) { //NOI18N
- // Warning message
- this.getLogger().warn(MessageFormat.format("columnName={0} has null value.", columnName)); //NOI18N
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("fieldName={0}", fieldName)); //NOI18N
- // Set null
- object = null;
- } else {
- // Hard-coded "cast" again ... :-(
- // TODO Can't we get rid of this???
- switch (type.getSimpleName()) {
- case "Long": // Long object //NOI18N
- object = Long.parseLong((String) value);
- break;
+ // Search for proper field instance
+ for (final Field field : fields) {
+ // Is a dollar character there?
+ if (field.getName().startsWith("$")) { //NOI18N
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Field name {0} starts with a dollar, skipped.", field.getName())); //NOI18N
+ // Skip this
+ continue;
+ }
- case "Float": // Float object //NOI18N
- object = Float.parseFloat((String) value);
- break;
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("field.getName()={0},fieldName={1}", field.getName(), fieldName)); //NOI18N
- case "Boolean": // Boolean object //NOI18N
- object = Boolean.parseBoolean((String) value);
- break;
+ // Does it match?
+ if (field.getName().equals(fieldName)) {
+ // Found it
+ type = field.getType();
- case "String": // String object //NOI18N
- break;
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Found fieldName={0}: setting type={1}", fieldName, type.getSimpleName())); //NOI18N
- default: // Unsupported type
- throw new IllegalArgumentException(MessageFormat.format("value {0} has unsupported type {1}", value, type.getSimpleName())); //NOI18N
+ // Don't continue with searching
+ break;
}
}
// Debug message
- this.getLogger().debug(MessageFormat.format("object={0}", object)); //NOI18N
-
- // Get method to call
- Method method = this.getMethodFromName(instance, targetClass, methodName, type);
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("method={0},instance={1},value[{2}]={3}", method, instance, value.getClass().getSimpleName(), value)); //NOI18N
-
- // Get value from field
- method.invoke(instance, object);
+ this.getLogger().debug(MessageFormat.format("type={0}", type)); //NOI18N
- // Trace messahe
- this.getLogger().trace("EXIT!"); //NOI18N
- }
+ // type should not be null
+ if (null == type) {
+ // No null allowed
+ throw new NullPointerException("type is null"); //NOI18N
+ }
- /**
- * Getter for property which must exist
- *
- * @param key Key to get
- * @return Propety value
- */
- protected final String getProperty (final String key) {
- return BaseFrameworkSystem.properties.getProperty(String.format("org.mxchange.%s", key)); //NOI18N
- }
+ // Trace message
+ this.getLogger().debug(MessageFormat.format("type={0} - EXIT!", type)); //NOI18N
- /**
- * Name of used database table, handled over to backend
- *
- * @param tableName the tableName to set
- */
- protected final void setTableName (final String tableName) {
- this.tableName = tableName;
+ // Return it
+ return type;
}
/**
* @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.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?
*/
}
/**
- * Setter for session id
+ * Some getter for properties names (without org.mxchange)
*
- * @param sessionId Session id
+ * @return An array with property names
*/
- @Override
- public final void setSessionId (final String sessionId) {
- this.sessionId = sessionId;
- }
+ 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
+ };
- /**
- * Getter for session id
- *
- * @return Session id
- */
- @Override
- public final String getSessionId () {
- return this.sessionId;
+ // Return it
+ return names;
}
/**
- * Checks if the bundle is initialized
+ * Some "getter" for a value from given Storable instance and target class
*
- * @return Whether the bundle has been initialized
+ * @param instance An instance of a Storable class
+ * @param targetClass The target class (where the field resides)
+ * @param columnName Column name (= field name)
+ * @return value Value to get
+ * @throws java.lang.NoSuchMethodException If the getter was not found
+ * @throws java.lang.IllegalAccessException If the getter cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Some other problems?
*/
- protected boolean isBundledInitialized () {
- // Check it
- return (bundle instanceof ResourceBundle);
+ protected Object getValueInStorableFromColumn (final Storable instance, final String targetClass, final String columnName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N
+
+ // A '$' means not our field
+ if (columnName.startsWith("$")) { //NOI18N
+ // Don't handle these
+ throw new IllegalArgumentException("columnsName contains $"); //NOI18N
+ }
+
+ // Determine if the given column is boolean
+ if (this.isBooleanField(instance, targetClass, columnName)) {
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N
+
+ // Yes, then call other method
+ return this.getBooleanField(instance, targetClass, this.convertColumnNameToGetterMethod(columnName, true));
+ }
+
+ // Convert column name to field name
+ String methodName = this.convertColumnNameToGetterMethod(columnName, false);
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("methodName={0}", methodName)); //NOI18N
+
+ // Get field
+ Object value = this.getField(instance, targetClass, methodName);
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
+
+ // Return value
+ return value;
}
/**
return isBool;
}
+ /**
+ * Checks if the bundle is initialized
+ *
+ * @return Whether the bundle has been initialized
+ */
+ protected boolean isBundledInitialized () {
+ // Check it
+ return (bundle instanceof ResourceBundle);
+ }
+
+ /**
+ * Sets boolean field value with 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
+ * @param columnName Column name
+ * @param value 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 void setBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName, final String columnName, final Boolean value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ // Trace messahe
+ this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
+
+ // Get field type
+ Class<?> type = this.getType(instance, targetClass, columnName);
+
+ // Get method instance
+ Method method = this.getMethodFromName(instance, targetClass, methodName, type);
+
+ // Try to get the value by invoking the method
+ method.invoke(instance, value);
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
+ /**
+ * Sets any field value with 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
+ * @param columnName Column name
+ * @param value 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 void setField (final FrameworkInterface instance, final String targetClass, final String methodName, final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ // Trace messahe
+ this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},methodName={2},value={3}", instance, targetClass, methodName, value)); //NOI18N
+
+ // Get field type
+ Class<?> type = this.getType(instance, targetClass, columnName);
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("type={0}", type)); //NOI18N
+
+ // Init object
+ Object object = value;
+
+ // Is the value null?
+ if ("null".equals(value)) { //NOI18N
+ // Warning message
+ this.getLogger().warn(MessageFormat.format("columnName={0} has null value.", columnName)); //NOI18N
+
+ // Set null
+ object = null;
+ } else {
+ // Hard-coded "cast" again ... :-(
+ // TODO Can't we get rid of this???
+ switch (type.getSimpleName()) {
+ case "Long": // Long object //NOI18N
+ object = Long.parseLong((String) value);
+ break;
+
+ case "Float": // Float object //NOI18N
+ object = Float.parseFloat((String) value);
+ break;
+
+ case "Boolean": // Boolean object //NOI18N
+ object = Boolean.parseBoolean((String) value);
+ break;
+
+ case "String": // String object //NOI18N
+ break;
+
+ default: // Unsupported type
+ throw new IllegalArgumentException(MessageFormat.format("value {0} has unsupported type {1}", value, type.getSimpleName())); //NOI18N
+ }
+ }
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("object={0}", object)); //NOI18N
+
+ // Get method to call
+ Method method = this.getMethodFromName(instance, targetClass, methodName, type);
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("method={0},instance={1},value[{2}]={3}", method, instance, value.getClass().getSimpleName(), value)); //NOI18N
+
+ // Get value from field
+ method.invoke(instance, object);
+
+ // Trace messahe
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
/**
* Sets value in properties instance.
*
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;
- }
-
/**
* Some "setter" for a value in given Storable instance and target class
- *
+ *
* @param instance An instance of a Storable class
* @param targetClass The target class (where the field resides)
* @param columnName Column name (= field name)
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
}
-
- /**
- * Some "getter" for a value from given Storable instance and target class
- *
- * @param instance An instance of a Storable class
- * @param targetClass The target class (where the field resides)
- * @param columnName Column name (= field name)
- * @return value Value to get
- * @throws java.lang.NoSuchMethodException If the getter was not found
- * @throws java.lang.IllegalAccessException If the getter cannot be accessed
- * @throws java.lang.reflect.InvocationTargetException Some other problems?
- */
- protected Object getValueInStorableFromColumn (final Storable instance, final String targetClass, final String columnName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- // Trace message
- this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N
-
- // A '$' means not our field
- if (columnName.startsWith("$")) { //NOI18N
- // Don't handle these
- throw new IllegalArgumentException("columnsName contains $"); //NOI18N
- }
-
- // Determine if the given column is boolean
- if (this.isBooleanField(instance, targetClass, columnName)) {
- // Debug message
- this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N
-
- // Yes, then call other method
- return this.getBooleanField(instance, targetClass, this.convertColumnNameToGetterMethod(columnName, true));
- }
-
- // Convert column name to field name
- String methodName = this.convertColumnNameToGetterMethod(columnName, false);
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("methodName={0}", methodName)); //NOI18N
-
- // Get field
- Object value = this.getField(instance, targetClass, methodName);
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
-
- // Return value
- return value;
- }
-
- /**
- * Some getter for type reflection of given column name
- *
- * @param instance The instance to check
- * @param targetClass Target class to check
- * @param columnName Column name
- * @return Type reflection of value
- */
- private Class<?> getType (final FrameworkInterface instance, final String targetClass, final String columnName) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N
-
- // Init field tye
- Class<?> type = null;
-
- // Get super class fields
- Field[] superFields = this.getClassFromTarget(instance, "BaseFrameworkSystem").getDeclaredFields(); //NOI18N
-
- // Get all attributes from given instance
- Field[] fields = ArrayUtils.addAll(superFields, this.getClassFromTarget(instance, targetClass).getDeclaredFields());
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("fields()={0}", fields.length)); //NOI18N
-
- // Convert column_name to fieldName ;-)
- String fieldName = this.convertColumnNameToFieldName(columnName);
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("fieldName={0}", fieldName)); //NOI18N
-
- // Search for proper field instance
- for (final Field field : fields) {
- // Is a dollar character there?
- if (field.getName().startsWith("$")) { //NOI18N
- // Debug message
- this.getLogger().debug(MessageFormat.format("Field name {0} starts with a dollar, skipped.", field.getName())); //NOI18N
- // Skip this
- continue;
- }
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("field.getName()={0},fieldName={1}", field.getName(), fieldName)); //NOI18N
-
- // Does it match?
- if (field.getName().equals(fieldName)) {
- // Found it
- type = field.getType();
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("Found fieldName={0}: setting type={1}", fieldName, type.getSimpleName())); //NOI18N
-
- // Don't continue with searching
- break;
- }
- }
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("type={0}", type)); //NOI18N
-
- // type should not be null
- if (null == type) {
- // No null allowed
- throw new NullPointerException("type is null"); //NOI18N
- }
-
- // Trace message
- this.getLogger().debug(MessageFormat.format("type={0} - EXIT!", type)); //NOI18N
-
- // Return it
- return type;
- }
}