Package org.huihoo.workflow.rules.compiler

Source Code of org.huihoo.workflow.rules.compiler.ScriptCompiler

//----------------------------BEGIN LICENSE----------------------------
/*
* Willow : the Open Source WorkFlow Project
* Distributable under GNU LGPL license by gun.org
*
* Copyright (C) 2004-2010 huihoo.org
* Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com>
*
* ====================================================================
* Project Homepage : http://www.huihoo.org/willow
* Source Forge     : http://sourceforge.net/projects/huihoo
* Mailing list     : willow@lists.sourceforge.net
*/
//----------------------------END  LICENSE-----------------------------
package org.huihoo.workflow.rules.compiler;

import java.io.File;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.huihoo.workflow.rules.config.ScriptCompilationContext;
import org.huihoo.workflow.xpdl.WorkflowCondition;
import org.huihoo.workflow.xpdl.condition.ScriptCondition;

/**
* @author zosatapo
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ScriptCompiler extends Compiler
{
  private static Log log = LogFactory.getLog(ScriptCompiler.class);

  // ------------------------------------------------------------ Constructor
  public ScriptCompiler(ScriptCompilationContext ctxt)
  {
    super(ctxt);
  }

  // --------------------------------------------------------- Public Methods

  /**
   * Determine if a compilation is necessary by checking the time stamp
   * of the script page with that of the corresponding .class or .java file.
   *
   * This method can by overidden by a subclasses of Compiler.
   * @param checkClass If true, check against .class file,
   *                   if false, check against .java file.
   */
  public boolean isOutDated(boolean checkClass)
  {   
    WorkflowCondition condition=ctxt.getCondition();
   
    if(condition==null)
    {
      return false;
    }
   
    if(!(condition instanceof ScriptCondition))
    {
      return true;
    }
   
     
    long wfsRealLastModified = 0;
    String scriptFilePath=options.getScriptDir() + File.separator + condition.getContent();
    try
    {
      File scriptFile=new File(scriptFilePath);
      if (!scriptFile.exists())
      {
        return true;
      }

      wfsRealLastModified = scriptFile.lastModified();
    }
    catch (Exception e)
    {
     
      return true;
    }

    long targetLastModified = 0;
    File targetFile = null;

    if (checkClass)
    {
      targetFile = new File(ctxt.getScriptClassFileName());
    }
    else
    {
      targetFile = new File(ctxt.getScriptJavaFileName());
    }
   
    if (!targetFile.exists())
    {
      log.info("Compiler: outdated: " + targetFile + " " + targetLastModified);
      return true;
    }

    targetLastModified = targetFile.lastModified();
   
    if (targetLastModified < wfsRealLastModified)
    {
      log.info("Compiler: outdated: " + targetFile + " " + targetLastModified);
      return true;
    }
   
    return false;

  }
}
TOP

Related Classes of org.huihoo.workflow.rules.compiler.ScriptCompiler

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.