Java tutorial
/** * PureInfo Dolphin * @(#)FormatterDefinement.java 1.0 Aug 25, 2005 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.dolphin.script.formatter.model; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.dom4j.Element; import com.pureinfo.dolphin.script.param.ParameterMetadata; import com.pureinfo.force.exception.CheckUtils; import com.pureinfo.force.exception.PureException; import com.pureinfo.force.xml.IXMLSupporter; import com.pureinfo.force.xml.XMLUtil; /** * <P> * Created on Aug 25, 2005 4:53:55 PM <BR> * Last modified on Aug 25, 2005 * </P> * * @author Freeman.Hu * @version 1.0, Aug 25, 2005 * @since Dolphin 1.0 */ public class FormatterMetadata implements IXMLSupporter { public static final String ATTRIBUTE_CLASSNAME = "class"; public static final String ATTRIBUTE_TYPE = "type"; public static final String ELEMENT_FORMATTER = "formatter"; /** * a map of <code>ParameterDefinement</code> and her name. */ private Map m_params; /** * the name of class that implement formatter */ private String m_sClassName; /** * the type name of the formatter */ private String m_sType; public FormatterMetadata() { } /** * The type of formatter * * @return */ public String getType() { return m_sType; } /** * The name of the class which implements the formatter * * @return */ public String getClassName() { return m_sClassName; } /** * The parameters that declared in the formatter Mapping format: * <formatter-type(String),formatterMetadata(FormatterMetadata)><br> * * @return */ public Map getParams() { return m_params; } /** * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element) */ public void toXMLElement(Element _element) throws PureException { throw new UnsupportedOperationException("plz diy"); } /** * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element) */ public void fromXML(Element _element) throws PureException { CheckUtils.checkRequestNotNull(_element); CheckUtils.checkElementName(_element, ELEMENT_FORMATTER); m_sType = XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_TYPE); m_sClassName = XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_CLASSNAME); m_params = ParameterMetadata.getParameterMetadatas(_element, true); } /** * Returns the formatter metadatas mapping in the specified element. <BR> * Mapping format: * <formatter-type(String),formatterMedatada(FormatterMedatada)><br> * * @param _element * @return Empty map if has no formatters * @throws PureException */ public static Map getFormatters(Element _element) throws PureException { CheckUtils.checkRequestNotNull(_element); List elements = _element.elements(ELEMENT_FORMATTER); Map formatters = new HashMap(); for (Iterator iter = elements.iterator(); iter.hasNext();) { Element fmtEle = (Element) iter.next(); FormatterMetadata fmtMeta = new FormatterMetadata(); fmtMeta.fromXML(fmtEle); formatters.put(fmtMeta.getType(), fmtMeta); } return formatters; } }