Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ExternalizableBusinessObjectUtils |
|
| 7.0;7 |
1 | /* | |
2 | * Copyright 2007-2008 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.kns.util; | |
17 | ||
18 | import org.kuali.rice.kns.bo.BusinessObject; | |
19 | import org.kuali.rice.kns.bo.ExternalizableBusinessObject; | |
20 | import org.kuali.rice.kns.service.KNSServiceLocator; | |
21 | import org.kuali.rice.kns.service.KualiModuleService; | |
22 | import org.kuali.rice.kns.service.ModuleService; | |
23 | ||
24 | /** | |
25 | * A class with utilities related to externalizable business objects | |
26 | */ | |
27 | 0 | public class ExternalizableBusinessObjectUtils { |
28 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ExternalizableBusinessObjectUtils.class); |
29 | ||
30 | /** | |
31 | * Given a class, this method determines which of the interfaces that the class implements extends {@link ExternalizableBusinessObject} | |
32 | * | |
33 | * @param businessObjectClass | |
34 | * @return | |
35 | */ | |
36 | public static Class determineExternalizableBusinessObjectSubInterface(Class businessObjectClass) { | |
37 | 0 | if (businessObjectClass == null) { |
38 | 0 | return null; |
39 | } | |
40 | 0 | if (businessObjectClass.isInterface()) { |
41 | 0 | if (!ExternalizableBusinessObject.class.equals(businessObjectClass) && ExternalizableBusinessObject.class.isAssignableFrom(businessObjectClass)) { |
42 | 0 | return businessObjectClass; |
43 | } | |
44 | else { | |
45 | 0 | return null; |
46 | } | |
47 | } | |
48 | 0 | if (ExternalizableBusinessObject.class.isAssignableFrom(businessObjectClass)) { |
49 | 0 | Class tempClass = businessObjectClass; |
50 | 0 | while (tempClass != null && !Object.class.equals(tempClass)) { |
51 | 0 | for (Class tempClassInterface : tempClass.getInterfaces()) { |
52 | 0 | if (!ExternalizableBusinessObject.class.equals(tempClassInterface) && ExternalizableBusinessObject.class.isAssignableFrom(tempClassInterface)) { |
53 | 0 | return tempClassInterface; |
54 | } | |
55 | } | |
56 | 0 | tempClass = tempClass.getSuperclass(); |
57 | } | |
58 | } | |
59 | 0 | return null; |
60 | } | |
61 | ||
62 | public static boolean isExternalizableBusinessObjectInterface(Class businessObjectClass) { | |
63 | 0 | return businessObjectClass != null && businessObjectClass.isInterface() && ExternalizableBusinessObject.class.isAssignableFrom(businessObjectClass); |
64 | } | |
65 | ||
66 | public static boolean isExternalizableBusinessObjectInterface(String businessObjectClassName) { | |
67 | try { | |
68 | 0 | Class businessObjectClass = Class.forName( businessObjectClassName ); |
69 | 0 | return isExternalizableBusinessObjectInterface(businessObjectClass); |
70 | 0 | } catch ( Exception ex ) { |
71 | 0 | LOG.debug( "Unable to get class object for class name: " + businessObjectClassName, ex ); |
72 | 0 | return false; |
73 | } | |
74 | } | |
75 | } |