Example usage for org.apache.commons.lang ClassUtils getAllSuperclasses

List of usage examples for org.apache.commons.lang ClassUtils getAllSuperclasses

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils getAllSuperclasses.

Prototype

public static List<Class<?>> getAllSuperclasses(Class<?> cls) 

Source Link

Document

Gets a List of superclasses for the given class.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    System.out//from w  w  w.  j av  a2 s . c  o m
            .println("2) SuperClasses of java.lang.String >>> " + ClassUtils.getAllSuperclasses(String.class));

}

From source file:ClassUtilsTrial.java

public static void main(String[] args) {
    System.out.println(//from   w  w w  .  j a  v  a 2 s . co  m
            "1) Interfaces implemented by java.lang.String >>> " + ClassUtils.getAllInterfaces(String.class));
    System.out
            .println("2) SuperClasses of java.lang.String >>> " + ClassUtils.getAllSuperclasses(String.class));
    System.out.println("3) PackageName of a string >>> " + ClassUtils.getPackageName("A String", "IfNull"));
    System.out.println("4) Every String is an Object = " + ClassUtils.isAssignable(String.class, Object.class));
    System.out.println("5) Every Object is an String = " + ClassUtils.isAssignable(Object.class, String.class));
}

From source file:com.ggasoftware.uitest.utils.ReporterNGExt.java

/**
 * Get element level for log./*from ww  w.  jav  a 2  s.  co m*/
 *
 * @param element - element to get level
 * @return log level (ReporterNG.BUSINESS_LEVEL, ReporterNG.COMPONENT_LEVEL or ReporterNG.TECHNICAL_LEVEL)
 */
//TODO Improve this method
private static char getLogLevel(Object element) {
    if (ClassUtils.getPackageName(element.getClass()).contains(".panel")) {
        return COMPONENT_LEVEL;
    } else if (ClassUtils.getAllSuperclasses(element.getClass()).contains(TestBaseWebDriver.class)) {
        return BUSINESS_LEVEL;
    }
    return TECHNICAL_LEVEL;
}

From source file:cn.fql.utility.ClassUtility.java

/**
 * Return is one class implements a class or extends a class
 *
 * @param currClass  current class/*from  ww w. j av  a2 s. c  o m*/
 * @param superClass the super class or interface
 * @return the result
 */
public static boolean isRelationClass(Class currClass, Class superClass) {
    boolean result = false;
    if (currClass != null) {
        if (currClass.equals(superClass)) {
            result = true;
        } else {
            // find in interface
            Class[] interfaces = currClass.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                Class currInterface = interfaces[i];
                if (currInterface.equals(superClass)) {
                    result = true;
                }
            }

            if (!result) {
                //find in superclass
                if (currClass.equals(Object.class)) {
                    result = false;
                } else {
                    List superClasses = ClassUtils.getAllSuperclasses(currClass);
                    if (!CollectionUtils.isEmpty(superClasses)) {
                        Class currSuperClass = (Class) superClasses.get(0);
                        if (currSuperClass == null) {
                            System.out.println("Super Class is null");
                            result = false;
                        } else {
                            result = isRelationClass(currSuperClass, superClass);
                        }
                    }
                }
            }
        }
    }
    return result;
}

From source file:com.haulmont.cuba.gui.CompanionDependencyInjector.java

public void inject() {
    Map<AnnotatedElement, Class> toInject = new HashMap<>();

    @SuppressWarnings("unchecked")
    List<Class> classes = ClassUtils.getAllSuperclasses(companion.getClass());
    classes.add(0, companion.getClass());
    Collections.reverse(classes);

    for (Field field : getAllFields(classes)) {
        Class aClass = injectionAnnotation(field);
        if (aClass != null) {
            toInject.put(field, aClass);
        }// w w  w .  j  av  a 2s .  co  m
    }
    for (Method method : companion.getClass().getMethods()) {
        Class aClass = injectionAnnotation(method);
        if (aClass != null) {
            toInject.put(method, aClass);
        }
    }

    for (Map.Entry<AnnotatedElement, Class> entry : toInject.entrySet()) {
        doInjection(entry.getKey(), entry.getValue());
    }
}

From source file:de.Keyle.MyPet.api.util.service.ServiceManager.java

@SuppressWarnings("unchecked")
private void registerService(ServiceContainer service) {
    boolean genericService = true;
    for (Object o : ClassUtils.getAllInterfaces(service.getClass())) {
        if (o != ServiceContainer.class && ServiceContainer.class.isAssignableFrom((Class) o)) {
            services.put((Class) o, service);
            genericService = false;/* w  w  w .  j ava 2 s  .  com*/
        }
    }
    for (Object o : ClassUtils.getAllSuperclasses(service.getClass())) {
        if (o != ServiceContainer.class && ServiceContainer.class.isAssignableFrom((Class) o)) {
            services.put((Class) o, service);
            genericService = false;
        }
    }
    if (genericService) {
        services.put(ServiceContainer.class, service);
    }
    serviceByName.put(service.getServiceName(), service);
    services.put(service.getClass(), service);
}

From source file:net.sf.maltcms.chromaui.project.spi.nodes.DescriptorNode.java

@Override
public Action[] getActions(boolean context) {
    List<?> interfaces = ClassUtils.getAllInterfaces(getBean().getClass());
    List<?> superClasses = ClassUtils.getAllSuperclasses(getBean().getClass());
    LinkedHashSet<Action> descriptorActions = new LinkedHashSet<>();
    for (Object o : interfaces) {
        Class<?> c = (Class) o;
        descriptorActions.addAll(Utilities.actionsForPath("Actions/DescriptorNodeActions/" + c.getName()));
        descriptorActions//from   ww w.j av a 2s.co m
                .addAll(Utilities.actionsForPath("Actions/DescriptorNodeActions/" + c.getSimpleName()));
    }
    for (Object o : superClasses) {
        Class<?> c = (Class) o;
        descriptorActions.addAll(Utilities.actionsForPath("Actions/DescriptorNodeActions/" + c.getName()));
        descriptorActions
                .addAll(Utilities.actionsForPath("Actions/DescriptorNodeActions/" + c.getSimpleName()));
    }
    descriptorActions.addAll(
            Utilities.actionsForPath("Actions/DescriptorNodeActions/" + getBean().getClass().getName()));
    descriptorActions.addAll(
            Utilities.actionsForPath("Actions/DescriptorNodeActions/" + getBean().getClass().getSimpleName()));
    descriptorActions.add(null);
    descriptorActions.addAll(Utilities.actionsForPath("Actions/DescriptorNodeActions/DefaultActions"));
    descriptorActions.add(SystemAction.get(PropertiesAction.class));
    return descriptorActions.toArray(new Action[descriptorActions.size()]);
}

From source file:com.haulmont.cuba.gui.ControllerDependencyInjector.java

public void inject() {
    Map<AnnotatedElement, Class> toInject = new HashMap<>();

    @SuppressWarnings("unchecked")
    List<Class> classes = ClassUtils.getAllSuperclasses(frame.getClass());
    classes.add(0, frame.getClass());//from  w w  w.  j av  a2  s.  com
    Collections.reverse(classes);

    for (Field field : getAllFields(classes)) {
        Class aClass = injectionAnnotation(field);
        if (aClass != null) {
            toInject.put(field, aClass);
        }
    }
    for (Method method : frame.getClass().getMethods()) {
        Class aClass = injectionAnnotation(method);
        if (aClass != null) {
            toInject.put(method, aClass);
        }
    }

    for (Map.Entry<AnnotatedElement, Class> entry : toInject.entrySet()) {
        doInjection(entry.getKey(), entry.getValue());
    }

    injectEventListeners(frame);
}

From source file:com.blurengine.blur.framework.ticking.TickMethodsCache.java

private static TickMethod getTickMethod(Class clazz, Method method) {
    // Order of list is from bottom (subclass) to top (superclass).
    List<Class> superclasses = (List<Class>) ClassUtils.getAllSuperclasses(clazz);
    superclasses.add(0, clazz);// ww w .ja v  a2s  . co  m
    // Loop over clazz and its superclasses
    for (Class superclass : superclasses) {
        // find and iterate over the current class' tick methods, if it has any.
        for (TickMethod tickMethod : CLASS_TICK_METHODS.get(superclass)) {
            // if the superclass TickMethod has the same method as ours, return it.
            if (ReflectionUtils.sameMethodSignature(method, tickMethod.method)) {
                return tickMethod;
            }
        }
    }
    return null;
}

From source file:fr.exanpe.t5.lib.internal.authorize.AuthorizePageFilter.java

/**
 * Look for an {@link Authorize} annotation in the Page class or superclass
 * /*from   ww w .j a  v a  2  s .c  o m*/
 * @param pageName the name of the page
 * @return the annotation found, or null
 */
@SuppressWarnings("unchecked")
private Authorize process(String pageName) {
    Component page = componentSource.getPage(pageName);

    Authorize auth = null;

    if ((auth = process(page.getClass())) != null) {
        return auth;
    }

    // handle inheritance
    for (Class<?> c : (List<Class<?>>) ClassUtils.getAllSuperclasses(page.getClass())) {
        if ((auth = process(c)) != null) {
            return auth;
        }
    }

    // handle inheritance
    for (Class<?> c : (List<Class<?>>) ClassUtils.getAllInterfaces(page.getClass())) {
        if ((auth = process(c)) != null) {
            return auth;
        }
    }

    return auth;
}