コード例 #1
0
 private final JAXBContext newJAXBContext() {
   BundleContext ctx = getBundleContext();
   IBundleScanService svc = lookupBundleScanner(ctx);
   try {
     List<Class<?>> cls =
         svc.getAnnotatedClasses(
             ctx,
             new String[] {XmlRootElement.class.getPackage().getName()},
             parseManifestEntry(ctx, JAXRS_EXCLUDES_MANIFEST_NAME),
             true);
     return JAXBContext.newInstance(cls.toArray(new Class[cls.size()]));
   } catch (JAXBException je) {
     LOGGER.error("Error creating JAXBContext", je);
     return null;
   }
 }
コード例 #2
0
  private final Set<Class<?>> findJAXRSResourceClasses() {
    BundleContext ctx = getBundleContext();
    String bundleName = ctx.getBundle().getSymbolicName();
    Set<Class<?>> result = new HashSet<Class<?>>();
    ServiceException recordException = null;
    try {
      IBundleScanService svc = lookupBundleScanner(ctx);
      result.addAll(
          svc.getAnnotatedClasses(
              ctx, new String[] {javax.ws.rs.Path.class.getName()}, null, false));
    } catch (ServiceException se) {
      recordException = se;
      LOGGER.debug(
          "Error finding JAXRS resource annotated classes in " + "bundle: {} error: {}.",
          bundleName,
          se.getMessage());
      // the bundle scan service cannot be lookedup. Lets attempt to
      // lookup the resources from the bundle manifest header
      for (String c : parseManifestEntry(ctx, JAXRS_RESOURCES_MANIFEST_NAME)) {
        try {
          result.add(ctx.getBundle().loadClass(c));
        } catch (ClassNotFoundException cnfe) {
          LOGGER.error(
              "Cannot load class: {} in bundle: {} " + "defined as MANIFEST JAX-RS resource",
              c,
              bundleName,
              cnfe);
        }
      }
    }

    if (result.size() == 0) {
      if (recordException != null) {
        throw recordException;
      } else {
        throw new ServiceException(
            "No resource classes found in bundle:" + ctx.getBundle().getSymbolicName());
      }
    }
    return result;
  }