|
9 | 9 | import java.lang.reflect.ParameterizedType;
|
10 | 10 | import java.lang.reflect.Type;
|
11 | 11 | import java.lang.reflect.TypeVariable;
|
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.Arrays; |
| 14 | +import java.util.List; |
| 15 | + |
12 | 16 | import javax.persistence.AttributeConverter;
|
13 | 17 | import javax.persistence.Converter;
|
14 | 18 |
|
15 | 19 | import org.hibernate.AnnotationException;
|
16 | 20 | import org.hibernate.AssertionFailure;
|
17 |
| - |
18 | 21 | import org.jboss.logging.Logger;
|
19 | 22 |
|
20 | 23 | /**
|
@@ -109,6 +112,12 @@ public AttributeConverterDefinition(AttributeConverter attributeConverter, boole
|
109 | 112 |
|
110 | 113 | final Class attributeConverterClass = attributeConverter.getClass();
|
111 | 114 | final ParameterizedType attributeConverterSignature = extractAttributeConverterParameterizedType( attributeConverterClass );
|
| 115 | + if ( attributeConverterSignature == null ) { |
| 116 | + throw new AssertionFailure( |
| 117 | + "Could not extract ParameterizedType representation of AttributeConverter definition " + |
| 118 | + "from AttributeConverter implementation class [" + attributeConverterClass.getName() + "]" |
| 119 | + ); |
| 120 | + } |
112 | 121 |
|
113 | 122 | if ( attributeConverterSignature.getActualTypeArguments().length < 2 ) {
|
114 | 123 | throw new AnnotationException(
|
@@ -140,20 +149,26 @@ public AttributeConverterDefinition(AttributeConverter attributeConverter, boole
|
140 | 149 | }
|
141 | 150 | }
|
142 | 151 |
|
143 |
| - private ParameterizedType extractAttributeConverterParameterizedType(Class attributeConverterClass) { |
144 |
| - for ( Type type : attributeConverterClass.getGenericInterfaces() ) { |
145 |
| - if ( ParameterizedType.class.isInstance( type ) ) { |
146 |
| - final ParameterizedType parameterizedType = (ParameterizedType) type; |
147 |
| - if ( AttributeConverter.class.equals( parameterizedType.getRawType() ) ) { |
| 152 | + private ParameterizedType extractAttributeConverterParameterizedType(Type base) { |
| 153 | + if ( base != null ) { |
| 154 | + Class clazz = extractClass( base ); |
| 155 | + List<Type> types = new ArrayList<Type>(); |
| 156 | + types.add( clazz.getGenericSuperclass() ); |
| 157 | + types.addAll( Arrays.asList( clazz.getGenericInterfaces() ) ); |
| 158 | + for ( Type type : types ) { |
| 159 | + if ( ParameterizedType.class.isInstance( type ) ) { |
| 160 | + final ParameterizedType parameterizedType = (ParameterizedType) type; |
| 161 | + if ( AttributeConverter.class.equals( parameterizedType.getRawType() ) ) { |
| 162 | + return parameterizedType; |
| 163 | + } |
| 164 | + } |
| 165 | + ParameterizedType parameterizedType = extractAttributeConverterParameterizedType( type ); |
| 166 | + if ( parameterizedType != null ) { |
148 | 167 | return parameterizedType;
|
149 | 168 | }
|
150 | 169 | }
|
151 | 170 | }
|
152 |
| - |
153 |
| - throw new AssertionFailure( |
154 |
| - "Could not extract ParameterizedType representation of AttributeConverter definition " + |
155 |
| - "from AttributeConverter implementation class [" + attributeConverterClass.getName() + "]" |
156 |
| - ); |
| 171 | + return null; |
157 | 172 | }
|
158 | 173 |
|
159 | 174 | public AttributeConverter getAttributeConverter() {
|
|
0 commit comments