com.pureinfo.dolphin.script.param.Parameter.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.dolphin.script.param.Parameter.java

Source

/**
 * PureInfo Dolphin
 * @(#)ParameterDeclaration.java   1.0 Aug 29, 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.param;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.dom4j.Element;

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 29, 2005 10:13:46 AM <BR>
 * Last modified on Aug 29, 2005
 * </P>
 * 
 * @author Freeman.Hu
 * @version 1.0, Aug 29, 2005
 * @since Dolphin 1.0
 */
public class Parameter implements IXMLSupporter {

    public static final String ELEMENT_PARAMETER = "param";

    public static final String ATTRIBUTE_NAME = "name";

    /**
     * the name of parameter
     */
    private String m_sName;

    /**
     * the value of parameter
     */
    private String m_sValue;

    public Parameter() {
    }

    public Parameter(String _sName, String _sValue) {
        setName(_sName);
        setValue(_sValue);
    }

    public String getName() {
        return m_sName;
    }

    public void setName(String _sName) {
        m_sName = _sName;
    }

    public String getValue() {
        return m_sValue;
    }

    public void setValue(String _sValue) {
        m_sValue = _sValue;
    }

    /**
     * @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_PARAMETER);

        setName(XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_NAME));
        setValue(_element.getText());
    }

    /**
     * 
     * @param _element
     * @param _bRequired
     * @throws PureException
     */
    public static void readParameters(Element _element, Map _container, boolean _bRequired) throws PureException {
        if (_element == null && _bRequired) {
            throw new PureException(PureException.INVALID_REQUEST, "_element can't be null.");
        }

        List paramEleList = _element.elements(ELEMENT_PARAMETER);
        for (Iterator iter = paramEleList.iterator(); iter.hasNext();) {
            Element paramEle = (Element) iter.next();
            Parameter param = new Parameter();
            param.fromXML(paramEle);
            _container.put(param.getName(), param.getValue());
        }
    }

    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
}