This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit f49633b444ed7e42a14e3b02879aac721ed504a2 Author: amghirbi <[email protected]> AuthorDate: Wed May 7 16:33:57 2025 +0200 JAMES-4130 creating interface GuiceLoader making guiceLoader an interface and GuiceGenericLoader is implementing it --- .../org/apache/james/utils/GuiceGenericLoader.java | 10 ++++-- .../java/org/apache/james/utils/GuiceLoader.java | 40 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/server/container/guice/utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java b/server/container/guice/utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java index 76e2391a99..09cf9cb534 100644 --- a/server/container/guice/utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java +++ b/server/container/guice/utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java @@ -33,7 +33,7 @@ import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.util.Modules; -public class GuiceGenericLoader { +public class GuiceGenericLoader implements GuiceLoader { private static final Logger LOGGER = LoggerFactory.getLogger(GuiceGenericLoader.class); @VisibleForTesting @@ -41,7 +41,7 @@ public class GuiceGenericLoader { return new GuiceGenericLoader(Guice.createInjector(), extendedClassLoader, ExtensionConfiguration.DEFAULT); } - public static class InvocationPerformer<T> { + public static class InvocationPerformer<T> implements GuiceLoader.InvocationPerformer<T> { private final Injector injector; private final ExtendedClassLoader extendedClassLoader; private final NamingScheme namingScheme; @@ -52,6 +52,7 @@ public class GuiceGenericLoader { this.namingScheme = namingScheme; } + @Override public T instantiate(ClassName className) throws ClassNotFoundException { try { Class<T> clazz = locateClass(className); @@ -80,10 +81,12 @@ public class GuiceGenericLoader { return (Stream) extendedClassLoader.locateClass(className).stream(); } + @Override public InvocationPerformer<T> withChildModule(Module childModule) { return new InvocationPerformer<>(injector.createChildInjector(childModule), extendedClassLoader, namingScheme); } + @Override public InvocationPerformer<T> withNamingSheme(NamingScheme namingSheme) { return new InvocationPerformer<>(injector, extendedClassLoader, namingSheme); } @@ -110,15 +113,18 @@ public class GuiceGenericLoader { .instantiate(className); } + @Override public <T> T instantiate(ClassName className) throws ClassNotFoundException { return new InvocationPerformer<T>(injector, extendedClassLoader, NamingScheme.IDENTITY) .instantiate(className); } + @Override public <T> InvocationPerformer<T> withNamingSheme(NamingScheme namingSheme) { return new InvocationPerformer<>(injector, extendedClassLoader, namingSheme); } + @Override public <T> InvocationPerformer<T> withChildModule(Module childModule) { return new InvocationPerformer<>(injector.createChildInjector(childModule), extendedClassLoader, NamingScheme.IDENTITY); } diff --git a/server/container/guice/utils/src/main/java/org/apache/james/utils/GuiceLoader.java b/server/container/guice/utils/src/main/java/org/apache/james/utils/GuiceLoader.java new file mode 100644 index 0000000000..04014ab0f7 --- /dev/null +++ b/server/container/guice/utils/src/main/java/org/apache/james/utils/GuiceLoader.java @@ -0,0 +1,40 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.utils; + +import com.google.inject.Module; + +public interface GuiceLoader { + + public interface InvocationPerformer<T> { + + T instantiate(ClassName className) throws ClassNotFoundException; + + InvocationPerformer<T> withChildModule(Module childModule); + + InvocationPerformer<T> withNamingSheme(NamingScheme namingSheme); + } + + <T> T instantiate(ClassName className) throws ClassNotFoundException; + + <T> InvocationPerformer<T> withNamingSheme(NamingScheme namingSheme); + + <T> InvocationPerformer<T> withChildModule(Module childModule); +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
