001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.axis2.client;
018
019 import java.net.URL;
020
021 import org.apache.axis2.context.ConfigurationContext;
022 import org.apache.axis2.jaxws.ClientConfigurationFactory;
023 import org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl;
024 import org.apache.axis2.metadata.registry.MetadataFactoryRegistry;
025 import org.apache.commons.logging.Log;
026 import org.apache.commons.logging.LogFactory;
027 import org.apache.geronimo.gbean.AbstractName;
028 import org.apache.geronimo.gbean.GBeanInfo;
029 import org.apache.geronimo.gbean.GBeanInfoBuilder;
030 import org.apache.geronimo.gbean.GBeanLifecycle;
031 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
032 import org.apache.geronimo.kernel.Kernel;
033
034 public class Axis2ConfigGBean implements GBeanLifecycle {
035
036 private static final Log LOG = LogFactory.getLog(Axis2ConfigGBean.class);
037
038 private AbstractName moduleName;
039 private ClassLoader classLoder;
040
041 public Axis2ConfigGBean(ClassLoader classLoader,
042 Kernel kernel,
043 URL configurationBaseUrl,
044 AbstractName moduleName) {
045 this.moduleName = moduleName;
046 this.classLoder = classLoader;
047 }
048
049 public synchronized static Axis2ClientConfigurationFactory registerClientConfigurationFactory() {
050 ClientConfigurationFactory factory =
051 (ClientConfigurationFactory)MetadataFactoryRegistry.getFactory(ClientConfigurationFactory.class);
052 if (factory instanceof Axis2ClientConfigurationFactory) {
053 return (Axis2ClientConfigurationFactory)factory;
054 } else {
055 factory = new Axis2ClientConfigurationFactory(false);
056 MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, factory);
057 LOG.debug("Registered client configuration factory: " + factory);
058 // ensure that the factory was installed at the right time
059 if (factory != DescriptionFactoryImpl.getClientConfigurationFactory()) {
060 throw new RuntimeException("Client configuration factory was registered too late");
061 }
062 return (Axis2ClientConfigurationFactory)factory;
063 }
064 }
065
066 public void doStart() throws Exception {
067 registerClientConfigurationFactory();
068 }
069
070 public void doStop() throws Exception {
071 ConfigurationContext configContext =
072 registerClientConfigurationFactory().clearCache(this.classLoder);
073 DescriptionFactoryImpl.clearServiceDescriptionCache(configContext);
074 }
075
076 public void doFail() {
077 }
078
079 public static final GBeanInfo GBEAN_INFO;
080
081 static {
082 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(Axis2ConfigGBean.class, Axis2ConfigGBean.class, NameFactory.GERONIMO_SERVICE);
083
084 infoFactory.addAttribute("classLoader", ClassLoader.class, false);
085 infoFactory.addAttribute("kernel", Kernel.class, false);
086 infoFactory.addAttribute("configurationBaseUrl", URL.class, true);
087 infoFactory.addAttribute("moduleName", AbstractName.class, true);
088
089 infoFactory.setConstructor(new String[]{"classLoader", "kernel", "configurationBaseUrl", "moduleName"});
090
091 GBEAN_INFO = infoFactory.getBeanInfo();
092 }
093
094 public static GBeanInfo getGBeanInfo() {
095 return GBEAN_INFO;
096 }
097
098 }