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