+++ /dev/null
-/*
- * 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;
- }
-
-}