1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.service;
17
18 import javax.xml.namespace.QName;
19
20 import org.apache.log4j.Logger;
21 import org.kuali.rice.core.config.ConfigContext;
22 import org.kuali.rice.core.config.ModuleConfigurer;
23 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
24 import org.kuali.rice.kim.bo.KimType;
25 import org.kuali.rice.kim.service.support.KimTypeService;
26 import org.kuali.rice.kim.util.KimCommonUtils;
27 import org.kuali.rice.kim.util.KimConstants;
28
29
30
31
32
33
34
35 public final class KIMServiceLocator {
36
37 private static final Logger LOG = Logger.getLogger(KIMServiceLocator.class);
38
39 public static final String KIM_RUN_MODE_PROPERTY = "kim.mode";
40
41 public static final String KIM_IDENTITY_MANAGEMENT_SERVICE = "kimIdentityManagementService";
42 public static final String KIM_ROLE_MANAGEMENT_SERVICE = "kimRoleManagementService";
43 public static final String KIM_PERSON_SERVICE = "personService";
44
45 public static final String KIM_IDENTITY_SERVICE = "kimIdentityService";
46 public static final String KIM_IDENTITY_UPDATE_SERVICE = "kimIdentityUpdateService";
47 public static final String KIM_IDENTITY_ARCHIVE_SERVICE = "kimIdentityArchiveService";
48
49 public static final String KIM_GROUP_SERVICE = "kimGroupService";
50 public static final String KIM_GROUP_UPDATE_SERVICE = "kimGroupUpdateService";
51
52 public static final String KIM_ROLE_SERVICE = "kimRoleService";
53 public static final String KIM_ROLE_UPDATE_SERVICE = "kimRoleUpdateService";
54
55 public static final String KIM_PERMISSION_SERVICE = "kimPermissionService";
56 public static final String KIM_PERMISSION_UPDATE_SERVICE = "kimPermissionUpdateService";
57
58 public static final String KIM_RESPONSIBILITY_SERVICE = "kimResponsibilityService";
59 public static final String KIM_RESPONSIBILITY_UPDATE_SERVICE = "kimResponsibilityUpdateService";
60
61 public static final String KIM_AUTHENTICATION_SERVICE = "kimAuthenticationService";
62 public static final String KIM_TYPE_INFO_SERVICE = "kimTypeInfoService";
63 public static final String KIM_UI_DOCUMENT_SERVICE = "kimUiDocumentService";
64 public static final String GROUP_INTERNAL_SERVICE = "groupInternalService";
65 public static final String RESPONSIBILITY_INTERNAL_SERVICE = "responsibilityInternalService";
66
67 public static Object getService(String serviceName) {
68 return getBean(serviceName);
69 }
70
71 public static Object getBean(String serviceName) {
72 if ( LOG.isDebugEnabled() ) {
73 LOG.debug("Fetching service " + serviceName);
74 }
75 return GlobalResourceLoader.getResourceLoader().getService(
76 (ModuleConfigurer.REMOTE_RUN_MODE.equals(ConfigContext.getCurrentContextConfig().getProperty(KIM_RUN_MODE_PROPERTY))) ?
77 new QName(KimConstants.KIM_MODULE_NAMESPACE, serviceName) : new QName(serviceName) );
78 }
79
80
81
82
83
84
85 public static KimTypeService getKimTypeService(KimType kimType) {
86 if( kimType == null ) {
87 LOG.warn( "null KimType passed into getKimTypeService" );
88 return null;
89 }
90 return getKimTypeService(KimCommonUtils.resolveKimTypeServiceName(kimType.getKimTypeServiceName()));
91 }
92
93
94
95
96
97
98
99 public static KimTypeService getKimTypeService(QName kimTypeServiceName) {
100 if (kimTypeServiceName == null) {
101 throw new IllegalArgumentException("Invalid service name passed, value was null.");
102 }
103 try {
104 return (KimTypeService) GlobalResourceLoader.getService(kimTypeServiceName);
105 } catch (Exception exception) {
106
107
108
109
110 LOG.error("Unable to find KIM type service with name: " + kimTypeServiceName, exception);
111 return null;
112 }
113 }
114
115 public static IdentityManagementService getIdentityManagementService() {
116 if ( LOG.isDebugEnabled() ) {
117 LOG.debug("Fetching service " + KIM_IDENTITY_MANAGEMENT_SERVICE);
118 }
119 return (IdentityManagementService) GlobalResourceLoader.getResourceLoader().getService(new QName(KIM_IDENTITY_MANAGEMENT_SERVICE));
120 }
121
122 public static IdentityService getIdentityService() {
123 return (IdentityService)getService(KIM_IDENTITY_SERVICE);
124 }
125
126 public static IdentityUpdateService getIdentityUpdateService() {
127 return (IdentityUpdateService)getService(KIM_IDENTITY_UPDATE_SERVICE);
128 }
129
130 public static IdentityArchiveService getIdentityArchiveService() {
131 return (IdentityArchiveService)getService(KIM_IDENTITY_ARCHIVE_SERVICE);
132 }
133
134 public static GroupService getGroupService() {
135 return (GroupService)getService(KIM_GROUP_SERVICE);
136 }
137
138 public static GroupUpdateService getGroupUpdateService() {
139 return (GroupUpdateService)getService(KIM_GROUP_UPDATE_SERVICE);
140 }
141
142 public static RoleService getRoleService() {
143 return (RoleService)getService(KIM_ROLE_SERVICE);
144 }
145
146 public static RoleUpdateService getRoleUpdateService() {
147 return (RoleUpdateService)getService(KIM_ROLE_UPDATE_SERVICE);
148 }
149
150 public static RoleManagementService getRoleManagementService() {
151 if ( LOG.isDebugEnabled() ) {
152 LOG.debug("Fetching service " + KIM_ROLE_MANAGEMENT_SERVICE);
153 }
154 return (RoleManagementService) GlobalResourceLoader.getResourceLoader().getService(new QName(KIM_ROLE_MANAGEMENT_SERVICE));
155 }
156
157 public static PermissionService getPermissionService() {
158 return (PermissionService)getService(KIM_PERMISSION_SERVICE);
159 }
160
161 public static PermissionUpdateService getPermissionUpdateService() {
162 return (PermissionUpdateService)getService(KIM_PERMISSION_UPDATE_SERVICE);
163 }
164
165 public static ResponsibilityService getResponsibilityService() {
166 return (ResponsibilityService)getService(KIM_RESPONSIBILITY_SERVICE);
167 }
168
169 public static ResponsibilityUpdateService getResponsibilityUpdateService() {
170 return (ResponsibilityUpdateService)getService(KIM_RESPONSIBILITY_UPDATE_SERVICE);
171 }
172
173 public static KimTypeInfoService getTypeInfoService() {
174 return (KimTypeInfoService)getService(KIM_TYPE_INFO_SERVICE);
175 }
176
177 public static AuthenticationService getAuthenticationService() {
178 if ( LOG.isDebugEnabled() ) {
179 LOG.debug("Fetching service " + KIM_AUTHENTICATION_SERVICE);
180 }
181 return (AuthenticationService) GlobalResourceLoader.getResourceLoader().getService(new QName(KIM_AUTHENTICATION_SERVICE));
182 }
183
184 public static UiDocumentService getUiDocumentService() {
185 return (UiDocumentService)getService(KIM_UI_DOCUMENT_SERVICE);
186 }
187
188 @SuppressWarnings("unchecked")
189 public static PersonService getPersonService() {
190 if ( LOG.isDebugEnabled() ) {
191 LOG.debug("Fetching service " + KIM_PERSON_SERVICE);
192 }
193 return (PersonService) GlobalResourceLoader.getResourceLoader().getService(new QName(KIM_PERSON_SERVICE));
194 }
195
196 public static GroupInternalService getGroupInternalService() {
197 return (GroupInternalService)getService(GROUP_INTERNAL_SERVICE);
198 }
199
200 public static ResponsibilityInternalService getResponsibilityInternalService() {
201 return (ResponsibilityInternalService)getService(RESPONSIBILITY_INTERNAL_SERVICE);
202 }
203
204 }