001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.fukurou.queue;
017
018import java.util.Locale;
019
020// import org.opengion.fukurou.util.StringUtil;
021
022/**
023 * キュータイプ別の受信クラス生成
024 * 指定されたキュータイプの受信クラスを生成します。
025 *
026 * 下記のキュータイプを指定可能です。
027 * MQ:Active MQ or Amazon MQ
028 * SQS:Amazon SQS。
029 *
030 * @og.group メッセージ連携
031 *
032 * @og.rev 5.10.15.2 (2019/09/20) 新規作成
033 * @og.rev 7.2.9.4 (2020/11/20) コーディングのみ修正
034 *
035 * @version 5
036 * @author oota
037 * @since JDK7
038 *
039 */
040final public class QueueReceiveFactory {
041//      private static final int BUFFER_MIDDLE = 200;
042
043        private static final String QUEUE_CLS = "org.opengion.fukurou.queue.QueueReceive_" ;
044
045        /**
046         * デフォルトコンストラクター
047         * static用クラスのため、クラス生成は不可にします。
048         */
049        private QueueReceiveFactory() {
050        }
051
052        /**
053         * キュー受信クラス生成
054         *
055         * 引数のキュータイプのキュー受信クラスを生成します。
056         * MQ:Apache ActiveMq、amazonMQの場合に設定します。
057         * SQS:Amazon SQSの場合に設定します。
058         *
059         * @param queueType キュータイプ
060         * @return キュータイプのキュー受信クラス
061         */
062        public static QueueReceive newQueueReceive(final String queueType) {
063                try {
064                        // 1. 前処理 大文字変換。queueType が null なら、当然エラーになる。
065                        // 2. 生成クラスの文字列生成
066                        final String cls = QUEUE_CLS + queueType.toUpperCase(Locale.JAPAN);
067
068                        // 3. 対象クラスの生成
069                        return (QueueReceive) Class.forName( cls ).getDeclaredConstructor().newInstance();
070
071                } catch (final Throwable th) {
072                        final String errMsg = "キュー受信クラス生成に失敗しました。"
073                                                        + " queueType =" + queueType ;
074                        throw new RuntimeException( errMsg ,th );
075                }
076
077//              QueueReceive queueReceive = null;
078//              String setQueueType = null;
079//
080//              final StringBuilder path = new StringBuilder(BUFFER_MIDDLE);
081//
082//              // 1. 前処理
083//              // 大文字変換
084//              if (!StringUtil.isNull(queueType)) {
085//                      setQueueType = queueType.toUpperCase(Locale.JAPAN);
086//              }
087//
088//              // 2. 生成クラスの文字列生成
089//              path.append("org.opengion.fukurou.queue.")
090//                      .append("QueueReceive_")
091//                      .append(setQueueType);
092//
093//              try {
094//                      // 3. 対象クラスの生成
095//                      queueReceive = (QueueReceive) Class.forName(path.toString()).newInstance();
096//              } catch (final Throwable th) {
097//                      // キャッチしたエラー情報をスロー
098//                      throw new RuntimeException(th);
099//              }
100//
101//              return queueReceive;
102        }
103}