1 15 package org.apache.hivemind.impl; 16 17 import java.util.Iterator ; 18 import java.util.Locale ; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.hivemind.ErrorHandler; 22 import org.apache.hivemind.ShutdownCoordinator; 23 import org.apache.hivemind.definition.ConfigurationPointDefinition; 24 import org.apache.hivemind.definition.ModuleDefinition; 25 import org.apache.hivemind.definition.RegistryDefinition; 26 import org.apache.hivemind.definition.ServicePointDefinition; 27 import org.apache.hivemind.internal.Module; 28 import org.apache.hivemind.internal.RegistryInfrastructure; 29 30 40 public class RegistryInfrastructureConstructor 41 { 42 private ErrorHandler _errorHandler; 43 44 private Log _log; 45 46 private RegistryInfrastructureImpl _infrastructure; 47 48 public RegistryInfrastructureConstructor(ErrorHandler errorHandler, Log log, Locale locale) 49 { 50 _errorHandler = errorHandler; 51 _log = log; 52 53 _infrastructure = new RegistryInfrastructureImpl(_errorHandler, locale); 54 } 55 56 59 60 private ShutdownCoordinator _shutdownCoordinator = new ShutdownCoordinatorImpl(); 61 62 66 public RegistryInfrastructure constructRegistryInfrastructure(RegistryDefinition definition) 67 { 68 addModules(definition); 69 70 _infrastructure.setShutdownCoordinator(_shutdownCoordinator); 71 72 74 return _infrastructure; 75 } 76 77 private void addModules(RegistryDefinition definition) 78 { 79 81 Iterator i = definition.getModules().iterator(); 82 while (i.hasNext()) 83 { 84 ModuleDefinition module = (ModuleDefinition) i.next(); 85 86 if (_log.isDebugEnabled()) 87 _log.debug("Adding module " + module.getId() + " to registry"); 88 89 addModule(module); 90 } 91 } 92 93 private void addModule(ModuleDefinition moduleDefinition) 94 { 95 String id = moduleDefinition.getId(); 96 97 if (_log.isDebugEnabled()) 98 _log.debug("Processing module " + id); 99 100 if (_infrastructure.getModule(id) != null) 101 { 102 Module existing = _infrastructure.getModule(id); 103 104 _errorHandler.error(_log, ImplMessages.duplicateModuleId(id, existing.getLocation(), moduleDefinition 105 .getLocation()), null, null); 106 107 return; 109 } 110 111 ModuleImpl module = new ModuleImpl(); 112 113 module.setLocation(moduleDefinition.getLocation()); 114 module.setModuleId(id); 115 module.setPackageName(moduleDefinition.getPackageName()); 116 module.setClassResolver(moduleDefinition.getClassResolver()); 117 118 addServicePoints(moduleDefinition, module); 119 120 addConfigurationPoints(moduleDefinition, module); 121 122 module.setRegistry(_infrastructure); 123 _infrastructure.addModule(module); 124 125 } 126 127 private void addServicePoints(ModuleDefinition md, Module module) 128 { 129 String moduleId = md.getId(); 130 131 for (Iterator services = md.getServicePoints().iterator(); services.hasNext();) 132 { 133 ServicePointDefinition sd = (ServicePointDefinition) services.next(); 134 135 String pointId = moduleId + "." + sd.getId(); 136 137 if (_log.isDebugEnabled()) 138 _log.debug("Creating service point " + pointId); 139 140 144 ServicePointImpl point = new ServicePointImpl(module, sd); 145 146 point.setShutdownCoordinator(_shutdownCoordinator); 147 148 _infrastructure.addServicePoint(point); 149 } 150 } 151 152 private void addConfigurationPoints(ModuleDefinition md, Module module) 153 { 154 String moduleId = md.getId(); 155 for (Iterator points = md.getConfigurationPoints().iterator(); points.hasNext();) 156 { 157 ConfigurationPointDefinition cpd = (ConfigurationPointDefinition) points.next(); 158 159 String pointId = moduleId + "." + cpd.getId(); 160 161 if (_log.isDebugEnabled()) 162 _log.debug("Creating configuration point " + pointId); 163 164 ConfigurationPointImpl point = new ConfigurationPointImpl(module, cpd); 165 166 point.setShutdownCoordinator(_shutdownCoordinator); 167 168 _infrastructure.addConfigurationPoint(point); 169 170 } 171 } 172 173 } | Popular Tags |