Clover coverage report - JFox Service-Oriented Application Framework - 1.0
Coverage timestamp: 星期一 八月 21 2006 22:56:01 CST
file stats: LOC: 119   Methods: 5
NCLOC: 51   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
PersistenceManagerFactoryServiceImpl.java 75% 87.5% 80% 84%
coverage coverage
 1   
 /**
 2   
  * @(#)PersistenceManagerFactoryServiceImpl.java
 3   
  * 
 4   
  * JFoxSOAF, Service-Oriented Application Framework
 5   
  * 
 6   
  * Copyright(c) JFoxSOAF Team
 7   
  * 
 8   
  * Licensed under the GNU LGPL, Version 2.1 (the "License"); 
 9   
  * you may not use this file except in compliance with the License. 
 10   
  * You may obtain a copy of the License at  
 11   
  * 
 12   
  * http://www.gnu.org/copyleft/lesser.html
 13   
  * 
 14   
  * Unless required by applicable law or agreed to in writing, software
 15   
  * distributed under the License is distributed on an "AS IS" BASIS, 
 16   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 17   
  * See the License for the specific language governing permissions and 
 18   
  * limitations under the License. 
 19   
  * 
 20   
  * For more information, please visit:
 21   
  * http://sourceforge.net/projects/jfox 
 22   
  */
 23   
 
 24   
 package org.huihoo.jfox.soaf.services.persistence;
 25   
 
 26   
 import java.io.IOException;
 27   
 import java.util.HashMap;
 28   
 import java.util.Iterator;
 29   
 import java.util.Properties;
 30   
 import java.util.Set;
 31   
 
 32   
 import javax.jdo.PersistenceManagerFactory;
 33   
 
 34   
 import org.apache.commons.logging.Log;
 35   
 import org.apache.commons.logging.LogFactory;
 36   
 import org.huihoo.jfox.soaf.util.resource.ResourceHelper;
 37   
 import org.jpox.PersistenceManagerFactoryImpl;
 38   
 import org.picocontainer.Startable;
 39   
 
 40   
 /**
 41   
  * <p>
 42   
  * PersistenceManagerFactory Service Implementation
 43   
  * </p>
 44   
  * 
 45   
  * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
 46   
  * @version $Revision: 1.1 $ $Date: 2006/02/15 08:45:45 $
 47   
  * @version Revision: 1.0
 48   
  */
 49   
 
 50   
 public class PersistenceManagerFactoryServiceImpl implements
 51   
         PersistenceManagerFactoryService, Startable {
 52   
 
 53   
     private final Log logger = LogFactory.getLog(getClass());
 54   
 
 55   
     private static String JDO_MULTI_CONFIG = "jdo-multi.properties";
 56   
 
 57   
     private static String JDO_DEFAULT_CONFIG = "jdo.default";
 58   
 
 59   
     private Properties props;
 60   
 
 61   
     private HashMap hashMap = new HashMap();
 62   
 
 63   
     /**
 64   
      * @see org.huihoo.jfox.soaf.services.persistence.PersistenceManagerFactoryService#getPersistenceManagerFactory(java.lang.String)
 65   
      */
 66  1
     public PersistenceManagerFactory getPersistenceManagerFactory(String key) {
 67  1
         if (key == null) {
 68  1
             return (PersistenceManagerFactory) hashMap.get(JDO_DEFAULT_CONFIG);
 69   
         } else {
 70  0
             return (PersistenceManagerFactory) hashMap.get(key);
 71   
         }
 72   
     }
 73   
 
 74   
     /**
 75   
      * @see org.picocontainer.Startable#start()
 76   
      */
 77  9
     public void start() {
 78  9
         loadConfig();
 79   
     }
 80   
 
 81   
     /**
 82   
      * @see org.picocontainer.Startable#stop()
 83   
      */
 84  0
     public void stop() {        
 85   
     }
 86   
 
 87   
     /**
 88   
      * Load configuation.
 89   
      */
 90  9
     private void loadConfig() {
 91  9
         try {
 92  9
             props = ResourceHelper.getResourceAsProperties(JDO_MULTI_CONFIG);
 93  9
             Set set = props.keySet();
 94  9
             Iterator iter = set.iterator();
 95  9
             while (iter.hasNext()) {
 96  9
                 String key = (String) iter.next();
 97  9
                 String value = props.getProperty(key);
 98  9
                 buildPersistenceManagerFactory(key, value);
 99   
             }
 100   
         } catch (Exception e) {
 101  0
             logger.error("JDO multi configuration initialization failed ", e);
 102   
         }
 103   
     }
 104   
 
 105   
     /**
 106   
      * Build PersistenceManagerFactory.
 107   
      * 
 108   
      * @param key
 109   
      * @param value
 110   
      * @throws IOException
 111   
      */
 112  9
     private void buildPersistenceManagerFactory(String key, String value)
 113   
             throws IOException {
 114  9
         Properties prop = ResourceHelper.getResourceAsProperties(value);
 115  9
         PersistenceManagerFactory pmFactory = PersistenceManagerFactoryImpl.getPersistenceManagerFactory(prop);    
 116  9
         hashMap.put(key, pmFactory);
 117   
     }
 118   
     
 119   
 }