KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_jms > JObjectFactory


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s):
22  * Contributor(s):
23  * Philippe Durieux
24  *
25  * --------------------------------------------------------------------------
26  * $Id: JObjectFactory.java,v 1.6 2003/04/11 12:00:55 coqp Exp $
27  * --------------------------------------------------------------------------
28  */

29
30 package org.objectweb.jonas_jms;
31
32 import java.util.Hashtable JavaDoc;
33 import javax.naming.Context JavaDoc;
34 import javax.naming.Name JavaDoc;
35 import javax.naming.Reference JavaDoc;
36 import javax.naming.spi.ObjectFactory JavaDoc;
37 import org.objectweb.jonas_jms.api.JmsManager;
38
39 import org.objectweb.util.monolog.api.BasicLevel;
40
41 /**
42  * Factory used by JNDI lookup to get Connection Factories.
43  * These factories are managed by the JMS Manager.
44  * @see javax.naming.spi.ObjectFactory
45  * @author Laurent Chauvirey, Frederic Maistre, Nicolas Tachker
46  * Contributor(s):
47  * Philippe Durieux
48  * Philippe Coq: Integration Joram 3.4 (JMS 1.1)
49  */

50 public class JObjectFactory implements ObjectFactory JavaDoc {
51
52     /**
53      * Always return the unique ConnectionFactory stored in the JmsManager
54      */

55     public Object JavaDoc getObjectInstance(Object JavaDoc refObj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc env) throws Exception JavaDoc {
56
57         Reference JavaDoc ref = (Reference JavaDoc) refObj;
58         JmsManager jms = JmsManagerImpl.getJmsManager();
59         String JavaDoc clname = ref.getClassName();
60
61         TraceJms.logger.log(BasicLevel.DEBUG, "instance " + clname);
62
63         if (clname.equals("org.objectweb.jonas_jms.JConnectionFactory")) {
64             // ConnectionFactory
65
return jms.getConnectionFactory();
66         } else if (clname.equals("org.objectweb.jonas_jms.JQueueConnectionFactory")) {
67             // QueueConnectionFactory
68
return jms.getQueueConnectionFactory();
69         } else if (clname.equals("org.objectweb.jonas_jms.JTopicConnectionFactory")) {
70             // TopicConnectionFactory
71
return jms.getTopicConnectionFactory();
72         } else {
73             TraceJms.logger.log(BasicLevel.ERROR, "bad class name: " + clname);
74             return null;
75         }
76     }
77 }
78
Popular Tags