//----------------------------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.parser.xmlrules;

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.RuleSetBase;


public class ActivityRuleSet extends RuleSetBase
{

	// ----------------------------------------------------- Instance Variables

	/**
	 * The matching pattern prefix to use for recognizing our elements.
	 */
	protected String prefix = null;

	// ------------------------------------------------------------ Constructor

	/**
	 * Construct an instance of this <code>RuleSet</code> with the default
	 * matching pattern prefix.
	 */
	public ActivityRuleSet()
	{

		this("");

	}

	/**
	 * Construct an instance of this <code>RuleSet</code> with the specified
	 * matching pattern prefix.
	 *
	 * @param prefix Prefix for matching pattern rules (including the
	 *  trailing slash character)
	 */
	public ActivityRuleSet(String prefix)
	{

		super();
		this.namespaceURI = null;
		this.prefix = prefix;

	}

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

	/**
	 * <p>Add the set of Rule instances defined in this RuleSet to the
	 * specified <code>Digester</code> instance, associating them with
	 * our namespace URI (if any).  This method should only be called
	 * by a Digester instance.</p>
	 *
	 * @param digester Digester instance to which the new Rule instances
	 *  should be added.
	 */
	public void addRuleInstances(Digester digester)
	{
		digester.addCallMethod(prefix + "Description", "setDescription", 0);
		digester.addCallMethod(prefix + "Limit", "setDuration", 0);
		//---------------------WorkflowActivity Implementation(No)
		digester.addObjectCreate(
			prefix + "Implementation/No",
			"org.huihoo.workflow.xpdl.activity.NoImplementation");
		digester.addSetNext(
			prefix + "Implementation/No",
			"setImplementation",
			"org.huihoo.workflow.xpdl.activity.NoImplementation");
		//---------------------WorkflowActivity Implementation(Tool)
		digester.addObjectCreate(
			prefix + "Implementation/Tool",
			"org.huihoo.workflow.xpdl.activity.ToolImplementation");
		//***********************************************************************************************    
		//  RESERVED PROPERTIES (Type)
		//  @author zosatapo 2004-03-26 
		//***********************************************************************************************
		//digester.addRule(prefix+"Implementation/Tool",new SetAliasPropertyRule("type","Type"));
		digester.addRule(
			prefix + "Implementation/Tool",
			new SetAliasPropertyRule("value", "Id"));
		digester.addObjectCreate(
			prefix + "Implementation/Tool/ActualParameters/ActualParameter",
			"org.huihoo.workflow.xpdl.parameter.ActualParameter");
		digester.addCallMethod(
			prefix + "Implementation/Tool/ActualParameters/ActualParameter",
			"setValue",
			0);
		digester.addSetNext(
			prefix + "Implementation/Tool/ActualParameters/ActualParameter",
			"addActualParameter",
			"org.huihoo.workflow.xpdl.parameter.ActualParameter");
		digester.addCallMethod(prefix + "Implementation/Tool/Description", "setDescription", 0);
		digester.addObjectCreate(
			prefix + "Implementation/Tool/ExtendedAttributes/ExtendedAttribute",
			"org.huihoo.workflow.xpdl.ExtendedAttribute");
		digester.addRule(
			prefix + "Implementation/Tool/ExtendedAttributes/ExtendedAttribute",
			new SetAllPropertiesRule());
		digester.addSetNext(
			prefix + "Implementation/Tool/ExtendedAttributes/ExtendedAttribute",
			"addExtendedAttribute",
			"org.huihoo.workflow.xpdl.ExtendedAttribute");
		digester.addSetNext(
			prefix + "Implementation/Tool",
			"addToolImplementation",
			"org.huihoo.workflow.xpdl.activity.ToolImplementation");
		//---------------------WorkflowActivity Implementation(SubFlow)
		digester.addObjectCreate(
			prefix + "Implementation/SubFlow",
			"org.huihoo.workflow.xpdl.activity.SubFlowImplementation");
 
		digester.addRule(
			prefix + "Implementation/SubFlow",
			new SetAliasPropertyRule("value", "Id"));

		//***********************************************************************************************    
		//  RESERVED PROPERTIES (Type)
		//  @author zosatapo 2004-10-29
		//***********************************************************************************************
//		digester.addRule(prefix+"Implementation/SubFlow",new SetAliasPropertyRule("Execution","Execution"));
//		digester.addObjectCreate(
//			prefix + "Implementation/SubFlow/ActualParameters/ActualParameter",
//			"org.huihoo.workflow.xpdl.parameter.ActualParameter");
//		digester.addCallMethod(
//			prefix + "Implementation/SubFlow/ActualParameters/ActualParameter",
//			"setUUID",
//			0);
//		digester.addSetNext(
//			prefix + "Implementation/Tool/ActualParameters/ActualParameter",
//			"addActualParameter",
//			"org.huihoo.workflow.xpdl.parameter.ActualParameter");
			
		digester.addSetNext(
			prefix + "Implementation/SubFlow",
			"setImplementation",
			"org.huihoo.workflow.xpdl.activity.SubFlowImplementation");
		digester.addCallMethod(prefix + "Performer", "parsePerformers", 0);
		//---------------------WorkflowActivity TransitionRestrictions
		digester.addRule(
			prefix + "TransitionRestrictions/TransitionRestriction/Join",
			new SetAliasPropertyRule("joinType", "Type"));
		digester.addRule(
			prefix + "TransitionRestrictions/TransitionRestriction/Split",
			new SetAliasPropertyRule("splitType", "Type"));
		digester.addObjectCreate(
			prefix + "ExtendedAttributes/ExtendedAttribute",
			"org.huihoo.workflow.xpdl.ExtendedAttribute");
		digester.addRule(prefix + "ExtendedAttributes/ExtendedAttribute", new SetAllPropertiesRule());
		digester.addSetNext(
			prefix + "ExtendedAttributes/ExtendedAttribute",
			"addExtendedAttribute",
			"org.huihoo.workflow.xpdl.ExtendedAttribute");
	}

}