List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.apache.cocoon.core.container.spring.avalon.PoolableFactoryBean.java
/** * Get a list of interfaces to proxy by scanning through * all interfaces a class implements.//from w w w . j a va2 s. c o m * * @param clazz the class * @param workInterfaces the set of current work interfaces */ private void guessWorkInterfaces(final Class clazz, final Set workInterfaces) { if (null != clazz) { this.addInterfaces(clazz.getInterfaces(), workInterfaces); this.guessWorkInterfaces(clazz.getSuperclass(), workInterfaces); } }
From source file:org.broadleafcommerce.common.util.dao.DynamicDaoHelperImpl.java
@Override public Class<?>[] sortEntities(Class<?> ceilingClass, List<Class<?>> entities) { /*//ww w .j a va 2 s . c om * Sort entities with the most derived appearing first */ Class<?>[] sortedEntities = new Class<?>[entities.size()]; List<Class<?>> stageItems = new ArrayList<Class<?>>(); stageItems.add(ceilingClass); int j = 0; while (j < sortedEntities.length) { List<Class<?>> newStageItems = new ArrayList<Class<?>>(); boolean topLevelClassFound = false; for (Class<?> stageItem : stageItems) { Iterator<Class<?>> itr = entities.iterator(); while (itr.hasNext()) { Class<?> entity = itr.next(); checkitem: { if (ArrayUtils.contains(entity.getInterfaces(), stageItem) || entity.equals(stageItem)) { topLevelClassFound = true; break checkitem; } if (topLevelClassFound) { continue; } if (entity.getSuperclass().equals(stageItem) && j > 0) { break checkitem; } continue; } sortedEntities[j] = entity; itr.remove(); j++; newStageItems.add(entity); } } if (newStageItems.isEmpty()) { throw new IllegalArgumentException( "There was a gap in the inheritance hierarchy for (" + ceilingClass.getName() + ")"); } stageItems = newStageItems; } ArrayUtils.reverse(sortedEntities); return sortedEntities; }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Return a descriptive name for the given object's type: usually simply * the class name, but component type class name + "[]" for arrays, * and an appended list of implemented interfaces for JDK proxies. * @param value the value to introspect// w w w. j a va 2s .c o m * @return the qualified name of the class */ public static String getDescriptiveType(Object value) { if (value == null) { return null; } Class<?> clazz = value.getClass(); if (Proxy.isProxyClass(clazz)) { StringBuilder result = new StringBuilder(clazz.getName()); result.append(" implementing "); Class<?>[] ifcs = clazz.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { result.append(ifcs[i].getName()); if (i < ifcs.length - 1) { result.append(','); } } return result.toString(); } else if (clazz.isArray()) { return getQualifiedNameForArray(clazz); } else { return clazz.getName(); } }
From source file:com.haulmont.cuba.gui.components.validators.RangeValidator.java
protected Class<? extends Comparable> getTypeFromString(String typeStr) { Class type; try {/*from ww w . j av a2 s. c o m*/ type = Class.forName(typeStr); } catch (ClassNotFoundException e) { throw new RuntimeException(String.format("Type '%s' not found", typeStr)); } if (!Arrays.asList(type.getInterfaces()).contains(Comparable.class)) { throw new RuntimeException(String.format("Type '%s' is not comparable", typeStr)); } return type; }
From source file:com.freetmp.common.util.ClassUtils.java
public static String getDescriptiveType(Object value) { if (value == null) { return null; }/* www . ja v a 2 s . c o m*/ Class<?> clazz = value.getClass(); if (Proxy.isProxyClass(clazz)) { StringBuilder result = new StringBuilder(clazz.getName()); result.append(" implementing "); Class<?>[] ifcs = clazz.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { result.append(ifcs[i].getName()); if (i < ifcs.length - 1) { result.append(','); } } return result.toString(); } else if (clazz.isArray()) { return getQualifiedNameForArray(clazz); } else { return clazz.getName(); } }
From source file:evyframework.common.ClassUtils.java
/** * Return all interfaces that the given class implements as Set, * including ones implemented by superclasses. * <p>If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze 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 Set *///from w ww .j a v a 2s. com @SuppressWarnings("rawtypes") public static Set<Class> getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) { Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface() && isVisible(clazz, classLoader)) { return Collections.singleton(clazz); } Set<Class> interfaces = new LinkedHashSet<Class>(); while (clazz != null) { Class<?>[] ifcs = clazz.getInterfaces(); for (Class<?> ifc : ifcs) { interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader)); } clazz = clazz.getSuperclass(); } return interfaces; }
From source file:org.lunarray.model.descriptor.scanner.impl.extensions.AnnotationMetaModelImpl.java
/** * Resolve classes./*from w w w . ja v a 2 s. com*/ * * @param tail * The result tail. * @param type * The type. */ private void resolveClasses(final Set<Class<?>> tail, final Class<?> type) { final Class<?> superType = type.getSuperclass(); if (!CheckUtil.isNull(superType)) { tail.add(superType); this.resolveClasses(tail, superType); } for (final Class<?> interfaceType : type.getInterfaces()) { tail.add(interfaceType); this.resolveClasses(tail, interfaceType); } }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Return the number of methods with a given name (with any argument types), * for the given class and/or its superclasses. Includes non-public methods. * @param clazz the clazz to check/*from w ww . j a v a 2 s. c o m*/ * @param methodName the name of the method * @return the number of methods with the given name */ public static int getMethodCountForName(Class clazz, String methodName) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); int count = 0; Method[] declaredMethods = clazz.getDeclaredMethods(); for (int i = 0; i < declaredMethods.length; i++) { Method method = declaredMethods[i]; if (methodName.equals(method.getName())) { count++; } } Class[] ifcs = clazz.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { count += getMethodCountForName(ifcs[i], methodName); } if (clazz.getSuperclass() != null) { count += getMethodCountForName(clazz.getSuperclass(), methodName); } return count; }
From source file:org.apache.openjpa.kernel.ResultPacker.java
boolean isInterface(Class<?> intf, Class<?> actual) { if (actual != null) { Class<?>[] intfs = actual.getInterfaces(); for (Class<?> c : intfs) { if (c == intf) return true; }//from www. j ava 2 s.c o m } return false; }
From source file:com.bstek.dorado.view.output.ClientOutputHelper.java
private void doGetClientObjectInfo(ClientObjectInfo clientObjectInfo, Class<?> type) { for (Class<?> i : type.getInterfaces()) { doGetClientObjectInfo(clientObjectInfo, i); }// w w w. j ava 2s .c o m Class<?> superclass = type.getSuperclass(); if (superclass != null && !superclass.equals(Object.class)) { doGetClientObjectInfo(clientObjectInfo, superclass); } collectClientObjectInfo(clientObjectInfo, type); }