You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2022/11/08 10:57:29 UTC
[syncope] 02/02: [SYNCOPE-1697] Better support to find actual CommandArgs class
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git
commit 846bfbf3abf430564edf3c3d87b9e5f7087194c3
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Tue Nov 8 11:57:16 2022 +0100
[SYNCOPE-1697] Better support to find actual CommandArgs class
---
.../implementation/ImplementationManager.java | 31 ++++++++++++++++++----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/core/spring/src/main/java/org/apache/syncope/core/spring/implementation/ImplementationManager.java b/core/spring/src/main/java/org/apache/syncope/core/spring/implementation/ImplementationManager.java
index ef93c05cf1..ea8e1455a3 100644
--- a/core/spring/src/main/java/org/apache/syncope/core/spring/implementation/ImplementationManager.java
+++ b/core/spring/src/main/java/org/apache/syncope/core/spring/implementation/ImplementationManager.java
@@ -21,6 +21,7 @@ package org.apache.syncope.core.spring.implementation;
import groovy.lang.GroovyClassLoader;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -35,6 +36,7 @@ import org.apache.syncope.common.lib.policy.PullCorrelationRuleConf;
import org.apache.syncope.common.lib.policy.PushCorrelationRuleConf;
import org.apache.syncope.common.lib.report.ReportletConf;
import org.apache.syncope.common.lib.types.IdRepoImplementationType;
+import org.apache.syncope.common.lib.types.ImplementationTypesHolder;
import org.apache.syncope.core.persistence.api.ImplementationLookup;
import org.apache.syncope.core.persistence.api.dao.AccountRule;
import org.apache.syncope.core.persistence.api.dao.PasswordRule;
@@ -184,6 +186,26 @@ public final class ImplementationManager {
}
}
+ @SuppressWarnings("unchecked")
+ private static Class<? extends CommandArgs> findCommandArgsClass(final Type type) {
+ if (type.getTypeName().startsWith(
+ ImplementationTypesHolder.getInstance().getValues().get(IdRepoImplementationType.COMMAND) + "<")) {
+
+ return (Class<? extends CommandArgs>) ((ParameterizedType) type).getActualTypeArguments()[0];
+ }
+
+ if (type instanceof Class) {
+ for (Type i : ((Class) type).getGenericInterfaces()) {
+ Class<? extends CommandArgs> r = findCommandArgsClass(i);
+ if (r != null) {
+ return r;
+ }
+ }
+ }
+
+ return null;
+ }
+
public static CommandArgs emptyArgs(final Implementation impl) throws Exception {
if (!IdRepoImplementationType.COMMAND.equals(impl.getType())) {
throw new IllegalArgumentException("This method can be only called on implementations");
@@ -191,12 +213,11 @@ public final class ImplementationManager {
Class<Object> commandClass = getClass(impl).getLeft();
- @SuppressWarnings("unchecked")
- Class<? extends CommandArgs> commandArgsClass =
- (Class<? extends CommandArgs>) (((ParameterizedType) commandClass.getGenericInterfaces()[0]).
- getActualTypeArguments()[0]);
+ Class<? extends CommandArgs> commandArgsClass = findCommandArgsClass(commandClass);
+ if (commandArgsClass != null
+ && (commandArgsClass.getEnclosingClass() == null
+ || Modifier.isStatic(commandArgsClass.getModifiers()))) {
- if (commandArgsClass.getEnclosingClass() == null || Modifier.isStatic(commandArgsClass.getModifiers())) {
return commandArgsClass.getDeclaredConstructor().newInstance();
}