1 17 package org.apache.geronimo.webservices.jaxr; 18 19 import org.apache.geronimo.gbean.GBeanInfo; 20 import org.apache.geronimo.gbean.GBeanInfoBuilder; 21 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 22 import org.apache.commons.logging.LogFactory; 23 import org.apache.commons.logging.Log; 24 25 import javax.xml.registry.ConnectionFactory ; 26 import javax.xml.registry.JAXRException ; 27 28 33 public class JAXRGBean { 34 35 private final Log log = LogFactory.getLog(JAXRGBean.class); 36 private final ClassLoader cl; 37 private final String connectionFactoryClass; 38 39 public JAXRGBean(String connectionFactoryClass, ClassLoader cl) { 40 this.cl = cl; 41 this.connectionFactoryClass = connectionFactoryClass; 42 } 43 44 49 public Object $getResource() { 50 if (connectionFactoryClass != null) { 51 System.setProperty("javax.xml.registry.ConnectionFactoryClass", connectionFactoryClass); 52 } 54 Thread currentThread = Thread.currentThread(); 55 ClassLoader oldCl = currentThread.getContextClassLoader(); 56 currentThread.setContextClassLoader(cl); 57 try { 58 return ConnectionFactory.newInstance(); 59 } catch (JAXRException e) { 60 log.error("Error creating ConnectionFactory", e); 61 } finally { 62 currentThread.setContextClassLoader(oldCl); 63 } 64 65 return null; 66 } 67 68 69 public static final GBeanInfo GBEAN_INFO; 70 71 static { 72 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(JAXRGBean.class, 73 NameFactory.JAXR_CONNECTION_FACTORY); 74 75 infoFactory.addAttribute("connectionFactoryClass", String .class, true, true); 76 infoFactory.addAttribute("classLoader", ClassLoader .class, false); 77 78 infoFactory.addOperation("$getResource"); 79 80 infoFactory.setConstructor(new String [] {"connectionFactoryClass", "classLoader"}); 81 82 GBEAN_INFO = infoFactory.getBeanInfo(); 83 } 84 85 public static GBeanInfo getGBeanInfo() { 86 return GBEAN_INFO; 87 } 88 89 90 } 91 | Popular Tags |