Coverage Report - org.kuali.student.common.dictionary.service.impl.ComplexSubstructuresHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
ComplexSubstructuresHelper
0%
0/27
0%
0/36
14.5
 
 1  
 package org.kuali.student.common.dictionary.service.impl;
 2  
 
 3  
 
 4  
 import java.beans.BeanInfo;
 5  
 import java.beans.IntrospectionException;
 6  
 import java.beans.Introspector;
 7  
 import java.beans.PropertyDescriptor;
 8  
 import java.lang.reflect.ParameterizedType;
 9  
 import java.util.Date;
 10  
 import java.util.LinkedHashSet;
 11  
 import java.util.List;
 12  
 import java.util.Set;
 13  
 
 14  
 import org.kuali.student.common.dto.MetaInfo;
 15  
 
 16  0
 public class ComplexSubstructuresHelper
 17  
 {
 18  
 
 19  
 
 20  
  public Set<String> getComplexStructures (String className)
 21  
  {
 22  0
   Set<String> complexStructures = new LinkedHashSet<String> ();
 23  0
   loadComplexStructures (className, complexStructures);
 24  0
   return complexStructures;
 25  
  }
 26  
 
 27  
  private void loadComplexStructures (String className,
 28  
                                      Set<String> complexStructures)
 29  
  {
 30  0
   if ( ! complexStructures.add (className))
 31  
   {
 32  0
    return;
 33  
   }
 34  
   BeanInfo beanInfo;
 35  
   Class<?> clazz;
 36  
   try
 37  
   {
 38  0
    clazz = Class.forName (className);
 39  
   }
 40  0
   catch (ClassNotFoundException ex)
 41  
   {
 42  0
    System.out.println ("ComplexSubstructuresHelper: Could not process because the class must be a freestanding object: " + className);
 43  0
    return;
 44  0
   }
 45  
   try
 46  
   {
 47  0
    beanInfo = Introspector.getBeanInfo (clazz);
 48  
   }
 49  0
   catch (IntrospectionException ex)
 50  
   {
 51  0
    throw new RuntimeException (ex);
 52  0
   }
 53  0
   for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors ())
 54  
   {
 55  0
    Class<?> subClass = pd.getPropertyType ();
 56  0
    if (List.class.equals (subClass))
 57  
    {
 58  
     try
 59  
     {
 60  0
      subClass =
 61  
      (Class<?>) ((ParameterizedType) clazz.getDeclaredField (
 62  
        pd.getName ()).getGenericType ()).getActualTypeArguments ()[0];
 63  
     }
 64  0
     catch (NoSuchFieldException ex)
 65  
     {
 66  0
      throw new RuntimeException (ex);
 67  
     }
 68  0
     catch (SecurityException ex)
 69  
     {
 70  0
      throw new RuntimeException (ex);
 71  0
     }
 72  
    }
 73  0
    if ( ! MetaInfo.class.equals (subClass)
 74  
        &&  ! Class.class.equals (subClass)
 75  
        &&  ! String.class.equals (subClass)
 76  
        &&  ! Integer.class.equals (subClass)
 77  
        &&  ! Long.class.equals (subClass)
 78  
        &&  ! Boolean.class.equals (subClass)
 79  
        &&  ! boolean.class.equals (subClass)
 80  
        &&  ! int.class.equals (subClass)
 81  
        &&  ! long.class.equals (subClass)
 82  
        &&  ! Double.class.equals (subClass)
 83  
        &&  ! Float.class.equals (subClass)
 84  
        &&  ! Date.class.equals (subClass)
 85  
        &&  ! DictionaryConstants.ATTRIBUTES.equals (pd.getName ())
 86  
        &&  ! Enum.class.isAssignableFrom (subClass)
 87  
        &&  ! Object.class.equals (subClass))
 88  
    {
 89  0
     loadComplexStructures (subClass.getName (), complexStructures);
 90  
    }
 91  
   }
 92  0
  }
 93  
 
 94  
 
 95  
 }