1 15 package org.apache.hivemind.annotations.internal; 16 17 import org.apache.hivemind.annotations.TypedRegistry; 18 import org.apache.hivemind.internal.Module; 19 import org.apache.hivemind.internal.RegistryInfrastructure; 20 import org.apache.hivemind.service.Autowiring; 21 import org.apache.hivemind.util.IdUtils; 22 23 29 public class TypedRegistryImpl implements TypedRegistry 30 { 31 private Module _callingModule; 32 33 private RegistryInfrastructure _delegate; 34 35 41 public TypedRegistryImpl(Module callingModule, RegistryInfrastructure delegate) 42 { 43 _callingModule = callingModule; 44 _delegate = delegate; 45 } 46 47 50 public <T> T getConfiguration(String configurationId, Class <T> configurationType) 51 { 52 String qualifiedConfigurationId = qualifyExtensionPointId(configurationId); 53 Object configuration = _delegate.getConfiguration( 54 qualifiedConfigurationId, 55 _callingModule); 56 return (T) configuration; 57 } 58 59 private String qualifyExtensionPointId(String extensionPointId) 60 { 61 if (_callingModule == null) { 62 return extensionPointId; 63 } else { 64 return IdUtils.qualify( 65 _callingModule.getModuleId(), 66 extensionPointId); 67 } 68 } 69 70 73 public <T> T getConfiguration(Class <T> configurationType) 74 { 75 Object configuration = _delegate.getConfiguration(configurationType, _callingModule); 76 return (T) configuration; 77 } 78 79 82 public <T> T getService(String serviceId, Class <T> serviceInterface) 83 { 84 String qualifiedServiceId = qualifyExtensionPointId(serviceId); 85 Object service = _delegate.getService(qualifiedServiceId, serviceInterface, _callingModule); 86 return (T) service; 87 } 88 89 92 public <T> T getService(Class <T> serviceInterface) 93 { 94 Object service = _delegate.getService(serviceInterface, _callingModule); 95 return (T) service; 96 } 97 98 101 public Autowiring getAutowiring() 102 { 103 return getService(Autowiring.class); 104 } 105 106 109 public void shutdown() 110 { 111 _delegate.shutdown(); 112 113 } 114 115 } 116 | Popular Tags |