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