- * 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) 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);
-
- // Get value from field
- Boolean value = (Boolean) method.invoke(instance);
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
-
- // Return value
- 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
- *
- * @param manager the manager instance to set
- */
- protected final void setContactManager (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;
- }
-
- /**
- * 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;
-
- // 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}]={1}", object.getClass().getSimpleName(), 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
- }
-
- /**
- * 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
- }
-
- /**
- * 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 (str == null) {
- // Return empty string
- return ""; //NOI18N
- }
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("str={0} - EXIT!", str)); //NOI18N
-
- // Return it
- return str;
- }
-
- /**
- * Creates an iterator from given instance and class name.
- *
- * @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?