You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2020/03/12 08:06:14 UTC
[cxf-fediz] 01/04: fediz-core: update ConfigUtils
This is an automated email from the ASF dual-hosted git repository.
buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git
commit b0c59662a9619af425bed52fdf9d1843864406b6
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Thu Mar 5 12:09:30 2020 +0300
fediz-core: update ConfigUtils
---
.../apache/cxf/fediz/core/config/ConfigUtils.java | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/ConfigUtils.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/ConfigUtils.java
index 70b450a..2dba210 100644
--- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/ConfigUtils.java
+++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/ConfigUtils.java
@@ -43,26 +43,25 @@ final class ConfigUtils {
if (cbt.getType() == null || cbt.getType().equals(ArgumentType.STRING)) {
return cbt.getValue();
} else if (cbt.getType().equals(ArgumentType.CLASS)) {
- List<Object> handler = new ArrayList<>();
- String[] cbtHandler = cbt.getValue().split(",");
+ final String[] cbtHandler = cbt.getValue().split(",");
+ // Backward compatible return handler directly if only one is configured
+ final List<Object> handlers = cbtHandler.length == 1 ? null : new ArrayList<>(cbtHandler.length);
for (String cbh : cbtHandler) {
try {
- if (classLoader == null) {
- handler.add(ClassLoaderUtils.loadClass(cbh, ConfigUtils.class).newInstance());
+ final Object handler = (classLoader == null
+ ? ClassLoaderUtils.loadClass(cbh, ConfigUtils.class)
+ : classLoader.loadClass(cbh)).getDeclaredConstructor().newInstance();
+ if (handlers != null) {
+ handlers.add(handler);
} else {
- handler.add(classLoader.loadClass(cbh).newInstance());
+ return handler;
}
} catch (Exception e) {
LOG.error("Failed to create instance of " + cbh, e);
//throw new IllegalStateException("Failed to create instance of " + cbt.getValue());
}
}
- if (handler.size() == 1) {
- // Backward compatible return handler directly if only one is configured
- return handler.get(0);
- } else {
- return handler;
- }
+ return handlers;
} else {
LOG.error("Only String and Class are supported for '{}'", name);
throw new IllegalStateException("Only String and Class are supported for '" + name + "'");