public Provider current() { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); if (tccl == null) { tccl = getSystemClassLoader(); } while (tccl != null) { final ResourceBundleControlProvider impl = providers.get(tccl); if (impl != null) { return new Provider(impl, tccl); } if (tccl == tccl.getParent()) { return null; } tccl = tccl.getParent(); } return null; }
private static Control getDefaultControl(String baseName) { if (providers != null) { for (ResourceBundleControlProvider provider : providers) { Control control = provider.getControl(baseName); if (control != null) { return control; } } } return Control.INSTANCE; }
private static Control getDefaultControl(Class<?> caller, String baseName) { if (providers != null && !caller.getModule().isNamed()) { for (ResourceBundleControlProvider provider : providers) { Control control = provider.getControl(baseName); if (control != null) { return control; } } } return Control.INSTANCE; }
Provider(final ResourceBundleControlProvider provider, final ClassLoader loader) { this.provider = provider; this.loader = loader; }
public ResourceBundleControlProvider getProvider() { return provider; }
/** * @param loader * the loader identifying the current context. * @param customProvider * the bundle control provider to associate with this loader. * @return a callback to call when you don't need the custom provider anymore. */ public Runnable register(final ClassLoader loader, final ResourceBundleControlProvider customProvider) { if (providers.putIfAbsent(loader, customProvider) != null) { throw new IllegalArgumentException("A custom ResourceBundleControlProvider is already registered for " + loader); } return () -> providers.remove(loader, customProvider); }