Beispiel #1
0
  private static void testClasspathScanning() throws IOException {
    // Note: We break down what PackageNameScanner does so we can identify where exactly it fails.

    // First check that we can look up directory resources.
    String packageName = "bake.example.foo";
    Enumeration<URL> resources =
        Foo.class.getClassLoader().getResources(packageName.replace('.', '/'));
    if (!resources.hasMoreElements()) {
      throw new AssertionError("Expected directory resources.");
    }

    // Now test the real thing.
    final List<String> names = new ArrayList<String>();
    PackageNamesScanner scanner =
        new PackageNamesScanner(Foo.class.getClassLoader(), new String[] {packageName});
    scanner.scan(
        new ScannerListener() {
          public boolean onAccept(String name) {
            names.add(name);
            return false;
          }

          public void onProcess(String name, InputStream in) throws IOException {
            throw new UnsupportedOperationException();
          }
        });
    if (names.isEmpty()) {
      throw new AssertionError("Jersey-style classpath scanning doesn't work.");
    }
  }
  /** Scan model classes and load up CF information from them */
  @SuppressWarnings("unchecked")
  public void scan(Class<? extends Annotation>... annotations) {
    AnnotationScannerListener scannerListener = new AnnotationScannerListener(annotations);
    _scanner.scan(scannerListener);

    Iterator<Class<?>> it = scannerListener.getAnnotatedClasses().iterator();
    while (it.hasNext()) {
      processClass(it.next());
    }
  }