KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > connector > ObjectFactoryImpl


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - Bull SA
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Frederic Maistre (Bull SA)
21  * Contributor(s): Nicolas Tachker (Bull SA)
22  */

23 package org.objectweb.joram.client.connector;
24
25 import javax.naming.Context JavaDoc;
26 import javax.naming.Name JavaDoc;
27 import javax.naming.Reference JavaDoc;
28
29 import org.objectweb.util.monolog.api.BasicLevel;
30
31 /**
32  * This class is a factory for building non managed outbound connection
33  * factories from their JNDI reference.
34  */

35 public class ObjectFactoryImpl implements javax.naming.spi.ObjectFactory JavaDoc
36 {
37   String JavaDoc cf =
38     "org.objectweb.joram.client.connector.OutboundConnectionFactory";
39   String JavaDoc qcf =
40     "org.objectweb.joram.client.connector.OutboundQueueConnectionFactory";
41   String JavaDoc tcf =
42     "org.objectweb.joram.client.connector.OutboundTopicConnectionFactory";
43
44
45   /** Returns a factory given its reference. */
46   public Object JavaDoc getObjectInstance(Object JavaDoc obj,
47                                   Name JavaDoc name,
48                                   Context JavaDoc ctx,
49                                   java.util.Hashtable JavaDoc env)
50     throws Exception JavaDoc {
51
52     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
53       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " getObjectInstance(" + obj +
54                                     ", " + name +
55                                     ", " + ctx +
56                                     ", " + env + ")");
57
58     Reference JavaDoc ref = (Reference JavaDoc) obj;
59
60     String JavaDoc hostName = (String JavaDoc) ref.get("hostName").getContent();
61     Integer JavaDoc serverPort =
62       new Integer JavaDoc((String JavaDoc) ref.get("serverPort").getContent());
63     String JavaDoc userName = (String JavaDoc) ref.get("userName").getContent();
64     String JavaDoc password = (String JavaDoc) ref.get("password").getContent();
65
66     ManagedConnectionFactoryImpl mcf = null;
67
68     if (ref.getClassName().equals(cf))
69       mcf = new ManagedConnectionFactoryImpl();
70     else if (ref.getClassName().equals(qcf))
71       mcf = new ManagedQueueConnectionFactoryImpl();
72     else if (ref.getClassName().equals(tcf))
73       mcf = new ManagedTopicConnectionFactoryImpl();
74     else
75       return null;
76
77     mcf.setCollocated(new Boolean JavaDoc(false));
78     mcf.setHostName(hostName);
79     mcf.setServerPort(serverPort);
80     mcf.setUserName(userName);
81     mcf.setPassword(password);
82
83     try {
84       return mcf.createConnectionFactory();
85     }
86     catch (Exception JavaDoc exc) {
87       return null;
88     }
89   }
90 }
91
Popular Tags