use of org.reflections.Reflections in project alluxio by Alluxio.
the class AlluxioShell method loadCommands.
/**
* Uses reflection to get all the {@link ShellCommand} classes and store them in a map.
*/
private void loadCommands() {
String pkgName = ShellCommand.class.getPackage().getName();
Reflections reflections = new Reflections(pkgName);
for (Class<? extends ShellCommand> cls : reflections.getSubTypesOf(ShellCommand.class)) {
// Only instantiate a concrete class
if (!Modifier.isAbstract(cls.getModifiers())) {
ShellCommand cmd;
try {
cmd = CommonUtils.createNewClassInstance(cls, new Class[] { FileSystem.class }, new Object[] { mFileSystem });
} catch (Exception e) {
throw Throwables.propagate(e);
}
mCommands.put(cmd.getCommandName(), cmd);
}
}
}
use of org.reflections.Reflections in project asterixdb by apache.
the class SimpleSerializerDeserializerTest method test.
@SuppressWarnings("rawtypes")
@Test
public void test() {
Reflections reflections = new Reflections("org.apache.asterix.dataflow.data.nontagged.serde");
Set<Class<? extends ISerializerDeserializer>> allClasses = reflections.getSubTypesOf(ISerializerDeserializer.class);
for (Class<? extends ISerializerDeserializer> cl : allClasses) {
String className = cl.getName();
if (className.endsWith("ARecordSerializerDeserializer") || className.endsWith("AUnorderedListSerializerDeserializer") || className.endsWith("AOrderedListSerializerDeserializer") || className.endsWith("AStringSerializerDeserializer")) {
// Serializer/Deserializer for complex types can have (immutable) states.
continue;
}
// Verifies the class does not have non-static fields.
for (Field field : cl.getDeclaredFields()) {
if (!java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
throw new IllegalStateException("The serializer/deserializer " + cl.getName() + " is not stateless!");
}
}
// Verifies the class follows the singleton pattern.
for (Constructor constructor : cl.getDeclaredConstructors()) {
if (!java.lang.reflect.Modifier.isPrivate(constructor.getModifiers())) {
throw new IllegalStateException("The serializer/deserializer " + cl.getName() + " is not implemented as a singleton class!");
}
}
}
}
use of org.reflections.Reflections in project sling by apache.
the class ConfigurationMetadataUtil method getConfigurationClassesForPackages.
/**
* Get configuration classes in list of packages (and subpackages), and cache result in static map.
* @param packageNames Package names
* @return List of classes
*/
public static Collection<Class> getConfigurationClassesForPackages(String packageNames) {
List<Class> classes = CONFIGURATION_CLASSES_FOR_PACKAGES.get(packageNames);
if (classes == null) {
classes = new ArrayList<Class>();
String[] packageNameArray = StringUtils.split(packageNames, ",");
// add "." to each package name because it's a prefix, not a package name
Object[] prefixArray = new Object[packageNameArray.length];
for (int i = 0; i < packageNameArray.length; i++) {
prefixArray[i] = packageNameArray[i] + ".";
}
Reflections reflections = new Reflections(prefixArray);
classes.addAll(reflections.getTypesAnnotatedWith(Configuration.class));
CONFIGURATION_CLASSES_FOR_PACKAGES.putIfAbsent(packageNames, classes);
}
return classes;
}
use of org.reflections.Reflections in project sling by apache.
the class ModelAdapterFactoryUtil method getModelClassUrlsForPackages.
/**
* Get model classes in list of packages (and subpackages), and cache result in static map.
* @param packageNames Package names
* @return List of URLs
*/
private static Collection<URL> getModelClassUrlsForPackages(String packageNames) {
List<URL> urls = MODEL_URLS_FOR_PACKAGES.get(packageNames);
if (urls == null) {
urls = new ArrayList<URL>();
String[] packageNameArray = StringUtils.split(packageNames, ",");
// add "." to each package name because it's a prefix, not a package name
Object[] prefixArray = new Object[packageNameArray.length];
for (int i = 0; i < packageNameArray.length; i++) {
prefixArray[i] = packageNameArray[i] + ".";
}
Reflections reflections = new Reflections(prefixArray);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Model.class);
for (Class<?> clazz : classes) {
urls.add(classToUrl(clazz));
}
MODEL_URLS_FOR_PACKAGES.putIfAbsent(packageNames, urls);
}
return urls;
}
use of org.reflections.Reflections in project opennms by OpenNMS.
the class FunctionsManager method getTypesAnnotatedWithFunction.
private List<Class<?>> getTypesAnnotatedWithFunction(String packageToScan) {
Reflections reflections = new Reflections(packageToScan);
Set<Class<?>> functions = reflections.getTypesAnnotatedWith(Function.class);
return new ArrayList<>(functions);
}
Aggregations