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