/** * Check each element of an array of classes is an interface, and that it is in a whitelisted package. Throws * IllegalArgumentException otherwise. Returns the names of the classes as an array of strings. */ String[] getInterfaceNames(final Class<?>[] interfaces) { final String[] interfaceNames = new String[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { interfaceNames[i] = getInterfaceName(interfaces[i]); } return interfaceNames; }
/** * Get the names of interfaces on the classpath that extend a given superinterface. * * @param superInterface * The superinterface. * @return The sorted list of the names of subinterfaces of the given superinterface, or the empty list if none. */ public List<String> getNamesOfSubinterfacesOf(final Class<?> superInterface) { return getNamesOfSubinterfacesOf(scanSpec.getInterfaceName(superInterface)); }
/** * Get the names of all superinterfaces of the given subinterface. * * @param subInterface * The subinterface. * @return The sorted list of the names of superinterfaces of the given subinterface, or the empty list if none. */ public List<String> getNamesOfSuperinterfacesOf(final Class<?> subInterface) { return getNamesOfSuperinterfacesOf(scanSpec.getInterfaceName(subInterface)); }
/** * Get the names of all classes that implement (or have superclasses that implement) the given interface (or one * of its subinterfaces). * * @param implementedInterface * The interface. * @return The sorted list of the names of all classes that implement the given interface, or the empty list if * none. */ public List<String> getNamesOfClassesImplementing(final Class<?> implementedInterface) { return getNamesOfClassesImplementing(scanSpec.getInterfaceName(implementedInterface)); }
@Override public void lookForMatches(final ScanResult scanResult, final LogNode log) { final String superinterfaceName = getInterfaceName(superinterface); for (final String subinterfaceName : scanResult.getNamesOfSubinterfacesOf(superinterfaceName)) { LogNode subLog = null; if (log != null) { subLog = log.log("Matched subinterface of " + superinterfaceName + ": " + subinterfaceName); } try { // Call classloader @SuppressWarnings("unchecked") final Class<? extends T> cls = (Class<? extends T>) loadClassForMatchProcessor( subinterfaceName, scanResult, log); // Process match if (cls != null) { subinterfaceMatchProcessor.processMatch(cls); } } catch (final Throwable e) { if (subLog != null) { subLog.log("Exception while processing match for class " + subinterfaceName, e); } scanResult.addMatchProcessorException(e); } } } });
@Override public void lookForMatches(final ScanResult scanResult, final LogNode log) { final String implementedInterfaceName = getInterfaceName(implementedInterface); for (final String implementingClassName : scanResult .getNamesOfClassesImplementing(implementedInterfaceName)) { LogNode subLog = null; if (log != null) { subLog = log.log("Matched class implementing interface " + implementedInterfaceName + ": " + implementingClassName); } try { // Call classloader @SuppressWarnings("unchecked") final Class<? extends T> cls = (Class<? extends T>) loadClassForMatchProcessor( implementingClassName, scanResult, log); // Process match if (cls != null) { implementingClassMatchProcessor.processMatch(cls); } } catch (final Throwable e) { if (subLog != null) { subLog.log("Exception while processing match for class " + implementingClassName, e); } scanResult.addMatchProcessorException(e); } } } });