if (!annotationAttribute.getType().isArray())
{
// handle primitive value
if (!annotationAttribute.getType().isAnnotation())
{
SimpleTypeCaster caster = SimpleTypeCasterFactory.getCaster(value.getClass(), annotationAttribute.getType());
Object finalValue = caster.cast(value);
if (finalValue == null)
{
throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " +
annotationAttribute.getType().getSimpleName() + "-typed value for attribute '" + annotationAttribute.getName() + "' but received " +
"a " + value.getClass().getSimpleName() + "-typed value");
}
return finalValue;
}
else
{
// nested annotation
if (!(value instanceof AnnotationDesc))
{
throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " +
annotationAttribute.getType().getSimpleName() + "-typed value for attribute '" + annotationAttribute.getName() + "' but received " +
"a " + value.getClass().getSimpleName() + "-typed value");
}
return createProxy((AnnotationDesc) value, engineImportService);
}
}
if (!value.getClass().isArray())
{
throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " +
annotationAttribute.getType().getSimpleName() + "-typed value for attribute '" + annotationAttribute.getName() + "' but received " +
"a " + value.getClass().getSimpleName() + "-typed value");
}
Object array = Array.newInstance(annotationAttribute.getType().getComponentType(), Array.getLength(value));
for (int i = 0; i < Array.getLength(value); i++)
{
Object arrayValue = Array.get(value, i);
if (arrayValue == null)
{
throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " +
"non-null value for array elements for attribute '" + annotationAttribute.getName() + "'");
}
SimpleTypeCaster caster = SimpleTypeCasterFactory.getCaster(arrayValue.getClass(), annotationAttribute.getType().getComponentType());
Object finalValue = caster.cast(arrayValue);
if (finalValue == null)
{
throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " +
annotationAttribute.getType().getComponentType().getSimpleName() + "-typed value for array elements for attribute '" + annotationAttribute.getName() + "' but received " +
"a " + arrayValue.getClass().getSimpleName() + "-typed value");