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:com.opensymphony.xwork2.conversion.impl.XWorkConverter.java

/**
 * Recurses through a class' interfaces and class hierarchy looking for a TypeConverter in the default mapping that
 * can handle the specified class./*from   w  ww .ja v a 2  s  .c om*/
 *
 * @param clazz the class the TypeConverter must handle
 * @return a TypeConverter to handle the specified class or null if none can be found
 */
TypeConverter lookupSuper(Class clazz) {
    TypeConverter result = null;

    if (clazz != null) {
        result = converterHolder.getDefaultMapping(clazz.getName());

        if (result == null) {
            // Looks for direct interfaces (depth = 1 )
            Class[] interfaces = clazz.getInterfaces();

            for (Class anInterface : interfaces) {
                if (converterHolder.containsDefaultMapping(anInterface.getName())) {
                    result = converterHolder.getDefaultMapping(anInterface.getName());
                    break;
                }
            }

            if (result == null) {
                // Looks for the superclass
                // If 'clazz' is the Object class, an interface, a primitive type or void then clazz.getSuperClass() returns null
                result = lookupSuper(clazz.getSuperclass());
            }
        }
    }

    return result;
}

From source file:com.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java

private XmlNodeInfo getXmlNodeInfo(Class<?> type) {
    XmlNodeInfo xmlNodeInfo = new XmlNodeInfo();

    for (Class<?> i : type.getInterfaces()) {
        collectXmlNodeInfo(xmlNodeInfo, i);
    }/*w  w  w .j av  a 2s . c  o m*/
    collectXmlNodeInfo(xmlNodeInfo, type);

    if ("#className".equals(xmlNodeInfo.getNodeName())) {
        xmlNodeInfo.setNodeName(type.getSimpleName());
    }
    // if (xmlNodeInfo.getSourceTypes() == null) {
    // xmlNodeInfo = null;
    // }
    return xmlNodeInfo;
}

From source file:org.broadleafcommerce.openadmin.server.dao.provider.metadata.AbstractFieldMetadataProvider.java

protected Map<String, FieldMetadataOverride> getTargetedOverride(DynamicEntityDao dynamicEntityDao,
        String configurationKey, String ceilingEntityFullyQualifiedClassname) {
    if (metadataOverrides != null
            && (configurationKey != null || ceilingEntityFullyQualifiedClassname != null)) {
        if (metadataOverrides.containsKey(configurationKey)) {
            return metadataOverrides.get(configurationKey);
        }//  w  w  w .j  a  v a  2 s .  c  o  m
        if (metadataOverrides.containsKey(ceilingEntityFullyQualifiedClassname)) {
            return metadataOverrides.get(ceilingEntityFullyQualifiedClassname);
        }
        Class<?> test;
        try {
            test = Class.forName(ceilingEntityFullyQualifiedClassname);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        if (test.isInterface()) {
            //if it's an interface, get the least derive polymorphic concrete implementation
            Class<?>[] types = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(test);
            return metadataOverrides.get(types[types.length - 1].getName());
        } else {
            //if it's a concrete implementation, try the interfaces
            Class<?>[] types = test.getInterfaces();
            for (Class<?> type : types) {
                if (metadataOverrides.containsKey(type.getName())) {
                    return metadataOverrides.get(type.getName());
                }
            }
        }
    }
    return null;
}

From source file:org.jumpmind.db.util.CallbackClosure.java

/**
 * {@inheritDoc}//from   w  w  w  .j a v a  2  s  . c o m
 */
public void execute(Object obj) throws DdlException {
    LinkedList queue = new LinkedList();

    queue.add(obj.getClass());
    while (!queue.isEmpty()) {
        Class type = (Class) queue.removeFirst();
        Method callback = (Method) _callbacks.get(type);

        if (callback != null) {
            try {
                _parameters[_callbackTypePos] = obj;
                callback.invoke(_callee, _parameters);
                return;
            } catch (InvocationTargetException ex) {
                throw new DdlException(ex.getTargetException());
            } catch (IllegalAccessException ex) {
                throw new DdlException(ex);
            }
        }
        if ((type.getSuperclass() != null) && !type.getSuperclass().equals(Object.class)) {
            queue.add(type.getSuperclass());
        }

        Class[] baseInterfaces = type.getInterfaces();

        if (baseInterfaces != null) {
            for (int idx = 0; idx < baseInterfaces.length; idx++) {
                queue.add(baseInterfaces[idx]);
            }
        }
    }
}

From source file:com.springframework.core.annotation.AnnotationUtils.java

/**
 * Perform the search algorithm for {@link #findAnnotation(Class, Class)},
 * avoiding endless recursion by tracking which annotations have already
 * been <em>visited</em>.//from w ww  .  ja  v  a 2  s  . co m
 * @param clazz the class to look for annotations on
 * @param annotationType the type of annotation to look for
 * @param visited the set of annotations that have already been visited
 * @return the matching annotation, or {@code null} if not found
 */
@SuppressWarnings("unchecked")
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType,
        Set<Annotation> visited) {
    Assert.notNull(clazz, "Class must not be null");

    try {
        Annotation[] anns = clazz.getDeclaredAnnotations();
        for (Annotation ann : anns) {
            if (ann.annotationType().equals(annotationType)) {
                return (A) ann;
            }
        }
        for (Annotation ann : anns) {
            if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) {
                A annotation = findAnnotation(ann.annotationType(), annotationType, visited);
                if (annotation != null) {
                    return annotation;
                }
            }
        }
    } catch (Exception ex) {
        // Assuming nested Class values not resolvable within annotation attributes...
        logIntrospectionFailure(clazz, ex);
        return null;
    }

    for (Class<?> ifc : clazz.getInterfaces()) {
        A annotation = findAnnotation(ifc, annotationType, visited);
        if (annotation != null) {
            return annotation;
        }
    }

    Class<?> superclass = clazz.getSuperclass();
    if (superclass == null || superclass.equals(Object.class)) {
        return null;
    }
    return findAnnotation(superclass, annotationType, visited);
}

From source file:org.apache.ddlutils.util.CallbackClosure.java

/**
 * {@inheritDoc}/*www  .  j  ava2 s. c om*/
 */
public void execute(Object obj) throws DdlUtilsException {
    LinkedList queue = new LinkedList();

    queue.add(obj.getClass());
    while (!queue.isEmpty()) {
        Class type = (Class) queue.removeFirst();
        Method callback = (Method) _callbacks.get(type);

        if (callback != null) {
            try {
                _parameters[_callbackTypePos] = obj;
                callback.invoke(_callee, _parameters);
                return;
            } catch (InvocationTargetException ex) {
                throw new DdlUtilsException(ex.getTargetException());
            } catch (IllegalAccessException ex) {
                throw new DdlUtilsException(ex);
            }
        }
        if ((type.getSuperclass() != null) && !type.getSuperclass().equals(Object.class)) {
            queue.add(type.getSuperclass());
        }

        Class[] baseInterfaces = type.getInterfaces();

        if (baseInterfaces != null) {
            for (int idx = 0; idx < baseInterfaces.length; idx++) {
                queue.add(baseInterfaces[idx]);
            }
        }
    }
}

From source file:com.bstek.dorado.config.xml.XmlParserHelper.java

private void doGetXmlNodeInfo(XmlNodeInfo xmlNodeInfo, Class<?> type) {
    for (Class<?> i : type.getInterfaces()) {
        doGetXmlNodeInfo(xmlNodeInfo, i);
    }//www.  ja  v  a 2s  .  c om

    Class<?> superclass = type.getSuperclass();
    if (superclass != null && !superclass.equals(Object.class)) {
        doGetXmlNodeInfo(xmlNodeInfo, superclass);
    }

    collectXmlNodeInfo(xmlNodeInfo, type);
}

From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

private void registerMethod(Class<? extends Config> clazz, Method method, Function<Object[], Object> func) {
    this.registerMethod(method, func);
    for (Class<?> aClass : clazz.getInterfaces()) {
        Method m;/*from www . jav  a 2  s  . c o  m*/
        try {
            m = aClass.getMethod(method.getName(), method.getParameterTypes());
        } catch (Exception e) {
            continue;
        }
        this.registerMethod(m, func);
    }
}

From source file:org.apache.impala.extdatasource.ExternalDataSourceExecutor.java

/**
 * Returns the ExternalDataSource class, loading the jar if necessary. The
 * class is cached if initString_ starts with CACHE_CLASS_PREFIX.
 *//*from w w  w .  j  a  v a 2 s. c  o m*/
private Class<?> getDataSourceClass() throws Exception {
    Class<?> c = null;
    // Cache map key needs to contain both the class name and init string in case
    // the same class is used for multiple tables where some are cached and others
    // are not.
    String cacheMapKey = String.format("%s.%s", className_, initString_);
    synchronized (cachedClassesLock_) {
        c = cachedClasses_.get(cacheMapKey);
        if (c == null) {
            URL url = new File(jarPath_).toURI().toURL();
            URLClassLoader loader = URLClassLoader.newInstance(new URL[] { url }, getClass().getClassLoader());
            c = Class.forName(className_, true, loader);
            if (!ArrayUtils.contains(c.getInterfaces(), apiVersion_.getApiInterface())) {
                throw new ImpalaRuntimeException(String.format(
                        "Class '%s' does not implement interface '%s' required for API version %s", className_,
                        apiVersion_.getApiInterface().getName(), apiVersion_.name()));
            }
            // Only cache the class if the init string starts with CACHE_CLASS_PREFIX
            if (initString_ != null && initString_.startsWith(CACHE_CLASS_PREFIX)) {
                cachedClasses_.put(cacheMapKey, c);
            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("Loaded jar for class {} at path {}", className_, jarPath_);
            }
            numClassCacheMisses_++;
        } else {
            numClassCacheHits_++;
        }
    }
    return c;
}

From source file:org.apache.axis.encoding.TypeMappingImpl.java

/**
 * Gets the QName for the type mapped to Class.
 * @param javaType class or type//from  w  w  w. ja  v a  2  s . co  m
 * @return xmlType qname or null
 */
public QName getTypeQNameRecursive(Class javaType) {
    QName ret = null;
    while (javaType != null) {
        ret = getTypeQName(javaType, null);
        if (ret != null)
            return ret;

        // Walk my interfaces...
        Class[] interfaces = javaType.getInterfaces();
        if (interfaces != null) {
            for (int i = 0; i < interfaces.length; i++) {
                Class iface = interfaces[i];
                ret = getTypeQName(iface, null);
                if (ret != null)
                    return ret;
            }
        }

        javaType = javaType.getSuperclass();
    }
    return null;
}