Example usage for java.lang Class getInterfaces

List of usage examples for java.lang Class getInterfaces

Introduction

In this page you can find the example usage for java.lang Class getInterfaces.

Prototype

public Class<?>[] getInterfaces() 

Source Link

Document

Returns the interfaces directly implemented by the class or interface represented by this object.

Usage

From source file:org.apache.openjpa.eclipse.util.PCEnhancerHelperTest.java

public void todotestEnhanceFile() throws Exception {
    String className = "TestEntity";

    URL[] urls = new URL[] { targetDir.toURI().toURL() };
    ClassLoader classLoader = new URLClassLoader(urls);
    PCEnhancerHelper eh = new PCEnhancerHelperImpl(classLoader);
    boolean r = checkEnhance(eh, className);
    Assert.assertTrue(r); // was enhanced..

    // Reset/re-initialize classLoader, to freshly load and check the enhanced class
    classLoader = new URLClassLoader(urls);
    Class<?> testClass = classLoader.loadClass(classPackage + className);
    Assert.assertNotNull(testClass);/*from  w  w  w  . j  a va 2s .c  o  m*/
    Assert.assertEquals(1, testClass.getInterfaces().length);
    Assert.assertTrue(testClass.getInterfaces()[0].equals(PersistenceCapable.class));
}

From source file:com.github.philippn.springremotingautoconfigure.server.annotation.HttpInvokerServiceExporterRegistrar.java

@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    for (String beanName : registry.getBeanDefinitionNames()) {
        BeanDefinition definition = registry.getBeanDefinition(beanName);
        if (definition.getBeanClassName() != null) {
            try {
                Class<?> resolvedClass = ClassUtils.forName(definition.getBeanClassName(), null);
                Class<?>[] beanInterfaces = resolvedClass.getInterfaces();
                for (Class<?> clazz : beanInterfaces) {
                    if (AnnotationUtils.isAnnotationDeclaredLocally(RemoteExport.class, clazz)) {
                        setupExport(clazz, beanName, registry);
                    }// w w  w.j  a v a  2 s  .  c o  m
                }
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException("Unable to inspect class " + definition.getBeanClassName()
                        + " for @RemoteExport annotations");
            }
        }
    }
}

From source file:com.google.code.rees.scope.spring.SpringConversationArbitrator.java

@Override
protected Set<Class<?>> getConversationControllers(Class<?> clazz) {
    Set<Class<?>> annotatedClasses = new HashSet<Class<?>>();
    for (Class<?> clazzClass : clazz.getInterfaces()) {
        if (clazzClass.isAnnotationPresent(ConversationController.class) || clazzClass
                .isAnnotationPresent(com.google.code.rees.scope.spring.ConversationController.class)) {
            annotatedClasses.add(clazzClass);
        }/*from   w w w  .j a  v  a2s.c  o m*/
    }
    if (clazz.isAnnotationPresent(ConversationController.class)
            || clazz.isAnnotationPresent(com.google.code.rees.scope.spring.ConversationController.class)) {
        annotatedClasses.add(clazz);
    }
    Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        annotatedClasses.addAll(getConversationControllers(superClass));
    }
    return annotatedClasses;
}

From source file:org.vbossica.springbox.annotation.AnnotatedMethodResolver.java

/**
 * Traverses the {@code bean} in search for annotated methods. Calls the
 * {@link #doWithAnnotatedMethod(String, Object, Method, Annotation)} for every method found.
 *
 * @param beanName the name of the Spring bean
 * @param bean the Spring bean itself//from w  w  w  . ja  v a  2  s .co m
 * @see #doWithAnnotatedMethod(String, Object, java.lang.reflect.Method, java.lang.annotation.Annotation)
 */
public void traverse(final String beanName, final Object bean) {
    logger.info("traversing bean " + beanName);

    Class<?> handlerType = bean.getClass();

    Class<?>[] handlerTypes = Proxy.isProxyClass(handlerType) ? handlerType.getInterfaces()
            : new Class<?>[] { handlerType };
    for (final Class<?> currentHandlerType : handlerTypes) {
        ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) {
                Method specificMethod = ClassUtils.getMostSpecificMethod(method, currentHandlerType);
                A annotation = AnnotationUtils.findAnnotation(method, annotationClass);
                if (annotation != null) {
                    doWithAnnotatedMethod(beanName, bean, specificMethod, annotation);
                }
            }
        }, ReflectionUtils.NON_BRIDGED_METHODS);
    }
}

From source file:com.tmind.framework.pub.utils.MethodUtils.java

/**
 * <p>Return an accessible method (that is, one that can be invoked via
 * reflection) that implements the specified method, by scanning through
 * all implemented interfaces and subinterfaces.  If no such method
 * can be found, return <code>null</code>.</p>
 *
 * <p> There isn't any good reason why this method must be private.
 * It is because there doesn't seem any reason why other classes should
 * call this rather than the higher level methods.</p>
 *
 * @param clazz Parent class for the interfaces to be checked
 * @param methodName Method name of the method we wish to call
 * @param parameterTypes The parameter type signatures
 *//*from  ww w  .j a v  a 2 s.c  o  m*/
private static Method getAccessibleMethodFromInterfaceNest(Class clazz, String methodName,
        Class parameterTypes[]) {

    Method method = null;

    // Search up the superclass chain
    for (; clazz != null; clazz = clazz.getSuperclass()) {

        // Check the implemented interfaces of the parent class
        Class interfaces[] = clazz.getInterfaces();
        for (int i = 0; i < interfaces.length; i++) {

            // Is this interface public?
            if (!Modifier.isPublic(interfaces[i].getModifiers()))
                continue;

            // Does the method exist on this interface?
            try {
                method = interfaces[i].getDeclaredMethod(methodName, parameterTypes);
            } catch (NoSuchMethodException e) {
                ;
            }
            if (method != null)
                break;

            // Recursively check our parent interfaces
            method = getAccessibleMethodFromInterfaceNest(interfaces[i], methodName, parameterTypes);
            if (method != null)
                break;

        }

    }

    // If we found a method return it
    if (method != null)
        return (method);

    // We did not find anything
    return (null);

}

From source file:org.ff4j.aop.FeatureAutoProxy.java

/** {@inheritDoc} */
@Override//from   w w w  .  j ava 2  s  . co m
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName,
        TargetSource targetSource) {
    // Scan interface only once.
    if (!beanClass.isInterface() && beanClass.getInterfaces() != null) {
        // Get Interface
        for (Class<?> currentInterface : beanClass.getInterfaces()) {
            Object[] r = addAnnotedInterface(currentInterface);
            if (r != null) {
                return r;
            }
        }
    }
    return DO_NOT_PROXY;
}

From source file:de.taimos.dvalin.jaxrs.swagger.SwaggerScanner.java

private boolean hasAnnotation(Class<?> clz, Class<? extends Annotation> ann) {
    if (clz.isAnnotationPresent(ann)) {
        return true;
    }// w w  w.j av a 2s  .co  m
    for (Class<?> iface : clz.getInterfaces()) {
        if (this.hasAnnotation(iface, ann)) {
            return true;
        }
    }
    return (clz.getSuperclass() != null) && this.hasAnnotation(clz.getSuperclass(), ann);
}

From source file:org.apache.openaz.pepapi.std.StdMapperRegistry.java

private ObjectMapper getClassMapper(Class<?> clazz) {
    ObjectMapper mapper = map.get(clazz);
    if (mapper == null) {
        Class<?>[] interfaces = clazz.getInterfaces();
        if (interfaces != null && interfaces.length > 0) {
            for (Class<?> inf : interfaces) {
                mapper = map.get(inf);/*from  w w  w .ja  va2s  .  c o  m*/
                if (mapper != null) {
                    break;
                }
            }
        }
    }
    return mapper;
}

From source file:com.ixcode.framework.javabean.format.JavaBeanFormatter.java

private IJavaBeanValueFormat searchInterfaces(Class valueClass, Locale locale) {
    Class[] ifcs = valueClass.getInterfaces();
    IJavaBeanValueFormat format = null;// ww  w . ja  va 2s .  c om
    for (int i = 0; (i < ifcs.length) && (format == null); ++i) {
        Class ifc = ifcs[i];
        format = searchClasses(ifc, locale);
    }
    return format;
}

From source file:com.jeeframework.util.classes.ClassUtils.java

/**
 * Return all interfaces that the given class implements as array,
 * including ones implemented by superclasses.
 * <p>If the class itself is an interface, it gets returned as sole interface.
 * @param clazz the class to analyse for interfaces
 * @param classLoader the ClassLoader that the interfaces need to be visible in
 * (may be <code>null</code> when accepting all declared interfaces)
 * @return all interfaces that the given object implements as array
 */// w  ww  . j  a v a 2  s.  co  m
public static Class[] getAllInterfacesForClass(Class clazz, ClassLoader classLoader) {
    Assert.notNull(clazz, "Class must not be null");
    if (clazz.isInterface()) {
        return new Class[] { clazz };
    }
    List interfaces = new ArrayList();
    while (clazz != null) {
        for (int i = 0; i < clazz.getInterfaces().length; i++) {
            Class ifc = clazz.getInterfaces()[i];
            if (!interfaces.contains(ifc) && (classLoader == null || isVisible(ifc, classLoader))) {
                interfaces.add(ifc);
            }
        }
        clazz = clazz.getSuperclass();
    }
    return (Class[]) interfaces.toArray(new Class[interfaces.size()]);
}