Package org.huihoo.workflow.xpdl

Source Code of org.huihoo.workflow.xpdl.WorkflowParameter

//----------------------------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;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.MethodUtils;

import com.zosatapo.commons.util.converters.ClassConverter;
/**
* @author reic
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public final class WorkflowParameter extends ComplexComponentObject implements Cloneable
{
  private Class type = String.class;
 
  private Object value;
 
  public WorkflowParameter()
  {
    super();
  }
 
  public WorkflowParameter(String id, String name, Class type)
  {
    this(id, name, type,null);
  }
 
  public WorkflowParameter(
    String id,
    String name,
    Class type,
    Object initialValue)
  {
    super(id, name);
    this.type = type;
   
    this.value = initialValue;
  }
 
  public void setType(Class type_)
  {
    this.type = type_;
  }
  public Class getType()
  {
    return type;
  }
  public void setValue(Object value_)
  {       
    if (value_ == null)
    {
      return;
    }
    if (type!=null && value_.getClass().getName().equals(type.getName()))
    {
      this.value = value_;
    }
    else
    {     
      if (value_ instanceof java.lang.String)
      {
        ConvertUtils.register(new ClassConverter(), Class.class);
        value = ConvertUtils.convert((String) value_, type);
      }
      else if(type.isPrimitive())
      {
        value=value_.toString();
      }
      else
      {
        throw new java.lang.IllegalArgumentException("WorkflowParameter#setValue");
      }
    }
  }
 
  public Object getValue()
  {
    return value;
  }
 
  public WorkflowParameter copy()
  throws CloneNotSupportedException
  {
    return (WorkflowParameter)clone();
  }
 
  public Object clone() throws CloneNotSupportedException
  {
    WorkflowParameter result=new WorkflowParameter(getUUID(), getName(), getType());
    result.setValue(copyValue());
    return result; 
  }
 
  public String getTagName()
  {
    return "DataField";
  }
 
  public String toString()
  {
    return "[id="
      + getUUID()
      + "] "
      + "[name="
      + getName()
      + "] "
      + "[type="
      + getType()
      + "] "
      + "[value="
      + getValue()
      + "]"
      + "[description="
      + getDescription()
      + "] ";
  }
 
  private Object copyValue()
  throws CloneNotSupportedException
  {
    if (value == null)
    {
      return null;
    }
   
    if( value instanceof java.lang.String)
    {
      return value;
    }
    else if(type.isPrimitive())
    {
      return value;
   
       
    try
    {
      return MethodUtils.invokeMethod(value, "clone", null);
    }
    catch (Throwable ex)
    {    
      throw new CloneNotSupportedException("[class="+value.getClass()+",value="+value.toString()+"]");
    }
  }
 
}
TOP

Related Classes of org.huihoo.workflow.xpdl.WorkflowParameter

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.