001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.service;
017
018import javax.persistence.EntityManagerFactory;
019import javax.sql.DataSource;
020
021import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
022import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
023import org.kuali.rice.krad.data.DataObjectService;
024import org.kuali.rice.krad.data.metadata.MetadataRepository;
025import org.kuali.rice.krad.data.provider.ProviderRegistry;
026
027/**
028 * Service locator for the KRAD App Module
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class KRADServiceLocator {
033    public static final String ATTACHMENT_SERVICE = "attachmentService";
034    public static final String NOTE_SERVICE = "noteService";
035    public static final String ENTITY_MANAGER_FACTORY = "entityManagerFactory";
036    public static final String APPLICATION_ENTITY_MANAGER_FACTORY = "kradApplicationEntityManagerFactory";
037    public static final String XML_OBJECT_SERIALIZER_SERVICE = "xmlObjectSerializerService";
038    public static final String XML_OBJECT_SERIALIZER_IGNORE_MISSING_FIELDS_SERVICE =
039            "xmlObjectSerializerIgnoreMissingFieldsService";
040    public static final String KNS_SERIALIZER_SERVICE = "businessObjectSerializerService";
041    public static final String KRAD_SERIALIZER_SERVICE = "dataObjectSerializerService";
042    public static final String MAIL_SERVICE = "mailService";
043    public static final String DB_PLATFORM = "dbPlatform";
044    public static final String INACTIVATEABLE_FROM_TO_SERVICE = "inactivateableFromToService";
045    public static final String DATA_OBJECT_SERVICE = "dataObjectService";
046    public static final String METADATA_REPOSITORY = "metadataRepository";
047    public static final String PROVIDER_REGISTRY = "providerRegistry";
048    public static final String KRAD_APPLICATION_DATA_SOURCE = "kradApplicationDataSource";
049    public static final String LEGACY_DATA_ADAPTER = "legacyDataAdapter";
050
051    static <T> T getService(String serviceName) {
052        return GlobalResourceLoader.<T>getService(serviceName);
053    }
054
055    public static AttachmentService getAttachmentService() {
056        return getService(ATTACHMENT_SERVICE);
057    }
058
059    public static NoteService getNoteService() {
060        return getService(NOTE_SERVICE);
061    }
062
063    public static EntityManagerFactory getEntityManagerFactory() {
064        return getService(ENTITY_MANAGER_FACTORY);
065    }
066
067    public static EntityManagerFactory getApplicationEntityManagerFactory() {
068        return getService(APPLICATION_ENTITY_MANAGER_FACTORY);
069    }
070
071    public static XmlObjectSerializerService getXmlObjectSerializerService() {
072        return getService(XML_OBJECT_SERIALIZER_SERVICE);
073    }
074
075    public static XmlObjectSerializerService getXmlObjectSerializerIgnoreMissingFieldsService() {
076        return getService(XML_OBJECT_SERIALIZER_IGNORE_MISSING_FIELDS_SERVICE);
077    }
078
079    public static BusinessObjectSerializerService getBusinessObjectSerializerService() {
080        return getService(KNS_SERIALIZER_SERVICE);
081    }
082
083    public static BusinessObjectSerializerService getDataObjectSerializerService() {
084        return getService(KRAD_SERIALIZER_SERVICE);
085    }
086
087    public static final MailService getMailService() {
088        return (MailService) getService(MAIL_SERVICE);
089    }
090
091    public static DatabasePlatform getDatabasePlatform() {
092        return (DatabasePlatform) getService(DB_PLATFORM);
093    }
094
095    public static InactivateableFromToService getInactivateableFromToService() {
096        return (InactivateableFromToService) getService(INACTIVATEABLE_FROM_TO_SERVICE);
097    }
098
099    public static DataObjectService getDataObjectService() {
100        return getService(DATA_OBJECT_SERVICE);
101    }
102
103    public static MetadataRepository getMetadataRepository() {
104        return getService(METADATA_REPOSITORY);
105    }
106
107    public static ProviderRegistry getProviderRegistry() {
108        return getService(PROVIDER_REGISTRY);
109    }
110
111    public static DataSource getKradApplicationDataSource() {
112        return getService(KRAD_APPLICATION_DATA_SOURCE);
113    }
114
115    /**
116     * Returns the legacy data adapter for handling legacy KNS and KRAD data and metadata.
117     *
118     * @return the legacy data adapter
119     * @deprecated application code should never use this! Always use KRAD code directly.
120     */
121    @Deprecated
122    public static LegacyDataAppAdapter getLegacyDataAdapter() {
123        return getService(LEGACY_DATA_ADAPTER);
124    }
125
126}