iteratormethod.java

来自「EclipseIM是一个Eclipse插件, 其可以与Java开发人员即时聊天,」· Java 代码 · 共 73 行

JAVA
73
字号
/**
 *
 */
package com.asterix.validation;

import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Iterator;

import com.asterix.validation.annotations.RuleIterator;

/**
 * @author Andrei A Adamian
 *
 */
public class IteratorMethod {
    private Method method;
    private Class<IValidationRule> clazz;
    private IValidationRule target;

    public IteratorMethod(Method method, Class<IValidationRule> clazz) {
	this.method = method;
	this.clazz = clazz;
    }

    public IteratorMethod(Method method, IValidationRule target) {
	this.method = method;
	this.target = target;
    }

    public Method getMethod() {
	return method;
    }

    public void setMethod(Method method) {
	this.method = method;
    }

    public IValidationRule getTarget() {
	return target;
    }

    public void setTarget(IValidationRule target) {
	this.target = target;
    }

    public Class<IValidationRule> getClazz() {
	return clazz;
    }

    public void setClazz(Class<IValidationRule> clazz) {
	this.clazz = clazz;
    }

    public String getMessage() {
	RuleIterator rule = method.getAnnotation(RuleIterator.class);
	if (rule != null) {
	    return rule.message();
	}
	throw new IllegalStateException("Rule annotation not specified");
    }

    public Iterator invoke(Object param) {
	try {
	    return (Iterator) method.invoke(target, param);
	} catch (Throwable t) {
	    t.printStackTrace();
	}
	return Collections.EMPTY_LIST.iterator();
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?