package com.jxml.quick.model.qdml;
import com.jxml.quick.ocm.*;
import com.jxml.quick.*;
import org.xml.sax.*;
import java.util.*;
import java.io.*;

/**
 * Link coins are used to define hyperlinks between documents.
 <pre>
DTD :

&lt;!ELEMENT link EMPTY>

&lt;!ATTLIST link
&nbsp;&nbsp;&nbsp;&nbsp;<a href="QDMCoin.html#label">label</a> CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#tag">tag</a> CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#wild">wild</a> CDATA "False"
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#coin">coin</a> CDATA #REQUIRED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#schema">schema</a> CDATA #REQUIRED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#inline">inline</a> CDATA "False"
&nbsp;&nbsp;&nbsp;&nbsp;ID id #IMPLIED
>
 </pre>
 */
public class QDMLink extends QDMCoin
	implements QDMElement
{
	/**
	 * <p>
	 * Models the tag attribute on the link element.
	 * The tag attribute holds the XML tag name for the element
	 * being defined by the link element.
	 * </p><p>
	 * When the label attribute is not present, the tag attribute is used to name the link coin.
	 * </p>
	 */
	public String tag="";

	/**
	 * <p>
	 * Models the wild attribute on the link coin.
	 * The wild attribute defaults to false.
	 * When the wild attribute is true,
	 * the link element can be used to represent an element with any tag name.
	 * </p><p>
	 * When the wild attribute is false, the tag attribute is required, but
	 * when the wild attribute is true, the tag attribute must not be present.
	 * </p><p>
	 * When the wild attribute is false, the label attribute is optional,
	 * but when the wild attribute is true, the label attribute is required.
	 * </p>
	 */
	public boolean wild=false;

	/**
	 * Models the coin attribute on the link element.
	 * The coin attribute is required.
	 * The coin attribute names a coin which defines the type of element
	 * that the link will reference.
	 * The coin that is named must be local to the current document or included in it.
	 */
	public String coin="";

	/**
	 * Models the schema attribute on the link element.
	 * The schema attribute is required.
	 * The schema attribute gives the URL of the QIML document which describes the 
	 * XML document being referenced by the link.
	 */
	public String schema="";

	/**
	 * Models the inline attribute on the link element.
	 * The inline attribute is optional, with a default value of false.
	 * When creating an XML document, the element is begun on a new line
	 * unless inline is set to true.
	 */
	public boolean inline=false;

	/**
	 * The QDMInterface, QDMAbstract, QDMText or QDMBean object named by the coin attribute.
	 * This variable is set when the data model is initialized.
	 */
	public transient QDMCoin mCoin=null;

	public Object clone()
	{
		QDMLink rv=(QDMLink)super.clone();
		rv.mCoin=null;
		return rv;
	}

	public String getLabel()
	{
		if (!"".equals(label))
			return label;
		return tag;
	}

	/**
	 * Returns the XML tag name assigned to the bean element.
	 * When wild is true, the value of the label attribute is returned.
	 */
	public String getTag()
	{
		if (wild)
			return label;
		return tag;
	}

	public void buildMaps(Map coinMap, Map contentMap)
		throws SAXException
	{
		String l=getLabel();
		if ("".equals(l))
			throw new SAXException(
				"Link has no label or tag.");
		if (coinMap.containsKey(l))
			throw new SAXException("Duplicate label: "+l);
		coinMap.put(l,this);
	}

	public void init(Map coinMap, Map contentMap)
		throws SAXException
	{
		mCoin=(QDMCoin)coinMap.get(coin);
		if (mCoin==null)
			throw new SAXException("Undefined coin: "+coin);
	}

	public Map getAtts()
		throws SAXException
	{
		return new HashMap();
	}
}
