package com.jxml.quick.util.qjml2qiml;
import com.jxml.quick.model.qjml.*;
import com.jxml.quick.*;
import org.xml.sax.*;
import java.util.*;
import com.jxml.quick.ocm.*;
import java.io.*;

/**
 * Extracts QJML data.
 */
public class QCTargetEditor extends OCMpeerSupport
{

	public static QMTargetEditor stringEditor;
	static
	{
		stringEditor=new QMTargetEditor();
		stringEditor.target="java.lang.String";
		stringEditor.editor="sun.beans.editors.StringEditor";
	}

	public static QMTargetEditor newEditor(String type) 
	{
		TypeManager.Entry ei = TypeManager.getEntry(type);
		if (ei==null)
			return stringEditor;
		synchronized (ei)
		{
			QMTargetEditor te=(QMTargetEditor)ei.targetEditor;
			if (te==null)
			{
				te=new QMTargetEditor();
	    			te.target = ei.target;
 	    			te.editor = ei.editor;
	    			ei.targetEditor=te;
			}
			return te;
		}
	}

	/**
	 * convert
	 */
	public void cvt(Object param)
		throws SAXException, IOException
	{
		if (param==null) // no data
			throw new SAXException("targetEditor requires PCDATA or CDATA");

		List validList=(List)param;
		QMTargetEditor dm=(QMTargetEditor)dataModel;

		addStringAttribute("class",dm.editor);
		addStringAttribute("targetClass",dm.target);
		startElement("targetEditor");
		doCvt(validList,null);
		endElement("targetEditor");
	}
}
