package com.jxml.quick.util.setid;
import com.jxml.quick.ocm.*;
import java.util.*;

/**
 * Track the ID assignments.
<pre>
DTD:

&lt;!ELEMENT setid ((<a href="../../ocm/OCMsinkSupport.html#source">source|sourceLink</a>),(<a href="../../ocm/OCMsinkSupport.html#validator">validate|validateLink</a>)?,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<a href="../../ocm/OCMcontextSupport.html#factory">factory|factoryLink</a>))>

&lt;!ATTLIST setid 
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../ocm/OCMsinkSupport.html#prefix">docNamePrefix </a>CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../ocm/OCMsinkSupport.html#expressDefaults">expressDefaults</a> CDATA "False"
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../ocm/OCMtranscribe.html#schemaName">outputSchema</a> CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;ID CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#IdPrefix">Prefix </a>CDATA #IMPLIED
>
</pre>
 */
public class Counter extends OCMcontextSupport
{
	/**
	 * Prefix added to the generated ID.
	 */
	public String IdPrefix="ID";

	// implements an OCMbase method
	public OCMbase.SubBase spawn(HashMap prior)
	{
		OCMbase.SubBase rv=(OCMbase.SubBase)prior.get(this);
		if (rv!=null)
			return rv;
		OCMbase.SubBase base=new SubCounter(prior);
		prior.put(this,base);
		return base;
	}

	public class SubCounter extends SubContextSupport
	{
		/**
		 * The count value used in previously generated ID.
		 */
		public int count=0;

		public SubCounter(HashMap prior)
		{
			super(prior);
		}

		/**
		 * Generate an ID.
		 */
		public String genID()
		{
			return IdPrefix+(++count);
		}
	}
}
