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

		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 PackageRuleSet(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 + "PackageHeader", "org.huihoo.workflow.coreImpl.xpdl.WorkflowPackageHeaderImpl");
		digester.addSetNext(
			prefix + "PackageHeader",
			"setPackageHeader",
			"org.huihoo.workflow.xpdl.WorkflowPackageHeader");

		digester.addObjectCreate(
			prefix + "Applications/Application",
			"org.huihoo.workflow.coreImpl.xpdl.WorkflowApplicationImpl");
		digester.addSetNext(
			prefix + "Applications/Application",
			"addApplication",
			"org.huihoo.workflow.xpdl.WorkflowApplication");

		digester.addObjectCreate(
			prefix + "DataFields/DataField",
			"org.huihoo.workflow.xpdl.WorkflowParameter");
		digester.addSetNext(
			prefix + "DataFields/DataField",
			"addDataField",
			"org.huihoo.workflow.xpdl.WorkflowParameter");

		digester.addObjectCreate(
			prefix + "WorkflowProcesses/WorkflowProcess",
			"org.huihoo.workflow.coreImpl.xpdl.WorkflowProcessImpl");
		digester.addSetNext(
			prefix + "WorkflowProcesses/WorkflowProcess",
			"addWorkflowProcess",
			"org.huihoo.workflow.xpdl.WorkflowProcess");

		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");

		
		digester.addObjectCreate(prefix + "Script", "org.huihoo.workflow.xpdl.WorkflowScript");
		digester.addRule(prefix + "Script", new SetAliasPropertyRule("type", "Type"));
		digester.addRule(prefix + "Script", new SetAliasPropertyRule("version", "Version"));
		digester.addRule(prefix + "Script", new SetAliasPropertyRule("grammar", "Grammar"));
		digester.addSetNext(prefix + "Script", "setScript", "org.huihoo.workflow.xpdl.WorkflowScript");

	}

}