1 15 package org.apache.examples; 16 17 import java.net.URL ; 18 import java.util.Locale ; 19 20 import org.apache.hivemind.ClassResolver; 21 import org.apache.hivemind.Registry; 22 import org.apache.hivemind.Resource; 23 import org.apache.hivemind.impl.DefaultClassResolver; 24 import org.apache.hivemind.impl.RegistryBuilder; 25 import org.apache.hivemind.impl.XmlModuleReader; 26 import org.apache.hivemind.util.URLResource; 27 28 33 public final class ExampleUtils 34 { 35 36 37 private ExampleUtils() 38 { 39 } 40 41 45 public static Registry buildClasspathRegistry(String file) 46 throws Exception 47 { 48 return buildClasspathRegistry(new String [] { file }); 49 } 50 51 54 public static Registry buildClasspathRegistry(String [] files) 55 throws Exception 56 { 57 ClassResolver resolver = new DefaultClassResolver(); 58 59 RegistryBuilder builder = new RegistryBuilder(); 60 builder.autoDetectModules(); 61 62 for (int i = 0; i < files.length; i++) 63 { 64 Resource resource = getResource(files[i]); 65 66 XmlModuleReader reader = new XmlModuleReader(builder.getRegistryDefinition(), 67 resolver, builder.getErrorHandler()); 68 reader.readModule(resource); 69 } 70 71 return builder.constructRegistry(Locale.getDefault()); 72 } 73 74 75 80 protected static Resource getResource(String file) 81 { 82 URL url = ExampleUtils.class.getResource(file); 83 84 if (url == null) throw new NullPointerException ("No resource named '" + file + "'."); 85 86 return new URLResource(url); 87 } 88 89 } 90 | Popular Tags |