Package org.huihoo.workflow.xpdl.activity

Source Code of org.huihoo.workflow.xpdl.activity.ToolImplementation

//----------------------------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.xpdl.activity;
import java.util.ArrayList;
import java.util.List;

import org.huihoo.workflow.WorkflowException;
import org.huihoo.workflow.runtime.WorkflowCall;
import org.huihoo.workflow.runtime.WorkflowCase;
import org.huihoo.workflow.runtime.WorkflowWork;
import org.huihoo.workflow.xpdl.WorkflowApplication;
import org.huihoo.workflow.xpdl.WorkflowPackage;
import org.huihoo.workflow.xpdl.WorkflowParameter;
import org.huihoo.workflow.xpdl.parameter.ActualParameter;
import org.huihoo.workflow.xpdl.parameter.FormalParameter;
import org.huihoo.workflow.xpdl.parameter.ParameterMode;
/**
* @author reic
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ToolImplementation  extends AbstractImplementation
{
  private List parameters = new ArrayList();

  public void execute(WorkflowWork workItem) throws WorkflowException
  {
    execute(workItem, ToolImplementation.class.getClassLoader());
  }

  public void execute(WorkflowWork workItem, ClassLoader loader) throws WorkflowException
  {
    if (loader == null)
    {
      loader = ToolImplementation.class.getClassLoader();
    }

    try
    {
      WorkflowCase workflowCase = workItem.getWorkflowCase();
      WorkflowPackage pkg = workflowCase.getWorkflowProcess().getWorkflowPackage();
      WorkflowApplication app = pkg.findWorkflowApplication(getApplicationID());
      String implClassName = app.getQualifiedClassName();
      Class implClass = loader.loadClass(implClassName);

      WorkflowCall call = (WorkflowCall) implClass.newInstance();
      call.invoke(workItem, makeParamerers(workflowCase, app));
    }
    catch (Exception ex)
    {
      throw new WorkflowException(ex);
    }
  }
  public List getActualParameters()
  {
    return parameters;
  }
  public void addActualParameter(ActualParameter parameter)
  {
    if(parameter!=null && findActualParameter(parameter.getUUID())==null)
    {
      parameters.add(parameter);
    }
  }
  public ActualParameter findActualParameter(String id)
  {
    int sizeParams = parameters.size();
    ActualParameter result = null;

    for (int i = 0; i < sizeParams; ++i)
    {
      result = (ActualParameter) parameters.get(i);

      if (result.getUUID().equals(id))
      {
        return result;
      }

    }
    return result;
  }

  public String getApplicationID()
  {
    return getUUID();
  }
  public void setApplicationID(String applicationId)
  {
    setUUID(applicationId);
  }
 
  //---------------------private blocks
  private WorkflowParameter[] makeParamerers(WorkflowCase workflowCase, WorkflowApplication app)
    throws CloneNotSupportedException
  {
    WorkflowParameter[] params = null;

    FormalParameter formalParameter = null;
    WorkflowParameter initParameter = null;
    ActualParameter actualParameter = null;

    ParameterMode paramMode = null;
    Class srcClass = null;
    Class dstClass = null;

    int sizeParams = app.getFormalParameters().size();

    params = new WorkflowParameter[sizeParams];

    for (int i = 0; i < sizeParams; ++i)
    {
      formalParameter = app.findFormalParameter(i);
      actualParameter = (ActualParameter) parameters.get(i);
      initParameter = workflowCase.getCaseContext().getParameterByName(actualParameter.getUUID());

      srcClass = formalParameter.getType();
      dstClass = initParameter.getType();
      paramMode = formalParameter.getMode();

      if (dstClass.equals(srcClass))
      {
        if (paramMode.equals(ParameterMode.MODE_IN))
        {
          params[i] = initParameter.copy();
        }
        else
        {
          params[i] = initParameter;
        }
      }
      else
      {
        //type check failed
        throw new java.lang.IllegalArgumentException();
      }
    }

    return params;
  }
 
  public String getTagName()
  {
    return "Tool";
  }
}
TOP

Related Classes of org.huihoo.workflow.xpdl.activity.ToolImplementation

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.