Project

General

Profile

Download (1.99 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2014 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.model;
11

    
12
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
13

    
14
/**
15
 * Special implementation for the cdm which allows to also match
16
 * abstract base types and interfaces in eu.etaxonomy.cdm.model.
17
 *
18
 *
19
 * @author a.kohlbecker
20
 * @date Jul 31, 2014
21
 *
22
 */
23
public class CdmAssignableTypeFilter extends AbstractTypeHierarchyTraversingFilter {
24

    
25

    
26
    private final Class targetType;
27

    
28
    /**
29
     * @param targetType
30
     */
31
    public CdmAssignableTypeFilter(Class targetType, boolean considerInherited, boolean considerInterfaces) {
32
        super(considerInherited, considerInterfaces);
33
        this.targetType = targetType;
34
    }
35

    
36
    @Override
37
    protected boolean matchClassName(String className) {
38
        return this.targetType.getName().equals(className);
39
    }
40

    
41
    @Override
42
    protected Boolean matchSuperClass(String superClassName) {
43
        return matchTargetType(superClassName);
44
    }
45

    
46
    @Override
47
    protected Boolean matchInterface(String interfaceName) {
48
        return matchTargetType(interfaceName);
49
    }
50

    
51

    
52
    protected Boolean matchTargetType(String typeName) {
53
        if (this.targetType.getName().equals(typeName)) {
54
            return true;
55
        }
56
        else if (Object.class.getName().equals(typeName)) {
57
            return Boolean.FALSE;
58
        }
59
        else if (typeName.startsWith("eu.etaxonomy.cdm.model.")) {
60
            try {
61
                Class clazz = getClass().getClassLoader().loadClass(typeName);
62
                return Boolean.valueOf(this.targetType.isAssignableFrom(clazz));
63
            }
64
            catch (ClassNotFoundException ex) {
65
                // Class not found - can't determine a match that way.
66
            }
67
        }
68
        return null;
69
    }
70

    
71
}
(1-1/7)