00001
00026 package org.objectweb.jonas.jaxr.factory;
00027
00028 import java.util.Hashtable;
00029 import java.util.Properties;
00030
00031 import javax.naming.Context;
00032 import javax.naming.Name;
00033 import javax.naming.RefAddr;
00034 import javax.naming.Reference;
00035 import javax.naming.spi.ObjectFactory;
00036 import javax.xml.registry.ConnectionFactory;
00037
00038 import org.objectweb.jonas.common.JNDIUtils;
00039 import org.objectweb.jonas.common.Log;
00040 import org.objectweb.jonas.common.PropDump;
00041
00042 import org.objectweb.util.monolog.api.BasicLevel;
00043 import org.objectweb.util.monolog.api.Logger;
00044
00045
00050 public class JAXRFactory implements ObjectFactory {
00051
00055 private static Logger logger;
00056
00060 public static final String FACTORY_TYPE = "javax.xml.registry.ConnectionFactory";
00061
00065 public static final String PROPS_NAME = "jaxr.properties";
00066
00070 private static final String JAXR_FACTORY_CLASSNAME = "jaxr.factory.classname";
00071
00075 public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
00076
00077 if (logger == null) {
00078 logger = Log.getLogger(Log.JONAS_JAXR_PREFIX);
00079 }
00080
00081
00082 if (!(obj instanceof Reference)) {
00083 return null;
00084 }
00085 Reference ref = (Reference) obj;
00086
00087
00088 String clname = ref.getClassName();
00089
00090
00091 if (!ref.getClassName().equals(FACTORY_TYPE)) {
00092 logger.log(BasicLevel.ERROR, "Cannot create object : required type is '" + FACTORY_TYPE + "', but found type is '" + clname + "'.");
00093 return null;
00094 }
00095
00096
00097 Properties jaxrProps = new Properties();
00098 RefAddr refAddr = null;
00099
00100 refAddr = ref.get(PROPS_NAME);
00101 if (refAddr != null) {
00102 jaxrProps = (Properties) JNDIUtils.getObjectFromBytes((byte[]) refAddr.getContent());
00103 PropDump.print("These are the properties used to obtain a new jaxr object", jaxrProps, logger, BasicLevel.DEBUG);
00104 }
00105
00106
00107 String clsName = jaxrProps.getProperty(JAXR_FACTORY_CLASSNAME);
00108 if (clsName != null) {
00109 System.setProperty("javax.xml.registry.ConnectionFactoryClass", clsName);
00110 }
00111
00112 ConnectionFactory cf = ConnectionFactory.newInstance();
00113
00114
00115 cf.setProperties(jaxrProps);
00116
00117 return cf;
00118 }
00119
00120 }