001package org.kuali.ole.docstore.service; 002 003import org.kuali.ole.docstore.discovery.service.AdminService; 004import org.kuali.ole.docstore.discovery.service.AdminServiceImpl; 005import org.kuali.ole.docstore.indexer.solr.IndexerService; 006import org.kuali.ole.docstore.indexer.solr.WorkBibDocumentIndexer; 007import org.kuali.ole.solr.DummyAdminService; 008import org.kuali.ole.solr.DummyIndexerServiceImpl; 009import org.slf4j.Logger; 010import org.slf4j.LoggerFactory; 011 012/** 013 * Class for getting services without depending on the implementation classes. 014 * User: tirumalesh.b 015 * Date: 22/12/11 Time: 8:05 PM 016 */ 017public class ServiceLocator { 018 private static Boolean OLE_DOCSTORE_USE_DISCOVERY = null; 019 private static IndexerService indexerService = WorkBibDocumentIndexer.getInstance(); 020 private static IndexerService dummyIndexerService = DummyIndexerServiceImpl.getInstance(); 021 private static final Logger LOG = LoggerFactory.getLogger(ServiceLocator.class); 022 private static AdminService adminService = AdminServiceImpl.getInstance(); 023 private static AdminService adminServiceDummy = new DummyAdminService(); 024 025 public static IndexerService getIndexerService() { 026 initUseDiscovery(); 027 if (OLE_DOCSTORE_USE_DISCOVERY) { 028 return indexerService; 029 } else { 030 return dummyIndexerService; 031 } 032 } 033 034 private static void initUseDiscovery() { 035 if (OLE_DOCSTORE_USE_DISCOVERY != null) { 036 return; 037 } 038 039 String strUseDiscovery = System.getProperty("OLE_DOCSTORE_USE_DISCOVERY"); 040 if ((strUseDiscovery != null) && strUseDiscovery.equalsIgnoreCase("false")) { 041 OLE_DOCSTORE_USE_DISCOVERY = Boolean.FALSE; 042 } else { 043 OLE_DOCSTORE_USE_DISCOVERY = Boolean.TRUE; 044 } 045 LOG.info("OLE_DOCSTORE_USE_DISCOVERY = " + OLE_DOCSTORE_USE_DISCOVERY); 046 } 047 048 public static AdminService getDiscoveryAdminService() { 049 initUseDiscovery(); 050 if (OLE_DOCSTORE_USE_DISCOVERY) { 051 return adminService; 052 } else { 053 return adminServiceDummy; 054 } 055 } 056}