Skip to content

Commit

Permalink
Add custom classloader version to API
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcsakany committed Aug 24, 2024
1 parent f9a9c29 commit 3e3085c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public interface EnumI18nService {
*/
void register(Class<? extends Enum> clazz, Supplier<Locale> localeSupplier);

void register(String className, ClassLoader classLoader) throws ClassNotFoundException;

/**
* Unregister an Enm i18n message.
* @param clazz
*/
void register(String className, Supplier<Locale> localeSupplier, ClassLoader classLoader) throws ClassNotFoundException;
/**
* Unregister an Enm i18n message.
* @param clazz
*/
void unregister(Class<? extends Enum> clazz);

String getMessageForEnum(Enum entry, Object... args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ void activate(Config config) {
defaultLocale = I18NUtil.getLocaleFromBCP47(config.defaultLocale());
}

@Override
public void register(Class<? extends Enum> clazz) {
register(clazz, this.localeSupplier);
}

@Override
public void register(String className, ClassLoader classLoader) throws ClassNotFoundException {
Class<? extends Enum> clazz = (Class<? extends Enum>) classLoader.loadClass(className);
register(clazz, this.localeSupplier);
}

@Override
public void register(Class<? extends Enum> clazz, Supplier<Locale> localeSupplier) {
MessageStreamLoader messageStreamLoader = new ClassLoaderBasedMessageStreamLoader(clazz.getClassLoader());
Expand All @@ -60,6 +67,12 @@ public void register(Class<? extends Enum> clazz, Supplier<Locale> localeSupplie
resolvers.put(clazz, messageResolver);
}

@Override
public void register(String className, Supplier<Locale> localeSupplier, ClassLoader classLoader) throws ClassNotFoundException {
Class<? extends Enum> clazz = (Class<? extends Enum>) classLoader.loadClass(className);
register(clazz, localeSupplier);
}

public void unregister(Class<? extends Enum> clazz) {
resolvers.remove(clazz);
}
Expand Down

0 comments on commit 3e3085c

Please sign in to comment.