Package org.springframework.core
Interface AttributeAccessor
- All Known Subinterfaces:
AnnotatedBeanDefinition
,BeanDefinition
,TestContext
- All Known Implementing Classes:
AbstractBeanDefinition
,AnnotatedGenericBeanDefinition
,AttributeAccessorSupport
,AutowireCandidateQualifier
,BeanMetadataAttributeAccessor
,ChildBeanDefinition
,DefaultTestContext
,GenericBeanDefinition
,PropertyValue
,RootBeanDefinition
,ScannedGenericBeanDefinition
public interface AttributeAccessor
Interface defining a generic contract for attaching and accessing metadata
to/from arbitrary objects.
- Since:
- 2.0
- Author:
- Rob Harrop, Sam Brannen
-
Method Summary
Modifier and TypeMethodDescriptionString[]
Return the names of all attributes.default <T> T
computeAttribute
(String name, Function<String, T> computeFunction) Compute a new value for the attribute identified byname
if necessary and set the new value in thisAttributeAccessor
.getAttribute
(String name) Get the value of the attribute identified byname
.boolean
hasAttribute
(String name) Returntrue
if the attribute identified byname
exists.removeAttribute
(String name) Remove the attribute identified byname
and return its value.void
setAttribute
(String name, Object value) Set the attribute defined byname
to the suppliedvalue
.
-
Method Details
-
setAttribute
Set the attribute defined byname
to the suppliedvalue
.If
value
isnull
, the attribute isremoved
.In general, users should take care to prevent overlaps with other metadata attributes by using fully-qualified names, perhaps using class or package names as prefix.
- Parameters:
name
- the unique attribute keyvalue
- the attribute value to be attached
-
getAttribute
Get the value of the attribute identified byname
.Return
null
if the attribute doesn't exist.- Parameters:
name
- the unique attribute key- Returns:
- the current value of the attribute, if any
-
computeAttribute
Compute a new value for the attribute identified byname
if necessary and set the new value in thisAttributeAccessor
.If a value for the attribute identified by
name
already exists in thisAttributeAccessor
, the existing value will be returned without applying the supplied compute function.The default implementation of this method is not thread safe but can be overridden by concrete implementations of this interface.
- Type Parameters:
T
- the type of the attribute value- Parameters:
name
- the unique attribute keycomputeFunction
- a function that computes a new value for the attribute name; the function must not return anull
value- Returns:
- the existing value or newly computed value for the named attribute
- Since:
- 5.3.3
- See Also:
-
removeAttribute
Remove the attribute identified byname
and return its value.Return
null
if no attribute undername
is found.- Parameters:
name
- the unique attribute key- Returns:
- the last value of the attribute, if any
-
hasAttribute
Returntrue
if the attribute identified byname
exists.Otherwise return
false
.- Parameters:
name
- the unique attribute key
-
attributeNames
String[] attributeNames()Return the names of all attributes.
-