1 15 package org.apache.hivemind.definition.impl; 16 17 import java.util.ArrayList ; 18 import java.util.Collection ; 19 import java.util.Collections ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.hivemind.ApplicationRuntimeException; 27 import org.apache.hivemind.definition.ConfigurationPointDefinition; 28 import org.apache.hivemind.definition.DefinitionMessages; 29 import org.apache.hivemind.definition.ModuleDefinition; 30 import org.apache.hivemind.definition.RegistryDefinition; 31 import org.apache.hivemind.definition.RegistryDefinitionPostProcessor; 32 import org.apache.hivemind.definition.ServicePointDefinition; 33 import org.apache.hivemind.events.RegistryInitializationListener; 34 import org.apache.hivemind.util.IdUtils; 35 36 41 public class RegistryDefinitionImpl implements RegistryDefinition 42 { 43 private static final Log LOG = LogFactory.getLog(RegistryDefinitionImpl.class); 44 45 private Map _modules = new HashMap (); 46 47 private List _postProcessors = new ArrayList (); 48 49 private List _initializationListeners = new ArrayList (); 50 51 public RegistryDefinitionImpl() 52 { 53 } 54 55 58 public void addModule(ModuleDefinition module) throws ApplicationRuntimeException 59 { 60 if (_modules.containsKey(module.getId())) 61 { 62 throw new ApplicationRuntimeException(DefinitionMessages.duplicateModuleId(module.getId())); 63 } 64 else 65 { 66 if (LOG.isDebugEnabled()) 67 LOG.debug("Adding module " + module.getId() + " to registry definition"); 68 69 _modules.put(module.getId(), module); 70 } 71 } 72 73 76 public void addPostProcessor(RegistryDefinitionPostProcessor postProcessor) 77 { 78 _postProcessors.add(postProcessor); 79 } 80 81 84 public List getPostProcessors() 85 { 86 return Collections.unmodifiableList(_postProcessors); 87 } 88 89 92 public void addRegistryInitializationListener(RegistryInitializationListener listener) 93 { 94 _initializationListeners.add(listener); 95 } 96 97 100 public List getRegistryInitializationListeners() 101 { 102 return Collections.unmodifiableList(_initializationListeners); 103 } 104 105 108 public Collection getModules() 109 { 110 return Collections.unmodifiableCollection(_modules.values()); 111 } 112 113 116 public ModuleDefinition getModule(String id) 117 { 118 return (ModuleDefinition) _modules.get(id); 119 } 120 121 124 public ServicePointDefinition getServicePoint(String qualifiedServicePointId) 125 { 126 String moduleId = IdUtils.extractModule(qualifiedServicePointId); 127 String servicePointId = IdUtils.stripModule(qualifiedServicePointId); 128 129 ServicePointDefinition servicePoint = null; 130 ModuleDefinition module = getModule(moduleId); 131 if (module != null) 132 { 133 servicePoint = module.getServicePoint(servicePointId); 134 } 135 return servicePoint; 136 } 137 138 141 public ConfigurationPointDefinition getConfigurationPoint(String qualifiedConfigurationPointId) 142 { 143 String moduleId = IdUtils.extractModule(qualifiedConfigurationPointId); 144 String configurationPointId = IdUtils.stripModule(qualifiedConfigurationPointId); 145 146 ConfigurationPointDefinition configurationPoint = null; 147 ModuleDefinition module = getModule(moduleId); 148 if (module != null) 149 { 150 configurationPoint = module.getConfigurationPoint(configurationPointId); 151 } 152 return configurationPoint; 153 } 154 155 } 156 | Popular Tags |