View Javadoc

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  public class ComplexSubstructuresHelper
17  {
18  
19  
20   public Set<String> getComplexStructures (String className)
21   {
22    Set<String> complexStructures = new LinkedHashSet<String> ();
23    loadComplexStructures (className, complexStructures);
24    return complexStructures;
25   }
26  
27   private void loadComplexStructures (String className,
28                                       Set<String> complexStructures)
29   {
30    if ( ! complexStructures.add (className))
31    {
32     return;
33    }
34    BeanInfo beanInfo;
35    Class<?> clazz;
36    try
37    {
38     clazz = Class.forName (className);
39    }
40    catch (ClassNotFoundException ex)
41    {
42     System.out.println ("ComplexSubstructuresHelper: Could not process because the class must be a freestanding object: " + className);
43     return;
44    }
45    try
46    {
47     beanInfo = Introspector.getBeanInfo (clazz);
48    }
49    catch (IntrospectionException ex)
50    {
51     throw new RuntimeException (ex);
52    }
53    for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors ())
54    {
55     Class<?> subClass = pd.getPropertyType ();
56     if (List.class.equals (subClass))
57     {
58      try
59      {
60       subClass =
61       (Class<?>) ((ParameterizedType) clazz.getDeclaredField (
62         pd.getName ()).getGenericType ()).getActualTypeArguments ()[0];
63      }
64      catch (NoSuchFieldException ex)
65      {
66       throw new RuntimeException (ex);
67      }
68      catch (SecurityException ex)
69      {
70       throw new RuntimeException (ex);
71      }
72     }
73     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      loadComplexStructures (subClass.getName (), complexStructures);
90     }
91    }
92   }
93  
94  
95  }