Search in sources :

Example 96 with Reflections

use of org.reflections.Reflections in project zhcet-web by zhcet-amu.

the class Hibernate5DDLExporter method mapAnnotatedClasses.

private MetadataSources mapAnnotatedClasses(ServiceRegistry serviceRegistry) {
    MetadataSources sources = new MetadataSources(serviceRegistry);
    final Reflections reflections = new Reflections();
    for (final Class<?> mappedSuperClass : reflections.getTypesAnnotatedWith(MappedSuperclass.class)) {
        sources.addAnnotatedClass(mappedSuperClass);
        System.out.println("Mapped = " + mappedSuperClass.getName());
    }
    for (final Class<?> entityClasses : reflections.getTypesAnnotatedWith(Entity.class)) {
        sources.addAnnotatedClass(entityClasses);
        System.out.println("Mapped = " + entityClasses.getName());
    }
    return sources;
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Reflections(org.reflections.Reflections)

Example 97 with Reflections

use of org.reflections.Reflections in project sldeditor by robward-scisys.

the class RegisterClasses method registerRenderers.

/**
 * Register renderer converters.
 *
 * @param classLoadersList the class loaders list
 * @param data the data
 */
private static void registerRenderers(List<ClassLoader> classLoadersList, ConversionData data) {
    logger.info("Renderers 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.renderer"))));
    Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
    for (Class<? extends Object> claszz : allClasses) {
        try {
            if (validClass(claszz, EsriRendererInterface.class)) {
                EsriRendererInterface rendererObj = (EsriRendererInterface) claszz.newInstance();
                logger.info(rendererObj.getRendererClass().getName());
                data.addRenderer(rendererObj);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) FilterBuilder(org.reflections.util.FilterBuilder) EsriRendererInterface(com.sldeditor.importdata.esri.renderer.EsriRendererInterface) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Example 98 with Reflections

use of org.reflections.Reflections in project sldeditor by robward-scisys.

the class RegisterClasses method registerTextBackground.

/**
 * Register text background converters.
 *
 * @param classLoadersList the class loaders list
 * @param data the data
 */
private static void registerTextBackground(List<ClassLoader> classLoadersList, ConversionData data) {
    logger.info("Text backgrounds 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.textbackground"))));
    Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
    for (Class<? extends Object> claszz : allClasses) {
        try {
            if (validClass(claszz, EsriTextBackgroundInterface.class)) {
                EsriTextBackgroundInterface textBackgroundObj = (EsriTextBackgroundInterface) claszz.newInstance();
                logger.info(textBackgroundObj.getBackgroundClass().getName());
                data.addTextBackground(textBackgroundObj);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) FilterBuilder(org.reflections.util.FilterBuilder) ResourcesScanner(org.reflections.scanners.ResourcesScanner) EsriTextBackgroundInterface(com.sldeditor.importdata.esri.textbackground.EsriTextBackgroundInterface) Reflections(org.reflections.Reflections)

Example 99 with Reflections

use of org.reflections.Reflections in project cxf by apache.

the class Java2SwaggerMojo method loadResourceClasses.

private Set<Class<?>> loadResourceClasses(Class<? extends Annotation> clazz) throws MojoExecutionException {
    resourceClasses = new LinkedHashSet<Class<?>>(this.resourcePackages.size());
    Thread.currentThread().setContextClassLoader(getClassLoader());
    for (String resourcePackage : resourcePackages) {
        Set<Class<?>> c = new Reflections(resourcePackage).getTypesAnnotatedWith(clazz, true);
        resourceClasses.addAll(c);
        Set<Class<?>> inherited = new Reflections(resourcePackage).getTypesAnnotatedWith(clazz);
        resourceClasses.addAll(inherited);
    }
    return resourceClasses;
}
Also used : Reflections(org.reflections.Reflections)

Example 100 with Reflections

use of org.reflections.Reflections in project startup-os by google.

the class ClassScanner method scanPackage.

public void scanPackage(String packagePrefix, Map<String, FlagData> flags) {
    // TODO - figure out configuration builder.
    Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packagePrefix))).setUrls(ClasspathHelper.forPackage(packagePrefix)).setScanners(new FieldAnnotationsScanner()));
    Set<Field> fields = reflections.getFieldsAnnotatedWith(FlagDesc.class);
    for (Field field : fields) {
        Class<?> clazz = field.getType();
        if (!Flag.class.isAssignableFrom(clazz)) {
            throw new IllegalArgumentException("Annotation '" + field + "' does not annotate a flag.");
        }
        if ((field.getModifiers() & Modifier.STATIC) == 0) {
            throw new IllegalArgumentException("Flag '" + field + "' should be static but is not.");
        }
        Class<?> declaringClass = field.getDeclaringClass();
        Flag<?> flag = getFlagMember(declaringClass, field);
        FlagData flagData = createFlagData(declaringClass, field, flag);
        if (flags.containsKey(flagData.getName())) {
            throw new IllegalArgumentException(String.format("Flag '%s' is already defined here:\n%s", field, flags.get(flagData.getName())));
        }
        flags.put(flagData.getName(), flagData);
        flag.setName(flagData.getName());
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Field(java.lang.reflect.Field) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) FilterBuilder(org.reflections.util.FilterBuilder) Reflections(org.reflections.Reflections)

Aggregations

Reflections (org.reflections.Reflections)160 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)54 SubTypesScanner (org.reflections.scanners.SubTypesScanner)41 ArrayList (java.util.ArrayList)26 Set (java.util.Set)23 ResourcesScanner (org.reflections.scanners.ResourcesScanner)21 Test (org.junit.Test)20 FilterBuilder (org.reflections.util.FilterBuilder)20 HashSet (java.util.HashSet)19 URL (java.net.URL)18 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)18 IOException (java.io.IOException)17 Collectors (java.util.stream.Collectors)17 Method (java.lang.reflect.Method)16 List (java.util.List)15 File (java.io.File)13 InputStream (java.io.InputStream)9 Field (java.lang.reflect.Field)9 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)9 ClasspathHelper (org.reflections.util.ClasspathHelper)9