private void scanAndRegisterActionClass(List<RegisteredAction> actions) {
assert actions != null;
assert !actions.isEmpty();
RegisteredAction actionTemplate = actions.get(0);
// *All* methods are candidates, including those in base classes,
// even if the base class does not have a DirectAction annotation!
List<Method> allMethods = new ArrayList<Method>();
Class<?> cls = actionTemplate.getActionClass();
while( cls != null ) {
Method[] methods = cls.getDeclaredMethods(); // Get private, protected and other methods!
Collections.addAll( allMethods, methods );
cls = cls.getSuperclass();
}
for( Method method : allMethods ) {
// Check if the kind of direct method -if any
DirectMethod methodAnnotation = method.getAnnotation(DirectMethod.class);
boolean isStandardMethod = methodAnnotation != null;
if( !isStandardMethod ) {
isStandardMethod = method.getName().startsWith(STANDARD_METHOD_NAME_PREFIX);
}
DirectFormPostMethod postMethodAnnotation = method.getAnnotation(DirectFormPostMethod.class);
boolean isFormPostMethod = postMethodAnnotation != null;
if( !isFormPostMethod ) {
isFormPostMethod = method.getName().startsWith(FORM_POST_METHOD_NAME_PREFIX);
}
DirectPollMethod pollMethodAnnotation = method.getAnnotation(DirectPollMethod.class);
boolean isPollMethod = pollMethodAnnotation != null;
if( !isPollMethod ) {
isPollMethod = method.getName().startsWith( POLL_METHOD_NAME_PREFIX );
}
// Check that a method is just of only one kind of method
if( isStandardMethod && isFormPostMethod ) {
ApiConfigurationException ex = ApiConfigurationException.forMethodCantBeStandardAndFormPostMethodAtTheSameTime(actionTemplate, method);
logger.fatal( ex.getMessage(), ex );
throw ex;
}
if( (methodAnnotation != null || postMethodAnnotation != null) && isPollMethod) {
ApiConfigurationException ex = ApiConfigurationException.forPollMethodCantBeStandardOrFormPostMethodAtTheSameTime(actionTemplate, method);
logger.fatal( ex.getMessage(), ex );
throw ex;
}
// Process standard and form post methods together, as they are very similar
if( isStandardMethod || isFormPostMethod) {
String methodName = "";
if( isStandardMethod ) {
methodName = getStandardMethodName(method, methodAnnotation);
}
else {
methodName = getFormPostMethodName( method, postMethodAnnotation);
}
if( actionTemplate.hasStandardMethod(methodName) ) {
ApiConfigurationException ex = ApiConfigurationException.forMethodAlreadyRegisteredInAction(methodName, actionTemplate.getName());
logger.fatal( ex.getMessage(), ex );
throw ex;
}
if( isFormPostMethod && !RegisteredStandardMethod.isValidFormHandlingMethod(method)) {
ApiConfigurationException ex = ApiConfigurationException.forMethodHasWrongParametersForAFormHandler( actionTemplate.getName(), methodName );
logger.fatal( ex.getMessage(), ex );
throw ex;
}
for( RegisteredAction actionToRegister : actions ) {