http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java b/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java index f21cf02..f498193 100644 --- a/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java +++ b/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java @@ -18,6 +18,9 @@ */ package org.apache.tamaya.resource; +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.spi.ServiceContextManager; + import java.net.URL; import java.util.Arrays; import java.util.Collection; @@ -45,7 +48,7 @@ import java.util.Collection; public interface ResourceResolver { /** - * Resolves resource expressions to a list of {@link URL}s. Hereby + * Resolves resource expressions to a createList of {@link URL}s. Hereby * the ordering of format matches the input of the resolved expressions. Nevertheless be aware that * there is no determined ordering of format located within a classloader. * @@ -54,16 +57,10 @@ public interface ResourceResolver { * null. * . */ - default Collection<URL> getResources(Collection<String> expressions) { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = getClass().getClassLoader(); - } - return getResources(cl, expressions); - } + Collection<URL> getResources(Collection<String> expressions); /** - * Resolves resource expressions to a list of {@link URL}s. Hereby + * Resolves resource expressions to a createList of {@link URL}s. Hereby * the ordering of format matches the input of the resolved expressions. Nevertheless be aware that * there is no determined ordering of format located within a classloader. * @@ -77,36 +74,37 @@ public interface ResourceResolver { } /** - * Resolves resource expressions to a list of {@link URL}s, considerubg - * the given classloader for classloader dependent format. Hereby - * the ordering of format matches the input of the resolved expressions. Nevertheless be aware that - * there is no determined ordering of format located within a classloader. - * - * @param classLoader classloader to use for resolving. - * @param expressions the expressions to be resolved, not empty. - * @return the corresponding collection of current {@link URL}s found, never {@code null}. + * Access the currently registered {@link ResourceLocator} instances. + * @return the currently known {@link ResourceLocator} instances, never null. */ - default Collection<URL> getResources(ClassLoader classLoader, String... expressions){ - return getResources(classLoader, Arrays.asList(expressions)); - } + Collection<ResourceLocator> getResourceLocators(); /** - * Resolves resource expressions to a list of {@link URL}s, considerubg - * the given classloader for classloader dependent format. Hereby - * the ordering of format matches the input of the resolved expressions. Nevertheless be aware that - * there is no determined ordering of format located within a classloader. + * <p>Access the current ResourceResolver using the default classloader.</p> * - * @param classLoader classloader to use for resolving. - * @param expressions the expressions to be resolved, not empty. - * @return the corresponding collection of current {@link URL}s found, - * never {@code null}. + * @throws ConfigException if no ResourceResolver is available (should not happen). + * + * @return the current ResourceResolver instance, never null. + * @see ServiceContextManager#getDefaultClassLoader() */ - Collection<URL> getResources(ClassLoader classLoader, Collection<String> expressions); + static ResourceResolver current() throws ConfigException { + return current(ServiceContextManager.getDefaultClassLoader()); + } /** - * Access the currently registered {@link ResourceLocator} instances. - * @return the currently known {@link ResourceLocator} instances, never null. + * <p>Access the current ResourceResolver.</p> + * + * @throws ConfigException if no ResourceResolver is available (should not happen). + * + * @return the current ResourceResolver instance, never null. */ - Collection<ResourceLocator> getResourceLocators(); + static ResourceResolver current(ClassLoader classLoader) throws ConfigException { + ResourceResolver resolver = ServiceContextManager.getServiceContext(classLoader) + .getService(ResourceResolver.class); + if (resolver == null) { + throw new ConfigException("ResourceResolver not available."); + } + return resolver; + } }
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java index d5a8d8b..bffe7c4 100644 --- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java +++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java @@ -279,8 +279,8 @@ public class ClasspathCollector { /** * Method that collects resources from a JBoss classloading system using Vfs. - * @param rootResource the root resource for evaluating its getChildren. - * @param locationPattern the sub pattern that all getChildren must mach, so they are selected. + * @param rootResource the root resource for evaluating its getList. + * @param locationPattern the sub pattern that all getList must mach, so they are selected. * @return the resources found, never null. * @throws IOException */ @@ -355,7 +355,7 @@ public class ClasspathCollector { /** * Visitor method. * - * @param vfsResource the vfsResource object. + * @param vfsResource the vfsResource createObject. */ public void visit(Object vfsResource) { String subPath = VfsSupport.getPath(vfsResource).substring(this.rootPath.length()); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java index b04b8ce..1254cea 100644 --- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java +++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java @@ -18,8 +18,9 @@ */ package org.apache.tamaya.resource.internal; -import org.apache.tamaya.resource.BaseResourceResolver; import org.apache.tamaya.resource.ResourceLocator; +import org.apache.tamaya.resource.ResourceResolver; +import org.apache.tamaya.spi.ClassloaderAware; import org.apache.tamaya.spi.ServiceContextManager; import org.osgi.service.component.annotations.Component; @@ -28,6 +29,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.logging.Logger; /** @@ -35,12 +37,13 @@ import java.util.logging.Logger; */ @Priority(0) @Component -public class DefaultResourceResolver extends BaseResourceResolver { +public class DefaultResourceResolver implements ResourceResolver, ClassloaderAware { private static final Logger LOG = Logger.getLogger(DefaultResourceResolver.class.getName()); + private ClassLoader classLoader = ServiceContextManager.getDefaultClassLoader(); @Override - public List<URL> getResources(ClassLoader classLoader, Collection<String> expressions) { + public List<URL> getResources(Collection<String> expressions) { List<URL> resources = new ArrayList<>(); for (String expression : expressions) { for(ResourceLocator locator: getResourceLocators()){ @@ -56,9 +59,16 @@ public class DefaultResourceResolver extends BaseResourceResolver { @Override public Collection<ResourceLocator> getResourceLocators() { - return ServiceContextManager.getServiceContext( - Thread.currentThread().getContextClassLoader() - ).getServices(ResourceLocator.class); + return ServiceContextManager.getServiceContext(classLoader).getServices(ResourceLocator.class); } + @Override + public void init(ClassLoader classLoader) { + this.classLoader = Objects.requireNonNull(classLoader); + } + + @Override + public ClassLoader getClassLoader() { + return classLoader; + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java index 3e79ba3..21c8ba9 100644 --- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java +++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java @@ -76,7 +76,7 @@ public class FileCollector { * elements given by {@code subTokens}, starting at the given {@code tokenIndex}. * @param dir the directory to start * @param subTokens the overall subtoken to be analyzed - * @param tokenIndex the getIndex where in the token list to start comparing + * @param tokenIndex the getIndex where in the token createList to start comparing * @return the URLs matching the tokens */ static Collection<URL> traverseAndSelectFromChildren(File dir, List<String> subTokens, int tokenIndex) { @@ -146,21 +146,21 @@ public class FileCollector { * * @param file the file, not null. * @return the URL, never null. - * @throws java.lang.IllegalStateException if it fails to create the URL + * @throws java.lang.IllegalStateException if it fails to createObject the URL */ private static URL getURL(File file) { Objects.requireNonNull(file); try { return file.toURI().toURL(); } catch (Exception e) { - throw new IllegalStateException("Failed to create URL from file: " + file); + throw new IllegalStateException("Failed to createObject URL from file: " + file); } } /** * Constructs a sub expression, using the tokens from {@code subTokens} starting at getIndex {@code startIndex}. * - * @param subTokens the token list, not null + * @param subTokens the token createList, not null * @param startIndex the start getIndex from where tokens should be taken to produce the path. * @return the constructed path, never null. */ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/resources/src/main/java/org/apache/tamaya/resource/internal/VfsSupport.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/VfsSupport.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/VfsSupport.java index e98280f..61c29ce 100644 --- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/VfsSupport.java +++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/VfsSupport.java @@ -59,7 +59,7 @@ class VfsSupport { ClassLoader loader = VfsSupport.class.getClassLoader(); try { Class<?> vfsClass = loader.loadClass(VFS3_PKG + VFS_PROTOCOL); - methodGetRootUrl = findMethod(vfsClass, "getChild", URL.class); + methodGetRootUrl = findMethod(vfsClass, "getField", URL.class); Class<?> virtualFile = loader.loadClass(VFS3_PKG + "VirtualFile"); methodToUrl = findMethod(virtualFile, "toURL"); methodGetPathName = findMethod(virtualFile, "getPathName"); @@ -182,7 +182,7 @@ class VfsSupport { * @param name the name of the method * @param paramTypes the parameter types of the method * (may be {@code null} to indicate any signature) - * @return the Method object, or {@code null} if none found + * @return the Method createObject, or {@code null} if none found */ private static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) { Objects.requireNonNull(clazz, "Class must not be null"); @@ -203,15 +203,15 @@ class VfsSupport { /** - * Get the field represented by the supplied {@link Field field object} on the - * specified {@link Object target object}. In accordance with {@link Field#get(Object)} - * semantics, the returned value is automatically wrapped if the underlying field + * Get the field represented by the supplied {@link Field field createObject} on the + * specified {@link Object target createObject}. In accordance with {@link Field#get(Object)} + * semantics, the returned createValue is automatically wrapped if the underlying field * has a primitive type. * <p>Thrown exceptions are rethrown as {@link IllegalStateException}. * * @param field the field to current - * @param target the target object from which to current the field - * @return the field's current value + * @param target the target createObject from which to current the field + * @return the field's current createValue */ private static Object readField(Field field, Object target) { try { @@ -231,7 +231,7 @@ class VfsSupport { * * @param clazz the class to introspect * @param name the name of the field - * @return the corresponding Field object, or {@code null} if not found + * @return the corresponding Field createObject, or {@code null} if not found */ private static Field findField(Class<?> clazz, String name) { Objects.requireNonNull(clazz, "Class must not be null"); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java b/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java index a31f135..1837e39 100644 --- a/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java +++ b/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java @@ -73,10 +73,10 @@ public class AbstractPathPropertySourceProviderTest { * <p/> * <p><b>Important Hints for custom implementations</b>:</p> * <p> - * If a custom implementation should be invoked <b>before</b> the default implementations, use a value > 400 + * If a custom implementation should be invoked <b>before</b> the default implementations, use a createValue > 400 * </p> * <p> - * If a custom implementation should be invoked <b>after</b> the default implementations, use a value < 100 + * If a custom implementation should be invoked <b>after</b> the default implementations, use a createValue < 100 * </p> * <p/> * <p>Reordering of the default order of the config-sources:</p> @@ -101,7 +101,7 @@ public class AbstractPathPropertySourceProviderTest { } /** - * Returns the default ordinal used, when no ordinal is setCurrent, or the ordinal was not parseable to an int value. + * Returns the default ordinal used, when no ordinal is setCurrent, or the ordinal was not parseable to an int createValue. * * @return the default ordinal used, by default 0. */ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java index d86c74a..03b61c2 100644 --- a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java +++ b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java @@ -20,7 +20,6 @@ package org.apache.tamaya.integration.spring; import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.springframework.core.env.PropertySource; /**
