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

import org.huihoo.workflow.xpdl.ExtendedAttribute;
import org.huihoo.workflow.xpdl.WorkflowApplication;
import org.huihoo.workflow.xpdl.XPDLGlobals;
import org.huihoo.workflow.xpdl.parameter.FormalParameter;

public class WorkflowApplicationImpl extends WorkflowApplication
{	
	protected List parameters = new ArrayList();
	protected String qualifiedClassName;
	
	public WorkflowApplicationImpl()
	{
		super();
	}
	public WorkflowApplicationImpl(String uuid_, String name_)
	{
		super(uuid_, name_);
	}
	public WorkflowApplicationImpl(String uuid_, String name_, String description_)
	{
		super(uuid_, name_,description_);
	}
	
	public List getFormalParameters()
	{
		return (this.parameters);
	}
  
	public FormalParameter findFormalParameter(int index)
	{
		int sizeParams=parameters.size();
    FormalParameter result=null;
    
    for(int i=0;i<sizeParams;++i)
    {
      result=(FormalParameter)parameters.get(i);
      
      if(result.getIndex()==index)
      {
        return result;
      }
      
    }
    return result;
	}
  
	public FormalParameter findFormalParameter(String id)
	{
    int sizeParams=parameters.size();
    FormalParameter result=null;
    
    for(int i=0;i<sizeParams;++i)
    {
      result=(FormalParameter)parameters.get(i);
      
      if(result.getUUID().equals(id))
      {
        return result;
      }
      
    }
    return result;
	}
 
	public FormalParameter removeFormalParameter(FormalParameter fp)
	{
		if(parameters.remove(fp))
		{
			return fp;
		}
		
		return null;
	}
	 
	public void addFormalParameter(FormalParameter formalParameter)
	{
		this.parameters.add(formalParameter);
	}

	public String getQualifiedClassName()
	{
		ExtendedAttribute attribute =
			(ExtendedAttribute) getExtendedAttributes().get(
				XPDLGlobals.APPLICATION_QUALIFIED_CLASS_NAME);
		if (attribute != null)
		{
			return attribute.getValue();
		}
		return qualifiedClassName;
	}
	
	public void  setQualifiedClassName(String className)
	{
		qualifiedClassName=className;
	}

	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		
		sb.append("[");
		sb.append(getTagName()+":");
		sb.append("[uuid=");
		sb.append(uuid==null ? "?" : uuid);
		sb.append("],");
		sb.append("[name=");
		sb.append(name==null ? "?" : name);
		sb.append("]");
		sb.append("]");
		
		return sb.toString();
	}
	
	public String getTagName()
	{
		return "Application";
	}
}
