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

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

    public final QIterator createIterator()
    {
	return new QListIterator();
    }

    protected List getList(Object parent, QContext context)
	throws QPE
    {
	if (!(parent instanceof List))
	    context.throwPE("List required");
	return (List)parent;
    }

    public final void setIteratorParent(QIterator it, 
					Object parent, 
					QTargetFactory parentFactory,
					QContext context)
	throws QPE
    {
	((QListIterator)it).setList(getList(parent,context));
    }

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

    public final void add(Object parent, 
			  QTargetFactory parentFactory,
			  Object child, 
			  QContext context)
	throws QPE
    {
	getList(parent,context).add(child);
    }

    public int reserve(QTargetFactory parentFactory,			//1.4.1
			Object parentObject,
		       QContext context)
	throws QPE
    {
	int reserved=-1;
	List list=getList(parentObject,context);
	reserved=list.size();
	list.add(null);
	return reserved;
    }

    public final void set(int reserved,
			  Object parent, 
			  QTargetFactory parentFactory,
			  Object child, 
			  QContext context)
	throws QPE
    {
	getList(parent,context).set(reserved,child);
    }
}
