// copyright => http://www.jxml.com/mdsax/License.txt

package com.jxml.quick.engine;

import com.jxml.quick.*;
import com.jxml.quick.access.*;
import com.jxml.quick.tf.*;
import java.beans.*;
import java.lang.reflect.*;

public class QHRefTF implements QTargetFactory
{
    public final static Class hrefClass;
    public PropertyDescriptor[] properties=null;
    public Field[] fields=null;

    static
    {
	try
	{
	    hrefClass=Class.forName("com.jxml.quick.HRef");
	}
	catch (Exception e)
	{
	    throw new Error(e.toString());
	}
    }

    public Object create(QContext context)
	throws QPE
    {
	return new QHRef();
    }

    public boolean isInstance(Object object, QContext context)
    {
	return object instanceof HRef;
    }

    public String getName(Object object)
    {
	return "";
    }

    public String getText(Object object, 
			  QContext context)
	throws QPE
    {
	return "";
    }

    public void add(Object object, 
		    String name, 
		    String text,
		    QAccess access,
		    Object parent,
		    QTargetFactory parentFactory,
		    QContext context)
	throws QPE
    {
	((QHRef)object).add(access,parent,parentFactory,context);
    }

    public synchronized PropertyDescriptor[] getPropertyDescriptors(QContext context)
	throws QPE
    {
	if (properties!=null)
	    return properties;
	try
	    {
		BeanInfo info=Introspector.getBeanInfo(hrefClass);
		properties=info.getPropertyDescriptors();
		return properties;
	    }
	catch (IntrospectionException e)
	    {
		context.throwPE(e);
	    }
	return null;
    }

    public synchronized Field[] getFields(QContext context)
	throws QPE
    {
	if (fields!=null)
	    return fields;
//	try
//	    {
		fields=hrefClass.getFields();
		return fields;
//	    }
//	catch (Exception e)
//	    {
//		context.throwPE(e);
//	    }
//	return null;
    }
}
