2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

Clover coverage report - Cactus 1.8dev for J2EE API 1.3
Coverage timestamp: Sun Mar 26 2006 18:50:18 BRT
file stats: LOC: 135   Methods: 3
NCLOC: 65   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
ContainerFactory.java 0% 5.9% 33.3% 8.3%
coverage coverage
 1   
 /* 
 2   
  * ========================================================================
 3   
  * 
 4   
  * Copyright 2003 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   
  */
 20   
 package org.apache.cactus.integration.ant.container;
 21   
 
 22   
 import java.util.MissingResourceException;
 23   
 import java.util.PropertyResourceBundle;
 24   
 import java.util.ResourceBundle;
 25   
 
 26   
 import org.apache.tools.ant.BuildException;
 27   
 
 28   
 /**
 29   
  * Factory for container support classes.
 30   
  * 
 31   
  * @version $Id: ContainerFactory.java 238810 2004-02-29 10:05:26Z vmassol $
 32   
  */
 33   
 public class ContainerFactory
 34   
 {
 35   
 
 36   
     // Constants ---------------------------------------------------------------
 37   
 
 38   
     /**
 39   
      * Name of the resource bundle that contains the definitions of the
 40   
      * default containers supported by this element.
 41   
      */
 42   
     private static final String DEFAULT_CONTAINERS_BUNDLE =
 43   
         "org.apache.cactus.integration.ant.container.default";
 44   
 
 45   
     // Instance Variables ------------------------------------------------------
 46   
 
 47   
     /**
 48   
      * The list of nested container elements.
 49   
      */
 50   
     private ResourceBundle defaultContainers;
 51   
 
 52   
     // Constructors ------------------------------------------------------------
 53   
 
 54   
     /**
 55   
      * Constructor.
 56   
      */
 57  6
     public ContainerFactory()
 58   
     {
 59  6
         defaultContainers =
 60   
             PropertyResourceBundle.getBundle(DEFAULT_CONTAINERS_BUNDLE);
 61   
     }
 62   
 
 63   
     // Public Methods ----------------------------------------------------------
 64   
 
 65   
     /**
 66   
      * Creates and returns the implementation of the <code>Container</code> 
 67   
      * interface which is mapped to the specified name.
 68   
      * 
 69   
      * @param theName The name of the container
 70   
      * @return The instantiated container
 71   
      * @throws BuildException If there was a problem creating the container
 72   
      */
 73  0
     public final Container createContainer(String theName) throws BuildException
 74   
     {
 75  0
         Container container = null;
 76  0
         try
 77   
         {
 78  0
             String className = defaultContainers.getString(theName);
 79  0
             if (className == null)
 80   
             {
 81  0
                 throw unsupportedContainer(theName, null);
 82   
             }
 83  0
             Class clazz = Class.forName(className);
 84  0
             container = (Container) clazz.newInstance();
 85   
         }
 86   
         catch (MissingResourceException mre)
 87   
         {
 88  0
             throw unsupportedContainer(theName, mre);
 89   
         }
 90   
         catch (ClassCastException cce)
 91   
         {
 92  0
             throw unsupportedContainer(theName, cce);
 93   
         }
 94   
         catch (ClassNotFoundException cnfe)
 95   
         {
 96  0
             throw unsupportedContainer(theName, cnfe);
 97   
         }
 98   
         catch (InstantiationException ie)
 99   
         {
 100  0
             throw unsupportedContainer(theName, ie);
 101   
         }
 102   
         catch (IllegalAccessException iae)
 103   
         {
 104  0
             throw unsupportedContainer(theName, iae);
 105   
         }
 106  0
         return container;
 107   
     }
 108   
 
 109   
     // Private Methods ---------------------------------------------------------
 110   
 
 111   
     /**
 112   
      * Creates an exception that indicates that a specific container is not 
 113   
      * supported. 
 114   
      * 
 115   
      * @param theName The container name
 116   
      * @param theCause The root cause of the exception
 117   
      * @return The created exception
 118   
      */
 119  0
     private BuildException unsupportedContainer(String theName,
 120   
         Exception theCause)
 121   
     {
 122  0
         if (theCause != null)
 123   
         {
 124  0
             return new BuildException("The container '" + theName 
 125   
                 + "' is not supported", theCause);
 126   
         }
 127   
         else
 128   
         {
 129  0
             return new BuildException("The container '" + theName 
 130   
                 + "' is not supported");
 131   
         }
 132   
     }
 133   
 
 134   
 }
 135