01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.beans.factory.support;
18:
19: import org.springframework.beans.BeanMetadataAttributeAccessor;
20: import org.springframework.util.Assert;
21:
22: /**
23: * Qualifier for resolving autowire candidates. A bean definition that
24: * includes one or more such qualifiers enables fine-grained matching
25: * against annotations on a field or parameter to be autowired.
26: *
27: * @author Mark Fisher
28: * @author Juergen Hoeller
29: * @since 2.5
30: * @see org.springframework.beans.factory.annotation.Qualifier
31: */
32: public class AutowireCandidateQualifier extends
33: BeanMetadataAttributeAccessor {
34:
35: public static String VALUE_KEY = "value";
36:
37: private final String typeName;
38:
39: /**
40: * Construct a qualifier to match against an annotation of the
41: * given type.
42: * @param type the annotation type
43: */
44: public AutowireCandidateQualifier(Class type) {
45: this (type.getName());
46: }
47:
48: /**
49: * Construct a qualifier to match against an annotation of the
50: * given type name.
51: * <p>The type name may match the fully-qualified class name of
52: * the annotation or the short class name (without the package).
53: * @param typeName the name of the annotation type
54: */
55: public AutowireCandidateQualifier(String typeName) {
56: Assert.notNull(typeName, "Type name must not be null");
57: this .typeName = typeName;
58: }
59:
60: /**
61: * Construct a qualifier to match against an annotation of the
62: * given type whose <code>value</code> attribute also matches
63: * the specified value.
64: * @param type the annotation type
65: * @param value the annotation value to match
66: */
67: public AutowireCandidateQualifier(Class type, Object value) {
68: this (type.getName(), value);
69: }
70:
71: /**
72: * Construct a qualifier to match against an annotation of the
73: * given type name whose <code>value</code> attribute also matches
74: * the specified value.
75: * <p>The type name may match the fully-qualified class name of
76: * the annotation or the short class name (without the package).
77: * @param typeName the name of the annotation type
78: * @param value the annotation value to match
79: */
80: public AutowireCandidateQualifier(String typeName, Object value) {
81: Assert.notNull(typeName, "Type name must not be null");
82: this .typeName = typeName;
83: setAttribute(VALUE_KEY, value);
84: }
85:
86: /**
87: * Retrieve the type name. This value will be the same as the
88: * type name provided to the constructor or the fully-qualified
89: * class name if a Class instance was provided to the constructor.
90: */
91: public String getTypeName() {
92: return this.typeName;
93: }
94:
95: }
|