1 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 ; 30 import javax.naming.Name ; 31 import javax.naming.Reference ; 32 import javax.naming.spi.ObjectFactory ; 33 import javax.resource.cci.ConnectionFactory ; 34 import java.util.Hashtable ; 35 36 public class JalistoObjectFactory implements ObjectFactory { 37 38 public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) 39 throws Exception { 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 ref = (Reference ) refObj; 46 String driverName = (String ) ref.get(JALISTOID).getContent(); 47 Object 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 getConnectionFactory(Reference ref) { 55 String driverName = (String ) ref.get(JALISTOID).getContent(); 56 return factoryList.get(driverName); 57 } 58 59 public static void addConnectionFactory(String factoryId, ConnectionFactory 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 factoryList = new Hashtable (); 74 private static Trace trace; 75 76 private static final String TRACE_ID = "[JalistoObjectFactory]"; 77 public static final String JALISTOID = "Naming.JALISTO"; 78 } 79 | Popular Tags |