//----------------------------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 ProcessRuleSet 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 ProcessRuleSet()
	{

		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 ProcessRuleSet(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.addObjectCreate(prefix + "ProcessHeader", "org.huihoo.workflow.coreImpl.xpdl.WorkflowProcessHeaderImpl");
		digester.addSetNext(
			prefix + "ProcessHeader",
			"setProcessHeader",
			"org.huihoo.workflow.xpdl.WorkflowProcessHeader");

		digester.addObjectCreate(prefix + "Activities/Activity", "org.huihoo.workflow.coreImpl.xpdl.WorkflowActivityImpl");
		digester.addRule(
			prefix + "Activities/Activity",
			new SetNextRuleInBeginning("addActivity", "org.huihoo.workflow.xpdl.WorkflowActivity"));

		digester.addObjectCreate(
			prefix + "Transitions/Transition",
			"org.huihoo.workflow.coreImpl.xpdl.WorkflowTransitionImpl");
		digester.addRule(
			prefix + "Transitions/Transition",
			new SetNextRuleInBeginning("addTransition", "org.huihoo.workflow.xpdl.WorkflowTransition"));		
		digester.addRule(prefix + "Transitions/Transition",
			new SetTransitionActivityRule("fromActivity", "From"));
		digester.addRule(prefix + "Transitions/Transition",
			new SetTransitionActivityRule("toActivity", "To"));
								
		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");
	}

}