Package com.googlecode.richrest.server.interceptor

Source Code of com.googlecode.richrest.server.interceptor.ValidationInterceptor

package com.googlecode.richrest.server.interceptor;

import java.io.Serializable;

import com.googlecode.richrest.Action;
import com.googlecode.richrest.server.ActionContext;
import com.googlecode.richrest.server.ActionInterceptor;
import com.googlecode.richrest.server.action.Validatable;
import com.googlecode.richrest.util.validator.Validator;

/**
* 验证拦截器
* @author <a href="mailto:liangfei0201@gmail.com">liangfei</a>
*/
public class ValidationInterceptor implements ActionInterceptor {

  public Serializable intercept(Action<Serializable, Serializable> action,
      Serializable model) throws Exception {
    Action<Serializable, Serializable> srcAction = ActionContext.getContext().getAction();
    if (srcAction instanceof Validatable) {
      Validatable validationAction = (Validatable)srcAction;
      Validator validator = validationAction.getValidator();
      if (validator != null)
        validator.validate(model);
    }
    return action.execute(model);
  }

}
TOP

Related Classes of com.googlecode.richrest.server.interceptor.ValidationInterceptor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.