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

/**
 * <p>
 * Models the element coin, which represents a family of elements in QJML
 * that are used to define XML elements and attributes.
 * Corrispondingly, QMCoin serves as a base class 
 * for classes which model that family of QJML elements.
 * (The inheritance model used by QJML is the same model used by Java.)
 * </p>
 */
public abstract class QMCoin extends QMCloneable
{
	/**
	 * <p>
	 * Models the attribute label, a required attribute on the coin element.
	 * The label uniquely (within a document) names a coin.
	 * </p>
	 */
	public String label="";

	/**
	 * Models the generate attribute, an optional attribute which defaults to true.
	 * When set to false, the production of Java code for the class described by the
	 * coin is inhibited.
	 */
	public boolean generate=true;

	/**
	 * A container for QMRem objects, which model rem elements.
	 * The rem elements are optional and repeating.
	 * When a class is generated from the coin, the rem elements are used
	 * to produce the JavaDoc comment which describes the class.
	 */
	public ArrayList remList=new ArrayList();

	/**
	 * <p>
	 * A list of all the coins which extend this one.
	 * This list is populated when the data model is initialized.
	 * </p>
	 */
	public transient ArrayList extensions=new ArrayList();

	/**
	 * <p>
	 * A list of all the coins which implement this one.
	 * This list is populated when the data model is initialized.
	 * </p>
	 */
	public transient ArrayList implementations=new ArrayList();

	/**
	 * <p>
	 * A table of all the variables and properties implemented by this coin,
	 * keyed by the variable and property name.
	 * This table is populated when the data model is initialized.
	 * </p><p>
	 * The keys include both the field or property name and a prefix,
	 * as follows:
	 * </p>
	 * <ul>
	 * <li>
	 * field_ prefixes the name of a field entry;
	 * </li>
	 * <li>
	 * get_ prefixes the name of a property entry with the read attribute set to true;
	 * </li>
	 * <li>
	 * set_ prefixes the name of a property entry with the write attribute set to true.
	 * (There can be two entries for property elements.)
	 * </li>
	 * </ul>
	 * <p>
	 * The field and property elements which duplicate inherited field and property elements
	 * are not included in this table, but are accessable via the getAccessor method.
	 * For example, for a read/write property on a coin which extends another coin with
	 * a read-only property by the same name, the read/write property will be put in the coin's
	 * accessor table only once--with a prefix of "set_".
	 * </p>
	 */
	public transient HashMap accessors=new HashMap();

	/**
	 * Returns a deep copy of this object, but in an uninitialized form.
	 */
	public Object clone()
	{
		QMCoin rv=(QMCoin)super.clone();
		rv.remList=clone(remList);
		rv.extensions.clear();
		rv.implementations.clear();
		rv.accessors.clear();
		return rv;
	}

	/**
	 * Returns the unique (within the scope of the QJML document) name of the coin,
	 * as specified by the coin's label.
	 */
	public String getLabel()
	{
		return label;
	}

	/**
	 * Builds the maps.
	 * This method is called during initialization of the data model.
	 */
	public void buildMaps(Map coinMap, Map contentMap)
		throws SAXException
	{
	}

	/**
	 * <p>
	 * Returns the object which models the named field or property element.
	 * This can be a field or property found within the content of the coin element being modeled,
	 * or one found within the content of a coin which this coin extends.
	 * </p><p>
	 * The keys include both the field or property name and a prefix,
	 * as follows:
	 * </p>
	 * <ul>
	 * <li>
	 * field_ prefixes the name of a field entry;
	 * </li>
	 * <li>
	 * get_ prefixes the name of a property entry with the read attribute set to true;
	 * </li>
	 * <li>
	 * set_ prefixes the name of a property entry with the write attribute set to true.
	 * (There can be two entries for property elements.)
	 * </li>
	 * </ul>
	 */
	public QMAccess getAccessor(Map coinMap, String name)
		throws SAXException
	{
		return (QMAccess)accessors.get(name);
	}

	/**
	 * Resolve references, inheritance.
	 * This method is called during initialization of the data model.
	 */
	public void init(Map coinMap, Map contentMap)
		throws SAXException
	{
	}

	/**
	 * Returns the fully qualified name of the class described by this coin.
	 */
	public abstract String getClassName()
		throws SAXException;

}
