NewProcessValidator.java :  » Workflow-Engines » bpmscript » org » bpmscript » web » Java Open Source

Java Open Source » Workflow Engines » bpmscript 
bpmscript » org » bpmscript » web » NewProcessValidator.java
package org.bpmscript.web;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.EvaluatorException;
import org.mozilla.javascript.Script;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class NewProcessValidator implements Validator {
  
  
  public void compile(String name, String source) {
    Context cx = Context.enter();
    cx.setOptimizationLevel(-1);
    try {
      cx.compileString(source, name, 0, null);
    } finally {
      Context.exit();
    }
  }

  public boolean supports(Class clazz) {
    return clazz == NewProcess.class;
  }

  public void validate(Object command, Errors errors) {
    NewProcess newProcess = (NewProcess) command;
    if(newProcess.getProcessName() == null || newProcess.getProcessName().trim().length() == 0) {
      errors.rejectValue("processName", "error.required", "Process Name is Required");
    }
    try {
      compile(newProcess.getProcessName(), newProcess.getSource());
    } catch (EvaluatorException ex) {
      errors.rejectValue("source", "error.compile", ex.details());
      errors.rejectValue("source", "error.compile", ex.lineSource());
      errors.rejectValue("source", "error.compile", "line " + ex.lineNumber() + " column " + ex.columnNumber());
    }
  }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.