{
typeArguments = ReflectionUtils.getTypeArguments(CollectionResult.class, returnType.asSubclass(CollectionResult.class));
}
else
{
throw new ResourceConfigException("@Finder method '" + method.getName()
+ "' on class '" + resourceModel.getResourceClass().getName()
+ "' has an unsupported return type");
}
if (typeArguments == null || typeArguments.get(0) == null)
{
// the return type may leave value type as parameterized and specify in runtime
final ParameterizedType collectionType = (ParameterizedType) getLogicalReturnType(method);
elementType = (Class<?>) collectionType.getActualTypeArguments()[0];
}
else
{
elementType = typeArguments.get(0);
}
}
catch (ClassCastException e)
{
throw new ResourceConfigException("@Finder method '" + method.getName()
+ "' on class '" + resourceModel.getResourceClass().getName()
+ "' has an invalid return or a data template type", e);
}
if (!List.class.isAssignableFrom(returnType)
&& !CollectionResult.class.isAssignableFrom(returnType))
{
throw new ResourceConfigException("@Finder method '" + method.getName()
+ "' on class '" + resourceModel.getResourceClass().getName()
+ "' has an invalid return type '" + returnType.getName() + "'. Expected "
+ "List<" + valueClass.getName() + "> or CollectionResult<"
+ valueClass.getName() + ">");
}
String collectionClassName = returnType.getSimpleName();
if (!RecordTemplate.class.isAssignableFrom(elementType)
|| !resourceModel.getValueClass().equals(elementType))
{
throw new ResourceConfigException("@Finder method '" + method.getName()
+ "' on class '" + resourceModel.getResourceClass().getName()
+ "' has an invalid return type. Expected " + collectionClassName + "<"
+ valueClass.getName() + ">, but found " + collectionClassName + "<"
+ elementType + '>');
}
ResourceMethodDescriptor existingFinder =
resourceModel.findNamedMethod(finderMethodDescriptor.getFinderName());
if (existingFinder != null)
{
throw new ResourceConfigException("Found duplicate @Finder method named '"
+ finderMethodDescriptor.getFinderName() + "' on class '"
+ resourceModel.getResourceClass().getName() + '\'');
}
// query parameters are checked in getQueryParameters method