]> git.mxchange.org Git - jcore-utils.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 13 Mar 2018 00:00:03 +0000 (01:00 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 13 Mar 2018 00:00:03 +0000 (01:00 +0100)
- renamed BaseDatabaseBean to BaseEnterpriseBean as this is a generic bean for EJBs
- only EJBs have message queues and the others, so no real good idea of having such
  code in BaseBean
- removed no longer used BaseBean, was an overdose anyway ... ;-)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcoreee/bean/BaseBean.java [deleted file]
src/org/mxchange/jcoreee/bean/ejb/BaseEnterpriseBean.java [new file with mode: 0644]
src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java
src/org/mxchange/jcoreee/database/BaseDatabaseBean.java [deleted file]
src/org/mxchange/jcoreee/utils/FacesUtils.java
src/org/mxchange/jcoreee/utils/StringUtils.java [new file with mode: 0644]

diff --git a/src/org/mxchange/jcoreee/bean/BaseBean.java b/src/org/mxchange/jcoreee/bean/BaseBean.java
deleted file mode 100644 (file)
index 8f0c235..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2017, 2018 Free Software Foundation
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jcoreee.bean;
-
-import java.io.Serializable;
-import javax.faces.FacesException;
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-/**
- * A generic bean class
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public abstract class BaseBean implements Serializable {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 18_305_698_567_265L;
-
-       /**
-        * Connection
-        */
-       private Connection connection;
-
-       /**
-        * Message producer
-        */
-       private MessageProducer messageProducer;
-
-       /**
-        * Mailer message queue
-        */
-       private Queue queue;
-
-       /**
-        * Session instance
-        */
-       private Session session;
-
-       /**
-        * This class' default protected constructor. Please call
-        * super("jms/project-queue-factory", "jms/project-email-queue"); if you
-        * need to send emails.
-        */
-       protected BaseBean () {
-       }
-
-       /**
-        * Constructor with queue factory JNDI and queue JNDI names
-        * <p>
-        * @param factoryJndi    JNDI name for queue factory
-        * @param queueJndi JNDI name for email queue
-        */
-       protected BaseBean (final String factoryJndi, final String queueJndi) {
-               // Call default constructor
-               this();
-
-               // Try it out
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Get factory from JMS resource
-                       QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup(factoryJndi);
-
-                       // Lookup queue
-                       this.queue = (Queue) context.lookup(queueJndi);
-
-                       // Create connection
-                       this.connection = connectionFactory.createConnection();
-
-                       // Init session instance
-                       this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-                       // And message producer
-                       this.messageProducer = this.session.createProducer(this.queue);
-               } catch (final NamingException | JMSException e) {
-                       // Continued to throw
-                       throw new FacesException(e);
-               }
-       }
-
-       /**
-        * Getter for configured message producer instance
-        * <p>
-        * @return Message producer
-        */
-       protected MessageProducer getMessageProducer () {
-               return this.messageProducer;
-       }
-
-       /**
-        * Getter for configured session instance
-        * <p>
-        * @return Session
-        */
-       protected Session getSession () {
-               return this.session;
-       }
-
-}
diff --git a/src/org/mxchange/jcoreee/bean/ejb/BaseEnterpriseBean.java b/src/org/mxchange/jcoreee/bean/ejb/BaseEnterpriseBean.java
new file mode 100644 (file)
index 0000000..a08610c
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2016 - 2018 Free Software Foundation
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcoreee.bean.ejb;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import javax.faces.FacesException;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+
+/**
+ * A helper class for beans that access the database.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public abstract class BaseEnterpriseBean implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 217_687_175_985_875L;
+
+       /**
+        * Connection
+        */
+       private Connection connection;
+
+       /**
+        * Entity manager
+        */
+       @PersistenceContext
+       private EntityManager entityManager;
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Message producer
+        */
+       private MessageProducer messageProducer;
+
+       /**
+        * Mailer message queue
+        */
+       private Queue queue;
+
+       /**
+        * Session instance
+        */
+       private Session session;
+
+       /**
+        * This class' default protected constructor. Please invoke
+        * super("jms/project-queue-factory", "jms/project-email-queue"); if you
+        * need to send emails.
+        */
+       protected BaseEnterpriseBean () {
+               // Call super constructor
+               super();
+
+               // Init logger instance
+               this.initLoggerInstance();
+       }
+
+       /**
+        * Constructor with queue factory JNDI and queue JNDI names
+        * <p>
+        * @param factoryJndi JNDI name for queue factory
+        * @param queueJndi   JNDI name for email queue
+        */
+       protected BaseEnterpriseBean (final String factoryJndi, final String queueJndi) {
+               // Call default constructor
+               this();
+
+               // Try it out
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Get factory from JMS resource
+                       QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup(factoryJndi);
+
+                       // Lookup queue
+                       this.queue = (Queue) context.lookup(queueJndi);
+
+                       // Create connection
+                       this.connection = connectionFactory.createConnection();
+
+                       // Init session instance
+                       this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+                       // And message producer
+                       this.messageProducer = this.session.createProducer(this.queue);
+               } catch (final NamingException | JMSException e) {
+                       // Continued to throw
+                       throw new FacesException(e);
+               }
+       }
+
+       /**
+        * Initializes logger instance
+        */
+       private void initLoggerInstance () {
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+               }
+       }
+
+       /**
+        * Getter for connection instance
+        * <p>
+        * @return Connection instance
+        */
+       protected EntityManager getEntityManager () {
+               return this.entityManager;
+       }
+
+       /**
+        * Getter for loggerBeanLocal
+        * <p>
+        * @return Logger instance
+        */
+       protected LoggerBeanLocal getLoggerBeanLocal () {
+               return this.loggerBeanLocal;
+       }
+
+       /**
+        * Getter for configured message producer instance
+        * <p>
+        * @return Message producer
+        */
+       protected MessageProducer getMessageProducer () {
+               return this.messageProducer;
+       }
+
+       /**
+        * Getter for configured session instance
+        * <p>
+        * @return Session
+        */
+       protected Session getSession () {
+               return this.session;
+       }
+
+       /**
+        * Sends given message to configured queue
+        * <p>
+        * @param message Message to send
+        * <p>
+        * @throws JMSException if something went wrong
+        */
+       protected void sendMessage (final ObjectMessage message) throws JMSException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N
+
+               // The parameter should be valid
+               if (null == message) {
+                       // Throw NPE
+                       throw new NullPointerException("message is null"); //NOI18N
+               } else if (this.getMessageProducer() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.messageProvider is null"); //NOI18N
+               }
+
+               // Send it
+               this.getMessageProducer().send(message);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: EXIT!", this.getClass().getSimpleName())); //NOI18N
+       }
+
+}
index e71eb0716c3bb6b74c19a2b54cb6fd635ded2d0a..61019433a301e7ccc3d561e912d840c1f22f3029 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jcoreee.bean.faces;
 
+import java.io.Serializable;
 import java.security.Principal;
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -25,14 +26,13 @@ import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
-import org.mxchange.jcoreee.bean.BaseBean;
 
 /**
  * An abstract bean for faces (web) projects.
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public abstract class BaseFacesBean extends BaseBean {
+public abstract class BaseFacesBean implements Serializable {
 
        /**
         * Loaded resource bundles ("cached")
diff --git a/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java b/src/org/mxchange/jcoreee/database/BaseDatabaseBean.java
deleted file mode 100644 (file)
index 7620419..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2016 - 2018 Free Software Foundation
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jcoreee.database;
-
-import java.text.MessageFormat;
-import javax.jms.JMSException;
-import javax.jms.ObjectMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.mxchange.jcoreee.bean.BaseBean;
-import org.mxchange.jcoreeelogger.beans.local.logger.Log;
-import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
-
-/**
- * A helper class for beans that access the database.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public abstract class BaseDatabaseBean extends BaseBean {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 217_687_175_985_875L;
-
-       /**
-        * Entity manager
-        */
-       @PersistenceContext
-       private EntityManager entityManager;
-
-       /**
-        * Logger instance
-        */
-       @Log
-       private LoggerBeanLocal loggerBeanLocal;
-
-       /**
-        * This class' default protected constructor. Please call
-        * super("jms/project-queue-factory", "jms/project-email-queue"); if you
-        * need to send emails.
-        */
-       protected BaseDatabaseBean () {
-               // Call super constructor
-               super();
-
-               // Init logger instance
-               this.initLoggerInstance();
-       }
-
-       /**
-        * Constructor with queue factory JNDI and queue JNDI names
-        * <p>
-        * @param factoryJndi JNDI name for queue factory
-        * @param queueJndi   JNDI name for email queue
-        */
-       protected BaseDatabaseBean (final String factoryJndi, final String queueJndi) {
-               // Call super constructor
-               super(factoryJndi, queueJndi);
-
-               // Init logger instance
-               this.initLoggerInstance();
-       }
-
-       /**
-        * Initializes logger instance
-        */
-       private void initLoggerInstance () {
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Lookup logger
-                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw
-                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
-       }
-
-       /**
-        * Getter for connection instance
-        * <p>
-        * @return Connection instance
-        */
-       protected EntityManager getEntityManager () {
-               return this.entityManager;
-       }
-
-       /**
-        * Getter for loggerBeanLocal
-        * <p>
-        * @return Logger instance
-        */
-       protected LoggerBeanLocal getLoggerBeanLocal () {
-               return this.loggerBeanLocal;
-       }
-
-       /**
-        * Sends given message to configured queue
-        * <p>
-        * @param message Message to send
-        * <p>
-        * @throws JMSException if something went wrong
-        */
-       protected void sendMessage (final ObjectMessage message) throws JMSException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N
-
-               // The parameter should be valid
-               if (null == message) {
-                       // Throw NPE
-                       throw new NullPointerException("message is null"); //NOI18N
-               } else if (this.getMessageProducer() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("this.messageProvider is null"); //NOI18N
-               }
-
-               // Send it
-               this.getMessageProducer().send(message);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: EXIT!", this.getClass().getSimpleName())); //NOI18N
-       }
-
-}
index 674b8f1bd1752619d63288876be96247ccbf6e7a..35e0b28e42fcbe294824bb5adbe828b08138d3a6 100644 (file)
  */
 package org.mxchange.jcoreee.utils;
 
+import java.io.Serializable;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 
 /**
- * An utilities class for JSF
+ * An utilities class for JavaEE applications, entities and EJBs and more
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public class FacesUtils {
+public class FacesUtils implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 19_863_546_716_250L;
 
        /**
         * Generates a "base URL" for for example mail templates. For JSF
@@ -78,66 +84,6 @@ public class FacesUtils {
                return baseUrl;
        }
 
-       /**
-        * Compares both string with null-safety. This method is based on the
-        * example from
-        * https://codereview.stackexchange.com/questions/20191/comparing-two-strings-which-could-be-null-or-blank-in-a-comparator
-        * <p>
-        * @param str0 First string
-        * @param str1 Second string
-        * <p>
-        * @return Comparison value, 0 means equals, -1 means str0 smaller str2 and
-        *         2 means str0 bigger str2
-        */
-       @SuppressWarnings ("null")
-       public static int comareTo (final String str0, final String str1) {
-               // Check both strings for null and empty
-               boolean isStr0Empty = (str0 == null || str0.isEmpty());
-               boolean isStr1Empty = (str1 == null || str1.isEmpty());
-
-               // Check conditions
-               if (isStr0Empty && isStr1Empty) {
-                       return 0;
-               } else if (isStr0Empty) {
-                       return -1;
-               } else if (isStr1Empty) {
-                       return 1;
-               }
-
-               // Compare both
-               return str0.compareTo(str1);
-       }
-
-       /**
-        * Compares both string with null-safety, ignoring case-sensitivity. This
-        * method is based on the example from
-        * https://codereview.stackexchange.com/questions/20191/comparing-two-strings-which-could-be-null-or-blank-in-a-comparator
-        * <p>
-        * @param str0 First string
-        * @param str1 Second string
-        * <p>
-        * @return Comparison value, 0 means equals, -1 means str0 smaller str2 and
-        *         2 means str0 bigger str2
-        */
-       @SuppressWarnings ("null")
-       public static int comareToIgnoreCase (final String str0, final String str1) {
-               // Check both strings for null and empty
-               boolean isStr0Empty = (str0 == null || str0.isEmpty());
-               boolean isStr1Empty = (str1 == null || str1.isEmpty());
-
-               // Check conditions
-               if (isStr0Empty && isStr1Empty) {
-                       return 0;
-               } else if (isStr0Empty) {
-                       return -1;
-               } else if (isStr1Empty) {
-                       return 1;
-               }
-
-               // Compare both
-               return str0.compareToIgnoreCase(str1);
-       }
-
        /**
         * No instances from this class are required
         */
diff --git a/src/org/mxchange/jcoreee/utils/StringUtils.java b/src/org/mxchange/jcoreee/utils/StringUtils.java
new file mode 100644 (file)
index 0000000..7a3d6c2
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2018 Roland Häder<roland@mxchange.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcoreee.utils;
+
+import java.io.Serializable;
+
+/**
+ * String utilities class
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class StringUtils implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 30_894_676_712_650L;
+
+       /**
+        * Compares both string with null-safety. This method is based on the
+        * example from
+        * https://codereview.stackexchange.com/questions/20191/comparing-two-strings-which-could-be-null-or-blank-in-a-comparator
+        * <p>
+        * @param str0 First string
+        * @param str1 Second string
+        * <p>
+        * @return Comparison value, 0 means equals, -1 means str0 smaller str2 and
+        *         2 means str0 bigger str2
+        */
+       @SuppressWarnings ("null")
+       public static int comareTo (final String str0, final String str1) {
+               // Check both strings for null and empty
+               boolean isStr0Empty = (str0 == null || str0.isEmpty());
+               boolean isStr1Empty = (str1 == null || str1.isEmpty());
+
+               // Check conditions
+               if (isStr0Empty && isStr1Empty) {
+                       return 0;
+               } else if (isStr0Empty) {
+                       return -1;
+               } else if (isStr1Empty) {
+                       return 1;
+               }
+
+               // Compare both
+               return str0.compareTo(str1);
+       }
+
+       /**
+        * Compares both string with null-safety, ignoring case-sensitivity. This
+        * method is based on the example from
+        * https://codereview.stackexchange.com/questions/20191/comparing-two-strings-which-could-be-null-or-blank-in-a-comparator
+        * <p>
+        * @param str0 First string
+        * @param str1 Second string
+        * <p>
+        * @return Comparison value, 0 means equals, -1 means str0 smaller str2 and
+        *         2 means str0 bigger str2
+        */
+       @SuppressWarnings ("null")
+       public static int comareToIgnoreCase (final String str0, final String str1) {
+               // Check both strings for null and empty
+               boolean isStr0Empty = (str0 == null || str0.isEmpty());
+               boolean isStr1Empty = (str1 == null || str1.isEmpty());
+
+               // Check conditions
+               if (isStr0Empty && isStr1Empty) {
+                       return 0;
+               } else if (isStr0Empty) {
+                       return -1;
+               } else if (isStr1Empty) {
+                       return 1;
+               }
+
+               // Compare both
+               return str0.compareToIgnoreCase(str1);
+       }
+
+       /**
+        * Utility classes don't have instances
+        */
+       private StringUtils () {
+               // Empty constructor
+       }
+
+}