List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.apache.syncope.core.persistence.SQLSchemaGenerator.java
/** * @param cls the Class to check/*from ww w. j av a 2 s. co m*/ * @return <code>true</code> if the given Class cls implements the interface {@link PersistenceCapable} */ private static boolean implementsPersistenceCapable(final Class<?> cls) { boolean isPersistenceCapable = false; Class<?>[] interfaces = cls.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (interfaces[i].getName().equals(PersistenceCapable.class.getName())) { isPersistenceCapable = true; break; } } return isPersistenceCapable; }
From source file:Main.java
public static <A extends Annotation> A getClassAnnotation(Class<?> clientInterface, Class<A> annotationClass) { A annotation = clientInterface.getAnnotation(annotationClass); if (annotation == null) { for (Class<?> parentClass : clientInterface.getInterfaces()) { annotation = getClassAnnotation(parentClass, annotationClass); if (annotation != null) { System.out.println(parentClass); return annotation; }//from ww w . java 2s. c o m } } return annotation; }
From source file:nl.strohalm.cyclos.utils.ClassHelper.java
/** * Returns all implemented types for a given class - itself if a class and interfaces *//*from ww w . java2 s .co m*/ public static List<Class<?>> allImplementedTypes(Class<?> clazz) { final Class<?>[] interfaces = clazz.getInterfaces(); final List<Class<?>> classes = new ArrayList<Class<?>>(interfaces.length + 1); while (clazz != null && !clazz.equals(Object.class)) { classes.add(clazz); clazz = clazz.getSuperclass(); } classes.addAll(Arrays.asList(interfaces)); return classes; }
From source file:com.examples.with.different.packagename.ClassHierarchyIncludingInterfaces.java
public static Iterable<Class<?>> hierarchy(final Class<?> type, final Interfaces interfacesBehavior) { final Iterable<Class<?>> classes = new Iterable<Class<?>>() { @Override/* ww w. ja v a2 s .c om*/ public Iterator<Class<?>> iterator() { final MutableObject<Class<?>> next = new MutableObject<Class<?>>(type); return new Iterator<Class<?>>() { @Override public boolean hasNext() { return next.getValue() != null; } @Override public Class<?> next() { final Class<?> result = next.getValue(); next.setValue(result.getSuperclass()); return result; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; if (interfacesBehavior != Interfaces.INCLUDE) { return classes; } return new Iterable<Class<?>>() { @Override public Iterator<Class<?>> iterator() { final Set<Class<?>> seenInterfaces = new HashSet<Class<?>>(); final Iterator<Class<?>> wrapped = classes.iterator(); return new Iterator<Class<?>>() { Iterator<Class<?>> interfaces = Collections.<Class<?>>emptySet().iterator(); @Override public boolean hasNext() { return interfaces.hasNext() || wrapped.hasNext(); } @Override public Class<?> next() { if (interfaces.hasNext()) { final Class<?> nextInterface = interfaces.next(); seenInterfaces.add(nextInterface); return nextInterface; } final Class<?> nextSuperclass = wrapped.next(); final Set<Class<?>> currentInterfaces = new LinkedHashSet<Class<?>>(); walkInterfaces(currentInterfaces, nextSuperclass); interfaces = currentInterfaces.iterator(); return nextSuperclass; } private void walkInterfaces(final Set<Class<?>> addTo, final Class<?> c) { for (final Class<?> iface : c.getInterfaces()) { if (!seenInterfaces.contains(iface)) { addTo.add(iface); } walkInterfaces(addTo, iface); } } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:org.apache.roller.weblogger.business.plugins.PluginManagerImpl.java
private static boolean isPagePlugin(Class pluginClass) { Class[] interfaces = pluginClass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (interfaces[i].equals(WeblogEntryPlugin.class)) return true; }// w w w . j ava 2s . c o m return false; }
From source file:Main.java
private static void collectAssignables(Class c1, Class c2, Set s) { if (c1.isAssignableFrom(c2)) { s.add(c1);//from w w w. j a va 2 s .c om } Class sc = c1.getSuperclass(); if (sc != null) { collectAssignables(sc, c2, s); } Class[] itf = c1.getInterfaces(); for (int i = 0; i < itf.length; ++i) { collectAssignables(itf[i], c2, s); } }
From source file:Main.java
static void findAllInterfaces(Class c, Set<Class> interfaces) { if (c.isInterface()) { interfaces.add(c);/* w w w . j a v a2 s .c o m*/ } Class s = c.getSuperclass(); if (s != null) { findAllInterfaces(s, interfaces); } Class[] is = c.getInterfaces(); for (int i = 0; i < is.length; i++) { findAllInterfaces(is[i], interfaces); } }
From source file:org.red5.server.api.persistence.PersistenceUtils.java
/** * Returns persistence store object. Persistence store is a special object that stores persistence objects and provides methods to manipulate them (save, load, remove, list). * /*from w ww. jav a2 s .co m*/ * @param resolver * Resolves connection pattern into Resource object * @param className * Name of persistence class * @return IPersistence store object that provides methods for persistence object handling * @throws Exception * if error */ public static IPersistenceStore getPersistenceStore(ResourcePatternResolver resolver, String className) throws Exception { Class<?> persistenceClass = Class.forName(className); Constructor<?> constructor = getPersistenceStoreConstructor(persistenceClass, resolver.getClass().getInterfaces()); if (constructor == null) { // Search in superclasses of the object. Class<?> superClass = resolver.getClass().getSuperclass(); while (superClass != null) { constructor = getPersistenceStoreConstructor(persistenceClass, superClass.getInterfaces()); if (constructor != null) { break; } superClass = superClass.getSuperclass(); } } if (constructor == null) { throw new NoSuchMethodException(); } return (IPersistenceStore) constructor.newInstance(new Object[] { resolver }); }
From source file:Main.java
public static Class<?> messageClass(Object message) { final Class<?> messageClass = message.getClass(); if (messageClass.isAnonymousClass() || messageClass.getSimpleName().contains("-$Lambda$") // Jack || messageClass.getSimpleName().contains("$$Lambda$") // Retrolambda )//from w w w . j a v a 2 s. c o m return messageClass.getInterfaces()[0]; return messageClass; }
From source file:org.opendaylight.controller.yang2sources.plugin.Util.java
private static boolean isImplemented(Class<?> expectedIface, Class<?> byClazz) { for (Class<?> iface : byClazz.getInterfaces()) { if (iface.equals(expectedIface)) return true; }/*from w w w . jav a2 s. c o m*/ return false; }