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

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

Introduction

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

Prototype

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

Source Link

Document

Gets a List of all interfaces implemented by the given class and its superclasses.

The order is determined by looking through each interface in turn as declared in the source file and following its hierarchy up.

Usage

From source file:org.pentaho.di.ui.core.dialog.DisplayInvocationHandler.java

@SuppressWarnings("unchecked")
public static <T> T forObject(Class<T> iface, T delegate, Display display, LogChannelInterface log,
        boolean asyncForVoid) {
    return (T) Proxy.newProxyInstance(delegate.getClass().getClassLoader(),
            (Class<?>[]) ClassUtils.getAllInterfaces(delegate.getClass()).toArray(new Class<?>[] {}),
            new DisplayInvocationHandler<T>(display, delegate, log, asyncForVoid));
}

From source file:org.pentaho.di.ui.repo.controller.RepositoryConnectController.java

@SuppressWarnings("unchecked")
private Repository wrapWithRepositoryTimeoutHandler(ReconnectableRepository repository) {
    List<Class<?>> repositoryIntrerfaces = ClassUtils.getAllInterfaces(repository.getClass());
    Class<?>[] repositoryIntrerfacesArray = repositoryIntrerfaces
            .toArray(new Class<?>[repositoryIntrerfaces.size()]);
    return (Repository) Proxy.newProxyInstance(repository.getClass().getClassLoader(),
            repositoryIntrerfacesArray, new RepositorySessionTimeoutHandler(repository, this));
}

From source file:org.pentaho.di.ui.repo.RepositorySessionTimeoutHandler.java

@SuppressWarnings("unchecked")
static <T> T wrapObjectWithTimeoutHandler(T objectToWrap, InvocationHandler timeoutHandler) {
    List<Class<?>> objectIntrerfaces = ClassUtils.getAllInterfaces(objectToWrap.getClass());
    Class<?>[] objectIntrerfacesArray = objectIntrerfaces.toArray(new Class<?>[objectIntrerfaces.size()]);
    return (T) Proxy.newProxyInstance(objectToWrap.getClass().getClassLoader(), objectIntrerfacesArray,
            timeoutHandler);//w  ww . ja v  a 2  s  . c  o  m
}

From source file:org.pentaho.platform.engine.core.system.objfac.spring.BeanPublishParser.java

@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder beanDefinitionHolder,
        ParserContext parserContext) {//from   w w w . j  a  v  a  2s . co  m

    String publishType = null;
    String beanClassName;

    // If this is a republish of a pen:bean, the class will be a FactoryBean and the actual class returned back the
    // factory will be stored as an attribute.
    if (beanDefinitionHolder.getBeanDefinition().getAttribute("originalClassName") != null) {
        beanClassName = beanDefinitionHolder.getBeanDefinition().getAttribute("originalClassName").toString();
    } else {
        beanClassName = beanDefinitionHolder.getBeanDefinition().getBeanClassName();
    }

    if (node.getAttributes().getNamedItem(ATTR) != null) { // publish as type if specified
        publishType = node.getAttributes().getNamedItem(ATTR).getNodeValue();
    } else { // fallback to publish as itself
        publishType = beanClassName;
    }

    // capture the "ID" of the bean as an attribute so it can be queried for
    beanDefinitionHolder.getBeanDefinition().setAttribute("id", beanDefinitionHolder.getBeanName());
    NodeList nodes = node.getChildNodes();

    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        if (stripNamespace(n.getNodeName()).equals(Const.ATTRIBUTES)) {
            NodeList attrnodes = n.getChildNodes();

            for (int y = 0; y < attrnodes.getLength(); y++) {
                Node an = attrnodes.item(y);
                if (stripNamespace(an.getNodeName()).equals(Const.ATTR)) {
                    beanDefinitionHolder.getBeanDefinition().setAttribute(
                            an.getAttributes().getNamedItem(Const.KEY).getNodeValue(),
                            an.getAttributes().getNamedItem(Const.VALUE).getNodeValue());
                }
            }
        }
    }

    try {
        List<Class<?>> classesToPublish = new ArrayList<Class<?>>();

        Class<?> clazz = findClass(beanClassName);

        if (specialPublishTypes.INTERFACES.name().equals(publishType)) {
            if (clazz.isInterface()) { // publish as self if interface already (re-publish flow)
                classesToPublish.add(clazz);
            } else {
                classesToPublish.addAll(ClassUtils.getAllInterfaces(clazz));
            }
        } else if (specialPublishTypes.CLASSES.name().equals(publishType)) {

            classesToPublish.addAll(ClassUtils.getAllSuperclasses(clazz));
            classesToPublish.add(clazz);
        } else if (specialPublishTypes.ALL.name().equals(publishType)) {

            classesToPublish.addAll(ClassUtils.getAllInterfaces(clazz));
            classesToPublish.addAll(ClassUtils.getAllSuperclasses(clazz));
            classesToPublish.add(clazz);
        } else {
            classesToPublish.add(getClass().getClassLoader().loadClass(publishType));
        }

        String beanFactoryId = null;

        if (parserContext.getRegistry().containsBeanDefinition(Const.FACTORY_MARKER) == false) {
            beanFactoryId = UUID.randomUUID().toString();
            parserContext.getRegistry().registerBeanDefinition(Const.FACTORY_MARKER,
                    BeanDefinitionBuilder.genericBeanDefinition(Marker.class)
                            .setScope(BeanDefinition.SCOPE_PROTOTYPE).addConstructorArgValue(beanFactoryId)
                            .getBeanDefinition());
        } else {
            beanFactoryId = (String) parserContext.getRegistry().getBeanDefinition(Const.FACTORY_MARKER)
                    .getConstructorArgumentValues().getArgumentValue(0, String.class).getValue();
        }

        for (Class cls : classesToPublish) {
            PublishedBeanRegistry.registerBean(beanDefinitionHolder.getBeanName(), cls, beanFactoryId);
        }

    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Cannot find class for publish type: " + publishType
                + " specified on publish of bean id: " + beanDefinitionHolder.getBeanName(), e);
    }
    return beanDefinitionHolder;
}

From source file:org.sonar.api.utils.AnnotationUtils.java

/**
 * Searches for a class annotation. All inheritance tree is analysed.
 * /*from w w  w. j  a va2s .c  om*/
 * @since 3.1
 */
public static <A extends Annotation> A getAnnotation(Object objectOrClass, Class<A> annotationClass) {
    Class<?> initialClass = (objectOrClass instanceof Class<?> ? (Class<?>) objectOrClass
            : objectOrClass.getClass());

    for (Class<?> aClass = initialClass; aClass != null; aClass = aClass.getSuperclass()) {
        A result = aClass.getAnnotation(annotationClass);
        if (result != null) {
            return result;
        }
    }

    for (Class<?> anInterface : (List<Class<?>>) ClassUtils.getAllInterfaces(initialClass)) {
        A result = anInterface.getAnnotation(annotationClass);
        if (result != null) {
            return result;
        }
    }

    return null;
}

From source file:org.sonar.api.utils.FieldUtils2.java

/**
 * Get accessible <code>Field</code> breaking scope if requested. Superclasses/interfaces are considered.
 *
 * @param clazz       the class to reflect, must not be null
 * @param forceAccess whether to break scope restrictions using the <code>setAccessible</code> method.
 *                    <code>False</code> only matches public fields.
 *///from  w w w  .  j  ava2  s .co  m
public static List<Field> getFields(Class clazz, boolean forceAccess) {
    List<Field> result = Lists.newArrayList();
    Class c = clazz;
    while (c != null) {
        for (Field declaredField : c.getDeclaredFields()) {
            if (!Modifier.isPublic(declaredField.getModifiers())) {
                if (forceAccess) {
                    declaredField.setAccessible(true);//NOSONAR only works from sufficiently privileged code
                } else {
                    continue;
                }
            }
            result.add(declaredField);
        }
        c = c.getSuperclass();
    }

    for (Object anInterface : ClassUtils.getAllInterfaces(clazz)) {
        Collections.addAll(result, ((Class) anInterface).getDeclaredFields());
    }

    return result;
}

From source file:org.tangram.view.AbstractTemplateResolver.java

/**
 * @throws IOException - in subclasses not this one
 *//*from  w  w  w  . j  a  va 2  s.  co m*/
protected T lookupView(String viewName, Locale locale, Object content, String key) throws IOException {
    Class<? extends Object> cls = content.getClass();
    T view = null;
    Set<String> alreadyChecked = new HashSet<>();
    List<Object> allInterfaces = new ArrayList<>();
    while ((view == null) && (cls != null)) {
        String pack = (cls.getPackage() == null) ? "" : cls.getPackage().getName();
        view = checkView(viewName, pack, cls.getSimpleName(), key, locale);
        if (view == null) {
            for (Object i : ClassUtils.getAllInterfaces(cls)) {
                if (allInterfaces.contains(i)) {
                    allInterfaces.remove(i);
                } // if
            } // for
            for (Object i : ClassUtils.getAllInterfaces(cls)) {
                allInterfaces.add(i);
            } // for
        } // if
        cls = cls.getSuperclass();
    } // while
      // Walk down interfaces
    if (view == null) {
        for (Object i : allInterfaces) {
            Class<? extends Object> c = (Class<? extends Object>) i;
            LOG.debug("lookupView() type to check templates for {}", c.getName());
            if (!(alreadyChecked.contains(c.getName()))) {
                alreadyChecked.add(c.getName());
                String interfacePackage = (c.getPackage() == null) ? "" : c.getPackage().getName();
                view = checkView(viewName, interfacePackage, c.getSimpleName(), key, locale);
                if (view != null) {
                    break;
                } // if
            } // if
        } // for
    } // if
    return view;
}

From source file:org.wicketopia.mapping.ClassBasedTypeMapping.java

@SuppressWarnings("unchecked")
private Queue<Class<?>> createTypeQueue(final Class<?> originalType) {
    Queue<Class<?>> queue = new LinkedList<Class<?>>();
    Class currentType = originalType;
    do {/*from  www.  j  a v  a 2  s  .c om*/
        queue.add(currentType);
        currentType = currentType.getSuperclass();
    } while (currentType != null);
    queue.addAll(ClassUtils.getAllInterfaces(originalType));
    return queue;
}

From source file:ummisco.gama.serializer.gamaType.converters.GamaFileConverter.java

@Override
public boolean canConvert(final Class arg0) {
    final List<Class<?>> allInterfaceApa = ClassUtils.getAllInterfaces(arg0);

    for (final Object i : allInterfaceApa) {
        if (i.equals(IGamaFile.class))
            return true;
    }//  w  w  w .ja v a2 s.co  m
    return false;

    // return (arg0.equals(GamaShapeFile.class));
}

From source file:ummisco.gama.serializer.gamaType.converters.GamaGraphConverter.java

@Override
public boolean canConvert(final Class arg0) {
    final List allInterfaceApa = ClassUtils.getAllInterfaces(arg0);

    for (final Object i : allInterfaceApa) {
        if (i.equals(IGraph.class))
            return true;
    }/*from  w  ww .ja v a2 s.c o  m*/
    return false;
}