/*
* Jalisto - JAva LIght STOrage
* Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Xcalia
* 71, rue Desnouettes
* 75014 Paris - France
* http://www.xcalia.com
*/
package org.objectweb.jalisto.se.jca;
import org.objectweb.jalisto.se.exception.JcaException;
import org.objectweb.jalisto.se.impl.trace.Trace;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import javax.resource.cci.ConnectionFactory;
import java.util.Hashtable;
public class JalistoObjectFactory implements ObjectFactory {
public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env)
throws Exception {
trace.println(Trace.JCA, TRACE_ID + " ClassLoader {0}" + JalistoObjectFactory.class.getClassLoader());
trace.println(Trace.JCA, TRACE_ID + " getObjectInstance \n{0}\nNaming pmfContext name : {1}",
refObj, name);
trace.println(Trace.JCA, TRACE_ID + " registered factories {0}", factoryList);
Reference ref = (Reference) refObj;
String driverName = (String) ref.get(JALISTOID).getContent();
Object connectionFactory = factoryList.get(driverName);
if (connectionFactory == null) {
throw new JcaException("Jalisto Driver resource adapter does not exist");
}
return connectionFactory;
}
public static Object getConnectionFactory(Reference ref) {
String driverName = (String) ref.get(JALISTOID).getContent();
return factoryList.get(driverName);
}
public static void addConnectionFactory(String factoryId, ConnectionFactory cf) {
if (factoryList.contains(factoryId)) {
throw new JcaException("JCA resource adapter already exists");
}
factoryList.put(factoryId, cf);
trace.println(Trace.JCA, "List " + factoryList);
}
public static void setTrace(Trace trace) {
JalistoObjectFactory.trace = trace;
}
private static final Hashtable factoryList = new Hashtable();
private static Trace trace;
private static final String TRACE_ID = "[JalistoObjectFactory]";
public static final String JALISTOID = "Naming.JALISTO";
}
|