Search in sources :

Example 16 with ConfigBean

use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.

the class IOCConfig method check.

public static synchronized String check() {
    String error = null;
    ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
    if (cb == null)
        return null;
    List<String> iocXmlFilePaths = cb.getIoc().getIocXmlFiles().getPath();
    log.debug("ioc xml files size -> " + iocXmlFilePaths.size());
    for (String filePath : iocXmlFilePaths) {
        if (filePath == null || filePath.length() == 0)
            continue;
        File configFile = new File(ConfigConstant.CONFIG_BASE_PATH + filePath);
        log.debug("check ioc file -> " + configFile.getAbsolutePath());
        try {
            XMLReader reader = BeanXMLUtil.getBeanXMLReader(configFile);
            reader.setBeanName("ioc");
            reader.setClass("ioc", IOCConfigBean.class);
            List<IOCConfigBean> iocList = reader.read();
            if (iocList == null || iocList.isEmpty()) {
                error = rebuildXmlFile(ConfigInfoCons.CANNOT_READ_CONFIG_FILE, configFile);
            } else {
                log.debug("read from the ioc file there has ->" + iocList.size() + " beans will be checked ");
                for (IOCConfigBean ioc : iocList) {
                    String error1 = CheckConfigBean.checkIOC(ioc, filePath);
                    if (error1 != null)
                        if (error == null)
                            error = error1;
                        else
                            error += error1;
                    String error2 = CheckConfigBean.checkIOCJnject(ioc.getInject(), iocList, ioc.getId(), filePath);
                    if (error2 != null)
                        if (error == null)
                            error = error2;
                        else
                            error += error2;
                }
                if (error == null) {
                    for (IOCConfigBean ioc : iocList) IOCConfigBeanCache.add(ioc.getId(), ioc);
                    log.debug(configFile.getAbsolutePath() + " beans has checked success ");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            error = rebuildXmlFile(error + "|" + CommonUtil.getExceptionString(e), configFile);
        }
    }
    if (error != null)
        IOCConfigBeanCache.clear();
    return error;
}
Also used : CheckConfigBean(org.eweb4j.config.CheckConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) IOCConfigBean(org.eweb4j.ioc.config.bean.IOCConfigBean) IOCConfigBean(org.eweb4j.ioc.config.bean.IOCConfigBean) File(java.io.File) XMLReader(org.eweb4j.util.xml.XMLReader)

Example 17 with ConfigBean

use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.

the class EWebFilter method destroy.

/**
	 * 退出Filter
	 */
public void destroy() {
    String info = "eweb4j filter destroy invoke...\n";
    LogFactory.getMVCLogger(EWebFilter.class).debug(info);
    //CallBack after destroy
    ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
    Listeners listeners = cb.getListeners();
    if (listeners != null && listeners.getListener() != null && !listeners.getListener().isEmpty()) {
        for (ListenerBean lb : listeners.getListener()) {
            String clazz = lb.getClazz();
            try {
                EWeb4JListener listener = (EWeb4JListener) CommonUtil.loadClass(clazz).newInstance();
                listener.onDestroy();
                LogFactory.getMVCLogger(EWebFilter.class).debug("listener->" + listener + ".onDestroy execute...");
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Listeners(org.eweb4j.config.bean.Listeners) EWeb4JListener(org.eweb4j.config.EWeb4JListener) ListenerBean(org.eweb4j.config.bean.ListenerBean) ConfigBean(org.eweb4j.config.bean.ConfigBean)

Example 18 with ConfigBean

use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.

the class ORMConfig method check.

public static synchronized String check() {
    String error = null;
    ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
    if (cb == null)
        return null;
    List<String> ormXmlFilePaths = cb.getOrm().getOrmXmlFiles().getPath();
    for (String filePath : ormXmlFilePaths) {
        if (filePath == null || filePath.length() == 0)
            continue;
        File configFile = new File(ConfigConstant.CONFIG_BASE_PATH + filePath);
        try {
            XMLReader reader = BeanXMLUtil.getBeanXMLReader(configFile);
            reader.setBeanName("orm");
            reader.setClass("orm", ORMConfigBean.class);
            List<ORMConfigBean> ormList = reader.read();
            if (ormList == null || ormList.isEmpty()) {
                error = rebuildXmlFile(configFile, ConfigInfoCons.CANNOT_READ_ANY_CONFIG_INFO);
            } else {
                for (ORMConfigBean orm : ormList) {
                    String error1 = CheckConfigBean.checkORM(orm, filePath);
                    if (error1 != null)
                        if (error == null)
                            error = error1;
                        else
                            error += error1;
                    String error2 = CheckConfigBean.checkORMProperty(orm.getProperty(), ormList, orm.getId(), filePath);
                    if (error2 != null)
                        if (error == null)
                            error = error2;
                        else
                            error += error2;
                }
                if (error == null) {
                    for (ORMConfigBean orm : ormList) {
                        if (!"".equals(orm.getClazz()))
                            ORMConfigBeanCache.add(orm.getClazz(), orm);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            error = rebuildXmlFile(configFile, CommonUtil.getExceptionString(e));
        }
    }
    if (error != null)
        ORMConfigBeanCache.clear();
    else
        log.debug(ConfigInfoCons.READ_CONFIG_INFO_SUCCESS);
    return error;
}
Also used : ORMConfigBean(org.eweb4j.orm.config.bean.ORMConfigBean) CheckConfigBean(org.eweb4j.config.CheckConfigBean) ORMConfigBean(org.eweb4j.orm.config.bean.ORMConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) File(java.io.File) XMLReader(org.eweb4j.util.xml.XMLReader)

Example 19 with ConfigBean

use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.

the class CheckConfigBean method checkMVCValidator.

/**
	 * Check the Validator part of MVC components configuration
	 * 
	 * @param rList
	 * @return
	 */
public static String checkMVCValidator(List<ValidatorConfigBean> vList, String beanID, String xmlFile) {
    String error = null;
    ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
    if ("true".equals(cb.getMvc().getOpen()) || "1".equals(cb.getMvc().getOpen())) {
        if (vList != null && !vList.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            for (Iterator<ValidatorConfigBean> it = vList.iterator(); it.hasNext(); ) {
                ValidatorConfigBean v = it.next();
                if (!"".equals(v.getName())) {
                    if (!Validators.REQUIRED.equalsIgnoreCase(v.getName()) && !Validators.INT.equalsIgnoreCase(v.getName()) && !Validators.EMAIL.equalsIgnoreCase(v.getName()) && !Validators.DATE.equalsIgnoreCase(v.getName()) && !Validators.URL.equalsIgnoreCase(v.getName()) && !Validators.ID_CARD.equalsIgnoreCase(v.getName()) && !Validators.ZIP.equalsIgnoreCase(v.getName()) && !Validators.PHONE.equalsIgnoreCase(v.getName()) && !Validators.QQ.equalsIgnoreCase(v.getName()) && !Validators.IP.equals(v.getName()) && !Validators.CHINESE.equalsIgnoreCase(v.getName()) && !Validators.LENGTH.equalsIgnoreCase(v.getName()) && !Validators.SIZE.equalsIgnoreCase(v.getName()) && !Validators.FORBID.equalsIgnoreCase(v.getName()) && !Validators.ENUM.equalsIgnoreCase(v.getName())) {
                        sb.append("当前您填写的:( name=").append(v.getName());
                        sb.append(" )是错误的!它只能填写为:required|int|");
                        sb.append("email|date|url|idCard|zip|phone|qq|ip|");
                        sb.append("chinese|length|size|forbid|enum|留空  中的一种 ,忽略大小写 ;\n");
                    } else if (Validators.SIZE.equalsIgnoreCase(v.getName())) {
                        int minSize = 0;
                        for (FieldConfigBean f : v.getField()) {
                            for (ParamConfigBean p : f.getParam()) {
                                if (Validators.MIN_SIZE_PARAM.equalsIgnoreCase(p.getName())) {
                                    if (!(p.getValue().matches(RegexList.integer_regexp))) {
                                        sb.append("<param>当前您填写的:( value=").append(p.getValue());
                                        sb.append(" )是错误的!它应该填写为数字");
                                    } else {
                                        minSize = Integer.parseInt(p.getValue());
                                    }
                                } else if (Validators.MAX_SIZE_PARAM.equalsIgnoreCase(p.getName())) {
                                    if (!(p.getValue().matches(RegexList.integer_regexp))) {
                                        sb.append("<param>当前您填写的:( value=").append(p.getValue());
                                        sb.append(" )是错误的!它应该填写为数字");
                                    } else {
                                        int maxSize = Integer.parseInt(p.getValue());
                                        if (minSize > maxSize) {
                                            sb.append("<param>当前您填写的:( value=").append(p.getValue());
                                            sb.append(" )是错误的!它不能比minSize的值");
                                            sb.append(minSize).append("更小");
                                        }
                                    }
                                } else {
                                    sb.append("<param>当前您填写的:( name=").append(p.getName());
                                    sb.append(" )是错误的!它只能填写为:minSize|maxSize|");
                                    sb.append("中的一种 ,忽略大小写 ;\n");
                                }
                            }
                        }
                    } else if (Validators.LENGTH.equalsIgnoreCase(v.getName())) {
                        int minLength = 0;
                        for (FieldConfigBean f : v.getField()) {
                            for (ParamConfigBean p : f.getParam()) {
                                if (Validators.MIN_LENGTH_PARAM.equalsIgnoreCase(p.getName())) {
                                    if (!(p.getValue().matches(RegexList.integer_regexp))) {
                                        sb.append("<param>当前您填写的:( value=").append(p.getValue());
                                        sb.append(" )是错误的!它应该填写为数字");
                                    } else {
                                        minLength = Integer.parseInt(p.getValue());
                                    }
                                } else if (Validators.MAX_LENGTH_PARAM.equalsIgnoreCase(p.getName())) {
                                    if (!(p.getValue().matches(RegexList.integer_regexp))) {
                                        sb.append("<param>当前您填写的:( value=").append(p.getValue());
                                        sb.append(" )是错误的!它应该填写为数字");
                                    } else {
                                        int maxLength = Integer.parseInt(p.getValue());
                                        if (minLength > maxLength) {
                                            sb.append("<param>当前您填写的:( value=").append(p.getValue());
                                            sb.append(" )是错误的!它不能比minLength的值");
                                            sb.append(minLength).append("更小");
                                        }
                                    }
                                } else {
                                    sb.append("<param>当前您填写的:( name=").append(p.getName());
                                    sb.append(" )是错误的!它只能填写为:minLength|maxLength|");
                                    sb.append("中的一种 ,忽略大小写 ;\n");
                                }
                            }
                        }
                    } else if (Validators.FORBID.equalsIgnoreCase(v.getName())) {
                        for (FieldConfigBean f : v.getField()) {
                            for (ParamConfigBean p : f.getParam()) {
                                if (!Validators.FORBID_WORD_PARAM.equalsIgnoreCase(p.getName())) {
                                    sb.append("<param>当前您填写的:( name=").append(p.getName());
                                    sb.append(" )是错误的!它只能填写为:forbidWord|");
                                    sb.append("忽略大小写 ;\n");
                                }
                            }
                        }
                    } else if (Validators.ENUM.equalsIgnoreCase(v.getName())) {
                        for (FieldConfigBean f : v.getField()) {
                            for (ParamConfigBean p : f.getParam()) {
                                if (!Validators.ENUM_WORD_PARAM.equalsIgnoreCase(p.getName())) {
                                    sb.append("<param>当前您填写的:( name=").append(p.getName());
                                    sb.append(" )是错误的!它只能填写为:enumWord|");
                                    sb.append("忽略大小写 ;\n");
                                }
                            }
                        }
                    }
                }
                if (!"".equals(v.getClazz())) {
                    try {
                        if (Thread.currentThread().getContextClassLoader().loadClass(v.getClazz()) == null) {
                            sb.append("当前您填写的( class=").append(v.getClazz()).append(" )是错误的!它必须是一个有效的类 ;\n");
                        }
                    } catch (ClassNotFoundException e) {
                        sb.append("当前您填写的( class=").append(v.getClazz()).append(" )是错误的!它必须是一个有效的类 ;\n");
                    }
                }
            }
            if (!"".equals(sb.toString())) {
                error = "\n<br /><b>" + xmlFile + "[bean name=" + beanID + "][validator]:</b>\n" + sb.toString();
            }
        }
    }
    return error;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean) ORMConfigBean(org.eweb4j.orm.config.bean.ORMConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) ResultConfigBean(org.eweb4j.mvc.config.bean.ResultConfigBean) IOCConfigBean(org.eweb4j.ioc.config.bean.IOCConfigBean) LogConfigBean(org.eweb4j.config.bean.LogConfigBean) ActionConfigBean(org.eweb4j.mvc.config.bean.ActionConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) InterConfigBean(org.eweb4j.mvc.config.bean.InterConfigBean) ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean)

Example 20 with ConfigBean

use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.

the class CheckConfigBean method checkIOC.

/**
	 * Check the IOC independent components configuration files
	 * 
	 * @param ioc
	 * @return
	 */
public static String checkIOC(IOCConfigBean ioc, String xmlFile) {
    String error = null;
    ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
    if ("true".equalsIgnoreCase(cb.getIoc().getOpen()) || "1".equals(cb.getIoc().getOpen())) {
        StringBuilder sb = new StringBuilder();
        if (ioc.getScope() == null)
            ioc.setScope("");
        if (!"prototype".equalsIgnoreCase(ioc.getScope()) && !"singleton".equalsIgnoreCase(ioc.getScope()) && !"".equals(ioc.getScope())) {
            sb.append("当前您填写的:( scope=").append(ioc.getScope()).append(" )是错误的!它只能填写为:prototype|singleton 中的一种 ;").append("\n");
        }
        if (!"".equals(ioc.getClazz())) {
            try {
                if (Thread.currentThread().getContextClassLoader().loadClass(ioc.getClazz()) == null) {
                    sb.append("当前您填写的( class=").append(ioc.getClazz()).append(" )是错误的!它必须是一个有效的类 ;\n");
                }
            } catch (ClassNotFoundException e) {
                sb.append("当前您填写的( class=").append(ioc.getClazz()).append(" )是错误的!它必须是一个有效的类 ;\n");
            }
        }
        if (!"".equals(sb.toString())) {
            error = "\n<br /><b>" + xmlFile + ":[bean id=" + ioc.getId() + "]</b>\n" + sb.toString();
        }
    }
    return error;
}
Also used : ORMConfigBean(org.eweb4j.orm.config.bean.ORMConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) ResultConfigBean(org.eweb4j.mvc.config.bean.ResultConfigBean) IOCConfigBean(org.eweb4j.ioc.config.bean.IOCConfigBean) LogConfigBean(org.eweb4j.config.bean.LogConfigBean) ActionConfigBean(org.eweb4j.mvc.config.bean.ActionConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) InterConfigBean(org.eweb4j.mvc.config.bean.InterConfigBean) ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean)

Aggregations

ConfigBean (org.eweb4j.config.bean.ConfigBean)28 DBInfoConfigBean (org.eweb4j.orm.dao.config.bean.DBInfoConfigBean)13 LogConfigBean (org.eweb4j.config.bean.LogConfigBean)12 ORMConfigBean (org.eweb4j.orm.config.bean.ORMConfigBean)12 File (java.io.File)10 IOCConfigBean (org.eweb4j.ioc.config.bean.IOCConfigBean)10 ActionConfigBean (org.eweb4j.mvc.config.bean.ActionConfigBean)10 InterConfigBean (org.eweb4j.mvc.config.bean.InterConfigBean)10 FieldConfigBean (org.eweb4j.mvc.config.bean.FieldConfigBean)9 ParamConfigBean (org.eweb4j.mvc.config.bean.ParamConfigBean)9 ResultConfigBean (org.eweb4j.mvc.config.bean.ResultConfigBean)9 ValidatorConfigBean (org.eweb4j.mvc.config.bean.ValidatorConfigBean)9 XMLReader (org.eweb4j.util.xml.XMLReader)6 CheckConfigBean (org.eweb4j.config.CheckConfigBean)5 Method (java.lang.reflect.Method)4 Prop (org.eweb4j.config.bean.Prop)4 ReflectUtil (org.eweb4j.util.ReflectUtil)4 IOException (java.io.IOException)3 LogsConfigBean (org.eweb4j.config.bean.LogsConfigBean)3 FileInputStream (java.io.FileInputStream)2