001    package org.kuali.student.common.dictionary.service.impl;
002    
003    
004    import java.beans.BeanInfo;
005    import java.beans.IntrospectionException;
006    import java.beans.Introspector;
007    import java.beans.PropertyDescriptor;
008    import java.lang.reflect.ParameterizedType;
009    import java.util.Date;
010    import java.util.LinkedHashSet;
011    import java.util.List;
012    import java.util.Set;
013    
014    import org.kuali.student.common.dto.MetaInfo;
015    
016    public class ComplexSubstructuresHelper
017    {
018    
019    
020     public Set<String> getComplexStructures (String className)
021     {
022      Set<String> complexStructures = new LinkedHashSet<String> ();
023      loadComplexStructures (className, complexStructures);
024      return complexStructures;
025     }
026    
027     private void loadComplexStructures (String className,
028                                         Set<String> complexStructures)
029     {
030      if ( ! complexStructures.add (className))
031      {
032       return;
033      }
034      BeanInfo beanInfo;
035      Class<?> clazz;
036      try
037      {
038       clazz = Class.forName (className);
039      }
040      catch (ClassNotFoundException ex)
041      {
042       System.out.println ("ComplexSubstructuresHelper: Could not process because the class must be a freestanding object: " + className);
043       return;
044      }
045      try
046      {
047       beanInfo = Introspector.getBeanInfo (clazz);
048      }
049      catch (IntrospectionException ex)
050      {
051       throw new RuntimeException (ex);
052      }
053      for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors ())
054      {
055       Class<?> subClass = pd.getPropertyType ();
056       if (List.class.equals (subClass))
057       {
058        try
059        {
060         subClass =
061         (Class<?>) ((ParameterizedType) clazz.getDeclaredField (
062           pd.getName ()).getGenericType ()).getActualTypeArguments ()[0];
063        }
064        catch (NoSuchFieldException ex)
065        {
066         throw new RuntimeException (ex);
067        }
068        catch (SecurityException ex)
069        {
070         throw new RuntimeException (ex);
071        }
072       }
073       if ( ! MetaInfo.class.equals (subClass)
074           &&  ! Class.class.equals (subClass)
075           &&  ! String.class.equals (subClass)
076           &&  ! Integer.class.equals (subClass)
077           &&  ! Long.class.equals (subClass)
078           &&  ! Boolean.class.equals (subClass)
079           &&  ! boolean.class.equals (subClass)
080           &&  ! int.class.equals (subClass)
081           &&  ! long.class.equals (subClass)
082           &&  ! Double.class.equals (subClass)
083           &&  ! Float.class.equals (subClass)
084           &&  ! Date.class.equals (subClass)
085           &&  ! DictionaryConstants.ATTRIBUTES.equals (pd.getName ())
086           &&  ! Enum.class.isAssignableFrom (subClass)
087           &&  ! Object.class.equals (subClass))
088       {
089        loadComplexStructures (subClass.getName (), complexStructures);
090       }
091      }
092     }
093    
094    
095    }