< prev index next >
src/java.xml.bind/share/classes/javax/xml/bind/ServiceLoaderUtil.java
Print this page
*** 26,35 ****
--- 26,36 ----
package javax.xml.bind;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.Properties;
*** 47,63 ****
class ServiceLoaderUtil {
private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "com.sun.org.glassfish.hk2.osgiresourcelocator.ServiceLoader";
private static final String OSGI_SERVICE_LOADER_METHOD_NAME = "lookupProviderClasses";
! static <P> P firstByServiceLoader(Class<P> spiClass, Logger logger) {
// service discovery
ServiceLoader<P> serviceLoader = ServiceLoader.load(spiClass);
for (P impl : serviceLoader) {
logger.fine("ServiceProvider loading Facility used; returning object [" + impl.getClass().getName() + "]");
return impl;
}
return null;
}
static boolean isOsgi(Logger logger) {
try {
--- 48,68 ----
class ServiceLoaderUtil {
private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "com.sun.org.glassfish.hk2.osgiresourcelocator.ServiceLoader";
private static final String OSGI_SERVICE_LOADER_METHOD_NAME = "lookupProviderClasses";
! static <P, T extends Exception> P firstByServiceLoader(Class<P> spiClass, Logger logger, ExceptionHandler<T> handler) throws T {
// service discovery
+ try {
ServiceLoader<P> serviceLoader = ServiceLoader.load(spiClass);
for (P impl : serviceLoader) {
logger.fine("ServiceProvider loading Facility used; returning object [" + impl.getClass().getName() + "]");
return impl;
}
+ } catch (Throwable t) {
+ throw handler.createException(t, "Error while searching for service [" + spiClass.getName() + "]");
+ }
return null;
}
static boolean isOsgi(Logger logger) {
try {
*** 81,91 ****
logger.fine("Found implementation using OSGi facility; returning object [" + next.getClass().getName() + "].");
return next;
} else {
return null;
}
! } catch (Exception ignored) {
logger.log(Level.FINE, "Unable to find from OSGi: [" + factoryId + "]", ignored);
return null;
}
}
--- 86,96 ----
logger.fine("Found implementation using OSGi facility; returning object [" + next.getClass().getName() + "].");
return next;
} else {
return null;
}
! } catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException ignored) {
logger.log(Level.FINE, "Unable to find from OSGi: [" + factoryId + "]", ignored);
return null;
}
}
< prev index next >