Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.spi » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.spi;
   15   
   16   import org.apache.webbeans.config.OpenWebBeansConfiguration;
   17   import org.apache.webbeans.config.WebBeansFinder;
   18   import org.apache.webbeans.exception.WebBeansConfigurationException;
   19   
   20   /**
   21    * Loads any Service Provider Interface implementation declared in the 
   22    * {@link OpenWebBeansConfiguration}.
   23    * 
   24    * The Configuration for Services looks like
   25    * <pre>
   26    * org.apache.webbeans.spi.MyServiceInterface=my.package.webbeans.spi.MyServiceImplementation
   27    * </pre>
   28    * 
   29    * 
   30    */
   31   public class ServiceLoader
   32   {
   33       private static OpenWebBeansConfiguration config = OpenWebBeansConfiguration.getInstance();
   34       
   35       /**
   36        * Get a new service singleton instance for the given interface.
   37        * 
   38        * @param serviceInterface
   39        * @return the new service implementation
   40        */
   41       @SuppressWarnings("unchecked")
   42       public static <T> T getService(Class<T> serviceInterface)
   43       {
   44           String implName = config.getProperty(serviceInterface.getName());
   45           if (implName == null)
   46           {
   47               throw new WebBeansConfigurationException("Cannot find Service configuration for " + 
   48                                                        serviceInterface.getName() +
   49                                                        " in the openwebbeans-default.properties file");
   50           }
   51           return (T) WebBeansFinder.getSingletonInstance(implName);
   52       }
   53   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.spi » [javadoc | source]