Search in sources :

Example 1 with PresetHelper

use of app.hongs.action.PresetHelper in project HongsCORE by ihongs.

the class PresetInvoker method invoke.

@Override
public void invoke(ActionHelper helper, ActionRunner chains, Annotation anno) throws HongsException {
    Preset ann = (Preset) anno;
    String conf = ann.conf();
    String form = ann.form();
    String[] deft = ann.deft();
    String[] defs = ann.defs();
    // 默认参数可完全由外部指定
    if (deft == null || deft.length == 0) {
        Set<String> uzed = Synt.toTerms(helper.getParameter(Cnst.AB_KEY));
        Set<String> used = new LinkedHashSet();
        if (null != uzed && !uzed.isEmpty()) {
            for (String item : uzed) {
                if (item.startsWith("_") || item.startsWith(".") || item.startsWith("!")) {
                    if (item.equals("_obj_")) {
                        Core.getInstance().put(Cnst.OBJECT_MODE, true);
                    } else if (item.equals("_str_")) {
                        Core.getInstance().put(Cnst.OBJECT_MODE, false);
                    }
                    continue;
                }
                used.add("!" + item);
            }
            deft = used.toArray(new String[0]);
        }
    }
    // 识别路径
    if (form.length() == 0) {
        form = chains.getEntity();
    }
    if (conf.length() == 0) {
        conf = chains.getModule();
        // 照顾 Module Action 的配置规则
        if (FormSet.hasConfFile(conf + "/" + form)) {
            conf = conf + "/" + form;
        }
    }
    // 补充参数
    try {
        Map req;
        PresetHelper pre;
        req = helper.getRequestData();
        pre = new PresetHelper();
        pre.addItemsByForm(conf, form, deft, defs);
        pre.preset(req, helper);
    } catch (HongsException ex) {
        int ec = ex.getErrno();
        if (ec != 0x10e8 && ec != 0x10e9 && ec != 0x10eb) {
            throw ex;
        }
    }
    chains.doAction();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HongsException(app.hongs.HongsException) PresetHelper(app.hongs.action.PresetHelper) Map(java.util.Map)

Aggregations

HongsException (app.hongs.HongsException)1 PresetHelper (app.hongs.action.PresetHelper)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1