Java tutorial
/** * PureInfo Quake * @(#)NoticeItem.java 1.0 Nov 10, 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.notice.model; import org.apache.commons.lang.math.NumberUtils; 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 10, 2005 12:06:06 PM <BR> * Last modified on Nov 10, 2005 * </P> * * @author Freeman.Hu * @version 1.0, Nov 10, 2005 * @since Quake 1.0 */ public class NoticeItem implements IXMLSupporter { public static final int NOTICE_IMMEDIATE_DAY = -1; public static final String ATTRIBUTE_NAME = "name"; public static final String ELEMENT_CHECKED = "checked"; public static final String ELEMENT_DAY = "day"; public static final String ELEMENT_TEXT = "text"; private String m_sName; private boolean m_bChecked; private int m_nDay; private String m_sText; public NoticeItem(String _sName) { m_sName = _sName; m_bChecked = false; m_nDay = NOTICE_IMMEDIATE_DAY; m_sText = ""; } public NoticeItem() { } public boolean isChecked() { return m_bChecked; } public void setChecked(boolean _nChecked) { m_bChecked = _nChecked; } public int getDay() { return m_nDay; } public String getDayString() { return m_nDay == NoticeItem.NOTICE_IMMEDIATE_DAY ? "" : String.valueOf(m_nDay); } public void setDay(int _nDay) { m_nDay = _nDay; } public String getText() { return m_sText; } public void setText(String _nText) { m_sText = _nText; } public String getName() { return m_sName; } public void setName(String _nName) { m_sName = _nName; } /** * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element) */ public void toXMLElement(Element _element) throws PureException { _element.addAttribute(ATTRIBUTE_NAME, m_sName); _element.addElement(ELEMENT_CHECKED).addText(String.valueOf(m_bChecked)); _element.addElement(ELEMENT_DAY).addText(String.valueOf(m_nDay)); _element.add(XMLUtil.createElement(ELEMENT_TEXT, m_sText, true)); } /** * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element) */ public void fromXML(Element _element) throws PureException { m_sName = _element.attributeValue(ATTRIBUTE_NAME); m_bChecked = Boolean.valueOf(_element.elementText(ELEMENT_CHECKED)).booleanValue(); m_nDay = Integer.parseInt(_element.elementText(ELEMENT_DAY)); m_sText = _element.elementText(ELEMENT_TEXT); } public void setDayString(String _sDay) { if (NumberUtils.isDigits(_sDay)) { m_nDay = Integer.parseInt(_sDay); } else { m_nDay = NOTICE_IMMEDIATE_DAY; } } }