Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 100   Methods: 4
NCLOC: 42   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TagHandlersTagHandler.java 100% 100% 100% 100%
coverage
 1   
 /*
 2   
  * Created on Oct 24, 2003
 3   
  *
 4   
  * To change the template for this generated file go to
 5   
  * Window>Preferences>Java>Code Generation>Code and Comments
 6   
  */
 7   
 package junit.extensions.xml.elements;
 8   
 
 9   
 import junit.extensions.xml.IXMLTestCase;
 10   
 import junit.extensions.xml.IXMLTestSuite;
 11   
 import junit.extensions.xml.XMLException;
 12   
 import junit.extensions.xml.XMLTagResourceBundle;
 13   
 
 14   
 import org.w3c.dom.Element;
 15   
 
 16   
 
 17   
 /**
 18   
  * Provide a mechanism for sending debug messages to the
 19   
  * test case developer.
 20   
  *
 21   
  * <H3>Tag Name</H3>
 22   
  * taghandlers
 23   
  * <H3>Attributes</H3>
 24   
  * <pre>
 25   
  * action  - add or remove
 26   
  * tagname - tag name to be processed by the handler.
 27   
  * classname - Classname of the taghandler.
 28   
  * </pre>
 29   
  * <H3>Examples</H3>
 30   
  * <pre>
 31   
  * &lt;taghandlers action="add" tagname="mytag" classname="jfcTags.MyTagHandler"/&gt;
 32   
  * </pre>
 33   
  *
 34   
  * @author Kevin Wilson
 35   
  */
 36   
 public class TagHandlersTagHandler extends AbstractTagHandler {
 37   
     /**
 38   
      * Constructor.
 39   
      * @param element Element to be processed by the tag handler.
 40   
      * @param testcase parent test case.
 41   
      */
 42  9
     public TagHandlersTagHandler(final Element element,
 43   
         final IXMLTestCase testcase) {
 44  9
         super(element, testcase);
 45   
     }
 46   
 
 47   
     /**
 48   
      * Constructor.
 49   
      * @param element Element to be processed by the tag handler.
 50   
      * @param testsuite parent test suite.
 51   
      */
 52  2
     public TagHandlersTagHandler(final Element element,
 53   
         final IXMLTestSuite testsuite) {
 54  2
         super(element, testsuite);
 55   
     }
 56   
 
 57   
     /**
 58   
      * Handle the XML processing of the tag 'taghandlers'.
 59   
      * @throws XMLException is thrown if the element cannot be understood.
 60   
      */
 61  5
     public void processElement() throws XMLException {
 62  5
         validateElement();
 63   
     }
 64   
 
 65   
     /**
 66   
      * Make sure the appropriate tag and attributes are used.
 67   
      * @throws XMLException when validation fails.
 68   
      */
 69  5
     public void validateElement() throws XMLException {
 70  5
         super.validateElement();
 71   
 
 72   
         // message is a required attribute
 73  5
         checkRequiredAttribute(ACTION);
 74  5
         checkRequiredAttribute(TAGNAME);
 75   
 
 76  5
         String action  = getString(ACTION);
 77  5
         String tagname = getString(TAGNAME);
 78   
 
 79  5
         if (ADD.equals(action)) {
 80  3
             checkRequiredAttribute(CLASSNAME);
 81   
 
 82  3
             String classname = getString(CLASSNAME);
 83   
 
 84  3
             try {
 85  3
                 Class clz = Class.forName(classname);
 86   
             } catch (ClassNotFoundException ex) {
 87  1
                 throw new XMLException("Class not found:" + classname, ex,
 88   
                     getElement(), null);
 89   
             }
 90   
 
 91  2
             XMLTagResourceBundle.addTagHandler(tagname, classname);
 92  2
         } else if (REMOVE.equals(action)) {
 93  1
             XMLTagResourceBundle.removeTagHandler(tagname);
 94   
         } else {
 95  1
             throw new XMLException("Invalid action:" + action, null,
 96   
                 getElement(), null);
 97   
         }
 98   
     }
 99   
 }
 100