Java tutorial
/** * PureInfo Quake * @(#)OutlayPayoutConfigHelper.java 1.0 2007-2-8 * * 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.outlay; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.dom4j.Element; import com.pureinfo.force.exception.PureRuntimeException; import com.pureinfo.force.io.ClassResourceUtil; import com.pureinfo.force.xml.XMLUtil; import com.pureinfo.srm.SRMExceptionTypes; /** * <P> * Created on 2007-2-8 10:46:18<BR> * Last modified on 2007-2-8 * </P> * OutlayPayoutConfigHelper * * @author sunjie * @version 1.0, 2007-2-8 * @since Quake 1.0 */ public class OutlayPayoutConfigHelper { public final static String m_sConfigFileName = "OutlayPayout.cfg.xml"; /** * * <P> * Created on 2007-3-26 03:17:44<BR> * Last modified on 2007-3-26 * </P> * Rpms * * @author sunjie * @version 1.0, 2007-3-26 * @since SRM3.0 1.0 */ public static class RpmsName { /** */ public static String BUSINESS_FEE = ""; /** */ public static String BOOK_FEE = ""; /** */ public static String TRANSFERRED = ""; /** */ public static String DEVICE_FEE = ""; /** */ public static String MANAGE_FEE = ""; /** */ public static String OTHER_FEE = ""; /** */ public static String BIG_DEVICE_FEE = "1"; } private boolean m_bLoaded = false; private OutlayPayoutPropertyObj m_propertyObj; private static OutlayPayoutConfigHelper s_instance = new OutlayPayoutConfigHelper(); private Map map = new HashMap(); private List all = new ArrayList(); private OutlayPayoutConfigHelper() { super(); } public static OutlayPayoutConfigHelper getInstance() { if (!s_instance.m_bLoaded) { s_instance.insureLoaded(); } return s_instance; } private void insureLoaded() { if (m_bLoaded) return; synchronized (this) { if (m_bLoaded) return; this.init(); m_bLoaded = true; } } public static void clear() { // @ TODO } public static void remove(String _sName) { // @ TODO } public static String getDesc(String _sName) { return ((OutlayPayoutPropertyObj) getInstance().map.get(_sName)).getDesc(); } public static boolean isStat(String _sName) { return ((OutlayPayoutPropertyObj) getInstance().map.get(_sName)).isStat(); } public static boolean isEnabled(String _sName) { return ((OutlayPayoutPropertyObj) getInstance().map.get(_sName)).isEnable(); } /** * get all OutlayPayoutPropertyObj * * @return */ public List getAll() { return all; } private void init() { try { String sResource = ClassResourceUtil.mapFullPath(m_sConfigFileName, true); Element root = XMLUtil.fileToElement(sResource); Element element; for (Iterator iter = root.elementIterator("property"); iter.hasNext();) { element = (Element) iter.next(); m_propertyObj = new OutlayPayoutPropertyObj(); m_propertyObj.fromXML(element); map.put(m_propertyObj.getName(), m_propertyObj); all.add(m_propertyObj); } } catch (Exception ex) { throw new PureRuntimeException(SRMExceptionTypes.CONFIG_LOAD, m_sConfigFileName, ex); } } }