Home » geronimo-2.2-source-release » org.apache.geronimo.webservices.jaxr » [javadoc | source]

    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 javax.xml.registry.ConnectionFactory;
   20   import javax.xml.registry.JAXRException;
   21   
   22   import org.slf4j.Logger;
   23   import org.slf4j.LoggerFactory;
   24   import org.apache.geronimo.gbean.GBeanInfo;
   25   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   26   import org.apache.geronimo.naming.ResourceSource;
   27   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   28   
   29   /**
   30    * Simple GBean to provide access to a JAXR ConnectionFactory
   31    *
   32    * @version $Rev: 653218 $ $Date: 2008-05-04 07:45:02 -0700 (Sun, 04 May 2008) $
   33    */
   34   public class JAXRGBean implements ResourceSource
   35   {
   36       private static final Logger log = LoggerFactory.getLogger(JAXRGBean.class);
   37   
   38       private final ClassLoader cl;
   39       private final String connectionFactoryClass;
   40   
   41       public JAXRGBean(String connectionFactoryClass, ClassLoader cl) {
   42           this.cl = cl;
   43           this.connectionFactoryClass = connectionFactoryClass;
   44       }
   45   
   46       /**
   47        * Returns a fresh, new implementation of javax.xml.registry.ConnectionFactory
   48        *
   49        * @return ConnectionFactory
   50        */
   51       public Object $getResource() {
   52           if (connectionFactoryClass != null) {
   53               System.setProperty("javax.xml.registry.ConnectionFactoryClass", 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   
   71       public static final GBeanInfo GBEAN_INFO;
   72   
   73       static {
   74           GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(JAXRGBean.class,
   75                   NameFactory.JAXR_CONNECTION_FACTORY);
   76   
   77           infoFactory.addAttribute("connectionFactoryClass", String.class, true, true);
   78           infoFactory.addAttribute("classLoader", ClassLoader.class, false);
   79   
   80           infoFactory.addOperation("$getResource");
   81   
   82           infoFactory.setConstructor(new String[] {"connectionFactoryClass", "classLoader"});
   83   
   84           GBEAN_INFO = infoFactory.getBeanInfo();
   85       }
   86   
   87       public static GBeanInfo getGBeanInfo() {
   88           return GBEAN_INFO;
   89       }
   90   
   91   
   92   }

Home » geronimo-2.2-source-release » org.apache.geronimo.webservices.jaxr » [javadoc | source]