package com.jxml.quick.engine;
import com.jxml.quick.*;
import com.jxml.quick.access.*;
import com.jxml.quick.tf.*;

public class QIdAccess extends QSimpleAccess
{
    protected Object get(Object parent, QContext context)
	throws QPE
    {
	if (parent==null)
	    context.throwPE("ID may not be root");
	QDocImpl doc=(QDocImpl)context.doc;
	String id=doc.getId(parent);
	doc.mark(parent);
	return id;
    }

    public void add(Object parent, 
		    QTargetFactory parentFactory,
		    Object child, 
		    QContext context)
	throws QPE
    {
	if (parent==null)
	    context.throwPE("ID may not be root");
	if (!(child instanceof String))
	    context.throwPE("requires String child, not"+
			    child.getClass());
	QDocImpl doc=(QDocImpl)context.doc;
	doc.setId(((String)child).trim(),parent);
    }
}
