View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.service;
17  
18  import javax.persistence.EntityManagerFactory;
19  import javax.sql.DataSource;
20  
21  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22  import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
23  import org.kuali.rice.krad.data.DataObjectService;
24  import org.kuali.rice.krad.data.metadata.MetadataRepository;
25  import org.kuali.rice.krad.data.provider.ProviderRegistry;
26  
27  /**
28   * Service locator for the KRAD App Module
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class KRADServiceLocator {
33      public static final String ATTACHMENT_SERVICE = "attachmentService";
34      public static final String NOTE_SERVICE = "noteService";
35      public static final String ENTITY_MANAGER_FACTORY = "entityManagerFactory";
36      public static final String APPLICATION_ENTITY_MANAGER_FACTORY = "kradApplicationEntityManagerFactory";
37      public static final String XML_OBJECT_SERIALIZER_SERVICE = "xmlObjectSerializerService";
38      public static final String XML_OBJECT_SERIALIZER_IGNORE_MISSING_FIELDS_SERVICE =
39              "xmlObjectSerializerIgnoreMissingFieldsService";
40      public static final String KNS_SERIALIZER_SERVICE = "businessObjectSerializerService";
41      public static final String KRAD_SERIALIZER_SERVICE = "dataObjectSerializerService";
42      public static final String MAIL_SERVICE = "mailService";
43      public static final String DB_PLATFORM = "dbPlatform";
44      public static final String INACTIVATEABLE_FROM_TO_SERVICE = "inactivateableFromToService";
45      public static final String DATA_OBJECT_SERVICE = "dataObjectService";
46      public static final String METADATA_REPOSITORY = "metadataRepository";
47      public static final String PROVIDER_REGISTRY = "providerRegistry";
48      public static final String KRAD_APPLICATION_DATA_SOURCE = "kradApplicationDataSource";
49      public static final String LEGACY_DATA_ADAPTER = "legacyDataAdapter";
50  
51      static <T> T getService(String serviceName) {
52          return GlobalResourceLoader.<T>getService(serviceName);
53      }
54  
55      public static AttachmentService getAttachmentService() {
56          return getService(ATTACHMENT_SERVICE);
57      }
58  
59      public static NoteService getNoteService() {
60          return getService(NOTE_SERVICE);
61      }
62  
63      public static EntityManagerFactory getEntityManagerFactory() {
64          return getService(ENTITY_MANAGER_FACTORY);
65      }
66  
67      public static EntityManagerFactory getApplicationEntityManagerFactory() {
68          return getService(APPLICATION_ENTITY_MANAGER_FACTORY);
69      }
70  
71      public static XmlObjectSerializerService getXmlObjectSerializerService() {
72          return getService(XML_OBJECT_SERIALIZER_SERVICE);
73      }
74  
75      public static XmlObjectSerializerService getXmlObjectSerializerIgnoreMissingFieldsService() {
76          return getService(XML_OBJECT_SERIALIZER_IGNORE_MISSING_FIELDS_SERVICE);
77      }
78  
79      public static BusinessObjectSerializerService getBusinessObjectSerializerService() {
80          return getService(KNS_SERIALIZER_SERVICE);
81      }
82  
83      public static BusinessObjectSerializerService getDataObjectSerializerService() {
84          return getService(KRAD_SERIALIZER_SERVICE);
85      }
86  
87      public static final MailService getMailService() {
88          return (MailService) getService(MAIL_SERVICE);
89      }
90  
91      public static DatabasePlatform getDatabasePlatform() {
92          return (DatabasePlatform) getService(DB_PLATFORM);
93      }
94  
95      public static InactivateableFromToService getInactivateableFromToService() {
96          return (InactivateableFromToService) getService(INACTIVATEABLE_FROM_TO_SERVICE);
97      }
98  
99      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 }