1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.context.annotation;
18
19 import java.lang.annotation.Annotation;
20
21 import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
22 import org.springframework.beans.factory.config.BeanDefinition;
23 import org.springframework.core.annotation.AnnotationAttributes;
24 import org.springframework.util.Assert;
25
26
27
28
29
30
31
32
33
34
35
36
37
38 public class AnnotationScopeMetadataResolver implements ScopeMetadataResolver {
39
40 private final ScopedProxyMode defaultProxyMode;
41
42 protected Class<? extends Annotation> scopeAnnotationType = Scope.class;
43
44
45
46
47
48
49
50 public AnnotationScopeMetadataResolver() {
51 this.defaultProxyMode = ScopedProxyMode.NO;
52 }
53
54
55
56
57
58 public AnnotationScopeMetadataResolver(ScopedProxyMode defaultProxyMode) {
59 Assert.notNull(defaultProxyMode, "'defaultProxyMode' must not be null");
60 this.defaultProxyMode = defaultProxyMode;
61 }
62
63
64
65
66
67
68
69 public void setScopeAnnotationType(Class<? extends Annotation> scopeAnnotationType) {
70 Assert.notNull(scopeAnnotationType, "'scopeAnnotationType' must not be null");
71 this.scopeAnnotationType = scopeAnnotationType;
72 }
73
74
75 @Override
76 public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
77 ScopeMetadata metadata = new ScopeMetadata();
78 if (definition instanceof AnnotatedBeanDefinition) {
79 AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
80 AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(annDef.getMetadata(), this.scopeAnnotationType);
81 if (attributes != null) {
82 metadata.setScopeName(attributes.getString("value"));
83 ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
84 if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
85 proxyMode = this.defaultProxyMode;
86 }
87 metadata.setScopedProxyMode(proxyMode);
88 }
89 }
90 return metadata;
91 }
92
93 }