Coverage report

  %line %branch
org.apache.torque.engine.platform.PlatformFactory
77% 
100% 

 1  
 package org.apache.torque.engine.platform;
 2  
 
 3  
 /*
 4  
  * Copyright 2003,2004 The Apache Software Foundation.
 5  
  * 
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  * 
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  * 
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.HashMap;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 
 24  
 /**
 25  
  * Factory class responsible to create Platform objects that
 26  
  * define RDBMS platform specific behaviour.
 27  
  *
 28  
  * @author Thomas Mahler
 29  
  * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
 30  
  * @version $Id: PlatformFactory.java,v 1.2 2004/02/22 06:27:19 jmcnally Exp $
 31  
  */
 32  0
 public class PlatformFactory
 33  
 {
 34  40
     private static HashMap platforms = new HashMap();
 35  80
     private static Log log = LogFactory.getLog(PlatformFactory.class);
 36  
 
 37  
     /**
 38  
      * Returns the Platform for a platform name.
 39  
      *
 40  
      * @param dbms name of the platform
 41  
      */
 42  
     public static Platform getPlatformFor(String dbms)
 43  
     {
 44  14324
         Platform result = null;
 45  14324
         String platformName = null;
 46  
 
 47  14324
         result = (Platform) getPlatforms().get(dbms);
 48  14324
         if (result == null)
 49  
         {
 50  
             try
 51  
             {
 52  40
                 platformName = getClassnameFor(dbms);
 53  40
                 Class platformClass = Class.forName(platformName);
 54  40
                 result = (Platform) platformClass.newInstance();
 55  
 
 56  
             }
 57  0
             catch (Throwable t)
 58  
             {
 59  0
                 log.warn("problems with platform " + platformName 
 60  
                         + ": " + t.getMessage());
 61  0
                 log.warn("Torque will use PlatformDefaultImpl instead");
 62  
 
 63  0
                 result = new PlatformDefaultImpl();
 64  40
             }
 65  40
             getPlatforms().put(dbms, result); // cache the Platform
 66  
         }
 67  14324
         return result;
 68  
     }
 69  
 
 70  
     /**
 71  
      * compute the name of the concrete Class representing the Platform
 72  
      * specified by <code>platform</code>
 73  
      * 
 74  
      * @param platform the name of the platform as specified in the repository
 75  
      */
 76  
     private static String getClassnameFor(String platform)
 77  
     {
 78  40
         String pf = "Default";
 79  40
         if (platform != null)
 80  
         {
 81  40
             pf = platform;
 82  
         }
 83  40
         return "org.apache.torque.engine.platform.Platform" + pf.substring(0, 1).toUpperCase() + pf.substring(1) + "Impl";
 84  
     }
 85  
 
 86  
     /**
 87  
      * Gets the platforms.
 88  
      * 
 89  
      * @return Returns a HashMap
 90  
      */
 91  
     private static HashMap getPlatforms()
 92  
     {
 93  14364
         return platforms;
 94  
     }
 95  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.