2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.model
;
11 import org
.springframework
.core
.type
.filter
.AbstractTypeHierarchyTraversingFilter
;
14 * Special implementation for the cdm which allows to also match
15 * abstract base types and interfaces in eu.etaxonomy.cdm.model.
18 * @author a.kohlbecker
22 public class CdmAssignableTypeFilter
extends AbstractTypeHierarchyTraversingFilter
{
25 private final Class targetType
;
30 public CdmAssignableTypeFilter(Class targetType
, boolean considerInherited
, boolean considerInterfaces
) {
31 super(considerInherited
, considerInterfaces
);
32 this.targetType
= targetType
;
36 protected boolean matchClassName(String className
) {
37 return this.targetType
.getName().equals(className
);
41 protected Boolean
matchSuperClass(String superClassName
) {
42 return matchTargetType(superClassName
);
46 protected Boolean
matchInterface(String interfaceName
) {
47 return matchTargetType(interfaceName
);
51 protected Boolean
matchTargetType(String typeName
) {
52 if (this.targetType
.getName().equals(typeName
)) {
55 else if (Object
.class.getName().equals(typeName
)) {
58 else if (typeName
.startsWith("eu.etaxonomy.cdm.model.")) {
60 Class clazz
= getClass().getClassLoader().loadClass(typeName
);
61 return Boolean
.valueOf(this.targetType
.isAssignableFrom(clazz
));
63 catch (ClassNotFoundException ex
) {
64 // Class not found - can't determine a match that way.