Clover coverage report - Cactus 1.5 for J2EE API 1.2
Coverage timestamp: Wed Feb 18 2004 09:04:33 EST
file stats: LOC: 191   Methods: 3
NCLOC: 79   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ApplicationXmlIo.java 12.5% 31.8% 33.3% 27.3%
coverage coverage
 1   
 /*
 2   
  * ====================================================================
 3   
  *
 4   
  * The Apache Software License, Version 1.1
 5   
  *
 6   
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
 7   
  * reserved.
 8   
  *
 9   
  * Redistribution and use in source and binary forms, with or without
 10   
  * modification, are permitted provided that the following conditions
 11   
  * are met:
 12   
  *
 13   
  * 1. Redistributions of source code must retain the above copyright
 14   
  *    notice, this list of conditions and the following disclaimer.
 15   
  *
 16   
  * 2. Redistributions in binary form must reproduce the above copyright
 17   
  *    notice, this list of conditions and the following disclaimer in
 18   
  *    the documentation and/or other materials provided with the
 19   
  *    distribution.
 20   
  *
 21   
  * 3. The end-user documentation included with the redistribution, if
 22   
  *    any, must include the following acknowlegement:
 23   
  *       "This product includes software developed by the
 24   
  *        Apache Software Foundation (http://www.apache.org/)."
 25   
  *    Alternately, this acknowlegement may appear in the software itself,
 26   
  *    if and wherever such third-party acknowlegements normally appear.
 27   
  *
 28   
  * 4. The names "The Jakarta Project", "Cactus" and "Apache Software
 29   
  *    Foundation" must not be used to endorse or promote products
 30   
  *    derived from this software without prior written permission. For
 31   
  *    written permission, please contact apache@apache.org.
 32   
  *
 33   
  * 5. Products derived from this software may not be called "Apache"
 34   
  *    nor may "Apache" appear in their names without prior written
 35   
  *    permission of the Apache Group.
 36   
  *
 37   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 38   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 39   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 40   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 41   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 42   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 43   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 44   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 45   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 46   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 47   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 48   
  * SUCH DAMAGE.
 49   
  * ====================================================================
 50   
  *
 51   
  * This software consists of voluntary contributions made by many
 52   
  * individuals on behalf of the Apache Software Foundation.  For more
 53   
  * information on the Apache Software Foundation, please see
 54   
  * <http://www.apache.org/>.
 55   
  *
 56   
  */
 57   
 package org.apache.cactus.integration.ant.deployment;
 58   
 
 59   
 import java.io.File;
 60   
 import java.io.FileInputStream;
 61   
 import java.io.IOException;
 62   
 import java.io.InputStream;
 63   
 
 64   
 import javax.xml.parsers.DocumentBuilder;
 65   
 import javax.xml.parsers.DocumentBuilderFactory;
 66   
 import javax.xml.parsers.ParserConfigurationException;
 67   
 
 68   
 import org.xml.sax.EntityResolver;
 69   
 import org.xml.sax.InputSource;
 70   
 import org.xml.sax.SAXException;
 71   
 
 72   
 /**
 73   
  * Provides convenience methods for reading and writing enterprise application
 74   
  * deployment descriptors (application.xml).
 75   
  *
 76   
  * @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
 77   
  *
 78   
  * @since Cactus 1.5
 79   
  * @version $Id: ApplicationXmlIo.java,v 1.4.2.1 2003/10/25 17:22:05 vmassol Exp $
 80   
  */
 81   
 public class ApplicationXmlIo
 82   
 {
 83   
     
 84   
     // Inner Classes -----------------------------------------------------------
 85   
 
 86   
     /**
 87   
      * Implementation of the SAX EntityResolver interface that looks up the
 88   
      * application DTDs from the JAR.
 89   
      */
 90   
     private static class ApplicationXmlEntityResolver implements EntityResolver
 91   
     {
 92   
 
 93   
         /**
 94   
          * @see org.xml.sax.EntityResolver#resolveEntity
 95   
          */
 96  0
         public InputSource resolveEntity(String thePublicId, String theSystemId)
 97   
             throws SAXException, IOException
 98   
         {
 99  0
             ApplicationXmlVersion version =
 100   
                 ApplicationXmlVersion.valueOf(thePublicId);
 101  0
             if (version != null)
 102   
             {
 103  0
                 String fileName = version.getSystemId().substring(
 104   
                     version.getSystemId().lastIndexOf('/'));
 105  0
                 InputStream in = this.getClass().getResourceAsStream(
 106   
                     "/org/apache/cactus/integration/ant/deployment/resources"
 107   
                     + fileName);
 108  0
                 if (in != null)
 109   
                 {
 110  0
                     return new InputSource(in);
 111   
                 }
 112   
             }
 113  0
             return null;
 114   
         }
 115   
 
 116   
     }
 117   
 
 118   
     // Public Methods ----------------------------------------------------------
 119   
 
 120   
     /**
 121   
      * Parses a deployment descriptor stored in a regular file.
 122   
      * 
 123   
      * @param theFile The file to parse
 124   
      * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
 125   
      *        use the default
 126   
      * @return The parsed descriptor
 127   
      * @throws SAXException If the file could not be parsed
 128   
      * @throws ParserConfigurationException If the XML parser was not correctly
 129   
      *          configured
 130   
      * @throws IOException If an I/O error occurs
 131   
      */
 132  0
     public static ApplicationXml parseApplicationXmlFromFile(File theFile,
 133   
         EntityResolver theEntityResolver)
 134   
         throws SAXException, ParserConfigurationException, IOException
 135   
     {
 136  0
         InputStream in = null;
 137  0
         try
 138   
         {
 139  0
             in = new FileInputStream(theFile);
 140  0
             return parseApplicationXml(in, theEntityResolver);
 141   
         }
 142   
         finally
 143   
         {
 144  0
             if (in != null)
 145   
             {
 146  0
                 try
 147   
                 {
 148  0
                     in.close();
 149   
                 }
 150   
                 catch (IOException ioe)
 151   
                 {
 152   
                     // we'll pass on the original IO error, so ignore this one
 153   
                 }
 154   
             }
 155   
         }
 156   
     }
 157   
     
 158   
     /**
 159   
      * Parses a deployment descriptor provided as input stream.
 160   
      * 
 161   
      * @param theInput The input stream
 162   
      * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
 163   
      *        use the default
 164   
      * @return The parsed descriptor
 165   
      * @throws SAXException If the input could not be parsed
 166   
      * @throws ParserConfigurationException If the XML parser was not correctly
 167   
      *          configured
 168   
      * @throws IOException If an I/O error occurs
 169   
      */
 170  4
     public static ApplicationXml parseApplicationXml(InputStream theInput,
 171   
         EntityResolver theEntityResolver)
 172   
         throws SAXException, ParserConfigurationException, IOException
 173   
     {
 174  4
         DocumentBuilderFactory factory =
 175   
             DocumentBuilderFactory.newInstance();
 176  4
         factory.setValidating(false);
 177  4
         factory.setNamespaceAware(false);
 178  4
         DocumentBuilder builder = factory.newDocumentBuilder();
 179  4
         if (theEntityResolver != null)
 180   
         {
 181  0
             builder.setEntityResolver(theEntityResolver);
 182   
         }
 183   
         else
 184   
         {
 185  4
             builder.setEntityResolver(new ApplicationXmlEntityResolver());
 186   
         }
 187  4
         return new DefaultApplicationXml(builder.parse(theInput));
 188   
     }
 189   
 
 190   
 }
 191