2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind-examples release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:34:25 PST
file stats: LOC: 118   Methods: 5
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ExampleUtils.java 75% 72.7% 80% 74.2%
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.examples;
 16   
 17    import java.net.URL;
 18    import java.util.ArrayList;
 19    import java.util.List;
 20    import java.util.Locale;
 21   
 22    import org.apache.hivemind.ClassResolver;
 23    import org.apache.hivemind.ModuleDescriptorProvider;
 24    import org.apache.hivemind.Registry;
 25    import org.apache.hivemind.Resource;
 26    import org.apache.hivemind.impl.DefaultClassResolver;
 27    import org.apache.hivemind.impl.RegistryBuilder;
 28    import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
 29    import org.apache.hivemind.util.FileResource;
 30    import org.apache.hivemind.util.URLResource;
 31   
 32    /**
 33    * Utilities needed by the examples.
 34    *
 35    * @author Howard Lewis Ship
 36    */
 37    public class ExampleUtils
 38    {
 39    /**
 40    * Builds a Registry for a file stored in the src/descriptor/META-INF directory.
 41    *
 42    * @param fileName --
 43    * the name of the module descriptor file.
 44    */
 45  0 public static Registry buildRegistry(String fileName)
 46    {
 47    // The examples package is structured oddly (so that it doesn't interfere with
 48    // the main HiveMind framework tests), so we have to go through some gyrations
 49    // here that aren't necessary in an ordinary HiveMind application.
 50   
 51  0 String projectRoot = System.getProperty("PROJECT_ROOT", ".");
 52  0 String path = projectRoot + "/examples/src/descriptor/META-INF/" + fileName;
 53   
 54  0 ClassResolver resolver = new DefaultClassResolver();
 55   
 56    // Register the examples.xml file, which (given its non-standard name)
 57    // is not visible.
 58  0 ModuleDescriptorProvider provider = new XmlModuleDescriptorProvider(resolver,
 59    new FileResource(path));
 60  0 return buildRegistry(provider);
 61    }
 62   
 63    /**
 64    * Convenience method for invoking {@link #buildClasspathRegistry(String[])} with only a single
 65    * file.
 66    */
 67  1 public static Registry buildClasspathRegistry(String file) throws Exception
 68    {
 69  1 return buildClasspathRegistry(new String[] { file });
 70    }
 71   
 72    /**
 73    * Builds a registry for files in the classpath.
 74    */
 75  1 public static Registry buildClasspathRegistry(String[] files) throws Exception
 76    {
 77  1 ClassResolver resolver = new DefaultClassResolver();
 78   
 79  1 List descriptorResources = new ArrayList();
 80  1 for (int i = 0; i < files.length; i++)
 81    {
 82  1 Resource resource = getResource(files[i]);
 83  1 descriptorResources.add(resource);
 84    }
 85   
 86  1 ModuleDescriptorProvider provider = new XmlModuleDescriptorProvider(resolver,
 87    descriptorResources);
 88   
 89  1 return buildRegistry(provider);
 90    }
 91   
 92  1 protected static Registry buildRegistry(ModuleDescriptorProvider customProvider)
 93    {
 94  1 ClassResolver resolver = new DefaultClassResolver();
 95   
 96  1 RegistryBuilder builder = new RegistryBuilder();
 97   
 98  1 builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(resolver));
 99  1 builder.addModuleDescriptorProvider(customProvider);
 100   
 101  1 return builder.constructRegistry(Locale.getDefault());
 102    }
 103   
 104    /**
 105    * Returns the given file as a {@link Resource} from the classpath. Typically, this is to find
 106    * files in the same folder as the invoking class.
 107    */
 108  1 protected static Resource getResource(String file)
 109    {
 110  1 URL url = ExampleUtils.class.getResource(file);
 111   
 112  1 if (url == null)
 113  0 throw new NullPointerException("No resource named '" + file + "'.");
 114   
 115  1 return new URLResource(url);
 116    }
 117   
 118    }