AnyValueWriter
This commit is contained in:
@@ -21,13 +21,12 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
import static org.redkale.boot.Application.RESNAME_APP_CONF_DIR;
|
||||
import static org.redkale.boot.Application.RESNAME_APP_CONF_FILE;
|
||||
import static org.redkale.boot.Application.RESNAME_APP_HOME;
|
||||
import static org.redkale.boot.Application.*;
|
||||
import org.redkale.source.DataSources;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.util.RedkaleException;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
@@ -448,7 +447,7 @@ class AppConfig {
|
||||
conf = AnyValue.loadFromProperties(text).getAnyValue("redkale");
|
||||
}
|
||||
if (fromCache) {
|
||||
((AnyValue.DefaultAnyValue) conf).addValue("[config-from-cache]", "true");
|
||||
((AnyValueWriter) conf).addValue("[config-from-cache]", "true");
|
||||
}
|
||||
|
||||
return conf;
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.redkale.schedule.support.ScheduleModuleEngine;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
import org.redkale.watch.WatchServlet;
|
||||
|
||||
/**
|
||||
@@ -276,8 +275,14 @@ public final class Application {
|
||||
System.setProperty("redkale.application.nodeid", String.valueOf(this.nodeid));
|
||||
System.setProperty("redkale.application.home", this.home.getPath());
|
||||
System.setProperty("redkale.application.confPath", this.confPath.toString());
|
||||
this.sysPropNames = Collections.unmodifiableSet((Set) System.getProperties().keySet());
|
||||
this.envProperties.put(RESNAME_APP_NAME, this.name);
|
||||
this.envProperties.put(RESNAME_APP_NODEID, String.valueOf(this.nodeid));
|
||||
this.envProperties.put(RESNAME_APP_TIME, String.valueOf(this.startTime));
|
||||
this.envProperties.put(RESNAME_APP_HOME, this.home.getPath());
|
||||
this.envProperties.put(RESNAME_APP_ADDR, this.localAddress.getAddress().getHostAddress());
|
||||
this.envProperties.put(RESNAME_APP_CONF_DIR, this.confPath.toString());
|
||||
|
||||
this.sysPropNames = Collections.unmodifiableSet((Set) System.getProperties().keySet());
|
||||
//初始化本地配置的System.properties
|
||||
appConfig.localSysProperties.forEach((k, v) -> {
|
||||
String key = k.toString();
|
||||
@@ -596,51 +601,23 @@ public final class Application {
|
||||
final AtomicInteger propertyIndex = new AtomicInteger();
|
||||
Properties logProps = null; //新的日志配置项
|
||||
//------------------------------------ 读取配置项 ------------------------------------
|
||||
AnyValue propertiesConf = config.getAnyValue("properties");
|
||||
if (propertiesConf == null) {
|
||||
AnyValue propsConf = config.getAnyValue("properties");
|
||||
if (propsConf == null) {
|
||||
final AnyValue resources = config.getAnyValue("resources");
|
||||
if (resources != null) {
|
||||
logger.log(Level.WARNING, "<resources> in application config file is deprecated");
|
||||
propertiesConf = resources.getAnyValue("properties");
|
||||
propsConf = resources.getAnyValue("properties");
|
||||
}
|
||||
}
|
||||
if (propertiesConf != null) {
|
||||
if (propsConf != null) {
|
||||
final Properties agentEnvs = new Properties();
|
||||
if (propertiesConf.getValue("load") != null) { //加载本地配置项文件
|
||||
for (String dfload : propertiesConf.getValue("load").replace(',', ';').split(";")) {
|
||||
if (dfload.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
final URI df = RedkaleClassLoader.getConfResourceAsURI(configFromCache ? null : this.confPath.toString(), dfload.trim());
|
||||
if (df != null && (!"file".equals(df.getScheme()) || df.toString().contains("!") || new File(df).isFile())) {
|
||||
Properties ps = new Properties();
|
||||
try {
|
||||
InputStream in = df.toURL().openStream();
|
||||
ps.load(in);
|
||||
in.close();
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.log(Level.FINE, "Load properties(" + dfload + ") size = " + ps.size());
|
||||
}
|
||||
ps.forEach((x, y) -> { //load中的配置项除了redkale.cachesource.和redkale.datasource.开头,不应该有其他redkale.开头配置项
|
||||
if (!x.toString().startsWith("redkale.")) {
|
||||
agentEnvs.put(x, y);
|
||||
} else {
|
||||
logger.log(Level.WARNING, "skip illegal(startswith 'redkale.') key " + x + " in properties file");
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Load properties(" + dfload + ") error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{ //可能通过系统环境变量配置信息
|
||||
Iterator<PropertiesAgentProvider> it = ServiceLoader.load(PropertiesAgentProvider.class, classLoader).iterator();
|
||||
RedkaleClassLoader.putServiceLoader(PropertiesAgentProvider.class);
|
||||
List<PropertiesAgentProvider> providers = new ArrayList<>();
|
||||
while (it.hasNext()) {
|
||||
PropertiesAgentProvider provider = it.next();
|
||||
if (provider != null && provider.acceptsConf(propertiesConf)) {
|
||||
if (provider != null && provider.acceptsConf(propsConf)) {
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(provider.getClass(), provider.getClass().getName());
|
||||
providers.add(provider);
|
||||
}
|
||||
@@ -650,9 +627,9 @@ public final class Application {
|
||||
this.propertiesAgent = provider.createInstance();
|
||||
this.resourceFactory.inject(this.propertiesAgent);
|
||||
if (compileMode) {
|
||||
this.propertiesAgent.compile(propertiesConf);
|
||||
this.propertiesAgent.compile(propsConf);
|
||||
} else {
|
||||
Map<String, Properties> propMap = this.propertiesAgent.init(this, propertiesConf);
|
||||
Map<String, Properties> propMap = this.propertiesAgent.init(this, propsConf);
|
||||
int propCount = 0;
|
||||
if (propMap != null) {
|
||||
for (Map.Entry<String, Properties> en : propMap.entrySet()) {
|
||||
@@ -675,7 +652,7 @@ public final class Application {
|
||||
}
|
||||
|
||||
final Properties oldEnvs = new Properties();
|
||||
for (AnyValue prop : propertiesConf.getAnyValues("property")) {
|
||||
for (AnyValue prop : propsConf.getAnyValues("property")) {
|
||||
String key = prop.getValue("name");
|
||||
String value = prop.getValue("value");
|
||||
if (key == null || value == null) {
|
||||
@@ -691,14 +668,14 @@ public final class Application {
|
||||
}
|
||||
});
|
||||
//原有properties节点上的属性同步到dyncEnvs
|
||||
propertiesConf.forEach((k, v) -> dyncProps.put("redkale.properties[" + k + "]", v));
|
||||
propsConf.forEach((k, v) -> dyncProps.put("redkale.properties[" + k + "]", v));
|
||||
oldEnvs.forEach((k, v) -> { //去重后的配置项
|
||||
String prefix = "redkale.properties.property[" + propertyIndex.getAndIncrement() + "]";
|
||||
dyncProps.put(prefix + ".name", k);
|
||||
dyncProps.put(prefix + ".value", v);
|
||||
});
|
||||
//移除旧节点
|
||||
((DefaultAnyValue) this.config).removeAnyValues("properties");
|
||||
((AnyValueWriter) this.config).removeAnyValues("properties");
|
||||
}
|
||||
//环境变量的优先级最高
|
||||
System.getProperties().forEach((k, v) -> {
|
||||
@@ -734,12 +711,12 @@ public final class Application {
|
||||
this.config.merge(AnyValue.loadFromProperties(newDyncProps).getAnyValue("redkale"), NodeServer.appConfigmergeFunction);
|
||||
}
|
||||
//使用合并后的新配置节点
|
||||
propertiesConf = this.config.getAnyValue("properties");
|
||||
if (propertiesConf != null) {
|
||||
propsConf = this.config.getAnyValue("properties");
|
||||
if (propsConf != null) {
|
||||
//清除property节点数组的下坐标
|
||||
((DefaultAnyValue) propertiesConf).clearParentArrayIndex("property");
|
||||
((AnyValueWriter) propsConf).clearParentArrayIndex("property");
|
||||
//注入配置项
|
||||
for (AnyValue prop : propertiesConf.getAnyValues("property")) {
|
||||
for (AnyValue prop : propsConf.getAnyValues("property")) {
|
||||
String key = prop.getValue("name");
|
||||
String value = prop.getValue("value");
|
||||
if (key == null) {
|
||||
@@ -1361,10 +1338,10 @@ public final class Application {
|
||||
if ("SNCP".equals(protocol)) {
|
||||
server = NodeSncpServer.createNodeServer(Application.this, serconf);
|
||||
} else if ("WATCH".equalsIgnoreCase(protocol)) {
|
||||
DefaultAnyValue serconf2 = (DefaultAnyValue) serconf;
|
||||
DefaultAnyValue rest = (DefaultAnyValue) serconf2.getAnyValue("rest");
|
||||
AnyValueWriter serconf2 = (AnyValueWriter) serconf;
|
||||
AnyValueWriter rest = (AnyValueWriter) serconf2.getAnyValue("rest");
|
||||
if (rest == null) {
|
||||
rest = new DefaultAnyValue();
|
||||
rest = new AnyValueWriter();
|
||||
serconf2.addValue("rest", rest);
|
||||
}
|
||||
rest.setValue("base", WatchServlet.class.getName());
|
||||
@@ -1497,58 +1474,56 @@ public final class Application {
|
||||
Times.midnight(); //先初始化一下Utility
|
||||
Thread.currentThread().setName("Redkale-Application-Main-Thread");
|
||||
//运行主程序
|
||||
{
|
||||
String cmd = System.getProperty("cmd", System.getProperty("CMD"));
|
||||
String[] params = args;
|
||||
if (args != null && args.length > 0) {
|
||||
String cmd = System.getProperty("cmd", System.getProperty("CMD"));
|
||||
String[] params = args;
|
||||
if (args != null && args.length > 0) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i] != null && args[i].toLowerCase().startsWith("--conf-file=")) {
|
||||
System.setProperty(RESNAME_APP_CONF_FILE, args[i].substring("--conf-file=".length()));
|
||||
String[] newargs = new String[args.length - 1];
|
||||
System.arraycopy(args, 0, newargs, 0, i);
|
||||
System.arraycopy(args, i + 1, newargs, i, args.length - 1 - i);
|
||||
args = newargs;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cmd == null) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i] != null && args[i].toLowerCase().startsWith("--conf-file=")) {
|
||||
System.setProperty(RESNAME_APP_CONF_FILE, args[i].substring("--conf-file=".length()));
|
||||
String[] newargs = new String[args.length - 1];
|
||||
System.arraycopy(args, 0, newargs, 0, i);
|
||||
System.arraycopy(args, i + 1, newargs, i, args.length - 1 - i);
|
||||
args = newargs;
|
||||
if (args[i] != null && !args[i].startsWith("-")) { //非-开头的第一个视为命令号
|
||||
cmd = args[i];
|
||||
if ("start".equalsIgnoreCase(cmd) || "startup".equalsIgnoreCase(cmd)) {
|
||||
cmd = null;
|
||||
}
|
||||
params = new String[args.length - 1];
|
||||
System.arraycopy(args, 0, params, 0, i);
|
||||
System.arraycopy(args, i + 1, params, i, args.length - 1 - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cmd == null) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i] != null && !args[i].startsWith("-")) { //非-开头的第一个视为命令号
|
||||
cmd = args[i];
|
||||
if ("start".equalsIgnoreCase(cmd) || "startup".equalsIgnoreCase(cmd)) {
|
||||
cmd = null;
|
||||
}
|
||||
params = new String[args.length - 1];
|
||||
System.arraycopy(args, 0, params, 0, i);
|
||||
System.arraycopy(args, i + 1, params, i, args.length - 1 - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cmd == null) {
|
||||
if (args.length == 1 && ("--help".equalsIgnoreCase(args[0]) || "-h".equalsIgnoreCase(args[0]))) {
|
||||
cmd = args[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cmd != null) {
|
||||
if ("stop".equalsIgnoreCase(cmd)) {
|
||||
cmd = "shutdown";
|
||||
}
|
||||
if ("help".equalsIgnoreCase(cmd) || "--help".equalsIgnoreCase(cmd) || "-h".equalsIgnoreCase(cmd)) {
|
||||
(System.out).println(generateHelp());
|
||||
return;
|
||||
}
|
||||
boolean restart = "restart".equalsIgnoreCase(cmd);
|
||||
AnyValue config = AppConfig.loadAppConfig();
|
||||
Application.sendCommand(null, config.getIntValue("port"), restart ? "SHUTDOWN" : cmd, params);
|
||||
if (!restart) {
|
||||
return;
|
||||
if (cmd == null) {
|
||||
if (args.length == 1 && ("--help".equalsIgnoreCase(args[0]) || "-h".equalsIgnoreCase(args[0]))) {
|
||||
cmd = args[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
//PrepareCompiler.main(args); //测试代码
|
||||
if (cmd != null) {
|
||||
if ("stop".equalsIgnoreCase(cmd)) {
|
||||
cmd = "shutdown";
|
||||
}
|
||||
if ("help".equalsIgnoreCase(cmd) || "--help".equalsIgnoreCase(cmd) || "-h".equalsIgnoreCase(cmd)) {
|
||||
(System.out).println(generateHelp());
|
||||
return;
|
||||
}
|
||||
boolean restart = "restart".equalsIgnoreCase(cmd);
|
||||
AnyValue config = AppConfig.loadAppConfig();
|
||||
Application.sendCommand(null, config.getIntValue("port"), restart ? "SHUTDOWN" : cmd, params);
|
||||
if (!restart) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//PrepareCompiler.main(args); //测试代码
|
||||
final Application application = Application.create(false);
|
||||
application.init();
|
||||
application.startSelfServer();
|
||||
@@ -1732,6 +1707,10 @@ public final class Application {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public Environment getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
public AnyValue getAppConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.regex.Pattern;
|
||||
import org.redkale.annotation.*;
|
||||
import org.redkale.annotation.AutoLoad;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
|
||||
/**
|
||||
* class过滤器, 符合条件的class会保留下来存入FilterEntry。
|
||||
@@ -214,10 +213,10 @@ public final class ClassFilter<T> {
|
||||
if (cf.conf != null) {
|
||||
if (property == null) {
|
||||
property = cf.conf;
|
||||
} else if (property instanceof DefaultAnyValue) {
|
||||
((DefaultAnyValue) property).addAllStringSet(cf.conf);
|
||||
} else if (property instanceof AnyValueWriter) {
|
||||
((AnyValueWriter) property).addAllStringSet(cf.conf);
|
||||
} else {
|
||||
DefaultAnyValue dav = new DefaultAnyValue();
|
||||
AnyValueWriter dav = new AnyValueWriter();
|
||||
dav.addAllStringSet(property);
|
||||
dav.addAllStringSet(cf.conf);
|
||||
property = dav;
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.Environment;
|
||||
import org.redkale.util.ResourceEvent;
|
||||
import org.redkale.util.ResourceFactory;
|
||||
|
||||
@@ -29,16 +30,19 @@ public abstract class ModuleEngine {
|
||||
|
||||
protected final ResourceFactory resourceFactory;
|
||||
|
||||
protected final Environment environment;
|
||||
|
||||
public ModuleEngine(Application application) {
|
||||
this.application = application;
|
||||
this.resourceFactory = application.getResourceFactory();
|
||||
this.environment = application.getEnvironment();
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入Application.init方法时被调用
|
||||
* 此时状态:
|
||||
* 1、远程配置项未获取
|
||||
* 2、WorkExecutor未初始化
|
||||
* 1、远程配置项未获取
|
||||
* 2、WorkExecutor未初始化
|
||||
*/
|
||||
public void onAppPreInit() {
|
||||
//do nothing
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.redkale.net.http.*;
|
||||
import org.redkale.net.sncp.Sncp;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
import org.redkale.watch.*;
|
||||
|
||||
/**
|
||||
@@ -201,7 +200,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(clazz, clazz.getName());
|
||||
final HttpFilter filter = clazz.getDeclaredConstructor().newInstance();
|
||||
resourceFactory.inject(filter, this);
|
||||
DefaultAnyValue filterConf = (DefaultAnyValue) entry.getProperty();
|
||||
AnyValueWriter filterConf = (AnyValueWriter) entry.getProperty();
|
||||
this.httpServer.addHttpFilter(filter, filterConf);
|
||||
if (sb != null) {
|
||||
sb.append("Load ").append(clazz.getName()).append(LINE_SEPARATOR);
|
||||
@@ -265,7 +264,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
resourceFactory.inject(servlet, this);
|
||||
final String[] mappings = ws.value();
|
||||
String pref = ws.repair() ? prefix : "";
|
||||
DefaultAnyValue servletConf = (DefaultAnyValue) entry.getProperty();
|
||||
AnyValueWriter servletConf = (AnyValueWriter) entry.getProperty();
|
||||
this.httpServer.addHttpServlet(servlet, pref, servletConf, mappings);
|
||||
if (ss != null) {
|
||||
for (int i = 0; i < mappings.length; i++) {
|
||||
|
||||
@@ -243,44 +243,44 @@ public abstract class NodeServer {
|
||||
//---------------------------------------------------------------------------------------------
|
||||
final ResourceFactory appResFactory = application.getResourceFactory();
|
||||
//------------------------------------- 注册 Resource --------------------------------------------------------
|
||||
resourceFactory.register((ResourceFactory rf, String srcResourceName, final Object srcObj, String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
String resName = null;
|
||||
Resource res = field.getAnnotation(Resource.class);
|
||||
if (res != null) {
|
||||
resName = res.name();
|
||||
} else {
|
||||
javax.annotation.Resource res2 = field.getAnnotation(javax.annotation.Resource.class);
|
||||
if (res2 != null) {
|
||||
resName = res2.name();
|
||||
}
|
||||
}
|
||||
if (resName == null || !resName.startsWith("properties.")) {
|
||||
return null;
|
||||
}
|
||||
if ((srcObj instanceof Service) && Sncp.isRemote((Service) srcObj)) {
|
||||
return null; //远程模式不得注入 DataSource
|
||||
}
|
||||
Class type = field.getType();
|
||||
if (type != AnyValue.class && type != AnyValue[].class) {
|
||||
return null;
|
||||
}
|
||||
Object resource = null;
|
||||
final AnyValue properties = application.getAppConfig().getAnyValue("properties");
|
||||
if (properties != null && type == AnyValue.class) {
|
||||
resource = properties.getAnyValue(resName.substring("properties.".length()));
|
||||
appResFactory.register(resourceName, AnyValue.class, resource);
|
||||
} else if (properties != null && type == AnyValue[].class) {
|
||||
resource = properties.getAnyValues(resName.substring("properties.".length()));
|
||||
appResFactory.register(resourceName, AnyValue[].class, resource);
|
||||
}
|
||||
field.set(srcObj, resource);
|
||||
return resource;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Resource inject error", e);
|
||||
return null;
|
||||
}
|
||||
}, AnyValue.class, AnyValue[].class);
|
||||
// resourceFactory.register((ResourceFactory rf, String srcResourceName, final Object srcObj, String resourceName, Field field, final Object attachment) -> {
|
||||
// try {
|
||||
// String resName = null;
|
||||
// Resource res = field.getAnnotation(Resource.class);
|
||||
// if (res != null) {
|
||||
// resName = res.name();
|
||||
// } else {
|
||||
// javax.annotation.Resource res2 = field.getAnnotation(javax.annotation.Resource.class);
|
||||
// if (res2 != null) {
|
||||
// resName = res2.name();
|
||||
// }
|
||||
// }
|
||||
// if (resName == null || !resName.startsWith("properties.")) {
|
||||
// return null;
|
||||
// }
|
||||
// if ((srcObj instanceof Service) && Sncp.isRemote((Service) srcObj)) {
|
||||
// return null; //远程模式不得注入 DataSource
|
||||
// }
|
||||
// Class type = field.getType();
|
||||
// if (type != AnyValue.class && type != AnyValue[].class) {
|
||||
// return null;
|
||||
// }
|
||||
// Object resource = null;
|
||||
// final AnyValue properties = application.getAppConfig().getAnyValue("properties");
|
||||
// if (properties != null && type == AnyValue.class) {
|
||||
// resource = properties.getAnyValue(resName.substring("properties.".length()));
|
||||
// appResFactory.register(resourceName, AnyValue.class, resource);
|
||||
// } else if (properties != null && type == AnyValue[].class) {
|
||||
// resource = properties.getAnyValues(resName.substring("properties.".length()));
|
||||
// appResFactory.register(resourceName, AnyValue[].class, resource);
|
||||
// }
|
||||
// field.set(srcObj, resource);
|
||||
// return resource;
|
||||
// } catch (Exception e) {
|
||||
// logger.log(Level.SEVERE, "Resource inject error", e);
|
||||
// return null;
|
||||
// }
|
||||
// }, AnyValue.class, AnyValue[].class);
|
||||
|
||||
//------------------------------------- 注册 Local AutoLoad(false) Service --------------------------------------------------------
|
||||
resourceFactory.register((ResourceFactory rf, String srcResourceName, final Object srcObj, String resourceName, Field field, final Object attachment) -> {
|
||||
@@ -751,7 +751,7 @@ public abstract class NodeServer {
|
||||
}
|
||||
cf = null;
|
||||
for (AnyValue list : proplist) {
|
||||
AnyValue.DefaultAnyValue prop = null;
|
||||
AnyValueWriter prop = null;
|
||||
String sc = list.getValue("group");
|
||||
String mq = list.getValue("mq");
|
||||
if (sc != null) {
|
||||
@@ -761,7 +761,7 @@ public abstract class NodeServer {
|
||||
sc = localGroup;
|
||||
}
|
||||
if (sc != null || mq != null) {
|
||||
prop = new AnyValue.DefaultAnyValue();
|
||||
prop = new AnyValueWriter();
|
||||
if (sc != null) {
|
||||
prop.addValue("group", sc);
|
||||
}
|
||||
@@ -772,8 +772,8 @@ public abstract class NodeServer {
|
||||
ClassFilter filter = new ClassFilter(this.serverClassLoader, ref, inter, excludeSuperClasses, prop);
|
||||
for (AnyValue av : list.getAnyValues(property)) { // <service>、<filter>、<servlet> 节点
|
||||
final AnyValue[] items = av.getAnyValues("property");
|
||||
if (av instanceof AnyValue.DefaultAnyValue && items.length > 0) { //存在 <property>节点
|
||||
AnyValue.DefaultAnyValue dav = AnyValue.DefaultAnyValue.create();
|
||||
if (av instanceof AnyValueWriter && items.length > 0) { //存在 <property>节点
|
||||
AnyValueWriter dav = AnyValueWriter.create();
|
||||
final AnyValue.Entry<String>[] strings = av.getStringEntrys();
|
||||
if (strings != null) { //将<service>、<filter>、<servlet>节点的属性值传给dav
|
||||
for (AnyValue.Entry<String> en : strings) {
|
||||
@@ -788,7 +788,7 @@ public abstract class NodeServer {
|
||||
}
|
||||
}
|
||||
}
|
||||
AnyValue.DefaultAnyValue ps = AnyValue.DefaultAnyValue.create();
|
||||
AnyValueWriter ps = AnyValueWriter.create();
|
||||
for (AnyValue item : items) {
|
||||
ps.addValue(item.getValue("name"), item.getValue("value"));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.redkale.net.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Local;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
|
||||
/**
|
||||
* SNCP Server节点的配置Server
|
||||
@@ -123,7 +122,7 @@ public class NodeSncpServer extends NodeServer {
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(clazz, clazz.getName());
|
||||
final SncpFilter filter = clazz.getDeclaredConstructor().newInstance();
|
||||
resourceFactory.inject(filter, this);
|
||||
DefaultAnyValue filterConf = (DefaultAnyValue) entry.getProperty();
|
||||
AnyValueWriter filterConf = (AnyValueWriter) entry.getProperty();
|
||||
this.sncpServer.addSncpFilter(filter, filterConf);
|
||||
if (sb != null) {
|
||||
sb.append("Load ").append(clazz.getName()).append(LINE_SEPARATOR);
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.redkale.net.http.MimeType;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
|
||||
/**
|
||||
* 配置源Agent, 在init方法内需要实现读取配置信息,如果支持配置更改通知,也需要在init里实现监听
|
||||
@@ -164,11 +163,11 @@ public abstract class PropertiesAgent {
|
||||
if (!envRegisterProps.isEmpty()) {
|
||||
application.envProperties.putAll(envChangedProps);
|
||||
envRemovedKeys.forEach(application.envProperties::remove);
|
||||
DefaultAnyValue oldConf = (DefaultAnyValue) application.getAppConfig().getAnyValue("properties");
|
||||
DefaultAnyValue newConf = new DefaultAnyValue();
|
||||
AnyValueWriter oldConf = (AnyValueWriter) application.getAppConfig().getAnyValue("properties");
|
||||
AnyValueWriter newConf = new AnyValueWriter();
|
||||
oldConf.forEach((k, v) -> newConf.addValue(k, v));
|
||||
application.envProperties.forEach((k, v) -> {
|
||||
newConf.addValue("property", new DefaultAnyValue().addValue("name", k.toString()).addValue("value", v.toString()));
|
||||
newConf.addValue("property", new AnyValueWriter().addValue("name", k.toString()).addValue("value", v.toString()));
|
||||
});
|
||||
oldConf.replace(newConf);
|
||||
application.getResourceFactory().register(envRegisterProps, "", Environment.class);
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CacheModuleEngine extends ModuleEngine {
|
||||
public void onAppPostInit() {
|
||||
//设置缓存管理器
|
||||
this.cacheManager = CacheManagerService.create(null).enabled(false);
|
||||
final AnyValue cacheConf = application.getAppConfig().getAnyValue("cache");
|
||||
final AnyValue cacheConf = environment.getAnyValue("redkale.cache", false);
|
||||
this.resourceFactory.inject(this.cacheManager);
|
||||
if (!application.isCompileMode() && cacheConf != null) {
|
||||
this.cacheManager.init(cacheConf);
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.logging.Level;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.boot.ModuleEngine;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.util.ResourceEvent;
|
||||
|
||||
@@ -41,9 +41,9 @@ public class ClusterModuleEngine extends ModuleEngine {
|
||||
* 结束Application.init方法前被调用
|
||||
*/
|
||||
@Override
|
||||
public void onAppPostInit() {
|
||||
public void onAppPostInit() {
|
||||
ClusterAgent cluster = null;
|
||||
AnyValue clusterConf = application.getAppConfig().getAnyValue("cluster");
|
||||
AnyValue clusterConf = environment.getAnyValue("redkale.cluster", false);
|
||||
if (clusterConf != null) {
|
||||
try {
|
||||
String classVal = application.getPropertyValue(clusterConf.getValue("type", clusterConf.getValue("value"))); //兼容value字段
|
||||
@@ -88,7 +88,7 @@ public class ClusterModuleEngine extends ModuleEngine {
|
||||
}
|
||||
}
|
||||
this.clusterAgent = cluster;
|
||||
|
||||
|
||||
if (this.clusterAgent != null) {
|
||||
if (logger.isLoggable(Level.FINER)) {
|
||||
logger.log(Level.FINER, "ClusterAgent (type = " + this.clusterAgent.getClass().getSimpleName() + ") initing");
|
||||
@@ -143,7 +143,7 @@ public class ClusterModuleEngine extends ModuleEngine {
|
||||
//第三方服务注册配置项的变更
|
||||
if (!clusterChangedProps.isEmpty() || !clusterRemovedKeys.isEmpty()) {
|
||||
if (this.clusterAgent != null) {
|
||||
final DefaultAnyValue old = (DefaultAnyValue) application.getAppConfig().getAnyValue("cluster");
|
||||
final AnyValueWriter old = (AnyValueWriter) environment.getAnyValue("redkale.cluster", false);
|
||||
Properties newProps = new Properties();
|
||||
newProps.putAll(clusterProperties);
|
||||
List<ResourceEvent> changeEvents = new ArrayList<>();
|
||||
@@ -158,7 +158,7 @@ public class ClusterModuleEngine extends ModuleEngine {
|
||||
changeEvents.add(ResourceEvent.create(key.substring("redkale.cluster.".length()), null, this.clusterProperties.getProperty(key)));
|
||||
});
|
||||
if (!changeEvents.isEmpty()) {
|
||||
DefaultAnyValue back = old.copy();
|
||||
AnyValueWriter back = old.copy();
|
||||
try {
|
||||
old.replace(AnyValue.loadFromProperties(newProps).getAnyValue("redkale").getAnyValue("cluster"));
|
||||
clusterAgent.onResourceChange(changeEvents.toArray(new ResourceEvent[changeEvents.size()]));
|
||||
|
||||
@@ -141,7 +141,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
this.register(DoubleStream.class, DoubleArraySimpledCoder.DoubleStreamSimpledCoder.instance);
|
||||
this.register(String[].class, StringArraySimpledCoder.instance);
|
||||
//---------------------------------------------------------
|
||||
this.register(AnyValue.class, Creator.create(AnyValue.DefaultAnyValue.class));
|
||||
this.register(AnyValue.class, Creator.create(AnyValueWriter.class));
|
||||
this.register(HttpCookie.class, new Creator<HttpCookie>() {
|
||||
@Override
|
||||
@ConstructorParameters({"name", "value"})
|
||||
|
||||
@@ -47,8 +47,8 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
||||
instance.register(Serializable.class, objectDecoder);
|
||||
instance.register(Serializable.class, objectEncoder);
|
||||
|
||||
//instance.register(AnyValue.class, instance.loadDecoder(AnyValue.DefaultAnyValue.class));
|
||||
//instance.register(AnyValue.class, instance.loadEncoder(AnyValue.DefaultAnyValue.class));
|
||||
//instance.register(AnyValue.class, instance.loadDecoder(SimpleAnyValue.class));
|
||||
//instance.register(AnyValue.class, instance.loadEncoder(SimpleAnyValue.class));
|
||||
}
|
||||
|
||||
private BsonFactory(BsonFactory parent, int features) {
|
||||
|
||||
@@ -32,8 +32,8 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
||||
static {
|
||||
instance.register(Serializable.class, instance.loadEncoder(Object.class));
|
||||
|
||||
//instance.register(AnyValue.class, instance.loadDecoder(AnyValue.DefaultAnyValue.class));
|
||||
//instance.register(AnyValue.class, instance.loadEncoder(AnyValue.DefaultAnyValue.class));
|
||||
//instance.register(AnyValue.class, instance.loadDecoder(SimpleAnyValue.class));
|
||||
//instance.register(AnyValue.class, instance.loadEncoder(SimpleAnyValue.class));
|
||||
}
|
||||
|
||||
private JsonFactory(JsonFactory parent, int features) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.concurrent.atomic.*;
|
||||
import java.util.stream.Stream;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -36,8 +37,8 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
||||
instance.register(Serializable.class, objectDecoder);
|
||||
instance.register(Serializable.class, objectEncoder);
|
||||
|
||||
instance.register(AnyValue.class, instance.loadDecoder(AnyValue.DefaultAnyValue.class));
|
||||
instance.register(AnyValue.class, instance.loadEncoder(AnyValue.DefaultAnyValue.class));
|
||||
instance.register(AnyValue.class, instance.loadDecoder(AnyValueWriter.class));
|
||||
instance.register(AnyValue.class, instance.loadEncoder(AnyValueWriter.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("OverridableMethodCallInConstructor")
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.redkale.util.ResourceAnnotationProvider;
|
||||
import org.redkale.util.ResourceEvent;
|
||||
import org.redkale.util.ResourceFactory;
|
||||
import org.redkale.util.ResourceTypeLoader;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
@@ -225,7 +226,7 @@ public class MessageModuleEngine extends ModuleEngine {
|
||||
if (agent == null) {
|
||||
continue; //多余的数据源
|
||||
}
|
||||
final AnyValue.DefaultAnyValue old = (AnyValue.DefaultAnyValue) findMQConfig(mqName);
|
||||
final AnyValueWriter old = (AnyValueWriter) findMQConfig(mqName);
|
||||
Properties newProps = new Properties();
|
||||
this.messageProperties.forEach((k, v) -> {
|
||||
final String key = k.toString();
|
||||
@@ -270,7 +271,7 @@ public class MessageModuleEngine extends ModuleEngine {
|
||||
changeEvents.add(ResourceEvent.create(key.substring(prefix.length()), null, this.messageProperties.getProperty(key)));
|
||||
});
|
||||
if (!changeEvents.isEmpty()) {
|
||||
AnyValue.DefaultAnyValue back = old.copy();
|
||||
AnyValueWriter back = old.copy();
|
||||
try {
|
||||
old.replace(AnyValue.loadFromProperties(newProps).getAnyValue("redkale").getAnyValue("mq").getAnyValue(mqName));
|
||||
agent.onResourceChange(changeEvents.toArray(new ResourceEvent[changeEvents.size()]));
|
||||
@@ -403,7 +404,7 @@ public class MessageModuleEngine extends ModuleEngine {
|
||||
if (mqsNode != null) {
|
||||
AnyValue confNode = mqsNode.getAnyValue(mqName);
|
||||
if (confNode != null) { //必须要设置name属性
|
||||
((AnyValue.DefaultAnyValue) confNode).setValue("name", mqName);
|
||||
((AnyValueWriter) confNode).setValue("name", mqName);
|
||||
}
|
||||
return confNode;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.redkale.net.Filter;
|
||||
import org.redkale.net.http.Rest.RestDynSourceType;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
|
||||
/**
|
||||
* HTTP Servlet的总入口,请求在HttpDispatcherServlet中进行分流。 <br>
|
||||
@@ -268,11 +267,11 @@ public class HttpDispatcherServlet extends DispatcherServlet<String, HttpContext
|
||||
});
|
||||
{ //设置ResourceServlet
|
||||
AnyValue resConfig = config.getAnyValue("resource-servlet");
|
||||
if ((resConfig instanceof DefaultAnyValue) && resConfig.getValue("webroot", "").isEmpty()) {
|
||||
((DefaultAnyValue) resConfig).addValue("webroot", config.getValue("root"));
|
||||
if ((resConfig instanceof AnyValueWriter) && resConfig.getValue("webroot", "").isEmpty()) {
|
||||
((AnyValueWriter) resConfig).addValue("webroot", config.getValue("root"));
|
||||
}
|
||||
if (resConfig == null) { //主要用于嵌入式的HttpServer初始化
|
||||
DefaultAnyValue dresConfig = new DefaultAnyValue();
|
||||
AnyValueWriter dresConfig = new AnyValueWriter();
|
||||
dresConfig.addValue("webroot", config.getValue("root"));
|
||||
dresConfig.addValue("ranges", config.getValue("ranges"));
|
||||
dresConfig.addValue("cache", config.getAnyValue("cache"));
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.redkale.convert.json.*;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.service.RetResult;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
import org.redkale.util.AnyValue.Entry;
|
||||
import static org.redkale.util.Utility.append;
|
||||
|
||||
@@ -152,7 +151,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
|
||||
private final byte[] jsonContentTypeBytes;
|
||||
|
||||
private final DefaultAnyValue header = new DefaultAnyValue();
|
||||
private final AnyValueWriter header = new AnyValueWriter();
|
||||
|
||||
private final String[][] defaultAddHeaders;
|
||||
|
||||
@@ -1365,7 +1364,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected DefaultAnyValue duplicateHeader() {
|
||||
protected AnyValueWriter duplicateHeader() {
|
||||
return this.header.duplicate();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ScheduleModuleEngine extends ModuleEngine {
|
||||
public void onAppPostInit() {
|
||||
//设置定时管理器
|
||||
this.scheduleManager = ScheduleManagerService.create(null).enabled(false);
|
||||
final AnyValue scheduleConf = application.getAppConfig().getAnyValue("schedule", true);
|
||||
final AnyValue scheduleConf = environment.getAnyValue("redkale.schedule", true);
|
||||
this.resourceFactory.inject(this.scheduleManager);
|
||||
if (!application.isCompileMode()) {
|
||||
this.scheduleManager.init(scheduleConf);
|
||||
|
||||
@@ -297,7 +297,7 @@ public final class DataSources {
|
||||
//
|
||||
// RedkaleClassLoader.putServiceLoader(DataSourceProvider.class);
|
||||
// Class dsClass = null;
|
||||
// final AnyValue.DefaultAnyValue lc = new AnyValue.DefaultAnyValue();
|
||||
// final SimpleAnyValue lc = new SimpleAnyValue();
|
||||
// readprop.forEach((k, v) -> lc.addValue(k.toString(), v.toString()));
|
||||
// lc.setValue("dbtype", dbtype);
|
||||
// List<DataSourceProvider> providers = new ArrayList<>();
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.redkale.net.Servlet;
|
||||
import org.redkale.net.sncp.Sncp;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.util.RedkaleException;
|
||||
@@ -205,7 +205,7 @@ public class SourceModuleEngine extends ModuleEngine {
|
||||
if (source == null) {
|
||||
continue; //多余的数据源
|
||||
}
|
||||
final AnyValue.DefaultAnyValue old = (AnyValue.DefaultAnyValue) findSourceConfig(sourceName, "cachesource");
|
||||
final AnyValueWriter old = (AnyValueWriter) findSourceConfig(sourceName, "cachesource");
|
||||
Properties newProps = new Properties();
|
||||
this.sourceProperties.forEach((k, v) -> {
|
||||
final String key = k.toString();
|
||||
@@ -250,7 +250,7 @@ public class SourceModuleEngine extends ModuleEngine {
|
||||
changeEvents.add(ResourceEvent.create(key.substring(prefix.length()), null, this.sourceProperties.getProperty(key)));
|
||||
});
|
||||
if (!changeEvents.isEmpty()) {
|
||||
AnyValue.DefaultAnyValue back = old.copy();
|
||||
AnyValueWriter back = old.copy();
|
||||
try {
|
||||
old.replace(AnyValue.loadFromProperties(newProps).getAnyValue("redkale").getAnyValue("cachesource").getAnyValue(sourceName));
|
||||
((AbstractCacheSource) source).onResourceChange(changeEvents.toArray(new ResourceEvent[changeEvents.size()]));
|
||||
@@ -266,7 +266,7 @@ public class SourceModuleEngine extends ModuleEngine {
|
||||
if (source == null) {
|
||||
continue; //多余的数据源
|
||||
}
|
||||
AnyValue.DefaultAnyValue old = (AnyValue.DefaultAnyValue) findSourceConfig(sourceName, "datasource");
|
||||
AnyValueWriter old = (AnyValueWriter) findSourceConfig(sourceName, "datasource");
|
||||
Properties newProps = new Properties();
|
||||
this.sourceProperties.forEach((k, v) -> {
|
||||
final String key = k.toString();
|
||||
@@ -311,7 +311,7 @@ public class SourceModuleEngine extends ModuleEngine {
|
||||
changeEvents.add(ResourceEvent.create(key.substring(prefix.length()), null, this.sourceProperties.getProperty(key)));
|
||||
});
|
||||
if (!changeEvents.isEmpty()) {
|
||||
AnyValue.DefaultAnyValue back = old.copy();
|
||||
AnyValueWriter back = old.copy();
|
||||
try {
|
||||
old.replace(AnyValue.loadFromProperties(newProps).getAnyValue("redkale").getAnyValue("datasource").getAnyValue(sourceName));
|
||||
((AbstractDataSource) source).onResourceChange(changeEvents.toArray(new ResourceEvent[changeEvents.size()]));
|
||||
@@ -496,8 +496,8 @@ public class SourceModuleEngine extends ModuleEngine {
|
||||
if (props.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
AnyValue conf = DefaultAnyValue.loadFromProperties(props);
|
||||
((DefaultAnyValue) conf).setValue("name", sourceName);
|
||||
AnyValue conf = AnyValueWriter.loadFromProperties(props);
|
||||
((AnyValueWriter) conf).setValue("name", sourceName);
|
||||
return conf;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.*;
|
||||
import java.util.function.*;
|
||||
import org.redkale.annotation.ConstructorParameters;
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
import static org.redkale.util.Utility.isEmpty;
|
||||
|
||||
/**
|
||||
@@ -48,602 +47,18 @@ public abstract class AnyValue {
|
||||
}
|
||||
|
||||
/**
|
||||
* 可读写的AnyValue默认实现类
|
||||
*
|
||||
* @author zhangjx
|
||||
* @see org.redkale.util.AnyValueWriter
|
||||
* @deprecated replace {@link org.redkale.util.AnyValueWriter}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final class DefaultAnyValue extends AnyValue {
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static final class DefaultAnyValue extends AnyValueWriter {
|
||||
|
||||
/**
|
||||
* 区分name大小写的比较策略
|
||||
*
|
||||
*/
|
||||
public static final BiPredicate<String, String> EQUALS_PREDICATE = (name1, name2) -> name1.equals(name2);
|
||||
|
||||
/**
|
||||
* 不区分name大小写的比较策略
|
||||
*/
|
||||
public static final BiPredicate<String, String> EQUALS_IGNORE = (name1, name2) -> name1.equalsIgnoreCase(name2);
|
||||
|
||||
@ConvertColumn(index = 1)
|
||||
private boolean ignoreCase;
|
||||
|
||||
private BiPredicate<String, String> predicate;
|
||||
|
||||
@ConvertColumn(index = 2)
|
||||
private Entry<String>[] stringEntrys = new Entry[0];
|
||||
|
||||
@ConvertColumn(index = 3)
|
||||
private Entry<DefaultAnyValue>[] anyEntrys = new Entry[0];
|
||||
|
||||
private int parentArrayIndex = -1; //只可能被loadFromProperties方法赋值
|
||||
|
||||
/**
|
||||
* 创建空的DefaultAnyValue对象
|
||||
*
|
||||
* @return DefaultAnyValue对象
|
||||
*/
|
||||
public static final DefaultAnyValue create() {
|
||||
return new DefaultAnyValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建含name-value值的DefaultAnyValue对象
|
||||
*
|
||||
* @param name name
|
||||
* @param value value值
|
||||
*
|
||||
* @return DefaultAnyValue对象
|
||||
*/
|
||||
public static final DefaultAnyValue create(String name, Number value) {
|
||||
DefaultAnyValue conf = new DefaultAnyValue();
|
||||
conf.addValue(name, value);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建含name-value值的DefaultAnyValue对象
|
||||
*
|
||||
* @param name name
|
||||
* @param value value值
|
||||
*
|
||||
* @return DefaultAnyValue对象
|
||||
*/
|
||||
public static final DefaultAnyValue create(String name, String value) {
|
||||
DefaultAnyValue conf = new DefaultAnyValue();
|
||||
conf.addValue(name, value);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建含name-value值的DefaultAnyValue对象
|
||||
*
|
||||
* @param name name
|
||||
* @param value value值
|
||||
*
|
||||
* @return DefaultAnyValue对象
|
||||
*/
|
||||
public static final DefaultAnyValue create(String name, AnyValue value) {
|
||||
DefaultAnyValue conf = new DefaultAnyValue();
|
||||
conf.addValue(name, value);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个区分大小写比较策略的DefaultAnyValue对象
|
||||
*
|
||||
*/
|
||||
public DefaultAnyValue() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建DefaultAnyValue对象
|
||||
*
|
||||
* @param ignoreCase name是否不区分大小写
|
||||
*/
|
||||
public DefaultAnyValue(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
this.predicate = ignoreCase ? EQUALS_IGNORE : EQUALS_PREDICATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建共享此内容的DefaultAnyValue对象
|
||||
*
|
||||
* @return DefaultAnyValue对象
|
||||
*/
|
||||
public DefaultAnyValue duplicate() {
|
||||
DefaultAnyValue rs = new DefaultAnyValue(this.ignoreCase);
|
||||
rs.stringEntrys = this.stringEntrys;
|
||||
rs.anyEntrys = this.anyEntrys;
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制一份对象
|
||||
*
|
||||
* @return DefaultAnyValue对象
|
||||
*/
|
||||
@Override
|
||||
public DefaultAnyValue copy() {
|
||||
DefaultAnyValue rs = new DefaultAnyValue(this.ignoreCase);
|
||||
rs.predicate = this.predicate;
|
||||
rs.parentArrayIndex = this.parentArrayIndex;
|
||||
if (this.stringEntrys != null) {
|
||||
rs.stringEntrys = new Entry[this.stringEntrys.length];
|
||||
for (int i = 0; i < rs.stringEntrys.length; i++) {
|
||||
Entry<String> en = this.stringEntrys[i];
|
||||
if (en == null) {
|
||||
continue;
|
||||
}
|
||||
rs.stringEntrys[i] = new Entry(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (this.anyEntrys != null) {
|
||||
rs.anyEntrys = new Entry[this.anyEntrys.length];
|
||||
for (int i = 0; i < rs.anyEntrys.length; i++) {
|
||||
Entry<DefaultAnyValue> en = this.anyEntrys[i];
|
||||
if (en == null) {
|
||||
continue;
|
||||
}
|
||||
rs.anyEntrys[i] = new Entry(en.name, en.value == null ? null : en.value.copy());
|
||||
}
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将另一个对象替换本对象
|
||||
*
|
||||
* @param node 替换的对象
|
||||
*
|
||||
* @return AnyValue
|
||||
*/
|
||||
@Override
|
||||
public DefaultAnyValue replace(AnyValue node) {
|
||||
if (node != null) {
|
||||
DefaultAnyValue rs = (DefaultAnyValue) node;
|
||||
this.ignoreCase = rs.ignoreCase;
|
||||
this.predicate = rs.predicate;
|
||||
this.parentArrayIndex = rs.parentArrayIndex;
|
||||
this.stringEntrys = rs.stringEntrys;
|
||||
this.anyEntrys = rs.anyEntrys;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将另一个对象合并过来
|
||||
*
|
||||
* @param node 代合并对象
|
||||
* @param func 判断覆盖方式的函数
|
||||
*
|
||||
* @return AnyValue
|
||||
*/
|
||||
@Override
|
||||
public DefaultAnyValue merge(AnyValue node, MergeFunction func) {
|
||||
return merge(node, "", func);
|
||||
}
|
||||
|
||||
protected DefaultAnyValue merge(AnyValue node0, String path, MergeFunction func) {
|
||||
if (node0 == null) {
|
||||
return this;
|
||||
}
|
||||
if (node0 == this) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
DefaultAnyValue node = (DefaultAnyValue) node0;
|
||||
if (node.stringEntrys != null) {
|
||||
for (Entry<String> en : node.stringEntrys) {
|
||||
if (en == null) {
|
||||
continue;
|
||||
}
|
||||
setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (node.anyEntrys != null) {
|
||||
for (Entry<DefaultAnyValue> en : node.anyEntrys) {
|
||||
if (en == null || en.value == null) {
|
||||
continue;
|
||||
}
|
||||
Entry<AnyValue>[] ns = getAnyValueEntrys(en.name);
|
||||
if (ns == null || ns.length < 1) {
|
||||
addValue(en.name, en.value);
|
||||
} else {
|
||||
boolean ok = false;
|
||||
for (Entry<AnyValue> item : ns) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if (item.value != null && en.value.parentArrayIndex == ((DefaultAnyValue) item.value).parentArrayIndex) {
|
||||
if (func == null) {
|
||||
item.value.merge(en.value, func);
|
||||
ok = true;
|
||||
break;
|
||||
} else {
|
||||
int funcVal = func.apply(path, en.name, en.value, item.value);
|
||||
if (funcVal == MergeFunction.MERGE) {
|
||||
String subPath = path.isEmpty() ? en.name : (path + "." + en.name);
|
||||
((DefaultAnyValue) item.value).merge(en.value, subPath, func);
|
||||
ok = true;
|
||||
break;
|
||||
} else if (funcVal == MergeFunction.REPLACE) {
|
||||
item.value = en.value.copy();
|
||||
ok = true;
|
||||
break;
|
||||
} else if (funcVal == MergeFunction.SKIP) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并两个AnyValue对象, 会去重, 没有的才增加
|
||||
*
|
||||
* @param av AnyValue
|
||||
*
|
||||
* @return DefaultAnyValue
|
||||
*/
|
||||
public DefaultAnyValue addAllStringSet(final AnyValue av) {
|
||||
if (av == null) {
|
||||
return this;
|
||||
}
|
||||
final Entry<String>[] strings = av.getStringEntrys();
|
||||
if (strings == null) {
|
||||
return this;
|
||||
}
|
||||
for (Entry<String> en : strings) {
|
||||
if (!existsValue(en.name)) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并两个AnyValue对象 不去重
|
||||
*
|
||||
* @param av AnyValue
|
||||
*
|
||||
* @return DefaultAnyValue
|
||||
*/
|
||||
public DefaultAnyValue addAll(final AnyValue av) {
|
||||
if (av == null) {
|
||||
return this;
|
||||
}
|
||||
if (av instanceof DefaultAnyValue) {
|
||||
final DefaultAnyValue adv = (DefaultAnyValue) av;
|
||||
if (adv.stringEntrys != null) {
|
||||
for (Entry<String> en : adv.stringEntrys) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (adv.anyEntrys != null) {
|
||||
for (Entry<DefaultAnyValue> en : adv.anyEntrys) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final Entry<String>[] strings = av.getStringEntrys();
|
||||
if (strings != null) {
|
||||
for (Entry<String> en : strings) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
final Entry<AnyValue>[] anys = av.getAnyEntrys();
|
||||
if (anys != null) {
|
||||
for (Entry<AnyValue> en : anys) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并两个AnyValue对象 会去重
|
||||
*
|
||||
* @param av AnyValue
|
||||
*
|
||||
* @return DefaultAnyValue
|
||||
*/
|
||||
@ConvertDisabled
|
||||
public DefaultAnyValue setAll(final AnyValue av) {
|
||||
if (av == null) {
|
||||
return this;
|
||||
}
|
||||
if (av instanceof DefaultAnyValue) {
|
||||
final DefaultAnyValue adv = (DefaultAnyValue) av;
|
||||
if (adv.stringEntrys != null) {
|
||||
for (Entry<String> en : adv.stringEntrys) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (adv.anyEntrys != null) {
|
||||
for (Entry<DefaultAnyValue> en : adv.anyEntrys) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final Entry<String>[] strings = av.getStringEntrys();
|
||||
if (strings != null) {
|
||||
for (Entry<String> en : strings) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
final Entry<AnyValue>[] anys = av.getAnyEntrys();
|
||||
if (anys != null) {
|
||||
for (Entry<AnyValue> en : anys) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<String, String> stringConsumer) {
|
||||
forEach(stringConsumer, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<String, String> stringConsumer, BiConsumer<String, AnyValue> anyConsumer) {
|
||||
if (stringConsumer != null) {
|
||||
for (Entry<String> en : stringEntrys) {
|
||||
stringConsumer.accept(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (anyConsumer != null) {
|
||||
for (Entry<AnyValue> en : (Entry[]) anyEntrys) {
|
||||
anyConsumer.accept(en.name, en.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<String>[] getStringEntrys() {
|
||||
return stringEntrys;
|
||||
}
|
||||
|
||||
public void setStringEntrys(Entry<String>[] stringEntrys) {
|
||||
this.stringEntrys = stringEntrys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<AnyValue>[] getAnyEntrys() {
|
||||
return (Entry<AnyValue>[]) (Entry[]) anyEntrys;
|
||||
}
|
||||
|
||||
public void setAnyEntrys(Entry<DefaultAnyValue>[] anyEntrys) {
|
||||
this.anyEntrys = anyEntrys;
|
||||
}
|
||||
|
||||
public boolean isIgnoreCase() {
|
||||
return ignoreCase;
|
||||
}
|
||||
|
||||
public void setIgnoreCase(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
if (this.predicate == null) {
|
||||
this.predicate = ignoreCase ? EQUALS_IGNORE : EQUALS_PREDICATE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ConvertDisabled
|
||||
public String[] getNames() {
|
||||
Set<String> set = new LinkedHashSet<>();
|
||||
for (Entry en : this.stringEntrys) {
|
||||
set.add(en.name);
|
||||
}
|
||||
for (Entry en : this.anyEntrys) {
|
||||
set.add(en.name);
|
||||
}
|
||||
return set.toArray(new String[set.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValues(String... names) {
|
||||
return Entry.getStringArray(this.predicate, this.stringEntrys, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue[] getAnyValues(String... names) {
|
||||
return Entry.getAnyValueArray(this.predicate, this.anyEntrys, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValues(String name) {
|
||||
return Entry.getStringArray(this.predicate, this.stringEntrys, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue[] getAnyValues(String name) {
|
||||
return Entry.getAnyValueArray(this.predicate, this.anyEntrys, name);
|
||||
}
|
||||
|
||||
protected Entry<AnyValue>[] getAnyValueEntrys(String name) {
|
||||
return Entry.getEntryAnyValueArray(this.predicate, this.anyEntrys, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(0, (any, space) -> {
|
||||
int index = ((DefaultAnyValue) any).parentArrayIndex;
|
||||
if (index < 0) {
|
||||
return null;
|
||||
}
|
||||
return new StringBuilder().append(space).append(" '$index': ").append(index).append(",\r\n");
|
||||
});
|
||||
}
|
||||
|
||||
public DefaultAnyValue clear() {
|
||||
if (this.stringEntrys != null && this.stringEntrys.length > 0) {
|
||||
this.stringEntrys = new Entry[0];
|
||||
}
|
||||
if (this.anyEntrys != null && this.anyEntrys.length > 0) {
|
||||
this.anyEntrys = new Entry[0];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultAnyValue setValue(String name, String value) {
|
||||
Objects.requireNonNull(name);
|
||||
if (!existsValue(name)) {
|
||||
this.addValue(name, value);
|
||||
} else {
|
||||
for (Entry<String> en : this.stringEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
en.value = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultAnyValue setValue(String name, AnyValue value) {
|
||||
Objects.requireNonNull(name);
|
||||
if (!existsValue(name)) {
|
||||
this.addValue(name, value);
|
||||
} else {
|
||||
for (Entry<DefaultAnyValue> en : this.anyEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
en.value = (DefaultAnyValue) value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultAnyValue put(String name, boolean value) {
|
||||
return addValue(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public DefaultAnyValue put(String name, Number value) {
|
||||
return addValue(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public DefaultAnyValue put(String name, String value) {
|
||||
this.stringEntrys = Utility.append(this.stringEntrys, new Entry(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultAnyValue addValue(String name, boolean value) {
|
||||
return addValue(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public DefaultAnyValue addValue(String name, Number value) {
|
||||
return addValue(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public DefaultAnyValue addValue(String name, String value) {
|
||||
Objects.requireNonNull(name);
|
||||
this.stringEntrys = Utility.append(this.stringEntrys, new Entry(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultAnyValue addValue(String name, AnyValue value) {
|
||||
Objects.requireNonNull(name);
|
||||
this.anyEntrys = Utility.append(this.anyEntrys, new Entry(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void clearParentArrayIndex(String name) {
|
||||
for (Entry<AnyValue> item : getAnyValueEntrys(name)) {
|
||||
if (item.value != null) {
|
||||
((DefaultAnyValue) item.value).parentArrayIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DefaultAnyValue removeAnyValues(String name) {
|
||||
Objects.requireNonNull(name);
|
||||
if (this.anyEntrys == null) {
|
||||
return this;
|
||||
}
|
||||
this.anyEntrys = Utility.remove(this.anyEntrys, t -> name.equals(((Entry) t).name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultAnyValue removeValue(String name, AnyValue value) {
|
||||
Objects.requireNonNull(name);
|
||||
if (value == null || this.anyEntrys == null) {
|
||||
return this;
|
||||
}
|
||||
this.anyEntrys = Utility.remove(this.anyEntrys, t -> name.equals(((Entry) t).name) && ((Entry) t).getValue().equals(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultAnyValue removeStringValues(String name) {
|
||||
Objects.requireNonNull(name);
|
||||
if (this.stringEntrys == null) {
|
||||
return this;
|
||||
}
|
||||
this.stringEntrys = Utility.remove(this.stringEntrys, t -> name.equals(((Entry) t).name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultAnyValue removeValue(String name, String value) {
|
||||
Objects.requireNonNull(name);
|
||||
if (value == null || this.stringEntrys == null) {
|
||||
return this;
|
||||
}
|
||||
this.stringEntrys = Utility.remove(this.stringEntrys, t -> name.equals(((Entry) t).name) && ((Entry) t).getValue().equals(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue getAnyValue(String name) {
|
||||
return getAnyValue(name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue getAnyValue(String name, boolean create) {
|
||||
for (Entry<DefaultAnyValue> en : this.anyEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
return en.value;
|
||||
}
|
||||
}
|
||||
return create ? new DefaultAnyValue() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String name) {
|
||||
return getValue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String name) {
|
||||
for (Entry<String> en : this.stringEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
return en.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean existsValue(String name) {
|
||||
for (Entry<String> en : this.stringEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
/**
|
||||
* 字段名和值的组合对象
|
||||
@@ -685,7 +100,7 @@ public abstract class AnyValue {
|
||||
return value;
|
||||
}
|
||||
|
||||
static Entry<AnyValue>[] getEntryAnyValueArray(BiPredicate<String, String> comparison, Entry<DefaultAnyValue>[] entitys, String name) {
|
||||
static Entry<AnyValue>[] getEntryAnyValueArray(BiPredicate<String, String> comparison, Entry<AnyValueWriter>[] entitys, String name) {
|
||||
int len = 0;
|
||||
for (Entry en : entitys) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
@@ -697,7 +112,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
Entry[] rs = new Entry[len];
|
||||
int i = 0;
|
||||
for (Entry<DefaultAnyValue> en : entitys) {
|
||||
for (Entry<AnyValueWriter> en : entitys) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
rs[i++] = en;
|
||||
}
|
||||
@@ -725,7 +140,7 @@ public abstract class AnyValue {
|
||||
return rs;
|
||||
}
|
||||
|
||||
static AnyValue[] getAnyValueArray(BiPredicate<String, String> comparison, Entry<DefaultAnyValue>[] entitys, String name) {
|
||||
static AnyValue[] getAnyValueArray(BiPredicate<String, String> comparison, Entry<AnyValueWriter>[] entitys, String name) {
|
||||
int len = 0;
|
||||
for (Entry en : entitys) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
@@ -737,7 +152,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
AnyValue[] rs = new AnyValue[len];
|
||||
int i = 0;
|
||||
for (Entry<DefaultAnyValue> en : entitys) {
|
||||
for (Entry<AnyValueWriter> en : entitys) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
rs[i++] = en.value;
|
||||
}
|
||||
@@ -771,7 +186,7 @@ public abstract class AnyValue {
|
||||
return rs;
|
||||
}
|
||||
|
||||
static AnyValue[] getAnyValueArray(BiPredicate<String, String> comparison, Entry<DefaultAnyValue>[] entitys, String... names) {
|
||||
static AnyValue[] getAnyValueArray(BiPredicate<String, String> comparison, Entry<AnyValueWriter>[] entitys, String... names) {
|
||||
int len = 0;
|
||||
for (Entry en : entitys) {
|
||||
for (String name : names) {
|
||||
@@ -786,7 +201,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
AnyValue[] rs = new AnyValue[len];
|
||||
int i = 0;
|
||||
for (Entry<DefaultAnyValue> en : entitys) {
|
||||
for (Entry<AnyValueWriter> en : entitys) {
|
||||
for (String name : names) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
rs[i++] = en.value;
|
||||
@@ -799,12 +214,12 @@ public abstract class AnyValue {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建DefaultAnyValue
|
||||
* 创建AnyValueWriter
|
||||
*
|
||||
* @return DefaultAnyValue
|
||||
* @return AnyValueWriter
|
||||
*/
|
||||
public static DefaultAnyValue create() {
|
||||
return new DefaultAnyValue();
|
||||
public static AnyValueWriter create() {
|
||||
return new AnyValueWriter();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -900,9 +315,9 @@ public abstract class AnyValue {
|
||||
if (properties == null) {
|
||||
return null;
|
||||
}
|
||||
DefaultAnyValue conf = new DefaultAnyValue();
|
||||
AnyValueWriter conf = new AnyValueWriter();
|
||||
final char splitChar = (char) 2;
|
||||
Map<String, DefaultAnyValue> prefixArray = new TreeMap<>(); //已处理的数组key,如 redkale.source[0].xx 存redkale.source[0]
|
||||
Map<String, AnyValueWriter> prefixArray = new TreeMap<>(); //已处理的数组key,如:redkale.source[0].xx存redkale.source[0]
|
||||
properties.forEach((key, value) -> {
|
||||
StringBuilder temp = new StringBuilder();
|
||||
boolean flag = false;
|
||||
@@ -921,15 +336,15 @@ public abstract class AnyValue {
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
keys[i] = keys[i].replace(splitChar, '.');
|
||||
}
|
||||
DefaultAnyValue parent = conf;
|
||||
AnyValueWriter parent = conf;
|
||||
if (keys.length > 1) {
|
||||
for (int i = 0; i < keys.length - 1; i++) {
|
||||
String item = keys[i];
|
||||
int pos = item.indexOf('[');
|
||||
if (pos < 0) {
|
||||
DefaultAnyValue child = (DefaultAnyValue) parent.getAnyValue(item);
|
||||
AnyValueWriter child = (AnyValueWriter) parent.getAnyValue(item);
|
||||
if (child == null) {
|
||||
child = new DefaultAnyValue();
|
||||
child = new AnyValueWriter();
|
||||
parent.addValue(item, child);
|
||||
}
|
||||
parent = child;
|
||||
@@ -948,12 +363,12 @@ public abstract class AnyValue {
|
||||
for (int j = 0; j < i; j++) {
|
||||
prefixKey += keys[j] + ".";
|
||||
}
|
||||
DefaultAnyValue array = prefixArray.get(prefixKey + item); //item: [1]
|
||||
AnyValueWriter array = prefixArray.get(prefixKey + item); //item: [1]
|
||||
if (array == null) {
|
||||
final int ii = i;
|
||||
String findkey = prefixKey + itemField + "[";
|
||||
Map<String, DefaultAnyValue> keymap = new TreeMap<>();
|
||||
Map<Integer, DefaultAnyValue> sortmap = new TreeMap<>();
|
||||
Map<String, AnyValueWriter> keymap = new TreeMap<>();
|
||||
Map<Integer, AnyValueWriter> sortmap = new TreeMap<>();
|
||||
properties.keySet().stream().filter(x -> x.toString().startsWith(findkey)).forEach(k -> {
|
||||
String[] ks = k.toString().split("\\.");
|
||||
String prefixKey2 = "";
|
||||
@@ -962,7 +377,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
prefixKey2 += ks[ii];
|
||||
if (!keymap.containsKey(prefixKey2)) {
|
||||
DefaultAnyValue vv = new DefaultAnyValue();
|
||||
AnyValueWriter vv = new AnyValueWriter();
|
||||
keymap.put(prefixKey2, vv);
|
||||
int aindex = Integer.parseInt(ks[ii].substring(ks[ii].indexOf('[') + 1, ks[ii].lastIndexOf(']')));
|
||||
vv.parentArrayIndex = aindex;
|
||||
@@ -970,20 +385,20 @@ public abstract class AnyValue {
|
||||
}
|
||||
});
|
||||
prefixArray.putAll(keymap);
|
||||
DefaultAnyValue pv = parent;
|
||||
AnyValueWriter pv = parent;
|
||||
sortmap.values().forEach(v -> pv.addValue(itemField, v));
|
||||
array = prefixArray.get(prefixKey + item);
|
||||
}
|
||||
parent = array;
|
||||
} else { //Map结构
|
||||
DefaultAnyValue field = (DefaultAnyValue) parent.getAnyValue(itemField);
|
||||
AnyValueWriter field = (AnyValueWriter) parent.getAnyValue(itemField);
|
||||
if (field == null) {
|
||||
field = new DefaultAnyValue();
|
||||
field = new AnyValueWriter();
|
||||
parent.addValue(itemField, field);
|
||||
}
|
||||
DefaultAnyValue index = (DefaultAnyValue) field.getAnyValue(keyOrIndex);
|
||||
AnyValueWriter index = (AnyValueWriter) field.getAnyValue(keyOrIndex);
|
||||
if (index == null) {
|
||||
index = new DefaultAnyValue();
|
||||
index = new AnyValueWriter();
|
||||
if (nameName != null) {
|
||||
index.setValue(nameName, keyOrIndex);
|
||||
}
|
||||
@@ -1027,13 +442,13 @@ public abstract class AnyValue {
|
||||
sortmap.put(Integer.parseInt(ks[ii].substring(ks[ii].indexOf('[') + 1, ks[ii].lastIndexOf(']'))), vv);
|
||||
}
|
||||
});
|
||||
DefaultAnyValue pv = parent;
|
||||
AnyValueWriter pv = parent;
|
||||
sortmap.values().forEach(v -> pv.addValue(itemField, v));
|
||||
}
|
||||
} else { //Map
|
||||
DefaultAnyValue child = (DefaultAnyValue) parent.getAnyValue(itemField);
|
||||
AnyValueWriter child = (AnyValueWriter) parent.getAnyValue(itemField);
|
||||
if (child == null) {
|
||||
child = new DefaultAnyValue();
|
||||
child = new AnyValueWriter();
|
||||
parent.addValue(itemField, child);
|
||||
}
|
||||
child.addValue(itemIndex, value.toString());
|
||||
@@ -1088,7 +503,7 @@ public abstract class AnyValue {
|
||||
* @return AnyValue
|
||||
* @throws IOException 异常
|
||||
*/
|
||||
public static AnyValue loadFromXml(String text, BiFunction<String, String, String> attrFunc) throws IOException {
|
||||
public static AnyValue loadFromXml(String text, BinaryOperator<String> attrFunc) throws IOException {
|
||||
return new XmlReader(text).attrFunc(attrFunc).read();
|
||||
}
|
||||
|
||||
@@ -1101,7 +516,7 @@ public abstract class AnyValue {
|
||||
* @return AnyValue
|
||||
* @throws IOException 异常
|
||||
*/
|
||||
public static AnyValue loadFromXml(InputStream in, BiFunction<String, String, String> attrFunc) throws IOException {
|
||||
public static AnyValue loadFromXml(InputStream in, BinaryOperator<String> attrFunc) throws IOException {
|
||||
return loadFromXml(in, StandardCharsets.UTF_8, attrFunc);
|
||||
}
|
||||
|
||||
@@ -1115,7 +530,7 @@ public abstract class AnyValue {
|
||||
* @return AnyValue
|
||||
* @throws IOException 异常
|
||||
*/
|
||||
public static AnyValue loadFromXml(InputStream in, Charset charset, BiFunction<String, String, String> attrFunc) throws IOException {
|
||||
public static AnyValue loadFromXml(InputStream in, Charset charset, BinaryOperator<String> attrFunc) throws IOException {
|
||||
return new XmlReader(Utility.read(in, charset)).attrFunc(attrFunc).read();
|
||||
}
|
||||
|
||||
@@ -1282,7 +697,7 @@ public abstract class AnyValue {
|
||||
/**
|
||||
* 根据字段名获取AnyValue类型的字段值
|
||||
*
|
||||
* @param name 字段名
|
||||
* @param name 字段名
|
||||
* @param create 没有是否创建一个新的对象返回
|
||||
*
|
||||
* @return AnyValue
|
||||
|
||||
604
src/main/java/org/redkale/util/AnyValueWriter.java
Normal file
604
src/main/java/org/redkale/util/AnyValueWriter.java
Normal file
@@ -0,0 +1,604 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.util;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiPredicate;
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
|
||||
/**
|
||||
* AnyValue的可写版
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AnyValueWriter extends AnyValue {
|
||||
|
||||
/**
|
||||
* 区分name大小写的比较策略
|
||||
*
|
||||
*/
|
||||
public static final BiPredicate<String, String> EQUALS_PREDICATE = (name1, name2) -> name1.equals(name2);
|
||||
|
||||
/**
|
||||
* 不区分name大小写的比较策略
|
||||
*/
|
||||
public static final BiPredicate<String, String> EQUALS_IGNORE = (name1, name2) -> name1.equalsIgnoreCase(name2);
|
||||
|
||||
@ConvertColumn(index = 1)
|
||||
private boolean ignoreCase;
|
||||
|
||||
private BiPredicate<String, String> predicate;
|
||||
|
||||
@ConvertColumn(index = 2)
|
||||
private Entry<String>[] stringEntrys = new Entry[0];
|
||||
|
||||
@ConvertColumn(index = 3)
|
||||
private Entry<AnyValueWriter>[] anyEntrys = new Entry[0];
|
||||
|
||||
int parentArrayIndex = -1; //只可能被loadFromProperties方法赋值
|
||||
|
||||
/**
|
||||
* 创建含name-value值的AnyValueWriter
|
||||
*
|
||||
* @param name name
|
||||
* @param value value值
|
||||
*
|
||||
* @return AnyValueWriter
|
||||
*/
|
||||
public static final AnyValueWriter create(String name, Number value) {
|
||||
AnyValueWriter conf = new AnyValueWriter();
|
||||
conf.addValue(name, value);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建含name-value值的AnyValueWriter对象
|
||||
*
|
||||
* @param name name
|
||||
* @param value value值
|
||||
*
|
||||
* @return AnyValueWriter对象
|
||||
*/
|
||||
public static final AnyValueWriter create(String name, String value) {
|
||||
AnyValueWriter conf = new AnyValueWriter();
|
||||
conf.addValue(name, value);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建含name-value值的AnyValueWriter对象
|
||||
*
|
||||
* @param name name
|
||||
* @param value value值
|
||||
*
|
||||
* @return AnyValueWriter对象
|
||||
*/
|
||||
public static final AnyValueWriter create(String name, AnyValue value) {
|
||||
AnyValueWriter conf = new AnyValueWriter();
|
||||
conf.addValue(name, value);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个区分大小写比较策略的AnyValueWriter对象
|
||||
*
|
||||
*/
|
||||
public AnyValueWriter() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建AnyValueWriter对象
|
||||
*
|
||||
* @param ignoreCase name是否不区分大小写
|
||||
*/
|
||||
public AnyValueWriter(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
this.predicate = ignoreCase ? EQUALS_IGNORE : EQUALS_PREDICATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建共享此内容的AnyValueWriter对象
|
||||
*
|
||||
* @return AnyValueWriter对象
|
||||
*/
|
||||
public AnyValueWriter duplicate() {
|
||||
AnyValueWriter rs = new AnyValueWriter(this.ignoreCase);
|
||||
rs.stringEntrys = this.stringEntrys;
|
||||
rs.anyEntrys = this.anyEntrys;
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制一份对象
|
||||
*
|
||||
* @return AnyValueWriter对象
|
||||
*/
|
||||
@Override
|
||||
public AnyValueWriter copy() {
|
||||
AnyValueWriter rs = new AnyValueWriter(this.ignoreCase);
|
||||
rs.predicate = this.predicate;
|
||||
rs.parentArrayIndex = this.parentArrayIndex;
|
||||
if (this.stringEntrys != null) {
|
||||
rs.stringEntrys = new Entry[this.stringEntrys.length];
|
||||
for (int i = 0; i < rs.stringEntrys.length; i++) {
|
||||
Entry<String> en = this.stringEntrys[i];
|
||||
if (en == null) {
|
||||
continue;
|
||||
}
|
||||
rs.stringEntrys[i] = new Entry(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (this.anyEntrys != null) {
|
||||
rs.anyEntrys = new Entry[this.anyEntrys.length];
|
||||
for (int i = 0; i < rs.anyEntrys.length; i++) {
|
||||
Entry<AnyValueWriter> en = this.anyEntrys[i];
|
||||
if (en == null) {
|
||||
continue;
|
||||
}
|
||||
rs.anyEntrys[i] = new Entry(en.name, en.value == null ? null : en.value.copy());
|
||||
}
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将另一个对象替换本对象
|
||||
*
|
||||
* @param node 替换的对象
|
||||
*
|
||||
* @return AnyValue
|
||||
*/
|
||||
@Override
|
||||
public AnyValueWriter replace(AnyValue node) {
|
||||
if (node != null) {
|
||||
AnyValueWriter rs = (AnyValueWriter) node;
|
||||
this.ignoreCase = rs.ignoreCase;
|
||||
this.predicate = rs.predicate;
|
||||
this.parentArrayIndex = rs.parentArrayIndex;
|
||||
this.stringEntrys = rs.stringEntrys;
|
||||
this.anyEntrys = rs.anyEntrys;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将另一个对象合并过来
|
||||
*
|
||||
* @param node 代合并对象
|
||||
* @param func 判断覆盖方式的函数
|
||||
*
|
||||
* @return AnyValue
|
||||
*/
|
||||
@Override
|
||||
public AnyValueWriter merge(AnyValue node, MergeFunction func) {
|
||||
return merge(node, "", func);
|
||||
}
|
||||
|
||||
protected AnyValueWriter merge(AnyValue node0, String path, MergeFunction func) {
|
||||
if (node0 == null) {
|
||||
return this;
|
||||
}
|
||||
if (node0 == this) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
AnyValueWriter node = (AnyValueWriter) node0;
|
||||
if (node.stringEntrys != null) {
|
||||
for (Entry<String> en : node.stringEntrys) {
|
||||
if (en == null) {
|
||||
continue;
|
||||
}
|
||||
setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (node.anyEntrys != null) {
|
||||
for (Entry<AnyValueWriter> en : node.anyEntrys) {
|
||||
if (en == null || en.value == null) {
|
||||
continue;
|
||||
}
|
||||
Entry<AnyValue>[] ns = getAnyValueEntrys(en.name);
|
||||
if (ns == null || ns.length < 1) {
|
||||
addValue(en.name, en.value);
|
||||
} else {
|
||||
boolean ok = false;
|
||||
for (Entry<AnyValue> item : ns) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if (item.value != null && en.value.parentArrayIndex == ((AnyValueWriter) item.value).parentArrayIndex) {
|
||||
if (func == null) {
|
||||
item.value.merge(en.value, func);
|
||||
ok = true;
|
||||
break;
|
||||
} else {
|
||||
int funcVal = func.apply(path, en.name, en.value, item.value);
|
||||
if (funcVal == MergeFunction.MERGE) {
|
||||
String subPath = path.isEmpty() ? en.name : (path + "." + en.name);
|
||||
((AnyValueWriter) item.value).merge(en.value, subPath, func);
|
||||
ok = true;
|
||||
break;
|
||||
} else if (funcVal == MergeFunction.REPLACE) {
|
||||
item.value = en.value.copy();
|
||||
ok = true;
|
||||
break;
|
||||
} else if (funcVal == MergeFunction.SKIP) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并两个AnyValue对象, 会去重, 没有的才增加
|
||||
*
|
||||
* @param av AnyValue
|
||||
*
|
||||
* @return AnyValueWriter
|
||||
*/
|
||||
public AnyValueWriter addAllStringSet(final AnyValue av) {
|
||||
if (av == null) {
|
||||
return this;
|
||||
}
|
||||
final Entry<String>[] strings = av.getStringEntrys();
|
||||
if (strings == null) {
|
||||
return this;
|
||||
}
|
||||
for (Entry<String> en : strings) {
|
||||
if (!existsValue(en.name)) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并两个AnyValue对象 不去重
|
||||
*
|
||||
* @param av AnyValue
|
||||
*
|
||||
* @return AnyValueWriter
|
||||
*/
|
||||
public AnyValueWriter addAll(final AnyValue av) {
|
||||
if (av == null) {
|
||||
return this;
|
||||
}
|
||||
if (av instanceof AnyValueWriter) {
|
||||
final AnyValueWriter adv = (AnyValueWriter) av;
|
||||
if (adv.stringEntrys != null) {
|
||||
for (Entry<String> en : adv.stringEntrys) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (adv.anyEntrys != null) {
|
||||
for (Entry<AnyValueWriter> en : adv.anyEntrys) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final Entry<String>[] strings = av.getStringEntrys();
|
||||
if (strings != null) {
|
||||
for (Entry<String> en : strings) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
final Entry<AnyValue>[] anys = av.getAnyEntrys();
|
||||
if (anys != null) {
|
||||
for (Entry<AnyValue> en : anys) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并两个AnyValue对象 会去重
|
||||
*
|
||||
* @param av AnyValue
|
||||
*
|
||||
* @return AnyValueWriter
|
||||
*/
|
||||
@ConvertDisabled
|
||||
public AnyValueWriter setAll(final AnyValue av) {
|
||||
if (av == null) {
|
||||
return this;
|
||||
}
|
||||
if (av instanceof AnyValueWriter) {
|
||||
final AnyValueWriter adv = (AnyValueWriter) av;
|
||||
if (adv.stringEntrys != null) {
|
||||
for (Entry<String> en : adv.stringEntrys) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (adv.anyEntrys != null) {
|
||||
for (Entry<AnyValueWriter> en : adv.anyEntrys) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final Entry<String>[] strings = av.getStringEntrys();
|
||||
if (strings != null) {
|
||||
for (Entry<String> en : strings) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
final Entry<AnyValue>[] anys = av.getAnyEntrys();
|
||||
if (anys != null) {
|
||||
for (Entry<AnyValue> en : anys) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<String, String> stringConsumer) {
|
||||
forEach(stringConsumer, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<String, String> stringConsumer, BiConsumer<String, AnyValue> anyConsumer) {
|
||||
if (stringConsumer != null) {
|
||||
for (Entry<String> en : stringEntrys) {
|
||||
stringConsumer.accept(en.name, en.value);
|
||||
}
|
||||
}
|
||||
if (anyConsumer != null) {
|
||||
for (Entry<AnyValue> en : (Entry[]) anyEntrys) {
|
||||
anyConsumer.accept(en.name, en.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<String>[] getStringEntrys() {
|
||||
return stringEntrys;
|
||||
}
|
||||
|
||||
public void setStringEntrys(Entry<String>[] stringEntrys) {
|
||||
this.stringEntrys = stringEntrys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<AnyValue>[] getAnyEntrys() {
|
||||
return (Entry<AnyValue>[]) (Entry[]) anyEntrys;
|
||||
}
|
||||
|
||||
public void setAnyEntrys(Entry<AnyValueWriter>[] anyEntrys) {
|
||||
this.anyEntrys = anyEntrys;
|
||||
}
|
||||
|
||||
public boolean isIgnoreCase() {
|
||||
return ignoreCase;
|
||||
}
|
||||
|
||||
public void setIgnoreCase(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
if (this.predicate == null) {
|
||||
this.predicate = ignoreCase ? EQUALS_IGNORE : EQUALS_PREDICATE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ConvertDisabled
|
||||
public String[] getNames() {
|
||||
Set<String> set = new LinkedHashSet<>();
|
||||
for (Entry en : this.stringEntrys) {
|
||||
set.add(en.name);
|
||||
}
|
||||
for (Entry en : this.anyEntrys) {
|
||||
set.add(en.name);
|
||||
}
|
||||
return set.toArray(new String[set.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValues(String... names) {
|
||||
return Entry.getStringArray(this.predicate, this.stringEntrys, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue[] getAnyValues(String... names) {
|
||||
return Entry.getAnyValueArray(this.predicate, this.anyEntrys, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValues(String name) {
|
||||
return Entry.getStringArray(this.predicate, this.stringEntrys, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue[] getAnyValues(String name) {
|
||||
return Entry.getAnyValueArray(this.predicate, this.anyEntrys, name);
|
||||
}
|
||||
|
||||
protected Entry<AnyValue>[] getAnyValueEntrys(String name) {
|
||||
return Entry.getEntryAnyValueArray(this.predicate, this.anyEntrys, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(0, (any, space) -> {
|
||||
int index = ((AnyValueWriter) any).parentArrayIndex;
|
||||
if (index < 0) {
|
||||
return null; //不能用"null"
|
||||
}
|
||||
return new StringBuilder().append(space).append(" '$index': ").append(index).append(",\r\n");
|
||||
});
|
||||
}
|
||||
|
||||
public AnyValueWriter clear() {
|
||||
if (this.stringEntrys != null && this.stringEntrys.length > 0) {
|
||||
this.stringEntrys = new Entry[0];
|
||||
}
|
||||
if (this.anyEntrys != null && this.anyEntrys.length > 0) {
|
||||
this.anyEntrys = new Entry[0];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValueWriter setValue(String name, String value) {
|
||||
Objects.requireNonNull(name);
|
||||
if (!existsValue(name)) {
|
||||
this.addValue(name, value);
|
||||
} else {
|
||||
for (Entry<String> en : this.stringEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
en.value = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValueWriter setValue(String name, AnyValue value) {
|
||||
Objects.requireNonNull(name);
|
||||
if (!existsValue(name)) {
|
||||
this.addValue(name, value);
|
||||
} else {
|
||||
for (Entry<AnyValueWriter> en : this.anyEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
en.value = (AnyValueWriter) value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValueWriter put(String name, boolean value) {
|
||||
return addValue(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public AnyValueWriter put(String name, Number value) {
|
||||
return addValue(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public AnyValueWriter put(String name, String value) {
|
||||
this.stringEntrys = Utility.append(this.stringEntrys, new Entry(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValueWriter addValue(String name, boolean value) {
|
||||
return addValue(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public AnyValueWriter addValue(String name, Number value) {
|
||||
return addValue(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public AnyValueWriter addValue(String name, String value) {
|
||||
Objects.requireNonNull(name);
|
||||
this.stringEntrys = Utility.append(this.stringEntrys, new Entry(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValueWriter addValue(String name, AnyValue value) {
|
||||
Objects.requireNonNull(name);
|
||||
this.anyEntrys = Utility.append(this.anyEntrys, new Entry(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void clearParentArrayIndex(String name) {
|
||||
for (Entry<AnyValue> item : getAnyValueEntrys(name)) {
|
||||
if (item.value != null) {
|
||||
((AnyValueWriter) item.value).parentArrayIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AnyValueWriter removeAnyValues(String name) {
|
||||
Objects.requireNonNull(name);
|
||||
if (this.anyEntrys == null) {
|
||||
return this;
|
||||
}
|
||||
this.anyEntrys = Utility.remove(this.anyEntrys, t -> name.equals(((Entry) t).name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValueWriter removeValue(String name, AnyValue value) {
|
||||
Objects.requireNonNull(name);
|
||||
if (value == null || this.anyEntrys == null) {
|
||||
return this;
|
||||
}
|
||||
this.anyEntrys = Utility.remove(this.anyEntrys, t -> name.equals(((Entry) t).name) && ((Entry) t).getValue().equals(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValueWriter removeStringValues(String name) {
|
||||
Objects.requireNonNull(name);
|
||||
if (this.stringEntrys == null) {
|
||||
return this;
|
||||
}
|
||||
this.stringEntrys = Utility.remove(this.stringEntrys, t -> name.equals(((Entry) t).name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValueWriter removeValue(String name, String value) {
|
||||
Objects.requireNonNull(name);
|
||||
if (value == null || this.stringEntrys == null) {
|
||||
return this;
|
||||
}
|
||||
this.stringEntrys = Utility.remove(this.stringEntrys, t -> name.equals(((Entry) t).name) && ((Entry) t).getValue().equals(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue getAnyValue(String name) {
|
||||
return getAnyValue(name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue getAnyValue(String name, boolean create) {
|
||||
for (Entry<AnyValueWriter> en : this.anyEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
return en.value;
|
||||
}
|
||||
}
|
||||
return create ? new AnyValueWriter() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String name) {
|
||||
return getValue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String name) {
|
||||
for (Entry<String> en : this.stringEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
return en.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean existsValue(String name) {
|
||||
for (Entry<String> en : this.stringEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -35,30 +35,82 @@ public class Environment implements java.io.Serializable {
|
||||
return properties.containsKey(key);
|
||||
}
|
||||
|
||||
public String getProperty(String key) {
|
||||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
public String getProperty(String key, String defaultValue) {
|
||||
return properties.getProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
public void forEach(BiConsumer<String, String> action) {
|
||||
properties.forEach((BiConsumer) action);
|
||||
}
|
||||
|
||||
public void forEach(Predicate<String> predicate, BiConsumer<String, String> action) {
|
||||
properties.entrySet().stream().filter(en -> predicate.test(en.getKey().toString()))
|
||||
.forEach(en -> action.accept(en.getKey().toString(), en.getValue() == null ? null : en.getValue().toString()));
|
||||
.forEach(en -> action.accept(en.getKey().toString(), String.valueOf(en.getValue())));
|
||||
}
|
||||
|
||||
public String getProperty(String name) {
|
||||
return getProperty(name, null);
|
||||
}
|
||||
|
||||
public String getProperty(String name, String defaultValue) {
|
||||
return getPropertyValue(getRawProperty(name, defaultValue));
|
||||
}
|
||||
|
||||
public String getPropertyValue(String val, Properties... envs) {
|
||||
if (val == null || val.isBlank()) {
|
||||
return val;
|
||||
}
|
||||
//${domain}/${path}/xxx ${aa${bbb}}
|
||||
int pos2 = val.indexOf("}");
|
||||
int pos1 = val.lastIndexOf("${", pos2);
|
||||
if (pos1 >= 0 && pos2 > 0) {
|
||||
String key = val.substring(pos1 + 2, pos2);
|
||||
String subVal = properties.getProperty(key);
|
||||
if (subVal != null) {
|
||||
String newVal = getPropertyValue(subVal, envs);
|
||||
return getPropertyValue(val.substring(0, pos1) + newVal + val.substring(pos2 + 1));
|
||||
} else {
|
||||
for (Properties prop : envs) {
|
||||
subVal = prop.getProperty(key);
|
||||
if (subVal != null) {
|
||||
String newVal = getPropertyValue(subVal, envs);
|
||||
return getPropertyValue(val.substring(0, pos1) + newVal + val.substring(pos2 + 1));
|
||||
}
|
||||
}
|
||||
throw new RedkaleException("Not found '" + key + "' value");
|
||||
}
|
||||
|
||||
} else if ((pos1 >= 0 && pos2 < 0) || (pos1 < 0 && pos2 >= 0)) {
|
||||
throw new RedkaleException(val + " is illegal naming");
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public AnyValue getAnyValue(String name, boolean autoCreated) {
|
||||
Properties props = new Properties();
|
||||
String prefix = name + ".";
|
||||
properties.forEach((k, v) -> {
|
||||
if (k.toString().equals(name) || k.toString().startsWith(prefix)) {
|
||||
props.put(k, getProperty(k.toString()));
|
||||
}
|
||||
});
|
||||
if (props.isEmpty()) {
|
||||
return autoCreated ? AnyValueWriter.create() : null;
|
||||
}
|
||||
return AnyValueWriter.loadFromProperties(props);
|
||||
}
|
||||
|
||||
public String getRawProperty(String key) {
|
||||
return getRawProperty(key, null);
|
||||
}
|
||||
|
||||
public String getRawProperty(String key, String defaultValue) {
|
||||
return properties.getProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
public boolean getBooleanProperty(String key) {
|
||||
String val = properties.getProperty(key);
|
||||
String val = getProperty(key);
|
||||
return "true".equalsIgnoreCase(val) || "1".equalsIgnoreCase(val);
|
||||
}
|
||||
|
||||
public boolean getBooleanProperty(String key, boolean defaultValue) {
|
||||
String val = properties.getProperty(key);
|
||||
String val = getProperty(key);
|
||||
if (val == null || val.isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -66,11 +118,11 @@ public class Environment implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public short getShortProperty(String key) {
|
||||
return Short.parseShort(properties.getProperty(key));
|
||||
return Short.parseShort(getProperty(key));
|
||||
}
|
||||
|
||||
public short getShortProperty(String key, short defaultValue) {
|
||||
String val = properties.getProperty(key);
|
||||
String val = getProperty(key);
|
||||
if (val == null || val.isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -82,11 +134,11 @@ public class Environment implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public int getIntProperty(String key) {
|
||||
return Integer.parseInt(properties.getProperty(key));
|
||||
return Integer.parseInt(getProperty(key));
|
||||
}
|
||||
|
||||
public int getIntProperty(String key, int defaultValue) {
|
||||
String val = properties.getProperty(key);
|
||||
String val = getProperty(key);
|
||||
if (val == null || val.isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -98,11 +150,11 @@ public class Environment implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public float getFloatProperty(String key) {
|
||||
return Float.parseFloat(properties.getProperty(key));
|
||||
return Float.parseFloat(getProperty(key));
|
||||
}
|
||||
|
||||
public float getFloatProperty(String key, float defaultValue) {
|
||||
String val = properties.getProperty(key);
|
||||
String val = getProperty(key);
|
||||
if (val == null || val.isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -114,11 +166,11 @@ public class Environment implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public long getLongProperty(String key) {
|
||||
return Long.parseLong(properties.getProperty(key));
|
||||
return Long.parseLong(getProperty(key));
|
||||
}
|
||||
|
||||
public long getLongProperty(String key, long defaultValue) {
|
||||
String val = properties.getProperty(key);
|
||||
String val = getProperty(key);
|
||||
if (val == null || val.isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -130,11 +182,11 @@ public class Environment implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public double getDoubleProperty(String key) {
|
||||
return Double.parseDouble(properties.getProperty(key));
|
||||
return Double.parseDouble(getProperty(key));
|
||||
}
|
||||
|
||||
public double getDoubleProperty(String key, double defaultValue) {
|
||||
String val = properties.getProperty(key);
|
||||
String val = getProperty(key);
|
||||
if (val == null || val.isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ class Inners {
|
||||
creatorCacheMap.put(CompletableFuture.class, p -> new CompletableFuture<>());
|
||||
creatorCacheMap.put(CompletionStage.class, p -> new CompletableFuture<>());
|
||||
creatorCacheMap.put(Future.class, p -> new CompletableFuture<>());
|
||||
creatorCacheMap.put(AnyValue.DefaultAnyValue.class, p -> new AnyValue.DefaultAnyValue());
|
||||
creatorCacheMap.put(AnyValue.class, p -> new AnyValue.DefaultAnyValue());
|
||||
creatorCacheMap.put(AnyValueWriter.class, p -> new AnyValueWriter());
|
||||
creatorCacheMap.put(AnyValue.class, p -> new AnyValueWriter());
|
||||
creatorCacheMap.put(Map.Entry.class, new Creator<Map.Entry>() {
|
||||
@Override
|
||||
@org.redkale.annotation.ConstructorParameters({"key", "value"})
|
||||
|
||||
@@ -8,7 +8,6 @@ package org.redkale.util;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
|
||||
/**
|
||||
* 简单的xml读取器, 只读element节点信息,其他信息(如: namespace、comment、docdecl等)都会丢弃
|
||||
@@ -38,9 +37,9 @@ public class XmlReader {
|
||||
|
||||
public String tag;
|
||||
|
||||
public DefaultAnyValue config;
|
||||
public AnyValueWriter config;
|
||||
|
||||
public TagNode(String tag, DefaultAnyValue node) {
|
||||
public TagNode(String tag, AnyValueWriter node) {
|
||||
this.tag = tag;
|
||||
this.config = node;
|
||||
}
|
||||
@@ -71,7 +70,7 @@ public class XmlReader {
|
||||
}
|
||||
|
||||
public AnyValue read() {
|
||||
DefaultAnyValue root = DefaultAnyValue.create();
|
||||
AnyValueWriter root = AnyValueWriter.create();
|
||||
char ch;
|
||||
lineNumber++;
|
||||
ByteArray array = new ByteArray(128);
|
||||
@@ -172,7 +171,7 @@ public class XmlReader {
|
||||
}
|
||||
|
||||
//返回是否endtag, 即以 />结尾
|
||||
protected boolean readTagAttribute(String tag, DefaultAnyValue config) {
|
||||
protected boolean readTagAttribute(String tag, AnyValueWriter config) {
|
||||
boolean first = true;
|
||||
boolean endtag = false;
|
||||
boolean endattr = false;
|
||||
@@ -254,7 +253,7 @@ public class XmlReader {
|
||||
return readTagAttribute(tag, config);
|
||||
}
|
||||
|
||||
protected void readStartTag(DefaultAnyValue root) {
|
||||
protected void readStartTag(AnyValueWriter root) {
|
||||
final int start = this.position;
|
||||
boolean hasattr = false;
|
||||
boolean endtag = false;
|
||||
@@ -273,7 +272,7 @@ public class XmlReader {
|
||||
ch = nextChar();
|
||||
}
|
||||
final String tag = new String(this.text, start, this.position - start).trim();
|
||||
DefaultAnyValue config = DefaultAnyValue.create();
|
||||
AnyValueWriter config = AnyValueWriter.create();
|
||||
TagNode tagNode = new TagNode(tag, config);
|
||||
if (tags.isEmpty()) {
|
||||
root.addValue(tag, tagNode.config);
|
||||
@@ -322,7 +321,7 @@ public class XmlReader {
|
||||
}
|
||||
}
|
||||
|
||||
protected void readDocdecl(DefaultAnyValue root, ByteArray array) {//读取到 <!D 才进入此方法 '<!DOCTYPE' S Name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'
|
||||
protected void readDocdecl(AnyValueWriter root, ByteArray array) {//读取到 <!D 才进入此方法 '<!DOCTYPE' S Name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'
|
||||
if (nextChar() != 'O') {
|
||||
throw newException("expected <!DOCTYPE");
|
||||
}
|
||||
@@ -355,7 +354,7 @@ public class XmlReader {
|
||||
}
|
||||
}
|
||||
|
||||
protected void readCDSect(DefaultAnyValue root, ByteArray array) {//读取到 <![ 才进入此方法 '<![CDATA[ (Char* - (Char* ']]>' Char*)) ]]>'
|
||||
protected void readCDSect(AnyValueWriter root, ByteArray array) {//读取到 <![ 才进入此方法 '<![CDATA[ (Char* - (Char* ']]>' Char*)) ]]>'
|
||||
if (nextChar() != 'C') {
|
||||
throw newException("expected <![CDATA[ for cdsect start");
|
||||
}
|
||||
@@ -391,7 +390,7 @@ public class XmlReader {
|
||||
}
|
||||
}
|
||||
|
||||
protected void readXmlDecl(DefaultAnyValue root, ByteArray array) {//读取到 <? 才进入此方法 <?xml version="1.0" encoding="UTF-8"?>
|
||||
protected void readXmlDecl(AnyValueWriter root, ByteArray array) {//读取到 <? 才进入此方法 <?xml version="1.0" encoding="UTF-8"?>
|
||||
char ch;
|
||||
array.clear();
|
||||
array.putByte('<');
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.redkale.net.AsyncIOGroup;
|
||||
import org.redkale.net.http.HttpServer;
|
||||
import org.redkale.net.http.HttpSimpleClient;
|
||||
import org.redkale.net.http.HttpSimpleRequest;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
import org.redkale.util.ResourceFactory;
|
||||
|
||||
/**
|
||||
@@ -96,7 +96,7 @@ public class HttpSimpleClientTest {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||
AnyValueWriter conf = new AnyValueWriter();
|
||||
conf.addValue("host", "0.0.0.0");
|
||||
conf.addValue("port", "" + port);
|
||||
conf.addValue("protocol", "HTTP");
|
||||
|
||||
@@ -43,7 +43,7 @@ public class RestSleepTest {
|
||||
HttpServer server = new HttpServer(application, System.currentTimeMillis(), resFactory);
|
||||
server.getResourceFactory().register(application);
|
||||
System.out.println("servlet = " + server.addRestServlet(null, service, null, HttpServlet.class, ""));
|
||||
server.init(AnyValue.DefaultAnyValue.create("port", 0));
|
||||
server.init(AnyValueWriter.create("port", 0));
|
||||
server.start();
|
||||
|
||||
int port = server.getSocketAddress().getPort();
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.redkale.net.http.*;
|
||||
import org.redkale.service.RetResult;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
|
||||
@WebServlet(value = {"/hello/*"}, repair = true)
|
||||
public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
@@ -27,7 +26,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
System.out.println(server.addRestServlet(null, service, null, SimpleRestServlet.class, "/pipes"));
|
||||
System.out.println(server.addRestServlet(null, new HelloService(3), null, SimpleRestServlet.class, "/pipes"));
|
||||
|
||||
DefaultAnyValue conf = DefaultAnyValue.create("port", "" + port);
|
||||
AnyValueWriter conf = AnyValueWriter.create("port", "" + port);
|
||||
server.init(conf);
|
||||
server.start();
|
||||
Utility.sleep(100);
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.redkale.net.http.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -58,7 +57,7 @@ public class ABMainService implements Service {
|
||||
cserver.getResourceFactory().register(application);
|
||||
//cserver.getLogger().setLevel(Level.WARNING);
|
||||
cserver.addSncpServlet(cservice);
|
||||
cserver.init(DefaultAnyValue.create("port", 5577));
|
||||
cserver.init(AnyValueWriter.create("port", 5577));
|
||||
cserver.start();
|
||||
|
||||
//------------------------ 初始化 BCService ------------------------------------
|
||||
@@ -72,7 +71,7 @@ public class ABMainService implements Service {
|
||||
bcserver.getResourceFactory().register(application);
|
||||
//bcserver.getLogger().setLevel(Level.WARNING);
|
||||
bcserver.addSncpServlet(bcservice);
|
||||
bcserver.init(DefaultAnyValue.create("port", 5588));
|
||||
bcserver.init(AnyValueWriter.create("port", 5588));
|
||||
bcserver.start();
|
||||
|
||||
//------------------------ 初始化 ABMainService ------------------------------------
|
||||
@@ -91,7 +90,7 @@ public class ABMainService implements Service {
|
||||
server.getResourceFactory().register(application);
|
||||
//server.getLogger().setLevel(Level.WARNING);
|
||||
|
||||
server.init(DefaultAnyValue.create("port", abport));
|
||||
server.init(AnyValueWriter.create("port", abport));
|
||||
server.addRestServlet(null, service, null, HttpServlet.class, "/pipes");
|
||||
server.start();
|
||||
Thread.sleep(100);
|
||||
@@ -140,7 +139,7 @@ public class ABMainService implements Service {
|
||||
|
||||
server.addRestServlet(null, service, null, HttpServlet.class, "/pipes");
|
||||
|
||||
server.init(DefaultAnyValue.create("port", "" + abport));
|
||||
server.init(AnyValueWriter.create("port", "" + abport));
|
||||
server.start();
|
||||
Thread.sleep(100);
|
||||
|
||||
|
||||
@@ -29,6 +29,6 @@ public class TestService implements Service {
|
||||
SncpServer cserver = new SncpServer();
|
||||
cserver.getResourceFactory().register(application);
|
||||
cserver.addSncpServlet(new TestService());
|
||||
cserver.init(AnyValue.DefaultAnyValue.create("port", 5577));
|
||||
cserver.init(AnyValueWriter.create("port", 5577));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class SncpSleepTest {
|
||||
SncpServer server = new SncpServer(application, System.currentTimeMillis(), null, resFactory);
|
||||
server.getResourceFactory().register(application);
|
||||
server.addSncpServlet(service);
|
||||
server.init(AnyValue.DefaultAnyValue.create("port", 0));
|
||||
server.init(AnyValueWriter.create("port", 0));
|
||||
server.start();
|
||||
|
||||
int port = server.getSocketAddress().getPort();
|
||||
|
||||
@@ -167,7 +167,7 @@ public class SncpTest {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||
AnyValueWriter conf = new AnyValueWriter();
|
||||
conf.addValue("host", "0.0.0.0");
|
||||
conf.addValue("port", "" + port);
|
||||
conf.addValue("protocol", protocol);
|
||||
@@ -206,7 +206,7 @@ public class SncpTest {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||
AnyValueWriter conf = new AnyValueWriter();
|
||||
conf.addValue("host", "0.0.0.0");
|
||||
conf.addValue("port", "" + (port2 < 10 ? 0 : port2));
|
||||
conf.addValue("protocol", protocol);
|
||||
|
||||
@@ -7,12 +7,11 @@ package org.redkale.test.source;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.persistence.Column;
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -63,7 +62,7 @@ public class JsonRecord {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
DefaultAnyValue conf = DefaultAnyValue.create();
|
||||
AnyValueWriter conf = AnyValueWriter.create();
|
||||
conf.addValue("name", "");
|
||||
conf.addValue("url", "jdbc:mysql://localhost:3306/center?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true");
|
||||
conf.addValue("user", "root");
|
||||
|
||||
@@ -5,7 +5,7 @@ package org.redkale.test.util;
|
||||
import java.util.Properties;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -110,7 +110,7 @@ public class AnyValuePropertiesTest {
|
||||
|
||||
@Test
|
||||
public void run3() {
|
||||
DefaultAnyValue conf = AnyValue.create();
|
||||
AnyValueWriter conf = AnyValue.create();
|
||||
conf.addValue("name", "haha");
|
||||
conf.addValue("value", AnyValue.create().addValue("id", 1234).addValue("key", (String) null).addValue("desc", "nothing !!!"));
|
||||
String json = "{\"name\":\"haha\",\"value\":{\"id\":\"1234\",\"key\":null,\"desc\":\"nothing !!!\"}}";
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
*/
|
||||
package org.redkale.test.websocket;
|
||||
|
||||
import org.redkale.net.http.WebServlet;
|
||||
import org.redkale.net.http.WebSocketServlet;
|
||||
import org.redkale.net.http.HttpRequest;
|
||||
import org.redkale.net.http.WebSocket;
|
||||
import org.redkale.net.http.HttpServer;
|
||||
import org.redkale.util.TypeToken;
|
||||
import org.redkale.util.AnyValue;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import org.redkale.net.http.HttpRequest;
|
||||
import org.redkale.net.http.HttpServer;
|
||||
import org.redkale.net.http.WebServlet;
|
||||
import org.redkale.net.http.WebSocket;
|
||||
import org.redkale.net.http.WebSocketServlet;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
import org.redkale.util.TypeToken;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -108,7 +108,7 @@ public class VideoWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
CountDownLatch cdl = new CountDownLatch(1);
|
||||
AnyValue.DefaultAnyValue config = AnyValue.create()
|
||||
AnyValueWriter config = AnyValueWriter.create()
|
||||
.addValue("threads", System.getProperty("threads"))
|
||||
.addValue("bufferPoolSize", System.getProperty("bufferPoolSize"))
|
||||
.addValue("responsePoolSize", System.getProperty("responsePoolSize"))
|
||||
|
||||
Reference in New Issue
Block a user