Java Code Examples for org.apache.commons.lang3.ClassUtils#getAllSuperclasses()

The following examples show how to use org.apache.commons.lang3.ClassUtils#getAllSuperclasses() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractRunMojo.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Method to check if the Launcher is {@link AbstractRunMojo#IO_VERTX_CORE_LAUNCHER} or instance of
 * {@code io.vertx.core.Launcher}
 *
 * @param launcher - the launcher class as string that needs to be checked
 * @return true if its {@link AbstractRunMojo#IO_VERTX_CORE_LAUNCHER} or instance of
 * {@code io.vertx.core.Launcher}
 * @throws MojoExecutionException - any error that might occur while checking
 */
boolean isVertxLauncher(String launcher) throws MojoExecutionException {
    if (launcher != null) {
        if (IO_VERTX_CORE_LAUNCHER.equals(launcher)) {
            return true;
        } else {
            try {
                Class customLauncher = buildClassLoader(getClassPathUrls()).loadClass(launcher);
                List<Class<?>> superClasses = ClassUtils.getAllSuperclasses(customLauncher);
                return lookupForLauncherInClassHierarchy(superClasses);
            } catch (ClassNotFoundException e) {
                getLog().error("Unable to load the class " + launcher, e);
                throw new MojoExecutionException("Class \"" + launcher + "\" not found");
            }
        }
    } else {
        return false;
    }
}
 
Example 2
Source File: JPAAnyUtils.java    From syncope with Apache License 2.0 6 votes vote down vote up
private static void initFieldNames(final Class<?> entityClass, final Map<String, Field> fields) {
    List<Class<?>> classes = ClassUtils.getAllSuperclasses(entityClass);
    classes.add(entityClass);
    classes.forEach(clazz -> {
        for (Field field : clazz.getDeclaredFields()) {
            if (!Modifier.isStatic(field.getModifiers())
                    && !field.getName().startsWith("pc")
                    && !Collection.class.isAssignableFrom(field.getType())
                    && !Map.class.isAssignableFrom(field.getType())) {

                fields.put(field.getName(), field);
                if ("id".equals(field.getName())) {
                    fields.put("key", field);
                }
            }
        }
    });
}
 
Example 3
Source File: AbstractRunMojo.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Method to check if the Launcher is {@link AbstractRunMojo#IO_VERTX_CORE_LAUNCHER} or instance of
 * {@code io.vertx.core.Launcher}
 *
 * @param launcher - the launcher class as string that needs to be checked
 * @return true if its {@link AbstractRunMojo#IO_VERTX_CORE_LAUNCHER} or instance of
 * {@code io.vertx.core.Launcher}
 * @throws MojoExecutionException - any error that might occur while checking
 */
protected boolean isVertxLauncher(String launcher) throws MojoExecutionException {
    if (launcher != null) {
        if (IO_VERTX_CORE_LAUNCHER.equals(launcher)) {
            return true;
        } else {
            try {
                Class customLauncher = buildClassLoader(getClassPathUrls()).loadClass(launcher);
                List<Class<?>> superClasses = ClassUtils.getAllSuperclasses(customLauncher);
                boolean isAssignable = false;
                if (superClasses != null) {
                    for (Class<?> superClass : superClasses) {
                        if (IO_VERTX_CORE_LAUNCHER.equals(superClass.getName())) {
                            isAssignable = true;
                            break;
                        }
                    }
                }
                return isAssignable;
            } catch (ClassNotFoundException e) {
                throw new MojoExecutionException("Class \"" + launcher + "\" not found");
            }
        }
    } else {
        return false;
    }
}
 
Example 4
Source File: StageDefinitionExtractor.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public static List<String> getGroups(Class klass) {
  Set<String> set = new LinkedHashSet<>();
  addGroupsToList(klass, set);
  List<Class<?>> allSuperclasses = ClassUtils.getAllSuperclasses(klass);
  for(Class<?> superClass : allSuperclasses) {
    if(!superClass.isInterface() && superClass.isAnnotationPresent(ConfigGroups.class)) {
      addGroupsToList(superClass, set);
    }
  }
  if(set.isEmpty()) {
    set.add(""); // the default empty group
  }

  return new ArrayList<>(set);
}
 
Example 5
Source File: ClassUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 递归返回所有的SupperClasses,包含Object.class
 */
public static List<Class<?>> getAllSuperclasses(final Class<?> cls) {
	return ClassUtils.getAllSuperclasses(cls);
}
 
Example 6
Source File: ClassUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 递归返回所有的SupperClasses,包含Object.class
 */
public static List<Class<?>> getAllSuperclasses(final Class<?> cls) {
	return ClassUtils.getAllSuperclasses(cls);
}
 
Example 7
Source File: HelpLanguageManager.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override public ICompatibilityChecker getChecker() {
    return new ICompatibilityChecker() {
        @Override public boolean isCompatible(Method method) {
            int modifiers = method.getModifiers();

            if (!Modifier.isPublic(modifiers) || !method.isAnnotationPresent(ActionMethod.class)) {
                return false;
            }

            Class<?>[] parameterTypes = method.getParameterTypes();

            if (parameterTypes.length != 1 && parameterTypes.length != 2) {
                return false;
            }

            if (!IActionContext.class.isAssignableFrom(parameterTypes[0])) {
                return false;
            }

            if (parameterTypes.length == 2) {

                if (IMessage.class.isAssignableFrom(parameterTypes[1])) {
                    return method.isAnnotationPresent(MessageDirection.class);
                }

                List<Class<?>> superClasses = ClassUtils.getAllSuperclasses(parameterTypes[1]);

                boolean isBaseMessage = BaseMessage.class.isAssignableFrom(parameterTypes[1]);

                boolean isFixMessage = superClasses.size() >= 2 && "quickfix.Message".equals(superClasses.get(1).getCanonicalName());

                //noinspection SimplifiableIfStatement
                if ((isBaseMessage || isFixMessage) && method.isAnnotationPresent(MessageDirection.class)) {
                    return false;
                }

                return isBaseMessage || isFixMessage || HashMap.class.isAssignableFrom(parameterTypes[1]);
            }

            return true;
        }
    };
}
 
Example 8
Source File: ClassUtil.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
/**
 * 递归返回所有的SupperClasses,包含Object.class
 */
public static List<Class<?>> getAllSuperclasses(final Class<?> cls) {
	return ClassUtils.getAllSuperclasses(cls);
}