1 17 package org.alfresco.repo.service; 18 19 import java.util.Collection ; 20 import java.util.Collections ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 import org.alfresco.service.ServiceDescriptor; 26 import org.alfresco.service.ServiceRegistry; 27 import org.alfresco.service.cmr.action.ActionService; 28 import org.alfresco.service.cmr.coci.CheckOutCheckInService; 29 import org.alfresco.service.cmr.dictionary.DictionaryService; 30 import org.alfresco.service.cmr.lock.LockService; 31 import org.alfresco.service.cmr.model.FileFolderService; 32 import org.alfresco.service.cmr.repository.ContentService; 33 import org.alfresco.service.cmr.repository.CopyService; 34 import org.alfresco.service.cmr.repository.MimetypeService; 35 import org.alfresco.service.cmr.repository.NodeService; 36 import org.alfresco.service.cmr.repository.TemplateService; 37 import org.alfresco.service.cmr.rule.RuleService; 38 import org.alfresco.service.cmr.search.CategoryService; 39 import org.alfresco.service.cmr.search.SearchService; 40 import org.alfresco.service.cmr.security.AuthenticationService; 41 import org.alfresco.service.cmr.security.AuthorityService; 42 import org.alfresco.service.cmr.security.PermissionService; 43 import org.alfresco.service.cmr.version.VersionService; 44 import org.alfresco.service.cmr.view.ExporterService; 45 import org.alfresco.service.cmr.view.ImporterService; 46 import org.alfresco.service.descriptor.DescriptorService; 47 import org.alfresco.service.namespace.NamespaceService; 48 import org.alfresco.service.namespace.QName; 49 import org.alfresco.service.transaction.TransactionService; 50 import org.springframework.beans.BeansException; 51 import org.springframework.beans.factory.BeanFactory; 52 import org.springframework.beans.factory.BeanFactoryAware; 53 import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 54 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 55 56 57 63 public class ServiceDescriptorRegistry 64 implements BeanFactoryAware, BeanFactoryPostProcessor, ServiceRegistry 65 { 66 private BeanFactory beanFactory = null; 68 69 private Map <QName, BeanServiceDescriptor> descriptors = new HashMap <QName, BeanServiceDescriptor>(); 71 72 73 76 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException 77 { 78 Map beans = beanFactory.getBeansOfType(ServiceDescriptorMetaData.class); 79 Iterator iter = beans.entrySet().iterator(); 80 while (iter.hasNext()) 81 { 82 Map.Entry entry = (Map.Entry )iter.next(); 83 ServiceDescriptorMetaData metaData = (ServiceDescriptorMetaData)entry.getValue(); 84 QName serviceName = QName.createQName(metaData.getNamespace(), (String )entry.getKey()); 85 StoreRedirector redirector = (entry.getValue() instanceof StoreRedirector) ? (StoreRedirector)entry.getValue() : null; 86 BeanServiceDescriptor serviceDescriptor = new BeanServiceDescriptor(serviceName, metaData, redirector); 87 descriptors.put(serviceDescriptor.getQualifiedName(), serviceDescriptor); 88 } 89 } 90 91 94 public void setBeanFactory(BeanFactory beanFactory) throws BeansException 95 { 96 this.beanFactory = beanFactory; 97 } 98 99 102 public Collection <QName> getServices() 103 { 104 return Collections.unmodifiableSet(descriptors.keySet()); 105 } 106 107 110 public boolean isServiceProvided(QName service) 111 { 112 return descriptors.containsKey(service); 113 } 114 115 118 public ServiceDescriptor getServiceDescriptor(QName service) 119 { 120 return descriptors.get(service); 121 } 122 123 126 public Object getService(QName service) 127 { 128 return beanFactory.getBean(service.getLocalName()); 129 } 130 131 134 public DescriptorService getDescriptorService() 135 { 136 return (DescriptorService)getService(DESCRIPTOR_SERVICE); 137 } 138 139 142 public NodeService getNodeService() 143 { 144 return (NodeService)getService(NODE_SERVICE); 145 } 146 147 150 public AuthenticationService getAuthenticationService() 151 { 152 return (AuthenticationService)getService(AUTHENTICATION_SERVICE); 153 } 154 155 158 public ContentService getContentService() 159 { 160 return (ContentService)getService(CONTENT_SERVICE); 161 } 162 163 166 public MimetypeService getMimetypeService() 167 { 168 return (MimetypeService)getService(MIMETYPE_SERVICE); 169 } 170 171 174 public VersionService getVersionService() 175 { 176 return (VersionService)getService(VERSION_SERVICE); 177 } 178 179 182 public LockService getLockService() 183 { 184 return (LockService)getService(LOCK_SERVICE); 185 } 186 187 190 public DictionaryService getDictionaryService() 191 { 192 return (DictionaryService)getService(DICTIONARY_SERVICE); 193 } 194 195 198 public SearchService getSearchService() 199 { 200 return (SearchService)getService(SEARCH_SERVICE); 201 } 202 203 206 public TransactionService getTransactionService() 207 { 208 return (TransactionService)getService(TRANSACTION_SERVICE); 209 } 210 211 214 public CopyService getCopyService() 215 { 216 return (CopyService)getService(COPY_SERVICE); 217 } 218 219 222 public CheckOutCheckInService getCheckOutCheckInService() 223 { 224 return (CheckOutCheckInService)getService(COCI_SERVICE); 225 } 226 227 230 public CategoryService getCategoryService() 231 { 232 return (CategoryService)getService(CATEGORY_SERVICE); 233 } 234 235 238 public NamespaceService getNamespaceService() 239 { 240 return (NamespaceService)getService(NAMESPACE_SERVICE); 241 } 242 243 246 public ImporterService getImporterService() 247 { 248 return (ImporterService)getService(IMPORTER_SERVICE); 249 } 250 251 254 public ExporterService getExporterService() 255 { 256 return (ExporterService)getService(EXPORTER_SERVICE); 257 } 258 259 262 public RuleService getRuleService() 263 { 264 return (RuleService)getService(RULE_SERVICE); 265 } 266 267 271 public ActionService getActionService() 272 { 273 return (ActionService)getService(ACTION_SERVICE); 274 } 275 276 279 public PermissionService getPermissionService() 280 { 281 return (PermissionService)getService(PERMISSIONS_SERVICE); 282 } 283 284 287 public AuthorityService getAuthorityService() 288 { 289 return (AuthorityService)getService(AUTHORITY_SERVICE); 290 } 291 292 295 public TemplateService getTemplateService() 296 { 297 return (TemplateService)getService(TEMPLATE_SERVICE); 298 } 299 300 303 public FileFolderService getFileFolderService() 304 { 305 return (FileFolderService) getService(FILE_FOLDER_SERVICE); 306 } 307 } 308 | Popular Tags |