1 15 package org.apache.hivemind.annotations; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.ClassResolver; 21 import org.apache.hivemind.ErrorHandler; 22 import org.apache.hivemind.HiveMind; 23 import org.apache.hivemind.annotations.internal.AnnotatedModuleProcessor; 24 import org.apache.hivemind.definition.RegistryDefinition; 25 import org.apache.hivemind.impl.DefaultClassResolver; 26 import org.apache.hivemind.impl.DefaultErrorHandler; 27 28 36 public class AnnotatedModuleReader 37 { 38 private static final Log LOG = LogFactory.getLog(AnnotatedModuleReader.class); 39 40 private RegistryDefinition _registryDefinition; 41 42 private AnnotatedModuleProcessor _processor; 43 44 private ErrorHandler _errorHandler; 45 46 private ClassResolver _classResolver; 47 48 51 public AnnotatedModuleReader(RegistryDefinition registryDefinition) 52 { 53 this(registryDefinition, new DefaultClassResolver(), new DefaultErrorHandler()); 54 } 55 56 62 public AnnotatedModuleReader(RegistryDefinition registryDefinition, ClassResolver classResolver, 63 ErrorHandler errorHandler) 64 { 65 _registryDefinition = registryDefinition; 66 _classResolver = classResolver; 67 _errorHandler = errorHandler; 68 _processor = new AnnotatedModuleProcessor(_registryDefinition, _classResolver, _errorHandler); 69 } 70 71 77 public void readModule(String moduleClassName) 78 { 79 Class moduleClass = findModuleInClassResolver(moduleClassName); 80 readModule(moduleClass); 81 } 82 83 88 public void readModule(Class moduleClass) 89 { 90 try 91 { 92 _processor.processModule(moduleClass); 93 } 94 catch (RuntimeException ex) 95 { 96 _errorHandler.error(LOG, ex.getMessage(), HiveMind.getLocation(ex), ex); 97 } 98 } 99 100 private Class findModuleInClassResolver(String type) 101 { 102 Class result = _classResolver.checkForClass(type); 103 104 if (result == null) 105 throw new ApplicationRuntimeException(AnnotationsMessages.unableToFindModuleClass( 106 type, _classResolver)); 107 108 return result; 109 } 110 111 } 112 | Popular Tags |