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

public class QOptionalAccess extends QSimpleAccess
{
    protected void validateParent(Object parent, QContext context)
	throws QPE
    {
	if (!(parent instanceof QCMFactory))
	    context.throwPE("requires QCMFactory parent, not"+
			    parent.getClass());
    }

    protected Object get(Object parent, QContext context)
	throws QPE
    {
	validateParent(parent,context);
	QCMFactory cmf=(QCMFactory)parent;
	return new Boolean(cmf.optional);
    }

    protected void validateChild(Object child, QContext context)
	throws QPE
    {
	if (!(child instanceof Boolean))
	    context.throwPE("requires Boolean child, not"+
			    child.getClass());
    }

    public void add(Object parent, 
		    QTargetFactory parentFactory,
		    Object child, 
		    QContext context)
	throws QPE
    {
	validateParent(parent,context);
	validateChild(child,context);
	QCMFactory cmf=(QCMFactory)parent;
	cmf.optional=((Boolean)child).booleanValue();
    }
}
