Search in sources :

Example 16 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class JointGate method getForm.

private Map getForm(String mod, String ent) throws HongsException {
    String cuf = FormSet.hasConfFile(mod + "/" + ent) ? mod + "/" + ent : mod;
    FormSet form = FormSet.getInstance(cuf);
    try {
        return form.getFormTranslated(ent);
    } catch (HongsException ex) {
        if (ex.getErrno() == 0x10ea) {
            return null;
        } else {
            throw ex;
        }
    }
}
Also used : HongsException(app.hongs.HongsException) FormSet(app.hongs.action.FormSet)

Example 17 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class JoistBean method getSaveTypes.

/**
 * 获取字段类型映射
 * @return
 */
public Map<String, Set<String>> getSaveTypes() {
    if (null != fsavez) {
        return fsavez;
    }
    try {
        Map<String, Object> m = FormSet.getInstance().getEnum("__saves__");
        fsavez = new HashMap();
        for (Map.Entry<String, Object> et : m.entrySet()) {
            fsavez.put(et.getKey(), Synt.toSet(et.getValue()));
        }
        return fsavez;
    } catch (HongsException e) {
        throw e.toExpedient();
    }
}
Also used : HashMap(java.util.HashMap) HongsException(app.hongs.HongsException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class Batch method close.

@Override
public void close() {
    if (!servs.isShutdown()) {
        servs.shutdownNow();
    }
    if (back == null) {
        if (!tasks.isEmpty()) {
            CoreLogger.error("There has " + tasks.size() + " task(s) not run.");
        }
        return;
    }
    /**
     * 将缓冲区滞留的任务写回 tasks
     * 即使重启后 servs 数量改变也没有关系
     */
    Collection<T> c = new ArrayList();
    for (Collection<T> taskz : cache) {
        c.addAll(taskz);
        taskz.clear();
    }
    c.addAll(tasks);
    tasks.clear();
    tasks.addAll(c);
    File file;
    file = back;
    back = null;
    if (!tasks.isEmpty()) {
        try {
            save(file);
            CoreLogger.trace("There has " + tasks.size() + " task(s) not run, save to '" + back.getPath() + "'.");
        } catch (HongsException ex) {
            CoreLogger.error(ex);
        }
    } else if (file.exists()) {
        file.delete();
    }
}
Also used : HongsException(app.hongs.HongsException) ArrayList(java.util.ArrayList) File(java.io.File)

Example 19 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class ActionRunner method doAction.

/**
 * 执行动作方法
 * 会执行 action 方法上 annotation 指定的过滤器
 * @throws HongsException
 */
public void doAction() throws HongsException {
    // 如果超出链长度, 则终止执行
    if (idx > annarr.length) {
        throw new HongsException(0x110f, "Action annotation out of index: " + idx + ">" + annarr.length);
    }
    // 如果已到达链尾, 则执行动作
    if (idx == annarr.length) {
        doInvoke();
        return;
    }
    Filter actw;
    Annotation anno = annarr[idx++];
    if (anno instanceof Filter) {
        actw = (Filter) anno;
    } else {
        actw = anno.annotationType().getAnnotation(Filter.class);
    }
    // 如果不是动作链, 则跳过注解
    if (actw == null) {
        doAction();
        return;
    }
    // 执行注解过滤器
    Class<? extends FilterInvoker> classo = actw.value();
    FilterInvoker filter = Core.getInstance(classo);
    filter.invoke(helper, this, anno);
}
Also used : HongsException(app.hongs.HongsException) Filter(app.hongs.action.anno.Filter) FilterInvoker(app.hongs.action.anno.FilterInvoker) Annotation(java.lang.annotation.Annotation)

Example 20 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class FormSet method imports.

@Override
protected void imports() throws HongsException {
    InputStream is;
    String fn;
    try {
        fn = Core.CONF_PATH + File.separator + name + Cnst.FORM_EXT + ".xml";
        is = new FileInputStream(fn);
    } catch (FileNotFoundException ex) {
        fn = name.contains(".") || name.contains("/") ? name + Cnst.FORM_EXT + ".xml" : "app/hongs/conf/" + name + Cnst.FORM_EXT + ".xml";
        is = this.getClass().getClassLoader().getResourceAsStream(fn);
        if (null == is) {
            throw new app.hongs.HongsException(0x10e8, "Can not find the config file '" + name + Cnst.FORM_EXT + ".xml'.");
        }
    }
    Element root;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder dbn = dbf.newDocumentBuilder();
        Document doc = dbn.parse(is);
        root = doc.getDocumentElement();
    } catch (IOException ex) {
        throw new HongsException(0x10e9, "Read '" + name + Cnst.FORM_EXT + ".xml error'", ex);
    } catch (SAXException ex) {
        throw new HongsException(0x10e9, "Parse '" + name + Cnst.FORM_EXT + ".xml error'", ex);
    } catch (ParserConfigurationException ex) {
        throw new HongsException(0x10e9, "Parse '" + name + Cnst.FORM_EXT + ".xml error'", ex);
    }
    this.forms = new HashMap();
    this.enums = new HashMap();
    this.parse(root, this.forms, this.enums);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) HongsException(app.hongs.HongsException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HongsException(app.hongs.HongsException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

HongsException (app.hongs.HongsException)89 Map (java.util.Map)42 HashMap (java.util.HashMap)34 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)15 LinkedHashMap (java.util.LinkedHashMap)15 Set (java.util.Set)15 List (java.util.List)13 File (java.io.File)11 SQLException (java.sql.SQLException)10 FileNotFoundException (java.io.FileNotFoundException)9 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 PreparedStatement (java.sql.PreparedStatement)8 Iterator (java.util.Iterator)8 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)8 HongsExpedient (app.hongs.HongsExpedient)7 FormSet (app.hongs.action.FormSet)7 Table (app.hongs.db.Table)7