diff --git a/dist/platform/src/main/java/cloud/piranha/dist/platform/PlatformPiranhaBuilder.java b/dist/platform/src/main/java/cloud/piranha/dist/platform/PlatformPiranhaBuilder.java index 2a27cca058..d0156ab606 100644 --- a/dist/platform/src/main/java/cloud/piranha/dist/platform/PlatformPiranhaBuilder.java +++ b/dist/platform/src/main/java/cloud/piranha/dist/platform/PlatformPiranhaBuilder.java @@ -56,7 +56,7 @@ public class PlatformPiranhaBuilder { /** * Stores the InitialContext factory. */ - private String initialContextFactory = "cloud.piranha.naming.thread.ThreadInitialContextFactory"; + private String initialContextFactory = "com.manorrock.herring.thread.ThreadInitialContextFactory"; /** * Stores the verbose flag. diff --git a/dist/server/src/main/java/cloud/piranha/dist/server/ServerPiranhaBuilder.java b/dist/server/src/main/java/cloud/piranha/dist/server/ServerPiranhaBuilder.java index 85db5b0e62..e0a86fac13 100644 --- a/dist/server/src/main/java/cloud/piranha/dist/server/ServerPiranhaBuilder.java +++ b/dist/server/src/main/java/cloud/piranha/dist/server/ServerPiranhaBuilder.java @@ -56,7 +56,7 @@ public class ServerPiranhaBuilder { /** * Stores the InitialContext factory. */ - private String initialContextFactory = "cloud.piranha.naming.thread.ThreadInitialContextFactory"; + private String initialContextFactory = "com.manorrock.herring.thread.ThreadInitialContextFactory"; /** * Stores the verbose flag. diff --git a/extension/naming-cdi/pom.xml b/extension/naming-cdi/pom.xml index 3290d6465f..71943b8725 100644 --- a/extension/naming-cdi/pom.xml +++ b/extension/naming-cdi/pom.xml @@ -23,15 +23,15 @@ compile - cloud.piranha.naming - piranha-naming-impl - ${project.version} + com.manorrock.herring + herring + 23.5.0 compile - cloud.piranha.naming - piranha-naming-thread - ${project.version} + com.manorrock.herring + herring-thread + 23.5.0 compile diff --git a/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/DefaultInitialContextFactory.java b/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/DefaultInitialContextFactory.java index 25ea19ca7e..00f131b9ad 100644 --- a/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/DefaultInitialContextFactory.java +++ b/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/DefaultInitialContextFactory.java @@ -33,7 +33,7 @@ import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; -import cloud.piranha.naming.impl.DefaultInitialContext; +import com.manorrock.herring.DefaultInitialContext; /** * The default InitialContextFactory. diff --git a/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/NamingExtension.java b/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/NamingExtension.java index 1315d0906e..93eb214fca 100644 --- a/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/NamingExtension.java +++ b/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/NamingExtension.java @@ -48,7 +48,7 @@ import cloud.piranha.core.api.WebApplication; import cloud.piranha.core.api.WebApplicationExtension; -import cloud.piranha.naming.impl.DefaultInitialContext; +import com.manorrock.herring.DefaultInitialContext; import jakarta.annotation.Resource; import jakarta.enterprise.inject.spi.CDI; diff --git a/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/NamingServletRequestListener.java b/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/NamingServletRequestListener.java index 8bc290b6fc..91bd52b1e7 100644 --- a/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/NamingServletRequestListener.java +++ b/extension/naming-cdi/src/main/java/cloud/piranha/extension/naming/cdi/NamingServletRequestListener.java @@ -28,7 +28,7 @@ package cloud.piranha.extension.naming.cdi; import cloud.piranha.core.api.WebApplication; -import cloud.piranha.naming.thread.ThreadInitialContextFactory; +import com.manorrock.herring.thread.ThreadInitialContextFactory; import jakarta.servlet.ServletRequestEvent; import jakarta.servlet.ServletRequestListener; import static java.lang.System.Logger.Level.DEBUG; diff --git a/extension/naming-cdi/src/main/java/module-info.java b/extension/naming-cdi/src/main/java/module-info.java index 26357aea2e..77d6595d8c 100644 --- a/extension/naming-cdi/src/main/java/module-info.java +++ b/extension/naming-cdi/src/main/java/module-info.java @@ -37,8 +37,8 @@ exports cloud.piranha.extension.naming.cdi; opens cloud.piranha.extension.naming.cdi; requires cloud.piranha.core.api; - requires transitive cloud.piranha.naming.impl; - requires transitive cloud.piranha.naming.thread; + requires transitive com.manorrock.herring; + requires transitive com.manorrock.herring.thread; requires jakarta.annotation; requires jakarta.cdi; requires transitive java.naming; diff --git a/extension/naming/pom.xml b/extension/naming/pom.xml index fac453e9fd..1fb334ed83 100644 --- a/extension/naming/pom.xml +++ b/extension/naming/pom.xml @@ -23,15 +23,15 @@ compile - cloud.piranha.naming - piranha-naming-impl - ${project.version} + com.manorrock.herring + herring + 23.5.0 compile - cloud.piranha.naming - piranha-naming-thread - ${project.version} + com.manorrock.herring + herring-thread + 23.5.0 compile diff --git a/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingExtension.java b/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingExtension.java index c6c9bacac6..ed6103c376 100644 --- a/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingExtension.java +++ b/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingExtension.java @@ -29,7 +29,7 @@ import cloud.piranha.core.api.WebApplication; import cloud.piranha.core.api.WebApplicationExtension; -import cloud.piranha.naming.impl.DefaultInitialContext; +import com.manorrock.herring.DefaultInitialContext; import jakarta.annotation.Resource; import static java.lang.System.Logger.Level.DEBUG; import static java.lang.System.Logger.Level.WARNING; diff --git a/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingInitialContextFactory.java b/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingInitialContextFactory.java index 6ae7da1718..f9b350e761 100644 --- a/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingInitialContextFactory.java +++ b/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingInitialContextFactory.java @@ -27,7 +27,7 @@ */ package cloud.piranha.extension.naming; -import cloud.piranha.naming.impl.DefaultInitialContext; +import com.manorrock.herring.DefaultInitialContext; import java.util.Hashtable; import javax.naming.Context; import javax.naming.NamingException; diff --git a/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingServletRequestListener.java b/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingServletRequestListener.java index fdefe5cb04..cca2679dae 100644 --- a/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingServletRequestListener.java +++ b/extension/naming/src/main/java/cloud/piranha/extension/naming/NamingServletRequestListener.java @@ -28,7 +28,7 @@ package cloud.piranha.extension.naming; import cloud.piranha.core.api.WebApplication; -import cloud.piranha.naming.thread.ThreadInitialContextFactory; +import com.manorrock.herring.thread.ThreadInitialContextFactory; import jakarta.servlet.ServletRequestEvent; import jakarta.servlet.ServletRequestListener; import static java.lang.System.Logger.Level.DEBUG; diff --git a/extension/naming/src/main/java/module-info.java b/extension/naming/src/main/java/module-info.java index 09ce0a36fd..84ac97588c 100644 --- a/extension/naming/src/main/java/module-info.java +++ b/extension/naming/src/main/java/module-info.java @@ -36,8 +36,8 @@ exports cloud.piranha.extension.naming; opens cloud.piranha.extension.naming; requires cloud.piranha.core.api; - requires transitive cloud.piranha.naming.impl; - requires transitive cloud.piranha.naming.thread; + requires transitive com.manorrock.herring; + requires transitive com.manorrock.herring.thread; requires jakarta.annotation; requires transitive java.naming; } diff --git a/naming/impl/README.md b/naming/impl/README.md deleted file mode 100644 index 428403685d..0000000000 --- a/naming/impl/README.md +++ /dev/null @@ -1,22 +0,0 @@ - -# Piranha Naming Implementation - -The Piranha Naming Implementation module delivers you with a JNDI -implementation. - -Add the following dependency to your project to use it. - - - cloud.piranha.naming - piranha-naming-impl - x.y.z - - -And then you either will have to pass in the InitialContextFactory using a property - - -Djava.naming.factory.initial=cloud.piranha.naming.impl.DefaultInitialContextFactory - -or programmatically set it: - - System.getProperties().put("java.naming.factory.initial", - "cloud.piranha.naming.impl.DefaultInitialContextFactory"); diff --git a/naming/impl/pom.xml b/naming/impl/pom.xml deleted file mode 100644 index 4518ce97d2..0000000000 --- a/naming/impl/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - 4.0.0 - - - cloud.piranha.naming - project - 23.9.0-SNAPSHOT - - - piranha-naming-impl - jar - - Piranha - Naming - Impl - diff --git a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultBindingNamingEnumeration.java b/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultBindingNamingEnumeration.java deleted file mode 100644 index 6321a86a56..0000000000 --- a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultBindingNamingEnumeration.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl; - -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; -import javax.naming.Binding; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; - -/** - * The default Binding NamingEnumeration. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class DefaultBindingNamingEnumeration implements NamingEnumeration { - - /** - * Stores the list of bindings. - */ - private List list; - - /** - * Stores the iterator. - */ - private Iterator iterator; - - /** - * Constructor. - * - * @param list the list of bindings. - */ - public DefaultBindingNamingEnumeration(List list) { - this.list = list; - this.iterator = list.iterator(); - } - - /** - * Get the next binding. - * - * @return the next binding. - * @throws NamingException when a naming error occurs. - */ - @Override - public Binding next() throws NamingException { - Binding result; - checkClosed(); - if (iterator.hasNext()) { - result = iterator.next(); - } else { - throw new NoSuchElementException("Next binding was not found"); - } - return result; - } - - /** - * Does the enumeration have more elements. - * - * @return true if it does, false otherwise. - * @throws NamingException when a naming error occurs. - */ - @Override - public boolean hasMore() throws NamingException { - checkClosed(); - return iterator.hasNext(); - } - - /** - * Close the enumeration for use. - * - * @throws NamingException when a naming error occurs. - */ - @Override - public void close() throws NamingException { - checkClosed(); - list = null; - iterator = null; - } - - /** - * Does the enumeration have more elements. - * - * @return true if it does, false otherwise. - */ - @Override - public boolean hasMoreElements() { - return iterator.hasNext(); - } - - /** - * Get the next element. - * - * @return the next element. - */ - @Override - public Binding nextElement() { - return iterator.next(); - } - - /** - * Check if the enumeration has been closed. - * - * @throws NamingException when a naming error occurs. - */ - private void checkClosed() throws NamingException { - if (list == null) { - throw new NamingException("Cannot call any method on a closed NamingEnumeration"); - } - } -} diff --git a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultInitialContext.java b/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultInitialContext.java deleted file mode 100644 index 2c65929508..0000000000 --- a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultInitialContext.java +++ /dev/null @@ -1,577 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl; - -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import javax.naming.Binding; -import javax.naming.CompositeName; -import javax.naming.Context; -import javax.naming.ContextNotEmptyException; -import javax.naming.Name; -import javax.naming.NameAlreadyBoundException; -import javax.naming.NameClassPair; -import javax.naming.NameNotFoundException; -import javax.naming.NameParser; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; -import javax.naming.NotContextException; -import javax.naming.OperationNotSupportedException; - -/** - * The default InitialContext. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class DefaultInitialContext implements Context { - - /** - * Stores the one and only NameParser instance. - */ - private static final NameParser NAME_PARSER = new DefaultNameParser(); - - /** - * Stores the bindings. - */ - private final Map bindings = new ConcurrentHashMap<>(); - - /** - * Stores the closeable flag. - */ - private boolean closeable = false; - - /** - * Stores the closed flag. - */ - private boolean closed = false; - - /** - * Stores the environment. - */ - private final Map environment = new ConcurrentHashMap<>(); - - /** - * Constructor. - */ - public DefaultInitialContext() { - } - - /** - * Constructor. - * - * @param closeable the closeable flag. - */ - public DefaultInitialContext(boolean closeable) { - this.closeable = closeable; - } - - /** - * Add to the environment. - * - * @param name the name of the property. - * @param value the value of the property. - * @return the previous value, or null if none. - * @throws NamingException when a Naming error occurs. - */ - @Override - public Object addToEnvironment(String name, Object value) throws NamingException { - Object result = removeFromEnvironment(name); - environment.put(name, value); - return result; - } - - /** - * Bind the object to the given name. - * - * @param name the name. - * @param object the object. - * @throws NamingException when a naming error occurs. - */ - @Override - public void bind(Name name, Object object) throws NamingException { - checkClosed(); - String nameString = name.toString(); - bind(nameString, object); - } - - /** - * Bind the object to the given name. - * - * @param name the name. - * @param object the object. - * @throws NamingException when an naming error occurs. - */ - @Override - public void bind(String name, Object object) throws NamingException { - checkClosed(); - if (name.contains("/")) { - String[] names = name.split("/"); - DefaultInitialContext contextMap = this; - for (int i = 0; i < names.length - 1; i++) { - try { - contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); - } catch (NameNotFoundException ne) { - contextMap = (DefaultInitialContext) contextMap.createSubcontext(names[i]); - } - } - contextMap.bind(names[names.length - 1], object); - } else if (!bindings.containsKey(name)) { - bindings.put(name, object); - } else { - throw new NameAlreadyBoundException("Name '" + name + "' already bound"); - } - } - - /** - * Helper method to verify if we not are closed. - * - * @throws NamingException when the context is closed. - */ - private void checkClosed() throws NamingException { - if (closed) { - throw new NamingException("Cannot call any method on a closed context"); - } - } - - /** - * Close the context. - * - * If the closeable flag is set to true it will close the context for - * further use, otherwise this call has no effect. - * - * @throws NamingException when a naming error occurs. - */ - @Override - public void close() throws NamingException { - if (closeable) { - checkClosed(); - closed = true; - } - } - - /** - * Create a sub context. - * - * @param name the name. - * @return the sub context. - * @throws NamingException when a naming error occurs. - */ - @Override - public Context createSubcontext(Name name) throws NamingException { - checkClosed(); - return createSubcontext(name.toString()); - } - - /** - * Create a sub context. - * - * @param name the name. - * @return the sub context. - * @throws NamingException when a naming error occurs. - */ - @Override - public Context createSubcontext(String name) throws NamingException { - checkClosed(); - bindings.put(name, new DefaultInitialContext()); - return (Context) bindings.get(name); - } - - /** - * Compose the name. - * - * @param name the name. - * @param prefix the prefix. - * @return the name. - * @throws NamingException when a naming error occurs. - */ - @Override - public Name composeName(Name name, Name prefix) throws NamingException { - String returnedName = composeName(name.toString(), prefix.toString()); - return new CompositeName(returnedName); - } - - /** - * Compose the name. - * - * @param name the name. - * @param prefix the prefix. - * @return the name. - * @throws NamingException when a naming error occurs. - */ - @Override - public String composeName(String name, String prefix) throws NamingException { - if (prefix == null || !"".equals(prefix)) { - throw new NamingException("prefix is not the empty string"); - } - return name; - } - - /** - * Destroy the sub context. - * - * @param name the name. - * @throws NamingException when a naming error occurs. - */ - @Override - public void destroySubcontext(Name name) throws NamingException { - checkClosed(); - destroySubcontext(name.toString()); - } - - /** - * Destroy the sub context. - * - * @param name the name. - * @throws NamingException when a naming error occurs. - */ - @Override - public void destroySubcontext(String name) throws NamingException { - if (name.contains("/")) { - String[] names = name.split("/"); - DefaultInitialContext contextMap = this; - for (int i = 0; i < names.length - 1; i++) { - contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); - } - contextMap.destroySubcontext(names[names.length - 1]); - } else if (bindings.containsKey(name)) { - if (bindings.get(name) instanceof DefaultInitialContext subContext) { - if (subContext.bindings.isEmpty()) { - bindings.remove(name); - } else { - throw new ContextNotEmptyException("Context not empty: " + name); - } - } else { - throw new NotContextException("Not a context: " + name); - } - } else { - throw new NameNotFoundException("Unable to find name: " + name); - } - } - - /** - * Get the environment. - * - * @return the environment. - * @throws NamingException when a naming error occurs. - */ - @Override - public Hashtable getEnvironment() throws NamingException { - checkClosed(); - return new Hashtable<>(); - } - - /** - * Get the name in the namespace. - * - * @return the name in its own namespace. - * @throws NamingException when a naming error occurs. - */ - @Override - public String getNameInNamespace() throws NamingException { - checkClosed(); - throw new OperationNotSupportedException(); - } - - /** - * Get the name parser. - * - * @return the name parser. - * @param name the name. - * @throws NamingException when a serious error occurs. - */ - @Override - public NameParser getNameParser(Name name) throws NamingException { - return getNameParser(name.toString()); - } - - /** - * Get the name parser. - * - * @return the name parser. - * @param name the name parser. - * @throws NamingException when a serious error occurs. - */ - @Override - public NameParser getNameParser(String name) throws NamingException { - return NAME_PARSER; - } - - /** - * List the names in the named context. - * - * @param name the name. - * @return the enumeration. - * @throws NamingException when a naming error occurs. - */ - @Override - public NamingEnumeration list(Name name) throws NamingException { - return list(name.toString()); - } - - /** - * List the entries for the given name. - * - * @param name the name. - * @return the name class pair enumeration. - * @throws NamingException when a naming error occurs. - */ - @Override - public NamingEnumeration list(String name) throws NamingException { - return new DefaultNamingEnumeration(new ArrayList<>()); - } - - /** - * List the bindings. - * - * @param name the name. - * @return the bindings. - * @throws NamingException when a naming error occurs. - */ - @Override - public NamingEnumeration listBindings(Name name) throws NamingException { - return listBindings(name.toString()); - } - - /** - * List the bindings. - * - * @param name the name. - * @return the bindings. - * @throws NamingException when a naming error occurs. - */ - @Override - public NamingEnumeration listBindings(String name) throws NamingException { - ArrayList list = new ArrayList<>(); - DefaultInitialContext contextMap = this; - - if (name.contains("/")) { - String[] names = name.split("/"); - for (int i = 0; i < names.length - 1; i++) { - contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); - } - if (contextMap.lookup(names[names.length - 1]) instanceof DefaultInitialContext defaultInitialContext) { - contextMap = defaultInitialContext; - } else { - throw new NamingException("Name " + name + " is not a named context"); - } - } else if (bindings.containsKey(name) && bindings.get(name) instanceof DefaultInitialContext) { - contextMap = (DefaultInitialContext) bindings.get(name); - } else { - contextMap = null; - } - - if (contextMap != null) { - for (Map.Entry entry : contextMap.bindings.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - Binding binding = new Binding(key, value); - list.add(binding); - } - } - - return new DefaultBindingNamingEnumeration(list); - } - - /** - * Look the name. - * - * @param name the name. - * @return the object. - * @throws NamingException when a naming error occurs. - */ - @Override - public Object lookup(Name name) throws NamingException { - return lookup(name.toString()); - } - - /** - * Lookup the name. - * - * @param name the name. - * @return the object. - * @throws NamingException when a naming error occurs. - */ - @Override - public Object lookup(String name) throws NamingException { - checkClosed(); - if (name.contains("/")) { - String[] names = name.split("/"); - DefaultInitialContext contextMap = this; - for (int i = 0; i < names.length - 1; i++) { - contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); - } - return contextMap.lookup(names[names.length - 1]); - } else if (bindings.containsKey(name)) { - return bindings.get(name); - } else { - throw new NameNotFoundException("Name " + name + " not found"); - } - } - - /** - * Lookup the link. - * - * @param name the name. - * @return the link. - * @throws NamingException when a naming error occurs. - */ - @Override - public Object lookupLink(Name name) throws NamingException { - return lookupLink(name.toString()); - } - - /** - * Lookup the link. - * - * @param name the name. - * @return the link. - * @throws NamingException when a naming error occurs. - */ - @Override - public Object lookupLink(String name) throws NamingException { - return lookup(name); - } - - /** - * Rebind the name. - * - * @param name the name. - * @param object the object. - * @throws NamingException when a naming error occurs. - */ - @Override - public void rebind(Name name, Object object) throws NamingException { - rebind(name.toString(), object); - } - - /** - * Rebind to the given name. - * - * @param name the name. - * @param obj the object. - * @throws NamingException when a naming error occurs. - */ - @Override - public void rebind(String name, Object obj) throws NamingException { - checkClosed(); - if (name.contains("/")) { - String[] names = name.split("/"); - DefaultInitialContext contextMap = this; - for (int i = 0; i < names.length - 1; i++) { - try { - contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); - } catch (NameNotFoundException nnfe) { - contextMap.createSubcontext(names[i]); - contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); - } - } - contextMap.rebind(names[names.length - 1], obj); - } else { - bindings.put(name, obj); - } - } - - /** - * Remove the property from the environment. - * - * @param name the property name. - * @return the value, or null if not found. - * @throws NamingException when a naming error occurs. - */ - @Override - public Object removeFromEnvironment(String name) throws NamingException { - return environment.remove(name); - } - - /** - * Rename the object. - * - * @param oldName the old name. - * @param newName the new name. - * @throws NamingException when a naming error occurs. - */ - @Override - public void rename(Name oldName, Name newName) throws NamingException { - rename(oldName.toString(), newName.toString()); - } - - /** - * Rename the object. - * - * @param oldName the old name. - * @param newName the new name. - * @throws NamingException when a naming error occurs. - */ - @Override - public void rename(String oldName, String newName) throws NamingException { - checkClosed(); - try { - lookup(newName); - throw new NameAlreadyBoundException(newName); - } catch (NameNotFoundException nnfe) { - // intentionally not caught. - } - Object object = lookup(oldName); - bind(newName, object); - unbind(oldName); - } - - /** - * Unbind the specified name. - * - * @param name the name. - * @throws NamingException when a naming error occurs. - */ - @Override - public void unbind(Name name) throws NamingException { - unbind(name.toString()); - } - - /** - * Unbind the specified name. - * - * @param name the name. - * @throws NamingException when a naming error occurs. - */ - @Override - public void unbind(String name) throws NamingException { - checkClosed(); - if (name.contains("/")) { - String[] names = name.split("/"); - DefaultInitialContext contextMap = this; - for (int i = 0; i < names.length - 1; i++) { - contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); - } - contextMap.unbind(names[names.length - 1]); - } else { - bindings.remove(name); - } - } -} diff --git a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultInitialContextFactory.java b/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultInitialContextFactory.java deleted file mode 100644 index 01c290a20d..0000000000 --- a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultInitialContextFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl; - -import java.util.Hashtable; -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.spi.InitialContextFactory; - -/** - * The default InitialContextFactory. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class DefaultInitialContextFactory implements InitialContextFactory { - - /** - * Stores the initial context. - */ - private static final DefaultInitialContext INITIAL_CONTEXT = new DefaultInitialContext(); - - /** - * Get the initial context. - * - * @return the initial context. - * @param environment the environment. - * @throws NamingException when a naming error occurs. - */ - @Override - public Context getInitialContext(Hashtable environment) throws NamingException { - return INITIAL_CONTEXT; - } -} diff --git a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultNameParser.java b/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultNameParser.java deleted file mode 100644 index cee36933ab..0000000000 --- a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultNameParser.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl; - -import javax.naming.CompositeName; -import javax.naming.Name; -import javax.naming.NameParser; -import javax.naming.NamingException; - -/** - * The default NameParser. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class DefaultNameParser implements NameParser { - - /** - * Parse the name. - * - * @param name the name. - * @return the parsed name. - * @throws NamingException when a serious error occurs. - */ - @Override - public Name parse(String name) throws NamingException { - return new CompositeName(name); - } -} diff --git a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultNamingEnumeration.java b/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultNamingEnumeration.java deleted file mode 100644 index 11ed050e79..0000000000 --- a/naming/impl/src/main/java/cloud/piranha/naming/impl/DefaultNamingEnumeration.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl; - -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import javax.naming.NameClassPair; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; - -/** - * The default NamingEnumeration. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class DefaultNamingEnumeration implements NamingEnumeration { - - /** - * Stores the name class pairs. - */ - private final Enumeration nameClassPairs; - - /** - * Constructor. - * - * @param nameClassPairs the name class pairs. - */ - public DefaultNamingEnumeration(Collection nameClassPairs) { - this.nameClassPairs = Collections.enumeration(nameClassPairs); - } - - /** - * Close the enumeration. - * - * @throws NamingException when a naming error occurs. - */ - @Override - public void close() throws NamingException { - // nothing to do here. - } - - /** - * Do we have more elements? - * - * @return true if we do, false otherwise. - * @throws NamingException when a naming error occurs. - */ - @Override - public boolean hasMore() throws NamingException { - return hasMoreElements(); - } - - /** - * Do we have more elements? - * - * @return true if we do, false otherwise. - */ - @Override - public boolean hasMoreElements() { - return nameClassPairs.hasMoreElements(); - } - - /** - * Get the next element. - * - * @return the next element. - * @throws NamingException when a naming error occurs. - */ - @Override - public NameClassPair next() throws NamingException { - return nextElement(); - } - - /** - * Get the next element. - * - * @return the next element. - */ - @Override - public NameClassPair nextElement() { - return nameClassPairs.nextElement(); - } -} diff --git a/naming/impl/src/main/java/module-info.java b/naming/impl/src/main/java/module-info.java deleted file mode 100644 index df2c797202..0000000000 --- a/naming/impl/src/main/java/module-info.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * This module delivers the default JNDI integration for Piranha. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -module cloud.piranha.naming.impl { - - exports cloud.piranha.naming.impl; - opens cloud.piranha.naming.impl; - requires transitive java.naming; -} diff --git a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultBindingNamingEnumerationTest.java b/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultBindingNamingEnumerationTest.java deleted file mode 100644 index 6d01082418..0000000000 --- a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultBindingNamingEnumerationTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl.tests; - -import cloud.piranha.naming.impl.DefaultBindingNamingEnumeration; -import java.util.ArrayList; -import javax.naming.NamingException; -import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; - -/** - * The JUnit tests for the DefaultBindingNamingEnumeration class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class DefaultBindingNamingEnumerationTest { - - /** - * Test checkClosed method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testCheckClosed() throws Exception { - DefaultBindingNamingEnumeration enumeration = new DefaultBindingNamingEnumeration(new ArrayList<>()); - enumeration.close(); - assertThrows(NamingException.class, enumeration::close); - } -} diff --git a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultInitialContextFactoryTest.java b/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultInitialContextFactoryTest.java deleted file mode 100644 index 3f50d6b5bf..0000000000 --- a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultInitialContextFactoryTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl.tests; - -import cloud.piranha.naming.impl.DefaultInitialContextFactory; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.jupiter.api.Test; - -/** - * The JUnit tests for the DefaultInitialContextFactory class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class DefaultInitialContextFactoryTest { - - /** - * Test getInitialContext method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testGetInitialContext() throws Exception { - DefaultInitialContextFactory factory = new DefaultInitialContextFactory(); - assertNotNull(factory.getInitialContext(null)); - } -} diff --git a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultInitialContextTest.java b/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultInitialContextTest.java deleted file mode 100644 index 5204a69983..0000000000 --- a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultInitialContextTest.java +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl.tests; - -import cloud.piranha.naming.impl.DefaultInitialContext; -import java.util.NoSuchElementException; -import javax.naming.Binding; -import javax.naming.CompositeName; -import javax.naming.Context; -import javax.naming.ContextNotEmptyException; -import javax.naming.InitialContext; -import javax.naming.Name; -import javax.naming.NameAlreadyBoundException; -import javax.naming.NameClassPair; -import javax.naming.NameNotFoundException; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; -import javax.naming.NotContextException; -import javax.naming.OperationNotSupportedException; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; -import org.junit.jupiter.api.Test; - -/** - * The JUnit tests for the SparrowInitialContext class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class DefaultInitialContextTest { - - /** - * Test addToEnvironment method. - * - * @throws Exception when an error occurs. - */ - @Test - void testAddToEnvironment() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.addToEnvironment("test", "test"); - assertEquals("test", context.removeFromEnvironment("test")); - assertNull(context.removeFromEnvironment("test")); - } - - /** - * Test bind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testBind() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Name name = new CompositeName("name"); - context.bind(name, "value"); - assertNotNull(context.lookup(name)); - } - - /** - * Test bind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testBind2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.createSubcontext("context"); - context.bind("context/name1", "value1"); - assertNotNull(context.lookup("context/name1")); - assertEquals("value1", context.lookup("context/name1")); - context.bind("context/name2", "value2"); - assertNotNull(context.lookup("context/name2")); - assertEquals("value2", context.lookup("context/name2")); - } - - /** - * Test bind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testBind3() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Name name = new CompositeName("name"); - context.bind(name, "value"); - assertNotNull(context.lookup(name)); - assertThrows(NameAlreadyBoundException.class, () -> context.bind(name, "value")); - } - - /** - * Test close method. - * - * @throws Exception when an error occurs. - */ - @Test - void testClose() { - try { - DefaultInitialContext context = new DefaultInitialContext(); - context.close(); - } catch (NamingException ex) { - fail(); - } - } - - /** - * Test rename method. - * - * @throws Exception when an error occurs. - */ - @Test - void testClose2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("name", "value"); - context.close(); - assertThrows(NamingException.class, () -> context.rename("rename", "name")); - } - - /** - * Test createSubcontext method. - * - * @throws Exception when an error occurs. - */ - @Test - void testCreateSubcontext() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.createSubcontext(new CompositeName("context")); - context.bind("context/name1", "value1"); - assertNotNull(context.lookup("context/name1")); - } - - /** - * Test composeName method. - * - * @throws Exception when an error occurs. - */ - @Test - void testComposeName() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertNotNull(context.composeName("name", "")); - } - - /** - * Test composeName method. - * - * @throws Exception when an error occurs. - */ - @Test - void testComposeName2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertThrows(NamingException.class, () -> context.composeName("name", "kaboom")); - } - - /** - * Test composeName method. - * - * @throws Exception when an error occurs. - */ - @Test - void testComposeName3() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertThrows(NamingException.class, () -> context.composeName("name", null)); - } - - /** - * Test composeName method. - * - * @throws Exception when an error occurs. - */ - @Test - void testComposeName4() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertNotNull(context.composeName(new CompositeName("name"), new CompositeName(""))); - } - - /** - * Test destroySubcontext method. - * - * @throws Exception when an error occurs. - */ - @Test - void testDestroySubcontext() { - try { - DefaultInitialContext context = new DefaultInitialContext(); - context.createSubcontext(new CompositeName("context")); - context.destroySubcontext("context"); - } catch (NamingException ex) { - fail(); - } - } - - /** - * Test destroySubcontext method. - * - * @throws Exception when an error occurs. - */ - @Test - void testDestroySubcontext2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.createSubcontext(new CompositeName("context")); - context.bind("context/name", 12); - assertThrows(ContextNotEmptyException.class, () -> context.destroySubcontext("context")); - } - - /** - * Test destroySubcontext method. - * - * @throws Exception when an error occurs. - */ - @Test - void testDestroySubcontext3() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("name", 12); - assertThrows(NotContextException.class, () -> context.destroySubcontext("name")); - } - - /** - * Test destroySubcontext method. - * - * @throws Exception when an error occurs. - */ - @Test - void testDestroySubcontext4() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertThrows(NameNotFoundException.class, () -> context.destroySubcontext("name")); - } - - /** - * Test destroySubcontext method. - */ - @Test - void testDestroySubcontext5() { - try { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("context1/context2/name", 12); - context.unbind("context1/context2/name"); - context.destroySubcontext(new CompositeName("context1/context2")); - } catch (NamingException ex) { - fail(); - } - } - - /** - * Test destroySubcontext method. - * - * @throws Exception when an error occurs. - */ - @Test - void testDestroySubcontext6() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("context1/name", 12); - context.unbind("context1/name"); - assertThrows(NameNotFoundException.class, () -> context.destroySubcontext(new CompositeName("context1/context2"))); - } - - /** - * Test getEnvironment method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testGetEnvironment() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertNotNull(context.getEnvironment()); - } - - /** - * Test getNameInNamespace method. - * - * @throws Exception when an error occurs. - */ - @Test - void testGetNameInNamespace() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertThrows(OperationNotSupportedException.class, () -> context.getNameInNamespace()); - } - - /** - * Test getNameParser method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testGetNameParser() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertNotNull(context.getNameParser(new CompositeName())); - } - - /** - * Test getNameParser method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testGetNameParser2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertNotNull(context.getNameParser("")); - } - - /** - * Test lookup method. - * - * @throws Exception when an error occurs. - */ - @Test - void testLookup() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Name name = new CompositeName("name"); - assertThrows(NameNotFoundException.class, () -> context.lookup(name)); - } - - /** - * Test list method. - * - * @throws Exception when an error occurs. - */ - @Test - void testList() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Name name = new CompositeName("name"); - NamingEnumeration enumeration = context.list(name); - assertNotNull(enumeration); - } - - /** - * Test listBindings method. - * - * @throws Exception when an error occurs. - */ - @Test - void testListBindings() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.createSubcontext("name"); - NamingEnumeration enumeration = context.listBindings("name"); - assertNotNull(enumeration); - } - - /** - * Test listBindings method. - * - * @throws Exception when an error occurs. - */ - @Test - void testListBindings2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Context subContext = context.createSubcontext("subcontext"); - subContext.bind("name", "value"); - NamingEnumeration enumeration = context.listBindings("subcontext"); - assertNotNull(enumeration); - assertTrue(enumeration.hasMore()); - Binding binding = enumeration.next(); - assertEquals("name", binding.getName()); - assertThrows(NoSuchElementException.class, enumeration::next); - } - - /** - * Test listBindings method. - * - * @throws Exception when an error occurs. - */ - @Test - void testListBindings3() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - NamingEnumeration enumeration = context.listBindings("name"); - assertNotNull(enumeration); - enumeration.close(); - assertThrows(NamingException.class, enumeration::hasMore); - } - - /** - * Test listBindings method. - * - * @throws Exception when an error occurs. - */ - @Test - void testListBindings4() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Context subContext = context.createSubcontext("subcontext"); - subContext.bind("name", "value"); - NamingEnumeration enumeration = context.listBindings("subcontext"); - assertNotNull(enumeration); - assertTrue(enumeration.hasMoreElements()); - Binding binding = enumeration.nextElement(); - assertEquals("name", binding.getName()); - } - - /** - * Test listBindings method. - * - * @throws Exception when an error occurs. - */ - @Test - void testListBindings5() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Context subContext = context.createSubcontext("context1"); - subContext.createSubcontext("context2"); - NamingEnumeration enumeration = context.listBindings("context1/context2"); - assertNotNull(enumeration); - } - - /** - * Test listBindings method. - * - * @throws Exception when an error occurs. - */ - @Test - void testListBindings6() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Context subContext = context.createSubcontext("context1"); - subContext.bind("context2", "value"); - assertThrows(NamingException.class, () -> context.listBindings("context1/context2")); - } - - /** - * Test listBindings method. - * - * @throws Exception when an error occurs. - */ - @Test - void testListBindings7() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.createSubcontext("name"); - NamingEnumeration enumeration = context.listBindings(new CompositeName("name")); - assertNotNull(enumeration); - } - - /** - * Test listBindings method. - * - * @throws Exception when an error occurs. - */ - @Test - void testListBindings8() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("name", new InitialContext()); - NamingEnumeration enumeration = context.listBindings(new CompositeName("name")); - assertNotNull(enumeration); - } - - /** - * Test lookup method. - * - * @throws Exception when an error occurs. - */ - @Test - void testLookup2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertThrows(NameNotFoundException.class, () -> context.lookup("name")); - } - - /** - * Test lookup method. - * - * @throws Exception when an error occurs. - */ - @Test - void testLookup3() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("subContext/name", true); - assertNotNull(context.lookup("subContext/name")); - } - - /** - * Test lookup method. - * - * @throws Exception when an error occurs. - */ - @Test - void testLookup4() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("subContext/name", true); - assertThrows(NameNotFoundException.class, () -> context.lookup("subContext/subContext2/name")); - } - - /** - * Test lookupLink method. - * - * @throws Exception when an error occurs. - */ - @Test - void testLookupLink() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("name", "value"); - assertNotNull(context.lookupLink("name")); - } - - /** - * Test lookupLink method. - * - * @throws Exception when an error occurs. - */ - @Test - void testLookupLink2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("name", "value"); - assertNotNull(context.lookupLink(new CompositeName("name"))); - } - - /** - * Test rebind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testRebind() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Name name = new CompositeName("name"); - context.rebind(name, "value"); - assertNotNull(context.lookup(name)); - } - - /** - * Test rebind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testRebind2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Name name = new CompositeName("context/name"); - context.rebind(name, "value"); - assertNotNull(context.lookup(name)); - context.rebind(name, "value"); - assertNotNull(context.lookup(name)); - } - - /** - * Test rename method. - * - * @throws Exception when an error occurs. - */ - @Test - void testRename() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("name", "value"); - assertThrows(NameAlreadyBoundException.class, () -> context.rename("rename", "name")); - } - - /** - * Test rename method. - */ - @Test - void testRename2() { - try { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("name", "value"); - context.rename(new CompositeName("name"), new CompositeName("newname")); - } catch (NamingException ex) { - fail(); - } - } - - /** - * Test unbind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testUnbind() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("name", "value"); - assertNotNull(context.lookup("name")); - context.unbind("name"); - assertThrows(NameNotFoundException.class, () -> context.lookup("name")); - } - - /** - * Test unbind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testUnbind2() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - Name name = new CompositeName("name"); - context.bind(name, "value"); - assertNotNull(context.lookup(name)); - context.unbind(name); - assertThrows(NameNotFoundException.class, () -> context.lookup(name)); - } - - /** - * Test unbind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testUnbind3() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - assertThrows(NameNotFoundException.class, () -> context.unbind("composite/name")); - } - - /** - * Test unbind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testUnbind4() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("composite/name", "test"); - context.unbind("composite/name"); - assertThrows(NameNotFoundException.class, () -> context.lookup("composite/name")); - } - - /** - * Test unbind method. - * - * @throws Exception when an error occurs. - */ - @Test - void testUnbind5() throws Exception { - DefaultInitialContext context = new DefaultInitialContext(); - context.bind("composite/name", "test"); - assertThrows(NameNotFoundException.class, () -> context.unbind("composite2/name")); - } -} diff --git a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultNameParserTest.java b/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultNameParserTest.java deleted file mode 100644 index 2e1c729206..0000000000 --- a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultNameParserTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl.tests; - -import cloud.piranha.naming.impl.DefaultNameParser; -import javax.naming.Name; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.jupiter.api.Test; - -/** - * The JUnit tests for the DefaultNameParser class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class DefaultNameParserTest { - - /** - * Test parse method. - * - * @throws Exception when an error occurs. - */ - @Test - void testParse() throws Exception { - DefaultNameParser parser = new DefaultNameParser(); - Name result = parser.parse("MyName"); - assertNotNull(result); - } -} diff --git a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultNamingEnumerationTest.java b/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultNamingEnumerationTest.java deleted file mode 100644 index 6c995a69b8..0000000000 --- a/naming/impl/src/test/java/cloud/piranha/naming/impl/tests/DefaultNamingEnumerationTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.impl.tests; - -import cloud.piranha.naming.impl.DefaultNamingEnumeration; -import java.util.ArrayList; -import java.util.NoSuchElementException; -import javax.naming.NameClassPair; -import javax.naming.NamingException; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; -import org.junit.jupiter.api.Test; - -/** - * The JUnit tests for the DefaultNamingEnumeration class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class DefaultNamingEnumerationTest { - - /** - * Test close method. - */ - @Test - void testClose() { - try { - DefaultNamingEnumeration enumeration = new DefaultNamingEnumeration(new ArrayList<>()); - enumeration.close(); - } catch (NamingException ex) { - fail(); - } - } - - /** - * Test hasMore method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testHasMore() throws Exception { - DefaultNamingEnumeration enumeration = new DefaultNamingEnumeration(new ArrayList<>()); - assertFalse(enumeration.hasMore()); - } - - /** - * Test hasMoreElements method. - */ - @Test - void testHasMoreElements() { - DefaultNamingEnumeration enumeration = new DefaultNamingEnumeration(new ArrayList<>()); - assertFalse(enumeration.hasMoreElements()); - } - - /** - * Test next method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testNext() throws Exception { - DefaultNamingEnumeration enumeration = new DefaultNamingEnumeration(new ArrayList<>()); - assertThrows(NoSuchElementException.class, enumeration::next); - } - - /** - * Test next method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testNext2() throws Exception { - NameClassPair pair = new NameClassPair("name", "className"); - ArrayList list = new ArrayList<>(); - list.add(pair); - DefaultNamingEnumeration enumeration = new DefaultNamingEnumeration(list); - assertNotNull(enumeration.next()); - } - - /** - * Test nextElement method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testNextElement() throws Exception { - DefaultNamingEnumeration enumeration = new DefaultNamingEnumeration(new ArrayList<>()); - assertThrows(NoSuchElementException.class, enumeration::nextElement); - } -} diff --git a/naming/impl/src/test/java/module-info.java b/naming/impl/src/test/java/module-info.java deleted file mode 100644 index b6074d51bb..0000000000 --- a/naming/impl/src/test/java/module-info.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The module-info file for tests. - */ -module cloud.piranha.naming.impl.tests { - - exports cloud.piranha.naming.impl.tests; - opens cloud.piranha.naming.impl.tests; - requires cloud.piranha.naming.impl; - requires org.junit.jupiter.api; - requires org.junit.jupiter.engine; -} diff --git a/naming/pom.xml b/naming/pom.xml deleted file mode 100644 index fad51b6b74..0000000000 --- a/naming/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - 4.0.0 - - - cloud.piranha - project - 23.9.0-SNAPSHOT - - - cloud.piranha.naming - project - pom - - Piranha - Naming - Project - - - impl - thread - - - - UTF-8 - - - - - - cloud.piranha - bom - ${project.version} - pom - import - - - - - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.jupiter - junit-jupiter-params - test - - - diff --git a/naming/thread/README.md b/naming/thread/README.md deleted file mode 100644 index 49c7f976bd..0000000000 --- a/naming/thread/README.md +++ /dev/null @@ -1,22 +0,0 @@ - -# Piranha Naming Thread - -The Piranha Naming Thread module delivers you with Thread based JNDI -implementation. - -Add the following dependency to your project to use it. - - - cloud.piranha.naming - piranha-naming-thread - x.y.z - - -And then you either will have to pass in the InitialContextFactory using a property - - -Djava.naming.factory.initial=cloud.piranha.naming.thread.ThreadInitialContextFactory - -or programmatically set it: - - System.getProperties().put("java.naming.factory.initial", - "cloud.piranha.naming.thread.ThreadInitialContextFactory"); diff --git a/naming/thread/pom.xml b/naming/thread/pom.xml deleted file mode 100644 index 3a4e92ccbd..0000000000 --- a/naming/thread/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - 4.0.0 - - - cloud.piranha.naming - project - 23.9.0-SNAPSHOT - - - piranha-naming-thread - jar - - Piranha - Naming - Thread - - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-params - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - diff --git a/naming/thread/src/main/java/cloud/piranha/naming/thread/ThreadInitialContextFactory.java b/naming/thread/src/main/java/cloud/piranha/naming/thread/ThreadInitialContextFactory.java deleted file mode 100644 index bd143e9276..0000000000 --- a/naming/thread/src/main/java/cloud/piranha/naming/thread/ThreadInitialContextFactory.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.thread; - -import java.util.HashMap; -import java.util.Hashtable; -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.spi.InitialContextFactory; - -/** - * The Thread InitialContextFactory. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class ThreadInitialContextFactory implements InitialContextFactory { - - /** - * Stores the initial contexts by thread id. - */ - private static final HashMap INITIAL_CONTEXTS = new HashMap<>(1); - - /** - * Get the initial context. - * - * @return the initial context. - * @param environment the environment. - * @throws NamingException when a naming error occurs. - */ - @Override - public Context getInitialContext(Hashtable environment) throws NamingException { - if (INITIAL_CONTEXTS.containsKey(Thread.currentThread().getId())) { - return INITIAL_CONTEXTS.get(Thread.currentThread().getId()); - } - throw new NamingException("Initial context not available for thread: " + Thread.currentThread()); - } - - /** - * Remove the initial context. - */ - public static void removeInitialContext() { - INITIAL_CONTEXTS.remove(Thread.currentThread().getId()); - } - - /** - * Set the initial context. - * - * @param initialContext the initial context. - */ - public static void setInitialContext(Context initialContext) { - INITIAL_CONTEXTS.put(Thread.currentThread().getId(), initialContext); - } -} diff --git a/naming/thread/src/main/java/module-info.java b/naming/thread/src/main/java/module-info.java deleted file mode 100644 index 50e756c009..0000000000 --- a/naming/thread/src/main/java/module-info.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * This module delivers the Thread-based JNDI integration for Piranha. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -module cloud.piranha.naming.thread { - - exports cloud.piranha.naming.thread; - opens cloud.piranha.naming.thread; - requires transitive java.naming; -} diff --git a/naming/thread/src/test/java/cloud/piranha/naming/thread/ThreadInitialContextFactoryTest.java b/naming/thread/src/test/java/cloud/piranha/naming/thread/ThreadInitialContextFactoryTest.java deleted file mode 100644 index cac74cc518..0000000000 --- a/naming/thread/src/test/java/cloud/piranha/naming/thread/ThreadInitialContextFactoryTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package cloud.piranha.naming.thread; - -import javax.naming.InitialContext; -import javax.naming.NamingException; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; - -/** - * The JUnit tests for the ThreadInitialContextFactory class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class ThreadInitialContextFactoryTest { - - /** - * Test getInitialContext method. - */ - @Test - void testGetInitialContext() { - ThreadInitialContextFactory factory = new ThreadInitialContextFactory(); - assertThrows(NamingException.class, () -> { - factory.getInitialContext(null); - }); - } - - /** - * Test getInitialContext method. - * - * @throws NamingException when a naming error occurs. - */ - @Test - void testGetInitialContext2() throws NamingException { - ThreadInitialContextFactory factory = new ThreadInitialContextFactory(); - ThreadInitialContextFactory.setInitialContext(new InitialContext() {}); - assertNotNull(factory.getInitialContext(null)); - ThreadInitialContextFactory.removeInitialContext(); - assertThrows(NamingException.class, () -> { - factory.getInitialContext(null); - }); - } -} diff --git a/pom.xml b/pom.xml index 996261e1ab..74b412e2d5 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,6 @@ http maven micro - naming resource spring diff --git a/test/embedded/soteria-basic/src/test/java/basic/DynamicInitialContextFactory.java b/test/embedded/soteria-basic/src/test/java/basic/DynamicInitialContextFactory.java index 1ac65375ad..a01adb631d 100644 --- a/test/embedded/soteria-basic/src/test/java/basic/DynamicInitialContextFactory.java +++ b/test/embedded/soteria-basic/src/test/java/basic/DynamicInitialContextFactory.java @@ -34,7 +34,7 @@ import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; -import cloud.piranha.naming.impl.DefaultInitialContext; +import com.manorrock.herring.DefaultInitialContext; /** * The default InitialContextFactory. diff --git a/test/embedded/soteria-form/src/test/java/form/DynamicInitialContextFactory.java b/test/embedded/soteria-form/src/test/java/form/DynamicInitialContextFactory.java index a3b8b68c48..d4b80a74f4 100644 --- a/test/embedded/soteria-form/src/test/java/form/DynamicInitialContextFactory.java +++ b/test/embedded/soteria-form/src/test/java/form/DynamicInitialContextFactory.java @@ -34,7 +34,7 @@ import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; -import cloud.piranha.naming.impl.DefaultInitialContext; +import com.manorrock.herring.DefaultInitialContext; /** * The default InitialContextFactory.