1 26 package org.objectweb.jonas.jaxr.factory; 27 28 import java.util.Hashtable ; 29 import java.util.Properties ; 30 31 import javax.naming.Context ; 32 import javax.naming.Name ; 33 import javax.naming.RefAddr ; 34 import javax.naming.Reference ; 35 import javax.naming.spi.ObjectFactory ; 36 import javax.xml.registry.ConnectionFactory ; 37 38 import org.objectweb.jonas.common.JNDIUtils; 39 import org.objectweb.jonas.common.Log; 40 import org.objectweb.jonas.common.PropDump; 41 42 import org.objectweb.util.monolog.api.BasicLevel; 43 import org.objectweb.util.monolog.api.Logger; 44 45 46 50 public class JAXRFactory implements ObjectFactory { 51 52 55 private static Logger logger; 56 57 60 public static final String FACTORY_TYPE = "javax.xml.registry.ConnectionFactory"; 61 62 65 public static final String PROPS_NAME = "jaxr.properties"; 66 67 70 private static final String JAXR_FACTORY_CLASSNAME = "jaxr.factory.classname"; 71 72 75 public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { 76 if (logger == null) { 78 logger = Log.getLogger(Log.JONAS_JAXR_PREFIX); 79 } 80 81 if (!(obj instanceof Reference )) { 83 return null; 84 } 85 Reference ref = (Reference ) obj; 86 87 String clname = ref.getClassName(); 89 90 if (!ref.getClassName().equals(FACTORY_TYPE)) { 92 logger.log(BasicLevel.ERROR, "Cannot create object : required type is '" + FACTORY_TYPE + "', but found type is '" + clname + "'."); 93 return null; 94 } 95 96 Properties jaxrProps = new Properties (); 98 RefAddr refAddr = null; 99 100 refAddr = ref.get(PROPS_NAME); 101 if (refAddr != null) { 102 jaxrProps = (Properties ) JNDIUtils.getObjectFromBytes((byte[]) refAddr.getContent()); 103 if (logger.isLoggable(BasicLevel.DEBUG)) { 104 PropDump.print("These are the properties used to obtain a new jaxr object", jaxrProps, logger, BasicLevel.DEBUG); 105 } 106 } 107 108 String clsName = jaxrProps.getProperty(JAXR_FACTORY_CLASSNAME); 110 if (clsName != null) { 111 System.setProperty("javax.xml.registry.ConnectionFactoryClass", clsName); 112 } 113 ConnectionFactory cf = ConnectionFactory.newInstance(); 115 116 cf.setProperties(jaxrProps); 118 119 return cf; 120 } 121 122 } 123 | Popular Tags |