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 018 package org.apache.geronimo.axis2.builder; 019 020 import org.apache.geronimo.jaxws.builder.JAXWSServiceRefBuilder; 021 import org.apache.geronimo.kernel.GBeanAlreadyExistsException; 022 import org.apache.geronimo.kernel.GBeanNotFoundException; 023 import org.apache.geronimo.kernel.repository.Environment; 024 import org.apache.geronimo.xbeans.javaee.PortComponentRefType; 025 import org.apache.geronimo.xbeans.javaee.ServiceRefType; 026 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType; 027 import org.apache.geronimo.j2ee.deployment.EARContext; 028 import org.apache.geronimo.j2ee.deployment.Module; 029 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 030 import org.apache.geronimo.axis2.client.Axis2ConfigGBean; 031 import org.apache.geronimo.common.DeploymentException; 032 import org.apache.geronimo.gbean.AbstractName; 033 import org.apache.geronimo.gbean.GBeanData; 034 import org.apache.geronimo.gbean.GBeanInfo; 035 import org.apache.geronimo.gbean.GBeanInfoBuilder; 036 import org.apache.geronimo.naming.deployment.ServiceRefBuilder; 037 038 import javax.xml.namespace.QName; 039 import java.net.URI; 040 import java.util.Map; 041 042 public class Axis2ServiceRefBuilder extends JAXWSServiceRefBuilder { 043 044 private final Axis2Builder axis2Builder; 045 046 public Axis2ServiceRefBuilder(Environment defaultEnvironment, 047 String[] eeNamespaces, 048 Axis2Builder axis2Builder) { 049 super(defaultEnvironment, eeNamespaces); 050 this.axis2Builder = axis2Builder; 051 } 052 053 public Object createService(ServiceRefType serviceRef, GerServiceRefType gerServiceRef, 054 Module module, ClassLoader cl, Class serviceInterfaceClass, 055 QName serviceQName, URI wsdlURI, Class serviceReferenceType, 056 Map<Class, PortComponentRefType> portComponentRefMap) throws DeploymentException { 057 registerConfigGBean(module); 058 return this.axis2Builder.createService(serviceInterfaceClass, serviceReferenceType, wsdlURI, 059 serviceQName, portComponentRefMap, serviceRef.getHandlerChains(), 060 gerServiceRef, module, cl); 061 } 062 063 private void registerConfigGBean(Module module) throws DeploymentException { 064 EARContext context = module.getEarContext(); 065 AbstractName containerFactoryName = context.getNaming().createChildName( 066 module.getModuleName(), Axis2ConfigGBean.GBEAN_INFO.getName(), 067 NameFactory.GERONIMO_SERVICE); 068 069 try { 070 context.getGBeanInstance(containerFactoryName); 071 } catch (GBeanNotFoundException e1) { 072 GBeanData configGBeanData = new GBeanData(containerFactoryName, Axis2ConfigGBean.GBEAN_INFO); 073 configGBeanData.setAttribute("moduleName", module.getModuleName()); 074 075 try { 076 context.addGBean(configGBeanData); 077 } catch (GBeanAlreadyExistsException e) { 078 throw new DeploymentException("Could not add config gbean", e); 079 } 080 } 081 } 082 083 public static final GBeanInfo GBEAN_INFO; 084 085 static { 086 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic( 087 Axis2ServiceRefBuilder.class, NameFactory.MODULE_BUILDER); 088 infoBuilder.addInterface(ServiceRefBuilder.class); 089 infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, 090 true); 091 infoBuilder.addAttribute("eeNamespaces", String[].class, true, true); 092 infoBuilder.addReference("Axis2Builder", Axis2Builder.class, 093 NameFactory.MODULE_BUILDER); 094 095 infoBuilder.setConstructor(new String[] { "defaultEnvironment", 096 "eeNamespaces", "Axis2Builder" }); 097 098 GBEAN_INFO = infoBuilder.getBeanInfo(); 099 } 100 101 public static GBeanInfo getGBeanInfo() { 102 return Axis2ServiceRefBuilder.GBEAN_INFO; 103 } 104 }