use of org.reflections.scanners.SubTypesScanner in project sldeditor by robward-scisys.
the class RegisterClasses method registerSymbols.
/**
* Register symbols converters.
*
* @param classLoadersList the class loaders list
* @param data the data
*/
private static void registerSymbols(List<ClassLoader> classLoadersList, ConversionData data) {
logger.info("Symbols supported:");
Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false), new ResourcesScanner()).setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))).filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.sldeditor.importdata.esri.symbol"))));
Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
for (Class<? extends Object> claszz : allClasses) {
try {
if (validClass(claszz, EsriSymbolInterface.class)) {
EsriSymbolInterface symbolObj = (EsriSymbolInterface) claszz.newInstance();
logger.info(symbolObj.getSymbolClass().getName());
data.addSymbol(symbolObj);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of org.reflections.scanners.SubTypesScanner in project sldeditor by robward-scisys.
the class RegisterClasses method registerNumberFormat.
/**
* Register number format converters.
*
* @param classLoadersList the class loaders list
* @param data the data
*/
private static void registerNumberFormat(List<ClassLoader> classLoadersList, ConversionData data) {
logger.info("Number formats supported:");
Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false), new ResourcesScanner()).setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))).filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.sldeditor.importdata.esri.numberformat"))));
Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
for (Class<? extends Object> claszz : allClasses) {
try {
if (validClass(claszz, EsriNumberFormatInterface.class)) {
EsriNumberFormatInterface numberFormatObj = (EsriNumberFormatInterface) claszz.newInstance();
logger.info(numberFormatObj.getNumberFormatClass().getName());
data.addNumberFormat(numberFormatObj);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of org.reflections.scanners.SubTypesScanner in project BoofCV by lessthanoptimal.
the class ExampleLauncherApp method createTree.
@Override
protected void createTree(DefaultMutableTreeNode root) {
List<String> packages = new ArrayList<>();
packages.add("boofcv.examples.calibration");
packages.add("boofcv.examples.enhance");
packages.add("boofcv.examples.features");
packages.add("boofcv.examples.fiducial");
packages.add("boofcv.examples.geometry");
packages.add("boofcv.examples.imageprocessing");
packages.add("boofcv.examples.recognition");
packages.add("boofcv.examples.segmentation");
packages.add("boofcv.examples.sfm");
packages.add("boofcv.examples.stereo");
packages.add("boofcv.examples.tracking");
// Reflections is a weird package that does not behave the way one would expect. Several hacks below
for (String p : packages) {
Reflections reflections = new Reflections(p, new SubTypesScanner(false));
List<String> listTypes = new ArrayList<>();
listTypes.addAll(reflections.getAllTypes());
addAll((Set) reflections.getSubTypesOf(LearnSceneFromFiles.class), listTypes);
String name = p.split("\\.")[2];
Collections.sort(listTypes);
List<Class> classes = new ArrayList<>();
String[] classNames = listTypes.toArray(new String[1]);
for (int i = 0; i < classNames.length; i++) {
if (!classNames[i].contains("Example"))
continue;
// no idea why this is needed
if (classNames[i].contains("$"))
continue;
try {
classes.add(Class.forName(classNames[i]));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
createNodes(root, name, classes.toArray(new Class[0]));
}
}
use of org.reflections.scanners.SubTypesScanner in project motech by motech.
the class ReflectionsUtil method getClasses.
/**
* Looks for classes annotated with a given annotation.
*
* @param annotation an annotation to look for
* @param bundle a bundle to look in.
* @return A list of classes, annotated with the given annotation
*/
public static Set<Class<?>> getClasses(Class<? extends Annotation> annotation, Bundle bundle) {
LOGGER.debug("Scanning bundle: {}", bundle.getSymbolicName());
LOGGER.debug("Searching for classes with annotations: {}", annotation.getName());
Reflections reflections = configureReflection(bundle, new PristineBundleClassLoader(bundle), new TypeAnnotationsScanner(), new SubTypesScanner());
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(annotation);
// in order to prevent processing of user defined or auto generated fields
// we have to load the bytecode from the jar and define the class in a temporary
// classLoader
PristineBundleClassLoader pristineBundleClassLoader = new PristineBundleClassLoader(bundle);
Set<Class<?>> result = new HashSet<>();
for (Class clazz : classes) {
try {
result.add(pristineBundleClassLoader.loadClass(clazz.getName()));
} catch (ClassNotFoundException e) {
LOGGER.error("Could not find class", e);
}
}
LOGGER.debug("Searched for classes with annotations: {}", annotation.getName());
LOGGER.trace("Found {} classes with annotations: {}", result.size(), annotation.getName());
return result;
}
use of org.reflections.scanners.SubTypesScanner in project pwm by pwm-project.
the class ControlledPwmServletTest method getClassAndMethods.
private Map<Class<? extends ControlledPwmServlet>, Map<String, Method>> getClassAndMethods() {
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("password.pwm")).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new FieldAnnotationsScanner()));
Set<Class<? extends ControlledPwmServlet>> classes = reflections.getSubTypesOf(ControlledPwmServlet.class);
final Map<Class<? extends ControlledPwmServlet>, Map<String, Method>> returnMap = new HashMap<>();
for (final Class<? extends ControlledPwmServlet> controlledPwmServlet : classes) {
if (!Modifier.isAbstract(controlledPwmServlet.getModifiers())) {
final Map<String, Method> annotatedMethods = new HashMap<>();
for (Method method : JavaHelper.getAllMethodsForClass(controlledPwmServlet)) {
if (method.getAnnotation(ControlledPwmServlet.ActionHandler.class) != null) {
final String actionName = method.getAnnotation(ControlledPwmServlet.ActionHandler.class).action();
annotatedMethods.put(actionName, method);
}
}
returnMap.put(controlledPwmServlet, Collections.unmodifiableMap(annotatedMethods));
}
}
return Collections.unmodifiableMap(returnMap);
}
Aggregations