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;
}
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();
}
}
}
}
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;
}
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;
}
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;
}
Aggregations