/* */
|
package com.gkhy.exam.pay.utils.config;
|
/* */
|
/* */
|
|
//import com.xjhys.edu.fee.sdk.annotation.PropertiesConfig;
|
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.lang.reflect.Field;
|
import java.net.URL;
|
import java.sql.Date;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Properties;
|
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */ public class PropertiesUtil
|
/* */ {
|
/* */ public static final String PROPERTIES_SUFFIX_NAME = "properties";
|
/* */ public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
/* */ public static final String RESOURCES_PATH = "/";
|
/* */ public static final String INT_NAME = "int";
|
/* */ public static final String DOUBLE_NAME = "double";
|
/* */ public static final String FLOAT_NAME = "float";
|
/* */ public static final String LONG_NAME = "long";
|
/* */ public static final String METHOD_SET = "set";
|
|
/* */
|
/* */
|
public static Properties loadPropertiesFile(InputStream in) throws IOException {
|
/* 43 */
|
Properties p = new Properties();
|
/* 44 */
|
p.load(in);
|
/* 45 */
|
return p;
|
/* */
|
}
|
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
public static void loadData(Object propertiesBean) throws IOException {
|
/* 56 */
|
if (propertiesBean == null) {
|
/* */
|
return;
|
/* */
|
}
|
/* 59 */
|
PropertiesConfig pc = propertiesBean.getClass().<PropertiesConfig>getAnnotation(PropertiesConfig.class);
|
/* 60 */
|
String fileNmae = pc.fileName();
|
/* 61 */
|
loadData(fileNmae, propertiesBean);
|
/* */
|
}
|
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
public static void loadData(String fileNmae, Object propertiesBean) throws IOException {
|
/* 75 */
|
if (propertiesBean == null) {
|
/* */
|
return;
|
/* */
|
}
|
/* 78 */
|
URL url = PropertiesUtil.class.getResource("/" + fileNmae);
|
/* 79 */
|
InputStream openStream = url.openStream();
|
/* 80 */
|
Properties p = loadPropertiesFile(openStream);
|
/* 81 */
|
Field[] fs = propertiesBean.getClass().getDeclaredFields();
|
/* 82 */
|
for (int i = 0; i < fs.length; i++) {
|
/* 83 */
|
Field field = fs[i];
|
/* 84 */
|
PropertiesConfig pc = field.<PropertiesConfig>getAnnotation(PropertiesConfig.class);
|
/* 85 */
|
String pKey = field.getName();
|
/* 86 */
|
String value = null;
|
/* 87 */
|
if (pc != null) {
|
/* 88 */
|
value = p.getProperty(pc.name());
|
/* */
|
} else {
|
/* 90 */
|
value = p.getProperty(pKey);
|
/* */
|
}
|
/* 92 */
|
if (value != null) {
|
/* 93 */
|
field.setAccessible(true);
|
/* */
|
try {
|
/* 95 */
|
field.set(propertiesBean, conversion(value, field.getType()));
|
/* 96 */
|
} catch (IllegalArgumentException e) {
|
/* */
|
/* 98 */
|
e.printStackTrace();
|
/* 99 */
|
} catch (IllegalAccessException e) {
|
/* */
|
/* 101 */
|
e.printStackTrace();
|
/* */
|
}
|
/* */
|
}
|
/* */
|
}
|
/* */
|
}
|
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
/* */
|
public static Object conversion(String value, Class<?> type) {
|
/* 118 */
|
if (value == null) {
|
/* 119 */
|
return null;
|
/* */
|
}
|
/* 121 */
|
if ("int".equals(type.getName()) || type.getName().equals(Integer.class.getName()))
|
/* 122 */ return Integer.valueOf(value);
|
/* 123 */
|
if ("double".equals(type.getName()) || type.getName().equals(Double.class.getName()))
|
/* 124 */ return Double.valueOf(value);
|
/* 125 */
|
if ("float".equals(type.getName()) || type.getName().equals(Float.class.getName()))
|
/* 126 */ return Float.valueOf(value);
|
/* 127 */
|
if ("long".equals(type.getName()) || type.getName().equals(Long.class.getName()))
|
/* 128 */ return Long.valueOf(value);
|
/* 129 */
|
if (type.getName().equals(Date.class.getName())) {
|
/* 130 */
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
/* */
|
try {
|
/* 132 */
|
return format.parse(value);
|
/* 133 */
|
} catch (ParseException e) {
|
/* */
|
/* 135 */
|
e.printStackTrace();
|
/* */
|
}
|
/* */
|
}
|
/* */
|
/* 139 */
|
return value;
|
/* */
|
}
|
/* */
|
}
|
|
|
/* Location: D:\jar\sign_util-1.0-SNAPSHOT.20240227.jar!\BOOT-INF\lib\SNAPSHOT-1.0.0.jar!\com\xjhys\edu\fee\sd\\utils\PropertiesUtil.class
|
* Java compiler version: 8 (52.0)
|
* JD-Core Version: 1.1.3
|
*/
|