com.pureinfo.srm.view.function.IsOutlayPayoutPropertyEnabledFunctionHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.view.function.IsOutlayPayoutPropertyEnabledFunctionHandler.java

Source

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

package com.pureinfo.srm.view.function;

import java.util.Iterator;

import org.dom4j.Element;

import com.pureinfo.dolphin.script.ScriptExceptionTypes;
import com.pureinfo.dolphinview.context.model.IDVContext;
import com.pureinfo.dolphinview.parser.function.FunctionHandlerDVImplBase;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.force.io.ClassResourceUtil;
import com.pureinfo.force.xml.XMLUtil;

/**
 * <P>
 * Created on 2007-2-7 07:06:48<BR>
 * Last modified on 2007-2-7
 * </P>
 * 
 * @author sunjie
 * @version 1.0, 2007-2-7
 * @since Quake 1.0 
 */
public class IsOutlayPayoutPropertyEnabledFunctionHandler extends FunctionHandlerDVImplBase {

    /** the minimum number of arguments */
    public final static int MIN_ARG_NUM = 1;

    /** index of argument property name */
    private final static int PROPERTY_NAME = 0;

    /**
     * Constructor
     * 
     * @return
     */
    public IsOutlayPayoutPropertyEnabledFunctionHandler() {
        super();
    }

    /**
     * @see com.pureinfo.dolphinview.parser.function.FunctionHandlerDVImplBase#perform(java.lang.Object[],
     *      com.pureinfo.dolphinview.context.model.IDVContext)
     */
    public Object perform(Object[] _args, IDVContext _context) throws PureException {
        if (_args.length < MIN_ARG_NUM) {
            throw new PureException(ScriptExceptionTypes.FUNCTION_ARGS_NUM_NOTMATCH,
                    "required " + MIN_ARG_NUM + " but actual " + _args.length);
        }
        String sFileName = ClassResourceUtil.mapFullPath("OutlayPayout.cfg.xml", true);
        String sProperty = (String) _args[PROPERTY_NAME];
        String sResult = "";
        Element m_root;
        Element singleElement;

        m_root = XMLUtil.fileToElement(sFileName);
        if (m_root == null)
            return "";
        for (Iterator iter = m_root.elementIterator("property"); iter.hasNext();) {
            singleElement = (Element) iter.next();
            if (XMLUtil.getAttributeValueTrim(singleElement, "name").equals(sProperty)) {
                sResult = XMLUtil.getAttributeValueTrim(singleElement, "enabled");
                return new Boolean(sResult);
            }
        }
        return new Boolean(sResult);
    }

}