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