|
|
|
@ -55,6 +55,7 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
@@ -55,6 +55,7 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
|
|
|
|
|
*/ |
|
|
|
|
AbstractAliasAwareAnnotationAttributeExtractor(Class<? extends Annotation> annotationType, |
|
|
|
|
AnnotatedElement annotatedElement, Object source) { |
|
|
|
|
|
|
|
|
|
Assert.notNull(annotationType, "annotationType must not be null"); |
|
|
|
|
Assert.notNull(source, "source must not be null"); |
|
|
|
|
this.annotationType = annotationType; |
|
|
|
@ -63,6 +64,7 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
@@ -63,6 +64,7 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
|
|
|
|
|
this.attributeAliasMap = AnnotationUtils.getAttributeAliasMap(annotationType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public final Class<? extends Annotation> getAnnotationType() { |
|
|
|
|
return this.annotationType; |
|
|
|
@ -84,25 +86,24 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
@@ -84,25 +86,24 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
|
|
|
|
|
Object attributeValue = getRawAttributeValue(attributeMethod); |
|
|
|
|
|
|
|
|
|
String aliasName = this.attributeAliasMap.get(attributeName); |
|
|
|
|
if ((aliasName != null)) { |
|
|
|
|
|
|
|
|
|
if (aliasName != null) { |
|
|
|
|
Object aliasValue = getRawAttributeValue(aliasName); |
|
|
|
|
Object defaultValue = AnnotationUtils.getDefaultValue(getAnnotationType(), attributeName); |
|
|
|
|
|
|
|
|
|
if (!nullSafeEquals(attributeValue, aliasValue) && !nullSafeEquals(attributeValue, defaultValue) |
|
|
|
|
&& !nullSafeEquals(aliasValue, defaultValue)) { |
|
|
|
|
String elementName = (getAnnotatedElement() == null ? "unknown element" |
|
|
|
|
: getAnnotatedElement().toString()); |
|
|
|
|
String msg = String.format("In annotation [%s] declared on [%s] and synthesized from [%s], " |
|
|
|
|
+ "attribute [%s] and its alias [%s] are present with values of [%s] and [%s], " |
|
|
|
|
+ "but only one is permitted.", getAnnotationType().getName(), elementName, getSource(), |
|
|
|
|
attributeName, aliasName, nullSafeToString(attributeValue), nullSafeToString(aliasValue)); |
|
|
|
|
throw new AnnotationConfigurationException(msg); |
|
|
|
|
if (!ObjectUtils.nullSafeEquals(attributeValue, aliasValue) && |
|
|
|
|
!ObjectUtils.nullSafeEquals(attributeValue, defaultValue) && |
|
|
|
|
!ObjectUtils.nullSafeEquals(aliasValue, defaultValue)) { |
|
|
|
|
String elementName = (getAnnotatedElement() != null ? getAnnotatedElement().toString() : "unknown element"); |
|
|
|
|
throw new AnnotationConfigurationException(String.format( |
|
|
|
|
"In annotation [%s] declared on %s and synthesized from [%s], attribute '%s' and its " + |
|
|
|
|
"alias '%s' are present with values of [%s] and [%s], but only one is permitted.", |
|
|
|
|
getAnnotationType().getName(), elementName, getSource(), attributeName, aliasName, |
|
|
|
|
ObjectUtils.nullSafeToString(attributeValue), ObjectUtils.nullSafeToString(aliasValue))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If the user didn't declare the annotation with an explicit value,
|
|
|
|
|
// return the value of the alias.
|
|
|
|
|
if (nullSafeEquals(attributeValue, defaultValue)) { |
|
|
|
|
if (ObjectUtils.nullSafeEquals(attributeValue, defaultValue)) { |
|
|
|
|
attributeValue = aliasValue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -110,6 +111,7 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
@@ -110,6 +111,7 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
|
|
|
|
|
return attributeValue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the raw, unmodified attribute value from the underlying |
|
|
|
|
* {@linkplain #getSource source} that corresponds to the supplied |
|
|
|
@ -124,12 +126,4 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
@@ -124,12 +126,4 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Annotat
|
|
|
|
|
*/ |
|
|
|
|
protected abstract Object getRawAttributeValue(String attributeName); |
|
|
|
|
|
|
|
|
|
private static boolean nullSafeEquals(Object o1, Object o2) { |
|
|
|
|
return ObjectUtils.nullSafeEquals(o1, o2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String nullSafeToString(Object obj) { |
|
|
|
|
return ObjectUtils.nullSafeToString(obj); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|