package com.jxml.quick.ocm; // Open Conversion Model
import com.jxml.quick.*;
import org.xml.sax.*;
import java.io.*;
import java.util.*;

/**
 * Provides the functionality for the conversion.
 */
public abstract class OCMpeerSupportLite implements OCMpeer
{
	/**
	 * The data model object paired to this peer.
	 */
	public Object dataModel=null;

	/**
	 * The conversion context.
	 */
	public OCMcontext context=null;

	/**
	 * The conversion peer parent.
	 */
	public OCMpeer parent=null;
	/**
	 * Parameter data from the .util or .ocm file.
	 */
	public Map paramMap=null;

	// Implement method on OCMpeer
	public final void init(Object dataModel, OCMcontext context, OCMpeer parent, Map paramMap)
		throws SAXException, IOException
	{
		this.dataModel=dataModel;
		this.context=context;
		this.parent=parent;
		this.paramMap=paramMap;
	}

	// Method on OCMpeer
	public abstract void cvt(Object param)
		throws SAXException, IOException;

	/**
	 * Convenience method for retrieving another peer object.
	 */
	public OCMpeer peer(Object dm)
		throws SAXException, IOException
	{
		return context.peer(dm,this);
	}

	/**
	 * convenience method for converting other data model objects.
	 */
	public void doCvt(Object dm, Object param)
		throws SAXException, IOException
	{
		OCMpeer p=peer(dm);
		if (p==null)
			return;
		p.cvt(param);
	}

	/**
	 * Convenience method for converting lists of data model objects.
	 */
	public void doCvt(List l, Object param)
		throws SAXException, IOException
	{
		int s,i;
		if (l==null)
			return;
		s=l.size();
		for (i=0;i<s;++i)
		{
			Object dm=l.get(i);
			doCvt(dm,param);
		}
	}

	/**
	 * Convenience method for converting maps of data model objects.
	 */
	public void doCvt(Map m, Object param)
		throws SAXException, IOException
	{
		Collection col=m.values();
		Iterator it=col.iterator();
		while(it.hasNext())
		{
			Object dm=it.next();
			doCvt(dm,param);
		}
	}
}
