7
7
package org .hibernate .models .internal .dynamic ;
8
8
9
9
import java .lang .annotation .Annotation ;
10
- import java .lang .reflect .InvocationTargetException ;
11
- import java .util .ArrayList ;
12
10
import java .util .HashMap ;
13
- import java .util .List ;
14
11
import java .util .Locale ;
15
12
import java .util .Map ;
16
13
17
- import org .hibernate .models .AnnotationAccessException ;
18
14
import org .hibernate .models .internal .AnnotationProxy ;
19
15
import org .hibernate .models .spi .AnnotationDescriptor ;
20
16
import org .hibernate .models .spi .AttributeDescriptor ;
21
17
import org .hibernate .models .spi .MutableAnnotationUsage ;
22
- import org .hibernate .models .spi .SourceModelContext ;
18
+ import org .hibernate .models .spi .SourceModelBuildingContext ;
23
19
24
20
/**
25
21
* AnnotationUsage built dynamically (for dynamic models, XML mappings, etc.)
@@ -31,7 +27,7 @@ public class DynamicAnnotationUsage<A extends Annotation> implements MutableAnno
31
27
32
28
private Map <String , Object > values ;
33
29
34
- public DynamicAnnotationUsage ( AnnotationDescriptor <A > annotationDescriptor , SourceModelContext context ) {
30
+ public DynamicAnnotationUsage ( AnnotationDescriptor <A > annotationDescriptor , SourceModelBuildingContext context ) {
35
31
this ( annotationDescriptor , extractBaselineValues ( annotationDescriptor , context ) );
36
32
}
37
33
@@ -96,59 +92,14 @@ public <V> V setAttributeValue(String name, V value) {
96
92
97
93
private static <A extends Annotation > Map <String , Object > extractBaselineValues (
98
94
AnnotationDescriptor <A > annotationDescriptor ,
99
- SourceModelContext context ) {
95
+ SourceModelBuildingContext context ) {
100
96
final HashMap <String , Object > values = new HashMap <>();
101
97
for ( AttributeDescriptor <?> attribute : annotationDescriptor .getAttributes () ) {
102
98
values .put (
103
99
attribute .getName (),
104
- extractDefaultValue ( attribute .getAttributeMethod ().getDefaultValue () , context )
100
+ attribute .getTypeDescriptor ().createValue ( attribute , context )
105
101
);
106
102
}
107
103
return values ;
108
104
}
109
-
110
- private static Object extractDefaultValue (Object value , SourceModelContext context ) {
111
- if ( value != null ) {
112
- if ( value .getClass ().isArray () ) {
113
- return extractList ( value , context );
114
- }
115
- else if ( value instanceof Class <?> clazz ) {
116
- return context .getClassDetailsRegistry ().resolveClassDetails ( clazz .getName () );
117
- }
118
- else if ( value instanceof Annotation annotation ) {
119
- try {
120
- return extractAnnotation ( annotation , context );
121
- }
122
- catch (InvocationTargetException | IllegalAccessException e ) {
123
- throw new AnnotationAccessException ( "Error accessing default annotation-typed attribute" , e );
124
- }
125
- }
126
- }
127
- return value ;
128
- }
129
-
130
- private static <E > List <Object > extractList (Object value , SourceModelContext context ) {
131
- final List <Object > result = new ArrayList <>();
132
- //noinspection unchecked
133
- final E [] array = (E []) value ;
134
- for ( E element : array ) {
135
- result .add ( extractDefaultValue ( element , context ) );
136
- }
137
- return result ;
138
- }
139
-
140
- private static DynamicAnnotationUsage <?> extractAnnotation (Annotation annotation , SourceModelContext context )
141
- throws InvocationTargetException , IllegalAccessException {
142
- final Class <? extends Annotation > annotationType = annotation .annotationType ();
143
- final AnnotationDescriptor <?> descriptor = context .getAnnotationDescriptorRegistry ()
144
- .getDescriptor ( annotationType );
145
- final Map <String , Object > values = new HashMap <>();
146
- for ( AttributeDescriptor <?> attribute : descriptor .getAttributes () ) {
147
- values .put (
148
- attribute .getName (),
149
- extractDefaultValue ( attribute .getAttributeMethod ().invoke ( annotation ), context )
150
- );
151
- }
152
- return new DynamicAnnotationUsage <>( descriptor , values );
153
- }
154
105
}
0 commit comments