/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package leap.web.action;

import leap.lang.Classes;
import leap.lang.Named;
import leap.lang.accessor.AnnotationsGetter;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

public interface Action extends Named,AnnotationsGetter {
	
	Argument[]			EMPTY_ARGUMENTS	   = new Argument[]{};
	ActionInterceptor[] EMPTY_INTERCEPTORS = new ActionInterceptor[]{};
	
	@Override
	default String getName() {
		return toString();
	}

    default boolean hasController() {
        return null != getController();
    }

    default Object getController() {
        return null;
    }
	
	default boolean hasReturnValue() {
		return false;
	}
	
	default boolean hasArguments() {
		return false;
	}
	
	default Class<?> getReturnType() {
		return null;
	}
	
	default Type getGenericReturnType() {
		return null;
	}
	
	default Argument[] getArguments() {
		return EMPTY_ARGUMENTS;
	}
	
	/**
	 * Returns the annotations defined in action level.
	 */
	default Annotation[] getAnnotations() {
		return Classes.EMPTY_ANNOTATION_ARRAY;
	}

	/**
	 * @see {@link java.lang.reflect.Method#getAnnotationsByType(Class)}
     */
	default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
		return (T[])Classes.EMPTY_ANNOTATION_ARRAY;
	}
	
	/**
	 * Returns the annotations defined in controller level.
	 */
	default Annotation[] getControllerAnnotations() {
		return Classes.EMPTY_ANNOTATION_ARRAY;
	}
	
	/**
	 * Returns the a merged annotations of controller and action.
	 * 
	 * <p>
	 * If an annotation ared defined both in controller and action, the action's will override the annotation of controller.  
	 */
	default Annotation[] getMergedAnnotations() {
		return Classes.EMPTY_ANNOTATION_ARRAY;
	}
	
	/**
	 * Returns the interceptors of this action.
	 */
	default ActionInterceptor[] getInterceptors() {
		return EMPTY_INTERCEPTORS;
	}
	
	default <T extends Annotation> T getControllerAnnotation(Class<T> annotationType) {
		return Classes.getAnnotation(getControllerAnnotations(), annotationType);
	}
	
	default <T extends Annotation> T searchAnnotation(Class<T> annotationType) {
		return null;
	}
	
	Object execute(ActionContext context,Object[] args) throws Throwable;

}
@@ -771,16 +771,48 @@
 tation;%0A
+import java.lang.reflect.Array;%0A
 import j
@@ -1864,38 +1864,44 @@
 T%5B%5D)
-Classes.EMPTY_ANNOTATION_ARRAY
+Array.newInstance(annotationClass,0)
 ;%0A%09%7D

fix bug of Annotation class case exception