Example #1
0
 // Build a resource URL for the given resource
 private static URL getResourceURL(String rsrc) throws IOException {
   Enumeration<URL> urls = null;
   try {
     ClassLoader cl = ContainerEMFTest.class.getClassLoader();
     urls = AccessController.doPrivileged(J2DoPrivHelper.getResourcesAction(cl, rsrc));
   } catch (PrivilegedActionException pae) {
     throw (IOException) pae.getException();
   }
   return Collections.list(urls).get(0);
 }
  public Object newInstance(String clsName, Class type, Configuration conf, boolean fatal) {
    // since the MappingRepository takes a JDBConfiguration constructor,
    // we need to manually perform the instantiation
    try {
      Class cls =
          Strings.toClass(
              clsName, AccessController.doPrivileged(J2DoPrivHelper.getClassLoaderAction(type)));
      return cls.getConstructor(new Class[] {JDBCConfiguration.class})
          .newInstance(new Object[] {conf});
    } catch (RuntimeException e) {
      throw e;
    } catch (InvocationTargetException e) {
      if (e.getTargetException() instanceof RuntimeException)
        throw (RuntimeException) e.getTargetException();

      // fall back to default behavior for better error reporting
      return super.newInstance(clsName, type, conf, fatal);
    } catch (Exception e) {
      // fall back to default behavior for better error reporting
      return super.newInstance(clsName, type, conf, fatal);
    }
  }