Java tutorial
/** * PureInfo Dolphin * @(#)Function.java 1.0 2005-8-30 * * 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.lang; import java.util.ArrayList; import java.util.List; import org.dom4j.Element; import com.pureinfo.dolphin.script.ScriptConstants; import com.pureinfo.force.container.ContainerUtil; import com.pureinfo.force.container.IClearable; import com.pureinfo.force.exception.PureException; import com.pureinfo.force.xml.IXMLSupporter; /** * <P> * Created on 2005-8-30 0:27:09 <BR> * Last modified on 2005-8-30 * </P> * Function: function in Dolphin view script. * * @author Why * @version 1.0, 2005-8-30 * @since Dolphin 1.0 */ public class Function implements IClearable, IXMLSupporter { private String m_sName; private List m_parameters; /** * Constructor */ public Function() { super(); m_parameters = new ArrayList(0); } /** * @see com.pureinfo.force.container.IClearable#clear() */ public void clear() { if (m_parameters != null) { ContainerUtil.clear(m_parameters); } } /** * Returns the function name. * * @return the function name. */ public String getName() { return m_sName; } /** * Sets the function name. * * @param _sName * the function name. */ public void setName(String _sName) { m_sName = _sName; } /** * Returns the parameters list. * * @return the parameters list. */ public List getParameters() { return m_parameters; } /** * Adds a parameter. * * @param _parameter * a statement as parameter. */ public void addParameter(Expression _parameter) { m_parameters.add(_parameter); } /** * @see java.lang.Object#toString() */ public String toString() { StringBuffer buff = new StringBuffer(); try { buff.append(ScriptConstants.PREFIX_FUNCTION); buff.append(m_sName); buff.append('('); for (int i = 0; i < m_parameters.size(); i++) { if (i > 0) { buff.append(","); } buff.append(m_parameters.get(i).toString()); } buff.append(')'); return buff.toString(); } finally { buff.setLength(0); } } //========================================================================= //implementation for IXMLSupporter /** * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element) */ public void toXMLElement(Element _element) throws PureException { _element.addAttribute("name", m_sName); Expression param; Element eleParam; for (int i = 0; i < m_parameters.size(); i++) { param = (Expression) m_parameters.get(i); eleParam = _element.addElement("param"); param.toXMLElement(eleParam); } } /** * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element) */ public void fromXML(Element _element) throws PureException { // TODO Auto-generated method stub } }