KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > webservices > jaxr > JAXRGBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
26 import javax.xml.registry.JAXRException JavaDoc;
27
28 /**
29  * Simple GBean to provide access to a JAXR ConnectionFactory
30  *
31  * @version $Rev: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
32  */

33 public class JAXRGBean {
34
35     private final Log log = LogFactory.getLog(JAXRGBean.class);
36     private final ClassLoader JavaDoc cl;
37     private final String JavaDoc connectionFactoryClass;
38
39     public JAXRGBean(String JavaDoc connectionFactoryClass, ClassLoader JavaDoc 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 JavaDoc $getResource() {
50         if (connectionFactoryClass != null) {
51             System.setProperty("javax.xml.registry.ConnectionFactoryClass", connectionFactoryClass);
52             //TODO consider whether we should bypass the code below and just construct it ourselves, like it does.
53
}
54         Thread JavaDoc currentThread = Thread.currentThread();
55         ClassLoader JavaDoc oldCl = currentThread.getContextClassLoader();
56         currentThread.setContextClassLoader(cl);
57         try {
58             return ConnectionFactory.newInstance();
59         } catch (JAXRException JavaDoc 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 JavaDoc.class, true, true);
76         infoFactory.addAttribute("classLoader", ClassLoader JavaDoc.class, false);
77
78         infoFactory.addOperation("$getResource");
79
80         infoFactory.setConstructor(new String JavaDoc[] {"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