Java tutorial
/** * PureInfo Dolphin * @(#)FormatterDeclaration.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.Parameter; import com.pureinfo.force.container.IClearable; 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:52:59 PM <BR> * Last modified on Aug 25, 2005 * </P> * * @author Freeman.Hu * @version 1.0, Aug 25, 2005 * @since Dolphin 1.0 */ public class Formatter implements IXMLSupporter, IClearable { public static final String ATTRIBUTE_ID = "id"; public static final String ATTRIBUTE_TYPE = "type"; public static final String ELEMENT_FORMATTER = "formatter"; public static final String ELEMENT_PARAMETER = "param"; private final Map m_params = new HashMap(); private String m_sId; private String m_sType; /** * Constructor: default */ public Formatter() { super(); } /** * @see com.pureinfo.force.container.IClearable#clear() */ public synchronized void clear() { m_params.clear(); } /** * The formatter id * * @return */ public String getId() { return m_sId; } /** * The type of the formatter which is defined in formatter metadata. * * @return */ public String getType() { return m_sType; } /** * The parameters of the formatter. <br> * Mapping formatter: <param-name(String),param-value(String)> * * @return Empty map if no parameters */ 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_sId = XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_ID); m_sType = XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_TYPE); Parameter.readParameters(_element, m_params, true); } /** * Returns the formatters mapping in the specified element. <BR> * Mapping format: <formatter-id(String), formatter(Formatter)> * * @param _element * @throws PureException */ public static void readFormatters(Element _element, Map _container) throws PureException { CheckUtils.checkRequestNotNull(_element); List fmtEleList = _element.elements(ELEMENT_FORMATTER); for (Iterator iter = fmtEleList.iterator(); iter.hasNext();) { Element fmtEle = (Element) iter.next(); Formatter formatter = new Formatter(); formatter.fromXML(fmtEle); _container.put(formatter.getId(), formatter); } } }