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 // This source code implements specifications defined by the Java
019 // Community Process. In order to remain compliant with the specification
020 // DO NOT add / change / or delete method signatures!
021 //
022 package javax.ejb.embeddable;
023
024 import java.util.Collections;
025 import java.util.List;
026
027 import javax.ejb.EJBException;
028 import javax.ejb.spi.EJBContainerProvider;
029 import org.apache.geronimo.osgi.locator.ProviderLocator;
030
031 public abstract class EJBContainer {
032
033 public static final String PROVIDER = "javax.ejb.embeddable.provider";
034 public static final String APP_NAME = "javax.ejb.embeddable.appName";
035 public static final String MODULES = "javax.ejb.embeddable.modules";
036
037 public EJBContainer() {
038 }
039
040 public abstract void close();
041
042 public static EJBContainer createEJBContainer() {
043 return createEJBContainer(Collections.EMPTY_MAP);
044 }
045
046 public static EJBContainer createEJBContainer(java.util.Map<?, ?> properties) {
047 if (properties == null) {
048 properties = Collections.EMPTY_MAP;
049 }
050
051 try {
052 ClassLoader loader = Thread.currentThread().getContextClassLoader();
053 // go check the loader files.
054 List<Object> providers = ProviderLocator.getServices(EJBContainerProvider.class.getName(), EJBContainer.class, loader);
055 for (Object o : providers) {
056 EJBContainer container = ((EJBContainerProvider) o).createEJBContainer(properties);
057 if (container != null) {
058 return container;
059 }
060 }
061 throw new EJBException("Provider error. No provider definition found");
062 } catch (EJBException e) {
063 // if the container provider throws an EJBException, don't wrap another one
064 // around the original.
065 throw e;
066 } catch (Exception e) {
067 throw new EJBException("Provider error. No provider found", e);
068 }
069 }
070
071 public abstract javax.naming.Context getContext();
072 }