KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > jca > JalistoObjectFactory


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
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 (at your option) 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, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.jca;
25
26 import org.objectweb.jalisto.se.exception.JcaException;
27 import org.objectweb.jalisto.se.impl.trace.Trace;
28
29 import javax.naming.Context JavaDoc;
30 import javax.naming.Name JavaDoc;
31 import javax.naming.Reference JavaDoc;
32 import javax.naming.spi.ObjectFactory JavaDoc;
33 import javax.resource.cci.ConnectionFactory JavaDoc;
34 import java.util.Hashtable JavaDoc;
35
36 public class JalistoObjectFactory implements ObjectFactory JavaDoc {
37
38     public Object JavaDoc getObjectInstance(Object JavaDoc refObj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc env)
39             throws Exception JavaDoc {
40         trace.println(Trace.JCA, TRACE_ID + " ClassLoader {0}" + JalistoObjectFactory.class.getClassLoader());
41         trace.println(Trace.JCA, TRACE_ID + " getObjectInstance \n{0}\nNaming pmfContext name : {1}",
42                       refObj, name);
43         trace.println(Trace.JCA, TRACE_ID + " registered factories {0}", factoryList);
44
45         Reference JavaDoc ref = (Reference JavaDoc) refObj;
46         String JavaDoc driverName = (String JavaDoc) ref.get(JALISTOID).getContent();
47         Object JavaDoc connectionFactory = factoryList.get(driverName);
48         if (connectionFactory == null) {
49             throw new JcaException("Jalisto Driver resource adapter does not exist");
50         }
51         return connectionFactory;
52     }
53
54     public static Object JavaDoc getConnectionFactory(Reference JavaDoc ref) {
55         String JavaDoc driverName = (String JavaDoc) ref.get(JALISTOID).getContent();
56         return factoryList.get(driverName);
57     }
58
59     public static void addConnectionFactory(String JavaDoc factoryId, ConnectionFactory JavaDoc cf) {
60         if (factoryList.contains(factoryId)) {
61             throw new JcaException("JCA resource adapter already exists");
62         }
63         factoryList.put(factoryId, cf);
64         trace.println(Trace.JCA, "List " + factoryList);
65     }
66
67
68     public static void setTrace(Trace trace) {
69         JalistoObjectFactory.trace = trace;
70     }
71
72
73     private static final Hashtable JavaDoc factoryList = new Hashtable JavaDoc();
74     private static Trace trace;
75
76     private static final String JavaDoc TRACE_ID = "[JalistoObjectFactory]";
77     public static final String JavaDoc JALISTOID = "Naming.JALISTO";
78 }
79
Popular Tags