]> git.mxchange.org Git - jcore.git/blob - src/org/mxchange/jcore/BaseFrameworkSystem.java
A lot changes on jcore:
[jcore.git] / src / org / mxchange / jcore / BaseFrameworkSystem.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcore;
18
19 import java.io.BufferedReader;
20 import java.io.FileInputStream;
21 import java.io.FileNotFoundException;
22 import java.io.IOException;
23 import java.io.InputStreamReader;
24 import java.io.PrintWriter;
25 import java.lang.reflect.Field;
26 import java.lang.reflect.InvocationTargetException;
27 import java.lang.reflect.Method;
28 import java.text.MessageFormat;
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.Iterator;
32 import java.util.Map;
33 import java.util.Properties;
34 import java.util.ResourceBundle;
35 import java.util.StringTokenizer;
36 import org.apache.logging.log4j.LogManager;
37 import org.apache.logging.log4j.Logger;
38 import org.mxchange.jcore.application.Application;
39 import org.mxchange.jcore.client.Client;
40 import org.mxchange.jcore.contact.Contact;
41 import org.mxchange.jcore.database.backend.DatabaseBackend;
42 import org.mxchange.jcore.database.frontend.DatabaseFrontend;
43 import org.mxchange.jcore.manager.Manageable;
44
45 /**
46  * General class
47  *
48  * @author Roland Haeder
49  */
50 public class BaseFrameworkSystem implements FrameworkInterface {
51
52         /**
53          * Bundle instance
54          */
55         private static ResourceBundle bundle;
56
57         /**
58          * Instance for own properties
59          */
60         private static final Properties properties = new Properties(System.getProperties());
61
62         /**
63          * Self instance
64          */
65         private static FrameworkInterface selfInstance;
66
67         /**
68          * Class' logger
69          */
70         private final Logger LOG;
71
72         /**
73          * Application instance
74          */
75         private Application application;
76
77         /**
78          * Instance for database backend
79          */
80         private DatabaseBackend backend;
81
82         /**
83          * Client instance
84          */
85         private Client client;
86
87         /**
88          * Contact instance
89          */
90         private Contact contact;
91
92         /**
93          * Manager instance
94          */
95         private Manageable manager;
96
97         /**
98          * Name of used database table, handled over to backend
99          */
100         private String tableName;
101
102         /**
103          * DatabaseFrontend instance
104          */
105         private DatabaseFrontend wrapper;
106
107         /**
108          * Initialize object
109          */
110         {
111                 LOG = LogManager.getLogger(this);
112         }
113
114         /**
115          * No instances can be created of this class
116          */
117         protected BaseFrameworkSystem () {
118                 // Set own instance
119                 this.setSelfInstance();
120         }
121
122         /**
123          * Getter for this application
124          *
125          * @return Instance from this application
126          */
127         public static final FrameworkInterface getInstance () {
128                 // Return it
129                 return selfInstance;
130         }
131
132         /**
133          * Application instance
134          *
135          * @return the application
136          */
137         @Override
138         public final Application getApplication () {
139                 return this.application;
140         }
141
142         /**
143          * Getter for logger
144          *
145          * @return Logger
146          */
147         @Override
148         public final Logger getLogger () {
149                 return this.LOG;
150         }
151
152         /**
153          * Manager instance
154          *
155          * @return the contactManager
156          */
157         @Override
158         public final Manageable getManager () {
159                 return this.manager;
160         }
161
162         /**
163          * Getter for human-readable string from given key
164          *
165          * @param key Key to return
166          * @return Human-readable message
167          */
168         @Override
169         public final String getMessageStringFromKey (final String key) {
170                 // Return message
171                 return this.getBundle().getString(key);
172         }
173
174         /**
175          * Some "getter for a value from given column name. This name will be
176          * translated into a method name and then this method is called.
177          *
178          * @param columnName Column name
179          * @return Value from field
180          * @throws IllegalArgumentException Some implementations may throw this.
181          * @throws NoSuchMethodException Some implementations may throw this.
182          * @throws java.lang.IllegalAccessException If the method cannot be accessed
183          * @throws java.lang.reflect.InvocationTargetException Any other problems?
184          */
185         @Override
186         public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
187                 throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0}", columnName)); //NOI18N
188         }
189
190         /**
191          * Some "getter" for target class instance from given name.
192          *
193          * @param instance Instance to iterate on
194          * @param targetClass Class name to look for
195          * @return Class instance
196          */
197         @SuppressWarnings("unchecked")
198         private Class<? extends FrameworkInterface> getClassFromTarget (final FrameworkInterface instance, final String targetClass) {
199                 // Trace message
200                 this.getLogger().debug(MessageFormat.format("instance={0},targetClass={1}", instance, targetClass)); //NOI18N
201
202                 // Instance reflaction of this class
203                 Class<? extends FrameworkInterface> c = instance.getClass();
204
205                 // Analyze class
206                 while (!targetClass.equals(c.getSimpleName())) {
207                         // Debug message
208                         this.getLogger().debug(MessageFormat.format("c={0}", c.getSimpleName())); //NOI18N
209
210                         // Get super class (causes unchecked warning)
211                         c = (Class<? extends FrameworkInterface>) c.getSuperclass();
212                 }
213
214                 // Trace message
215                 this.getLogger().trace(MessageFormat.format("c={0} - EXIT!", c)); //NOI18N
216
217                 // Return it
218                 return c;
219         }
220
221         /**
222          * Some "getter" for a Method instance from given method name
223          *
224          * @param instance Actual instance to call
225          * @param targetClass Target class name
226          * @param methodName Method name
227          * @return A Method instance
228          */
229         private Method getMethodFromName (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException {
230                 // Trace messahe
231                 this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
232
233                 // Get target class instance
234                 Class<? extends FrameworkInterface> c = this.getClassFromTarget(instance, targetClass);
235
236                 // Init field instance
237                 Method method = null;
238
239                 // Use reflection to get all attributes
240                 method = c.getDeclaredMethod(methodName, new Class<?>[0]);
241
242                 // Assert on field
243                 assert (method instanceof Method) : "method is not a Method instance"; //NOI18N
244
245                 // Trace message
246                 this.getLogger().trace(MessageFormat.format("method={0} - EXIT!", method)); //NOI18N
247
248                 // Return it
249                 return method;
250         }
251
252         /**
253          * Setter for self instance
254          */
255         private void setSelfInstance () {
256                 // Need to set it here
257                 selfInstance = this;
258         }
259
260         /**
261          * Aborts program with given exception
262          *
263          * @param throwable Any type of Throwable
264          */
265         protected final void abortProgramWithException (final Throwable throwable) {
266                 // Log exception ...
267                 this.getLogger().catching(throwable);
268
269                 // .. and exit
270                 System.exit(1);
271         }
272
273         /**
274          * Application instance
275          *
276          * @param application the application to set
277          */
278         protected final void setApplication (final Application application) {
279                 this.application = application;
280         }
281
282         /**
283          * Client instance
284          *
285          * @return the client
286          */
287         @Override
288         public final Client getClient () {
289                 return this.client;
290         }
291
292         /**
293          * Getter for bundle instance
294          *
295          * @return Resource bundle
296          */
297         protected final ResourceBundle getBundle () {
298                 return BaseFrameworkSystem.bundle;
299         }
300
301         /**
302          * Client instance
303          *
304          * @param client the client to set
305          */
306         protected final void setClient (final Client client) {
307                 this.client = client;
308         }
309
310         /**
311          * Name of used database table, handled over to backend
312          *
313          * @return the tableName
314          */
315         public final String getTableName () {
316                 return this.tableName;
317         }
318
319         /**
320          * Checks if given boolean field is available and set to same value
321          *
322          * @param columnName Column name to check
323          * @param bool Boolean value
324          * @return Whether all conditions are met
325          * @throws NoSuchMethodException May be thrown by some implementations
326          * @throws java.lang.IllegalAccessException If the method cannot be accessed
327          * @throws java.lang.reflect.InvocationTargetException Any other problems?
328          */
329         @Override
330         public boolean isValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
331                 // Not implemented
332                 throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0},bool={1}", columnName, bool)); //NOI18N
333         }
334
335         /**
336          * Log exception
337          *
338          * @param exception Exception to log
339          */
340         @Override
341         public final void logException (final Throwable exception) {
342                 // Log this exception
343                 this.getLogger().catching(exception);
344         }
345
346         /**
347          * Initializes properties with default values
348          */
349         private void initPropertiesWithDefault () {
350                 // Trace message
351                 this.getLogger().trace("CALLED!"); //NOI18N
352
353                 // Init default values:
354                 // Default database backend
355                 BaseFrameworkSystem.properties.put("org.mxchange.database.backend.class", "org.mxchange.jcore.database.backend.base64.Base64CsvDatabaseBackend"); //NOI18N
356                 BaseFrameworkSystem.properties.put("database.backend.storagepath", "data/"); //NOI18N
357
358                 // For MySQL backend
359                 BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.host", "localhost"); //NOI18N
360                 BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.dbname", "test"); //NOI18N
361                 BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.login", ""); //NOI18N
362                 BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.password", ""); //NOI18N
363
364                 // Trace message
365                 this.getLogger().trace("EXIT!"); //NOI18N
366         }
367
368         /**
369          * Writes the properties file to disk
370          */
371         private void writePropertiesFile () throws IOException {
372                 // Trace message
373                 this.getLogger().trace("CALLED!"); //NOI18N
374
375                 // Write it
376                 BaseFrameworkSystem.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
377
378                 // Trace message
379                 this.getLogger().trace("EXIT!"); //NOI18N
380         }
381
382         /**
383          * Converts a column name like "foo_bar" to an attribute name like "fooBar"
384          *
385          * @param columnName Column name to convert
386          * @return Attribute name
387          */
388         protected String convertColumnNameToAttribute (final String columnName) {
389                 // Trace message
390                 this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); //NOI18N
391
392                 // First all lower case
393                 String lower = columnName.toLowerCase();
394
395                 // Then split on "_"
396                 StringTokenizer tokenizer = new StringTokenizer(lower, "_"); //NOI18N
397
398                 // Resulting string
399                 StringBuilder builder = new StringBuilder(tokenizer.countTokens());
400
401                 // Init counter
402                 int count = 0;
403
404                 // Walk through all
405                 while (tokenizer.hasMoreTokens()) {
406                         // Get token
407                         String token = tokenizer.nextToken();
408
409                         // Is later than first element?
410                         if (count > 0) {
411                                 // Make first character upper-case
412                                 char c = token.charAt(0);
413                                 token = String.valueOf(c).toUpperCase() + token.substring(1);
414                         }
415
416                         // Add token
417                         builder.append(token);
418
419                         // Increment counter
420                         count++;
421                 }
422
423                 // Trace message
424                 this.getLogger().trace(MessageFormat.format("builder={0} - EXIT!", builder)); //NOI18N
425
426                 // Return result
427                 return builder.toString();
428         }
429
430         /**
431          * Converts a column name like "foo_bar" to a method name like "getFooBar"
432          * for non-booleans and to "isFooBar" for boolean fields.
433          *
434          * @param columnName Column name to convert
435          * @param isBool Whether the parameter is boolean
436          * @return Attribute name
437          */
438         protected String convertColumnNameToGetterMethod (final String columnName, boolean isBool) {
439                 // Trace message
440                 this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); //NOI18N
441
442                 // Then split on "_"
443                 StringTokenizer tokenizer = new StringTokenizer(columnName, "_"); //NOI18N
444
445                 // Resulting string
446                 StringBuilder builder = new StringBuilder(tokenizer.countTokens());
447
448                 // Is it boolean?
449                 if (isBool) {
450                         // Append "is"
451                         builder.append("is"); //NOI18N
452                 } else {
453                         // Append "get"
454                         builder.append("get"); //NOI18N
455                 }
456
457                 // Walk through all
458                 while (tokenizer.hasMoreTokens()) {
459                         // Get token
460                         String token = tokenizer.nextToken();
461
462                         // Debug message
463                         this.getLogger().debug(MessageFormat.format("token={0}", token)); //NOI18N
464
465                         // Make it upper-case
466                         char c = token.charAt(0);
467                         token = String.valueOf(c).toUpperCase() + token.substring(1);
468
469                         // Add token
470                         builder.append(token);
471                 }
472
473                 // Trace message
474                 this.getLogger().trace(MessageFormat.format("builder={0} - EXIT!", builder)); //NOI18N
475
476                 // Return result
477                 return builder.toString();
478         }
479
480         /**
481          * Some "getter" for an array from given string and tokenizer
482          *
483          * @param str String to tokenize and get array from
484          * @param delimiter Delimiter
485          * @param size Size of array
486          * @return Array from tokenized string
487          * @todo Get rid of size parameter
488          */
489         protected String[] getArrayFromString (final String str, final String delimiter, final int size) {
490                 // Trace message
491                 this.getLogger().trace(MessageFormat.format("str={0},delimiter={1},size={2} - CALLED!", str, delimiter, size)); //NOI18N
492
493                 // Get tokenizer
494                 StringTokenizer tokenizer = new StringTokenizer(str, delimiter);
495
496                 // Init array and index
497                 String[] tokens = new String[size];
498                 int index = 0;
499
500                 // Run through all tokens
501                 while (tokenizer.hasMoreTokens()) {
502                         // Get current token and add it
503                         tokens[index] = tokenizer.nextToken();
504
505                         // Debug message
506                         this.getLogger().debug(MessageFormat.format("Token at index{0}: {1}", index, tokens[1])); //NOI18N
507
508                         // Increment index
509                         index++;
510                 }
511
512                 // Trace message
513                 this.getLogger().trace(MessageFormat.format("tokens({0})={1} - EXIT!", tokens.length, Arrays.toString(tokens))); //NOI18N
514
515                 // Return it
516                 return tokens;
517         }
518
519         /**
520          * Returns boolean field value from given method name by invoking it
521          *
522          * @param instance The instance to call
523          * @param targetClass Target class to look in
524          * @param methodName Method name to look for
525          * @return Boolean value from field
526          * @throws java.lang.NoSuchMethodException If the method was not found
527          * @throws java.lang.IllegalAccessException If the method cannot be accessed
528          * @throws java.lang.reflect.InvocationTargetException Some other problems?
529          */
530         protected boolean getBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
531                 // Trace messahe
532                 this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
533
534                 // Get method instance
535                 Method method = this.getMethodFromName(instance, targetClass, methodName);
536
537                 // Get value from field
538                 Boolean value = false;
539
540                 // Try to get the value by invoking the method
541                 value = (Boolean) method.invoke(instance);
542
543                 // Return value
544                 return value;
545         }
546
547         /**
548          * Manager instance
549          *
550          * @param manager the manager instance to set
551          */
552         protected final void setContactManager (final Manageable manager) {
553                 this.manager = manager;
554         }
555
556         /**
557          * Returns any field value from given method name by invoking it
558          *
559          * @param instance The instance to call
560          * @param targetClass Target class to look in
561          * @param methodName Method name to look for
562          * @return Any value from field
563          * @throws java.lang.NoSuchMethodException If the method was not found
564          * @throws java.lang.IllegalAccessException If the method cannot be accessed
565          * @throws java.lang.reflect.InvocationTargetException Some other problems?
566          */
567         protected Object getField (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
568                 // Trace messahe
569                 this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
570
571                 // Get method to call
572                 Method method = this.getMethodFromName(instance, targetClass, methodName);
573
574                 // Get value from field
575                 Object object = method.invoke(instance);
576
577                 // Return value
578                 return object;
579         }
580
581         /**
582          * Getter for property which must exist
583          *
584          * @param key Key to get
585          * @return Propety value
586          */
587         protected final String getProperty (final String key) {
588                 return BaseFrameworkSystem.properties.getProperty(String.format("org.mxchange.%s", key)); //NOI18N
589         }
590
591         /**
592          * Name of used database table, handled over to backend
593          *
594          * @param tableName the tableName to set
595          */
596         protected final void setTableName (final String tableName) {
597                 this.tableName = tableName;
598         }
599
600         /**
601          * Converts null to empty string or leaves original string.
602          *
603          * @param str Any string
604          * @return Empty string if null or original string
605          */
606         protected Object convertNullToEmpty (final Object str) {
607                 // Trace message
608                 this.getLogger().trace(MessageFormat.format("str={0}", str)); //NOI18N
609
610                 // Is it null?
611                 if (str == null) {
612                         // Return empty string
613                         return ""; //NOI18N
614                 }
615
616                 // Trace message
617                 this.getLogger().trace(MessageFormat.format("str={0} - EXIT!", str)); //NOI18N
618
619                 // Return it
620                 return str;
621         }
622
623         /**
624          * Creates an iterator from given instance and class name.
625          *
626          * @param instance Instance to run getter calls on
627          * @param className Class name to iterate over
628          * @return An iterator over all object's fields
629          * @throws java.lang.NoSuchMethodException If the called method does not exist
630          * @throws java.lang.IllegalAccessException If the method cannot be accessed
631          * @throws java.lang.reflect.InvocationTargetException Any other problems?
632          */
633         protected Iterator<Map.Entry<Field, Object>> fieldIterator (final FrameworkInterface instance, final String className) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
634                 // Trace message
635                 this.getLogger().trace(MessageFormat.format("instance={0},className={1} - CALLED!", instance, className)); //NOI18N
636
637                 // Get all attributes from given instance
638                 Field[] fields = this.getClassFromTarget(instance, className).getDeclaredFields();
639
640                 // Debug message
641                 this.getLogger().debug(MessageFormat.format("Found {0} fields.", fields.length)); //NOI18N
642
643                 // A simple map with K=fieldName and V=Value is fine
644                 Map<Field, Object> map = new HashMap<>(fields.length);
645
646                 // Walk through all
647                 for (final Field field : fields) {
648                         // Debug log
649                         this.getLogger().debug(MessageFormat.format("field={0}", field.getName())); //NOI18N
650
651                         // Does the field start with "$"?
652                         if (field.getName().startsWith("$")) { //NOI18N
653                                 // Debug message
654                                 this.getLogger().debug(MessageFormat.format("Skipping field={0} as it starts with a dollar character.", field.getName())); //NOI18N
655
656                                 // Skip it silently
657                                 continue;
658                         }
659
660                         // Debug message
661                         this.getLogger().debug(MessageFormat.format("Calling getValueFromColumn({0}) on instance {1} ...", field.getName(), instance)); //NOI18N
662
663                         // Get value from it
664                         Object value = instance.getValueFromColumn(field.getName());
665
666                         // Debug message
667                         this.getLogger().debug(MessageFormat.format("Adding field={0},value={1}", field.getName(), value)); //NOI18N
668
669                         // Add it to list
670                         map.put(field, value);
671                 }
672
673                 // Debug message
674                 this.getLogger().debug(MessageFormat.format("Returning iterator for {0} entries ...", map.size())); //NOI18N
675
676                 // Return list iterator
677                 return map.entrySet().iterator();
678         }
679
680         /**
681          * Instance for database backend
682          *
683          * @return the backend
684          */
685         protected final DatabaseBackend getBackend () {
686                 return this.backend;
687         }
688
689         /**
690          * Instance for database backend
691          *
692          * @param backend the backend to set
693          */
694         protected final void setBackend (final DatabaseBackend backend) {
695                 this.backend = backend;
696         }
697
698         /**
699          * Getter for Contact instance
700          *
701          * @return Contact instance
702          */
703         protected final Contact getContact () {
704                 return this.contact;
705         }
706
707         /**
708          * Setter for Contact instance
709          *
710          * @param contact A Contact instance
711          */
712         protected final void setContact (final Contact contact) {
713                 this.contact = contact;
714         }
715
716         /**
717          * Getter for DatabaseFrontend instance
718          *
719          * @return DatabaseFrontend instance
720          */
721         protected final DatabaseFrontend getFrontend () {
722                 return this.wrapper;
723         }
724
725         /**
726          * Setter for wrapper instance
727          *
728          * @param wrapper A DatabaseFrontend instance
729          */
730         protected final void setFrontend (final DatabaseFrontend wrapper) {
731                 this.wrapper = wrapper;
732         }
733
734         /**
735          * Initializes i18n bundles
736          */
737         protected void initBundle () {
738                 // Trace message
739                 this.getLogger().trace("CALLED!");
740
741                 // Is the bundle set?
742                 if (bundle instanceof ResourceBundle) {
743                         // Is already set
744                         throw new IllegalStateException("called twice"); //NOI18N
745                 }
746
747                 // Set instance
748                 bundle = ResourceBundle.getBundle(FrameworkInterface.I18N_BUNDLE_FILE); // NOI18N
749
750                 // Trace message
751                 this.getLogger().trace("EXIT!");
752         }
753
754         /**
755          * Prepares all properties, the file is written if it is not found
756          *
757          * @throws java.io.IOException If any IO problem occurs
758          */
759         protected void initProperties () throws IOException {
760                 // Trace message
761                 this.getLogger().trace("CALLED!"); //NOI18N
762
763                 // Debug message
764                 this.getLogger().debug(MessageFormat.format("{0} properties are loaded already.", BaseFrameworkSystem.properties.size())); //NOI18N
765
766                 // Are some properties loaded?
767                 if (!BaseFrameworkSystem.properties.isEmpty()) {
768                         // Some are already loaded, abort here
769                         return;
770                 }
771
772                 try {
773                         // Try to read it
774                         BaseFrameworkSystem.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
775
776                         // Debug message
777                         this.getLogger().debug(MessageFormat.format("{0} properties has been loaded.", BaseFrameworkSystem.properties.size())); //NOI18N
778                 } catch (final FileNotFoundException ex) {
779                         // Debug message
780                         this.getLogger().debug(MessageFormat.format("Properties file {0} not found: {1}", FrameworkInterface.PROPERTIES_CONFIG_FILE, ex)); //NOI18N
781
782                         /*
783                          * The file is not found which is normal for first run, so
784                          * initialize default values.
785                          */
786                         this.initPropertiesWithDefault();
787
788                         // Write file
789                         this.writePropertiesFile();
790                 }
791
792                 // Trace message
793                 this.getLogger().trace("EXIT!"); //NOI18N
794         }
795
796         /**
797          * Checks whether the given field is a boolean field by probing it.
798          *
799          * @param instance Instance to call
800          * @param targetClass Target class
801          * @param columnName Column name to check
802          * @return Whether the given column name represents a boolean field
803          */
804         protected boolean isBooleanField (final FrameworkInterface instance, final String targetClass, final String columnName) {
805                 // Trace message
806                 this.getLogger().trace(MessageFormat.format("instance={0},targetCLass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N
807
808                 // Convert column name to getter name (boolean)
809                 String methodName = this.convertColumnNameToGetterMethod(columnName, true);
810
811                 // Get class instance
812                 Class<? extends FrameworkInterface> c = this.getClassFromTarget(instance, targetClass);
813
814                 // Defauzlt is boolean
815                 boolean isBool = true;
816
817                 try {
818                         // Now try to instance the method
819                         Method method = c.getDeclaredMethod(methodName, new Class<?>[0]);
820                 } catch (final NoSuchMethodException ex) {
821                         // Debug message
822                         this.getLogger().debug(MessageFormat.format("Method {0} does not exist, field {1} cannot be boolean: {2}", methodName, columnName, ex)); //NOI18N
823
824                         // Not found
825                         isBool = false;
826                 }
827
828                 // Trace message
829                 this.getLogger().trace(MessageFormat.format("isBool={0} - EXIT!", isBool)); //NOI18N
830
831                 // Return result
832                 return isBool;
833         }
834
835         /**
836          * Sets value in properties instance.
837          *
838          * @param key Property key (part) to set
839          * @param value Property value to set
840          */
841         protected void setProperty (final String key, final String value) {
842                 // Trace message
843                 this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N
844
845                 // Both should not be null
846                 if (key == null) {
847                         // key is null
848                         throw new NullPointerException("key is null");
849                 } else if (value == null) {
850                         // value is null
851                         throw new NullPointerException("value is null");
852                 }
853
854                 // Set it
855                 properties.setProperty(String.format("org.mxchange.%s", key), value); //NOI18N
856
857                 // Trace message
858                 this.getLogger().trace("EXIT!"); //NOI18N
859         }
860
861         /**
862          * Some getter for properties names (without org.mxchange)
863          *
864          * @return An array with property names
865          */
866         protected String[] getPropertyNames () {
867                 // Init array
868                 String[] names = {
869                         "database.backend.class", //NOI18N
870                         "database.backend.storagepath", //NOI18N
871                         "database.mysql.login", //NOI18N
872                         "database.mysql.host", //NOI18N
873                         "database.mysql.password", //NOI18N
874                         "database.mysql.dbname", //NOI18N
875                 };
876
877                 // Return it
878                 return names;
879         }
880 }