*/
package org.mxchange.jcore;
-import java.text.MessageFormat;
-import java.util.Arrays;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
import org.mxchange.jcore.application.Application;
import org.mxchange.jcore.client.Client;
-import org.mxchange.jcore.model.contact.Contact;
import org.mxchange.jcore.manager.Manageable;
+import org.mxchange.jcore.model.contact.Contact;
/**
* General class
- *
- * @author Roland Haeder
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
*/
-public class BaseFrameworkSystem implements FrameworkInterface {
+public abstract class BaseFrameworkSystem implements FrameworkInterface {
/**
* Bundle instance
*/
private static FrameworkInterface selfInstance;
- /**
- * Class' logger
- */
- private final Logger LOG;
-
/**
* Application instance
*/
* Initialize object
*/
{
- // Init logger
- this.LOG = LogManager.getLogger(this);
-
// Need to set it here
selfInstance = this;
}
/**
* Getter for this application
- *
+ * <p>
* @return Instance from this application
*/
- public static final FrameworkInterface getInstance () {
+ public static FrameworkInterface getInstance () {
// Return it
return selfInstance;
}
@Override
- public final Application getApplication () {
+ public Application getApplication () {
return this.application;
}
@Override
- public final Logger getLogger () {
- return this.LOG;
- }
-
- @Override
- public final Manageable getManager () {
- return this.manager;
- }
-
- @Override
- public final String getMessageStringFromKey (final String key) {
- // Return message
- return this.getBundle().getString(key);
- }
-
- /**
- * Aborts program with given exception
- *
- * @param throwable Any type of Throwable
- */
- protected final void abortProgramWithException (final Throwable throwable) {
- // Log exception ...
- this.logException(throwable);
-
- // .. and exit
- System.exit(1);
- }
-
- /**
- * Application instance
- *
- * @param application the application to set
- */
- protected final void setApplication (final Application application) {
- this.application = application;
- }
-
- @Override
- public final Client getClient () {
+ public Client getClient () {
return this.client;
}
/**
- * Getter for bundle instance
- *
- * @return Resource bundle
- */
- protected final ResourceBundle getBundle () {
- return BaseFrameworkSystem.bundle;
- }
-
- /**
- * Setter for bundle instance
- *
- * @param bundle the bundle to set
- */
- protected static void setBundle (final ResourceBundle bundle) {
- BaseFrameworkSystem.bundle = bundle;
- }
-
- /**
- * Client instance
- *
- * @param client the client to set
+ * Converts null to empty string or leaves original object untouched.
+ * <p>
+ * @param object Any string
+ * @return Empty string if null or original string TODO: Move to own utility
+ * class
*/
- protected final void setClient (final Client client) {
- this.client = client;
- }
+ protected Object convertNullToEmpty (final Object object) {
+ // Is it null?
+ if (null == object) {
+ // Return empty string
+ return ""; //NOI18N
+ }
- @Override
- public final void logException (final Throwable exception) {
- // Log this exception
- this.getLogger().catching(exception);
+ // Return it
+ return object;
}
/**
* Some "getter" for an array from given string and tokenizer
- *
+ * <p>
* @param str String to tokenize and get array from
* @param delimiter Delimiter
- * @return Array from tokenized string TODO Get rid of size parameter
- * TODO: Move to own utility class
+ * @return Array from tokenized string TODO Get rid of size parameter TODO:
+ * Move to own utility class
*/
protected String[] getArrayFromString (final String str, final String delimiter) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("str={0},delimiter={1} - CALLED!", str, delimiter)); //NOI18N
-
// Get tokenizer
StringTokenizer tokenizer = new StringTokenizer(str, delimiter);
// Get current token and add it
tokens[index] = tokenizer.nextToken();
- // Debug message
- this.getLogger().debug(MessageFormat.format("Token at index{0}: {1}", index, tokens[1])); //NOI18N
-
// Increment index
index++;
}
- // Trace message
- this.getLogger().trace(MessageFormat.format("tokens({0})={1} - EXIT!", tokens.length, Arrays.toString(tokens))); //NOI18N
-
// Return it
return tokens;
}
/**
- * Converts null to empty string or leaves original object untouched.
- *
- * @param object Any string
- * @return Empty string if null or original string
- * TODO: Move to own utility class
+ * Client instance
+ * <p>
+ * @param client the client to set
*/
- protected Object convertNullToEmpty (final Object object) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("object={0}", object)); //NOI18N
-
- // Is it null?
- if (null == object) {
- // Return empty string
- return ""; //NOI18N
- }
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("object={0} - EXIT!", object)); //NOI18N
-
- // Return it
- return object;
+ protected void setClient (final Client client) {
+ this.client = client;
}
/**
- * Manager instance
- *
- * @param manager the manager instance to set
+ * Application instance
+ * <p>
+ * @param application the application to set
*/
- protected final void setManager (final Manageable manager) {
- this.manager = manager;
+ protected void setApplication (final Application application) {
+ this.application = application;
+ }
+
+ @Override
+ public Manageable getManager () {
+ return this.manager;
}
/**
* Getter for Contact instance
- *
+ * <p>
* @return Contact instance
*/
- protected final Contact getContact () {
+ protected Contact getContact () {
return this.contact;
}
/**
* Setter for Contact instance
- *
+ * <p>
* @param contact A Contact instance
*/
- protected final void setContact (final Contact contact) {
+ protected void setContact (final Contact contact) {
this.contact = contact;
}
+ /**
+ * Manager instance
+ * <p>
+ * @param manager the manager instance to set
+ */
+ protected void setManager (final Manageable manager) {
+ this.manager = manager;
+ }
+
+ @Override
+ public String getMessageStringFromKey (final String key) {
+ // Return message
+ return this.getBundle().getString(key);
+ }
+
+ /**
+ * Getter for bundle instance
+ * <p>
+ * @return Resource bundle
+ */
+ protected ResourceBundle getBundle () {
+ return BaseFrameworkSystem.bundle;
+ }
+
+ /**
+ * Setter for bundle instance
+ * <p>
+ * @param bundle the bundle to set
+ */
+ protected static void setBundle (final ResourceBundle bundle) {
+ BaseFrameworkSystem.bundle = bundle;
+ }
+
/**
* Initializes i18n bundles
*/
protected void initBundle () {
- // Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
-
// Is the bundle set?
if (BaseFrameworkSystem.isBundledInitialized()) {
// Is already set
// Set instance
setBundle(ResourceBundle.getBundle(FrameworkInterface.I18N_BUNDLE_FILE)); // NOI18N
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
}
/**
* Checks if the bundle is initialized
- *
+ * <p>
* @return Whether the bundle has been initialized
*/
protected static boolean isBundledInitialized () {