YamlReader
This commit is contained in:
@@ -42,7 +42,7 @@ module org.redkale {
|
|||||||
exports org.redkale.util;
|
exports org.redkale.util;
|
||||||
exports org.redkale.watch;
|
exports org.redkale.watch;
|
||||||
|
|
||||||
uses org.redkale.util.YmlProvider;
|
uses org.redkale.util.YamlProvider;
|
||||||
uses org.redkale.props.spi.PropertiesAgentProvider;
|
uses org.redkale.props.spi.PropertiesAgentProvider;
|
||||||
uses org.redkale.cached.spi.CachedManagerProvider;
|
uses org.redkale.cached.spi.CachedManagerProvider;
|
||||||
uses org.redkale.cluster.spi.ClusterAgentProvider;
|
uses org.redkale.cluster.spi.ClusterAgentProvider;
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ public abstract class AnyValue {
|
|||||||
* @return AnyValue
|
* @return AnyValue
|
||||||
*/
|
*/
|
||||||
public static AnyValue loadFromYml(String text) {
|
public static AnyValue loadFromYml(String text) {
|
||||||
return new YmlReader(text).read();
|
return new YamlReader(text).read();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1179,12 +1179,12 @@ public abstract class AnyValue {
|
|||||||
String key = prefix;
|
String key = prefix;
|
||||||
int index = keyPrefixs.get(key);
|
int index = keyPrefixs.get(key);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
key = parent + k + "[" + (++index) + "]";
|
key = prefix + "[" + (++index) + "]";
|
||||||
props.put(key, props.remove(prefix));
|
props.put(key, props.remove(prefix));
|
||||||
}
|
}
|
||||||
key = parent + k + "[" + (++index) + "]";
|
key = prefix + "[" + (++index) + "]";
|
||||||
while (props.containsKey(key)) {
|
while (props.containsKey(key)) {
|
||||||
key = parent + k + "[" + (++index) + "]";
|
key = prefix + "[" + (++index) + "]";
|
||||||
}
|
}
|
||||||
props.put(key, v);
|
props.put(key, v);
|
||||||
keyPrefixs.put(prefix, index);
|
keyPrefixs.put(prefix, index);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ package org.redkale.util;
|
|||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public interface YmlProvider {
|
public interface YamlProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将yml内容转换成AnyValue
|
* 将yml内容转换成AnyValue
|
||||||
@@ -20,13 +20,13 @@ import org.redkale.annotation.Nonnull;
|
|||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public class YmlReader {
|
public class YamlReader {
|
||||||
|
|
||||||
private static YmlProvider currentProvider;
|
private static YamlProvider currentProvider;
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
||||||
public YmlReader(String text) {
|
public YamlReader(String text) {
|
||||||
this.text = Objects.requireNonNull(text);
|
this.text = Objects.requireNonNull(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,22 +37,22 @@ public class YmlReader {
|
|||||||
/**
|
/**
|
||||||
* 加载解析器的实现对象
|
* 加载解析器的实现对象
|
||||||
*
|
*
|
||||||
* @return YmlProvider
|
* @return YamlProvider
|
||||||
*/
|
*/
|
||||||
private static @Nonnull YmlProvider loadProvider() {
|
protected static @Nonnull YamlProvider loadProvider() {
|
||||||
if (currentProvider == null) {
|
if (currentProvider == null) {
|
||||||
Iterator<YmlProvider> it = ServiceLoader.load(YmlProvider.class).iterator();
|
Iterator<YamlProvider> it = ServiceLoader.load(YamlProvider.class).iterator();
|
||||||
RedkaleClassLoader.putServiceLoader(YmlProvider.class);
|
RedkaleClassLoader.putServiceLoader(YamlProvider.class);
|
||||||
List<YmlProvider> providers = new ArrayList<>();
|
List<YamlProvider> providers = new ArrayList<>();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
YmlProvider provider = it.next();
|
YamlProvider provider = it.next();
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
RedkaleClassLoader.putReflectionPublicConstructors(
|
RedkaleClassLoader.putReflectionPublicConstructors(
|
||||||
provider.getClass(), provider.getClass().getName());
|
provider.getClass(), provider.getClass().getName());
|
||||||
providers.add(provider);
|
providers.add(provider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (YmlProvider provider : Utility.sortPriority(providers)) {
|
for (YamlProvider provider : Utility.sortPriority(providers)) {
|
||||||
currentProvider = provider;
|
currentProvider = provider;
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ public class YmlReader {
|
|||||||
return currentProvider;
|
return currentProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class DefaultYmlProvider implements YmlProvider {
|
protected static class DefaultYmlProvider implements YamlProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnyValue read(String content) {
|
public AnyValue read(String content) {
|
||||||
Reference in New Issue
Block a user