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