01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.webservices.jaxr;
17:
18: import javax.xml.registry.ConnectionFactory;
19: import javax.xml.registry.JAXRException;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.apache.geronimo.gbean.GBeanInfo;
24: import org.apache.geronimo.gbean.GBeanInfoBuilder;
25: import org.apache.geronimo.naming.ResourceSource;
26: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
27:
28: /**
29: * Simple GBean to provide access to a JAXR ConnectionFactory
30: *
31: * @version $Rev: 607943 $ $Date: 2008-01-01 15:07:17 -0800 (Tue, 01 Jan 2008) $
32: */
33: public class JAXRGBean implements ResourceSource {
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(
52: "javax.xml.registry.ConnectionFactoryClass",
53: connectionFactoryClass);
54: //TODO consider whether we should bypass the code below and just construct it ourselves, like it does.
55: }
56: Thread currentThread = Thread.currentThread();
57: ClassLoader oldCl = currentThread.getContextClassLoader();
58: currentThread.setContextClassLoader(cl);
59: try {
60: return ConnectionFactory.newInstance();
61: } catch (JAXRException e) {
62: log.error("Error creating ConnectionFactory", e);
63: } finally {
64: currentThread.setContextClassLoader(oldCl);
65: }
66:
67: return null;
68: }
69:
70: public static final GBeanInfo GBEAN_INFO;
71:
72: static {
73: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
74: JAXRGBean.class, NameFactory.JAXR_CONNECTION_FACTORY);
75:
76: infoFactory.addAttribute("connectionFactoryClass",
77: String.class, true, true);
78: infoFactory.addAttribute("classLoader", ClassLoader.class,
79: false);
80:
81: infoFactory.addOperation("$getResource");
82:
83: infoFactory.setConstructor(new String[] {
84: "connectionFactoryClass", "classLoader" });
85:
86: GBEAN_INFO = infoFactory.getBeanInfo();
87: }
88:
89: public static GBeanInfo getGBeanInfo() {
90: return GBEAN_INFO;
91: }
92:
93: }
|