Coverage Report - org.kuali.rice.kim.service.KIMServiceLocator
 
Classes in this File Line Coverage Branch Coverage Complexity
KIMServiceLocator
0%
0/43
0%
0/16
1.522
 
 1  
 /*
 2  
  * Copyright 2008-2009 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.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  
  * Service locator for KIM.
 31  
  *
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  *
 34  
  */
 35  0
 public final class KIMServiceLocator {
 36  
 
 37  0
         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  0
                 return getBean(serviceName);
 69  
         }
 70  
 
 71  
         public static Object getBean(String serviceName) {
 72  0
                 if ( LOG.isDebugEnabled() ) {
 73  0
                         LOG.debug("Fetching service " + serviceName);
 74  
                 }
 75  0
                 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  
          * Fetches the KimTypeService for the given KimType  If the kimType passed in is null
 82  
          * then this method will return null.  This method will resolve the kimTypeServiceName
 83  
          * on the given KimType and then delegate to {@link #getKimTypeService(QName)}.
 84  
          */
 85  
         public static KimTypeService getKimTypeService(KimType kimType) {
 86  0
                 if( kimType == null ) {
 87  0
                         LOG.warn( "null KimType passed into getKimTypeService" );
 88  0
                         return null;
 89  
                 }
 90  0
                 return getKimTypeService(KimCommonUtils.resolveKimTypeServiceName(kimType.getKimTypeServiceName()));
 91  
         }
 92  
         
 93  
         /**
 94  
          * Fetches the KimTypeService for the given kim type service name.  If the given {@link QName}
 95  
          * is null, then this method will throw an IllegalArgumentException.
 96  
          * 
 97  
          * @throws IllegalArgumentException if the given kimTypeServiceName is null
 98  
          */
 99  
         public static KimTypeService getKimTypeService(QName kimTypeServiceName) {
 100  0
                 if (kimTypeServiceName == null) {
 101  0
                         throw new IllegalArgumentException("Invalid service name passed, value was null.");
 102  
                 }
 103  
                 try {
 104  0
                         return (KimTypeService) GlobalResourceLoader.getService(kimTypeServiceName);
 105  0
                 } catch (Exception exception) {
 106  
                         
 107  
                         // if we get an exception loading the remote KimTypeService, then instead of completly failing,
 108  
                         // we'll handle the exception and return a null reference to the service
 109  
                         
 110  0
                         LOG.error("Unable to find KIM type service with name: " + kimTypeServiceName, exception);
 111  0
                         return null;
 112  
                 }
 113  
         }
 114  
         
 115  
     public static IdentityManagementService getIdentityManagementService() {
 116  0
             if ( LOG.isDebugEnabled() ) {
 117  0
                         LOG.debug("Fetching service " + KIM_IDENTITY_MANAGEMENT_SERVICE);
 118  
                 }
 119  0
             return (IdentityManagementService) GlobalResourceLoader.getResourceLoader().getService(new QName(KIM_IDENTITY_MANAGEMENT_SERVICE));
 120  
     }
 121  
 
 122  
     public static IdentityService getIdentityService() {
 123  0
             return (IdentityService)getService(KIM_IDENTITY_SERVICE);
 124  
     }
 125  
 
 126  
     public static IdentityUpdateService getIdentityUpdateService() {
 127  0
             return (IdentityUpdateService)getService(KIM_IDENTITY_UPDATE_SERVICE);
 128  
     }
 129  
 
 130  
     public static IdentityArchiveService getIdentityArchiveService() {
 131  0
             return (IdentityArchiveService)getService(KIM_IDENTITY_ARCHIVE_SERVICE);
 132  
     }
 133  
 
 134  
     public static GroupService getGroupService() {
 135  0
             return (GroupService)getService(KIM_GROUP_SERVICE);
 136  
     }
 137  
 
 138  
     public static GroupUpdateService getGroupUpdateService() {
 139  0
             return (GroupUpdateService)getService(KIM_GROUP_UPDATE_SERVICE);
 140  
     }
 141  
 
 142  
     public static RoleService getRoleService() {
 143  0
             return (RoleService)getService(KIM_ROLE_SERVICE);
 144  
     }
 145  
 
 146  
     public static RoleUpdateService getRoleUpdateService() {
 147  0
             return (RoleUpdateService)getService(KIM_ROLE_UPDATE_SERVICE);
 148  
     }
 149  
 
 150  
     public static RoleManagementService getRoleManagementService() {
 151  0
             if ( LOG.isDebugEnabled() ) {
 152  0
                         LOG.debug("Fetching service " + KIM_ROLE_MANAGEMENT_SERVICE);
 153  
                 }
 154  0
             return (RoleManagementService) GlobalResourceLoader.getResourceLoader().getService(new QName(KIM_ROLE_MANAGEMENT_SERVICE));
 155  
     }
 156  
 
 157  
     public static PermissionService getPermissionService() {
 158  0
             return (PermissionService)getService(KIM_PERMISSION_SERVICE);
 159  
     }
 160  
 
 161  
     public static PermissionUpdateService getPermissionUpdateService() {
 162  0
             return (PermissionUpdateService)getService(KIM_PERMISSION_UPDATE_SERVICE);
 163  
     }
 164  
 
 165  
     public static ResponsibilityService getResponsibilityService() {
 166  0
             return (ResponsibilityService)getService(KIM_RESPONSIBILITY_SERVICE);
 167  
     }
 168  
 
 169  
     public static ResponsibilityUpdateService getResponsibilityUpdateService() {
 170  0
             return (ResponsibilityUpdateService)getService(KIM_RESPONSIBILITY_UPDATE_SERVICE);
 171  
     }
 172  
 
 173  
     public static KimTypeInfoService getTypeInfoService() {
 174  0
         return (KimTypeInfoService)getService(KIM_TYPE_INFO_SERVICE);
 175  
     }
 176  
 
 177  
     public static AuthenticationService getAuthenticationService() {
 178  0
             if ( LOG.isDebugEnabled() ) {
 179  0
                         LOG.debug("Fetching service " + KIM_AUTHENTICATION_SERVICE);
 180  
                 }
 181  0
             return (AuthenticationService) GlobalResourceLoader.getResourceLoader().getService(new QName(KIM_AUTHENTICATION_SERVICE));
 182  
     }
 183  
 
 184  
     public static UiDocumentService getUiDocumentService() {
 185  0
             return (UiDocumentService)getService(KIM_UI_DOCUMENT_SERVICE);
 186  
     }
 187  
 
 188  
     @SuppressWarnings("unchecked")
 189  
         public static PersonService getPersonService() {
 190  0
             if ( LOG.isDebugEnabled() ) {
 191  0
                         LOG.debug("Fetching service " + KIM_PERSON_SERVICE);
 192  
                 }
 193  0
             return (PersonService) GlobalResourceLoader.getResourceLoader().getService(new QName(KIM_PERSON_SERVICE));
 194  
     }
 195  
 
 196  
     public static GroupInternalService getGroupInternalService() {
 197  0
         return (GroupInternalService)getService(GROUP_INTERNAL_SERVICE);
 198  
     }
 199  
 
 200  
     public static ResponsibilityInternalService getResponsibilityInternalService() {
 201  0
         return (ResponsibilityInternalService)getService(RESPONSIBILITY_INTERNAL_SERVICE);
 202  
     }
 203  
 
 204  
 }