Coverage Report - org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
PersistenceBrokerFactoryFactory
N/A
N/A
5
 
 1  
 package org.apache.ojb.broker.core;
 2  
 
 3  
 /* Copyright 2003-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 import org.apache.ojb.broker.OJBRuntimeException;
 19  
 import org.apache.ojb.broker.util.ClassHelper;
 20  
 import org.apache.ojb.broker.util.configuration.Configuration;
 21  
 import org.apache.ojb.broker.util.configuration.Configurator;
 22  
 import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
 23  
 import org.apache.ojb.broker.util.logging.Logger;
 24  
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 25  
 
 26  
 /**
 27  
  *
 28  
  * @author Thomas Mahler
 29  
  * @version $Id: PersistenceBrokerFactoryFactory.java,v 1.1 2007-08-24 22:17:35 ewestfal Exp $
 30  
  */
 31  
 public class PersistenceBrokerFactoryFactory
 32  
 {
 33  
     private static Logger log = LoggerFactory.getBootLogger();
 34  
 
 35  
     private static final String PBF_KEY = "PersistenceBrokerFactoryClass";
 36  
     private static PersistenceBrokerFactoryIF singleton = init();
 37  
 
 38  
     /**
 39  
      * Returns an {@link PersistenceBrokerFactoryIF} instance.
 40  
      */
 41  
     public static PersistenceBrokerFactoryIF instance()
 42  
     {
 43  
         return singleton;
 44  
     }
 45  
 
 46  
     private static PersistenceBrokerFactoryIF init()
 47  
     {
 48  
         if (log.isDebugEnabled()) log.debug("Instantiate PersistenceBrokerFactory");
 49  
         Class pbfClass = null;
 50  
         try
 51  
         {
 52  
             Configurator configurator = OjbConfigurator.getInstance();
 53  
             Configuration config = configurator.getConfigurationFor(null);
 54  
             pbfClass = config.getClass(PBF_KEY, null);
 55  
             if(pbfClass == null)
 56  
             {
 57  
                 log.error("Creation of PersistenceBrokerFactory (PBF) instance failed, can't get PBF class object");
 58  
                 throw new OJBRuntimeException("Property for key '" + PBF_KEY + "' can not be found in properties file");
 59  
             }
 60  
             PersistenceBrokerFactoryIF result = (PersistenceBrokerFactoryIF) ClassHelper.newInstance(pbfClass);
 61  
             configurator.configure(result);
 62  
             log.info("PersistencebrokerFactory class instantiated: " + result);
 63  
             return result;
 64  
         }
 65  
         catch (Exception e)
 66  
         {
 67  
             if(e instanceof OJBRuntimeException)
 68  
             {
 69  
                 throw (OJBRuntimeException) e;
 70  
             }
 71  
             else
 72  
             {
 73  
                 throw new OJBRuntimeException("Error while instantiation of PersistenceBrokerFactory class", e);
 74  
             }
 75  
         }
 76  
     }
 77  
 }