1 /**
2 *
3 * Copyright 2005 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
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 /**
29 * Simple GBean to provide access to a JAXR ConnectionFactory
30 *
31 * @version $Rev: 398050 $ $Date: 2006-04-28 18:10:56 -0700 (Fri, 28 Apr 2006) $
32 */
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 /**
45 * Returns a fresh, new implementation of javax.xml.registry.ConnectionFactory
46 *
47 * @return ConnectionFactory
48 */
49 public Object $getResource() {
50 if (connectionFactoryClass != null) {
51 System.setProperty("javax.xml.registry.ConnectionFactoryClass", connectionFactoryClass);
52
53 }
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 }