/** * Method scanning given directory for classes containing Hibernate @Entity annotation * * @param pckgs string array with packages containing Hibernate entities (classes annotated with @Entity annotation) * e.g. com.codahale.fake.db.directory.entities * @return ImmutableList with classes from given directory annotated with Hibernate @Entity annotation */ public static List<Class<?>> findEntityClassesFromDirectory(String[] pckgs) { @SuppressWarnings("unchecked") final AnnotationAcceptingListener asl = new AnnotationAcceptingListener(Entity.class); try (final PackageNamesScanner scanner = new PackageNamesScanner(pckgs, true)) { while (scanner.hasNext()) { final String next = scanner.next(); if (asl.accept(next)) { try (final InputStream in = scanner.open()) { asl.process(next, in); } catch (IOException e) { throw new RuntimeException("AnnotationAcceptingListener failed to process scanned resource: " + next); } } } } return new ArrayList<>(asl.getAnnotatedClasses()); } }
/** * Create a scanner listener to check for annotated Java classes in Java * class files. * * @param classloader the class loader to use to load Java classes that * are annotated with any one of the annotations. * @param annotations the set of annotation classes to check on Java class * files. */ public AnnotationAcceptingListener(final ClassLoader classloader, final Class<? extends Annotation>... annotations) { this.classloader = classloader; this.classes = new LinkedHashSet<Class<?>>(); this.annotations = getAnnotationSet(annotations); this.classVisitor = new AnnotatedClassVisitor(); }
AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(_state.getClassLoader()); for (final ResourceFinder resourceFinder : rfs) { while (resourceFinder.hasNext()) { final String next = resourceFinder.next(); if (afl.accept(next)) { final InputStream in = resourceFinder.open(); try { afl.process(next, in); } catch (final IOException e) { LOGGER.log(Level.WARNING, LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_PROCESS(next)); result.addAll(afl.getAnnotatedClasses()); return result;
/** * Create a scanning listener to check for Java classes in Java * class files annotated with {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider}. * * @return new instance of {@link AnnotationAcceptingListener} which looks for * {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider} annotated classes. * */ @SuppressWarnings({"unchecked"}) public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener() { return new AnnotationAcceptingListener(Path.class, Provider.class); }
/** * Create a scanning listener to check for Java classes in Java * class files annotated with {@link Path} or {@link Provider}. * * @param classLoader the class loader to use to load Java classes that * are annotated with any one of the annotations. * @return new instance of {@link AnnotationAcceptingListener} which looks for * {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider} annotated classes. */ @SuppressWarnings({"unchecked"}) public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(final ClassLoader classLoader) { return new AnnotationAcceptingListener(classLoader, Path.class, Provider.class); }
AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(_state.getClassLoader()); for (final ResourceFinder resourceFinder : rfs) { while (resourceFinder.hasNext()) { final String next = resourceFinder.next(); if (afl.accept(next)) { final InputStream in = resourceFinder.open(); try { afl.process(next, in); } catch (final IOException e) { LOGGER.log(Level.WARNING, LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_PROCESS(next)); result.addAll(afl.getAnnotatedClasses()); return result;
final AnnotationAcceptingListener asl = new AnnotationAcceptingListener(Entity.class); try (final PackageNamesScanner scanner = new PackageNamesScanner(pckgs, true)) { while (scanner.hasNext()) { final String next = scanner.next(); if (asl.accept(next)) { try (final InputStream in = scanner.open()) { asl.process(next, in); } catch (IOException e) { throw new RuntimeException("AnnotationAcceptingListener failed to process scanned resource: " + next); for (Class<?> clazz : asl.getAnnotatedClasses()) { builder.add(clazz);
/** * Create a scanning listener to check for Java classes in Java * class files annotated with {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider}. * * @return new instance of {@link AnnotationAcceptingListener} which looks for * {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider} annotated classes. * */ @SuppressWarnings({"unchecked"}) public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener() { return new AnnotationAcceptingListener(Path.class, Provider.class); }
/** * Create a scanner listener to check for annotated Java classes in Java * class files. * * @param classloader the class loader to use to load Java classes that * are annotated with any one of the annotations. * @param annotations the set of annotation classes to check on Java class * files. */ public AnnotationAcceptingListener(final ClassLoader classloader, final Class<? extends Annotation>... annotations) { this.classloader = classloader; this.classes = new LinkedHashSet<Class<?>>(); this.annotations = getAnnotationSet(annotations); this.classVisitor = new AnnotatedClassVisitor(); }
AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(_state.getClassLoader()); for (final ResourceFinder resourceFinder : rfs) { while (resourceFinder.hasNext()) { final String next = resourceFinder.next(); if (afl.accept(next)) { final InputStream in = resourceFinder.open(); try { afl.process(next, in); } catch (final IOException e) { LOGGER.log(Level.WARNING, LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_PROCESS(next)); result.addAll(afl.getAnnotatedClasses()); return result;
/** * Method scanning given directory for classes containing Hibernate @Entity annotation * * @param pckgs string array with packages containing Hibernate entities (classes annotated with @Entity annotation) * e.g. com.codahale.fake.db.directory.entities * @return ImmutableList with classes from given directory annotated with Hibernate @Entity annotation */ public static ImmutableList<Class<?>> findEntityClassesFromDirectory(String[] pckgs) { @SuppressWarnings("unchecked") final AnnotationAcceptingListener asl = new AnnotationAcceptingListener(Entity.class); final PackageNamesScanner scanner = new PackageNamesScanner(pckgs, true); while (scanner.hasNext()) { final String next = scanner.next(); if (asl.accept(next)) { try (final InputStream in = scanner.open()) { asl.process(next, in); } catch (IOException e) { throw new RuntimeException("AnnotationAcceptingListener failed to process scanned resource: " + next); } } } final ImmutableList.Builder<Class<?>> builder = ImmutableList.builder(); for (Class<?> clazz : asl.getAnnotatedClasses()) { builder.add(clazz); } return builder.build(); } }
/** * Create a scanning listener to check for Java classes in Java * class files annotated with {@link Path} or {@link Provider}. * * @param classLoader the class loader to use to load Java classes that * are annotated with any one of the annotations. * @return new instance of {@link AnnotationAcceptingListener} which looks for * {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider} annotated classes. */ @SuppressWarnings({"unchecked"}) public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(final ClassLoader classLoader) { return new AnnotationAcceptingListener(classLoader, Path.class, Provider.class); }
/** * Create a scanner listener to check for annotated Java classes in Java * class files. * * @param classloader the class loader to use to load Java classes that * are annotated with any one of the annotations. * @param annotations the set of annotation classes to check on Java class * files. */ public AnnotationAcceptingListener(final ClassLoader classloader, final Class<? extends Annotation>... annotations) { this.classloader = classloader; this.classes = new LinkedHashSet<Class<?>>(); this.annotations = getAnnotationSet(annotations); this.classVisitor = new AnnotatedClassVisitor(); }
AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(_state.getClassLoader()); for (final ResourceFinder resourceFinder : rfs) { while (resourceFinder.hasNext()) { final String next = resourceFinder.next(); if (afl.accept(next)) { final InputStream in = resourceFinder.open(); try { afl.process(next, in); } catch (final IOException e) { LOGGER.log(Level.WARNING, LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_PROCESS(next)); result.addAll(afl.getAnnotatedClasses()); return result;
/** * Scans all classes accessible from the context class loader which belong to the given package and subpackages. * @param pckg package name * @param annotation Annotation to search * @return The classes */ static public List<Class<?>> getAnnotatedClasses(Package pckg, Class<? extends Annotation> annotation) { final AnnotationAcceptingListener annotationAcceptingListener = new AnnotationAcceptingListener(annotation); try (final PackageNamesScanner scanner = new PackageNamesScanner(new String[] { pckg.getName() }, true)) { while (scanner.hasNext()) { final String next = scanner.next(); if (annotationAcceptingListener.accept(next)) { try (final InputStream in = scanner.open()) { annotationAcceptingListener.process(next, in); } catch (IOException e) { throw new RuntimeException("AnnotationAcceptingListener failed to process scanned resource: " + next); } } } } return annotationAcceptingListener.getAnnotatedClasses() .stream().collect(Collectors.toCollection(ArrayList::new)); } }
/** * Create a scanning listener to check for Java classes in Java * class files annotated with {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider}. * * @return new instance of {@link AnnotationAcceptingListener} which looks for * {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider} annotated classes. * */ @SuppressWarnings({"unchecked"}) public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener() { return new AnnotationAcceptingListener(Path.class, Provider.class); }
/** * Create a scanner listener to check for annotated Java classes in Java * class files. * * @param classloader the class loader to use to load Java classes that * are annotated with any one of the annotations. * @param annotations the set of annotation classes to check on Java class * files. */ public AnnotationAcceptingListener(final ClassLoader classloader, final Class<? extends Annotation>... annotations) { this.classloader = classloader; this.classes = new LinkedHashSet<Class<?>>(); this.annotations = getAnnotationSet(annotations); this.classVisitor = new AnnotatedClassVisitor(); }
AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(_state.getClassLoader()); for (final ResourceFinder resourceFinder : rfs) { while (resourceFinder.hasNext()) { final String next = resourceFinder.next(); if (afl.accept(next)) { final InputStream in = resourceFinder.open(); try { afl.process(next, in); } catch (final IOException e) { LOGGER.log(Level.WARNING, LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_PROCESS(next)); result.addAll(afl.getAnnotatedClasses()); return result;
/** * Create a scanning listener to check for Java classes in Java * class files annotated with {@link Path} or {@link Provider}. * * @param classLoader the class loader to use to load Java classes that * are annotated with any one of the annotations. * @return new instance of {@link AnnotationAcceptingListener} which looks for * {@link javax.ws.rs.Path} or {@link javax.ws.rs.ext.Provider} annotated classes. */ @SuppressWarnings({"unchecked"}) public static AnnotationAcceptingListener newJaxrsResourceAndProviderListener(final ClassLoader classLoader) { return new AnnotationAcceptingListener(classLoader, Path.class, Provider.class); }
/** * Create a scanner listener to check for annotated Java classes in Java * class files. * * @param classloader the class loader to use to load Java classes that * are annotated with any one of the annotations. * @param annotations the set of annotation classes to check on Java class * files. */ public AnnotationAcceptingListener(final ClassLoader classloader, final Class<? extends Annotation>... annotations) { this.classloader = classloader; this.classes = new LinkedHashSet<Class<?>>(); this.annotations = getAnnotationSet(annotations); this.classVisitor = new AnnotatedClassVisitor(); }