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.openejb;
018
019 import javax.management.j2ee.Management;
020 import javax.management.j2ee.ManagementHome;
021
022 import org.apache.geronimo.gbean.GBeanInfo;
023 import org.apache.geronimo.gbean.GBeanInfoBuilder;
024 import org.apache.geronimo.gbean.GBeanLifecycle;
025 import org.apache.openejb.assembler.classic.EjbJarInfo;
026 import org.apache.openejb.config.EjbModule;
027 import org.apache.openejb.jee.EjbJar;
028 import org.apache.openejb.jee.StatelessBean;
029 import org.apache.openejb.mgmt.MEJBBean;
030
031 public class MEJBGBean implements GBeanLifecycle {
032
033 public static final GBeanInfo GBEAN_INFO;
034
035 private EjbContainer ejbContainer;
036
037 public MEJBGBean(EjbContainer ejbContainer) {
038 this.ejbContainer = ejbContainer;
039 }
040
041 public void doStart() throws Exception {
042 EjbJar ejbJar = new EjbJar();
043 StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean("MEJB",MEJBBean.class.getName()));
044 bean.setHomeAndRemote(ManagementHome.class, Management.class);
045
046 ClassLoader cl = MEJBBean.class.getClassLoader();
047 OpenEjbSystem openEjbSystem = ejbContainer.getOpenEjbSystem();
048 //A dummy URL MEJBGBean.class.getResource( "" ).toString() to avoid the "java.net.MalformedURLException: no protocol: MEJBGBean" when startup
049 EjbJarInfo ejbJarInfo = openEjbSystem.configureApplication(new EjbModule(cl, getClass().getSimpleName(), MEJBGBean.class.getResource( "" ).toString(), ejbJar, null));
050 openEjbSystem.createEjbJar(ejbJarInfo, cl);
051 }
052
053 static {
054 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(MEJBGBean.class);
055 infoBuilder.addReference("StatelessContainer", EjbContainer.class);
056 infoBuilder.setConstructor(new String[]{"StatelessContainer"});
057 GBEAN_INFO = infoBuilder.getBeanInfo();
058 }
059
060 public static GBeanInfo getGBeanInfo() {
061 return GBEAN_INFO;
062 }
063
064 public void doStop() throws Exception {
065
066 }
067
068 public void doFail() {
069
070 }
071
072 }