01 package com.bea.medrec.utils;
02
03 import javax.jms.Queue;
04 import javax.jms.QueueConnectionFactory;
05 import javax.naming.InitialContext;
06 import javax.naming.NamingException;
07 import org.apache.log4j.Logger;
08
09 /**
10 * <p>Encapsulates service lookup and creation processes for JMS.</p>
11 *
12 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
13 */
14 public class JMSFactory {
15
16 private static Logger logger = MedRecLog4jFactory.getLogger(JMSFactory.class.getName());
17 private InitialContext ic = null;
18 private static JMSFactory instance = null;
19
20 /**
21 * Constructor
22 */
23 private JMSFactory() throws NamingException {
24 try {
25 ic = new InitialContext();
26 } catch (NamingException ne) {
27 logger.error(ne);
28 throw ne;
29 }
30 }
31
32 private JMSFactory(InitialContext iCtx) {
33 ic = iCtx;
34 }
35
36 /**
37 * <p>Get instance of JMSFactory.</p>
38 *
39 * @return JMSFactory
40 */
41 public static JMSFactory getFactory() throws NamingException {
42 if (instance == null) instance = new JMSFactory();
43 return instance;
44 }
45
46 /**
47 * <p>Get instance of JMSFactory.</p>
48 *
49 * @param iCtx
50 * @return JMSFactory
51 */
52 public static JMSFactory getFactory(InitialContext iCtx) {
53 if (instance == null) instance = new JMSFactory(iCtx);
54 return instance;
55 }
56
57 /**
58 * <p>Lookup QueueConnectionFactory.</p>
59 *
60 * @param name
61 * @return QueueConnectionFactory
62 */
63 public QueueConnectionFactory lookupQCFactory(String name)
64 throws NamingException {
65 QueueConnectionFactory queConnFactory = null;
66 try {
67 queConnFactory = (QueueConnectionFactory) ic.lookup(name);
68 } catch (NamingException ne) {
69 logger.error(ne);
70 throw ne;
71 }
72
73 return queConnFactory;
74 }
75
76 /**
77 * <p>Lookup queue.</p>
78 *
79 * @param name
80 * @return Queue
81 */
82 public Queue lookupQueue(String name) throws NamingException {
83 Queue que = null;
84 try {
85 que = (Queue) ic.lookup(name);
86 } catch (NamingException ne) {
87 logger.error(ne);
88 throw ne;
89 }
90 return que;
91 }
92 }
|