cn.featherfly.constant.ConstantConfigurator Maven / Gradle / Ivy
The newest version!
package cn.featherfly.constant;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.core.type.classreading.MetadataReader;
import cn.featherfly.common.bean.BeanUtils;
import cn.featherfly.common.io.ClassPathScanningProvider;
import cn.featherfly.common.lang.ClassUtils;
import cn.featherfly.common.lang.LangUtils;
import cn.featherfly.common.lang.StringUtils;
import cn.featherfly.constant.annotation.ConstantClass;
import cn.featherfly.constant.configuration.ConstantParameter;
import cn.featherfly.conversion.core.ConversionPolicy;
import cn.featherfly.conversion.core.ConversionPolicysJdk8;
import cn.featherfly.conversion.parse.ParsePolity;
import cn.featherfly.conversion.parse.Parser;
/**
*
* 可配置常量配置读取.
*
*
* @author 钟冀
*/
public class ConstantConfigurator extends MulitiFileTypeConfigurator {
public static final String DEFAULT_FILE = "constant.yaml";
// ********************************************************************
// 构造方法
// ********************************************************************
/**
* @param abstractConfigurators
* abstractConfigurators
*/
private ConstantConfigurator(String fileName,
AbstractConfigurator... abstractConfigurators) {
super(fileName, abstractConfigurators);
}
//
// /**
// * @param conversionPolicy
// * conversionPolicy
// * @param parsePolity
// * parsePolity
// */
// ConstantConfigurator(String fileName, ConversionPolicy conversionPolicy,
// ParsePolity parsePolity, ConstantPool constantPool) {
// this(fileName, new DOMConfigurator(fileName, conversionPolicy,
// parsePolity, constantPool)
// , new YAMLConfigurator(fileName, conversionPolicy, parsePolity,
// constantPool));
// }
public static ConstantConfigurator config() {
return config(ConversionPolicysJdk8.getFormatConversionPolicy());
}
public static ConstantConfigurator config(String fileName) {
return config(fileName,
ConversionPolicysJdk8.getFormatConversionPolicy(), null);
}
public static ConstantConfigurator config(
ConversionPolicy conversionPolicy) {
return config(conversionPolicy, null);
}
public static ConstantConfigurator config(ConversionPolicy conversionPolicy,
ParsePolity parsePolity) {
return config(DEFAULT_FILE, conversionPolicy, parsePolity);
}
public static ConstantConfigurator config(String fileName,
ConversionPolicy conversionPolicy, ParsePolity parsePolity) {
ConstantParameter config = ConstantParameter.DEFAULT;
if (parsePolity == null) {
parsePolity = initParserPolity(config);
}
ConstantPool constantPool = ConstantPool.init();
DOMConfigurator domConfigurator = new DOMConfigurator(fileName,
conversionPolicy, parsePolity, constantPool);
domConfigurator.getFilterTypePolicy().clear().setEnableWhiteList(false)
.addBlack(ConstantParameter.class);
YAMLConfigurator yamlConfigurator = new YAMLConfigurator(fileName,
conversionPolicy, parsePolity, constantPool);
yamlConfigurator.getFilterTypePolicy().clear().setEnableWhiteList(false)
.addBlack(ConstantParameter.class);
ConstantConfigurator configurator = new ConstantConfigurator(fileName,
domConfigurator, yamlConfigurator);
configurator.addConstant(config, false);
configurator.load();
// configurator.parse(configurator.getConstants());
config = configurator.getConstant(config.getClass());
// Collection
© 2015 - 2024 Weber Informatics LLC | Privacy Policy