Clover coverage report - Code Coverage for hivemind-lib release 1.1-alpha-1
Coverage timestamp: Tue Jan 18 2005 07:56:07 EST
file stats: LOC: 86   Methods: 3
NCLOC: 48   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
GroovyScriptProcessor.java 100% 93.3% 100% 95%
coverage coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.lib.groovy;
 16   
 
 17   
 import groovy.lang.Binding;
 18   
 import groovy.lang.GroovyCodeSource;
 19   
 import groovy.lang.GroovyShell;
 20   
 import groovy.lang.Script;
 21   
 
 22   
 import java.io.IOException;
 23   
 
 24   
 import javax.xml.parsers.SAXParser;
 25   
 
 26   
 import org.apache.hivemind.ApplicationRuntimeException;
 27   
 import org.apache.hivemind.ClassResolver;
 28   
 import org.apache.hivemind.ErrorHandler;
 29   
 import org.apache.hivemind.Resource;
 30   
 import org.apache.hivemind.parse.DescriptorParser;
 31   
 import org.apache.hivemind.parse.ModuleDescriptor;
 32   
 import org.apache.hivemind.parse.XmlResourceProcessor;
 33   
 import org.xml.sax.SAXException;
 34   
 
 35   
 /**
 36   
  * This extension of the {@link org.apache.hivemind.parse.XmlResourceProcessor}is suitable for
 37   
  * processing Groovy scripts and is used internally by {@link GroovyModuleDescriptorProvider}.
 38   
  * 
 39   
  * @see org.apache.hivemind.lib.groovy.GroovyModuleDescriptorProvider
 40   
  * @author Knut Wannheden
 41   
  * @since 1.1
 42   
  */
 43   
 class GroovyScriptProcessor extends XmlResourceProcessor
 44   
 {
 45   
     private GroovyShell _groovyShell;
 46   
 
 47  2
     public GroovyScriptProcessor(ClassResolver resolver, ErrorHandler errorHandler)
 48   
     {
 49  2
         super(resolver, errorHandler);
 50   
     }
 51   
 
 52  3
     protected ModuleDescriptor parseResource(Resource resource, SAXParser parser,
 53   
             DescriptorParser contentHandler) throws SAXException, IOException
 54   
     {
 55  3
         HiveMindBuilder builder = new HiveMindBuilder(contentHandler);
 56   
 
 57  3
         GroovyCodeSource source = new GroovyCodeSource(resource.getResourceURL());
 58  3
         Script script;
 59   
 
 60  3
         try
 61   
         {
 62  3
             script = getGroovyShell().parse(source);
 63   
         }
 64   
         catch (Exception e)
 65   
         {
 66  0
             throw new ApplicationRuntimeException(e);
 67   
         }
 68   
 
 69  3
         Binding processorBinding = new Binding();
 70  3
         processorBinding.setVariable("processor", builder);
 71   
 
 72  3
         script.setBinding(processorBinding);
 73   
 
 74  3
         script.run();
 75   
 
 76  3
         return contentHandler.getModuleDescriptor();
 77   
     }
 78   
 
 79  3
     private GroovyShell getGroovyShell()
 80   
     {
 81  3
         if (_groovyShell == null)
 82  2
             _groovyShell = new GroovyShell(_resolver.getClassLoader());
 83   
 
 84  3
         return _groovyShell;
 85   
     }
 86   
 }