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.ejb;
019    
020    import java.net.URL;
021    
022    import javax.naming.Context;
023    
024    import org.apache.geronimo.gbean.GBeanInfo;
025    import org.apache.geronimo.gbean.GBeanInfoBuilder;
026    import org.apache.geronimo.gbean.GBeanLifecycle;
027    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
028    import org.apache.geronimo.jaxws.PortInfo;
029    import org.apache.geronimo.kernel.Kernel;
030    import org.apache.geronimo.openejb.EjbDeployment;
031    import org.apache.geronimo.webservices.SoapHandler;
032    import org.apache.openejb.DeploymentInfo;
033    
034    /**
035     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
036     */
037    public class EJBWebServiceGBean implements GBeanLifecycle {
038    
039        private SoapHandler soapHandler;
040        private String location;
041        private EJBWebServiceContainer container;
042    
043        public EJBWebServiceGBean(EjbDeployment ejbDeploymentContext,
044                                  PortInfo portInfo,                              
045                                  Kernel kernel,
046                                  URL configurationBaseUrl,                              
047                                  SoapHandler soapHandler,
048                                  String securityRealmName,
049                                  String realmName,
050                                  String transportGuarantee,
051                                  String authMethod,
052                                  String[] virtualHosts) throws Exception {        
053            if (ejbDeploymentContext == null || soapHandler == null || portInfo == null) {
054                return;
055            }
056                    
057            this.soapHandler = soapHandler;
058            this.location = portInfo.getLocation();
059            
060            assert this.location != null : "null location received";
061                    
062            String beanClassName = ejbDeploymentContext.getBeanClass().getName();    
063            Context context = ejbDeploymentContext.getComponentContext();        
064            ClassLoader classLoader = ejbDeploymentContext.getClassLoader();
065            DeploymentInfo deploymnetInfo = ejbDeploymentContext.getDeploymentInfo();
066            
067            this.container = 
068                new EJBWebServiceContainer(portInfo, beanClassName, classLoader, 
069                                           context, configurationBaseUrl, deploymnetInfo);
070            this.container.init();
071             
072            if (soapHandler != null) {
073                soapHandler.addWebService(this.location, 
074                                          virtualHosts, 
075                                          this.container, 
076                                          securityRealmName, 
077                                          realmName, 
078                                          transportGuarantee, 
079                                          authMethod, 
080                                          classLoader);
081            }
082            
083        }
084    
085        public void doStart() throws Exception {
086        }
087    
088        public void doStop() throws Exception {
089            if (this.soapHandler != null) {
090                this.soapHandler.removeWebService(this.location);
091            } 
092            if (this.container != null) {
093                this.container.destroy();
094            }
095        }
096    
097        public void doFail() {
098        }
099    
100        public static final GBeanInfo GBEAN_INFO;
101    
102        static {
103            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(EJBWebServiceGBean.class, EJBWebServiceGBean.class, NameFactory.WEB_SERVICE_LINK);
104            
105            infoFactory.addReference("EjbDeployment", EjbDeployment.class);
106            infoFactory.addAttribute("portInfo", PortInfo.class, true);       
107            infoFactory.addAttribute("kernel", Kernel.class, false);
108            infoFactory.addAttribute("configurationBaseUrl", URL.class, true);
109            infoFactory.addAttribute("securityRealmName", String.class, true);
110            infoFactory.addAttribute("realmName", String.class, true);
111            infoFactory.addAttribute("transportGuarantee", String.class, true);
112            infoFactory.addAttribute("authMethod", String.class, true);
113            infoFactory.addAttribute("virtualHosts", String[].class, true);
114            infoFactory.addReference("WebServiceContainer", SoapHandler.class);
115            
116            infoFactory.setConstructor(new String[]{
117                    "EjbDeployment",
118                    "portInfo",
119                    "kernel",
120                    "configurationBaseUrl",
121                    "WebServiceContainer",
122                    "securityRealmName",
123                    "realmName",
124                    "transportGuarantee",
125                    "authMethod",
126                    "virtualHosts"
127            });
128    
129            
130            GBEAN_INFO = infoFactory.getBeanInfo();
131        }
132    
133        public static GBeanInfo getGBeanInfo() {
134            return GBEAN_INFO;
135        }
136    
137    }