⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bizatomconfigchecker.java

📁 这个是使用java开发的一个平台
💻 JAVA
字号:
package com.exp.bizatom.auto.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import com.exp.bizatom.BizAtomContext;
import com.exp.bizatom.BizAtomEngine;
import com.exp.bizatom.auto.BizAutoAtomLogic;
import com.exp.bizatom.auto.statement.BizAtomStatement;
import com.exp.bizatom.auto.statement.BlockBizAtomStatement;
import com.exp.bizatom.auto.statement.CommandBizAtomStatement;
import com.exp.bizatom.auto.statement.ReturnBizAtomStatement;
import com.exp.bizatom.auto.statement.SetVOBizAtomStatement;
import com.exp.bizatom.auto.statement.SetVariableBizAtomStatement;

public class BizAtomConfigChecker {
    public static void check(String name) {
        BizAtomConfigChecker checker = new BizAtomConfigChecker();
        String[] names = name.split(";");
        int len = names.length;
        StringBuffer bufSum = new StringBuffer();
        for (int i = 0; i < len; i++) {
            try {
                if (!"".equals(names[i])) {
                    StringBuffer buf = new StringBuffer();
                    checker.check(buf, names[i]);
                    if (buf.length() == 0) {
                        buf.append("组件[");
                        buf.append(names[i]);
                        buf.append("]合法!\n");
                    } else {
                        buf.insert(0, "组件[" + names[i] + "校验信息==>>\n]");
                    }
                    bufSum.append(buf);
                }
            } catch (Throwable thr) {
                thr.printStackTrace();
            }
        }
        System.out.println(bufSum);
    }

    protected boolean check(StringBuffer buf, String name) throws Throwable {
        BizAtomContext bizAtomContext = BizAtomEngine.getBizAtomContext(name);
        if (bizAtomContext != null) {
            BizAutoAtomLogic logic = bizAtomContext.getAutoFunction();
            if (logic != null) {
                Vector statements = logic.getStatements();
                if (statements != null) {
                    Map variables = new HashMap();
                    variables.put("param", "");
                    variables.put("return", "");
                    checkStatements("", buf, bizAtomContext, statements,
                            variables);
                } else {
                    throw new RuntimeException("该业务组件[" + name + "]未定义语句!");
                }
            } else {
                throw new RuntimeException("该业务组件[" + name + "]为非自动组件!");
            }
        } else {
            throw new RuntimeException("该业务组件不存在[" + name + "]!");
        }
        return buf.length() == 0;
    }

    private void checkStatements(String row, StringBuffer buf,
            BizAtomContext bizAtomContext, Vector statements, Map variables) {
        int size = statements.size();
        for (int i = 0; i < size; i++) {
            String realRow = "" + (i + 1);
            if (!"".equals(row)) {
                realRow += "." + row;
            }
            BizAtomStatement statement = (BizAtomStatement) statements.get(i);
            if (statement instanceof SetVOBizAtomStatement) {
                SetVOBizAtomStatement setVO = (SetVOBizAtomStatement) statement;
                String target = setVO.getName();
                String values = setVO.getValues();
                String properties = setVO.getProperties();
                String create = setVO.getCreate();
                if (!"true".equalsIgnoreCase(create)) {
                    String type = (String) variables.get(target);
                    if (type == null) {
                        buf.append("第" + realRow + "行:");
                        buf.append("目标对象不存在!\n");
                    }
                } else {
                    if (variables.get(target) == null) {
                        variables.put(target, "object");
                    }
                }
                String[] arrayPops = properties.split(";");
                String[] arrayValues = values.split(";");
                if (arrayPops.length != arrayValues.length) {
                    buf.append("第" + realRow + "行:");
                    buf.append("指定的属性数量与给定的值数量不一致!\n");
                }
                int len = arrayValues.length;
                for (int j = 0; j < len; j++) {
                    String value = arrayValues[j];
                    if (!values.startsWith("@")) {
                        value = getRealVarName(value);
                        if (variables.get(value) == null) {
                            buf.append("第" + realRow + "行:");
                            buf.append("给定的属性值中对象" + value + "不存在!\n");
                        }
                    }
                }
            } else if (statement instanceof SetVariableBizAtomStatement) {
                SetVariableBizAtomStatement setVar = (SetVariableBizAtomStatement) statement;
                Map defines = setVar.getNameValueMap();
                Set set = defines.keySet();
                Iterator item = set.iterator();
                while (item.hasNext()) {
                    String key = item.next().toString();
                    String value = defines.get(key).toString();
                    if (value.startsWith("@")) {
                        variables.put(key, "string");
                    } else {
                        value = this.getRealVarName(value);
                        if (variables.get(value) == null) {
                            buf.append("第" + realRow + "行:");
                            buf.append("设定的属性值[" + value + "]不存在!\n");
                        } else {
                            variables.put(key, "");
                        }
                    }
                }
            } else if (statement instanceof ReturnBizAtomStatement) {
                String values = ((ReturnBizAtomStatement) statement)
                        .getValues();
                String[] arrayValues = values.split(";");
                int len = arrayValues.length;
                for (int j = 0; j < len; j++) {
                    String value = arrayValues[j];
                    if (!values.startsWith("@")) {
                        value = getRealVarName(value);
                        if (variables.get(value) == null) {
                            buf.append("第" + realRow + "行:");
                            buf.append("返回值列表中给定的变量" + value + "不存在!\n");
                        }
                    }
                }
            } else if (statement instanceof CommandBizAtomStatement) {
                CommandBizAtomStatement cmd = (CommandBizAtomStatement) statement;
                String type = cmd.getType();
                String id = cmd.getId();
                String param = cmd.getParam();
                String setVar = cmd.getSetVar();

                if (bizAtomContext.getSQL(id) == null) {
                    buf.append("第" + realRow + "行:");
                    buf.append("命令中指定的SQL命令[" + id + "]不存在!\n");
                }

                if (!"seq".equals(type)) {
                    param = this.getRealVarName(param);
                    if (variables.get(param) == null) {
                        buf.append("第" + realRow + "行:");
                        buf.append("命令中指定参数对象[" + param + "]不存在!\n");
                    }
                }
                if (!"".equals(setVar)) {
                    variables.put(setVar, "");
                }
            } else if (statement instanceof BlockBizAtomStatement) {
                BlockBizAtomStatement block = (BlockBizAtomStatement) statement;
                BizAutoAtomLogic subLogic = block.getSubFunction();
                if (subLogic != null) {
                    this.checkStatements("" + i, buf, bizAtomContext, subLogic
                            .getStatements(), variables);
                }
            }
        }
    }

    private String getRealVarName(String value) {
        int sepIndex = value.indexOf(".");
        if (sepIndex != -1) {
            value = value.substring(0, sepIndex);
            sepIndex = value.indexOf("[");
            if (sepIndex != -1 && value.endsWith("]")) {
                value = value.substring(0, sepIndex);
            }
        }
        return value;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -