com.pureinfo.srm.config.affirm.model.Affirm.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.config.affirm.model.Affirm.java

Source

/**
 * PureInfo Quake
 * @(#)Affirm.java   1.0 Nov 11, 2005
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.srm.config.affirm.model;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.dom4j.Element;

import com.pureinfo.force.exception.PureException;
import com.pureinfo.force.xml.IXMLSupporter;
import com.pureinfo.force.xml.XMLUtil;

/**
 * <P>
 * Created on Nov 11, 2005 8:28:05 PM <BR>
 * Last modified on Nov 11, 2005
 * </P>
 * 
 * @author Freeman.Hu
 * @version 1.0, Nov 11, 2005
 * @since Quake 1.0
 */
public class Affirm implements IXMLSupporter {
    public static final String ELEMENT_AFFIRM = "affirm";

    public static final String ATTRIBUTE_NAME = "name";

    public static final String ATTRIBUTE_DAY = "day";

    private Map m_affirms = new HashMap();

    public String getDayString(String _sName) {
        return (String) m_affirms.get(_sName);
    }

    public void setDayString(String _sName, String _sValue) {
        m_affirms.put(_sName, _sValue);
    }

    public void remove(String _sName) {
        m_affirms.remove(_sName);
    }

    /**
     * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
     */
    public void toXMLElement(Element _element) throws PureException {
        for (Iterator iter = m_affirms.entrySet().iterator(); iter.hasNext();) {
            Element element = _element.addElement(ELEMENT_AFFIRM);
            Map.Entry entry = (Entry) iter.next();
            element.addAttribute(ATTRIBUTE_NAME, (String) entry.getKey());
            element.addAttribute(ATTRIBUTE_DAY, (String) entry.getValue());
        }
    }

    /**
     * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
     */
    public void fromXML(Element _element) throws PureException {
        m_affirms = new HashMap();
        for (Iterator iter = _element.elementIterator(); iter.hasNext();) {
            Element element = (Element) iter.next();
            String sName = XMLUtil.getRequiredAttributeValue(element, ATTRIBUTE_NAME);
            String sDay = XMLUtil.getRequiredAttributeValue(element, ATTRIBUTE_DAY);
            m_affirms.put(sName, sDay);
        }
    }
}