Project

General

Profile

Revision a1765b1a

IDa1765b1ac1036e1582a49691e5b3699fca3c5128
Parent 99c779dd
Child d8cc12a4

Added by Andreas Kohlbecker almost 5 years ago

fix #6261 searching all superclasses for generic type arguments in base controller

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/BaseController.java
64 64

  
65 65
    protected Class<T> baseClass;
66 66

  
67
    @SuppressWarnings("unchecked")
67 68
    public BaseController (){
68 69

  
69
        Type superClass = this.getClass().getGenericSuperclass();
70
        if(superClass instanceof ParameterizedType){
71
            ParameterizedType parametrizedSuperClass = (ParameterizedType) superClass;
72
            Type[] typeArguments = parametrizedSuperClass.getActualTypeArguments();
73

  
74
            if(typeArguments.length > 1 && typeArguments[0] instanceof Class<?>){
75
                baseClass = (Class<T>) typeArguments[0];
76
            } else {
77
                logger.error("unable to find baseClass");
78
            }
79
        }
70
       Type superClass = this.getClass().getGenericSuperclass();
71
       while(true){
72
           if(superClass instanceof ParameterizedType){
73
               ParameterizedType parametrizedSuperClass = (ParameterizedType) superClass;
74
               Type[] typeArguments = parametrizedSuperClass.getActualTypeArguments();
75

  
76
               if(typeArguments.length > 1 && typeArguments[0] instanceof Class<?>){
77
                   baseClass = (Class<T>) typeArguments[0];
78
               } else {
79
                   logger.error("unable to find baseClass");
80
               }
81
               break;
82
           } else if(superClass instanceof Class<?>){
83
               superClass = ((Class<?>) superClass).getGenericSuperclass();
84
           } else {
85
               // no point digging deeper if neither Class or ParameterizedType
86
               logger.error("unable to find baseClass");
87
               break;
88
           }
89
       }
80 90
    }
81 91

  
82 92
    @InitBinder

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)