From: Roland Haeder Date: Fri, 4 Sep 2015 18:44:19 +0000 (+0200) Subject: Cleanup from unused methods (TDGP -> EJB) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a7f1b1006eb3a7109f1d46340af50a6be8622361;p=jcore.git Cleanup from unused methods (TDGP -> EJB) Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index 81f93c9..0e32cb5 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -16,8 +16,6 @@ */ package org.mxchange.jcore; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.text.MessageFormat; import java.util.Arrays; import java.util.ResourceBundle; @@ -71,11 +69,6 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ private Manageable manager; - /** - * Name of used database table, handled over to backend - */ - private String tableName; - /** * Initialize object */ @@ -124,124 +117,6 @@ public class BaseFrameworkSystem implements FrameworkInterface { return this.getBundle().getString(key); } - /** - * 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 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 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) 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 - - // Init method instance - Method method = null; - - // Try it from target class - try { - // Get target class instance - Class c = this.getClassFromTarget(instance, targetClass); - - // Init field instance - method = c.getDeclaredMethod(methodName, new Class[0]); - } catch (final NoSuchMethodException e) { - // Didn't found it - this.getLogger().debug(e); - - // So try it from super class - Class c = this.getClassFromTarget(instance, "BaseFrameworkSystem"); //NOI18N - - // Init field instance - 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; - } - - /** - * 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 - * @param type Type reflection to check type from - * @return A Method instance - */ - private Method getMethodFromName (final FrameworkInterface instance, final String targetClass, final String methodName, final Class type) throws NoSuchMethodException { - // Trace messahe - this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1},type={2}", targetClass, methodName, type)); //NOI18N - - // Init method instance - Method method = null; - - // Try it from target class - try { - // Get target class instance - Class c = this.getClassFromTarget(instance, targetClass); - - // Init field instance - method = c.getDeclaredMethod(methodName, type); - } catch (final NoSuchMethodException e) { - // Didn't found it - this.getLogger().debug(e); - - // So try it from super class - Class c = this.getClassFromTarget(instance, "BaseFrameworkSystem"); //NOI18N - - // Init field instance - method = c.getDeclaredMethod(methodName, type); - } - - // 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; - } - /** * Aborts program with given exception * @@ -296,174 +171,19 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.client = client; } - /** - * Name of used database table, handled over to backend - * - * @return the tableName - */ - public final String getTableName () { - return this.tableName; - } - - @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 - } - @Override public final void logException (final Throwable exception) { // Log this exception this.getLogger().catching(exception); } - /** - * Converts a column name like "foo_bar" to an attribute name like "fooBar" - * - * @param columnName Column name to convert - * @return Attribute name - */ - protected String convertColumnNameToFieldName (final String columnName) { - // Trace message - this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); //NOI18N - - // Split on "_" - StringTokenizer tokenizer = new StringTokenizer(columnName, "_"); //NOI18N - - // Resulting string - StringBuilder builder = new StringBuilder(tokenizer.countTokens()); - - // Init counter - int count = 0; - - // Walk through all - while (tokenizer.hasMoreTokens()) { - // Get token - String token = tokenizer.nextToken(); - - // Is later than first element? - if (count > 0) { - // Make first character upper-case - char c = token.charAt(0); - token = String.valueOf(c).toUpperCase() + token.substring(1); - } - - // Add token - builder.append(token); - - // Increment counter - count++; - } - - // Trace message - this.getLogger().trace(MessageFormat.format("builder={0} - EXIT!", builder)); //NOI18N - - // Return result - return builder.toString(); - } - - /** - * Converts a column name like "foo_bar" to a method name like "getFooBar" - * for non-booleans and to "isFooBar" for boolean fields. - * - * @param columnName Column name to convert - * @param isBool Whether the parameter is boolean - * @return Attribute name - */ - protected String convertColumnNameToGetterMethod (final String columnName, boolean isBool) { - // Trace message - this.getLogger().trace(MessageFormat.format("columnName={0},isBool={1} - CALLED!", columnName, isBool)); //NOI18N - - // Then split on "_" - StringTokenizer tokenizer = new StringTokenizer(columnName, "_"); //NOI18N - - // Resulting string - StringBuilder builder = new StringBuilder(tokenizer.countTokens()); - - // Is it boolean? - if (isBool) { - // Append "is" - builder.append("is"); //NOI18N - } else { - // Append "get" - builder.append("get"); //NOI18N - } - - // Walk through all - while (tokenizer.hasMoreTokens()) { - // Get token - String token = tokenizer.nextToken(); - - // Debug message - this.getLogger().debug(MessageFormat.format("token={0}", token)); //NOI18N - - // Make it upper-case - char c = token.charAt(0); - token = String.valueOf(c).toUpperCase() + token.substring(1); - - // Add token - builder.append(token); - } - - // Trace message - this.getLogger().trace(MessageFormat.format("builder={0} - EXIT!", builder)); //NOI18N - - // Return result - return builder.toString(); - } - - /** - * Converts a column name like "foo_bar" to a method name like "getFooBar" - * for non-booleans and to "isFooBar" for boolean fields. - * - * @param columnName Column name to convert - * @return Attribute name - */ - protected String convertColumnNameToSetterMethod (final String columnName) { - // Trace message - this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); //NOI18N - - // Then split on "_" - StringTokenizer tokenizer = new StringTokenizer(columnName, "_"); //NOI18N - - // Resulting string - StringBuilder builder = new StringBuilder(tokenizer.countTokens()); - - // Append "set" - builder.append("set"); //NOI18N - - // Walk through all - while (tokenizer.hasMoreTokens()) { - // Get token - String token = tokenizer.nextToken(); - - // Debug message - this.getLogger().debug(MessageFormat.format("token={0} - BEFORE", token)); //NOI18N - - // Make it upper-case - char c = token.charAt(0); - token = String.valueOf(c).toUpperCase() + token.substring(1); - - // Debug message - this.getLogger().debug(MessageFormat.format("token={0} - AFTER", token)); //NOI18N - - // Add token - builder.append(token); - } - - // Trace message - this.getLogger().trace(MessageFormat.format("builder={0} - EXIT!", builder)); //NOI18N - - // Return result - return builder.toString(); - } - /** * Some "getter" for an array from given string and tokenizer * * @param str String to tokenize and get array from * @param delimiter Delimiter * @return Array from tokenized string TODO Get rid of size parameter + * TODO: Move to own utility class */ protected String[] getArrayFromString (final String str, final String delimiter) { // Trace message @@ -496,31 +216,27 @@ public class BaseFrameworkSystem implements FrameworkInterface { } /** - * Returns boolean field value from given method name by invoking it + * Converts null to empty string or leaves original object untouched. * - * @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? + * @param object Any string + * @return Empty string if null or original string + * TODO: Move to own utility class */ - 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 method instance - Method method = this.getMethodFromName(instance, targetClass, methodName); + protected Object convertNullToEmpty (final Object object) { + // Trace message + this.getLogger().trace(MessageFormat.format("object={0}", object)); //NOI18N - // Get value from field - Boolean value = (Boolean) method.invoke(instance); + // Is it null? + if (null == object) { + // Return empty string + return ""; //NOI18N + } // Trace message - this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N + this.getLogger().trace(MessageFormat.format("object={0} - EXIT!", object)); //NOI18N - // Return value - return value; + // Return it + return object; } /** @@ -528,73 +244,10 @@ public class BaseFrameworkSystem implements FrameworkInterface { * * @param manager the manager instance to set */ - protected final void setContactManager (final Manageable manager) { + protected final void setManager (final Manageable manager) { this.manager = manager; } - /** - * Returns any 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 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 Object getField (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - // Trace messahe - this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},methodName={2}", instance, targetClass, methodName)); //NOI18N - - // Get method to call - Method method = this.getMethodFromName(instance, targetClass, methodName); - - // Debug message - this.getLogger().debug(MessageFormat.format("method={0},instance={1}", method, instance)); //NOI18N - - // Get value from field - Object value = method.invoke(instance); - - // Trace messahe - this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N - - // Return value - return value; - } - - /** - * 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; - } - - /** - * Converts null to empty string or leaves original string. - * - * @param str Any string - * @return Empty string if null or original string - */ - protected Object convertNullToEmpty (final Object str) { - // Trace message - this.getLogger().trace(MessageFormat.format("str={0}", str)); //NOI18N - - // Is it null? - if (null == str) { - // Return empty string - return ""; //NOI18N - } - - // Trace message - this.getLogger().trace(MessageFormat.format("str={0} - EXIT!", str)); //NOI18N - - // Return it - return str; - } - /** * Getter for Contact instance * @@ -621,7 +274,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().trace("CALLED!"); //NOI18N // Is the bundle set? - if (isBundledInitialized()) { + if (BaseFrameworkSystem.isBundledInitialized()) { // Is already set throw new IllegalStateException("called twice"); //NOI18N } diff --git a/src/org/mxchange/jcore/FrameworkInterface.java b/src/org/mxchange/jcore/FrameworkInterface.java index 03dd111..69f99d8 100644 --- a/src/org/mxchange/jcore/FrameworkInterface.java +++ b/src/org/mxchange/jcore/FrameworkInterface.java @@ -16,7 +16,6 @@ */ package org.mxchange.jcore; -import java.lang.reflect.InvocationTargetException; import org.apache.logging.log4j.Logger; import org.mxchange.jcore.application.Application; import org.mxchange.jcore.client.Client; @@ -75,16 +74,4 @@ public interface FrameworkInterface { * @param exception Exception to log */ public void logException (final Throwable exception); - - /** - * 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 java.lang.NoSuchMethodException If called method was not found - * @throws java.lang.IllegalAccessException If the method cannot be accessed - * @throws java.lang.reflect.InvocationTargetException Any other problems? - */ - public boolean isFieldValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException; }