package com.jxml.quick.qmap;

import com.jxml.quick.*;
import com.jxml.quick.access.*;
import com.jxml.quick.tf.*;
import java.util.*;

public class QMapAccess extends QAccess
{
    public boolean writeable(QTargetFactory parentFactory, QContext context)
	throws QPE
    {
	return true;
    }

    public void add(Object parentObject, 
		    QTargetFactory parentFactory,
		    Object childObject, 
		    QContext context)
	throws QPE
    {
	if (!(parentObject instanceof Map))
	    context.throwPE("QMapAccess parent must be a Map, not "+parentObject.getClass().getName());
	if (!(childObject instanceof QKeyed))
	    context.throwPE("QMapAccess child must be QKeyed, not "+childObject.getClass().getName());
	Map map=(Map)parentObject;
	QKeyed qk=(QKeyed)childObject;
	qk.attach(map);
    }

    public boolean readable(QTargetFactory parentFactory, QContext context)
	throws QPE
    {
	return true;
    }

    public QIterator createIterator()
    {
	return new QMapIterator();
    }

    public void setIteratorParent(QIterator it, 
				  Object parentObject, 
				  QTargetFactory parentFactory,
				  QContext context)
	throws QPE
    {
	if (!(parentObject instanceof Map))
	    context.throwPE("QMapAccess parent must be a Map, not "+parentObject.getClass().getName());
	((QMapIterator)it).setMap((Map)parentObject);
    }
}
