From: Roland Haeder Date: Fri, 4 Sep 2015 12:51:33 +0000 (+0200) Subject: Preprared jcore for EJB applications: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=739f0e48fad7cd1ac56afb7beb1cad4516805a7d;p=jcore.git Preprared jcore for EJB applications: - moved Gender into own sub package - added utility class GenderUtils - removed session-related stuff as this was a bad idea anyway Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index 3beeadd..1a96607 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -101,11 +101,6 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ private Manageable manager; - /** - * Session id assigned with this basket, or any other unique identifier - */ - private String sessionId; - /** * Name of used database table, handled over to backend */ @@ -331,26 +326,6 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.client = client; } - /** - * Getter for session id - * - * @return Session id - */ - @Override - public final String getSessionId () { - return this.sessionId; - } - - /** - * Setter for session id - * - * @param sessionId Session id - */ - @Override - public final void setSessionId (final String sessionId) { - this.sessionId = sessionId; - } - /** * Name of used database table, handled over to backend * @@ -955,7 +930,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().trace("CALLED!"); //NOI18N // Is the bundle set? - if (this.isBundledInitialized()) { + if (isBundledInitialized()) { // Is already set throw new IllegalStateException("called twice"); //NOI18N } @@ -1053,7 +1028,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * * @return Whether the bundle has been initialized */ - protected boolean isBundledInitialized () { + protected static boolean isBundledInitialized () { // Check it return (bundle instanceof ResourceBundle); } diff --git a/src/org/mxchange/jcore/FrameworkInterface.java b/src/org/mxchange/jcore/FrameworkInterface.java index 222b09d..bf9b1e8 100644 --- a/src/org/mxchange/jcore/FrameworkInterface.java +++ b/src/org/mxchange/jcore/FrameworkInterface.java @@ -66,18 +66,6 @@ public interface FrameworkInterface { */ public Application getApplication (); - /** - * Session id - * @return the sessionId - */ - public String getSessionId (); - - /** - * Session id - * @param sessionId the sessionId to set - */ - public void setSessionId (final String sessionId); - /** * Getter for human-readable string from given key * diff --git a/src/org/mxchange/jcore/contact/BaseContact.java b/src/org/mxchange/jcore/contact/BaseContact.java index 297b486..61455d5 100644 --- a/src/org/mxchange/jcore/contact/BaseContact.java +++ b/src/org/mxchange/jcore/contact/BaseContact.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Objects; import org.mxchange.jcore.BaseFrameworkSystem; import org.mxchange.jcore.client.Client; +import org.mxchange.jcore.contact.gender.Gender; /** * A general contact class which should only be extended. diff --git a/src/org/mxchange/jcore/contact/Contact.java b/src/org/mxchange/jcore/contact/Contact.java index 2f2f92a..4ac21d8 100644 --- a/src/org/mxchange/jcore/contact/Contact.java +++ b/src/org/mxchange/jcore/contact/Contact.java @@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import java.util.Map; import org.mxchange.jcore.client.Client; +import org.mxchange.jcore.contact.gender.Gender; import org.mxchange.jcore.database.storage.Storable; /** diff --git a/src/org/mxchange/jcore/contact/Gender.java b/src/org/mxchange/jcore/contact/Gender.java deleted file mode 100644 index 322c31f..0000000 --- a/src/org/mxchange/jcore/contact/Gender.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcore.contact; - -import java.text.MessageFormat; - -/** - * Gender enum - * - * @author Roland Haeder - */ -public enum Gender { - /** - * Unknown enum - */ - UNKNOWN('U', "BaseContact.gender.unknown.text"), //NOI18N - - /** - * Male enum - */ - MALE('M', "BaseContact.gender.male.text"), //NOI18N - - /** - * Female enum - */ - FEMALE('F', "BaseContact.gender.female.text"), //NOI18N - - /** - * Company enum - */ - COMPANY('C', "BaseContact.gender.company.text"); //NOI18N - - /** - * Cache for valid chars - */ - private static char[] validChars; - - /** - * Access key being entered by ConsoleClient - */ - private final char accessChar; - - /** - * Output value (for messages) - */ - private final String messageKey; - - /** - * Getter for Gender enum from given character - * - * @param c Gender character - * @return Gender enum - */ - public static Gender fromChar (final char c) { - // Init variable - Gender g = null; - - // Loop through all - for (final Gender gender : Gender.values()) { - // Does the char match? - if (c == gender.getAccessChar()) { - // Found it - g = gender; - break; - } - } - - // Still null? - if (null == g) { - // Didn't found a valid one - throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N - } - - // Return it - //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName()); - return g; - } - - /** - * Valid chars - * - * @return Valid chars - */ - public static char[] validChars () { - // Is cache set? - if (validChars != null) { - // Return it - return validChars; - } - - // Init array, only 3 are valid as 'U' is UNKNOWN and is not valid. - char[] valid = new char[3]; - - // Get values - int i = 0; - for (Gender gender : values()) { - // Debug message - //* NOISY-DEBUG: */ System.out.println("gender=" + gender); - - // Is it UNKNOWN? - if (gender.equals(Gender.UNKNOWN)) { - // Skip this - continue; - } - - // Debug message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i)); - - // Get access key as this is also the access - valid[i] = gender.getAccessChar(); - - // Increment index - i++; - } - - // Set it here - validChars = valid; - - // Return finialized array - return valid; - } - - /** - * Constructor - * - * @param accessChar Value being entered by ConsoleClient - * @param messageKey Message key for resource file - */ - private Gender (final char accessChar, final String messageKey) { - // Set both - this.accessChar = accessChar; - this.messageKey = messageKey; - } - - /** - * Acces key (console client mostly) - * - * @return the accessChar - */ - public char getAccessChar () { - return this.accessChar; - } - - /** - * Output value (for messages) - * - * @return the messageKey - */ - public String getMessageKey () { - return this.messageKey; - } -} diff --git a/src/org/mxchange/jcore/contact/gender/Gender.java b/src/org/mxchange/jcore/contact/gender/Gender.java new file mode 100644 index 0000000..576851d --- /dev/null +++ b/src/org/mxchange/jcore/contact/gender/Gender.java @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcore.contact.gender; + +import java.text.MessageFormat; + +/** + * Gender enum + * + * @author Roland Haeder + */ +public enum Gender { + /** + * Unknown enum + */ + UNKNOWN('U', "BaseContact.gender.unknown.text"), //NOI18N + + /** + * Male enum + */ + MALE('M', "BaseContact.gender.male.text"), //NOI18N + + /** + * Female enum + */ + FEMALE('F', "BaseContact.gender.female.text"), //NOI18N + + /** + * Company enum + */ + COMPANY('C', "BaseContact.gender.company.text"); //NOI18N + + /** + * Cache for valid chars + */ + private static char[] validChars; + + /** + * Access key being entered by ConsoleClient + */ + private final char accessChar; + + /** + * Output value (for messages) + */ + private final String messageKey; + + /** + * Getter for Gender enum from given character + * + * @param c Gender character + * @return Gender enum + */ + public static Gender fromChar (final char c) { + // Init variable + Gender g = null; + + // Loop through all + for (final Gender gender : GenderUtils.selectableGenders()) { + // Does the char match? + if (c == gender.getAccessChar()) { + // Found it + g = gender; + break; + } + } + + // Still null? + if (null == g) { + // Didn't found a valid one + throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N + } + + // Return it + //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName()); + return g; + } + + /** + * Valid chars (mostly for console client) + * + * @return Valid chars + */ + public static char[] validChars () { + // Is cache set? + if (validChars != null) { + // Return it + return validChars; + } + + // Init array, only 3 are valid as 'U' is UNKNOWN and is not valid. + char[] valid = new char[3]; + + // Get values + int i = 0; + for (final Gender gender : GenderUtils.selectableGenders()) { + // Debug message + //* NOISY-DEBUG: */ System.out.println("gender=" + gender); + + // Debug message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i)); + + // Get access key as this is also the access + valid[i] = gender.getAccessChar(); + + // Increment index + i++; + } + + // Set it here + validChars = valid; + + // Return finialized array + return valid; + } + + /** + * Constructor + * + * @param accessChar Value being entered by ConsoleClient + * @param messageKey Message key for resource file + */ + private Gender (final char accessChar, final String messageKey) { + // Set both + this.accessChar = accessChar; + this.messageKey = messageKey; + } + + /** + * Acces key (console client mostly) + * + * @return the accessChar + */ + public char getAccessChar () { + return this.accessChar; + } + + /** + * Output value (for messages) + * + * @return the messageKey + */ + public String getMessageKey () { + return this.messageKey; + } +} diff --git a/src/org/mxchange/jcore/contact/gender/GenderUtils.java b/src/org/mxchange/jcore/contact/gender/GenderUtils.java new file mode 100644 index 0000000..1fb0992 --- /dev/null +++ b/src/org/mxchange/jcore/contact/gender/GenderUtils.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcore.contact.gender; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; +import org.mxchange.jcore.BaseFrameworkSystem; + +/** + * Gender utils class + * + * @author Roland Haeder + */ +public final class GenderUtils extends BaseFrameworkSystem { + /** + * Private contructor as this is an utility class + */ + private GenderUtils () { + } + + /** + * All selectable genders (not UNKNOWN) + * + * @return Selectable genders (not UNKNOWN) + */ + public static List selectableGenders () { + // Trace message + new GenderUtils().getLogger().trace("CALLED!"); //NOI18N + + // Init list + List list = new LinkedList<>(); + + // Walk through all genders + for (final Gender gender : Gender.values()) { + // Debug log + new GenderUtils().getLogger().debug(MessageFormat.format("gender={0}", gender)); //NOI18N + + // Is it not UNKNOWN + if (!gender.equals(Gender.UNKNOWN)) { + // Add it + boolean added = list.add(gender); + + // Has it been added? + assert(added) : MessageFormat.format("gender {0} not added.", gender); //NOI18N + } + } + + // Trace message + new GenderUtils().getLogger().trace(MessageFormat.format("list={0} - EXIT!", list)); //NOI18N + + // Return it + return list; + } +}