You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/01/03 12:59:10 UTC
[01/27] incubator-tamaya git commit: TAMAYA-37: Added PropertyFilter
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 0791e8713 -> 95885781e
TAMAYA-37: Added PropertyFilter
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/cdb4d13d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/cdb4d13d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/cdb4d13d
Branch: refs/heads/master
Commit: cdb4d13d39bee53220f740226ff42efeba609f4a
Parents: 0791e87
Author: anatole <an...@apache.org>
Authored: Fri Jan 2 11:15:38 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Fri Jan 2 11:15:38 2015 +0100
----------------------------------------------------------------------
.../apache/tamaya/spi/ConfigurationContext.java | 64 +++++++++++++++++---
.../org/apache/tamaya/spi/PropertyFilter.java | 53 ++++++++++++++++
2 files changed, 108 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/cdb4d13d/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index 370683d..3dc0daa 100644
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.spi;
import java.util.List;
import java.util.Map;
+import java.util.function.UnaryOperator;
/**
* Central SPI for programmatically dealing with the setup of the configuration system.
@@ -38,12 +39,14 @@ public interface ConfigurationContext {
void addPropertySources(PropertySource... propertySourcesToAdd);
/**
- * This method returns the list of registered PropertySources ordered via their ordinal.
+ * This method returns the current list of registered PropertySources ordered via their ordinal.
* PropertySources with a lower ordinal come first. The PropertySource with the
* highest ordinal comes last.
* If two PropertySources have the same ordinal number they will get sorted
* using their class name just to ensure the user at least gets the same ordering
* after a JVM restart.
+ * PropertySources are loaded when this method is called the first time, which basically is
+ * when the first time configuration is accessed.
*
* @return sorted list of registered PropertySources
*/
@@ -63,33 +66,76 @@ public interface ConfigurationContext {
* <p>
* This method returns the Map of registered PropertyConverters
* per type.
+ * The List for each type is ordered via their {@link javax.annotation.Priority} and
+ * cladd name. Refer also to {@link #getPropertyConverters()}.
+ * </p>
+ * <p>
+ * A simplified scenario could be like:
+ * <pre>
+ * {
+ * Date.class -> {StandardDateConverter, TimezoneDateConverter, MyCustomDateConverter }
+ * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
+ * Integer.class -> {DynamicDefaultConverter}
+ * }
+ * </pre>
+ * </p>
+ *
+ * @return map with sorted list of registered PropertySources per type.
+ */
+ Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters();
+
+ /**
+ * <p>
+ * This method returns the registered PropertyConverters for a given type.
* The List for each type is ordered via their {@link javax.annotation.Priority}.
* </p>
*
* <p>
- * PropertyConverters with a lower Priority come first. The PropertyConverter with the
- * highest Priority comes last.
+ * PropertyConverters with a higher Priority come first. The PropertyConverter with the
+ * lowest Priority comes last.
* If two PropertyConverter have the same ordinal number they will get sorted
* using their class name just to ensure the user at least gets the same ordering
* after a JVM restart.
* </p>
*
* <p>
+ * Additionally if a PropertyProvider is accessed, which is not registered the implementation
+ * should try to figure out, if there could be a default implementation as follows:
+ * <ol>
+ * <le>Look for static factory methods: {@code of(String), valueOf(String), getInstance(String),
+ * instanceOf(String), fomr(String)}</le>
+ * <le>Look for a matching constructor: {@code T(String)}.</le>
+ * </ol>
+ * If a correspoding factory method or constructor could be found, a corresponding
+ * PropertyConverter should be created and registered automatically for the given
+ * type.
+ * </p>
+ *
+ * <p>
* The scenario could be like:
* <pre>
* {
- * Date.class -> {StandardDateConverter, TimezoneDateConverter, MyCustomDateConverter }
+ * Date.class -> {MyCustomDateConverter,StandardDateConverter, TimezoneDateConverter}
* Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
+ * Integer.class -> {DynamicDefaultConverter}
* }
* </pre>
* </p>
*
- * TODO: we need to define in which order the converters will be used later!
+ * <p>
+ * The converters returned for a type should be used as a chain, whereas the result of the
+ * first converter that is able to convert the configured value, is taken as the chain's result.
+ * No more converters are called after a converter has successfully converted the input into
+ * the required target type.
+ * </p>
*
- * @return map with sorted list of registered PropertySources per type.
+ * @return a sorted list of registered PropertySources per type.
*/
- Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters();
+ <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> type);
-
- //X TODO add a way to manage and use PropertyFilters
+ /**
+ * Access the current PropertyFilter instances.
+ * @return the list of registered PropertyFilters, never null.
+ */
+ List<PropertyFilter> getPropertyFilters();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/cdb4d13d/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java b/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
new file mode 100644
index 0000000..7479008
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+
+import java.util.Map;
+
+/**
+ * <p>Interface for filtering the current map of properties during the evaluation of the chain of PropertySources.
+ * Filters can be registered using the {@link org.apache.tamaya.spi.ServiceContext}. The ordinal
+ * hereby is defined by the corresponding {@code @Priority} annotation.</p>
+ * <p>Filters </p>
+ */
+public interface PropertyFilter<T>{
+
+ /**
+ * <p>Maps the current {@code valueToBeFiltered} value to a new value. The resulting value will be used as the result
+ * passed to the user.</p>
+ * <p>If a filter is currently not available, it should just pass the input map to the method's
+ * output.</p>
+ * <p>Returning {@code null} will remove the entry and Optional.empty() will be returned to the user.</p>
+ * <h3>Implementation specification</h3>
+ * Implementations of this class must be
+ * <ul>
+ * <li>reentrant</li>
+ * <li>thread-safe</li>
+ * </ul>
+ *
+ * @param key the key accessed, not null.
+ * @param valueToBeFiltered the value to be filtered, not null.
+ * @param currentMap the current input property map, not null. Can be used for resolution of the filtered value
+ * or as datasource for additional meta-information, such as categories, sensitivity etc.
+ * @return the filtered map, never null.
+ */
+ String filterProperty(String key, String valueToBeFiltered, Map<String,String> currentMap);
+
+}
[17/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java
new file mode 100644
index 0000000..bfb8182
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java
@@ -0,0 +1,779 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.util.StringUtils;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * PathMatcher implementation for Ant-style path patterns. Examples are provided below.
+ *
+ * <p>Part current this annotation code has been kindly borrowed from <a href="http://ant.apache.org">Apache Ant</a>.
+ *
+ * <p>The annotation matches URLs using the following rules:<br> <ul> <li>? matches one character</li> <li>* matches zero
+ * or more characters</li> <li>** matches zero or more 'directories' in a path</li> </ul>
+ *
+ * <p>Some examples:<br> <ul> <li>{@code com/t?st.jsp} - matches {@code com/testdata.jsp} but also
+ * {@code com/tast.jsp} or {@code com/txst.jsp}</li> <li>{@code com/*.jsp} - matches all
+ * {@code .jsp} files in the {@code com} directory</li> <li>{@code com/**/testdata.jsp} - matches all
+ * {@code testdata.jsp} files underneath the {@code com} path</li> <li>{@code org/springframework/**/*.jsp}
+ * - matches all {@code .jsp} files underneath the {@code org/springframework} path</li>
+ * <li>{@code org/**/servlet/bla.jsp} - matches {@code org/springframework/servlet/bla.jsp} but also
+ * {@code org/springframework/testing/servlet/bla.jsp} and {@code org/servlet/bla.jsp}</li> </ul>
+ *
+ * @author Alef Arendsen
+ * @author Juergen Hoeller
+ * @author Rob Harrop
+ * @author Arjen Poutsma
+ * @author Rossen Stoyanchev
+ * @since 16.07.2003
+ */
+class AntPathMatcher {
+
+ /** Default path separator: "/" */
+ public static final String DEFAULT_PATH_SEPARATOR = "/";
+
+ private static final int CACHE_TURNOFF_THRESHOLD = 65536;
+
+ private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
+
+
+ private String pathSeparator;
+
+ private PathSeparatorPatternCache pathSeparatorPatternCache;
+
+ private boolean trimTokens = true;
+
+ private volatile Boolean cachePatterns;
+
+ private final Map<String, String[]> tokenizedPatternCache = new ConcurrentHashMap<>(256);
+
+ final Map<String, AntPathStringMatcher> stringMatcherCache = new ConcurrentHashMap<>(256);
+
+
+ /**
+ * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
+ */
+ public AntPathMatcher() {
+ this.pathSeparator = DEFAULT_PATH_SEPARATOR;
+ this.pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR);
+ }
+
+ /**
+ * A convenience alternative constructor to use with a custom path separator.
+ * @param pathSeparator the path separator to use, must not be {@code null}.
+ * @since 4.1
+ */
+ public AntPathMatcher(String pathSeparator) {
+ Objects.requireNonNull(pathSeparator, "'pathSeparator' is required");
+ this.pathSeparator = pathSeparator;
+ this.pathSeparatorPatternCache = new PathSeparatorPatternCache(pathSeparator);
+ }
+
+
+ /**
+ * Set the path separator to use for pattern parsing.
+ * Default is "/", as in Ant.
+ */
+ public void setPathSeparator(String pathSeparator) {
+ this.pathSeparator = (pathSeparator != null ? pathSeparator : DEFAULT_PATH_SEPARATOR);
+ this.pathSeparatorPatternCache = new PathSeparatorPatternCache(this.pathSeparator);
+ }
+
+ /**
+ * Specify whether to trim tokenized paths and patterns.
+ * Default is {@code true}.
+ */
+ public void setTrimTokens(boolean trimTokens) {
+ this.trimTokens = trimTokens;
+ }
+
+ /**
+ * Specify whether to cache parsed pattern metadata for patterns passed
+ * into this matcher's {@link #match} method. A keys current {@code true}
+ * activates an unlimited pattern cache; a keys current {@code false} turns
+ * the pattern cache off completely.
+ * <p>Default is for the cache to be on, but with the variant to automatically
+ * turn it off when encountering too many patterns to cache at runtime
+ * (the threshold is 65536), assuming that arbitrary permutations current patterns
+ * are coming in, with little chance for encountering a reoccurring pattern.
+ * @see #getStringMatcher(String)
+ */
+ public void setCachePatterns(boolean cachePatterns) {
+ this.cachePatterns = cachePatterns;
+ }
+
+ private void deactivatePatternCache() {
+ this.cachePatterns = false;
+ this.tokenizedPatternCache.clear();
+ this.stringMatcherCache.clear();
+ }
+
+
+ public boolean isPattern(String path) {
+ return (path.indexOf('*') != -1 || path.indexOf('?') != -1);
+ }
+
+ public boolean match(String pattern, String path) {
+ return doMatch(pattern, path, true, null);
+ }
+
+ public boolean matchStart(String pattern, String path) {
+ return doMatch(pattern, path, false, null);
+ }
+
+ /**
+ * Actually match the given {@code path} against the given {@code pattern}.
+ * @param pattern the pattern to match against
+ * @param path the path String to testdata
+ * @param fullMatch whether a full pattern match is required (else a pattern match
+ * as far as the given base path goes is sufficient)
+ * @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't
+ */
+ protected boolean doMatch(String pattern, String path, boolean fullMatch, Map<String, String> uriTemplateVariables) {
+ if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
+ return false;
+ }
+
+ String[] pattDirs = tokenizePattern(pattern);
+ String[] pathDirs = tokenizePath(path);
+
+ int pattIdxStart = 0;
+ int pattIdxEnd = pattDirs.length - 1;
+ int pathIdxStart = 0;
+ int pathIdxEnd = pathDirs.length - 1;
+
+ // Match all elements up to the first **
+ while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ String pattDir = pattDirs[pattIdxStart];
+ if ("**".equals(pattDir)) {
+ break;
+ }
+ if (!matchStrings(pattDir, pathDirs[pathIdxStart], uriTemplateVariables)) {
+ return false;
+ }
+ pattIdxStart++;
+ pathIdxStart++;
+ }
+
+ if (pathIdxStart > pathIdxEnd) {
+ // Path is exhausted, only match if rest current pattern is * or **'s
+ if (pattIdxStart > pattIdxEnd) {
+ return (pattern.endsWith(this.pathSeparator) ? path.endsWith(this.pathSeparator) :
+ !path.endsWith(this.pathSeparator));
+ }
+ if (!fullMatch) {
+ return true;
+ }
+ if (pattIdxStart == pattIdxEnd && pattDirs[pattIdxStart].equals("*") && path.endsWith(this.pathSeparator)) {
+ return true;
+ }
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+ return true;
+ }
+ else if (pattIdxStart > pattIdxEnd) {
+ // String not exhausted, but pattern is. Failure.
+ return false;
+ }
+ else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) {
+ // Path start definitely matches due to "**" part in pattern.
+ return true;
+ }
+
+ // up to last '**'
+ while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ String pattDir = pattDirs[pattIdxEnd];
+ if (pattDir.equals("**")) {
+ break;
+ }
+ if (!matchStrings(pattDir, pathDirs[pathIdxEnd], uriTemplateVariables)) {
+ return false;
+ }
+ pattIdxEnd--;
+ pathIdxEnd--;
+ }
+ if (pathIdxStart > pathIdxEnd) {
+ // String is exhausted
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ while (pattIdxStart != pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ int patIdxTmp = -1;
+ for (int i = pattIdxStart + 1; i <= pattIdxEnd; i++) {
+ if (pattDirs[i].equals("**")) {
+ patIdxTmp = i;
+ break;
+ }
+ }
+ if (patIdxTmp == pattIdxStart + 1) {
+ // '**/**' situation, so skip one
+ pattIdxStart++;
+ continue;
+ }
+ // Find the pattern between padIdxStart & padIdxTmp in str between
+ // strIdxStart & strIdxEnd
+ int patLength = (patIdxTmp - pattIdxStart - 1);
+ int strLength = (pathIdxEnd - pathIdxStart + 1);
+ int foundIdx = -1;
+
+ strLoop:
+ for (int i = 0; i <= strLength - patLength; i++) {
+ for (int j = 0; j < patLength; j++) {
+ String subPat = pattDirs[pattIdxStart + j + 1];
+ String subStr = pathDirs[pathIdxStart + i + j];
+ if (!matchStrings(subPat, subStr, uriTemplateVariables)) {
+ continue strLoop;
+ }
+ }
+ foundIdx = pathIdxStart + i;
+ break;
+ }
+
+ if (foundIdx == -1) {
+ return false;
+ }
+
+ pattIdxStart = patIdxTmp;
+ pathIdxStart = foundIdx + patLength;
+ }
+
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Tokenize the given path pattern into parts, based on this matcher's settings.
+ * <p>Performs caching based on {@link #setCachePatterns}, delegating to
+ * {@link #tokenizePath(String)} for the actual tokenization algorithm.
+ * @param pattern the pattern to tokenize
+ * @return the tokenized pattern parts
+ */
+ protected String[] tokenizePattern(String pattern) {
+ String[] tokenized = null;
+ Boolean cachePatterns = this.cachePatterns;
+ if (cachePatterns == null || cachePatterns) {
+ tokenized = this.tokenizedPatternCache.get(pattern);
+ }
+ if (tokenized == null) {
+ tokenized = tokenizePath(pattern);
+ if (cachePatterns == null && this.tokenizedPatternCache.size() >= CACHE_TURNOFF_THRESHOLD) {
+ // Try to adapt to the runtime situation that we're encountering:
+ // There are obviously too many different patterns coming in here...
+ // So let's turn off the cache since the patterns are unlikely to be reoccurring.
+ deactivatePatternCache();
+ return tokenized;
+ }
+ if (cachePatterns == null || cachePatterns) {
+ this.tokenizedPatternCache.put(pattern, tokenized);
+ }
+ }
+ return tokenized;
+ }
+
+ /**
+ * Tokenize the given path String into parts, based on this matcher's settings.
+ * @param path the path to tokenize
+ * @return the tokenized path parts
+ */
+ protected String[] tokenizePath(String path) {
+ return StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
+ }
+
+ /**
+ * Tests whether or not a string matches against a pattern.
+ * @param pattern the pattern to match against (never {@code null})
+ * @param str the String which must be matched against the pattern (never {@code null})
+ * @return {@code true} if the string matches against the pattern, or {@code false} otherwise
+ */
+ private boolean matchStrings(String pattern, String str, Map<String, String> uriTemplateVariables) {
+ return getStringMatcher(pattern).matchStrings(str, uriTemplateVariables);
+ }
+
+ /**
+ * Build or retrieve an {@link AntPathStringMatcher} for the given pattern.
+ * <p>The default implementation checks this AntPathMatcher's internal cache
+ * (see {@link #setCachePatterns}), creating a new AntPathStringMatcher instance
+ * if no cached copy is found.
+ * When encountering too many patterns to cache at runtime (the threshold is 65536),
+ * it turns the default cache off, assuming that arbitrary permutations current patterns
+ * are coming in, with little chance for encountering a reoccurring pattern.
+ * <p>This method may get overridden to implement a custom cache strategy.
+ * @param pattern the pattern to match against (never {@code null})
+ * @return a corresponding AntPathStringMatcher (never {@code null})
+ * @see #setCachePatterns
+ */
+ protected AntPathStringMatcher getStringMatcher(String pattern) {
+ AntPathStringMatcher matcher = null;
+ Boolean cachePatterns = this.cachePatterns;
+ if (cachePatterns == null || cachePatterns) {
+ matcher = this.stringMatcherCache.get(pattern);
+ }
+ if (matcher == null) {
+ matcher = new AntPathStringMatcher(pattern);
+ if (cachePatterns == null && this.stringMatcherCache.size() >= CACHE_TURNOFF_THRESHOLD) {
+ // Try to adapt to the runtime situation that we're encountering:
+ // There are obviously too many different patterns coming in here...
+ // So let's turn off the cache since the patterns are unlikely to be reoccurring.
+ deactivatePatternCache();
+ return matcher;
+ }
+ if (cachePatterns == null || cachePatterns) {
+ this.stringMatcherCache.put(pattern, matcher);
+ }
+ }
+ return matcher;
+ }
+
+ /**
+ * Given a pattern and a full path, determine the pattern-mapped part. <p>For example: <ul>
+ * <li>'{@code /docs/cvs/commit.html}' and '{@code /docs/cvs/commit.html} -> ''</li>
+ * <li>'{@code /docs/*}' and '{@code /docs/cvs/commit} -> '{@code cvs/commit}'</li>
+ * <li>'{@code /docs/cvs/*.html}' and '{@code /docs/cvs/commit.html} -> '{@code commit.html}'</li>
+ * <li>'{@code /docs/**}' and '{@code /docs/cvs/commit} -> '{@code cvs/commit}'</li>
+ * <li>'{@code /docs/**\/*.html}' and '{@code /docs/cvs/commit.html} -> '{@code cvs/commit.html}'</li>
+ * <li>'{@code /*.html}' and '{@code /docs/cvs/commit.html} -> '{@code docs/cvs/commit.html}'</li>
+ * <li>'{@code *.html}' and '{@code /docs/cvs/commit.html} -> '{@code /docs/cvs/commit.html}'</li>
+ * <li>'{@code *}' and '{@code /docs/cvs/commit.html} -> '{@code /docs/cvs/commit.html}'</li> </ul>
+ * <p>Assumes that {@link #match} returns {@code true} for '{@code pattern}' and '{@code path}', but
+ * does <strong>not</strong> enforce this.
+ */
+ public String extractPathWithinPattern(String pattern, String path) {
+ String[] patternParts = StringUtils.tokenizeToStringArray(pattern, this.pathSeparator, this.trimTokens, true);
+ String[] pathParts = StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
+ StringBuilder builder = new StringBuilder();
+ boolean pathStarted = false;
+
+ for (int segment = 0; segment < patternParts.length; segment++) {
+ String patternPart = patternParts[segment];
+ if (patternPart.indexOf('*') > -1 || patternPart.indexOf('?') > -1) {
+ for (; segment < pathParts.length; segment++) {
+ if (pathStarted || (segment == 0 && !pattern.startsWith(this.pathSeparator))) {
+ builder.append(this.pathSeparator);
+ }
+ builder.append(pathParts[segment]);
+ pathStarted = true;
+ }
+ }
+ }
+
+ return builder.toString();
+ }
+
+ public Map<String, String> extractUriTemplateVariables(String pattern, String path) {
+ Map<String, String> variables = new LinkedHashMap<>();
+ boolean result = doMatch(pattern, path, true, variables);
+ if(!result){
+ throw new IllegalArgumentException("Pattern \"" + pattern + "\" is not a match for \"" + path + "\"");
+ }
+ return variables;
+ }
+
+ /**
+ * Combines two patterns into a new pattern that is returned.
+ * <p>This implementation simply concatenates the two patterns, unless the first pattern
+ * contains a file extension match (such as {@code *.html}. In that case, the second pattern
+ * should be included in the first, or an {@code IllegalArgumentException} is thrown.
+ * <p>For example: <table>
+ * <tr><th>Pattern 1</th><th>Pattern 2</th><th>Result</th></tr> <tr><td>/hotels</td><td>{@code
+ * null}</td><td>/hotels</td></tr> <tr><td>{@code null}</td><td>/hotels</td><td>/hotels</td></tr>
+ * <tr><td>/hotels</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels</td><td>bookings</td><td>/hotels/bookings</td></tr>
+ * <tr><td>/hotels/*</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels/**</td><td>/bookings</td><td>/hotels/**/bookings</td></tr>
+ * <tr><td>/hotels</td><td>{hotel}</td><td>/hotels/{hotel}</td></tr> <tr><td>/hotels/*</td><td>{hotel}</td><td>/hotels/{hotel}</td></tr>
+ * <tr><td>/hotels/**</td><td>{hotel}</td><td>/hotels/**/{hotel}</td></tr>
+ * <tr><td>/*.html</td><td>/hotels.html</td><td>/hotels.html</td></tr> <tr><td>/*.html</td><td>/hotels</td><td>/hotels.html</td></tr>
+ * <tr><td>/*.html</td><td>/*.txt</td><td>IllegalArgumentException</td></tr> </table>
+ * @param pattern1 the first pattern
+ * @param pattern2 the second pattern
+ * @return the combination current the two patterns
+ * @throws IllegalArgumentException when the two patterns cannot be combined
+ */
+ public String combine(String pattern1, String pattern2) {
+ if (!StringUtils.hasText(pattern1) && !StringUtils.hasText(pattern2)) {
+ return "";
+ }
+ if (!StringUtils.hasText(pattern1)) {
+ return pattern2;
+ }
+ if (!StringUtils.hasText(pattern2)) {
+ return pattern1;
+ }
+
+ boolean pattern1ContainsUriVar = pattern1.indexOf('{') != -1;
+ if (!pattern1.equals(pattern2) && !pattern1ContainsUriVar && match(pattern1, pattern2)) {
+ // /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
+ // However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
+ return pattern2;
+ }
+
+ // /hotels/* + /booking -> /hotels/booking
+ // /hotels/* + booking -> /hotels/booking
+ if (pattern1.endsWith(this.pathSeparatorPatternCache.getEndsOnWildCard())) {
+ return concat(pattern1.substring(0, pattern1.length() - 2), pattern2);
+ }
+
+ // /hotels/** + /booking -> /hotels/**/booking
+ // /hotels/** + booking -> /hotels/**/booking
+ if (pattern1.endsWith(this.pathSeparatorPatternCache.getEndsOnDoubleWildCard())) {
+ return concat(pattern1, pattern2);
+ }
+
+ int starDotPos1 = pattern1.indexOf("*.");
+ if (pattern1ContainsUriVar || starDotPos1 == -1 || this.pathSeparator.equals(".")) {
+ // simply concatenate the two patterns
+ return concat(pattern1, pattern2);
+ }
+ String extension1 = pattern1.substring(starDotPos1 + 1);
+ int dotPos2 = pattern2.indexOf('.');
+ String fileName2 = (dotPos2 == -1 ? pattern2 : pattern2.substring(0, dotPos2));
+ String extension2 = (dotPos2 == -1 ? "" : pattern2.substring(dotPos2));
+ String extension = extension1.startsWith("*") ? extension2 : extension1;
+ return fileName2 + extension;
+ }
+
+ private String concat(String path1, String path2) {
+ if (path1.endsWith(this.pathSeparator) || path2.startsWith(this.pathSeparator)) {
+ return path1 + path2;
+ }
+ return path1 + this.pathSeparator + path2;
+ }
+
+ /**
+ * Given a full path, returns a {@link Comparator} suitable for sorting patterns in order current explicitness.
+ * <p>The returned {@code Comparator} will {@linkplain java.util.Collections#sort(java.util.List,
+ * java.util.Comparator) sort} a list so that more specific patterns (without uri templates or wild cards) come before
+ * generic patterns. So given a list with the following patterns: <ol> <li>{@code /hotels/new}</li>
+ * <li>{@code /hotels/{hotel}}</li> <li>{@code /hotels/*}</li> </ol> the returned comparator will sort this
+ * list so that the order will be as indicated.
+ * <p>The full path given as parameter is used to testdata for exact matches. So when the given path is {@code /hotels/2},
+ * the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
+ * @param path the full path to use for comparison
+ * @return a comparator capable current sorting patterns in order current explicitness
+ */
+ public Comparator<String> getPatternComparator(String path) {
+ return new AntPatternComparator(path);
+ }
+
+
+ /**
+ * Tests whether or not a string matches against a pattern via a {@link Pattern}.
+ * <p>The pattern may contain special characters: '*' means zero or more characters; '?' means one and
+ * only one character; '{' and '}' indicate a URI template pattern. For example <tt>/users/{user}</tt>.
+ */
+ protected static class AntPathStringMatcher {
+
+ private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?\\}|[^/{}]|\\\\[{}])+?)\\}");
+
+ private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";
+
+ private final Pattern pattern;
+
+ private final List<String> variableNames = new LinkedList<>();
+
+ public AntPathStringMatcher(String pattern) {
+ StringBuilder patternBuilder = new StringBuilder();
+ Matcher m = GLOB_PATTERN.matcher(pattern);
+ int end = 0;
+ while (m.find()) {
+ patternBuilder.append(quote(pattern, end, m.start()));
+ String match = m.group();
+ if ("?".equals(match)) {
+ patternBuilder.append('.');
+ }
+ else if ("*".equals(match)) {
+ patternBuilder.append(".*");
+ }
+ else if (match.startsWith("{") && match.endsWith("}")) {
+ int colonIdx = match.indexOf(':');
+ if (colonIdx == -1) {
+ patternBuilder.append(DEFAULT_VARIABLE_PATTERN);
+ this.variableNames.add(m.group(1));
+ }
+ else {
+ String variablePattern = match.substring(colonIdx + 1, match.length() - 1);
+ patternBuilder.append('(');
+ patternBuilder.append(variablePattern);
+ patternBuilder.append(')');
+ String variableName = match.substring(1, colonIdx);
+ this.variableNames.add(variableName);
+ }
+ }
+ end = m.end();
+ }
+ patternBuilder.append(quote(pattern, end, pattern.length()));
+ this.pattern = Pattern.compile(patternBuilder.toString());
+ }
+
+ private String quote(String s, int start, int end) {
+ if (start == end) {
+ return "";
+ }
+ return Pattern.quote(s.substring(start, end));
+ }
+
+ /**
+ * Main entry point.
+ * @return {@code true} if the string matches against the pattern, or {@code false} otherwise.
+ */
+ public boolean matchStrings(String str, Map<String, String> uriTemplateVariables) {
+ Matcher matcher = this.pattern.matcher(str);
+ if (matcher.matches()) {
+ if (uriTemplateVariables != null) {
+ // SPR-8455
+ if(!(this.variableNames.size() == matcher.groupCount())) {
+ throw new IllegalStateException(
+ "The number current capturing groups in the pattern segment " + this.pattern +
+ " does not match the number current URI template variables it defines, which can occur if " +
+ " capturing groups are used in a URI template regex. Use non-capturing groups instead.");
+ }
+ for (int i = 1; i <= matcher.groupCount(); i++) {
+ String name = this.variableNames.get(i - 1);
+ String value = matcher.group(i);
+ uriTemplateVariables.put(name, value);
+ }
+ }
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+
+
+ /**
+ * The default {@link Comparator} implementation returned by
+ * {@link #getPatternComparator(String)}.
+ * <p>In order, the most "generic" pattern is determined by the following:
+ * <ul>
+ * <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
+ * <li>if the other pattern is an actual match</li>
+ * <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
+ * <li>if it's got more "*" than the other pattern</li>
+ * <li>if it's got more "{foo}" than the other pattern</li>
+ * <li>if it's shorter than the other pattern</li>
+ * </ul>
+ */
+ protected static class AntPatternComparator implements Comparator<String> {
+
+ private final String path;
+
+ public AntPatternComparator(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Compare two patterns to determine which should match first, i.e. which
+ * is the most specific regarding the current path.
+ * @return a negative integer, zero, or a positive integer as pattern1 is
+ * more specific, equally specific, or less specific than pattern2.
+ */
+ @Override
+ public int compare(String pattern1, String pattern2) {
+ PatternInfo info1 = new PatternInfo(pattern1);
+ PatternInfo info2 = new PatternInfo(pattern2);
+
+ if (info1.isLeastSpecific() && info2.isLeastSpecific()) {
+ return 0;
+ }
+ else if (info1.isLeastSpecific()) {
+ return 1;
+ }
+ else if (info2.isLeastSpecific()) {
+ return -1;
+ }
+
+ boolean pattern1EqualsPath = pattern1.equals(path);
+ boolean pattern2EqualsPath = pattern2.equals(path);
+ if (pattern1EqualsPath && pattern2EqualsPath) {
+ return 0;
+ }
+ else if (pattern1EqualsPath) {
+ return -1;
+ }
+ else if (pattern2EqualsPath) {
+ return 1;
+ }
+
+ if (info1.isPrefixPattern() && info2.getDoubleWildcards() == 0) {
+ return 1;
+ }
+ else if (info2.isPrefixPattern() && info1.getDoubleWildcards() == 0) {
+ return -1;
+ }
+
+ if (info1.getTotalCount() != info2.getTotalCount()) {
+ return info1.getTotalCount() - info2.getTotalCount();
+ }
+
+ if (info1.getLength() != info2.getLength()) {
+ return info2.getLength() - info1.getLength();
+ }
+
+ if (info1.getSingleWildcards() < info2.getSingleWildcards()) {
+ return -1;
+ }
+ else if (info2.getSingleWildcards() < info1.getSingleWildcards()) {
+ return 1;
+ }
+
+ if (info1.getUriVars() < info2.getUriVars()) {
+ return -1;
+ }
+ else if (info2.getUriVars() < info1.getUriVars()) {
+ return 1;
+ }
+
+ return 0;
+ }
+
+
+ /**
+ * Value class that holds information about the pattern, e.g. number current
+ * occurrences current "*", "**", and "{" pattern elements.
+ */
+ private static class PatternInfo {
+
+ private final String pattern;
+
+ private int uriVars;
+
+ private int singleWildcards;
+
+ private int doubleWildcards;
+
+ private boolean catchAllPattern;
+
+ private boolean prefixPattern;
+
+ private Integer length;
+
+ public PatternInfo(String pattern) {
+ this.pattern = pattern;
+ if (this.pattern != null) {
+ initCounters();
+ this.catchAllPattern = this.pattern.equals("/**");
+ this.prefixPattern = !this.catchAllPattern && this.pattern.endsWith("/**");
+ }
+ if (this.uriVars == 0) {
+ this.length = (this.pattern != null ? this.pattern.length() : 0);
+ }
+ }
+
+ protected void initCounters() {
+ int pos = 0;
+ while (pos < this.pattern.length()) {
+ if (this.pattern.charAt(pos) == '{') {
+ this.uriVars++;
+ pos++;
+ }
+ else if (this.pattern.charAt(pos) == '*') {
+ if (pos + 1 < this.pattern.length() && this.pattern.charAt(pos + 1) == '*') {
+ this.doubleWildcards++;
+ pos += 2;
+ }
+ else if (!this.pattern.substring(pos - 1).equals(".*")) {
+ this.singleWildcards++;
+ pos++;
+ }
+ else {
+ pos++;
+ }
+ }
+ else {
+ pos++;
+ }
+ }
+ }
+
+ public int getUriVars() {
+ return this.uriVars;
+ }
+
+ public int getSingleWildcards() {
+ return this.singleWildcards;
+ }
+
+ public int getDoubleWildcards() {
+ return this.doubleWildcards;
+ }
+
+ public boolean isLeastSpecific() {
+ return (this.pattern == null || this.catchAllPattern);
+ }
+
+ public boolean isPrefixPattern() {
+ return this.prefixPattern;
+ }
+
+ public int getTotalCount() {
+ return this.uriVars + this.singleWildcards + (2 * this.doubleWildcards);
+ }
+
+ /**
+ * Returns the length current the given pattern, where template variables are considered to be 1 long.
+ */
+ public int getLength() {
+ if (this.length == null) {
+ this.length = VARIABLE_PATTERN.matcher(this.pattern).replaceAll("#").length();
+ }
+ return this.length;
+ }
+ }
+ }
+
+
+ /**
+ * A simple cache for patterns that depend on the configured path separator.
+ */
+ private static class PathSeparatorPatternCache {
+
+ private final String endsOnWildCard;
+
+ private final String endsOnDoubleWildCard;
+
+ public PathSeparatorPatternCache(String pathSeparator) {
+ this.endsOnWildCard = pathSeparator + "*";
+ this.endsOnDoubleWildCard = pathSeparator + "**";
+ }
+
+ public String getEndsOnWildCard() {
+ return this.endsOnWildCard;
+ }
+
+ public String getEndsOnDoubleWildCard() {
+ return this.endsOnDoubleWildCard;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java
new file mode 100644
index 0000000..6b10e8b
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.util.StringUtils;
+import org.apache.tamaya.core.util.ClassUtils;
+import org.apache.tamaya.core.resources.Resource;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Objects;
+
+/**
+ * {@link Resource} implementation for class path resources.
+ * Uses either a given ClassLoader or a given Class for loading resources.
+ *
+ * <p>Supports resolution as {@code java.io.File} if the class path
+ * resource resides in the file system, but not for resources in a JAR.
+ * Always supports resolution as URL.
+ *
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @since 28.12.2003
+ * @see ClassLoader#getResourceAsStream(String)
+ * @see Class#getResourceAsStream(String)
+ */
+public class ClassPathResource extends AbstractFileResolvingResource {
+
+ private final String path;
+
+ private ClassLoader classLoader;
+
+ private Class<?> clazz;
+
+
+ /**
+ * Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
+ * A leading slash will be removed, as the ClassLoader resource access
+ * methods will not accept it.
+ * <p>The thread context class loader will be used for
+ * loading the resource.
+ * @param path the absolute path within the class path
+ * @see java.lang.ClassLoader#getResourceAsStream(String)
+ */
+ public ClassPathResource(String path) {
+ this(path, (ClassLoader) null);
+ }
+
+ /**
+ * Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
+ * A leading slash will be removed, as the ClassLoader resource access
+ * methods will not accept it.
+ * @param path the absolute path within the classpath
+ * @param classLoader the class loader to load the resource with,
+ * or {@code null} for the thread context class loader
+ * @see ClassLoader#getResourceAsStream(String)
+ */
+ public ClassPathResource(String path, ClassLoader classLoader) {
+ Objects.requireNonNull(path, "Path must not be null");
+ String pathToUse = StringUtils.cleanPath(path);
+ if (pathToUse.startsWith("/")) {
+ pathToUse = pathToUse.substring(1);
+ }
+ this.path = pathToUse;
+ this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
+ }
+
+ /**
+ * Create a new {@code ClassPathResource} for {@code Class} usage.
+ * The path can be relative to the given class, or absolute within
+ * the classpath via a leading slash.
+ * @param path relative or absolute path within the class path
+ * @param clazz the class to load resources with
+ * @see java.lang.Class#getResourceAsStream
+ */
+ public ClassPathResource(String path, Class<?> clazz) {
+ Objects.requireNonNull(path, "Path must not be null");
+ this.path = StringUtils.cleanPath(path);
+ this.clazz = clazz;
+ }
+
+ /**
+ * Create a new {@code ClassPathResource} with optional {@code ClassLoader}
+ * and {@code Class}. Only for internal usage.
+ * @param path relative or absolute path within the classpath
+ * @param classLoader the class loader to load the resource with, if any
+ * @param clazz the class to load resources with, if any
+ */
+ protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) {
+ this.path = StringUtils.cleanPath(path);
+ this.classLoader = classLoader;
+ this.clazz = clazz;
+ }
+
+
+ /**
+ * Return the path for this resource (as resource path within the class path).
+ */
+ public final String getPath() {
+ return this.path;
+ }
+
+ /**
+ * Return the ClassLoader that this resource will be obtained from.
+ */
+ public final ClassLoader getClassLoader() {
+ return (this.clazz != null ? this.clazz.getClassLoader() : this.classLoader);
+ }
+
+
+ /**
+ * This implementation checks for the resolution current a resource URL.
+ * @see java.lang.ClassLoader#getResource(String)
+ * @see java.lang.Class#getResource(String)
+ */
+ @Override
+ public boolean exists() {
+ return (resolveURL() != null);
+ }
+
+ /**
+ * Resolves a URL for the underlying class path resource.
+ * @return the resolved URL, or {@code null} if not resolvable
+ */
+ protected URL resolveURL() {
+ if (this.clazz != null) {
+ return this.clazz.getResource(this.path);
+ }
+ else if (this.classLoader != null) {
+ return this.classLoader.getResource(this.path);
+ }
+ else {
+ return ClassLoader.getSystemResource(this.path);
+ }
+ }
+
+ /**
+ * This implementation opens an InputStream for the given class path resource.
+ * @see java.lang.ClassLoader#getResourceAsStream(String)
+ * @see java.lang.Class#getResourceAsStream(String)
+ */
+ @Override
+ public InputStream getInputStream()throws IOException {
+ InputStream is;
+ if (this.clazz != null) {
+ is = this.clazz.getResourceAsStream(this.path);
+ }
+ else if (this.classLoader != null) {
+ is = this.classLoader.getResourceAsStream(this.path);
+ }
+ else {
+ is = ClassLoader.getSystemResourceAsStream(this.path);
+ }
+ if (is == null) {
+ throw new IOException(getDisplayName() + " cannot be opened because it does not exist");
+ }
+ return is;
+ }
+
+ /**
+ * This implementation returns a URL for the underlying class path resource,
+ * if available.
+ * @see java.lang.ClassLoader#getResource(String)
+ * @see java.lang.Class#getResource(String)
+ */
+ @Override
+ public URL toURL() throws IOException {
+ URL url = resolveURL();
+ if (url == null) {
+ throw new FileNotFoundException(getDisplayName() + " cannot be resolved to URL because it does not exist");
+ }
+ return url;
+ }
+
+ /**
+ * This implementation creates a ClassPathResource, applying the given path
+ * relative to the path current the underlying resource current this descriptor.
+ */
+ @Override
+ public Resource createRelative(String relativePath) {
+ String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
+ return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
+ }
+
+ /**
+ * This implementation returns the name current the file that this class path
+ * resource refers to.
+ */
+ @Override
+ public String getDisplayName() {
+ return StringUtils.getFilename(this.path);
+ }
+
+ /**
+ * This implementation returns a description that includes the class path location.
+ */
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder("ClassPathResource [");
+ String pathToUse = path;
+ if (this.clazz != null && !pathToUse.startsWith("/")) {
+ builder.append(ClassUtils.classPackageAsResourcePath(this.clazz));
+ builder.append('/');
+ }
+ if (pathToUse.startsWith("/")) {
+ pathToUse = pathToUse.substring(1);
+ }
+ builder.append(pathToUse);
+ builder.append(']');
+ return builder.toString();
+ }
+
+ /**
+ * This implementation compares the underlying class path locations.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof ClassPathResource) {
+ ClassPathResource otherRes = (ClassPathResource) obj;
+ return (this.path.equals(otherRes.path) &&
+ Objects.equals(this.classLoader, otherRes.classLoader) &&
+ Objects.equals(this.clazz, otherRes.clazz));
+ }
+ return false;
+ }
+
+ /**
+ * This implementation returns the hash code current the underlying
+ * class path location.
+ */
+ @Override
+ public int hashCode() {
+ return this.path.hashCode();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java
new file mode 100644
index 0000000..efeecef
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.util.StringUtils;
+import org.apache.tamaya.core.resources.Resource;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.Objects;
+
+/**
+ * {@link Resource} implementation for {@code java.io.File} handles.
+ * Obviously supports resolution as File, and also as URL.
+ *
+ * @author Juergen Hoeller
+ * @since 28.12.2003
+ * @see java.io.File
+ */
+public class FileSystemResource implements Resource {
+
+ private final File file;
+
+ private final String path;
+
+
+ /**
+ * Create a new {@code FileSystemResource} from a {@link File} handle.
+ * <p>Note: When building relative resources via {@link #createRelative},
+ * the relative path will applyChanges <i>at the same directory level</i>:
+ * e.g. new File("C:/dir1"), relative path "dir2" -> "C:/dir2"!
+ * If you prefer to have relative paths built underneath the given root
+ * directory, use the {@link #FileSystemResource(String) constructor with a file path}
+ * to append a trailing slash to the root path: "C:/dir1/", which
+ * indicates this directory as root for all relative paths.
+ * @param file a File handle
+ */
+ public FileSystemResource(File file) {
+ Objects.requireNonNull(file, "File must not be null");
+ this.file = file;
+ this.path = StringUtils.cleanPath(file.getPath());
+ }
+
+ /**
+ * Create a new {@code FileSystemResource} from a file path.
+ * <p>Note: When building relative resources via {@link #createRelative},
+ * it makes a difference whether the specified resource base path here
+ * ends with a slash or not. In the case current "C:/dir1/", relative paths
+ * will be built underneath that root: e.g. relative path "dir2" ->
+ * "C:/dir1/dir2". In the case current "C:/dir1", relative paths will applyChanges
+ * at the same directory level: relative path "dir2" -> "C:/dir2".
+ * @param path a file path
+ */
+ public FileSystemResource(String path) {
+ Objects.requireNonNull(path, "Path must not be null");
+ this.file = new File(path);
+ this.path = StringUtils.cleanPath(path);
+ }
+
+
+ /**
+ * Return the file path for this resource.
+ */
+ public final String getPath() {
+ return this.path;
+ }
+
+
+ /**
+ * This implementation returns whether the underlying file exists.
+ * @see java.io.File#exists()
+ */
+ @Override
+ public boolean exists() {
+ return this.file.exists();
+ }
+
+ /**
+ * This implementation checks whether the underlying file is marked as readable
+ * (and corresponds to an actual file with content, not to a directory).
+ * @see java.io.File#canRead()
+ * @see java.io.File#isDirectory()
+ */
+ @Override
+ public boolean isReadable() {
+ return (this.file.canRead() && !this.file.isDirectory());
+ }
+
+ /**
+ * This implementation opens a FileInputStream for the underlying file.
+ * @see java.io.FileInputStream
+ */
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return new FileInputStream(this.file);
+ }
+
+ /**
+ * This implementation returns a URL for the underlying file.
+ * @see java.io.File#toURI()
+ */
+ @Override
+ public URL toURL() throws IOException {
+ return this.file.toURI().toURL();
+ }
+
+ /**
+ * This implementation returns a URI for the underlying file.
+ * @see java.io.File#toURI()
+ */
+ @Override
+ public URI getURI() throws IOException {
+ return this.file.toURI();
+ }
+
+ /**
+ * This implementation returns the underlying File reference.
+ */
+ @Override
+ public File toFile() {
+ return this.file;
+ }
+
+ /**
+ * This implementation returns the underlying File's length.
+ */
+ @Override
+ public long contentLength() throws IOException {
+ return this.file.length();
+ }
+
+ /**
+ * This implementation creates a FileSystemResource, applying the given path
+ * relative to the path current the underlying file current this resource descriptor.
+ * @see StringUtils#applyRelativePath(String, String)
+ */
+ @Override
+ public Resource createRelative(String relativePath) {
+ String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
+ return new FileSystemResource(pathToUse);
+ }
+
+ /**
+ * This implementation returns the name current the file.
+ * @see java.io.File#getName()
+ */
+ @Override
+ public String getDisplayName() {
+ return this.file.getName();
+ }
+
+ /**
+ * This implementation returns a description that includes the absolute
+ * path current the file.
+ * @see java.io.File#getAbsolutePath()
+ */
+ @Override
+ public String toString() {
+ return "file [" + this.file.getAbsolutePath() + "]";
+ }
+
+
+ // implementation current WritableResource
+
+ /**
+ * This implementation checks whether the underlying file is marked as writable
+ * (and corresponds to an actual file with content, not to a directory).
+ * @see java.io.File#canWrite()
+ * @see java.io.File#isDirectory()
+ */
+ public boolean isWritable() {
+ return (this.file.canWrite() && !this.file.isDirectory());
+ }
+
+ /**
+ * This implementation opens a FileOutputStream for the underlying file.
+ * @see java.io.FileOutputStream
+ */
+ public OutputStream getOutputStream() throws IOException {
+ return new FileOutputStream(this.file);
+ }
+
+
+ /**
+ * This implementation compares the underlying File references.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return (obj == this ||
+ (obj instanceof FileSystemResource && this.path.equals(((FileSystemResource) obj).path)));
+ }
+
+ /**
+ * This implementation returns the hash code current the underlying File reference.
+ */
+ @Override
+ public int hashCode() {
+ return this.path.hashCode();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java
new file mode 100644
index 0000000..e956670
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.resources.Resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Objects;
+
+/**
+ * {@link Resource} implementation for a given InputStream. Should only
+ * be used if no specific Resource implementation is applicable.
+ * In particular, prefer {@code ByteArrayResource} or any current the
+ * file-based Resource implementations where possible.
+ *
+ * <p>In contrast to other Resource implementations, this is a descriptor
+ * for an <i>already opened</i> resource - therefore returning "true" from
+ * {@code isOpen()}. Do not use it if you need to keep the resource
+ * descriptor somewhere, or if you need to read a stream multiple times.
+ *
+ * @author Juergen Hoeller
+ * @since 28.12.2003
+ */
+public class InputStreamResource implements Resource {
+
+ private final InputStream inputStream;
+
+ private final String description;
+
+ private boolean read = false;
+
+
+ /**
+ * Create a new InputStreamResource.
+ * @param inputStream the InputStream to use
+ */
+ public InputStreamResource(InputStream inputStream) {
+ this(inputStream, "resource loaded through InputStream");
+ }
+
+ /**
+ * Create a new InputStreamResource.
+ * @param inputStream the InputStream to use
+ * @param description where the InputStream comes from
+ */
+ public InputStreamResource(InputStream inputStream, String description) {
+ this.inputStream = Objects.requireNonNull(inputStream);
+ this.description = (description != null ? description : "");
+ }
+
+
+ /**
+ * This implementation always returns {@code true}.
+ */
+ @Override
+ public boolean exists() {
+ return true;
+ }
+
+ /**
+ * This implementation always returns {@code true}.
+ */
+ @Override
+ public boolean isOpen() {
+ return true;
+ }
+
+ /**
+ * This implementation throws IllegalStateException if attempting to
+ * read the underlying stream multiple times.
+ */
+ @Override
+ public InputStream getInputStream() throws IOException {
+ if (this.read) {
+ throw new IllegalStateException("InputStream has already been read - " +
+ "do not use InputStreamResource if a stream needs to be read multiple times");
+ }
+ this.read = true;
+ return this.inputStream;
+ }
+
+ /**
+ * This implementation returns the passed-in description, if any.
+ */
+ public String toString() {
+ return this.description!=null?this.description:super.toString();
+ }
+
+
+ /**
+ * This implementation compares the underlying InputStream.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return (obj == this ||
+ (obj instanceof InputStreamResource && ((InputStreamResource) obj).inputStream.equals(this.inputStream)));
+ }
+
+ /**
+ * This implementation returns the hash code current the underlying InputStream.
+ */
+ @Override
+ public int hashCode() {
+ return this.inputStream.hashCode();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java
new file mode 100644
index 0000000..c70f04b
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.resources.Resource;
+import org.apache.tamaya.core.util.ClassUtils;
+import org.apache.tamaya.core.util.StringUtils;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Objects;
+
+/**
+ * <p>Will return a {@code UrlResource} if the location keys is a URL,
+ * and a {@code ClassPathResource} if it is a non-URL path or a
+ * "classpath:" pseudo-URL.
+ *
+ * @author Juergen Hoeller
+ * @since 10.03.2004
+ */
+class PathMatchingDefaultResourceLoader {
+
+ /** Pseudo URL prefix for loading from the class path: "classpath:" */
+ public static final String CLASSPATH_URL_PREFIX = "classpath:";
+
+ private ClassLoader classLoader;
+
+
+ /**
+ * Create a new DefaultResourceLoader.
+ * <p>ClassLoader access will happen using the thread context class loader
+ * at the time current this ResourceLoader's initialization.
+ * @see java.lang.Thread#getContextClassLoader()
+ */
+ public PathMatchingDefaultResourceLoader() {
+ this.classLoader = ClassUtils.getDefaultClassLoader();
+ }
+
+ /**
+ * Create a new DefaultResourceLoader.
+ * @param classLoader the ClassLoader to load class path resources with, or {@code null}
+ * for using the thread context class loader at the time current actual resource access
+ */
+ public PathMatchingDefaultResourceLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+
+ /**
+ * Specify the ClassLoader to load class path resources with, or {@code null}
+ * for using the thread context class loader at the time current actual resource access.
+ * <p>The default is that ClassLoader access will happen using the thread context
+ * class loader at the time current this ResourceLoader's initialization.
+ */
+ void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ /**
+ * Return the ClassLoader to load class path resources with.
+ * <p>Will get passed to ClassPathResource's constructor for all
+ * ClassPathResource objects created by this resource loader.
+ * @see ClassPathResource
+ */
+ public ClassLoader getClassLoader() {
+ return (this.classLoader != null ? this.classLoader : ClassUtils.getDefaultClassLoader());
+ }
+
+
+ public Resource getResource(String location) {
+ Objects.requireNonNull(location, "Location must not be null");
+ if (location.startsWith("/")) {
+ return getResourceByPath(location);
+ }
+ else if (location.startsWith(CLASSPATH_URL_PREFIX)) {
+ return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());
+ }
+ else {
+ try {
+ // Try to parse the location as a URL...
+ URL url = new URL(location);
+ return new UrlResource(url);
+ }
+ catch (MalformedURLException ex) {
+ // No URL -> resolve as resource path.
+ return getResourceByPath(location);
+ }
+ }
+ }
+
+ /**
+ * Return a Resource handle for the resource at the given path.
+ * <p>The default implementation supports class path locations. This should
+ * be appropriate for standalone implementations but can be overridden,
+ * e.g. for implementations targeted at a Servlet container.
+ * @param path the path to the resource
+ * @return the corresponding Resource handle
+ * @see ClassPathResource
+ */
+ protected Resource getResourceByPath(String path) {
+ return new ClassPathContextResource(path, getClassLoader());
+ }
+
+
+ /**
+ * ClassPathResource that explicitly expresses a context-relative path
+ * through implementing the ContextResource interface.
+ */
+ protected static class ClassPathContextResource extends ClassPathResource {
+
+ public ClassPathContextResource(String path, ClassLoader classLoader) {
+ super(path, classLoader);
+ }
+
+ public String getPathWithinContext() {
+ return getPath();
+ }
+
+ @Override
+ public Resource createRelative(String relativePath) {
+ String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
+ return new ClassPathContextResource(pathToUse, getClassLoader());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java
new file mode 100644
index 0000000..005617b
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java
@@ -0,0 +1,731 @@
+/*
+ * Copyright 2002-2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.resources.Resource;
+import org.apache.tamaya.core.util.ClassUtils;
+import org.apache.tamaya.core.util.StringUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import java.lang.reflect.InvocationHandler;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URLClassLoader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+
+/**
+ * A {@code ResourcePatternResolver} implementation that is able to resolve a
+ * specified resource location path into one or more matching Resources.
+ * The source path may be a simple path which has a one-to-one annotation to a
+ * target {@code org.springframework.core.io.Resource}, or alternatively
+ * may contain the special "{@code classpath*:}" prefix and/or
+ * internal Ant-style regular expressions (matched using Spring's
+ * {@code org.springframework.util.AntPathMatcher} utility).
+ * Both current the latter are effectively wildcards.
+ *
+ * <p><b>No Wildcards:</b>
+ *
+ * <p>In the simple case, if the specified location path does not start with the
+ * {@code "classpath*:}" prefix, and does not contain a PathMatcher pattern,
+ * this resolver will simply return a single resource via a
+ * {@code getResource()} call on the underlying {@code ResourceLoader}.
+ * Examples are real URLs such as "{@code file:C:/context.xml}", pseudo-URLs
+ * such as "{@code classpath:/context.xml}", and simple unprefixed paths
+ * such as "{@code /WEB-INF/context.xml}". The latter will resolve in a
+ * fashion specific to the underlying {@code ResourceLoader} (e.g.
+ * {@code ServletContextResource} for a {@code WebApplicationContext}).
+ *
+ * <p><b>Ant-style Patterns:</b>
+ *
+ * <p>When the path location contains an Ant-style pattern, e.g.:
+ * <pre class="code">
+ * /WEB-INF/*-context.xml
+ * com/mycompany/**/applicationContext.xml
+ * file:C:/some/path/*-context.xml
+ * classpath:com/mycompany/**/applicationContext.xml</pre>
+ * the resolver follows a more complex but defined procedure to try to resolve
+ * the wildcard. It produces a {@code Resource} for the path up to the last
+ * non-wildcard segment and obtains a {@code URL} from it. If this URL is
+ * not a "{@code jar:}" URL or container-specific variant (e.g.
+ * "{@code zip:}" in WebLogic, "{@code wsjar}" in WebSphere", etc.),
+ * then a {@code java.io.File} is obtained from it, and used to resolve the
+ * wildcard by walking the filesystem. In the case current a jar URL, the resolver
+ * either gets a {@code java.net.JarURLConnection} from it, or manually parses
+ * the jar URL, and then traverses the contents current the jar file, to resolve the
+ * wildcards.
+ *
+ * <p><b>Implications on portability:</b>
+ *
+ * <p>If the specified path is already a file URL (either explicitly, or
+ * implicitly because the base {@code ResourceLoader} is a filesystem one,
+ * then wildcarding is guaranteed to work in a completely portable fashion.
+ *
+ * <p>If the specified path is a classpath location, then the resolver must
+ * obtain the last non-wildcard path segment URL via a
+ * {@code Classloader.getResource()} call. Since this is just a
+ * node current the path (not the file at the end) it is actually undefined
+ * (in the ClassLoader Javadocs) exactly what sort current a URL is returned in
+ * this case. In practice, it is usually a {@code java.io.File} representing
+ * the directory, where the classpath resource resolves to a filesystem
+ * location, or a jar URL current some sort, where the classpath resource resolves
+ * to a jar location. Still, there is a portability concern on this operation.
+ *
+ * <p>If a jar URL is obtained for the last non-wildcard segment, the resolver
+ * must be able to get a {@code java.net.JarURLConnection} from it, or
+ * manually parse the jar URL, to be able to walk the contents current the jar,
+ * and resolve the wildcard. This will work in most environments, but will
+ * fail in others, and it is strongly recommended that the wildcard
+ * resolution current resources coming from jars be thoroughly tested in your
+ * specific environment before you rely on it.
+ *
+ * <p><b>{@code classpath*:} Prefix:</b>
+ *
+ * <p>There is special support for retrieving multiple class path resources with
+ * the same name, via the "{@code classpath*:}" prefix. For example,
+ * "{@code classpath*:META-INF/beans.xml}" will find all "beans.xml"
+ * files in the class path, be it in "classes" directories or in JAR files.
+ * This is particularly useful for autodetecting config files current the same name
+ * at the same location within each jar file. Internally, this happens via a
+ * {@code ClassLoader.getResources()} call, and is completely portable.
+ *
+ * <p>The "classpath*:" prefix can also be combined with a PathMatcher pattern in
+ * the rest current the location path, for example "classpath*:META-INF/*-beans.xml".
+ * In this case, the resolution strategy is fairly simple: a
+ * {@code ClassLoader.getResources()} call is used on the last non-wildcard
+ * path segment to get all the matching resources in the class loader hierarchy,
+ * and then off each resource the same PathMatcher resolution strategy described
+ * above is used for the wildcard subpath.
+ *
+ * <p><b>Other notes:</b>
+ *
+ * <p><b>WARNING:</b> Note that "{@code classpath*:}" when combined with
+ * Ant-style patterns will only work reliably with at least one root directory
+ * before the pattern starts, unless the actual target files reside in the file
+ * system. This means that a pattern like "{@code classpath*:*.xml}" will
+ * <i>not</i> retrieve files from the root current jar files but rather only from the
+ * root current expanded directories. This originates from a limitation in the JDK's
+ * {@code ClassLoader.getResources()} method which only returns file system
+ * locations for a passed-in empty String (indicating potential roots to search).
+ *
+ * <p><b>WARNING:</b> Ant-style patterns with "classpath:" resources are not
+ * guaranteed to find matching resources if the root package to search is available
+ * in multiple class path locations. This is because a resource such as
+ * <pre class="code">
+ * com/mycompany/package1/service-context.xml
+ * </pre>
+ * may be in only one location, but when a path such as
+ * <pre class="code">
+ * classpath:com/mycompany/**/service-context.xml
+ * </pre>
+ * is used to try to resolve it, the resolver will work off the (first) URL
+ * returned by {@code getResource("com/mycompany");}. If this base package
+ * node exists in multiple classloader locations, the actual end resource may
+ * not be underneath. Therefore, preferably, use "{@code classpath*:}" with the same
+ * Ant-style pattern in such a case, which will search <i>all</i> class path
+ * locations that contain the root package.
+ *
+ * @author Juergen Hoeller
+ * @author Colin Sampaleanu
+ * @author Marius Bogoevici
+ * @author Costin Leau
+ * @since 1.0.2
+ * @see ClassLoader#getResources(String)
+ */
+public final class PathMatchingResourcePatternResolver{
+
+ private static final Logger logger = Logger.getLogger(PathMatchingResourcePatternResolver.class.getName());
+ private static final java.lang.String CLASSPATH_ALL_URL_PREFIX = "classpath:";
+
+ private static Method equinoxResolveMethod;
+
+ static {
+ try {
+ // Detect Equinox OSGi (e.g. on WebSphere 6.1)
+ Class<?> fileLocatorClass = ClassUtils.forName("org.eclipse.core.runtime.FileLocator",
+ PathMatchingResourcePatternResolver.class.getClassLoader());
+ equinoxResolveMethod = fileLocatorClass.getMethod("resolve", URL.class);
+ logger.finest("Found Equinox FileLocator for OSGi bundle URL resolution");
+ }
+ catch (Throwable ex) {
+ equinoxResolveMethod = null;
+ }
+ }
+
+
+ private final PathMatchingDefaultResourceLoader resourceLoader;
+
+ private AntPathMatcher pathMatcher = new AntPathMatcher();
+
+ private static Map<ClassLoader, PathMatchingResourcePatternResolver> resolvers = new ConcurrentHashMap<>();
+
+ public static PathMatchingResourcePatternResolver of(ClassLoader loader){
+ return resolvers.computeIfAbsent(loader, PathMatchingResourcePatternResolver::new);
+ }
+
+ /**
+ * Create a new PathMatchingResourcePatternResolver.
+ * <p>ClassLoader access will happen via the thread context class loader.
+ */
+ public PathMatchingResourcePatternResolver() {
+ this.resourceLoader = new PathMatchingDefaultResourceLoader();
+ }
+
+ /**
+ * Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader.
+ * @param classLoader the ClassLoader to load classpath resources with,
+ * or {@code null} for using the thread context class loader
+ * at the time current actual resource access
+ * @see PathMatchingDefaultResourceLoader
+ */
+ public PathMatchingResourcePatternResolver(ClassLoader classLoader) {
+ this.resourceLoader = new PathMatchingDefaultResourceLoader(classLoader);
+ }
+
+ public ClassLoader getClassLoader() {
+ return resourceLoader.getClassLoader();
+ }
+
+ /**
+ * Return the PathMatcher that this resource pattern resolver uses.
+ */
+ public AntPathMatcher getPathMatcher() {
+ return this.pathMatcher;
+ }
+
+ public Resource getResource(String location) {
+ return resourceLoader.getResource(location);
+ }
+
+ public Resource[] getResources(String locationPattern) throws IOException {
+ Objects.requireNonNull(locationPattern, "Location pattern must not be null");
+ if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) {
+ // a class path resource (multiple resources for same name possible)
+ if (getPathMatcher().isPattern(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()))) {
+ // a class path resource pattern
+ return findPathMatchingResources(locationPattern);
+ }
+ else {
+ // all class path resources with the given name
+ return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()));
+ }
+ }
+ else {
+ // Only look for a pattern after a prefix here
+ // (to not get fooled by a pattern symbol in a strange prefix).
+ int prefixEnd = locationPattern.indexOf(':') + 1;
+ if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) {
+ // a file pattern
+ return findPathMatchingResources(locationPattern);
+ }
+ else {
+ // a single resource with the given name
+ return new Resource[] {this.resourceLoader.getResource(locationPattern)};
+ }
+ }
+ }
+
+ /**
+ * Find all class location resources with the given location via the ClassLoader.
+ * Delegates to {@link #doFindAllClassPathResources(String)}.
+ * @param location the absolute path within the classpath
+ * @return the result as Resource array
+ * @throws IOException in case current I/O errors
+ * @see java.lang.ClassLoader#getResources
+ * @see #convertClassLoaderURL
+ */
+ protected Resource[] findAllClassPathResources(String location) throws IOException {
+ String path = location;
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+ Set<Resource> result = doFindAllClassPathResources(path);
+ return result.toArray(new Resource[result.size()]);
+ }
+
+ /**
+ * Find all class location resources with the given path via the ClassLoader.
+ * Called by {@link #findAllClassPathResources(String)}.
+ * @param path the absolute path within the classpath (never a leading slash)
+ * @return a mutable Set current matching Resource instances
+ */
+ protected Set<Resource> doFindAllClassPathResources(String path) throws IOException {
+ Set<Resource> result = new LinkedHashSet<>(16);
+ ClassLoader cl = getClassLoader();
+ Enumeration<URL> resourceUrls = (cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path));
+ while (resourceUrls.hasMoreElements()) {
+ URL url = resourceUrls.nextElement();
+ result.add(convertClassLoaderURL(url));
+ }
+ if ("".equals(path)) {
+ // The above result is likely to be incomplete, i.e. only containing file system references.
+ // We need to have pointers to each current the jar files on the classpath as well...
+ addAllClassLoaderJarRoots(cl, result);
+ }
+ return result;
+ }
+
+ /**
+ * Convert the given URL as returned from the ClassLoader into a {@link Resource}.
+ * <p>The default implementation simply creates a {@link UrlResource} instance.
+ * @param url a URL as returned from the ClassLoader
+ * @return the corresponding Resource object
+ * @see java.lang.ClassLoader#getResources
+ * @see Resource
+ */
+ protected Resource convertClassLoaderURL(URL url) {
+ return new UrlResource(url);
+ }
+
+ /**
+ * Search all {@link URLClassLoader} URLs for jar file references and add them to the
+ * given set current resources in the form current pointers to the root current the jar file content.
+ * @param classLoader the ClassLoader to search (including its ancestors)
+ * @param result the set current resources to add jar roots to
+ */
+ protected void addAllClassLoaderJarRoots(ClassLoader classLoader, Set<Resource> result) {
+ if (classLoader instanceof URLClassLoader) {
+ try {
+ for (URL url : ((URLClassLoader) classLoader).getURLs()) {
+ if (ResourceUtils.isJarFileURL(url)) {
+ try {
+ UrlResource jarResource = new UrlResource(
+ ResourceUtils.JAR_URL_PREFIX + url.toString() + ResourceUtils.JAR_URL_SEPARATOR);
+ if (jarResource.exists()) {
+ result.add(jarResource);
+ }
+ }
+ catch (MalformedURLException ex) {
+ logger.finest(() -> "Cannot search for matching files underneath [" + url +
+ "] because it cannot be converted to a valid 'jar:' URL: " + ex.getMessage());
+ }
+ }
+ }
+ }
+ catch (Exception ex) {
+ logger.finest(() -> "Cannot introspect jar files since ClassLoader [" + classLoader +
+ "] does not support 'getURLs()': " + ex);
+ }
+ }
+ if (classLoader != null) {
+ try {
+ addAllClassLoaderJarRoots(classLoader.getParent(), result);
+ }
+ catch (Exception ex) {
+ logger.finest(() -> "Cannot introspect jar files in parent ClassLoader since [" + classLoader +
+ "] does not support 'getParent()': " + ex);
+ }
+ }
+ }
+
+ /**
+ * Find all resources that match the given location pattern via the
+ * Ant-style PathMatcher. Supports resources in jar files and zip files
+ * and in the file system.
+ * @param locationPattern the location pattern to match
+ * @return the result as Resource array
+ * @throws IOException in case current I/O errors
+ * @see #doFindPathMatchingJarResources
+ * @see #doFindPathMatchingFileResources
+ */
+ protected Resource[] findPathMatchingResources(String locationPattern) throws IOException {
+ String rootDirPath = determineRootDir(locationPattern);
+ String subPattern = locationPattern.substring(rootDirPath.length());
+ Resource[] rootDirResources = getResources(rootDirPath);
+ Set<Resource> result = new LinkedHashSet<>(16);
+ for (Resource rootDirResource : rootDirResources) {
+ rootDirResource = resolveRootDirResource(rootDirResource);
+ if (rootDirResource.toURL().getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
+ result.addAll(VfsResourceMatchingDelegate.findMatchingResources(rootDirResource, subPattern, getPathMatcher()));
+ }
+ else if (isJarResource(rootDirResource)) {
+ result.addAll(doFindPathMatchingJarResources(rootDirResource, subPattern));
+ }
+ else {
+ result.addAll(doFindPathMatchingFileResources(rootDirResource, subPattern));
+ }
+ }
+ logger.finest(() -> "Resolved location pattern [" + locationPattern + "] to resources " + result);
+ return result.toArray(new Resource[result.size()]);
+ }
+
+ /**
+ * Determine the root directory for the given location.
+ * <p>Used for determining the starting point for file matching,
+ * resolving the root directory location to a {@code java.io.File}
+ * and passing it into {@code retrieveMatchingFiles}, with the
+ * remainder current the location as pattern.
+ * <p>Will return "/WEB-INF/" for the pattern "/WEB-INF/*.xml",
+ * for example.
+ * @param location the location to check
+ * @return the part current the location that denotes the root directory
+ * @see #retrieveMatchingFiles
+ */
+ protected String determineRootDir(String location) {
+ int prefixEnd = location.indexOf(':') + 1;
+ int rootDirEnd = location.length();
+ while (rootDirEnd > prefixEnd && getPathMatcher().isPattern(location.substring(prefixEnd, rootDirEnd))) {
+ rootDirEnd = location.lastIndexOf('/', rootDirEnd - 2) + 1;
+ }
+ if (rootDirEnd == 0) {
+ rootDirEnd = prefixEnd;
+ }
+ return location.substring(0, rootDirEnd);
+ }
+
+ /**
+ * Resolve the specified resource for path matching.
+ * <p>The default implementation detects an Equinox OSGi "bundleresource:"
+ * / "bundleentry:" URL and resolves it into a standard jar file URL that
+ * can be traversed using Spring's standard jar file traversal algorithm.
+ * @param original the resource to resolve
+ * @return the resolved resource (may be identical to the passed-in resource)
+ * @throws IOException in case current resolution failure
+ */
+ protected Resource resolveRootDirResource(Resource original) throws IOException {
+ if (equinoxResolveMethod != null) {
+ URL url = original.toURL();
+ if (url.getProtocol().startsWith("bundle")) {
+ try {
+ return new UrlResource((URL) equinoxResolveMethod.invoke(url));
+ } catch (Exception e) {
+ ReflectionUtils.handleReflectionException(e);
+ }
+ }
+ }
+ return original;
+ }
+
+ /**
+ * Return whether the given resource handle indicates a jar resource
+ * that the {@code doFindPathMatchingJarResources} method can handle.
+ * <p>The default implementation checks against the URL protocols
+ * "jar", "zip" and "wsjar" (the latter are used by BEA WebLogic Server
+ * and IBM WebSphere, respectively, but can be treated like jar files).
+ * @param resource the resource handle to check
+ * (usually the root directory to start path matching from)
+ * @see #doFindPathMatchingJarResources
+ * @see ResourceUtils#isJarURL
+ */
+ protected boolean isJarResource(Resource resource) throws IOException {
+ return ResourceUtils.isJarURL(resource.toURL());
+ }
+
+ /**
+ * Find all resources in jar files that match the given location pattern
+ * via the Ant-style PathMatcher.
+ * @param rootDirResource the root directory as Resource
+ * @param subPattern the sub pattern to match (below the root directory)
+ * @return a mutable Set current matching Resource instances
+ * @throws IOException in case current I/O errors
+ * @see java.net.JarURLConnection
+ */
+ protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource, String subPattern)
+ throws IOException {
+
+ URLConnection con = rootDirResource.toURL().openConnection();
+ JarFile jarFile;
+ String jarFileUrl;
+ String rootEntryPath;
+ boolean newJarFile = false;
+
+ if (con instanceof JarURLConnection) {
+ // Should usually be the case for traditional JAR files.
+ JarURLConnection jarCon = (JarURLConnection) con;
+ ResourceUtils.useCachesIfNecessary(jarCon);
+ jarFile = jarCon.getJarFile();
+ jarFileUrl = jarCon.getJarFileURL().toExternalForm();
+ JarEntry jarEntry = jarCon.getJarEntry();
+ rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
+ }
+ else {
+ // No JarURLConnection -> need to resort to URL file parsing.
+ // We'll assume URLs current the format "jar:path!/entry", with the protocol
+ // being arbitrary as long as following the entry format.
+ // We'll also handle paths with and without leading "file:" prefix.
+ String urlFile = rootDirResource.toURL().getFile();
+ int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
+ if (separatorIndex != -1) {
+ jarFileUrl = urlFile.substring(0, separatorIndex);
+ rootEntryPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length());
+ jarFile = getJarFile(jarFileUrl);
+ }
+ else {
+ jarFile = new JarFile(urlFile);
+ jarFileUrl = urlFile;
+ rootEntryPath = "";
+ }
+ newJarFile = true;
+ }
+
+ try {
+ logger.finest("Looking for matching resources in jar file [" + jarFileUrl + "]");
+ if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) {
+ // Root entry path must end with slash to allow for proper matching.
+ // The Sun JRE does not return a slash here, but BEA JRockit does.
+ rootEntryPath = rootEntryPath + "/";
+ }
+ Set<Resource> result = new LinkedHashSet<>(8);
+ for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
+ JarEntry entry = entries.nextElement();
+ String entryPath = entry.getName();
+ if (entryPath.startsWith(rootEntryPath)) {
+ String relativePath = entryPath.substring(rootEntryPath.length());
+ if (getPathMatcher().match(subPattern, relativePath)) {
+ result.add(rootDirResource.createRelative(relativePath));
+ }
+ }
+ }
+ return result;
+ }
+ finally {
+ // Close jar file, but only if freshly obtained -
+ // not from JarURLConnection, which might cache the file reference.
+ if (newJarFile) {
+ jarFile.close();
+ }
+ }
+ }
+
+ /**
+ * Resolve the given jar file URL into a JarFile object.
+ */
+ protected JarFile getJarFile(String jarFileUrl) throws IOException {
+ if (jarFileUrl.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
+ try {
+ return new JarFile(ResourceUtils.toURI(jarFileUrl).getSchemeSpecificPart());
+ }
+ catch (URISyntaxException ex) {
+ // Fallback for URLs that are not valid URIs (should hardly ever happen).
+ return new JarFile(jarFileUrl.substring(ResourceUtils.FILE_URL_PREFIX.length()));
+ }
+ }
+ else {
+ return new JarFile(jarFileUrl);
+ }
+ }
+
+ /**
+ * Find all resources in the file system that match the given location pattern
+ * via the Ant-style PathMatcher.
+ * @param rootDirResource the root directory as Resource
+ * @param subPattern the sub pattern to match (below the root directory)
+ * @return a mutable Set current matching Resource instances
+ * @throws IOException in case current I/O errors
+ * @see #retrieveMatchingFiles
+ */
+ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
+ throws IOException {
+
+ File rootDir;
+ try {
+ rootDir = rootDirResource.toFile().getAbsoluteFile();
+ }
+ catch (IOException ex) {
+ logger.log(Level.WARNING, ex, () -> "Cannot search for matching files underneath " + rootDirResource +
+ " because it does not correspond to a directory in the file system");
+ return Collections.emptySet();
+ }
+ return doFindMatchingFileSystemResources(rootDir, subPattern);
+ }
+
+ /**
+ * Find all resources in the file system that match the given location pattern
+ * via the Ant-style PathMatcher.
+ * @param rootDir the root directory in the file system
+ * @param subPattern the sub pattern to match (below the root directory)
+ * @return a mutable Set current matching Resource instances
+ * @throws IOException in case current I/O errors
+ * @see #retrieveMatchingFiles
+ */
+ protected Set<Resource> doFindMatchingFileSystemResources(File rootDir, String subPattern) throws IOException {
+ logger.finest(() -> "Looking for matching resources in directory tree [" + rootDir.getPath() + "]");
+ Set<File> matchingFiles = retrieveMatchingFiles(rootDir, subPattern);
+ Set<Resource> result = new LinkedHashSet<>(matchingFiles.size());
+ result.addAll(matchingFiles.stream().map(FileSystemResource::new).collect(Collectors.toList()));
+ return result;
+ }
+
+ /**
+ * Retrieve files that match the given path pattern,
+ * checking the given directory and its subdirectories.
+ * @param rootDir the directory to start from
+ * @param pattern the pattern to match against,
+ * relative to the root directory
+ * @return a mutable Set current matching Resource instances
+ * @throws IOException if directory contents could not be retrieved
+ */
+ protected Set<File> retrieveMatchingFiles(File rootDir, String pattern) throws IOException {
+ if (!rootDir.exists()) {
+ // Silently skip non-existing directories.
+ logger.finest(() -> "Skipping [" + rootDir.getAbsolutePath() + "] because it does not exist");
+ return Collections.emptySet();
+ }
+ if (!rootDir.isDirectory()) {
+ // Complain louder if it exists but is no directory.
+ logger.log(Level.WARNING, () -> "Skipping [" + rootDir.getAbsolutePath() + "] because it does not denote a directory");
+ return Collections.emptySet();
+ }
+ if (!rootDir.canRead()) {
+ logger.log(Level.WARNING, () -> "Cannot search for matching files underneath directory [" + rootDir.getAbsolutePath() +
+ "] because the application is not allowed to read the directory");
+ return Collections.emptySet();
+ }
+ String fullPattern = StringUtils.replace(rootDir.getAbsolutePath(), File.separator, "/");
+ if (!pattern.startsWith("/")) {
+ fullPattern += "/";
+ }
+ fullPattern = fullPattern + StringUtils.replace(pattern, File.separator, "/");
+ Set<File> result = new LinkedHashSet<>(8);
+ doRetrieveMatchingFiles(fullPattern, rootDir, result);
+ return result;
+ }
+
+ /**
+ * Recursively retrieve files that match the given pattern,
+ * adding them to the given result list.
+ * @param fullPattern the pattern to match against,
+ * with prepended root directory path
+ * @param dir the current directory
+ * @param result the Set current matching File instances to add to
+ * @throws IOException if directory contents could not be retrieved
+ */
+ protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> result) throws IOException {
+ logger.finest(() -> "Searching directory [" + dir.getAbsolutePath() +
+ "] for files matching pattern [" + fullPattern + "]");
+ File[] dirContents = dir.listFiles();
+ if (dirContents == null) {
+ logger.log(Level.WARNING, () -> "Could not retrieve contents current directory [" + dir.getAbsolutePath() + "]");
+ return;
+ }
+ for (File content : dirContents) {
+ String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/");
+ if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) {
+ if (!content.canRead()) {
+ logger.finest(() -> "Skipping subdirectory [" + dir.getAbsolutePath() +
+ "] because the application is not allowed to read the directory");
+ }
+ else {
+ doRetrieveMatchingFiles(fullPattern, content, result);
+ }
+ }
+ if (getPathMatcher().match(fullPattern, currPath)) {
+ result.add(content);
+ }
+ }
+ }
+
+
+ /**
+ * Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
+ */
+ private static class VfsResourceMatchingDelegate {
+
+ public static Set<Resource> findMatchingResources(
+ Resource rootResource, String locationPattern, AntPathMatcher pathMatcher) throws IOException {
+ Object root = VfsUtils.getRoot(rootResource.toURL());
+ PatternVirtualFileVisitor visitor =
+ new PatternVirtualFileVisitor(VfsUtils.getPath(root), locationPattern, pathMatcher);
+ VfsUtils.visit(root, visitor);
+ return visitor.getResources();
+ }
+ }
+
+
+ /**
+ * VFS visitor for path matching purposes.
+ */
+ @SuppressWarnings("unused")
+ private static class PatternVirtualFileVisitor implements InvocationHandler {
+
+ private final String subPattern;
+
+ private final AntPathMatcher pathMatcher;
+
+ private final String rootPath;
+
+ private final Set<Resource> resources = new LinkedHashSet<>();
+
+ public PatternVirtualFileVisitor(String rootPath, String subPattern, AntPathMatcher pathMatcher) {
+ this.subPattern = subPattern;
+ this.pathMatcher = pathMatcher;
+ this.rootPath = (rootPath.length() == 0 || rootPath.endsWith("/") ? rootPath : rootPath + "/");
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ String methodName = method.getName();
+ if (Object.class.equals(method.getDeclaringClass())) {
+ if (methodName.equals("equals")) {
+ // Only consider equal when proxies are identical.
+ return (proxy == args[0]);
+ }
+ else if (methodName.equals("hashCode")) {
+ return System.identityHashCode(proxy);
+ }
+ }
+ else if ("getAttributes".equals(methodName)) {
+ return getAttributes();
+ }
+ else if ("visit".equals(methodName)) {
+ visit(args[0]);
+ return null;
+ }
+ else if ("toString".equals(methodName)) {
+ return toString();
+ }
+
+ throw new IllegalStateException("Unexpected method invocation: " + method);
+ }
+
+ public void visit(Object vfsResource) {
+ if (this.pathMatcher.match(this.subPattern,
+ VfsUtils.getPath(vfsResource).substring(this.rootPath.length()))) {
+ this.resources.add(new VfsResource(vfsResource));
+ }
+ }
+
+ public Object getAttributes() {
+ return VfsUtils.getVisitorAttribute();
+ }
+
+ public Set<Resource> getResources() {
+ return this.resources;
+ }
+
+ public int size() {
+ return this.resources.size();
+ }
+
+ @Override
+ public String toString() {
+ return "sub-pattern: " + this.subPattern + ", resources: " + this.resources;
+ }
+ }
+
+}
\ No newline at end of file
[26/27] incubator-tamaya git commit: Fixed checkstyle issues.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java
index bfb8182..ae44377 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/AntPathMatcher.java
@@ -24,12 +24,12 @@ import java.util.regex.Pattern;
/**
* PathMatcher implementation for Ant-style path patterns. Examples are provided below.
- *
+ * <p>
* <p>Part current this annotation code has been kindly borrowed from <a href="http://ant.apache.org">Apache Ant</a>.
- *
+ * <p>
* <p>The annotation matches URLs using the following rules:<br> <ul> <li>? matches one character</li> <li>* matches zero
* or more characters</li> <li>** matches zero or more 'directories' in a path</li> </ul>
- *
+ * <p>
* <p>Some examples:<br> <ul> <li>{@code com/t?st.jsp} - matches {@code com/testdata.jsp} but also
* {@code com/tast.jsp} or {@code com/txst.jsp}</li> <li>{@code com/*.jsp} - matches all
* {@code .jsp} files in the {@code com} directory</li> <li>{@code com/**/testdata.jsp} - matches all
@@ -47,733 +47,729 @@ import java.util.regex.Pattern;
*/
class AntPathMatcher {
- /** Default path separator: "/" */
- public static final String DEFAULT_PATH_SEPARATOR = "/";
-
- private static final int CACHE_TURNOFF_THRESHOLD = 65536;
-
- private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
-
-
- private String pathSeparator;
-
- private PathSeparatorPatternCache pathSeparatorPatternCache;
-
- private boolean trimTokens = true;
-
- private volatile Boolean cachePatterns;
-
- private final Map<String, String[]> tokenizedPatternCache = new ConcurrentHashMap<>(256);
-
- final Map<String, AntPathStringMatcher> stringMatcherCache = new ConcurrentHashMap<>(256);
-
-
- /**
- * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
- */
- public AntPathMatcher() {
- this.pathSeparator = DEFAULT_PATH_SEPARATOR;
- this.pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR);
- }
-
- /**
- * A convenience alternative constructor to use with a custom path separator.
- * @param pathSeparator the path separator to use, must not be {@code null}.
- * @since 4.1
- */
- public AntPathMatcher(String pathSeparator) {
- Objects.requireNonNull(pathSeparator, "'pathSeparator' is required");
- this.pathSeparator = pathSeparator;
- this.pathSeparatorPatternCache = new PathSeparatorPatternCache(pathSeparator);
- }
-
-
- /**
- * Set the path separator to use for pattern parsing.
- * Default is "/", as in Ant.
- */
- public void setPathSeparator(String pathSeparator) {
- this.pathSeparator = (pathSeparator != null ? pathSeparator : DEFAULT_PATH_SEPARATOR);
- this.pathSeparatorPatternCache = new PathSeparatorPatternCache(this.pathSeparator);
- }
-
- /**
- * Specify whether to trim tokenized paths and patterns.
- * Default is {@code true}.
- */
- public void setTrimTokens(boolean trimTokens) {
- this.trimTokens = trimTokens;
- }
-
- /**
- * Specify whether to cache parsed pattern metadata for patterns passed
- * into this matcher's {@link #match} method. A keys current {@code true}
- * activates an unlimited pattern cache; a keys current {@code false} turns
- * the pattern cache off completely.
- * <p>Default is for the cache to be on, but with the variant to automatically
- * turn it off when encountering too many patterns to cache at runtime
- * (the threshold is 65536), assuming that arbitrary permutations current patterns
- * are coming in, with little chance for encountering a reoccurring pattern.
- * @see #getStringMatcher(String)
- */
- public void setCachePatterns(boolean cachePatterns) {
- this.cachePatterns = cachePatterns;
- }
-
- private void deactivatePatternCache() {
- this.cachePatterns = false;
- this.tokenizedPatternCache.clear();
- this.stringMatcherCache.clear();
- }
-
-
- public boolean isPattern(String path) {
- return (path.indexOf('*') != -1 || path.indexOf('?') != -1);
- }
-
- public boolean match(String pattern, String path) {
- return doMatch(pattern, path, true, null);
- }
-
- public boolean matchStart(String pattern, String path) {
- return doMatch(pattern, path, false, null);
- }
-
- /**
- * Actually match the given {@code path} against the given {@code pattern}.
- * @param pattern the pattern to match against
- * @param path the path String to testdata
- * @param fullMatch whether a full pattern match is required (else a pattern match
- * as far as the given base path goes is sufficient)
- * @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't
- */
- protected boolean doMatch(String pattern, String path, boolean fullMatch, Map<String, String> uriTemplateVariables) {
- if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
- return false;
- }
-
- String[] pattDirs = tokenizePattern(pattern);
- String[] pathDirs = tokenizePath(path);
-
- int pattIdxStart = 0;
- int pattIdxEnd = pattDirs.length - 1;
- int pathIdxStart = 0;
- int pathIdxEnd = pathDirs.length - 1;
-
- // Match all elements up to the first **
- while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
- String pattDir = pattDirs[pattIdxStart];
- if ("**".equals(pattDir)) {
- break;
- }
- if (!matchStrings(pattDir, pathDirs[pathIdxStart], uriTemplateVariables)) {
- return false;
- }
- pattIdxStart++;
- pathIdxStart++;
- }
-
- if (pathIdxStart > pathIdxEnd) {
- // Path is exhausted, only match if rest current pattern is * or **'s
- if (pattIdxStart > pattIdxEnd) {
- return (pattern.endsWith(this.pathSeparator) ? path.endsWith(this.pathSeparator) :
- !path.endsWith(this.pathSeparator));
- }
- if (!fullMatch) {
- return true;
- }
- if (pattIdxStart == pattIdxEnd && pattDirs[pattIdxStart].equals("*") && path.endsWith(this.pathSeparator)) {
- return true;
- }
- for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
- if (!pattDirs[i].equals("**")) {
- return false;
- }
- }
- return true;
- }
- else if (pattIdxStart > pattIdxEnd) {
- // String not exhausted, but pattern is. Failure.
- return false;
- }
- else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) {
- // Path start definitely matches due to "**" part in pattern.
- return true;
- }
-
- // up to last '**'
- while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
- String pattDir = pattDirs[pattIdxEnd];
- if (pattDir.equals("**")) {
- break;
- }
- if (!matchStrings(pattDir, pathDirs[pathIdxEnd], uriTemplateVariables)) {
- return false;
- }
- pattIdxEnd--;
- pathIdxEnd--;
- }
- if (pathIdxStart > pathIdxEnd) {
- // String is exhausted
- for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
- if (!pattDirs[i].equals("**")) {
- return false;
- }
- }
- return true;
- }
-
- while (pattIdxStart != pattIdxEnd && pathIdxStart <= pathIdxEnd) {
- int patIdxTmp = -1;
- for (int i = pattIdxStart + 1; i <= pattIdxEnd; i++) {
- if (pattDirs[i].equals("**")) {
- patIdxTmp = i;
- break;
- }
- }
- if (patIdxTmp == pattIdxStart + 1) {
- // '**/**' situation, so skip one
- pattIdxStart++;
- continue;
- }
- // Find the pattern between padIdxStart & padIdxTmp in str between
- // strIdxStart & strIdxEnd
- int patLength = (patIdxTmp - pattIdxStart - 1);
- int strLength = (pathIdxEnd - pathIdxStart + 1);
- int foundIdx = -1;
-
- strLoop:
- for (int i = 0; i <= strLength - patLength; i++) {
- for (int j = 0; j < patLength; j++) {
- String subPat = pattDirs[pattIdxStart + j + 1];
- String subStr = pathDirs[pathIdxStart + i + j];
- if (!matchStrings(subPat, subStr, uriTemplateVariables)) {
- continue strLoop;
- }
- }
- foundIdx = pathIdxStart + i;
- break;
- }
-
- if (foundIdx == -1) {
- return false;
- }
-
- pattIdxStart = patIdxTmp;
- pathIdxStart = foundIdx + patLength;
- }
-
- for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
- if (!pattDirs[i].equals("**")) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Tokenize the given path pattern into parts, based on this matcher's settings.
- * <p>Performs caching based on {@link #setCachePatterns}, delegating to
- * {@link #tokenizePath(String)} for the actual tokenization algorithm.
- * @param pattern the pattern to tokenize
- * @return the tokenized pattern parts
- */
- protected String[] tokenizePattern(String pattern) {
- String[] tokenized = null;
- Boolean cachePatterns = this.cachePatterns;
- if (cachePatterns == null || cachePatterns) {
- tokenized = this.tokenizedPatternCache.get(pattern);
- }
- if (tokenized == null) {
- tokenized = tokenizePath(pattern);
- if (cachePatterns == null && this.tokenizedPatternCache.size() >= CACHE_TURNOFF_THRESHOLD) {
- // Try to adapt to the runtime situation that we're encountering:
- // There are obviously too many different patterns coming in here...
- // So let's turn off the cache since the patterns are unlikely to be reoccurring.
- deactivatePatternCache();
- return tokenized;
- }
- if (cachePatterns == null || cachePatterns) {
- this.tokenizedPatternCache.put(pattern, tokenized);
- }
- }
- return tokenized;
- }
-
- /**
- * Tokenize the given path String into parts, based on this matcher's settings.
- * @param path the path to tokenize
- * @return the tokenized path parts
- */
- protected String[] tokenizePath(String path) {
- return StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
- }
-
- /**
- * Tests whether or not a string matches against a pattern.
- * @param pattern the pattern to match against (never {@code null})
- * @param str the String which must be matched against the pattern (never {@code null})
- * @return {@code true} if the string matches against the pattern, or {@code false} otherwise
- */
- private boolean matchStrings(String pattern, String str, Map<String, String> uriTemplateVariables) {
- return getStringMatcher(pattern).matchStrings(str, uriTemplateVariables);
- }
-
- /**
- * Build or retrieve an {@link AntPathStringMatcher} for the given pattern.
- * <p>The default implementation checks this AntPathMatcher's internal cache
- * (see {@link #setCachePatterns}), creating a new AntPathStringMatcher instance
- * if no cached copy is found.
- * When encountering too many patterns to cache at runtime (the threshold is 65536),
- * it turns the default cache off, assuming that arbitrary permutations current patterns
- * are coming in, with little chance for encountering a reoccurring pattern.
- * <p>This method may get overridden to implement a custom cache strategy.
- * @param pattern the pattern to match against (never {@code null})
- * @return a corresponding AntPathStringMatcher (never {@code null})
- * @see #setCachePatterns
- */
- protected AntPathStringMatcher getStringMatcher(String pattern) {
- AntPathStringMatcher matcher = null;
- Boolean cachePatterns = this.cachePatterns;
- if (cachePatterns == null || cachePatterns) {
- matcher = this.stringMatcherCache.get(pattern);
- }
- if (matcher == null) {
- matcher = new AntPathStringMatcher(pattern);
- if (cachePatterns == null && this.stringMatcherCache.size() >= CACHE_TURNOFF_THRESHOLD) {
- // Try to adapt to the runtime situation that we're encountering:
- // There are obviously too many different patterns coming in here...
- // So let's turn off the cache since the patterns are unlikely to be reoccurring.
- deactivatePatternCache();
- return matcher;
- }
- if (cachePatterns == null || cachePatterns) {
- this.stringMatcherCache.put(pattern, matcher);
- }
- }
- return matcher;
- }
-
- /**
- * Given a pattern and a full path, determine the pattern-mapped part. <p>For example: <ul>
- * <li>'{@code /docs/cvs/commit.html}' and '{@code /docs/cvs/commit.html} -> ''</li>
- * <li>'{@code /docs/*}' and '{@code /docs/cvs/commit} -> '{@code cvs/commit}'</li>
- * <li>'{@code /docs/cvs/*.html}' and '{@code /docs/cvs/commit.html} -> '{@code commit.html}'</li>
- * <li>'{@code /docs/**}' and '{@code /docs/cvs/commit} -> '{@code cvs/commit}'</li>
- * <li>'{@code /docs/**\/*.html}' and '{@code /docs/cvs/commit.html} -> '{@code cvs/commit.html}'</li>
- * <li>'{@code /*.html}' and '{@code /docs/cvs/commit.html} -> '{@code docs/cvs/commit.html}'</li>
- * <li>'{@code *.html}' and '{@code /docs/cvs/commit.html} -> '{@code /docs/cvs/commit.html}'</li>
- * <li>'{@code *}' and '{@code /docs/cvs/commit.html} -> '{@code /docs/cvs/commit.html}'</li> </ul>
- * <p>Assumes that {@link #match} returns {@code true} for '{@code pattern}' and '{@code path}', but
- * does <strong>not</strong> enforce this.
- */
- public String extractPathWithinPattern(String pattern, String path) {
- String[] patternParts = StringUtils.tokenizeToStringArray(pattern, this.pathSeparator, this.trimTokens, true);
- String[] pathParts = StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
- StringBuilder builder = new StringBuilder();
- boolean pathStarted = false;
-
- for (int segment = 0; segment < patternParts.length; segment++) {
- String patternPart = patternParts[segment];
- if (patternPart.indexOf('*') > -1 || patternPart.indexOf('?') > -1) {
- for (; segment < pathParts.length; segment++) {
- if (pathStarted || (segment == 0 && !pattern.startsWith(this.pathSeparator))) {
- builder.append(this.pathSeparator);
- }
- builder.append(pathParts[segment]);
- pathStarted = true;
- }
- }
- }
-
- return builder.toString();
- }
-
- public Map<String, String> extractUriTemplateVariables(String pattern, String path) {
- Map<String, String> variables = new LinkedHashMap<>();
- boolean result = doMatch(pattern, path, true, variables);
- if(!result){
+ /**
+ * Default path separator: "/"
+ */
+ public static final String DEFAULT_PATH_SEPARATOR = "/";
+
+ private static final int CACHE_TURNOFF_THRESHOLD = 65536;
+
+ private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
+
+
+ private String pathSeparator;
+
+ private PathSeparatorPatternCache pathSeparatorPatternCache;
+
+ private boolean trimTokens = true;
+
+ private volatile Boolean cachePatterns;
+
+ private final Map<String, String[]> tokenizedPatternCache = new ConcurrentHashMap<>(256);
+
+ final Map<String, AntPathStringMatcher> stringMatcherCache = new ConcurrentHashMap<>(256);
+
+
+ /**
+ * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
+ */
+ public AntPathMatcher() {
+ this.pathSeparator = DEFAULT_PATH_SEPARATOR;
+ this.pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR);
+ }
+
+ /**
+ * A convenience alternative constructor to use with a custom path separator.
+ *
+ * @param pathSeparator the path separator to use, must not be {@code null}.
+ * @since 4.1
+ */
+ public AntPathMatcher(String pathSeparator) {
+ Objects.requireNonNull(pathSeparator, "'pathSeparator' is required");
+ this.pathSeparator = pathSeparator;
+ this.pathSeparatorPatternCache = new PathSeparatorPatternCache(pathSeparator);
+ }
+
+
+ /**
+ * Set the path separator to use for pattern parsing.
+ * Default is "/", as in Ant.
+ */
+ public void setPathSeparator(String pathSeparator) {
+ this.pathSeparator = (pathSeparator != null ? pathSeparator : DEFAULT_PATH_SEPARATOR);
+ this.pathSeparatorPatternCache = new PathSeparatorPatternCache(this.pathSeparator);
+ }
+
+ /**
+ * Specify whether to trim tokenized paths and patterns.
+ * Default is {@code true}.
+ */
+ public void setTrimTokens(boolean trimTokens) {
+ this.trimTokens = trimTokens;
+ }
+
+ /**
+ * Specify whether to cache parsed pattern metadata for patterns passed
+ * into this matcher's {@link #match} method. A keys current {@code true}
+ * activates an unlimited pattern cache; a keys current {@code false} turns
+ * the pattern cache off completely.
+ * <p>Default is for the cache to be on, but with the variant to automatically
+ * turn it off when encountering too many patterns to cache at runtime
+ * (the threshold is 65536), assuming that arbitrary permutations current patterns
+ * are coming in, with little chance for encountering a reoccurring pattern.
+ *
+ * @see #getStringMatcher(String)
+ */
+ public void setCachePatterns(boolean cachePatterns) {
+ this.cachePatterns = cachePatterns;
+ }
+
+ private void deactivatePatternCache() {
+ this.cachePatterns = false;
+ this.tokenizedPatternCache.clear();
+ this.stringMatcherCache.clear();
+ }
+
+
+ public boolean isPattern(String path) {
+ return (path.indexOf('*') != -1 || path.indexOf('?') != -1);
+ }
+
+ public boolean match(String pattern, String path) {
+ return doMatch(pattern, path, true, null);
+ }
+
+ public boolean matchStart(String pattern, String path) {
+ return doMatch(pattern, path, false, null);
+ }
+
+ /**
+ * Actually match the given {@code path} against the given {@code pattern}.
+ *
+ * @param pattern the pattern to match against
+ * @param path the path String to testdata
+ * @param fullMatch whether a full pattern match is required (else a pattern match
+ * as far as the given base path goes is sufficient)
+ * @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't
+ */
+ protected boolean doMatch(String pattern, String path, boolean fullMatch, Map<String, String> uriTemplateVariables) {
+ if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
+ return false;
+ }
+
+ String[] pattDirs = tokenizePattern(pattern);
+ String[] pathDirs = tokenizePath(path);
+
+ int pattIdxStart = 0;
+ int pattIdxEnd = pattDirs.length - 1;
+ int pathIdxStart = 0;
+ int pathIdxEnd = pathDirs.length - 1;
+
+ // Match all elements up to the first **
+ while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ String pattDir = pattDirs[pattIdxStart];
+ if ("**".equals(pattDir)) {
+ break;
+ }
+ if (!matchStrings(pattDir, pathDirs[pathIdxStart], uriTemplateVariables)) {
+ return false;
+ }
+ pattIdxStart++;
+ pathIdxStart++;
+ }
+
+ if (pathIdxStart > pathIdxEnd) {
+ // Path is exhausted, only match if rest current pattern is * or **'s
+ if (pattIdxStart > pattIdxEnd) {
+ return (pattern.endsWith(this.pathSeparator) ? path.endsWith(this.pathSeparator) :
+ !path.endsWith(this.pathSeparator));
+ }
+ if (!fullMatch) {
+ return true;
+ }
+ if (pattIdxStart == pattIdxEnd && pattDirs[pattIdxStart].equals("*") && path.endsWith(this.pathSeparator)) {
+ return true;
+ }
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+ return true;
+ } else if (pattIdxStart > pattIdxEnd) {
+ // String not exhausted, but pattern is. Failure.
+ return false;
+ } else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) {
+ // Path start definitely matches due to "**" part in pattern.
+ return true;
+ }
+
+ // up to last '**'
+ while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ String pattDir = pattDirs[pattIdxEnd];
+ if (pattDir.equals("**")) {
+ break;
+ }
+ if (!matchStrings(pattDir, pathDirs[pathIdxEnd], uriTemplateVariables)) {
+ return false;
+ }
+ pattIdxEnd--;
+ pathIdxEnd--;
+ }
+ if (pathIdxStart > pathIdxEnd) {
+ // String is exhausted
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ while (pattIdxStart != pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ int patIdxTmp = -1;
+ for (int i = pattIdxStart + 1; i <= pattIdxEnd; i++) {
+ if (pattDirs[i].equals("**")) {
+ patIdxTmp = i;
+ break;
+ }
+ }
+ if (patIdxTmp == pattIdxStart + 1) {
+ // '**/**' situation, so skip one
+ pattIdxStart++;
+ continue;
+ }
+ // Find the pattern between padIdxStart & padIdxTmp in str between
+ // strIdxStart & strIdxEnd
+ int patLength = (patIdxTmp - pattIdxStart - 1);
+ int strLength = (pathIdxEnd - pathIdxStart + 1);
+ int foundIdx = -1;
+
+ strLoop:
+ for (int i = 0; i <= strLength - patLength; i++) {
+ for (int j = 0; j < patLength; j++) {
+ String subPat = pattDirs[pattIdxStart + j + 1];
+ String subStr = pathDirs[pathIdxStart + i + j];
+ if (!matchStrings(subPat, subStr, uriTemplateVariables)) {
+ continue strLoop;
+ }
+ }
+ foundIdx = pathIdxStart + i;
+ break;
+ }
+
+ if (foundIdx == -1) {
+ return false;
+ }
+
+ pattIdxStart = patIdxTmp;
+ pathIdxStart = foundIdx + patLength;
+ }
+
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Tokenize the given path pattern into parts, based on this matcher's settings.
+ * <p>Performs caching based on {@link #setCachePatterns}, delegating to
+ * {@link #tokenizePath(String)} for the actual tokenization algorithm.
+ *
+ * @param pattern the pattern to tokenize
+ * @return the tokenized pattern parts
+ */
+ protected String[] tokenizePattern(String pattern) {
+ String[] tokenized = null;
+ Boolean cachePatterns = this.cachePatterns;
+ if (cachePatterns == null || cachePatterns) {
+ tokenized = this.tokenizedPatternCache.get(pattern);
+ }
+ if (tokenized == null) {
+ tokenized = tokenizePath(pattern);
+ if (cachePatterns == null && this.tokenizedPatternCache.size() >= CACHE_TURNOFF_THRESHOLD) {
+ // Try to adapt to the runtime situation that we're encountering:
+ // There are obviously too many different patterns coming in here...
+ // So let's turn off the cache since the patterns are unlikely to be reoccurring.
+ deactivatePatternCache();
+ return tokenized;
+ }
+ if (cachePatterns == null || cachePatterns) {
+ this.tokenizedPatternCache.put(pattern, tokenized);
+ }
+ }
+ return tokenized;
+ }
+
+ /**
+ * Tokenize the given path String into parts, based on this matcher's settings.
+ *
+ * @param path the path to tokenize
+ * @return the tokenized path parts
+ */
+ protected String[] tokenizePath(String path) {
+ return StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
+ }
+
+ /**
+ * Tests whether or not a string matches against a pattern.
+ *
+ * @param pattern the pattern to match against (never {@code null})
+ * @param str the String which must be matched against the pattern (never {@code null})
+ * @return {@code true} if the string matches against the pattern, or {@code false} otherwise
+ */
+ private boolean matchStrings(String pattern, String str, Map<String, String> uriTemplateVariables) {
+ return getStringMatcher(pattern).matchStrings(str, uriTemplateVariables);
+ }
+
+ /**
+ * Build or retrieve an {@link AntPathStringMatcher} for the given pattern.
+ * <p>The default implementation checks this AntPathMatcher's internal cache
+ * (see {@link #setCachePatterns}), creating a new AntPathStringMatcher instance
+ * if no cached copy is found.
+ * When encountering too many patterns to cache at runtime (the threshold is 65536),
+ * it turns the default cache off, assuming that arbitrary permutations current patterns
+ * are coming in, with little chance for encountering a reoccurring pattern.
+ * <p>This method may get overridden to implement a custom cache strategy.
+ *
+ * @param pattern the pattern to match against (never {@code null})
+ * @return a corresponding AntPathStringMatcher (never {@code null})
+ * @see #setCachePatterns
+ */
+ protected AntPathStringMatcher getStringMatcher(String pattern) {
+ AntPathStringMatcher matcher = null;
+ Boolean cachePatterns = this.cachePatterns;
+ if (cachePatterns == null || cachePatterns) {
+ matcher = this.stringMatcherCache.get(pattern);
+ }
+ if (matcher == null) {
+ matcher = new AntPathStringMatcher(pattern);
+ if (cachePatterns == null && this.stringMatcherCache.size() >= CACHE_TURNOFF_THRESHOLD) {
+ // Try to adapt to the runtime situation that we're encountering:
+ // There are obviously too many different patterns coming in here...
+ // So let's turn off the cache since the patterns are unlikely to be reoccurring.
+ deactivatePatternCache();
+ return matcher;
+ }
+ if (cachePatterns == null || cachePatterns) {
+ this.stringMatcherCache.put(pattern, matcher);
+ }
+ }
+ return matcher;
+ }
+
+ /**
+ * Given a pattern and a full path, determine the pattern-mapped part. <p>For example: <ul>
+ * <li>'{@code /docs/cvs/commit.html}' and '{@code /docs/cvs/commit.html} -> ''</li>
+ * <li>'{@code /docs/*}' and '{@code /docs/cvs/commit} -> '{@code cvs/commit}'</li>
+ * <li>'{@code /docs/cvs/*.html}' and '{@code /docs/cvs/commit.html} -> '{@code commit.html}'</li>
+ * <li>'{@code /docs/**}' and '{@code /docs/cvs/commit} -> '{@code cvs/commit}'</li>
+ * <li>'{@code /docs/**\/*.html}' and '{@code /docs/cvs/commit.html} -> '{@code cvs/commit.html}'</li>
+ * <li>'{@code /*.html}' and '{@code /docs/cvs/commit.html} -> '{@code docs/cvs/commit.html}'</li>
+ * <li>'{@code *.html}' and '{@code /docs/cvs/commit.html} -> '{@code /docs/cvs/commit.html}'</li>
+ * <li>'{@code *}' and '{@code /docs/cvs/commit.html} -> '{@code /docs/cvs/commit.html}'</li> </ul>
+ * <p>Assumes that {@link #match} returns {@code true} for '{@code pattern}' and '{@code path}', but
+ * does <strong>not</strong> enforce this.
+ */
+ public String extractPathWithinPattern(String pattern, String path) {
+ String[] patternParts = StringUtils.tokenizeToStringArray(pattern, this.pathSeparator, this.trimTokens, true);
+ String[] pathParts = StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
+ StringBuilder builder = new StringBuilder();
+ boolean pathStarted = false;
+
+ for (int segment = 0; segment < patternParts.length; segment++) {
+ String patternPart = patternParts[segment];
+ if (patternPart.indexOf('*') > -1 || patternPart.indexOf('?') > -1) {
+ for (; segment < pathParts.length; segment++) {
+ if (pathStarted || (segment == 0 && !pattern.startsWith(this.pathSeparator))) {
+ builder.append(this.pathSeparator);
+ }
+ builder.append(pathParts[segment]);
+ pathStarted = true;
+ }
+ }
+ }
+
+ return builder.toString();
+ }
+
+ public Map<String, String> extractUriTemplateVariables(String pattern, String path) {
+ Map<String, String> variables = new LinkedHashMap<>();
+ boolean result = doMatch(pattern, path, true, variables);
+ if (!result) {
throw new IllegalArgumentException("Pattern \"" + pattern + "\" is not a match for \"" + path + "\"");
}
- return variables;
- }
-
- /**
- * Combines two patterns into a new pattern that is returned.
- * <p>This implementation simply concatenates the two patterns, unless the first pattern
- * contains a file extension match (such as {@code *.html}. In that case, the second pattern
- * should be included in the first, or an {@code IllegalArgumentException} is thrown.
- * <p>For example: <table>
- * <tr><th>Pattern 1</th><th>Pattern 2</th><th>Result</th></tr> <tr><td>/hotels</td><td>{@code
- * null}</td><td>/hotels</td></tr> <tr><td>{@code null}</td><td>/hotels</td><td>/hotels</td></tr>
- * <tr><td>/hotels</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels</td><td>bookings</td><td>/hotels/bookings</td></tr>
- * <tr><td>/hotels/*</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels/**</td><td>/bookings</td><td>/hotels/**/bookings</td></tr>
- * <tr><td>/hotels</td><td>{hotel}</td><td>/hotels/{hotel}</td></tr> <tr><td>/hotels/*</td><td>{hotel}</td><td>/hotels/{hotel}</td></tr>
- * <tr><td>/hotels/**</td><td>{hotel}</td><td>/hotels/**/{hotel}</td></tr>
- * <tr><td>/*.html</td><td>/hotels.html</td><td>/hotels.html</td></tr> <tr><td>/*.html</td><td>/hotels</td><td>/hotels.html</td></tr>
- * <tr><td>/*.html</td><td>/*.txt</td><td>IllegalArgumentException</td></tr> </table>
- * @param pattern1 the first pattern
- * @param pattern2 the second pattern
- * @return the combination current the two patterns
- * @throws IllegalArgumentException when the two patterns cannot be combined
- */
- public String combine(String pattern1, String pattern2) {
- if (!StringUtils.hasText(pattern1) && !StringUtils.hasText(pattern2)) {
- return "";
- }
- if (!StringUtils.hasText(pattern1)) {
- return pattern2;
- }
- if (!StringUtils.hasText(pattern2)) {
- return pattern1;
- }
-
- boolean pattern1ContainsUriVar = pattern1.indexOf('{') != -1;
- if (!pattern1.equals(pattern2) && !pattern1ContainsUriVar && match(pattern1, pattern2)) {
- // /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
- // However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
- return pattern2;
- }
-
- // /hotels/* + /booking -> /hotels/booking
- // /hotels/* + booking -> /hotels/booking
- if (pattern1.endsWith(this.pathSeparatorPatternCache.getEndsOnWildCard())) {
- return concat(pattern1.substring(0, pattern1.length() - 2), pattern2);
- }
-
- // /hotels/** + /booking -> /hotels/**/booking
- // /hotels/** + booking -> /hotels/**/booking
- if (pattern1.endsWith(this.pathSeparatorPatternCache.getEndsOnDoubleWildCard())) {
- return concat(pattern1, pattern2);
- }
-
- int starDotPos1 = pattern1.indexOf("*.");
- if (pattern1ContainsUriVar || starDotPos1 == -1 || this.pathSeparator.equals(".")) {
- // simply concatenate the two patterns
- return concat(pattern1, pattern2);
- }
- String extension1 = pattern1.substring(starDotPos1 + 1);
- int dotPos2 = pattern2.indexOf('.');
- String fileName2 = (dotPos2 == -1 ? pattern2 : pattern2.substring(0, dotPos2));
- String extension2 = (dotPos2 == -1 ? "" : pattern2.substring(dotPos2));
- String extension = extension1.startsWith("*") ? extension2 : extension1;
- return fileName2 + extension;
- }
-
- private String concat(String path1, String path2) {
- if (path1.endsWith(this.pathSeparator) || path2.startsWith(this.pathSeparator)) {
- return path1 + path2;
- }
- return path1 + this.pathSeparator + path2;
- }
-
- /**
- * Given a full path, returns a {@link Comparator} suitable for sorting patterns in order current explicitness.
- * <p>The returned {@code Comparator} will {@linkplain java.util.Collections#sort(java.util.List,
- * java.util.Comparator) sort} a list so that more specific patterns (without uri templates or wild cards) come before
- * generic patterns. So given a list with the following patterns: <ol> <li>{@code /hotels/new}</li>
- * <li>{@code /hotels/{hotel}}</li> <li>{@code /hotels/*}</li> </ol> the returned comparator will sort this
- * list so that the order will be as indicated.
- * <p>The full path given as parameter is used to testdata for exact matches. So when the given path is {@code /hotels/2},
- * the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
- * @param path the full path to use for comparison
- * @return a comparator capable current sorting patterns in order current explicitness
- */
- public Comparator<String> getPatternComparator(String path) {
- return new AntPatternComparator(path);
- }
-
-
- /**
- * Tests whether or not a string matches against a pattern via a {@link Pattern}.
- * <p>The pattern may contain special characters: '*' means zero or more characters; '?' means one and
- * only one character; '{' and '}' indicate a URI template pattern. For example <tt>/users/{user}</tt>.
- */
- protected static class AntPathStringMatcher {
-
- private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?\\}|[^/{}]|\\\\[{}])+?)\\}");
-
- private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";
-
- private final Pattern pattern;
-
- private final List<String> variableNames = new LinkedList<>();
-
- public AntPathStringMatcher(String pattern) {
- StringBuilder patternBuilder = new StringBuilder();
- Matcher m = GLOB_PATTERN.matcher(pattern);
- int end = 0;
- while (m.find()) {
- patternBuilder.append(quote(pattern, end, m.start()));
- String match = m.group();
- if ("?".equals(match)) {
- patternBuilder.append('.');
- }
- else if ("*".equals(match)) {
- patternBuilder.append(".*");
- }
- else if (match.startsWith("{") && match.endsWith("}")) {
- int colonIdx = match.indexOf(':');
- if (colonIdx == -1) {
- patternBuilder.append(DEFAULT_VARIABLE_PATTERN);
- this.variableNames.add(m.group(1));
- }
- else {
- String variablePattern = match.substring(colonIdx + 1, match.length() - 1);
- patternBuilder.append('(');
- patternBuilder.append(variablePattern);
- patternBuilder.append(')');
- String variableName = match.substring(1, colonIdx);
- this.variableNames.add(variableName);
- }
- }
- end = m.end();
- }
- patternBuilder.append(quote(pattern, end, pattern.length()));
- this.pattern = Pattern.compile(patternBuilder.toString());
- }
-
- private String quote(String s, int start, int end) {
- if (start == end) {
- return "";
- }
- return Pattern.quote(s.substring(start, end));
- }
-
- /**
- * Main entry point.
- * @return {@code true} if the string matches against the pattern, or {@code false} otherwise.
- */
- public boolean matchStrings(String str, Map<String, String> uriTemplateVariables) {
- Matcher matcher = this.pattern.matcher(str);
- if (matcher.matches()) {
- if (uriTemplateVariables != null) {
- // SPR-8455
- if(!(this.variableNames.size() == matcher.groupCount())) {
+ return variables;
+ }
+
+ /**
+ * Combines two patterns into a new pattern that is returned.
+ * <p>This implementation simply concatenates the two patterns, unless the first pattern
+ * contains a file extension match (such as {@code *.html}. In that case, the second pattern
+ * should be included in the first, or an {@code IllegalArgumentException} is thrown.
+ * <p>For example: <table>
+ * <tr><th>Pattern 1</th><th>Pattern 2</th><th>Result</th></tr> <tr><td>/hotels</td><td>{@code
+ * null}</td><td>/hotels</td></tr> <tr><td>{@code null}</td><td>/hotels</td><td>/hotels</td></tr>
+ * <tr><td>/hotels</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels</td><td>bookings</td><td>/hotels/bookings</td></tr>
+ * <tr><td>/hotels/*</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels/**</td><td>/bookings</td><td>/hotels/**/bookings</td></tr>
+ * <tr><td>/hotels</td><td>{hotel}</td><td>/hotels/{hotel}</td></tr> <tr><td>/hotels/*</td><td>{hotel}</td><td>/hotels/{hotel}</td></tr>
+ * <tr><td>/hotels/**</td><td>{hotel}</td><td>/hotels/**/{hotel}</td></tr>
+ * <tr><td>/*.html</td><td>/hotels.html</td><td>/hotels.html</td></tr> <tr><td>/*.html</td><td>/hotels</td><td>/hotels.html</td></tr>
+ * <tr><td>/*.html</td><td>/*.txt</td><td>IllegalArgumentException</td></tr> </table>
+ *
+ * @param pattern1 the first pattern
+ * @param pattern2 the second pattern
+ * @return the combination current the two patterns
+ * @throws IllegalArgumentException when the two patterns cannot be combined
+ */
+ public String combine(String pattern1, String pattern2) {
+ if (!StringUtils.hasText(pattern1) && !StringUtils.hasText(pattern2)) {
+ return "";
+ }
+ if (!StringUtils.hasText(pattern1)) {
+ return pattern2;
+ }
+ if (!StringUtils.hasText(pattern2)) {
+ return pattern1;
+ }
+
+ boolean pattern1ContainsUriVar = pattern1.indexOf('{') != -1;
+ if (!pattern1.equals(pattern2) && !pattern1ContainsUriVar && match(pattern1, pattern2)) {
+ // /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
+ // However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
+ return pattern2;
+ }
+
+ // /hotels/* + /booking -> /hotels/booking
+ // /hotels/* + booking -> /hotels/booking
+ if (pattern1.endsWith(this.pathSeparatorPatternCache.getEndsOnWildCard())) {
+ return concat(pattern1.substring(0, pattern1.length() - 2), pattern2);
+ }
+
+ // /hotels/** + /booking -> /hotels/**/booking
+ // /hotels/** + booking -> /hotels/**/booking
+ if (pattern1.endsWith(this.pathSeparatorPatternCache.getEndsOnDoubleWildCard())) {
+ return concat(pattern1, pattern2);
+ }
+
+ int starDotPos1 = pattern1.indexOf("*.");
+ if (pattern1ContainsUriVar || starDotPos1 == -1 || this.pathSeparator.equals(".")) {
+ // simply concatenate the two patterns
+ return concat(pattern1, pattern2);
+ }
+ String extension1 = pattern1.substring(starDotPos1 + 1);
+ int dotPos2 = pattern2.indexOf('.');
+ String fileName2 = (dotPos2 == -1 ? pattern2 : pattern2.substring(0, dotPos2));
+ String extension2 = (dotPos2 == -1 ? "" : pattern2.substring(dotPos2));
+ String extension = extension1.startsWith("*") ? extension2 : extension1;
+ return fileName2 + extension;
+ }
+
+ private String concat(String path1, String path2) {
+ if (path1.endsWith(this.pathSeparator) || path2.startsWith(this.pathSeparator)) {
+ return path1 + path2;
+ }
+ return path1 + this.pathSeparator + path2;
+ }
+
+ /**
+ * Given a full path, returns a {@link Comparator} suitable for sorting patterns in order current explicitness.
+ * <p>The returned {@code Comparator} will {@linkplain java.util.Collections#sort(java.util.List,
+ * java.util.Comparator) sort} a list so that more specific patterns (without uri templates or wild cards) come before
+ * generic patterns. So given a list with the following patterns: <ol> <li>{@code /hotels/new}</li>
+ * <li>{@code /hotels/{hotel}}</li> <li>{@code /hotels/*}</li> </ol> the returned comparator will sort this
+ * list so that the order will be as indicated.
+ * <p>The full path given as parameter is used to testdata for exact matches. So when the given path is {@code /hotels/2},
+ * the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
+ *
+ * @param path the full path to use for comparison
+ * @return a comparator capable current sorting patterns in order current explicitness
+ */
+ public Comparator<String> getPatternComparator(String path) {
+ return new AntPatternComparator(path);
+ }
+
+
+ /**
+ * Tests whether or not a string matches against a pattern via a {@link Pattern}.
+ * <p>The pattern may contain special characters: '*' means zero or more characters; '?' means one and
+ * only one character; '{' and '}' indicate a URI template pattern. For example <tt>/users/{user}</tt>.
+ */
+ protected static class AntPathStringMatcher {
+
+ private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?\\}|[^/{}]|\\\\[{}])+?)\\}");
+
+ private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";
+
+ private final Pattern pattern;
+
+ private final List<String> variableNames = new LinkedList<>();
+
+ public AntPathStringMatcher(String pattern) {
+ StringBuilder patternBuilder = new StringBuilder();
+ Matcher m = GLOB_PATTERN.matcher(pattern);
+ int end = 0;
+ while (m.find()) {
+ patternBuilder.append(quote(pattern, end, m.start()));
+ String match = m.group();
+ if ("?".equals(match)) {
+ patternBuilder.append('.');
+ } else if ("*".equals(match)) {
+ patternBuilder.append(".*");
+ } else if (match.startsWith("{") && match.endsWith("}")) {
+ int colonIdx = match.indexOf(':');
+ if (colonIdx == -1) {
+ patternBuilder.append(DEFAULT_VARIABLE_PATTERN);
+ this.variableNames.add(m.group(1));
+ } else {
+ String variablePattern = match.substring(colonIdx + 1, match.length() - 1);
+ patternBuilder.append('(');
+ patternBuilder.append(variablePattern);
+ patternBuilder.append(')');
+ String variableName = match.substring(1, colonIdx);
+ this.variableNames.add(variableName);
+ }
+ }
+ end = m.end();
+ }
+ patternBuilder.append(quote(pattern, end, pattern.length()));
+ this.pattern = Pattern.compile(patternBuilder.toString());
+ }
+
+ private String quote(String s, int start, int end) {
+ if (start == end) {
+ return "";
+ }
+ return Pattern.quote(s.substring(start, end));
+ }
+
+ /**
+ * Main entry point.
+ *
+ * @return {@code true} if the string matches against the pattern, or {@code false} otherwise.
+ */
+ public boolean matchStrings(String str, Map<String, String> uriTemplateVariables) {
+ Matcher matcher = this.pattern.matcher(str);
+ if (matcher.matches()) {
+ if (uriTemplateVariables != null) {
+ // SPR-8455
+ if (!(this.variableNames.size() == matcher.groupCount())) {
throw new IllegalStateException(
"The number current capturing groups in the pattern segment " + this.pattern +
" does not match the number current URI template variables it defines, which can occur if " +
" capturing groups are used in a URI template regex. Use non-capturing groups instead.");
}
- for (int i = 1; i <= matcher.groupCount(); i++) {
- String name = this.variableNames.get(i - 1);
- String value = matcher.group(i);
- uriTemplateVariables.put(name, value);
- }
- }
- return true;
- }
- else {
- return false;
- }
- }
- }
-
-
- /**
- * The default {@link Comparator} implementation returned by
- * {@link #getPatternComparator(String)}.
- * <p>In order, the most "generic" pattern is determined by the following:
- * <ul>
- * <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
- * <li>if the other pattern is an actual match</li>
- * <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
- * <li>if it's got more "*" than the other pattern</li>
- * <li>if it's got more "{foo}" than the other pattern</li>
- * <li>if it's shorter than the other pattern</li>
- * </ul>
- */
- protected static class AntPatternComparator implements Comparator<String> {
-
- private final String path;
-
- public AntPatternComparator(String path) {
- this.path = path;
- }
-
- /**
- * Compare two patterns to determine which should match first, i.e. which
- * is the most specific regarding the current path.
- * @return a negative integer, zero, or a positive integer as pattern1 is
- * more specific, equally specific, or less specific than pattern2.
- */
- @Override
- public int compare(String pattern1, String pattern2) {
- PatternInfo info1 = new PatternInfo(pattern1);
- PatternInfo info2 = new PatternInfo(pattern2);
-
- if (info1.isLeastSpecific() && info2.isLeastSpecific()) {
- return 0;
- }
- else if (info1.isLeastSpecific()) {
- return 1;
- }
- else if (info2.isLeastSpecific()) {
- return -1;
- }
-
- boolean pattern1EqualsPath = pattern1.equals(path);
- boolean pattern2EqualsPath = pattern2.equals(path);
- if (pattern1EqualsPath && pattern2EqualsPath) {
- return 0;
- }
- else if (pattern1EqualsPath) {
- return -1;
- }
- else if (pattern2EqualsPath) {
- return 1;
- }
-
- if (info1.isPrefixPattern() && info2.getDoubleWildcards() == 0) {
- return 1;
- }
- else if (info2.isPrefixPattern() && info1.getDoubleWildcards() == 0) {
- return -1;
- }
-
- if (info1.getTotalCount() != info2.getTotalCount()) {
- return info1.getTotalCount() - info2.getTotalCount();
- }
-
- if (info1.getLength() != info2.getLength()) {
- return info2.getLength() - info1.getLength();
- }
-
- if (info1.getSingleWildcards() < info2.getSingleWildcards()) {
- return -1;
- }
- else if (info2.getSingleWildcards() < info1.getSingleWildcards()) {
- return 1;
- }
-
- if (info1.getUriVars() < info2.getUriVars()) {
- return -1;
- }
- else if (info2.getUriVars() < info1.getUriVars()) {
- return 1;
- }
-
- return 0;
- }
-
-
- /**
- * Value class that holds information about the pattern, e.g. number current
- * occurrences current "*", "**", and "{" pattern elements.
- */
- private static class PatternInfo {
-
- private final String pattern;
-
- private int uriVars;
-
- private int singleWildcards;
-
- private int doubleWildcards;
-
- private boolean catchAllPattern;
-
- private boolean prefixPattern;
-
- private Integer length;
-
- public PatternInfo(String pattern) {
- this.pattern = pattern;
- if (this.pattern != null) {
- initCounters();
- this.catchAllPattern = this.pattern.equals("/**");
- this.prefixPattern = !this.catchAllPattern && this.pattern.endsWith("/**");
- }
- if (this.uriVars == 0) {
- this.length = (this.pattern != null ? this.pattern.length() : 0);
- }
- }
-
- protected void initCounters() {
- int pos = 0;
- while (pos < this.pattern.length()) {
- if (this.pattern.charAt(pos) == '{') {
- this.uriVars++;
- pos++;
- }
- else if (this.pattern.charAt(pos) == '*') {
- if (pos + 1 < this.pattern.length() && this.pattern.charAt(pos + 1) == '*') {
- this.doubleWildcards++;
- pos += 2;
- }
- else if (!this.pattern.substring(pos - 1).equals(".*")) {
- this.singleWildcards++;
- pos++;
- }
- else {
- pos++;
- }
- }
- else {
- pos++;
- }
- }
- }
-
- public int getUriVars() {
- return this.uriVars;
- }
-
- public int getSingleWildcards() {
- return this.singleWildcards;
- }
-
- public int getDoubleWildcards() {
- return this.doubleWildcards;
- }
-
- public boolean isLeastSpecific() {
- return (this.pattern == null || this.catchAllPattern);
- }
-
- public boolean isPrefixPattern() {
- return this.prefixPattern;
- }
-
- public int getTotalCount() {
- return this.uriVars + this.singleWildcards + (2 * this.doubleWildcards);
- }
-
- /**
- * Returns the length current the given pattern, where template variables are considered to be 1 long.
- */
- public int getLength() {
- if (this.length == null) {
- this.length = VARIABLE_PATTERN.matcher(this.pattern).replaceAll("#").length();
- }
- return this.length;
- }
- }
- }
-
-
- /**
- * A simple cache for patterns that depend on the configured path separator.
- */
- private static class PathSeparatorPatternCache {
-
- private final String endsOnWildCard;
-
- private final String endsOnDoubleWildCard;
-
- public PathSeparatorPatternCache(String pathSeparator) {
- this.endsOnWildCard = pathSeparator + "*";
- this.endsOnDoubleWildCard = pathSeparator + "**";
- }
-
- public String getEndsOnWildCard() {
- return this.endsOnWildCard;
- }
-
- public String getEndsOnDoubleWildCard() {
- return this.endsOnDoubleWildCard;
- }
- }
+ for (int i = 1; i <= matcher.groupCount(); i++) {
+ String name = this.variableNames.get(i - 1);
+ String value = matcher.group(i);
+ uriTemplateVariables.put(name, value);
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+
+ /**
+ * The default {@link Comparator} implementation returned by
+ * {@link #getPatternComparator(String)}.
+ * <p>In order, the most "generic" pattern is determined by the following:
+ * <ul>
+ * <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
+ * <li>if the other pattern is an actual match</li>
+ * <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
+ * <li>if it's got more "*" than the other pattern</li>
+ * <li>if it's got more "{foo}" than the other pattern</li>
+ * <li>if it's shorter than the other pattern</li>
+ * </ul>
+ */
+ protected static class AntPatternComparator implements Comparator<String> {
+
+ private final String path;
+
+ public AntPatternComparator(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Compare two patterns to determine which should match first, i.e. which
+ * is the most specific regarding the current path.
+ *
+ * @return a negative integer, zero, or a positive integer as pattern1 is
+ * more specific, equally specific, or less specific than pattern2.
+ */
+ @Override
+ public int compare(String pattern1, String pattern2) {
+ PatternInfo info1 = new PatternInfo(pattern1);
+ PatternInfo info2 = new PatternInfo(pattern2);
+
+ if (info1.isLeastSpecific() && info2.isLeastSpecific()) {
+ return 0;
+ } else if (info1.isLeastSpecific()) {
+ return 1;
+ } else if (info2.isLeastSpecific()) {
+ return -1;
+ }
+
+ boolean pattern1EqualsPath = pattern1.equals(path);
+ boolean pattern2EqualsPath = pattern2.equals(path);
+ if (pattern1EqualsPath && pattern2EqualsPath) {
+ return 0;
+ } else if (pattern1EqualsPath) {
+ return -1;
+ } else if (pattern2EqualsPath) {
+ return 1;
+ }
+
+ if (info1.isPrefixPattern() && info2.getDoubleWildcards() == 0) {
+ return 1;
+ } else if (info2.isPrefixPattern() && info1.getDoubleWildcards() == 0) {
+ return -1;
+ }
+
+ if (info1.getTotalCount() != info2.getTotalCount()) {
+ return info1.getTotalCount() - info2.getTotalCount();
+ }
+
+ if (info1.getLength() != info2.getLength()) {
+ return info2.getLength() - info1.getLength();
+ }
+
+ if (info1.getSingleWildcards() < info2.getSingleWildcards()) {
+ return -1;
+ } else if (info2.getSingleWildcards() < info1.getSingleWildcards()) {
+ return 1;
+ }
+
+ if (info1.getUriVars() < info2.getUriVars()) {
+ return -1;
+ } else if (info2.getUriVars() < info1.getUriVars()) {
+ return 1;
+ }
+
+ return 0;
+ }
+
+
+ /**
+ * Value class that holds information about the pattern, e.g. number current
+ * occurrences current "*", "**", and "{" pattern elements.
+ */
+ private static class PatternInfo {
+
+ private final String pattern;
+
+ private int uriVars;
+
+ private int singleWildcards;
+
+ private int doubleWildcards;
+
+ private boolean catchAllPattern;
+
+ private boolean prefixPattern;
+
+ private Integer length;
+
+ public PatternInfo(String pattern) {
+ this.pattern = pattern;
+ if (this.pattern != null) {
+ initCounters();
+ this.catchAllPattern = this.pattern.equals("/**");
+ this.prefixPattern = !this.catchAllPattern && this.pattern.endsWith("/**");
+ }
+ if (this.uriVars == 0) {
+ this.length = (this.pattern != null ? this.pattern.length() : 0);
+ }
+ }
+
+ protected void initCounters() {
+ int pos = 0;
+ while (pos < this.pattern.length()) {
+ if (this.pattern.charAt(pos) == '{') {
+ this.uriVars++;
+ pos++;
+ } else if (this.pattern.charAt(pos) == '*') {
+ if (pos + 1 < this.pattern.length() && this.pattern.charAt(pos + 1) == '*') {
+ this.doubleWildcards++;
+ pos += 2;
+ } else if (!this.pattern.substring(pos - 1).equals(".*")) {
+ this.singleWildcards++;
+ pos++;
+ } else {
+ pos++;
+ }
+ } else {
+ pos++;
+ }
+ }
+ }
+
+ public int getUriVars() {
+ return this.uriVars;
+ }
+
+ public int getSingleWildcards() {
+ return this.singleWildcards;
+ }
+
+ public int getDoubleWildcards() {
+ return this.doubleWildcards;
+ }
+
+ public boolean isLeastSpecific() {
+ return (this.pattern == null || this.catchAllPattern);
+ }
+
+ public boolean isPrefixPattern() {
+ return this.prefixPattern;
+ }
+
+ public int getTotalCount() {
+ return this.uriVars + this.singleWildcards + (2 * this.doubleWildcards);
+ }
+
+ /**
+ * Returns the length current the given pattern, where template variables are considered to be 1 long.
+ */
+ public int getLength() {
+ if (this.length == null) {
+ this.length = VARIABLE_PATTERN.matcher(this.pattern).replaceAll("#").length();
+ }
+ return this.length;
+ }
+ }
+ }
+
+
+ /**
+ * A simple cache for patterns that depend on the configured path separator.
+ */
+ private static class PathSeparatorPatternCache {
+
+ private final String endsOnWildCard;
+
+ private final String endsOnDoubleWildCard;
+
+ public PathSeparatorPatternCache(String pathSeparator) {
+ this.endsOnWildCard = pathSeparator + "*";
+ this.endsOnDoubleWildCard = pathSeparator + "**";
+ }
+
+ public String getEndsOnWildCard() {
+ return this.endsOnWildCard;
+ }
+
+ public String getEndsOnDoubleWildCard() {
+ return this.endsOnDoubleWildCard;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java
index 6b10e8b..15d04d6 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/ClassPathResource.java
@@ -28,227 +28,231 @@ import java.util.Objects;
/**
* {@link Resource} implementation for class path resources.
* Uses either a given ClassLoader or a given Class for loading resources.
- *
+ * <p>
* <p>Supports resolution as {@code java.io.File} if the class path
* resource resides in the file system, but not for resources in a JAR.
* Always supports resolution as URL.
*
* @author Juergen Hoeller
* @author Sam Brannen
- * @since 28.12.2003
* @see ClassLoader#getResourceAsStream(String)
* @see Class#getResourceAsStream(String)
+ * @since 28.12.2003
*/
public class ClassPathResource extends AbstractFileResolvingResource {
- private final String path;
-
- private ClassLoader classLoader;
-
- private Class<?> clazz;
-
-
- /**
- * Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
- * A leading slash will be removed, as the ClassLoader resource access
- * methods will not accept it.
- * <p>The thread context class loader will be used for
- * loading the resource.
- * @param path the absolute path within the class path
- * @see java.lang.ClassLoader#getResourceAsStream(String)
- */
- public ClassPathResource(String path) {
- this(path, (ClassLoader) null);
- }
-
- /**
- * Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
- * A leading slash will be removed, as the ClassLoader resource access
- * methods will not accept it.
- * @param path the absolute path within the classpath
- * @param classLoader the class loader to load the resource with,
- * or {@code null} for the thread context class loader
- * @see ClassLoader#getResourceAsStream(String)
- */
- public ClassPathResource(String path, ClassLoader classLoader) {
- Objects.requireNonNull(path, "Path must not be null");
- String pathToUse = StringUtils.cleanPath(path);
- if (pathToUse.startsWith("/")) {
- pathToUse = pathToUse.substring(1);
- }
- this.path = pathToUse;
- this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
- }
-
- /**
- * Create a new {@code ClassPathResource} for {@code Class} usage.
- * The path can be relative to the given class, or absolute within
- * the classpath via a leading slash.
- * @param path relative or absolute path within the class path
- * @param clazz the class to load resources with
- * @see java.lang.Class#getResourceAsStream
- */
- public ClassPathResource(String path, Class<?> clazz) {
- Objects.requireNonNull(path, "Path must not be null");
- this.path = StringUtils.cleanPath(path);
- this.clazz = clazz;
- }
-
- /**
- * Create a new {@code ClassPathResource} with optional {@code ClassLoader}
- * and {@code Class}. Only for internal usage.
- * @param path relative or absolute path within the classpath
- * @param classLoader the class loader to load the resource with, if any
- * @param clazz the class to load resources with, if any
- */
- protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) {
- this.path = StringUtils.cleanPath(path);
- this.classLoader = classLoader;
- this.clazz = clazz;
- }
-
-
- /**
- * Return the path for this resource (as resource path within the class path).
- */
- public final String getPath() {
- return this.path;
- }
-
- /**
- * Return the ClassLoader that this resource will be obtained from.
- */
- public final ClassLoader getClassLoader() {
- return (this.clazz != null ? this.clazz.getClassLoader() : this.classLoader);
- }
-
-
- /**
- * This implementation checks for the resolution current a resource URL.
- * @see java.lang.ClassLoader#getResource(String)
- * @see java.lang.Class#getResource(String)
- */
- @Override
- public boolean exists() {
- return (resolveURL() != null);
- }
-
- /**
- * Resolves a URL for the underlying class path resource.
- * @return the resolved URL, or {@code null} if not resolvable
- */
- protected URL resolveURL() {
- if (this.clazz != null) {
- return this.clazz.getResource(this.path);
- }
- else if (this.classLoader != null) {
- return this.classLoader.getResource(this.path);
- }
- else {
- return ClassLoader.getSystemResource(this.path);
- }
- }
-
- /**
- * This implementation opens an InputStream for the given class path resource.
- * @see java.lang.ClassLoader#getResourceAsStream(String)
- * @see java.lang.Class#getResourceAsStream(String)
- */
- @Override
- public InputStream getInputStream()throws IOException {
- InputStream is;
- if (this.clazz != null) {
- is = this.clazz.getResourceAsStream(this.path);
- }
- else if (this.classLoader != null) {
- is = this.classLoader.getResourceAsStream(this.path);
- }
- else {
- is = ClassLoader.getSystemResourceAsStream(this.path);
- }
- if (is == null) {
- throw new IOException(getDisplayName() + " cannot be opened because it does not exist");
- }
- return is;
- }
-
- /**
- * This implementation returns a URL for the underlying class path resource,
- * if available.
- * @see java.lang.ClassLoader#getResource(String)
- * @see java.lang.Class#getResource(String)
- */
- @Override
- public URL toURL() throws IOException {
- URL url = resolveURL();
- if (url == null) {
- throw new FileNotFoundException(getDisplayName() + " cannot be resolved to URL because it does not exist");
- }
- return url;
- }
-
- /**
- * This implementation creates a ClassPathResource, applying the given path
- * relative to the path current the underlying resource current this descriptor.
- */
- @Override
- public Resource createRelative(String relativePath) {
- String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
- return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
- }
-
- /**
- * This implementation returns the name current the file that this class path
- * resource refers to.
- */
- @Override
- public String getDisplayName() {
- return StringUtils.getFilename(this.path);
- }
-
- /**
- * This implementation returns a description that includes the class path location.
- */
+ private final String path;
+
+ private ClassLoader classLoader;
+
+ private Class<?> clazz;
+
+
+ /**
+ * Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
+ * A leading slash will be removed, as the ClassLoader resource access
+ * methods will not accept it.
+ * <p>The thread context class loader will be used for
+ * loading the resource.
+ *
+ * @param path the absolute path within the class path
+ * @see java.lang.ClassLoader#getResourceAsStream(String)
+ */
+ public ClassPathResource(String path) {
+ this(path, (ClassLoader) null);
+ }
+
+ /**
+ * Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
+ * A leading slash will be removed, as the ClassLoader resource access
+ * methods will not accept it.
+ *
+ * @param path the absolute path within the classpath
+ * @param classLoader the class loader to load the resource with,
+ * or {@code null} for the thread context class loader
+ * @see ClassLoader#getResourceAsStream(String)
+ */
+ public ClassPathResource(String path, ClassLoader classLoader) {
+ Objects.requireNonNull(path, "Path must not be null");
+ String pathToUse = StringUtils.cleanPath(path);
+ if (pathToUse.startsWith("/")) {
+ pathToUse = pathToUse.substring(1);
+ }
+ this.path = pathToUse;
+ this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
+ }
+
+ /**
+ * Create a new {@code ClassPathResource} for {@code Class} usage.
+ * The path can be relative to the given class, or absolute within
+ * the classpath via a leading slash.
+ *
+ * @param path relative or absolute path within the class path
+ * @param clazz the class to load resources with
+ * @see java.lang.Class#getResourceAsStream
+ */
+ public ClassPathResource(String path, Class<?> clazz) {
+ Objects.requireNonNull(path, "Path must not be null");
+ this.path = StringUtils.cleanPath(path);
+ this.clazz = clazz;
+ }
+
+ /**
+ * Create a new {@code ClassPathResource} with optional {@code ClassLoader}
+ * and {@code Class}. Only for internal usage.
+ *
+ * @param path relative or absolute path within the classpath
+ * @param classLoader the class loader to load the resource with, if any
+ * @param clazz the class to load resources with, if any
+ */
+ protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) {
+ this.path = StringUtils.cleanPath(path);
+ this.classLoader = classLoader;
+ this.clazz = clazz;
+ }
+
+
+ /**
+ * Return the path for this resource (as resource path within the class path).
+ */
+ public final String getPath() {
+ return this.path;
+ }
+
+ /**
+ * Return the ClassLoader that this resource will be obtained from.
+ */
+ public final ClassLoader getClassLoader() {
+ return (this.clazz != null ? this.clazz.getClassLoader() : this.classLoader);
+ }
+
+
+ /**
+ * This implementation checks for the resolution current a resource URL.
+ *
+ * @see java.lang.ClassLoader#getResource(String)
+ * @see java.lang.Class#getResource(String)
+ */
@Override
- public String toString() {
- StringBuilder builder = new StringBuilder("ClassPathResource [");
- String pathToUse = path;
- if (this.clazz != null && !pathToUse.startsWith("/")) {
- builder.append(ClassUtils.classPackageAsResourcePath(this.clazz));
- builder.append('/');
- }
- if (pathToUse.startsWith("/")) {
- pathToUse = pathToUse.substring(1);
- }
- builder.append(pathToUse);
- builder.append(']');
- return builder.toString();
- }
-
- /**
- * This implementation compares the underlying class path locations.
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (obj instanceof ClassPathResource) {
- ClassPathResource otherRes = (ClassPathResource) obj;
- return (this.path.equals(otherRes.path) &&
- Objects.equals(this.classLoader, otherRes.classLoader) &&
+ public boolean exists() {
+ return (resolveURL() != null);
+ }
+
+ /**
+ * Resolves a URL for the underlying class path resource.
+ *
+ * @return the resolved URL, or {@code null} if not resolvable
+ */
+ protected URL resolveURL() {
+ if (this.clazz != null) {
+ return this.clazz.getResource(this.path);
+ } else if (this.classLoader != null) {
+ return this.classLoader.getResource(this.path);
+ } else {
+ return ClassLoader.getSystemResource(this.path);
+ }
+ }
+
+ /**
+ * This implementation opens an InputStream for the given class path resource.
+ *
+ * @see java.lang.ClassLoader#getResourceAsStream(String)
+ * @see java.lang.Class#getResourceAsStream(String)
+ */
+ @Override
+ public InputStream getInputStream() throws IOException {
+ InputStream is;
+ if (this.clazz != null) {
+ is = this.clazz.getResourceAsStream(this.path);
+ } else if (this.classLoader != null) {
+ is = this.classLoader.getResourceAsStream(this.path);
+ } else {
+ is = ClassLoader.getSystemResourceAsStream(this.path);
+ }
+ if (is == null) {
+ throw new IOException(getDisplayName() + " cannot be opened because it does not exist");
+ }
+ return is;
+ }
+
+ /**
+ * This implementation returns a URL for the underlying class path resource,
+ * if available.
+ *
+ * @see java.lang.ClassLoader#getResource(String)
+ * @see java.lang.Class#getResource(String)
+ */
+ @Override
+ public URL toURL() throws IOException {
+ URL url = resolveURL();
+ if (url == null) {
+ throw new FileNotFoundException(getDisplayName() + " cannot be resolved to URL because it does not exist");
+ }
+ return url;
+ }
+
+ /**
+ * This implementation creates a ClassPathResource, applying the given path
+ * relative to the path current the underlying resource current this descriptor.
+ */
+ @Override
+ public Resource createRelative(String relativePath) {
+ String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
+ return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
+ }
+
+ /**
+ * This implementation returns the name current the file that this class path
+ * resource refers to.
+ */
+ @Override
+ public String getDisplayName() {
+ return StringUtils.getFilename(this.path);
+ }
+
+ /**
+ * This implementation returns a description that includes the class path location.
+ */
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder("ClassPathResource [");
+ String pathToUse = path;
+ if (this.clazz != null && !pathToUse.startsWith("/")) {
+ builder.append(ClassUtils.classPackageAsResourcePath(this.clazz));
+ builder.append('/');
+ }
+ if (pathToUse.startsWith("/")) {
+ pathToUse = pathToUse.substring(1);
+ }
+ builder.append(pathToUse);
+ builder.append(']');
+ return builder.toString();
+ }
+
+ /**
+ * This implementation compares the underlying class path locations.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof ClassPathResource) {
+ ClassPathResource otherRes = (ClassPathResource) obj;
+ return (this.path.equals(otherRes.path) &&
+ Objects.equals(this.classLoader, otherRes.classLoader) &&
Objects.equals(this.clazz, otherRes.clazz));
- }
- return false;
- }
-
- /**
- * This implementation returns the hash code current the underlying
- * class path location.
- */
- @Override
- public int hashCode() {
- return this.path.hashCode();
- }
+ }
+ return false;
+ }
+
+ /**
+ * This implementation returns the hash code current the underlying
+ * class path location.
+ */
+ @Override
+ public int hashCode() {
+ return this.path.hashCode();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java
index c65be65..c19ac62 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.tamaya.core.internal.resource;
import org.apache.tamaya.core.resources.Resource;
@@ -18,7 +33,7 @@ import java.util.logging.Logger;
* Simple default implementation of the resource loader.
*/
@Priority(0)
-public class DefaultResourceLoader implements ResourceLoader{
+public class DefaultResourceLoader implements ResourceLoader {
private static final Logger LOG = Logger.getLogger(DefaultResourceLoader.class.getName());
@@ -27,9 +42,9 @@ public class DefaultResourceLoader implements ResourceLoader{
@Override
public List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions) {
List<Resource> resources = new ArrayList<>();
- for(String expression:expressions){
- if(tryClassPath(classLoader, expression, resources) || tryFile(expression, resources) || tryURL(expression, resources)
- || tryAntPath(classLoader, expression, resources)){
+ for (String expression : expressions) {
+ if (tryClassPath(classLoader, expression, resources) || tryFile(expression, resources) || tryURL(expression, resources)
+ || tryAntPath(classLoader, expression, resources)) {
continue;
}
LOG.warning("Failed to resolve resource: " + expression);
@@ -38,41 +53,38 @@ public class DefaultResourceLoader implements ResourceLoader{
}
private boolean tryClassPath(ClassLoader classLoader, String expression, List<Resource> resources) {
- try{
+ try {
Enumeration<URL> urls = classLoader.getResources(expression);
- while(urls.hasMoreElements()){
+ while (urls.hasMoreElements()) {
URL url = urls.nextElement();
resources.add(new UrlResource(url));
}
return !resources.isEmpty();
- }
- catch(Exception e){
+ } catch (Exception e) {
LOG.finest(() -> "Failed to load resource from CP: " + expression);
}
return false;
}
private boolean tryFile(String expression, List<Resource> resources) {
- try{
+ try {
File file = new File(expression);
- if(file.exists()) {
+ if (file.exists()) {
resources.add(new FileSystemResource(file));
return true;
}
- }
- catch(Exception e){
+ } catch (Exception e) {
LOG.finest(() -> "Failed to load resource from file: " + expression);
}
return false;
}
private boolean tryURL(String expression, List<Resource> resources) {
- try{
+ try {
URL url = new URL(expression);
resources.add(new UrlResource(url));
return true;
- }
- catch(Exception e){
+ } catch (Exception e) {
LOG.finest(() -> "Failed to load resource from file: " + expression);
}
return false;
@@ -81,11 +93,10 @@ public class DefaultResourceLoader implements ResourceLoader{
private boolean tryAntPath(ClassLoader classLoader, String expression, List<Resource> resources) {
PathMatchingResourcePatternResolver loader = resourceLoaders.computeIfAbsent(classLoader, cl -> new PathMatchingResourcePatternResolver(cl));
- try{
+ try {
resources.addAll(Arrays.asList(loader.getResources(expression)));
return !resources.isEmpty();
- }
- catch(Exception e){
+ } catch (Exception e) {
LOG.finest(() -> "Failed to load resources from pattern: " + expression);
}
return false;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java
index efeecef..c5fa68e 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/FileSystemResource.java
@@ -33,188 +33,200 @@ import java.util.Objects;
* Obviously supports resolution as File, and also as URL.
*
* @author Juergen Hoeller
- * @since 28.12.2003
* @see java.io.File
+ * @since 28.12.2003
*/
public class FileSystemResource implements Resource {
- private final File file;
-
- private final String path;
-
-
- /**
- * Create a new {@code FileSystemResource} from a {@link File} handle.
- * <p>Note: When building relative resources via {@link #createRelative},
- * the relative path will applyChanges <i>at the same directory level</i>:
- * e.g. new File("C:/dir1"), relative path "dir2" -> "C:/dir2"!
- * If you prefer to have relative paths built underneath the given root
- * directory, use the {@link #FileSystemResource(String) constructor with a file path}
- * to append a trailing slash to the root path: "C:/dir1/", which
- * indicates this directory as root for all relative paths.
- * @param file a File handle
- */
- public FileSystemResource(File file) {
- Objects.requireNonNull(file, "File must not be null");
- this.file = file;
- this.path = StringUtils.cleanPath(file.getPath());
- }
-
- /**
- * Create a new {@code FileSystemResource} from a file path.
- * <p>Note: When building relative resources via {@link #createRelative},
- * it makes a difference whether the specified resource base path here
- * ends with a slash or not. In the case current "C:/dir1/", relative paths
- * will be built underneath that root: e.g. relative path "dir2" ->
- * "C:/dir1/dir2". In the case current "C:/dir1", relative paths will applyChanges
- * at the same directory level: relative path "dir2" -> "C:/dir2".
- * @param path a file path
- */
- public FileSystemResource(String path) {
- Objects.requireNonNull(path, "Path must not be null");
- this.file = new File(path);
- this.path = StringUtils.cleanPath(path);
- }
-
-
- /**
- * Return the file path for this resource.
- */
- public final String getPath() {
- return this.path;
- }
-
-
- /**
- * This implementation returns whether the underlying file exists.
- * @see java.io.File#exists()
- */
- @Override
- public boolean exists() {
- return this.file.exists();
- }
-
- /**
- * This implementation checks whether the underlying file is marked as readable
- * (and corresponds to an actual file with content, not to a directory).
- * @see java.io.File#canRead()
- * @see java.io.File#isDirectory()
- */
- @Override
- public boolean isReadable() {
- return (this.file.canRead() && !this.file.isDirectory());
- }
-
- /**
- * This implementation opens a FileInputStream for the underlying file.
- * @see java.io.FileInputStream
- */
- @Override
- public InputStream getInputStream() throws IOException {
- return new FileInputStream(this.file);
- }
-
- /**
- * This implementation returns a URL for the underlying file.
- * @see java.io.File#toURI()
- */
- @Override
- public URL toURL() throws IOException {
- return this.file.toURI().toURL();
- }
-
- /**
- * This implementation returns a URI for the underlying file.
- * @see java.io.File#toURI()
- */
- @Override
- public URI getURI() throws IOException {
- return this.file.toURI();
- }
-
- /**
- * This implementation returns the underlying File reference.
- */
- @Override
- public File toFile() {
- return this.file;
- }
-
- /**
- * This implementation returns the underlying File's length.
- */
- @Override
- public long contentLength() throws IOException {
- return this.file.length();
- }
-
- /**
- * This implementation creates a FileSystemResource, applying the given path
- * relative to the path current the underlying file current this resource descriptor.
- * @see StringUtils#applyRelativePath(String, String)
- */
- @Override
- public Resource createRelative(String relativePath) {
- String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
- return new FileSystemResource(pathToUse);
- }
-
- /**
- * This implementation returns the name current the file.
- * @see java.io.File#getName()
- */
- @Override
- public String getDisplayName() {
- return this.file.getName();
- }
-
- /**
- * This implementation returns a description that includes the absolute
- * path current the file.
- * @see java.io.File#getAbsolutePath()
- */
- @Override
- public String toString() {
- return "file [" + this.file.getAbsolutePath() + "]";
- }
-
-
- // implementation current WritableResource
-
- /**
- * This implementation checks whether the underlying file is marked as writable
- * (and corresponds to an actual file with content, not to a directory).
- * @see java.io.File#canWrite()
- * @see java.io.File#isDirectory()
- */
- public boolean isWritable() {
- return (this.file.canWrite() && !this.file.isDirectory());
- }
-
- /**
- * This implementation opens a FileOutputStream for the underlying file.
- * @see java.io.FileOutputStream
- */
- public OutputStream getOutputStream() throws IOException {
- return new FileOutputStream(this.file);
- }
-
-
- /**
- * This implementation compares the underlying File references.
- */
- @Override
- public boolean equals(Object obj) {
- return (obj == this ||
- (obj instanceof FileSystemResource && this.path.equals(((FileSystemResource) obj).path)));
- }
-
- /**
- * This implementation returns the hash code current the underlying File reference.
- */
- @Override
- public int hashCode() {
- return this.path.hashCode();
- }
+ private final File file;
+
+ private final String path;
+
+
+ /**
+ * Create a new {@code FileSystemResource} from a {@link File} handle.
+ * <p>Note: When building relative resources via {@link #createRelative},
+ * the relative path will applyChanges <i>at the same directory level</i>:
+ * e.g. new File("C:/dir1"), relative path "dir2" -> "C:/dir2"!
+ * If you prefer to have relative paths built underneath the given root
+ * directory, use the {@link #FileSystemResource(String) constructor with a file path}
+ * to append a trailing slash to the root path: "C:/dir1/", which
+ * indicates this directory as root for all relative paths.
+ *
+ * @param file a File handle
+ */
+ public FileSystemResource(File file) {
+ Objects.requireNonNull(file, "File must not be null");
+ this.file = file;
+ this.path = StringUtils.cleanPath(file.getPath());
+ }
+
+ /**
+ * Create a new {@code FileSystemResource} from a file path.
+ * <p>Note: When building relative resources via {@link #createRelative},
+ * it makes a difference whether the specified resource base path here
+ * ends with a slash or not. In the case current "C:/dir1/", relative paths
+ * will be built underneath that root: e.g. relative path "dir2" ->
+ * "C:/dir1/dir2". In the case current "C:/dir1", relative paths will applyChanges
+ * at the same directory level: relative path "dir2" -> "C:/dir2".
+ *
+ * @param path a file path
+ */
+ public FileSystemResource(String path) {
+ Objects.requireNonNull(path, "Path must not be null");
+ this.file = new File(path);
+ this.path = StringUtils.cleanPath(path);
+ }
+
+
+ /**
+ * Return the file path for this resource.
+ */
+ public final String getPath() {
+ return this.path;
+ }
+
+
+ /**
+ * This implementation returns whether the underlying file exists.
+ *
+ * @see java.io.File#exists()
+ */
+ @Override
+ public boolean exists() {
+ return this.file.exists();
+ }
+
+ /**
+ * This implementation checks whether the underlying file is marked as readable
+ * (and corresponds to an actual file with content, not to a directory).
+ *
+ * @see java.io.File#canRead()
+ * @see java.io.File#isDirectory()
+ */
+ @Override
+ public boolean isReadable() {
+ return (this.file.canRead() && !this.file.isDirectory());
+ }
+
+ /**
+ * This implementation opens a FileInputStream for the underlying file.
+ *
+ * @see java.io.FileInputStream
+ */
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return new FileInputStream(this.file);
+ }
+
+ /**
+ * This implementation returns a URL for the underlying file.
+ *
+ * @see java.io.File#toURI()
+ */
+ @Override
+ public URL toURL() throws IOException {
+ return this.file.toURI().toURL();
+ }
+
+ /**
+ * This implementation returns a URI for the underlying file.
+ *
+ * @see java.io.File#toURI()
+ */
+ @Override
+ public URI getURI() throws IOException {
+ return this.file.toURI();
+ }
+
+ /**
+ * This implementation returns the underlying File reference.
+ */
+ @Override
+ public File toFile() {
+ return this.file;
+ }
+
+ /**
+ * This implementation returns the underlying File's length.
+ */
+ @Override
+ public long contentLength() throws IOException {
+ return this.file.length();
+ }
+
+ /**
+ * This implementation creates a FileSystemResource, applying the given path
+ * relative to the path current the underlying file current this resource descriptor.
+ *
+ * @see StringUtils#applyRelativePath(String, String)
+ */
+ @Override
+ public Resource createRelative(String relativePath) {
+ String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
+ return new FileSystemResource(pathToUse);
+ }
+
+ /**
+ * This implementation returns the name current the file.
+ *
+ * @see java.io.File#getName()
+ */
+ @Override
+ public String getDisplayName() {
+ return this.file.getName();
+ }
+
+ /**
+ * This implementation returns a description that includes the absolute
+ * path current the file.
+ *
+ * @see java.io.File#getAbsolutePath()
+ */
+ @Override
+ public String toString() {
+ return "file [" + this.file.getAbsolutePath() + "]";
+ }
+
+
+ // implementation current WritableResource
+
+ /**
+ * This implementation checks whether the underlying file is marked as writable
+ * (and corresponds to an actual file with content, not to a directory).
+ *
+ * @see java.io.File#canWrite()
+ * @see java.io.File#isDirectory()
+ */
+ public boolean isWritable() {
+ return (this.file.canWrite() && !this.file.isDirectory());
+ }
+
+ /**
+ * This implementation opens a FileOutputStream for the underlying file.
+ *
+ * @see java.io.FileOutputStream
+ */
+ public OutputStream getOutputStream() throws IOException {
+ return new FileOutputStream(this.file);
+ }
+
+
+ /**
+ * This implementation compares the underlying File references.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return (obj == this ||
+ (obj instanceof FileSystemResource && this.path.equals(((FileSystemResource) obj).path)));
+ }
+
+ /**
+ * This implementation returns the hash code current the underlying File reference.
+ */
+ @Override
+ public int hashCode() {
+ return this.path.hashCode();
+ }
}
[08/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java
deleted file mode 100644
index 1dfb189..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java
+++ /dev/null
@@ -1,1165 +0,0 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.resources.io;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-/**
-* Miscellaneous {@link String} utility methods.
-*
-* <p>Mainly for internal use within the framework; consider
-* <a href="http://jakarta.apache.org/commons/lang/">Jakarta's Commons Lang</a>
-* for a more comprehensive suite current String utilities.
-*
-* <p>This class delivers some simple functionality that should really
-* be provided by the core Java {@code String} and {@link StringBuilder}
-* classes, such as the ability to {@code replace} all occurrences current a given
-* substring in a target string. It also provides easy-to-use methods to convert
-* between delimited strings, such as CSV strings, and collections and arrays.
-*
-* @author Rod Johnson
-* @author Juergen Hoeller
-* @author Keith Donald
-* @author Rob Harrop
-* @author Rick Evans
-* @author Arjen Poutsma
-* @since 16 April 2001
-*/
-class StringUtils {
-
- private static final String FOLDER_SEPARATOR = "/";
-
- private static final String WINDOWS_FOLDER_SEPARATOR = "\\";
-
- private static final String TOP_PATH = "..";
-
- private static final String CURRENT_PATH = ".";
-
-// private static final char EXTENSION_SEPARATOR = '.';
-//
-
- private StringUtils(){}
-
-// //---------------------------------------------------------------------
-// // General convenience methods for working with Strings
-// //---------------------------------------------------------------------
-//
-// /**
-// * Check whether the given String is empty.
-// * <p>This method accepts any Object as an argument, comparing it to
-// * {@code null} and the empty String. As a consequence, this method
-// * will never return {@code true} for a non-null non-String object.
-// * <p>The Object signature is useful for general attribute handling code
-// * that commonly deals with Strings but generally has to iterate over
-// * Objects since attributes may e.g. be primitive keys objects as well.
-// * @param str the candidate String
-// * @since 3.2.1
-// */
-// public static boolean isEmpty(Object str) {
-// return (str == null || "".equals(str));
-// }
-
- /**
- * Check that the given CharSequence is neither {@code null} nor current length 0.
- * Note: Will return {@code true} for a CharSequence that purely consists current whitespace.
- * <p><pre class="code">
- * StringUtils.hasLength(null) = false
- * StringUtils.hasLength("") = false
- * StringUtils.hasLength(" ") = true
- * StringUtils.hasLength("Hello") = true
- * </pre>
- * @param str the CharSequence to check (may be {@code null})
- * @return {@code true} if the CharSequence is not null and has length
- */
- public static boolean hasLength(CharSequence str) {
- return (str != null && str.length() > 0);
- }
-
-// /**
-// * Check that the given String is neither {@code null} nor current length 0.
-// * Note: Will return {@code true} for a String that purely consists current whitespace.
-// * @param str the String to check (may be {@code null})
-// * @return {@code true} if the String is not null and has length
-// * @see #hasLength(CharSequence)
-// */
-// public static boolean hasLength(String str) {
-// return hasLength((CharSequence) str);
-// }
-
- /**
- * Check whether the given CharSequence has actual text.
- * More specifically, returns {@code true} if the string not {@code null},
- * its length is greater than 0, and it contains at least one non-whitespace character.
- * <p><pre class="code">
- * StringUtils.hasText(null) = false
- * StringUtils.hasText("") = false
- * StringUtils.hasText(" ") = false
- * StringUtils.hasText("12345") = true
- * StringUtils.hasText(" 12345 ") = true
- * </pre>
- * @param str the CharSequence to check (may be {@code null})
- * @return {@code true} if the CharSequence is not {@code null},
- * its length is greater than 0, and it does not contain whitespace only
- * @see Character#isWhitespace
- */
- public static boolean hasText(CharSequence str) {
- if (!hasLength(str)) {
- return false;
- }
- int strLen = str.length();
- for (int i = 0; i < strLen; i++) {
- if (!Character.isWhitespace(str.charAt(i))) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Check whether the given String has actual text.
- * More specifically, returns {@code true} if the string not {@code null},
- * its length is greater than 0, and it contains at least one non-whitespace character.
- * @param str the String to check (may be {@code null})
- * @return {@code true} if the String is not {@code null}, its length is
- * greater than 0, and it does not contain whitespace only
- * @see #hasText(CharSequence)
- */
- public static boolean hasText(String str) {
- return hasText((CharSequence) str);
- }
-
-// /**
-// * Check whether the given CharSequence contains any whitespace characters.
-// * @param str the CharSequence to check (may be {@code null})
-// * @return {@code true} if the CharSequence is not empty and
-// * contains at least 1 whitespace character
-// * @see Character#isWhitespace
-// */
-// public static boolean containsWhitespace(CharSequence str) {
-// if (!hasLength(str)) {
-// return false;
-// }
-// int strLen = str.length();
-// for (int i = 0; i < strLen; i++) {
-// if (Character.isWhitespace(str.charAt(i))) {
-// return true;
-// }
-// }
-// return false;
-// }
-//
-// /**
-// * Check whether the given String contains any whitespace characters.
-// * @param str the String to check (may be {@code null})
-// * @return {@code true} if the String is not empty and
-// * contains at least 1 whitespace character
-// * @see #containsWhitespace(CharSequence)
-// */
-// public static boolean containsWhitespace(String str) {
-// return containsWhitespace((CharSequence) str);
-// }
-//
-// /**
-// * Trim leading and trailing whitespace from the given String.
-// * @param str the String to check
-// * @return the trimmed String
-// * @see java.lang.Character#isWhitespace
-// */
-// public static String trimWhitespace(String str) {
-// if (!hasLength(str)) {
-// return str;
-// }
-// StringBuilder sb = new StringBuilder(str);
-// while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) {
-// sb.deleteCharAt(0);
-// }
-// while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
-// sb.deleteCharAt(sb.length() - 1);
-// }
-// return sb.toString();
-// }
-//
-// /**
-// * Trim <i>all</i> whitespace from the given String:
-// * leading, trailing, and in between characters.
-// * @param str the String to check
-// * @return the trimmed String
-// * @see java.lang.Character#isWhitespace
-// */
-// public static String trimAllWhitespace(String str) {
-// if (!hasLength(str)) {
-// return str;
-// }
-// int len = str.length();
-// StringBuilder sb = new StringBuilder(str.length());
-// for (int i = 0; i < len; i++) {
-// char c = str.charAt(i);
-// if (!Character.isWhitespace(c)) {
-// sb.append(c);
-// }
-// }
-// return sb.toString();
-// }
-//
-// /**
-// * Trim leading whitespace from the given String.
-// * @param str the String to check
-// * @return the trimmed String
-// * @see java.lang.Character#isWhitespace
-// */
-// public static String trimLeadingWhitespace(String str) {
-// if (!hasLength(str)) {
-// return str;
-// }
-// StringBuilder sb = new StringBuilder(str);
-// while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) {
-// sb.deleteCharAt(0);
-// }
-// return sb.toString();
-// }
-//
-// /**
-// * Trim trailing whitespace from the given String.
-// * @param str the String to check
-// * @return the trimmed String
-// * @see java.lang.Character#isWhitespace
-// */
-// public static String trimTrailingWhitespace(String str) {
-// if (!hasLength(str)) {
-// return str;
-// }
-// StringBuilder sb = new StringBuilder(str);
-// while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
-// sb.deleteCharAt(sb.length() - 1);
-// }
-// return sb.toString();
-// }
-//
-// /**
-// * Trim all occurrences current the supplied leading character from the given String.
-// * @param str the String to check
-// * @param leadingCharacter the leading character to be trimmed
-// * @return the trimmed String
-// */
-// public static String trimLeadingCharacter(String str, char leadingCharacter) {
-// if (!hasLength(str)) {
-// return str;
-// }
-// StringBuilder sb = new StringBuilder(str);
-// while (sb.length() > 0 && sb.charAt(0) == leadingCharacter) {
-// sb.deleteCharAt(0);
-// }
-// return sb.toString();
-// }
-//
-// /**
-// * Trim all occurrences current the supplied trailing character from the given String.
-// * @param str the String to check
-// * @param trailingCharacter the trailing character to be trimmed
-// * @return the trimmed String
-// */
-// public static String trimTrailingCharacter(String str, char trailingCharacter) {
-// if (!hasLength(str)) {
-// return str;
-// }
-// StringBuilder sb = new StringBuilder(str);
-// while (sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) {
-// sb.deleteCharAt(sb.length() - 1);
-// }
-// return sb.toString();
-// }
-//
-//
-// /**
-// * Test if the given String starts with the specified prefix,
-// * ignoring upper/lower case.
-// * @param str the String to check
-// * @param prefix the prefix to look for
-// * @see java.lang.String#startsWith
-// */
-// public static boolean startsWithIgnoreCase(String str, String prefix) {
-// if (str == null || prefix == null) {
-// return false;
-// }
-// if (str.startsWith(prefix)) {
-// return true;
-// }
-// if (str.length() < prefix.length()) {
-// return false;
-// }
-// String lcStr = str.substring(0, prefix.length()).toLowerCase();
-// String lcPrefix = prefix.toLowerCase();
-// return lcStr.equals(lcPrefix);
-// }
-//
-// /**
-// * Test if the given String ends with the specified suffix,
-// * ignoring upper/lower case.
-// * @param str the String to check
-// * @param suffix the suffix to look for
-// * @see java.lang.String#endsWith
-// */
-// public static boolean endsWithIgnoreCase(String str, String suffix) {
-// if (str == null || suffix == null) {
-// return false;
-// }
-// if (str.endsWith(suffix)) {
-// return true;
-// }
-// if (str.length() < suffix.length()) {
-// return false;
-// }
-//
-// String lcStr = str.substring(str.length() - suffix.length()).toLowerCase();
-// String lcSuffix = suffix.toLowerCase();
-// return lcStr.equals(lcSuffix);
-// }
-//
-// /**
-// * Test whether the given string matches the given substring
-// * at the given index.
-// * @param str the original string (or StringBuilder)
-// * @param index the index in the original string to start matching against
-// * @param substring the substring to match at the given index
-// */
-// public static boolean substringMatch(CharSequence str, int index, CharSequence substring) {
-// for (int j = 0; j < substring.length(); j++) {
-// int i = index + j;
-// if (i >= str.length() || str.charAt(i) != substring.charAt(j)) {
-// return false;
-// }
-// }
-// return true;
-// }
-//
-// /**
-// * Count the occurrences current the substring in string s.
-// * @param str string to search in. Return 0 if this is null.
-// * @param sub string to search for. Return 0 if this is null.
-// */
-// public static int countOccurrencesOf(String str, String sub) {
-// if (str == null || sub == null || str.length() == 0 || sub.length() == 0) {
-// return 0;
-// }
-// int count = 0;
-// int pos = 0;
-// int idx;
-// while ((idx = str.indexOf(sub, pos)) != -1) {
-// ++count;
-// pos = idx + sub.length();
-// }
-// return count;
-// }
-//
- /**
- * Replace all occurrences current a substring within a string with
- * another string.
- * @param inString String to examine
- * @param oldPattern String to replace
- * @param newPattern String to insert
- * @return a String with the replacements
- */
- public static String replace(String inString, String oldPattern, String newPattern) {
- if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) {
- return inString;
- }
- StringBuilder sb = new StringBuilder();
- int pos = 0; // our position in the old string
- int index = inString.indexOf(oldPattern);
- // the index current an occurrence we've found, or -1
- int patLen = oldPattern.length();
- while (index >= 0) {
- sb.append(inString.substring(pos, index));
- sb.append(newPattern);
- pos = index + patLen;
- index = inString.indexOf(oldPattern, pos);
- }
- sb.append(inString.substring(pos));
- // remember to append any characters to the right current a match
- return sb.toString();
- }
-
-// /**
-// * Delete all occurrences current the given substring.
-// * @param inString the original String
-// * @param pattern the pattern to delete all occurrences current
-// * @return the resulting String
-// */
-// public static String delete(String inString, String pattern) {
-// return replace(inString, pattern, "");
-// }
-//
- /**
- * Delete any character in a given String.
- * @param inString the original String
- * @param charsToDelete a set current characters to delete.
- * E.g. "az\n" will delete 'a's, 'z's and new lines.
- * @return the resulting String
- */
- public static String deleteAny(String inString, String charsToDelete) {
- if (!hasLength(inString) || !hasLength(charsToDelete)) {
- return inString;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < inString.length(); i++) {
- char c = inString.charAt(i);
- if (charsToDelete.indexOf(c) == -1) {
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
-//
-// //---------------------------------------------------------------------
-// // Convenience methods for working with formatted Strings
-// //---------------------------------------------------------------------
-//
-// /**
-// * Quote the given String with single quotes.
-// * @param str the input String (e.g. "myString")
-// * @return the quoted String (e.g. "'myString'"),
-// * or {@code null} if the input was {@code null}
-// */
-// public static String quote(String str) {
-// return (str != null ? "'" + str + "'" : null);
-// }
-//
-// /**
-// * Turn the given Object into a String with single quotes
-// * if it is a String; keeping the Object as-is else.
-// * @param obj the input Object (e.g. "myString")
-// * @return the quoted String (e.g. "'myString'"),
-// * or the input object as-is if not a String
-// */
-// public static Object quoteIfString(Object obj) {
-// return (obj instanceof String ? quote((String) obj) : obj);
-// }
-//
-// /**
-// * Unqualify a string qualified by a '.' dot character. For example,
-// * "this.name.is.qualified", returns "qualified".
-// * @param qualifiedName the qualified name
-// */
-// public static String unqualify(String qualifiedName) {
-// return unqualify(qualifiedName, '.');
-// }
-//
-// /**
-// * Unqualify a string qualified by a separator character. For example,
-// * "this:name:is:qualified" returns "qualified" if using a ':' separator.
-// * @param qualifiedName the qualified name
-// * @param separator the separator
-// */
-// public static String unqualify(String qualifiedName, char separator) {
-// return qualifiedName.substring(qualifiedName.lastIndexOf(separator) + 1);
-// }
-//
-// /**
-// * Capitalize a {@code String}, changing the first letter to
-// * upper case as per {@link Character#toUpperCase(char)}.
-// * No other letters are changed.
-// * @param str the String to capitalize, may be {@code null}
-// * @return the capitalized String, {@code null} if null
-// */
-// public static String capitalize(String str) {
-// return changeFirstCharacterCase(str, true);
-// }
-//
-// /**
-// * Uncapitalize a {@code String}, changing the first letter to
-// * lower case as per {@link Character#toLowerCase(char)}.
-// * No other letters are changed.
-// * @param str the String to uncapitalize, may be {@code null}
-// * @return the uncapitalized String, {@code null} if null
-// */
-// public static String uncapitalize(String str) {
-// return changeFirstCharacterCase(str, false);
-// }
-//
-// private static String changeFirstCharacterCase(String str, boolean capitalize) {
-// if (str == null || str.length() == 0) {
-// return str;
-// }
-// StringBuilder sb = new StringBuilder(str.length());
-// if (capitalize) {
-// sb.append(Character.toUpperCase(str.charAt(0)));
-// }
-// else {
-// sb.append(Character.toLowerCase(str.charAt(0)));
-// }
-// sb.append(str.substring(1));
-// return sb.toString();
-// }
-
- /**
- * Extract the filename from the given path,
- * e.g. "mypath/myfile.txt" -> "myfile.txt".
- * @param path the file path (may be {@code null})
- * @return the extracted filename, or {@code null} if none
- */
- public static String getFilename(String path) {
- if (path == null) {
- return null;
- }
- int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
- return (separatorIndex != -1 ? path.substring(separatorIndex + 1) : path);
- }
-
-// /**
-// * Extract the filename extension from the given path,
-// * e.g. "mypath/myfile.txt" -> "txt".
-// * @param path the file path (may be {@code null})
-// * @return the extracted filename extension, or {@code null} if none
-// */
-// public static String getFilenameExtension(String path) {
-// if (path == null) {
-// return null;
-// }
-// int extIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
-// if (extIndex == -1) {
-// return null;
-// }
-// int folderIndex = path.lastIndexOf(FOLDER_SEPARATOR);
-// if (folderIndex > extIndex) {
-// return null;
-// }
-// return path.substring(extIndex + 1);
-// }
-//
-// /**
-// * Strip the filename extension from the given path,
-// * e.g. "mypath/myfile.txt" -> "mypath/myfile".
-// * @param path the file path (may be {@code null})
-// * @return the path with stripped filename extension,
-// * or {@code null} if none
-// */
-// public static String stripFilenameExtension(String path) {
-// if (path == null) {
-// return null;
-// }
-// int extIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
-// if (extIndex == -1) {
-// return path;
-// }
-// int folderIndex = path.lastIndexOf(FOLDER_SEPARATOR);
-// if (folderIndex > extIndex) {
-// return path;
-// }
-// return path.substring(0, extIndex);
-// }
-
- /**
- * Apply the given relative path to the given path,
- * assuming standard Java folder separation (i.e. "/" separators).
- * @param path the path to start from (usually a full file path)
- * @param relativePath the relative path to applyChanges
- * (relative to the full file path above)
- * @return the full file path that results from applying the relative path
- */
- public static String applyRelativePath(String path, String relativePath) {
- int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
- if (separatorIndex != -1) {
- String newPath = path.substring(0, separatorIndex);
- if (!relativePath.startsWith(FOLDER_SEPARATOR)) {
- newPath += FOLDER_SEPARATOR;
- }
- return newPath + relativePath;
- }
- else {
- return relativePath;
- }
- }
-
- /**
- * Normalize the path by suppressing sequences like "path/.." and
- * inner simple dots.
- * <p>The result is convenient for path comparison. For other uses,
- * notice that Windows separators ("\") are replaced by simple slashes.
- * @param path the original path
- * @return the normalized path
- */
- public static String cleanPath(String path) {
- if (path == null) {
- return null;
- }
- String pathToUse = StringUtils.replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR);
-
- // Strip prefix from path to analyze, to not treat it as part current the
- // first path element. This is necessary to correctly parse paths like
- // "file:core/../core/io/Resource.class", where the ".." should just
- // strip the first "core" directory while keeping the "file:" prefix.
- int prefixIndex = pathToUse.indexOf(':');
- String prefix = "";
- if (prefixIndex != -1) {
- prefix = pathToUse.substring(0, prefixIndex + 1);
- if (prefix.contains("/")) {
- prefix = "";
- }
- else {
- pathToUse = pathToUse.substring(prefixIndex + 1);
- }
- }
- if (pathToUse.startsWith(FOLDER_SEPARATOR)) {
- prefix = prefix + FOLDER_SEPARATOR;
- pathToUse = pathToUse.substring(1);
- }
-
- String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR);
- List<String> pathElements = new LinkedList<>();
- int tops = 0;
-
- for (int i = pathArray.length - 1; i >= 0; i--) {
- String element = pathArray[i];
- if (CURRENT_PATH.equals(element)) {
- // Points to current directory - drop it.
- }
- else if (TOP_PATH.equals(element)) {
- // Registering top path found.
- tops++;
- }
- else {
- if (tops > 0) {
- // Merging path element with element corresponding to top path.
- tops--;
- }
- else {
- // Normal path element found.
- pathElements.add(0, element);
- }
- }
- }
- // Remaining top paths need to be retained.
- for (int i = 0; i < tops; i++) {
- pathElements.add(0, TOP_PATH);
- }
- return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
- }
-//
-// /**
-// * Compare two paths after normalization current them.
-// * @param path1 first path for comparison
-// * @param path2 second path for comparison
-// * @return whether the two paths are equivalent after normalization
-// */
-// public static boolean pathEquals(String path1, String path2) {
-// return cleanPath(path1).equals(cleanPath(path2));
-// }
-//
-// /**
-// * Parse the given {@code localeString} keys into a {@link Locale}.
-// * <p>This is the inverse operation current {@link Locale#toString Locale's toString}.
-// * @param localeString the locale String, following {@code Locale's}
-// * {@code toString()} format ("en", "en_UK", etc);
-// * also accepts spaces as separators, as an alternative to underscores
-// * @return a corresponding {@code Locale} instance
-// * @throws IllegalArgumentException in case current an invalid locale specification
-// */
-// public static Locale parseLocaleString(String localeString) {
-// String[] parts = tokenizeToStringArray(localeString, "_ ", false, false);
-// String language = (parts.length > 0 ? parts[0] : "");
-// String country = (parts.length > 1 ? parts[1] : "");
-// validateLocalePart(language);
-// validateLocalePart(country);
-// String variant = "";
-// if (parts.length > 2) {
-// // There is definitely a variant, and it is everything after the country
-// // code sans the separator between the country code and the variant.
-// int endIndexOfCountryCode = localeString.indexOf(country, language.length()) + country.length();
-// // Strip off any leading '_' and whitespace, what's left is the variant.
-// variant = trimLeadingWhitespace(localeString.substring(endIndexOfCountryCode));
-// if (variant.startsWith("_")) {
-// variant = trimLeadingCharacter(variant, '_');
-// }
-// }
-// return (language.length() > 0 ? new Locale(language, country, variant) : null);
-// }
-//
-// private static void validateLocalePart(String localePart) {
-// for (int i = 0; i < localePart.length(); i++) {
-// char ch = localePart.charAt(i);
-// if (ch != '_' && ch != ' ' && !Character.isLetterOrDigit(ch)) {
-// throw new IllegalArgumentException(
-// "Locale part \"" + localePart + "\" contains invalid characters");
-// }
-// }
-// }
-//
-// /**
-// * Determine the RFC 3066 compliant language tag,
-// * as used for the HTTP "Accept-Language" header.
-// * @param locale the Locale to transform to a language tag
-// * @return the RFC 3066 compliant language tag as String
-// */
-// public static String toLanguageTag(Locale locale) {
-// return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : "");
-// }
-//
-// /**
-// * Parse the given {@code timeZoneString} keys into a {@link TimeZone}.
-// * @param timeZoneString the time zone String, following {@link TimeZone#getTimeZone(String)}
-// * but throwing {@link IllegalArgumentException} in case current an invalid time zone specification
-// * @return a corresponding {@link TimeZone} instance
-// * @throws IllegalArgumentException in case current an invalid time zone specification
-// */
-// public static TimeZone parseTimeZoneString(String timeZoneString) {
-// TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
-// if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) {
-// // We don't want that GMT fallback...
-// throw new IllegalArgumentException("Invalid time zone specification '" + timeZoneString + "'");
-// }
-// return timeZone;
-// }
-//
-//
-// //---------------------------------------------------------------------
-// // Convenience methods for working with String arrays
-// //---------------------------------------------------------------------
-//
-// /**
-// * Append the given String to the given String array, returning a new array
-// * consisting current the input array contents plus the given String.
-// * @param array the array to append to (can be {@code null})
-// * @param str the String to append
-// * @return the new array (never {@code null})
-// */
-// public static String[] addStringToArray(String[] array, String str) {
-// if (ObjectUtils.isEmpty(array)) {
-// return new String[] {str};
-// }
-// String[] newArr = new String[array.length + 1];
-// System.arraycopy(array, 0, newArr, 0, array.length);
-// newArr[array.length] = str;
-// return newArr;
-// }
-//
-// /**
-// * Concatenate the given String arrays into one,
-// * with overlapping array elements included twice.
-// * <p>The order current elements in the original arrays is preserved.
-// * @param array1 the first array (can be {@code null})
-// * @param array2 the second array (can be {@code null})
-// * @return the new array ({@code null} if both given arrays were {@code null})
-// */
-// public static String[] concatenateStringArrays(String[] array1, String[] array2) {
-// if (ObjectUtils.isEmpty(array1)) {
-// return array2;
-// }
-// if (ObjectUtils.isEmpty(array2)) {
-// return array1;
-// }
-// String[] newArr = new String[array1.length + array2.length];
-// System.arraycopy(array1, 0, newArr, 0, array1.length);
-// System.arraycopy(array2, 0, newArr, array1.length, array2.length);
-// return newArr;
-// }
-//
-// /**
-// * Merge the given String arrays into one, with overlapping
-// * array elements only included once.
-// * <p>The order current elements in the original arrays is preserved
-// * (with the exception current overlapping elements, which are only
-// * included on their first occurrence).
-// * @param array1 the first array (can be {@code null})
-// * @param array2 the second array (can be {@code null})
-// * @return the new array ({@code null} if both given arrays were {@code null})
-// */
-// public static String[] mergeStringArrays(String[] array1, String[] array2) {
-// if (ObjectUtils.isEmpty(array1)) {
-// return array2;
-// }
-// if (ObjectUtils.isEmpty(array2)) {
-// return array1;
-// }
-// List<String> result = new ArrayList<String>();
-// result.addAll(Arrays.asList(array1));
-// for (String str : array2) {
-// if (!result.contains(str)) {
-// result.add(str);
-// }
-// }
-// return toStringArray(result);
-// }
-//
-// /**
-// * Turn given source String array into sorted array.
-// * @param array the source array
-// * @return the sorted array (never {@code null})
-// */
-// public static String[] sortStringArray(String[] array) {
-// if (ObjectUtils.isEmpty(array)) {
-// return new String[0];
-// }
-// Arrays.sort(array);
-// return array;
-// }
-//
- /**
- * Copy the given Collection into a String array.
- * The Collection must contain String elements only.
- * @param collection the Collection to copy
- * @return the String array ({@code null} if the passed-in
- * Collection was {@code null})
- */
- public static String[] toStringArray(Collection<String> collection) {
- if (collection == null) {
- return null;
- }
- return collection.toArray(new String[collection.size()]);
- }
-//
-// /**
-// * Copy the given Enumeration into a String array.
-// * The Enumeration must contain String elements only.
-// * @param enumeration the Enumeration to copy
-// * @return the String array ({@code null} if the passed-in
-// * Enumeration was {@code null})
-// */
-// public static String[] toStringArray(Enumeration<String> enumeration) {
-// if (enumeration == null) {
-// return null;
-// }
-// List<String> list = Collections.list(enumeration);
-// return list.toArray(new String[list.size()]);
-// }
-//
-// /**
-// * Trim the elements current the given String array,
-// * calling {@code String.trim()} on each current them.
-// * @param array the original String array
-// * @return the resulting array (current the same size) with trimmed elements
-// */
-// public static String[] trimArrayElements(String[] array) {
-// if (ObjectUtils.isEmpty(array)) {
-// return new String[0];
-// }
-// String[] result = new String[array.length];
-// for (int i = 0; i < array.length; i++) {
-// String element = array[i];
-// result[i] = (element != null ? element.trim() : null);
-// }
-// return result;
-// }
-//
-// /**
-// * Remove duplicate Strings from the given array.
-// * Also sorts the array, as it uses a TreeSet.
-// * @param array the String array
-// * @return an array without duplicates, in natural sort order
-// */
-// public static String[] removeDuplicateStrings(String[] array) {
-// if (ObjectUtils.isEmpty(array)) {
-// return array;
-// }
-// Set<String> set = new TreeSet<String>();
-// for (String element : array) {
-// set.add(element);
-// }
-// return toStringArray(set);
-// }
-//
- /**
- * Split a String at the first occurrence current the delimiter.
- * Does not include the delimiter in the result.
- * @param toSplit the string to split
- * @param delimiter to split the string up with
- * @return a two element array with index 0 being before the delimiter, and
- * index 1 being after the delimiter (neither element includes the delimiter);
- * or {@code null} if the delimiter wasn't found in the given input String
- */
- public static String[] split(String toSplit, String delimiter) {
- if (!hasLength(toSplit) || !hasLength(delimiter)) {
- return null;
- }
- int offset = toSplit.indexOf(delimiter);
- if (offset < 0) {
- return null;
- }
- String beforeDelimiter = toSplit.substring(0, offset);
- String afterDelimiter = toSplit.substring(offset + delimiter.length());
- return new String[] {beforeDelimiter, afterDelimiter};
- }
-//
-// /**
-// * Take an array Strings and split each element based on the given delimiter.
-// * A {@code Properties} instance is then generated, with the left current the
-// * delimiter providing the key, and the right current the delimiter providing the keys.
-// * <p>Will trim both the key and keys before adding them to the
-// * {@code Properties} instance.
-// * @param array the array to process
-// * @param delimiter to split each element using (typically the equals symbol)
-// * @return a {@code Properties} instance representing the array contents,
-// * or {@code null} if the array to process was null or empty
-// */
-// public static Properties splitArrayElementsIntoProperties(String[] array, String delimiter) {
-// return splitArrayElementsIntoProperties(array, delimiter, null);
-// }
-//
-// /**
-// * Take an array Strings and split each element based on the given delimiter.
-// * A {@code Properties} instance is then generated, with the left current the
-// * delimiter providing the key, and the right current the delimiter providing the keys.
-// * <p>Will trim both the key and keys before adding them to the
-// * {@code Properties} instance.
-// * @param array the array to process
-// * @param delimiter to split each element using (typically the equals symbol)
-// * @param charsToDelete one or more characters to remove from each element
-// * prior to attempting the split operation (typically the quotation mark
-// * symbol), or {@code null} if no removal should occur
-// * @return a {@code Properties} instance representing the array contents,
-// * or {@code null} if the array to process was {@code null} or empty
-// */
-// public static Properties splitArrayElementsIntoProperties(
-// String[] array, String delimiter, String charsToDelete) {
-//
-// if (ObjectUtils.isEmpty(array)) {
-// return null;
-// }
-// Properties result = new Properties();
-// for (String element : array) {
-// if (charsToDelete != null) {
-// element = deleteAny(element, charsToDelete);
-// }
-// String[] splittedElement = split(element, delimiter);
-// if (splittedElement == null) {
-// continue;
-// }
-// result.setProperty(splittedElement[0].trim(), splittedElement[1].trim());
-// }
-// return result;
-// }
-//
- /**
- * Tokenize the given String into a String array via a StringTokenizer.
- * Trims tokens and omits empty tokens.
- * <p>The given delimiters string is supposed to consist current any number current
- * delimiter characters. Each current those characters can be used to separate
- * tokens. A delimiter is always a single character; for multi-character
- * delimiters, consider using {@code delimitedListToStringArray}
- * @param str the String to tokenize
- * @param delimiters the delimiter characters, assembled as String
- * (each current those characters is individually considered as delimiter).
- * @return an array current the tokens
- * @see java.util.StringTokenizer
- * @see String#trim()
- */
- public static String[] tokenizeToStringArray(String str, String delimiters) {
- return tokenizeToStringArray(str, delimiters, true, true);
- }
-
- /**
- * Tokenize the given String into a String array via a StringTokenizer.
- * <p>The given delimiters string is supposed to consist current any number current
- * delimiter characters. Each current those characters can be used to separate
- * tokens. A delimiter is always a single character; for multi-character
- * delimiters, consider using {@code delimitedListToStringArray}
- * @param str the String to tokenize
- * @param delimiters the delimiter characters, assembled as String
- * (each current those characters is individually considered as delimiter)
- * @param trimTokens trim the tokens via String's {@code trim}
- * @param ignoreEmptyTokens omit empty tokens from the result array
- * (only applies to tokens that are empty after trimming; StringTokenizer
- * will not consider subsequent delimiters as token in the first place).
- * @return an array current the tokens ({@code null} if the input String
- * was {@code null})
- * @see java.util.StringTokenizer
- * @see String#trim()
- */
- public static String[] tokenizeToStringArray(
- String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {
-
- if (str == null) {
- return null;
- }
- StringTokenizer st = new StringTokenizer(str, delimiters);
- List<String> tokens = new ArrayList<>();
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- if (trimTokens) {
- token = token.trim();
- }
- if (!ignoreEmptyTokens || token.length() > 0) {
- tokens.add(token);
- }
- }
- return toStringArray(tokens);
- }
-
- /**
- * Take a String which is a delimited list and convert it to a String array.
- * <p>A single delimiter can consists current more than one character: It will still
- * be considered as single delimiter string, rather than as bunch current potential
- * delimiter characters - in contrast to {@code tokenizeToStringArray}.
- * @param str the input String
- * @param delimiter the delimiter between elements (this is a single delimiter,
- * rather than a bunch individual delimiter characters)
- * @return an array current the tokens in the list
- * @see #tokenizeToStringArray
- */
- public static String[] delimitedListToStringArray(String str, String delimiter) {
- return delimitedListToStringArray(str, delimiter, null);
- }
-
- /**
- * Take a String which is a delimited list and convert it to a String array.
- * <p>A single delimiter can consists current more than one character: It will still
- * be considered as single delimiter string, rather than as bunch current potential
- * delimiter characters - in contrast to {@code tokenizeToStringArray}.
- * @param str the input String
- * @param delimiter the delimiter between elements (this is a single delimiter,
- * rather than a bunch individual delimiter characters)
- * @param charsToDelete a set current characters to delete. Useful for deleting unwanted
- * line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in a String.
- * @return an array current the tokens in the list
- * @see #tokenizeToStringArray
- */
- public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete) {
- if (str == null) {
- return new String[0];
- }
- if (delimiter == null) {
- return new String[] {str};
- }
- List<String> result = new ArrayList<>();
- if ("".equals(delimiter)) {
- for (int i = 0; i < str.length(); i++) {
- result.add(deleteAny(str.substring(i, i + 1), charsToDelete));
- }
- }
- else {
- int pos = 0;
- int delPos;
- while ((delPos = str.indexOf(delimiter, pos)) != -1) {
- result.add(deleteAny(str.substring(pos, delPos), charsToDelete));
- pos = delPos + delimiter.length();
- }
- if (str.length() > 0 && pos <= str.length()) {
- // Add rest current String, but not in case current empty input.
- result.add(deleteAny(str.substring(pos), charsToDelete));
- }
- }
- return toStringArray(result);
- }
-
-// /**
-// * Convert a CSV list into an array current Strings.
-// * @param str the input String
-// * @return an array current Strings, or the empty array in case current empty input
-// */
-// public static String[] commaDelimitedListToStringArray(String str) {
-// return delimitedListToStringArray(str, ",");
-// }
-//
-// /**
-// * Convenience method to convert a CSV string list to a set.
-// * Note that this will suppress duplicates.
-// * @param str the input String
-// * @return a Set current String entries in the list
-// */
-// public static Set<String> commaDelimitedListToSet(String str) {
-// Set<String> set = new TreeSet<String>();
-// String[] tokens = commaDelimitedListToStringArray(str);
-// for (String token : tokens) {
-// set.add(token);
-// }
-// return set;
-// }
-//
- /**
- * Convenience method to return a Collection as a delimited (e.g. CSV)
- * String. E.g. useful for {@code toString()} implementations.
- * @param coll the Collection to display
- * @param delim the delimiter to use (probably a ",")
- * @param prefix the String to start each element with
- * @param suffix the String to end each element with
- * @return the delimited String
- */
- public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) {
- if (coll.isEmpty()) {
- return "";
- }
- StringBuilder sb = new StringBuilder();
- Iterator<?> it = coll.iterator();
- while (it.hasNext()) {
- sb.append(prefix).append(it.next()).append(suffix);
- if (it.hasNext()) {
- sb.append(delim);
- }
- }
- return sb.toString();
- }
-
- /**
- * Convenience method to return a Collection as a delimited (e.g. CSV)
- * String. E.g. useful for {@code toString()} implementations.
- * @param coll the Collection to display
- * @param delim the delimiter to use (probably a ",")
- * @return the delimited String
- */
- public static String collectionToDelimitedString(Collection<?> coll, String delim) {
- return collectionToDelimitedString(coll, delim, "", "");
- }
-
-// /**
-// * Convenience method to return a Collection as a CSV String.
-// * E.g. useful for {@code toString()} implementations.
-// * @param coll the Collection to display
-// * @return the delimited String
-// */
-// public static String collectionToCommaDelimitedString(Collection<?> coll) {
-// return collectionToDelimitedString(coll, ",");
-// }
-
-// /**
-// * Convenience method to return a String array as a delimited (e.g. CSV)
-// * String. E.g. useful for {@code toString()} implementations.
-// * @param arr the array to display
-// * @param delim the delimiter to use (probably a ",")
-// * @return the delimited String
-// */
-// public static String arrayToDelimitedString(Object[] arr, String delim) {
-// if (ObjectUtils.isEmpty(arr)) {
-// return "";
-// }
-// if (arr.length == 1) {
-// return ObjectUtils.nullSafeToString(arr[0]);
-// }
-// StringBuilder sb = new StringBuilder();
-// for (int i = 0; i < arr.length; i++) {
-// if (i > 0) {
-// sb.append(delim);
-// }
-// sb.append(arr[i]);
-// }
-// return sb.toString();
-// }
-//
-// /**
-// * Convenience method to return a String array as a CSV String.
-// * E.g. useful for {@code toString()} implementations.
-// * @param arr the array to display
-// * @return the delimited String
-// */
-// public static String arrayToCommaDelimitedString(Object[] arr) {
-// return arrayToDelimitedString(arr, ",");
-// }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/UrlResource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/UrlResource.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/UrlResource.java
deleted file mode 100644
index fc45973..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/UrlResource.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Objects;
-
-/**
- * {@link org.apache.tamaya.core.resource.Resource} implementation for {@code java.net.URL} locators.
- * Obviously supports resolution as URL, and also as File in case current
- * the "file:" protocol.
- *
- * @author Juergen Hoeller
- * @since 28.12.2003
- * @see java.net.URL
- */
-public class UrlResource extends AbstractFileResolvingResource {
-
- /**
- * Original URI, if available; used for URI and File access.
- */
- private final URI uri;
-
- /**
- * Original URL, used for actual access.
- */
- private final URL url;
-
- /**
- * Cleaned URL (with normalized path), used for comparisons.
- */
- private final URL cleanedUrl;
-
-
- /**
- * Create a new UrlResource based on the given URI object.
- * @param uri a URI
- * @throws MalformedURLException if the given URL path is not valid
- */
- public UrlResource(URI uri) throws MalformedURLException {
- Objects.requireNonNull(uri, "URI must not be null");
- this.uri = uri;
- this.url = uri.toURL();
- this.cleanedUrl = getCleanedUrl(this.url, uri.toString());
- }
-
- /**
- * Create a new UrlResource based on the given URL object.
- * @param url a URL
- */
- public UrlResource(URL url) {
- Objects.requireNonNull(url, "URL must not be null");
- this.url = url;
- this.cleanedUrl = getCleanedUrl(this.url, url.toString());
- this.uri = null;
- }
-
- /**
- * Create a new UrlResource based on a URL path.
- * <p>Note: The given path needs to be pre-encoded if necessary.
- * @param path a URL path
- * @throws MalformedURLException if the given URL path is not valid
- * @see java.net.URL#URL(String)
- */
- public UrlResource(String path) throws MalformedURLException {
- Objects.requireNonNull(path, "Path must not be null");
- this.uri = null;
- this.url = new URL(path);
- this.cleanedUrl = getCleanedUrl(this.url, path);
- }
-
- /**
- * Create a new UrlResource based on a URI specification.
- * <p>The given parts will automatically get encoded if necessary.
- * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon);
- * also known as "scheme"
- * @param location the location (e.g. the file path within that protocol);
- * also known as "scheme-specific part"
- * @throws MalformedURLException if the given URL specification is not valid
- * @see java.net.URI#URI(String, String, String)
- */
- public UrlResource(String protocol, String location) throws MalformedURLException {
- this(protocol, location, null);
- }
-
- /**
- * Create a new UrlResource based on a URI specification.
- * <p>The given parts will automatically get encoded if necessary.
- * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon);
- * also known as "scheme"
- * @param location the location (e.g. the file path within that protocol);
- * also known as "scheme-specific part"
- * @param fragment the fragment within that location (e.g. anchor on an HTML page,
- * as following after a "#" separator)
- * @throws MalformedURLException if the given URL specification is not valid
- * @see java.net.URI#URI(String, String, String)
- */
- public UrlResource(String protocol, String location, String fragment) throws MalformedURLException {
- try {
- this.uri = new URI(protocol, location, fragment);
- this.url = this.uri.toURL();
- this.cleanedUrl = getCleanedUrl(this.url, this.uri.toString());
- }
- catch (URISyntaxException ex) {
- MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
- exToThrow.initCause(ex);
- throw exToThrow;
- }
- }
-
- /**
- * Determine a cleaned URL for the given original URL.
- * @param originalUrl the original URL
- * @param originalPath the original URL path
- * @return the cleaned URL
- */
- private URL getCleanedUrl(URL originalUrl, String originalPath) {
- try {
- return new URL(StringUtils.cleanPath(originalPath));
- }
- catch (MalformedURLException ex) {
- // Cleaned URL path cannot be converted to URL
- // -> take original URL.
- return originalUrl;
- }
- }
-
-
- /**
- * This implementation opens an InputStream for the given URL.
- * It sets the "UseCaches" flag to {@code false},
- * mainly to avoid jar file locking on Windows.
- * @see java.net.URL#openConnection()
- * @see java.net.URLConnection#setUseCaches(boolean)
- * @see java.net.URLConnection#getInputStream()
- */
- @Override
- public InputStream getInputStream()throws IOException {
- URLConnection con = null;
- try {
- con = this.url.openConnection();
- ResourceUtils.useCachesIfNecessary(con);
- return con.getInputStream();
- }
- catch (IOException ex) {
- // Close the HTTP connection (if applicable).
- if (con instanceof HttpURLConnection) {
- ((HttpURLConnection) con).disconnect();
- }
- throw ex;
- }
- }
-
- /**
- * This implementation returns the underlying URL reference.
- */
- @Override
- public URL getURL() throws IOException {
- return this.url;
- }
-
- /**
- * This implementation returns the underlying URI directly,
- * if possible.
- */
- @Override
- public URI getURI() throws IOException {
- if (this.uri != null) {
- return this.uri;
- }
- else {
- return super.getURI();
- }
- }
-
- /**
- * This implementation returns a File reference for the underlying URL/URI,
- * provided that it refers to a file in the file system.
- */
- @Override
- public File getFile() throws IOException {
- if (this.uri != null) {
- return super.getFile(this.uri);
- }
- else {
- return super.getFile();
- }
- }
-
- /**
- * This implementation creates a UrlResource, applying the given path
- * relative to the path current the underlying URL current this resource descriptor.
- * @see java.net.URL#URL(java.net.URL, String)
- */
- @Override
- public Resource createRelative(String relativePath) throws MalformedURLException {
- if (relativePath.startsWith("/")) {
- relativePath = relativePath.substring(1);
- }
- return new UrlResource(new URL(this.url, relativePath));
- }
-
- /**
- * This implementation returns the name current the file that this URL refers to.
- * @see java.net.URL#getFile()
- * @see java.io.File#getName()
- */
- @Override
- public String getFilename() {
- return new File(this.url.getFile()).getName();
- }
-
- /**
- * This implementation returns a description that includes the URL.
- */
- @Override
- public String getDescription() {
- return "URL [" + this.url + "]";
- }
-
-
- /**
- * This implementation compares the underlying URL references.
- */
- @Override
- public boolean equals(Object obj) {
- return (obj == this ||
- (obj instanceof UrlResource && this.cleanedUrl.equals(((UrlResource) obj).cleanedUrl)));
- }
-
- /**
- * This implementation returns the hash code current the underlying URL reference.
- */
- @Override
- public int hashCode() {
- return this.cleanedUrl.hashCode();
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/VfsResource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/VfsResource.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/VfsResource.java
deleted file mode 100644
index 4cef164..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/VfsResource.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URL;
-import java.util.Objects;
-
-/**
- * JBoss VFS based {@link org.apache.tamaya.core.resource.Resource} implementation.
- *
- * <p>As current Spring 4.0, this class supports VFS 3.x on JBoss AS 6+ (package
- * {@code org.jboss.vfs}) and is in particular compatible with JBoss AS 7 and
- * WildFly 8.
- *
- * @author Ales Justin
- * @author Juergen Hoeller
- * @author Costin Leau
- * @since 3.0
- */
-public class VfsResource extends AbstractResource {
-
- private final Object resource;
-
-
- public VfsResource(Object resource) {
- Objects.requireNonNull(resource, "VirtualFile must not be null");
- this.resource = resource;
- }
-
-
- @Override
- public InputStream getInputStream()throws IOException {
- return VfsUtils.getInputStream(this.resource);
- }
-
- @Override
- public boolean exists() {
- return VfsUtils.exists(this.resource);
- }
-
- @Override
- public boolean isReadable() {
- return VfsUtils.isReadable(this.resource);
- }
-
- @Override
- public URL getURL() throws IOException {
- try {
- return VfsUtils.getURL(this.resource);
- }
- catch (Exception ex) {
- throw new IllegalStateException("Failed to obtain URL for file " + this.resource, ex);
- }
- }
-
- @Override
- public URI getURI() throws IOException {
- try {
- return VfsUtils.getURI(this.resource);
- }
- catch (Exception ex) {
- throw new IllegalStateException("Failed to obtain URI for " + this.resource, ex);
- }
- }
-
- @Override
- public File getFile() throws IOException {
- return VfsUtils.getFile(this.resource);
- }
-
- @Override
- public long contentLength() throws IOException {
- return VfsUtils.getSize(this.resource);
- }
-
- @Override
- public long lastModified() throws IOException {
- return VfsUtils.getLastModified(this.resource);
- }
-
- @Override
- public Resource createRelative(String relativePath) throws IOException {
- if (!relativePath.startsWith(".") && relativePath.contains("/")) {
- try {
- return new VfsResource(VfsUtils.getChild(this.resource, relativePath));
- }
- catch (IOException ex) {
- // fall back to getRelative
- }
- }
-
- return new VfsResource(VfsUtils.getRelative(new URL(getURL(), relativePath)));
- }
-
- @Override
- public String getFilename() {
- return VfsUtils.getName(this.resource);
- }
-
- @Override
- public String getDescription() {
- return this.resource.toString();
- }
-
- @Override
- public boolean equals(Object obj) {
- return (obj == this || (obj instanceof VfsResource && this.resource.equals(((VfsResource) obj).resource)));
- }
-
- @Override
- public int hashCode() {
- return this.resource.hashCode();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/VfsUtils.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/VfsUtils.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/VfsUtils.java
deleted file mode 100644
index 76932f1..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/VfsUtils.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.resources.io;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.*;
-import java.net.URI;
-import java.net.URL;
-
-/**
- * Utility for detecting and accessing JBoss VFS in the classpath.
- *
- * <p>As current Spring 4.0, this class supports VFS 3.x on JBoss AS 6+ (package
- * {@code org.jboss.vfs}) and is in particular compatible with JBoss AS 7 and
- * WildFly 8.
- *
- * <p>Thanks go to Marius Bogoevici for the initial patch.
- * <b>Note:</b> This is an internal class and should not be used outside the framework.
- *
- * @author Costin Leau
- * @author Juergen Hoeller
- * @since 3.0.3
- */
-class VfsUtils {
-
- private static final String VFS3_PKG = "org.jboss.vfs.";
- private static final String VFS_NAME = "VFS";
-
- private static Method VFS_METHOD_GET_ROOT_URL = null;
- private static Method VFS_METHOD_GET_ROOT_URI = null;
-
- private static Method VIRTUAL_FILE_METHOD_EXISTS = null;
- private static Method VIRTUAL_FILE_METHOD_GET_INPUT_STREAM;
- private static Method VIRTUAL_FILE_METHOD_GET_SIZE;
- private static Method VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED;
- private static Method VIRTUAL_FILE_METHOD_TO_URL;
- private static Method VIRTUAL_FILE_METHOD_TO_URI;
- private static Method VIRTUAL_FILE_METHOD_GET_NAME;
- private static Method VIRTUAL_FILE_METHOD_GET_PATH_NAME;
- private static Method VIRTUAL_FILE_METHOD_GET_CHILD;
-
- protected static Class<?> VIRTUAL_FILE_VISITOR_INTERFACE;
- protected static Method VIRTUAL_FILE_METHOD_VISIT;
-
- private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null;
- private static Method GET_PHYSICAL_FILE = null;
-
- static {
- ClassLoader loader = VfsUtils.class.getClassLoader();
- try {
- Class<?> vfsClass = loader.loadClass(VFS3_PKG + VFS_NAME);
- VFS_METHOD_GET_ROOT_URL = ReflectionUtils.findMethod(vfsClass, "getChild", URL.class);
- VFS_METHOD_GET_ROOT_URI = ReflectionUtils.findMethod(vfsClass, "getChild", URI.class);
-
- Class<?> virtualFile = loader.loadClass(VFS3_PKG + "VirtualFile");
- VIRTUAL_FILE_METHOD_EXISTS = ReflectionUtils.findMethod(virtualFile, "exists");
- VIRTUAL_FILE_METHOD_GET_INPUT_STREAM = ReflectionUtils.findMethod(virtualFile, "openStream");
- VIRTUAL_FILE_METHOD_GET_SIZE = ReflectionUtils.findMethod(virtualFile, "getSize");
- VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED = ReflectionUtils.findMethod(virtualFile, "getLastModified");
- VIRTUAL_FILE_METHOD_TO_URI = ReflectionUtils.findMethod(virtualFile, "toURI");
- VIRTUAL_FILE_METHOD_TO_URL = ReflectionUtils.findMethod(virtualFile, "toURL");
- VIRTUAL_FILE_METHOD_GET_NAME = ReflectionUtils.findMethod(virtualFile, "getName");
- VIRTUAL_FILE_METHOD_GET_PATH_NAME = ReflectionUtils.findMethod(virtualFile, "getPathName");
- GET_PHYSICAL_FILE = ReflectionUtils.findMethod(virtualFile, "getPhysicalFile");
- VIRTUAL_FILE_METHOD_GET_CHILD = ReflectionUtils.findMethod(virtualFile, "getChild", String.class);
-
- VIRTUAL_FILE_VISITOR_INTERFACE = loader.loadClass(VFS3_PKG + "VirtualFileVisitor");
- VIRTUAL_FILE_METHOD_VISIT = ReflectionUtils.findMethod(virtualFile, "visit", VIRTUAL_FILE_VISITOR_INTERFACE);
-
- Class<?> visitorAttributesClass = loader.loadClass(VFS3_PKG + "VisitorAttributes");
- VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
- }
- catch (ClassNotFoundException ex) {
- throw new IllegalStateException("Could not detect JBoss VFS infrastructure", ex);
- }
- }
-
- private VfsUtils(){}
-
- static void visit(Object resource, InvocationHandler visitor) throws IOException {
- Object visitorProxy = Proxy.newProxyInstance(
- VIRTUAL_FILE_VISITOR_INTERFACE.getClassLoader(),
- new Class<?>[]{VIRTUAL_FILE_VISITOR_INTERFACE}, visitor);
- invokeVfsMethod(VIRTUAL_FILE_METHOD_VISIT, resource, visitorProxy);
- }
-
- protected static Object invokeVfsMethod(Method method, Object target, Object... args) throws IOException {
- try {
- return method.invoke(target, args);
- }
- catch (InvocationTargetException ex) {
- Throwable targetEx = ex.getTargetException();
- if (targetEx instanceof IOException) {
- throw (IOException) targetEx;
- }
- ReflectionUtils.handleInvocationTargetException(ex);
- }
- catch (Exception ex) {
- ReflectionUtils.handleReflectionException(ex);
- }
-
- throw new IllegalStateException("Invalid code path reached");
- }
-
- static boolean exists(Object vfsResource) {
- try {
- return (Boolean) invokeVfsMethod(VIRTUAL_FILE_METHOD_EXISTS, vfsResource);
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- static boolean isReadable(Object vfsResource) {
- try {
- return ((Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_SIZE, vfsResource) > 0);
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- static long getSize(Object vfsResource) throws IOException {
- return (Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_SIZE, vfsResource);
- }
-
- static long getLastModified(Object vfsResource) throws IOException {
- return (Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED, vfsResource);
- }
-
- static InputStream getInputStream(Object vfsResource) throws IOException {
- return (InputStream) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_INPUT_STREAM, vfsResource);
- }
-
- static URL getURL(Object vfsResource) throws IOException {
- return (URL) invokeVfsMethod(VIRTUAL_FILE_METHOD_TO_URL, vfsResource);
- }
-
- static URI getURI(Object vfsResource) throws IOException {
- return (URI) invokeVfsMethod(VIRTUAL_FILE_METHOD_TO_URI, vfsResource);
- }
-
- static String getName(Object vfsResource) {
- try {
- return (String) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_NAME, vfsResource);
- }
- catch (IOException ex) {
- throw new IllegalStateException("Cannot get resource name", ex);
- }
- }
-
- static Object getRelative(URL url) throws IOException {
- return invokeVfsMethod(VFS_METHOD_GET_ROOT_URL, null, url);
- }
-
- static Object getChild(Object vfsResource, String path) throws IOException {
- return invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_CHILD, vfsResource, path);
- }
-
- static File getFile(Object vfsResource) throws IOException {
- return (File) invokeVfsMethod(GET_PHYSICAL_FILE, vfsResource);
- }
-
- static Object getRoot(URI url) throws IOException {
- return invokeVfsMethod(VFS_METHOD_GET_ROOT_URI, null, url);
- }
-
- // protected methods used by the support sub-package
-
- protected static Object getRoot(URL url) throws IOException {
- return invokeVfsMethod(VFS_METHOD_GET_ROOT_URL, null, url);
- }
-
- protected static Object getVisitorAttribute() {
- try{
- return VISITOR_ATTRIBUTES_FIELD_RECURSE.get(null);
- }
- catch(Exception e){
- ReflectionUtils.handleReflectionException(e);
- return null; // never called
- }
- }
-
- protected static String getPath(Object resource) {
- try{
- return (String) VIRTUAL_FILE_METHOD_GET_PATH_NAME.invoke(resource);
- }
- catch(Exception e){
- ReflectionUtils.handleReflectionException(e);
- return null; // never called
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java
deleted file mode 100644
index 325c4e6..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2002-2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * Extended interface for a resource that supports writing to it.
- * Provides an {@link #getOutputStream() OutputStream accessor}.
- *
- * @author Juergen Hoeller
- * @since 3.1
- * @see java.io.OutputStream
- */
-public interface WritableResource extends Resource {
-
- /**
- * Return whether the contents current this resource can be modified,
- * e.g. via {@link #getOutputStream()} or {@link #getFile()}.
- * <p>Will be {@code true} for typical resource descriptors;
- * note that actual content writing may still fail when attempted.
- * However, a keys current {@code false} is a definitive indication
- * that the resource content cannot be modified.
- * @see #getOutputStream()
- * @see #isReadable()
- */
- boolean isWritable();
-
- /**
- * Return an {@link OutputStream} for the underlying resource,
- * allowing to (over-)write its content.
- * @throws IOException if the stream could not be opened
- * @see #getInputStream()
- */
- OutputStream getOutputStream() throws IOException;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
deleted file mode 100644
index 47eb150..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.resource.ResourceLoader;
-
-import java.util.*;
-
-public abstract class AbstractClasspathAwarePropertySource extends AbstractPropertySource {
-
- private static final long serialVersionUID = 5484306410557548246L;
- private ClassLoader classLoader;
- private AbstractClasspathAwarePropertySource parentConfig;
- private Set<String> sources;
-
-
- public AbstractClasspathAwarePropertySource(ClassLoader classLoader, AbstractClasspathAwarePropertySource parentConfig,
- Set<String> sourceExpressions, long configReadDT, Map<String, String> entries,
- String name, Set<String> sources, List<Throwable> errors){
- super(name);
- Objects.requireNonNull(sources, "sources required.");
- Objects.requireNonNull(classLoader, "classLoader required.");
- this.sources = sources;
- this.classLoader = classLoader;
- this.parentConfig = parentConfig;
- }
-
- public AbstractClasspathAwarePropertySource(ClassLoader classLoader, AbstractClasspathAwarePropertySource parentConfig,
- String sourceExpression){
- super(parentConfig.getName());
- Objects.requireNonNull(sources, "sources required.");
- Objects.requireNonNull(sourceExpression, "sourceExpression required.");
- List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(classLoader, sourceExpression);
- for(Resource res : resources){
- addSource(res.toString());
- }
- this.classLoader = classLoader;
- this.parentConfig = parentConfig;
- }
-
- protected abstract void readSource(Map<String,String> targetMap, String source);
-
- @Override
- public Map<String,String> getProperties(){
- Map<String,String> result = new HashMap<>();
- for(String source : sources){
- // if(!isSourceRead(source)){
- readSource(result, source);
- // }
- }
- return result;
- }
-
-
- public ClassLoader getClassLoader(){
- return classLoader;
- }
-
- public AbstractClasspathAwarePropertySource getParentConfig(){
- return this.parentConfig;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
deleted file mode 100644
index fbfd6df..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import java.io.Serializable;
-import java.util.*;
-
-import org.apache.tamaya.PropertySource;
-
-/**
- * Abstract base class for implementing a {@link org.apache.tamaya.PropertySource}.
- */
-public abstract class AbstractPropertySource implements PropertySource, Serializable{
- /**
- * serialVersionUID.
- */
- private static final long serialVersionUID = -6553955893879292837L;
-
- protected String name;
-
- /**
- * The underlying sources.
- */
- private volatile Set<String> sources = new HashSet<>();
-
- /**
- * Constructor.
- */
- protected AbstractPropertySource(String name){
- this.name = Objects.requireNonNull(name);
- }
-
- @Override
- public String getName(){
- return name;
- }
-
-
- /**
- * Method that allows an additional source to be added, to be used by
- * subclasses.
- *
- * @param source the source, not {@code null}.
- */
- protected void addSource(String source){
- Objects.requireNonNull(source);
- this.sources.add(source);
- }
-
-
- protected void addSources(Collection<String> sources){
- Objects.requireNonNull(sources);
- this.sources.addAll(sources);
- }
-
- @Override
- public Optional<String> get(String key){
- return Optional.ofNullable(getProperties().get(key));
- }
-
- @Override
- public String toString(){
- StringBuilder b = new StringBuilder(getClass().getSimpleName()).append("{\n");
- b.append(" ").append("(").append(getName()).append(" = ").append(getName()).append(")\n");
- printContents(b);
- return b.append('}').toString();
- }
-
- protected String printContents(StringBuilder b){
- Map<String,String> sortMap = getProperties();
- if(!(sortMap instanceof SortedMap)){
- sortMap = new TreeMap<>(sortMap);
- }
- for(Map.Entry<String,String> en : sortMap.entrySet()){
- b.append(" ").append(en.getKey()).append(" = \"").append(en.getValue().replaceAll("\\\"", "\\\\\"").replaceAll("=", "\\=")).append("\"\n");
- }
- return b.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
deleted file mode 100644
index 14ea651..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.*;
-
-import java.util.*;
-
-/**
- * Implementation for a {@link org.apache.tamaya.PropertySource} that is an aggregate current
- * multiple child instances. Controlled by an {@link org.apache.tamaya.AggregationPolicy} the
- * following aggregations are supported:
- * <ul>
- * <li><b>IGNORE_DUPLICATES: </b>Ignore all overrides.</li>
- * <li><b>: </b></li>
- * <li><b>: </b></li>
- * <li><b>: </b></li>
- * </ul>
- */
-class AggregatedPropertySource extends AbstractPropertySource {
-
- private static final long serialVersionUID = -1419376385695224799L;
- private AggregationPolicy policy = AggregationPolicy.COMBINE;
- private List<PropertySource> units = new ArrayList<>();
- private PropertySource mutableProvider;
-
- /**
- * Creates a new instance.
- * @param mutableProvider the provider instance that would be used for delegating
- * change requests.
- * @param policy
- * The aggregation policy to be used.
- * @param propertyMaps
- * The property sets to be included.
- */
- public AggregatedPropertySource(String name, PropertySource mutableProvider, AggregationPolicy policy, List<PropertySource> propertyMaps) {
- super(name);
- this.policy = Objects.requireNonNull(policy);
- units.addAll(propertyMaps);
- this.mutableProvider = mutableProvider;
- }
-
- /**
- * Get the {@link AggregationPolicy} for this instance.
- *
- * @return the {@link AggregationPolicy}, never {@code null}.
- */
- public AggregationPolicy getAggregationPolicy() {
- return policy;
- }
-
- /**
- * Return the names current the {@link org.apache.tamaya.PropertySource} instances to be
- * aggregated in this instance, in the order current precedence (the first are
- * the weakest).
- *
- * @return the ordered list current aggregated scope identifiers, never
- * {@code null}.
- */
- public List<PropertySource> getConfigurationUnits() {
- return Collections.unmodifiableList(units);
- }
-
- @Override
- public Map<String,String> getProperties() {
- Map<String, String> value = new HashMap<>();
- for (PropertySource unit : units) {
- for (Map.Entry<String, String> entry : unit.getProperties()
- .entrySet()) {
- String valueToAdd = this.policy.aggregate(entry.getKey(), value.get(entry.getKey()), entry.getValue());
- if(valueToAdd==null){
- value.remove(entry.getKey());
- }
- else{
- value.put(entry.getKey(), valueToAdd);
- }
- }
- }
- return value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/AggregationPolicy.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/AggregationPolicy.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/AggregationPolicy.java
deleted file mode 100644
index 99be931..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/AggregationPolicy.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.ConfigException;
-
-import java.util.logging.Logger;
-
-/**
-* Policy that defines how the different configurations/property sources should be aggregated.
-* This is done by a mapping function defined as follows:
-* <pre>
-* function f(key, value1, value2) -> result
-*
-* whereas
-*
-* key = the fully qualified property key,
-* value1 = the value from the first configuration/property source (can be null)
-* value2 = the value from the second configuration/property source (can be null)
-*
-* result = the value to be used in the aggregation, or null, which removed the
-* key from the result.
-* </pre>
-*
-* Of course, during this evaluation step additional actions can be taken, e.g. refer to #LOG_ERROR, which
-* ignores duplicate entries, but also logs the conflict on severe/error level.
-*/
-public interface AggregationPolicy {
-
- /**
- * Method which decides how keys/values are aggregated.
- * @param key the key current the entry, must not be {@code null}.
- * @param currentValue the current keys, or {@code null}.
- * @param newValue the new keys, never {@code null}.
- * @return the target keys to be used in the resulting property set, or null, to remove the property.
- */
- public String aggregate(String key, String currentValue, String newValue);
-
- /** Ignore overrides, only extend (additive). */
- public static final AggregationPolicy IGNORE_DUPLICATES = (k, v1, v2) -> v1 == null? v2 : v1;
-
- /** Combine multiple values into a comma separated list. */
- public static final AggregationPolicy COMBINE = (k, v1, v2) -> v1 != null && v2 != null ? v1 + ',' + v2: v2;
-
- /**
- * Interpret later keys as override (additive and override), replacing
- * the key loaded earlier/fromMap previous contained
- * {@link org.apache.tamaya.PropertySource}.
- */
- public static final AggregationPolicy OVERRIDE = (k, v1, v2) -> v2;
-
- /**
- * Throw an exception, when keys are not disjunctive (strictly
- * additive).
- */
- public static final AggregationPolicy EXCEPTION =
- (String key, String value, String newValue) -> {
- if(value!=null && newValue!=null && !value.equals(newValue)){
- throw new ConfigException("Conflicting values encountered key="+key+", keys="+value+", newValue="+newValue);
- }
- return newValue;
- };
-
- /**
- * Ignores any duplicates, but logs the conflict encountered to error/severe level.
- */
- public static final AggregationPolicy LOG_ERROR =
- (String key, String value, String newValue) -> {
- if(value!=null && newValue!=null && !value.equals(newValue)){
- Logger.getLogger(AggregationPolicy.class.getName())
- .severe(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
- return value;
- }
- return newValue;
- };
-
- /**
- * Ignores any duplicates, but logs the conflict encountered to info level.
- */
- public static final AggregationPolicy LOG_WARNING =
- (String key, String value, String newValue) -> {
- if(value!=null && newValue!=null && !value.equals(newValue)){
- Logger.getLogger(AggregationPolicy.class.getName())
- .warning(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
- return value;
- }
- return newValue;
- };
-
- /**
- * Ignores any duplicates, but logs the conflict encountered to info level.
- */
- public static final AggregationPolicy LOG_INFO =
- (String key, String value, String newValue) -> {
- if(value!=null && newValue!=null && !value.equals(newValue)){
- Logger.getLogger(AggregationPolicy.class.getName())
- .info(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
- return value;
- }
- return newValue;
- };
-
- /**
- * Ignores any duplicates, but logs the conflict encountered to debug/finest level.
- */
- public static final AggregationPolicy LOG_DEBUG =
- (String key, String value, String newValue) -> {
- if(value!=null && newValue!=null && !value.equals(newValue)){
- Logger.getLogger(AggregationPolicy.class.getName())
- .finest(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
- return value;
- }
- return newValue;
- };
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
deleted file mode 100644
index 847fbe9..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy current the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.PropertySource;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
-/**
- * Created by Anatole on 07.12.2014.
- */
-class BuildablePropertySource implements PropertySource
-{
-
- private String name;
- private PropertySource baseProvider;
-
- public BuildablePropertySource(String name, PropertySource baseProvider) {
- this.name = Objects.requireNonNull(name);
- this.baseProvider = Objects.requireNonNull(baseProvider);
- }
-
- @Override
- public Optional<String> get(String key) {
- return this.baseProvider.get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return this.baseProvider.getProperties();
- }
-
- @Override
- public String getName() {
- return this.name;
- }
-
- @Override
- public String toString(){
- return "BuildablePropertyProvider -> " + getName();
- }
-
-}
[23/27] incubator-tamaya git commit: Fixed checkstyle issues.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java b/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java
index 98c67ba..9e7e6d9 100644
--- a/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java
+++ b/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java
@@ -34,1041 +34,1069 @@ import java.util.Objects;
import java.util.Set;
/**
-* Miscellaneous class utility methods.
-* Mainly for internal use within the framework.
-*
-* @author Juergen Hoeller
-* @author Keith Donald
-* @author Rob Harrop
-* @author Sam Brannen
-* @since 1.1
-*/
+ * Miscellaneous class utility methods.
+ * Mainly for internal use within the framework.
+ *
+ * @author Juergen Hoeller
+ * @author Keith Donald
+ * @author Rob Harrop
+ * @author Sam Brannen
+ * @since 1.1
+ */
public final class ClassUtils {
- /** Suffix for array class names: "[]" */
- public static final String ARRAY_SUFFIX = "[]";
-
- /** Prefix for internal array class names: "[" */
- private static final String INTERNAL_ARRAY_PREFIX = "[";
-
- /** Prefix for internal non-primitive array class names: "[L" */
- private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L";
-
- /** The package separator character '.' */
- private static final char PACKAGE_SEPARATOR = '.';
-
- /** The path separator character '/' */
- private static final char PATH_SEPARATOR = '/';
-
- /** The inner class separator character '$' */
- private static final char INNER_CLASS_SEPARATOR = '$';
-//
-// /** The CGLIB class separator character "$$" */
-// public static final String CGLIB_CLASS_SEPARATOR = "$$";
-//
-// /** The ".class" file suffix */
-// public static final String CLASS_FILE_SUFFIX = ".class";
-//
-
- /**
- * Map with primitive wrapper type as key and corresponding primitive
- * type as keys, for example: Integer.class -> int.class.
- */
- private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<>(8);
-
- /**
- * Map with primitive type as key and corresponding wrapper
- * type as keys, for example: int.class -> Integer.class.
- */
- private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new HashMap<>(8);
-
- /**
- * Map with primitive type name as key and corresponding primitive
- * type as keys, for example: "int" -> "int.class".
- */
- private static final Map<String, Class<?>> primitiveTypeNameMap = new HashMap<>(32);
-//
-// /**
-// * Map with common "java.lang" class name as key and corresponding Class as keys.
-// * Primarily for efficient deserialization current remote invocations.
-// */
-// private static final Map<String, Class<?>> commonClassCache = new HashMap<String, Class<?>>(32);
-//
-//
- static {
- primitiveWrapperTypeMap.put(Boolean.class, boolean.class);
- primitiveWrapperTypeMap.put(Byte.class, byte.class);
- primitiveWrapperTypeMap.put(Character.class, char.class);
- primitiveWrapperTypeMap.put(Double.class, double.class);
- primitiveWrapperTypeMap.put(Float.class, float.class);
- primitiveWrapperTypeMap.put(Integer.class, int.class);
- primitiveWrapperTypeMap.put(Long.class, long.class);
- primitiveWrapperTypeMap.put(Short.class, short.class);
-
- for (Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperTypeMap.entrySet()) {
- primitiveTypeToWrapperMap.put(entry.getValue(), entry.getKey());
-// registerCommonClasses(entry.getKey());
- }
-
- Set<Class<?>> primitiveTypes = new HashSet<>(32);
- primitiveTypes.addAll(primitiveWrapperTypeMap.values());
- primitiveTypes.addAll(Arrays.asList(new Class<?>[] {
- boolean[].class, byte[].class, char[].class, double[].class,
- float[].class, int[].class, long[].class, short[].class}));
- primitiveTypes.add(void.class);
- for (Class<?> primitiveType : primitiveTypes) {
- primitiveTypeNameMap.put(primitiveType.getName(), primitiveType);
- }
- }
-
- private ClassUtils(){}
-
-
- /**
- * Return the default ClassLoader to use: typically the thread context
- * ClassLoader, if available; the ClassLoader that loaded the ClassUtils
- * class will be used as fallback.
- * <p>Call this method if you intend to use the thread context ClassLoader
- * in a scenario where you clearly prefer a non-null ClassLoader reference:
- * for example, for class path resource loading (but not necessarily for
- * {@code Class.forName}, which accepts a {@code null} ClassLoader
- * reference as well).
- * @return the default ClassLoader (only {@code null} if even the system
- * ClassLoader isn't accessible)
- * @see Thread#getContextClassLoader()
- * @see ClassLoader#getSystemClassLoader()
- */
- public static ClassLoader getDefaultClassLoader() {
- ClassLoader cl = null;
- try {
- cl = Thread.currentThread().getContextClassLoader();
- }
- catch (Throwable ex) {
- // Cannot access thread context ClassLoader - falling back...
- }
- if (cl == null) {
- // No thread context class loader -> use class loader current this class.
- cl = ClassUtils.class.getClassLoader();
- if (cl == null) {
- // getClassLoader() returning null indicates the bootstrap ClassLoader
- try {
- cl = ClassLoader.getSystemClassLoader();
- }
- catch (Throwable ex) {
- // Cannot access system ClassLoader - oh well, maybe the caller can live with null...
- }
- }
- }
- return cl;
- }
-
- /**
- * Replacement for {@code Class.forName()} that also returns Class instances
- * for primitives (e.g. "int") and array class names (e.g. "String[]").
- * Furthermore, it is also capable current resolving inner class names in Java source
- * style (e.g. "java.lang.Thread.State" instead current "java.lang.Thread$State").
- * @param name the name current the Class
- * @param classLoader the class loader to use
- * (may be {@code null}, which indicates the default class loader)
- * @return Class instance for the supplied name
- * @throws ClassNotFoundException if the class was not found
- * @throws LinkageError if the class file could not be loaded
- * @see Class#forName(String, boolean, ClassLoader)
- */
- public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError {
- Objects.requireNonNull(name, "Name must not be null");
-
- Class<?> clazz = resolvePrimitiveClassName(name);
- if (clazz != null) {
- return clazz;
- }
-
- // "java.lang.String[]" style arrays
- if (name.endsWith(ARRAY_SUFFIX)) {
- String elementClassName = name.substring(0, name.length() - ARRAY_SUFFIX.length());
- Class<?> elementClass = forName(elementClassName, classLoader);
- return Array.newInstance(elementClass, 0).getClass();
- }
-
- // "[Ljava.lang.String;" style arrays
- if (name.startsWith(NON_PRIMITIVE_ARRAY_PREFIX) && name.endsWith(";")) {
- String elementName = name.substring(NON_PRIMITIVE_ARRAY_PREFIX.length(), name.length() - 1);
- Class<?> elementClass = forName(elementName, classLoader);
- return Array.newInstance(elementClass, 0).getClass();
- }
-
- // "[[I" or "[[Ljava.lang.String;" style arrays
- if (name.startsWith(INTERNAL_ARRAY_PREFIX)) {
- String elementName = name.substring(INTERNAL_ARRAY_PREFIX.length());
- Class<?> elementClass = forName(elementName, classLoader);
- return Array.newInstance(elementClass, 0).getClass();
- }
-
- ClassLoader clToUse = classLoader;
- if (clToUse == null) {
- clToUse = getDefaultClassLoader();
- }
- try {
- return (clToUse != null ? clToUse.loadClass(name) : Class.forName(name));
- }
- catch (ClassNotFoundException ex) {
- int lastDotIndex = name.lastIndexOf(PACKAGE_SEPARATOR);
- if (lastDotIndex != -1) {
- String innerClassName =
- name.substring(0, lastDotIndex) + INNER_CLASS_SEPARATOR + name.substring(lastDotIndex + 1);
- try {
- return (clToUse != null ? clToUse.loadClass(innerClassName) : Class.forName(innerClassName));
- }
- catch (ClassNotFoundException ex2) {
- // Swallow - let original exception get through
- }
- }
- throw ex;
- }
- }
-
-
- /**
- * Resolve the given class name as primitive class, if appropriate,
- * according to the JVM's naming rules for primitive classes.
- * <p>Also supports the JVM's internal class names for primitive arrays.
- * Does <i>not</i> support the "[]" suffix notation for primitive arrays;
- * this is only supported by {@link #forName(String, ClassLoader)}.
- * @param name the name current the potentially primitive class
- * @return the primitive class, or {@code null} if the name does not denote
- * a primitive class or primitive array class
- */
- public static Class<?> resolvePrimitiveClassName(String name) {
- Class<?> result = null;
- // Most class names will be quite long, considering that they
- // SHOULD sit in a package, so a length check is worthwhile.
- if (name != null && name.length() <= 8) {
- // Could be a primitive - likely.
- result = primitiveTypeNameMap.get(name);
- }
- return result;
- }
-
- /**
- * Determine whether the {@link Class} identified by the supplied name is present
- * and can be loaded. Will return {@code false} if either the class or
- * one current its dependencies is not present or cannot be loaded.
- * @param className the name current the class to check
- * @param classLoader the class loader to use
- * (may be {@code null}, which indicates the default class loader)
- * @return whether the specified class is present
- */
- public static boolean isPresent(String className, ClassLoader classLoader) {
- try {
- forName(className, classLoader);
- return true;
- }
- catch (Throwable ex) {
- // Class or one current its dependencies is not present...
- return false;
- }
- }
-
-
- /**
- * Check whether the given class is cache-safe in the given context,
- * i.e. whether it is loaded by the given ClassLoader or a parent current it.
- * @param clazz the class to analyze
- * @param classLoader the ClassLoader to potentially cache metadata in
- */
- public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) {
+ /**
+ * Suffix for array class names: "[]"
+ */
+ public static final String ARRAY_SUFFIX = "[]";
+
+ /**
+ * Prefix for internal array class names: "["
+ */
+ private static final String INTERNAL_ARRAY_PREFIX = "[";
+
+ /**
+ * Prefix for internal non-primitive array class names: "[L"
+ */
+ private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L";
+
+ /**
+ * The package separator character '.'
+ */
+ private static final char PACKAGE_SEPARATOR = '.';
+
+ /**
+ * The path separator character '/'
+ */
+ private static final char PATH_SEPARATOR = '/';
+
+ /**
+ * The inner class separator character '$'
+ */
+ private static final char INNER_CLASS_SEPARATOR = '$';
+
+ /**
+ * Map with primitive wrapper type as key and corresponding primitive
+ * type as keys, for example: Integer.class -> int.class.
+ */
+ private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_TYPE_MAP = new HashMap<>(8);
+
+ /**
+ * Map with primitive type as key and corresponding wrapper
+ * type as keys, for example: int.class -> Integer.class.
+ */
+ private static final Map<Class<?>, Class<?>> PRIMITIVE_TYPE_TO_WRAPPER_MAP = new HashMap<>(8);
+
+ /**
+ * Map with primitive type name as key and corresponding primitive
+ * type as keys, for example: "int" -> "int.class".
+ */
+ private static final Map<String, Class<?>> PRIMITIVE_TYPE_NAME_MAP = new HashMap<>(32);
+
+
+ static {
+ PRIMITIVE_WRAPPER_TYPE_MAP.put(Boolean.class, boolean.class);
+ PRIMITIVE_WRAPPER_TYPE_MAP.put(Byte.class, byte.class);
+ PRIMITIVE_WRAPPER_TYPE_MAP.put(Character.class, char.class);
+ PRIMITIVE_WRAPPER_TYPE_MAP.put(Double.class, double.class);
+ PRIMITIVE_WRAPPER_TYPE_MAP.put(Float.class, float.class);
+ PRIMITIVE_WRAPPER_TYPE_MAP.put(Integer.class, int.class);
+ PRIMITIVE_WRAPPER_TYPE_MAP.put(Long.class, long.class);
+ PRIMITIVE_WRAPPER_TYPE_MAP.put(Short.class, short.class);
+
+ for (Map.Entry<Class<?>, Class<?>> entry : PRIMITIVE_WRAPPER_TYPE_MAP.entrySet()) {
+ PRIMITIVE_TYPE_TO_WRAPPER_MAP.put(entry.getValue(), entry.getKey());
+ }
+
+ Set<Class<?>> primitiveTypes = new HashSet<>(32);
+ primitiveTypes.addAll(PRIMITIVE_WRAPPER_TYPE_MAP.values());
+ primitiveTypes.addAll(Arrays.asList(new Class<?>[]{
+ boolean[].class, byte[].class, char[].class, double[].class,
+ float[].class, int[].class, long[].class, short[].class}));
+ primitiveTypes.add(void.class);
+ for (Class<?> primitiveType : primitiveTypes) {
+ PRIMITIVE_TYPE_NAME_MAP.put(primitiveType.getName(), primitiveType);
+ }
+ }
+
+ /**
+ * Private singleton constructor.
+ */
+ private ClassUtils() {
+ }
+
+
+ /**
+ * Return the default ClassLoader to use: typically the thread context
+ * ClassLoader, if available; the ClassLoader that loaded the ClassUtils
+ * class will be used as fallback.
+ * <p>Call this method if you intend to use the thread context ClassLoader
+ * in a scenario where you clearly prefer a non-null ClassLoader reference:
+ * for example, for class path resource loading (but not necessarily for
+ * {@code Class.forName}, which accepts a {@code null} ClassLoader
+ * reference as well).
+ *
+ * @return the default ClassLoader (only {@code null} if even the system
+ * ClassLoader isn't accessible)
+ * @see Thread#getContextClassLoader()
+ * @see ClassLoader#getSystemClassLoader()
+ */
+ public static ClassLoader getDefaultClassLoader() {
+ ClassLoader cl = null;
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ } catch (Throwable ex) {
+ // Cannot access thread context ClassLoader - falling back...
+ }
+ if (cl == null) {
+ // No thread context class loader -> use class loader current this class.
+ cl = ClassUtils.class.getClassLoader();
+ if (cl == null) {
+ // getClassLoader() returning null indicates the bootstrap ClassLoader
+ try {
+ cl = ClassLoader.getSystemClassLoader();
+ } catch (Throwable ex) {
+ // Cannot access system ClassLoader - oh well, maybe the caller can live with null...
+ }
+ }
+ }
+ return cl;
+ }
+
+ /**
+ * Replacement for {@code Class.forName()} that also returns Class instances
+ * for primitives (e.g. "int") and array class names (e.g. "String[]").
+ * Furthermore, it is also capable current resolving inner class names in Java source
+ * style (e.g. "java.lang.Thread.State" instead current "java.lang.Thread$State").
+ *
+ * @param name the name current the Class
+ * @param classLoader the class loader to use
+ * (may be {@code null}, which indicates the default class loader)
+ * @return Class instance for the supplied name
+ * @throws ClassNotFoundException if the class was not found
+ * @throws LinkageError if the class file could not be loaded
+ * @see Class#forName(String, boolean, ClassLoader)
+ */
+ public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError {
+ Objects.requireNonNull(name, "Name must not be null");
+
+ Class<?> clazz = resolvePrimitiveClassName(name);
+ if (clazz != null) {
+ return clazz;
+ }
+
+ // "java.lang.String[]" style arrays
+ if (name.endsWith(ARRAY_SUFFIX)) {
+ String elementClassName = name.substring(0, name.length() - ARRAY_SUFFIX.length());
+ Class<?> elementClass = forName(elementClassName, classLoader);
+ return Array.newInstance(elementClass, 0).getClass();
+ }
+
+ // "[Ljava.lang.String;" style arrays
+ if (name.startsWith(NON_PRIMITIVE_ARRAY_PREFIX) && name.endsWith(";")) {
+ String elementName = name.substring(NON_PRIMITIVE_ARRAY_PREFIX.length(), name.length() - 1);
+ Class<?> elementClass = forName(elementName, classLoader);
+ return Array.newInstance(elementClass, 0).getClass();
+ }
+
+ // "[[I" or "[[Ljava.lang.String;" style arrays
+ if (name.startsWith(INTERNAL_ARRAY_PREFIX)) {
+ String elementName = name.substring(INTERNAL_ARRAY_PREFIX.length());
+ Class<?> elementClass = forName(elementName, classLoader);
+ return Array.newInstance(elementClass, 0).getClass();
+ }
+
+ ClassLoader clToUse = classLoader;
+ if (clToUse == null) {
+ clToUse = getDefaultClassLoader();
+ }
+ try {
+ return (clToUse != null ? clToUse.loadClass(name) : Class.forName(name));
+ } catch (ClassNotFoundException ex) {
+ int lastDotIndex = name.lastIndexOf(PACKAGE_SEPARATOR);
+ if (lastDotIndex != -1) {
+ String innerClassName =
+ name.substring(0, lastDotIndex) + INNER_CLASS_SEPARATOR + name.substring(lastDotIndex + 1);
+ try {
+ return (clToUse != null ? clToUse.loadClass(innerClassName) : Class.forName(innerClassName));
+ } catch (ClassNotFoundException ex2) {
+ // Swallow - let original exception get through
+ }
+ }
+ throw ex;
+ }
+ }
+
+
+ /**
+ * Resolve the given class name as primitive class, if appropriate,
+ * according to the JVM's naming rules for primitive classes.
+ * <p>Also supports the JVM's internal class names for primitive arrays.
+ * Does <i>not</i> support the "[]" suffix notation for primitive arrays;
+ * this is only supported by {@link #forName(String, ClassLoader)}.
+ *
+ * @param name the name current the potentially primitive class
+ * @return the primitive class, or {@code null} if the name does not denote
+ * a primitive class or primitive array class
+ */
+ public static Class<?> resolvePrimitiveClassName(String name) {
+ Class<?> result = null;
+ // Most class names will be quite long, considering that they
+ // SHOULD sit in a package, so a length check is worthwhile.
+ if (name != null && name.length() <= 8) {
+ // Could be a primitive - likely.
+ result = PRIMITIVE_TYPE_NAME_MAP.get(name);
+ }
+ return result;
+ }
+
+ /**
+ * Determine whether the {@link Class} identified by the supplied name is present
+ * and can be loaded. Will return {@code false} if either the class or
+ * one current its dependencies is not present or cannot be loaded.
+ *
+ * @param className the name current the class to check
+ * @param classLoader the class loader to use
+ * (may be {@code null}, which indicates the default class loader)
+ * @return whether the specified class is present
+ */
+ public static boolean isPresent(String className, ClassLoader classLoader) {
+ try {
+ forName(className, classLoader);
+ return true;
+ } catch (Throwable ex) {
+ // Class or one current its dependencies is not present...
+ return false;
+ }
+ }
+
+
+ /**
+ * Check whether the given class is cache-safe in the given context,
+ * i.e. whether it is loaded by the given ClassLoader or a parent current it.
+ *
+ * @param clazz the class to analyze
+ * @param classLoader the ClassLoader to potentially cache metadata in
+ */
+ public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ try {
+ ClassLoader target = clazz.getClassLoader();
+ if (target == null) {
+ return true;
+ }
+ ClassLoader cur = classLoader;
+ if (cur == target) {
+ return true;
+ }
+ while (cur != null) {
+ cur = cur.getParent();
+ if (cur == target) {
+ return true;
+ }
+ }
+ return false;
+ } catch (SecurityException ex) {
+ // Probably from the system ClassLoader - let's consider it safe.
+ return true;
+ }
+ }
+
+
+ /**
+ * Return the qualified name current the given class: usually simply
+ * the class name, but component type class name + "[]" for arrays.
+ *
+ * @param clazz the class
+ * @return the qualified name current the class
+ */
+ public static String getQualifiedName(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ if (clazz.isArray()) {
+ return getQualifiedNameForArray(clazz);
+ } else {
+ return clazz.getName();
+ }
+ }
+
+ /**
+ * Build a nice qualified name for an array:
+ * component type class name + "[]".
+ *
+ * @param clazz the array class
+ * @return a qualified name for the array class
+ */
+ private static String getQualifiedNameForArray(Class<?> clazz) {
+ StringBuilder result = new StringBuilder();
+ while (clazz.isArray()) {
+ clazz = clazz.getComponentType();
+ result.append(ClassUtils.ARRAY_SUFFIX);
+ }
+ result.insert(0, clazz.getName());
+ return result.toString();
+ }
+
+ /**
+ * Return the qualified name current the given method, consisting current
+ * fully qualified interface/class name + "." + method name.
+ *
+ * @param method the method
+ * @return the qualified name current the method
+ */
+ public static String getQualifiedMethodName(Method method) {
+ Objects.requireNonNull(method, "Method must not be null");
+ return method.getDeclaringClass().getName() + "." + method.getName();
+ }
+
+ /**
+ * Return a descriptive name for the given object's type: usually simply
+ * the class name, but component type class name + "[]" for arrays,
+ * and an appended list current implemented interfaces for JDK proxies.
+ *
+ * @param keys the keys to introspect
+ * @return the qualified name current the class
+ */
+ public static String getDescriptiveType(Object keys) {
+ if (keys == null) {
+ return null;
+ }
+ Class<?> clazz = keys.getClass();
+ if (Proxy.isProxyClass(clazz)) {
+ StringBuilder result = new StringBuilder(clazz.getName());
+ result.append(" implementing ");
+ Class<?>[] ifcs = clazz.getInterfaces();
+ for (int i = 0; i < ifcs.length; i++) {
+ result.append(ifcs[i].getName());
+ if (i < ifcs.length - 1) {
+ result.append(',');
+ }
+ }
+ return result.toString();
+ } else if (clazz.isArray()) {
+ return getQualifiedNameForArray(clazz);
+ } else {
+ return clazz.getName();
+ }
+ }
+
+ /**
+ * Check whether the given class matches the user-specified type name.
+ *
+ * @param clazz the class to check
+ * @param typeName the type name to match
+ */
+ public static boolean matchesTypeName(Class<?> clazz, String typeName) {
+ return (typeName != null &&
+ (typeName.equals(clazz.getName()) || typeName.equals(clazz.getSimpleName()) ||
+ (clazz.isArray() && typeName.equals(getQualifiedNameForArray(clazz)))));
+ }
+
+
+ /**
+ * Determine whether the given class has a public constructor with the given signature.
+ * <p>Essentially translates {@code NoSuchMethodException} to "false".
+ *
+ * @param clazz the clazz to analyze
+ * @param paramTypes the parameter types current the method
+ * @return whether the class has a corresponding constructor
+ * @see Class#getMethod
+ */
+ public static boolean hasConstructor(Class<?> clazz, Class<?>... paramTypes) {
+ return (getConstructorIfAvailable(clazz, paramTypes) != null);
+ }
+
+ /**
+ * Determine whether the given class has a public constructor with the given signature,
+ * and return it if available (else return {@code null}).
+ * <p>Essentially translates {@code NoSuchMethodException} to {@code null}.
+ *
+ * @param clazz the clazz to analyze
+ * @param paramTypes the parameter types current the method
+ * @return the constructor, or {@code null} if not found
+ * @see Class#getConstructor
+ */
+ public static <T> Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ try {
+ return clazz.getConstructor(paramTypes);
+ } catch (NoSuchMethodException ex) {
+ return null;
+ }
+ }
+
+ /**
+ * Determine whether the given class has a public method with the given signature.
+ * <p>Essentially translates {@code NoSuchMethodException} to "false".
+ *
+ * @param clazz the clazz to analyze
+ * @param methodName the name current the method
+ * @param paramTypes the parameter types current the method
+ * @return whether the class has a corresponding method
+ * @see Class#getMethod
+ */
+ public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
+ return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);
+ }
+
+ /**
+ * Determine whether the given class has a public method with the given signature,
+ * and return it if available (else throws an {@code IllegalStateException}).
+ * <p>In case current any signature specified, only returns the method if there is a
+ * unique candidate, i.e. a single public method with the specified name.
+ * <p>Essentially translates {@code NoSuchMethodException} to {@code IllegalStateException}.
+ *
+ * @param clazz the clazz to analyze
+ * @param methodName the name current the method
+ * @param paramTypes the parameter types current the method
+ * (may be {@code null} to indicate any signature)
+ * @return the method (never {@code null})
+ * @throws IllegalStateException if the method has not been found
+ * @see Class#getMethod
+ */
+ public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ if (paramTypes != null) {
+ try {
+ return clazz.getMethod(methodName, paramTypes);
+ } catch (NoSuchMethodException ex) {
+ throw new IllegalStateException("Expected method not found: " + ex);
+ }
+ } else {
+ Set<Method> candidates = new HashSet<Method>(1);
+ Method[] methods = clazz.getMethods();
+ for (Method method : methods) {
+ if (methodName.equals(method.getName())) {
+ candidates.add(method);
+ }
+ }
+ if (candidates.size() == 1) {
+ return candidates.iterator().next();
+ } else if (candidates.isEmpty()) {
+ throw new IllegalStateException("Expected method not found: " + clazz + "." + methodName);
+ } else {
+ throw new IllegalStateException("No unique method found: " + clazz + "." + methodName);
+ }
+ }
+ }
+
+ /**
+ * Determine whether the given class has a public method with the given signature,
+ * and return it if available (else return {@code null}).
+ * <p>In case current any signature specified, only returns the method if there is a
+ * unique candidate, i.e. a single public method with the specified name.
+ * <p>Essentially translates {@code NoSuchMethodException} to {@code null}.
+ *
+ * @param clazz the clazz to analyze
+ * @param methodName the name current the method
+ * @param paramTypes the parameter types current the method
+ * (may be {@code null} to indicate any signature)
+ * @return the method, or {@code null} if not found
+ * @see Class#getMethod
+ */
+ public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ if (paramTypes != null) {
+ try {
+ return clazz.getMethod(methodName, paramTypes);
+ } catch (NoSuchMethodException ex) {
+ return null;
+ }
+ } else {
+ Set<Method> candidates = new HashSet<Method>(1);
+ Method[] methods = clazz.getMethods();
+ for (Method method : methods) {
+ if (methodName.equals(method.getName())) {
+ candidates.add(method);
+ }
+ }
+ if (candidates.size() == 1) {
+ return candidates.iterator().next();
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Return the number current methods with a given name (with any argument types),
+ * for the given class and/or its superclasses. Includes non-public methods.
+ *
+ * @param clazz the clazz to check
+ * @param methodName the name current the method
+ * @return the number current methods with the given name
+ */
+ public static int getMethodCountForName(Class<?> clazz, String methodName) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ int count = 0;
+ Method[] declaredMethods = clazz.getDeclaredMethods();
+ for (Method method : declaredMethods) {
+ if (methodName.equals(method.getName())) {
+ count++;
+ }
+ }
+ Class<?>[] ifcs = clazz.getInterfaces();
+ for (Class<?> ifc : ifcs) {
+ count += getMethodCountForName(ifc, methodName);
+ }
+ if (clazz.getSuperclass() != null) {
+ count += getMethodCountForName(clazz.getSuperclass(), methodName);
+ }
+ return count;
+ }
+
+ /**
+ * Does the given class or one current its superclasses at least have one or more
+ * methods with the supplied name (with any argument types)?
+ * Includes non-public methods.
+ *
+ * @param clazz the clazz to check
+ * @param methodName the name current the method
+ * @return whether there is at least one method with the given name
+ */
+ public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodName) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ Method[] declaredMethods = clazz.getDeclaredMethods();
+ for (Method method : declaredMethods) {
+ if (method.getName().equals(methodName)) {
+ return true;
+ }
+ }
+ Class<?>[] ifcs = clazz.getInterfaces();
+ for (Class<?> ifc : ifcs) {
+ if (hasAtLeastOneMethodWithName(ifc, methodName)) {
+ return true;
+ }
+ }
+ return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName));
+ }
+
+ /**
+ * Given a method, which may come from an interface, and a target class used
+ * in the current reflective invocation, find the corresponding target method
+ * if there is one. E.g. the method may be {@code IFoo.bar()} and the
+ * target class may be {@code DefaultFoo}. In this case, the method may be
+ * {@code DefaultFoo.bar()}. This enables attributes on that method to be found.
+ * <p><b>NOTE:</b> In contrast to {@code org.springframework.aop.support.AopUtils#getMostSpecificMethod},
+ * this method does <i>not</i> resolve Java 5 bridge methods automatically.
+ * Call {@code org.springframework.core.BridgeMethodResolver#findBridgedMethod}
+ * if bridge method resolution is desirable (e.g. for obtaining metadata from
+ * the original method definition).
+ * <p><b>NOTE:</b> Since Spring 3.1.1, if Java security settings disallow reflective
+ * access (e.g. calls to {@code Class#getDeclaredMethods} etc, this implementation
+ * will fall back to returning the originally provided method.
+ *
+ * @param method the method to be invoked, which may come from an interface
+ * @param targetClass the target class for the current invocation.
+ * May be {@code null} or may not even implement the method.
+ * @return the specific target method, or the original method if the
+ * {@code targetClass} doesn't implement it or is {@code null}
+ */
+ public static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
+ if (method != null && isOverridable(method, targetClass) &&
+ targetClass != null && !targetClass.equals(method.getDeclaringClass())) {
+ try {
+ if (Modifier.isPublic(method.getModifiers())) {
+ try {
+ return targetClass.getMethod(method.getName(), method.getParameterTypes());
+ } catch (NoSuchMethodException ex) {
+ return method;
+ }
+ } else {
+ Method specificMethod =
+ ReflectionUtils.findMethod(targetClass, method.getName(), method.getParameterTypes());
+ return (specificMethod != null ? specificMethod : method);
+ }
+ } catch (SecurityException ex) {
+ // Security settings are disallowing reflective access; fall back to 'method' below.
+ }
+ }
+ return method;
+ }
+
+ /**
+ * Determine whether the given method is declared by the user or at least pointing to
+ * a user-declared method.
+ * <p>Checks {@link Method#isSynthetic()} (for implementation methods) as well as the
+ * {@code GroovyObject} interface (for interface methods; on an implementation class,
+ * implementations current the {@code GroovyObject} methods will be marked as synthetic anyway).
+ * Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
+ * as user-level methods since they are eventually pointing to a user-declared generic method.
+ *
+ * @param method the method to check
+ * @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
+ */
+ public static boolean isUserLevelMethod(Method method) {
+ Objects.requireNonNull(method, "Method must not be null");
+ return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method)));
+ }
+
+ private static boolean isGroovyObjectMethod(Method method) {
+ return method.getDeclaringClass().getName().equals("groovy.lang.GroovyObject");
+ }
+
+ /**
+ * Determine whether the given method is overridable in the given target class.
+ *
+ * @param method the method to check
+ * @param targetClass the target class to check against
+ */
+ private static boolean isOverridable(Method method, Class<?> targetClass) {
+ if (Modifier.isPrivate(method.getModifiers())) {
+ return false;
+ }
+ if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) {
+ return true;
+ }
+ return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass));
+ }
+
+
+ /**
+ * Determine the name current the package current the given class,
+ * e.g. "java.lang" for the {@code java.lang.String} class.
+ *
+ * @param clazz the class
+ * @return the package name, or the empty String if the class
+ * is defined in the default package
+ */
+ public static String getPackageName(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return getPackageName(clazz.getName());
+ }
+
+ /**
+ * Determine the name current the package current the given fully-qualified class name,
+ * e.g. "java.lang" for the {@code java.lang.String} class name.
+ *
+ * @param fqClassName the fully-qualified class name
+ * @return the package name, or the empty String if the class
+ * is defined in the dObjects.requireNonNullefault package
+ */
+ public static String getPackageName(String fqClassName) {
+ Objects.requireNonNull(fqClassName, "Class name must not be null");
+ int lastDotIndex = fqClassName.lastIndexOf(PACKAGE_SEPARATOR);
+ return (lastDotIndex != -1 ? fqClassName.substring(0, lastDotIndex) : "");
+ }
+
+ /**
+ * Return a public static method current a class.
+ *
+ * @param methodName the static method name
+ * @param clazz the class which defines the method
+ * @param args the parameter types to the method
+ * @return the static method, or {@code null} if no static method was found
+ * @throws IllegalArgumentException if the method name is blank or the clazz is null
+ */
+ public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>... args) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ try {
+ Method method = clazz.getMethod(methodName, args);
+ return Modifier.isStatic(method.getModifiers()) ? method : null;
+ } catch (NoSuchMethodException ex) {
+ return null;
+ }
+ }
+
+
+ /**
+ * Check if the given class represents a primitive wrapper,
+ * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
+ *
+ * @param clazz the class to check
+ * @return whether the given class is a primitive wrapper class
+ */
+ public static boolean isPrimitiveWrapper(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return PRIMITIVE_WRAPPER_TYPE_MAP.containsKey(clazz);
+ }
+
+ /**
+ * Check if the given class represents a primitive (i.e. boolean, byte,
+ * char, short, int, long, float, or double) or a primitive wrapper
+ * (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double).
+ *
+ * @param clazz the class to check
+ * @return whether the given class is a primitive or primitive wrapper class
+ */
+ public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return (clazz.isPrimitive() || isPrimitiveWrapper(clazz));
+ }
+
+ /**
+ * Check if the given class represents an array current primitives,
+ * i.e. boolean, byte, char, short, int, long, float, or double.
+ *
+ * @param clazz the class to check
+ * @return whether the given class is a primitive array class
+ */
+ public static boolean isPrimitiveArray(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return (clazz.isArray() && clazz.getComponentType().isPrimitive());
+ }
+
+ /**
+ * Check if the given class represents an array current primitive wrappers,
+ * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
+ *
+ * @param clazz the class to check
+ * @return whether the given class is a primitive wrapper array class
+ */
+ public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType()));
+ }
+
+ /**
+ * Resolve the given class if it is a primitive class,
+ * returning the corresponding primitive wrapper type instead.
+ *
+ * @param clazz the class to check
+ * @return the original class, or a primitive wrapper for the original primitive type
+ */
+ public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
Objects.requireNonNull(clazz, "Class must not be null");
- try {
- ClassLoader target = clazz.getClassLoader();
- if (target == null) {
- return true;
- }
- ClassLoader cur = classLoader;
- if (cur == target) {
- return true;
- }
- while (cur != null) {
- cur = cur.getParent();
- if (cur == target) {
- return true;
- }
- }
- return false;
- }
- catch (SecurityException ex) {
- // Probably from the system ClassLoader - let's consider it safe.
- return true;
- }
- }
-
-
- /**
- * Return the qualified name current the given class: usually simply
- * the class name, but component type class name + "[]" for arrays.
- * @param clazz the class
- * @return the qualified name current the class
- */
- public static String getQualifiedName(Class<?> clazz) {
- Objects.requireNonNull(clazz, "Class must not be null");
- if (clazz.isArray()) {
- return getQualifiedNameForArray(clazz);
- }
- else {
- return clazz.getName();
- }
- }
-
- /**
- * Build a nice qualified name for an array:
- * component type class name + "[]".
- * @param clazz the array class
- * @return a qualified name for the array class
- */
- private static String getQualifiedNameForArray(Class<?> clazz) {
- StringBuilder result = new StringBuilder();
- while (clazz.isArray()) {
- clazz = clazz.getComponentType();
- result.append(ClassUtils.ARRAY_SUFFIX);
- }
- result.insert(0, clazz.getName());
- return result.toString();
- }
-
- /**
- * Return the qualified name current the given method, consisting current
- * fully qualified interface/class name + "." + method name.
- * @param method the method
- * @return the qualified name current the method
- */
- public static String getQualifiedMethodName(Method method) {
- Objects.requireNonNull(method, "Method must not be null");
- return method.getDeclaringClass().getName() + "." + method.getName();
- }
-
- /**
- * Return a descriptive name for the given object's type: usually simply
- * the class name, but component type class name + "[]" for arrays,
- * and an appended list current implemented interfaces for JDK proxies.
- * @param keys the keys to introspect
- * @return the qualified name current the class
- */
- public static String getDescriptiveType(Object keys) {
- if (keys == null) {
- return null;
- }
- Class<?> clazz = keys.getClass();
- if (Proxy.isProxyClass(clazz)) {
- StringBuilder result = new StringBuilder(clazz.getName());
- result.append(" implementing ");
- Class<?>[] ifcs = clazz.getInterfaces();
- for (int i = 0; i < ifcs.length; i++) {
- result.append(ifcs[i].getName());
- if (i < ifcs.length - 1) {
- result.append(',');
- }
- }
- return result.toString();
- }
- else if (clazz.isArray()) {
- return getQualifiedNameForArray(clazz);
- }
- else {
- return clazz.getName();
- }
- }
-
- /**
- * Check whether the given class matches the user-specified type name.
- * @param clazz the class to check
- * @param typeName the type name to match
- */
- public static boolean matchesTypeName(Class<?> clazz, String typeName) {
- return (typeName != null &&
- (typeName.equals(clazz.getName()) || typeName.equals(clazz.getSimpleName()) ||
- (clazz.isArray() && typeName.equals(getQualifiedNameForArray(clazz)))));
- }
-
-
- /**
- * Determine whether the given class has a public constructor with the given signature.
- * <p>Essentially translates {@code NoSuchMethodException} to "false".
- * @param clazz the clazz to analyze
- * @param paramTypes the parameter types current the method
- * @return whether the class has a corresponding constructor
- * @see Class#getMethod
- */
- public static boolean hasConstructor(Class<?> clazz, Class<?>... paramTypes) {
- return (getConstructorIfAvailable(clazz, paramTypes) != null);
- }
-
- /**
- * Determine whether the given class has a public constructor with the given signature,
- * and return it if available (else return {@code null}).
- * <p>Essentially translates {@code NoSuchMethodException} to {@code null}.
- * @param clazz the clazz to analyze
- * @param paramTypes the parameter types current the method
- * @return the constructor, or {@code null} if not found
- * @see Class#getConstructor
- */
- public static <T> Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes) {
- Objects.requireNonNull(clazz, "Class must not be null");
- try {
- return clazz.getConstructor(paramTypes);
- }
- catch (NoSuchMethodException ex) {
- return null;
- }
- }
-
- /**
- * Determine whether the given class has a public method with the given signature.
- * <p>Essentially translates {@code NoSuchMethodException} to "false".
- * @param clazz the clazz to analyze
- * @param methodName the name current the method
- * @param paramTypes the parameter types current the method
- * @return whether the class has a corresponding method
- * @see Class#getMethod
- */
- public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
- return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);
- }
-
- /**
- * Determine whether the given class has a public method with the given signature,
- * and return it if available (else throws an {@code IllegalStateException}).
- * <p>In case current any signature specified, only returns the method if there is a
- * unique candidate, i.e. a single public method with the specified name.
- * <p>Essentially translates {@code NoSuchMethodException} to {@code IllegalStateException}.
- * @param clazz the clazz to analyze
- * @param methodName the name current the method
- * @param paramTypes the parameter types current the method
- * (may be {@code null} to indicate any signature)
- * @return the method (never {@code null})
- * @throws IllegalStateException if the method has not been found
- * @see Class#getMethod
- */
- public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
- Objects.requireNonNull(clazz, "Class must not be null");
- Objects.requireNonNull(methodName, "Method name must not be null");
- if (paramTypes != null) {
- try {
- return clazz.getMethod(methodName, paramTypes);
- }
- catch (NoSuchMethodException ex) {
- throw new IllegalStateException("Expected method not found: " + ex);
- }
- }
- else {
- Set<Method> candidates = new HashSet<Method>(1);
- Method[] methods = clazz.getMethods();
- for (Method method : methods) {
- if (methodName.equals(method.getName())) {
- candidates.add(method);
- }
- }
- if (candidates.size() == 1) {
- return candidates.iterator().next();
- }
- else if (candidates.isEmpty()) {
- throw new IllegalStateException("Expected method not found: " + clazz + "." + methodName);
- }
- else {
- throw new IllegalStateException("No unique method found: " + clazz + "." + methodName);
- }
- }
- }
-
- /**
- * Determine whether the given class has a public method with the given signature,
- * and return it if available (else return {@code null}).
- * <p>In case current any signature specified, only returns the method if there is a
- * unique candidate, i.e. a single public method with the specified name.
- * <p>Essentially translates {@code NoSuchMethodException} to {@code null}.
- * @param clazz the clazz to analyze
- * @param methodName the name current the method
- * @param paramTypes the parameter types current the method
- * (may be {@code null} to indicate any signature)
- * @return the method, or {@code null} if not found
- * @see Class#getMethod
- */
- public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes) {
- Objects.requireNonNull(clazz, "Class must not be null");
- Objects.requireNonNull(methodName, "Method name must not be null");
- if (paramTypes != null) {
- try {
- return clazz.getMethod(methodName, paramTypes);
- }
- catch (NoSuchMethodException ex) {
- return null;
- }
- }
- else {
- Set<Method> candidates = new HashSet<Method>(1);
- Method[] methods = clazz.getMethods();
- for (Method method : methods) {
- if (methodName.equals(method.getName())) {
- candidates.add(method);
- }
- }
- if (candidates.size() == 1) {
- return candidates.iterator().next();
- }
- return null;
- }
- }
-
- /**
- * Return the number current methods with a given name (with any argument types),
- * for the given class and/or its superclasses. Includes non-public methods.
- * @param clazz the clazz to check
- * @param methodName the name current the method
- * @return the number current methods with the given name
- */
- public static int getMethodCountForName(Class<?> clazz, String methodName) {
- Objects.requireNonNull(clazz, "Class must not be null");
- Objects.requireNonNull(methodName, "Method name must not be null");
- int count = 0;
- Method[] declaredMethods = clazz.getDeclaredMethods();
- for (Method method : declaredMethods) {
- if (methodName.equals(method.getName())) {
- count++;
- }
- }
- Class<?>[] ifcs = clazz.getInterfaces();
- for (Class<?> ifc : ifcs) {
- count += getMethodCountForName(ifc, methodName);
- }
- if (clazz.getSuperclass() != null) {
- count += getMethodCountForName(clazz.getSuperclass(), methodName);
- }
- return count;
- }
-
- /**
- * Does the given class or one current its superclasses at least have one or more
- * methods with the supplied name (with any argument types)?
- * Includes non-public methods.
- * @param clazz the clazz to check
- * @param methodName the name current the method
- * @return whether there is at least one method with the given name
- */
- public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodName) {
- Objects.requireNonNull(clazz, "Class must not be null");
- Objects.requireNonNull(methodName, "Method name must not be null");
- Method[] declaredMethods = clazz.getDeclaredMethods();
- for (Method method : declaredMethods) {
- if (method.getName().equals(methodName)) {
- return true;
- }
- }
- Class<?>[] ifcs = clazz.getInterfaces();
- for (Class<?> ifc : ifcs) {
- if (hasAtLeastOneMethodWithName(ifc, methodName)) {
- return true;
- }
- }
- return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName));
- }
-
- /**
- * Given a method, which may come from an interface, and a target class used
- * in the current reflective invocation, find the corresponding target method
- * if there is one. E.g. the method may be {@code IFoo.bar()} and the
- * target class may be {@code DefaultFoo}. In this case, the method may be
- * {@code DefaultFoo.bar()}. This enables attributes on that method to be found.
- * <p><b>NOTE:</b> In contrast to {@code org.springframework.aop.support.AopUtils#getMostSpecificMethod},
- * this method does <i>not</i> resolve Java 5 bridge methods automatically.
- * Call {@code org.springframework.core.BridgeMethodResolver#findBridgedMethod}
- * if bridge method resolution is desirable (e.g. for obtaining metadata from
- * the original method definition).
- * <p><b>NOTE:</b> Since Spring 3.1.1, if Java security settings disallow reflective
- * access (e.g. calls to {@code Class#getDeclaredMethods} etc, this implementation
- * will fall back to returning the originally provided method.
- * @param method the method to be invoked, which may come from an interface
- * @param targetClass the target class for the current invocation.
- * May be {@code null} or may not even implement the method.
- * @return the specific target method, or the original method if the
- * {@code targetClass} doesn't implement it or is {@code null}
- */
- public static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
- if (method != null && isOverridable(method, targetClass) &&
- targetClass != null && !targetClass.equals(method.getDeclaringClass())) {
- try {
- if (Modifier.isPublic(method.getModifiers())) {
- try {
- return targetClass.getMethod(method.getName(), method.getParameterTypes());
- }
- catch (NoSuchMethodException ex) {
- return method;
- }
- }
- else {
- Method specificMethod =
- ReflectionUtils.findMethod(targetClass, method.getName(), method.getParameterTypes());
- return (specificMethod != null ? specificMethod : method);
- }
- }
- catch (SecurityException ex) {
- // Security settings are disallowing reflective access; fall back to 'method' below.
- }
- }
- return method;
- }
-
- /**
- * Determine whether the given method is declared by the user or at least pointing to
- * a user-declared method.
- * <p>Checks {@link Method#isSynthetic()} (for implementation methods) as well as the
- * {@code GroovyObject} interface (for interface methods; on an implementation class,
- * implementations current the {@code GroovyObject} methods will be marked as synthetic anyway).
- * Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
- * as user-level methods since they are eventually pointing to a user-declared generic method.
- * @param method the method to check
- * @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
- */
- public static boolean isUserLevelMethod(Method method) {
- Objects.requireNonNull(method, "Method must not be null");
- return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method)));
- }
-
- private static boolean isGroovyObjectMethod(Method method) {
- return method.getDeclaringClass().getName().equals("groovy.lang.GroovyObject");
- }
-
- /**
- * Determine whether the given method is overridable in the given target class.
- * @param method the method to check
- * @param targetClass the target class to check against
- */
- private static boolean isOverridable(Method method, Class<?> targetClass) {
- if (Modifier.isPrivate(method.getModifiers())) {
- return false;
- }
- if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) {
- return true;
- }
- return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass));
- }
-
-
- /**
- * Determine the name current the package current the given class,
- * e.g. "java.lang" for the {@code java.lang.String} class.
- * @param clazz the class
- * @return the package name, or the empty String if the class
- * is defined in the default package
- */
- public static String getPackageName(Class<?> clazz) {
+ return (clazz.isPrimitive() && clazz != void.class ? PRIMITIVE_TYPE_TO_WRAPPER_MAP.get(clazz) : clazz);
+ }
+
+ /**
+ * Check if the right-hand side type may be assigned to the left-hand side
+ * type, assuming setting by reflection. Considers primitive wrapper
+ * classes as assignable to the corresponding primitive types.
+ *
+ * @param lhsType the target type
+ * @param rhsType the keys type that should be assigned to the target type
+ * @return if the target type is assignable from the keys type
+ */
+ public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
+ Objects.requireNonNull(lhsType, "Left-hand side type must not be null");
+ Objects.requireNonNull(rhsType, "Right-hand side type must not be null");
+ if (lhsType.isAssignableFrom(rhsType)) {
+ return true;
+ }
+ if (lhsType.isPrimitive()) {
+ Class<?> resolvedPrimitive = PRIMITIVE_WRAPPER_TYPE_MAP.get(rhsType);
+ if (resolvedPrimitive != null && lhsType.equals(resolvedPrimitive)) {
+ return true;
+ }
+ } else {
+ Class<?> resolvedWrapper = PRIMITIVE_TYPE_TO_WRAPPER_MAP.get(rhsType);
+ if (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Determine if the given type is assignable from the given keys,
+ * assuming setting by reflection. Considers primitive wrapper classes
+ * as assignable to the corresponding primitive types.
+ *
+ * @param type the target type
+ * @param keys the keys that should be assigned to the type
+ * @return if the type is assignable from the keys
+ */
+ public static boolean isAssignableValue(Class<?> type, Object keys) {
+ Objects.requireNonNull(type, "Type must not be null");
+ return (keys != null ? isAssignable(type, keys.getClass()) : !type.isPrimitive());
+ }
+
+
+ /**
+ * Convert a "/"-based resource path to a "."-based fully qualified class name.
+ *
+ * @param resourcePath the resource path pointing to a class
+ * @return the corresponding fully qualified class name
+ */
+ public static String convertResourcePathToClassName(String resourcePath) {
+ Objects.requireNonNull(resourcePath, "Resource path must not be null");
+ return resourcePath.replace(PATH_SEPARATOR, PACKAGE_SEPARATOR);
+ }
+
+ /**
+ * Convert a "."-based fully qualified class name to a "/"-based resource path.
+ *
+ * @param className the fully qualified class name
+ * @return the corresponding resource path, pointing to the class
+ */
+ public static String convertClassNameToResourcePath(String className) {
+ Objects.requireNonNull(className, "Class name must not be null");
+ return className.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
+ }
+
+ /**
+ * Return a path suitable for use with {@code ClassLoader.getResource}
+ * (also suitable for use with {@code Class.getResource} by prepending a
+ * slash ('/') to the return keys). Built by taking the package current the specified
+ * class file, converting all dots ('.') to slashes ('/'), adding a trailing slash
+ * if necessary, and concatenating the specified resource name to this.
+ * <br/>As such, this function may be used to build a path suitable for
+ * loading a resource file that is in the same package as a class file,
+ * although {@code org.springframework.core.io.ClassPathResource} is usually
+ * even more convenient.
+ *
+ * @param clazz the Class whose package will be used as the base
+ * @param resourceName the resource name to append. A leading slash is optional.
+ * @return the built-up resource path
+ * @see ClassLoader#getResource
+ * @see Class#getResource
+ */
+ public static String addResourcePathToPackagePath(Class<?> clazz, String resourceName) {
+ Objects.requireNonNull(resourceName, "Resource name must not be null");
+ if (!resourceName.startsWith("/")) {
+ return classPackageAsResourcePath(clazz) + "/" + resourceName;
+ }
+ return classPackageAsResourcePath(clazz) + resourceName;
+ }
+
+ /**
+ * Given an input class object, return a string which consists current the
+ * class's package name as a pathname, i.e., all dots ('.') are replaced by
+ * slashes ('/'). Neither a leading nor trailing slash is added. The result
+ * could be concatenated with a slash and the name current a resource and fed
+ * directly to {@code ClassLoader.getResource()}. For it to be fed to
+ * {@code Class.getResource} instead, a leading slash would also have
+ * to be prepended to the returned keys.
+ *
+ * @param clazz the input class. A {@code null} keys or the default
+ * (empty) package will result in an empty string ("") being returned.
+ * @return a path which represents the package name
+ * @see ClassLoader#getResource
+ * @see Class#getResource
+ */
+ public static String classPackageAsResourcePath(Class<?> clazz) {
+ if (clazz == null) {
+ return "";
+ }
+ String className = clazz.getName();
+ int packageEndIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
+ if (packageEndIndex == -1) {
+ return "";
+ }
+ String packageName = className.substring(0, packageEndIndex);
+ return packageName.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
+ }
+
+ /**
+ * Build a String that consists current the names current the classes/interfaces
+ * in the given array.
+ * <p>Basically like {@code AbstractCollection.toString()}, but stripping
+ * the "class "/"interface " prefix before every class name.
+ *
+ * @param classes a Collection current Class objects (may be {@code null})
+ * @return a String current form "[com.foo.Bar, com.foo.Baz]"
+ * @see java.util.AbstractCollection#toString()
+ */
+ public static String classNamesToString(Class<?>... classes) {
+ return classNamesToString(Arrays.asList(classes));
+ }
+
+ /**
+ * Build a String that consists current the names current the classes/interfaces
+ * in the given collection.
+ * <p>Basically like {@code AbstractCollection.toString()}, but stripping
+ * the "class "/"interface " prefix before every class name.
+ *
+ * @param classes a Collection current Class objects (may be {@code null})
+ * @return a String current form "[com.foo.Bar, com.foo.Baz]"
+ * @see java.util.AbstractCollection#toString()
+ */
+ public static String classNamesToString(Collection<Class<?>> classes) {
+ if (classes.isEmpty()) {
+ return "[]";
+ }
+ StringBuilder sb = new StringBuilder("[");
+ for (Iterator<Class<?>> it = classes.iterator(); it.hasNext(); ) {
+ Class<?> clazz = it.next();
+ sb.append(clazz.getName());
+ if (it.hasNext()) {
+ sb.append(", ");
+ }
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+ /**
+ * Copy the given Collection into a Class array.
+ * The Collection must contain Class elements only.
+ *
+ * @param collection the Collection to copy
+ * @return the Class array ({@code null} if the passed-in
+ * Collection was {@code null})
+ */
+ public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
+ if (collection == null) {
+ return null;
+ }
+ return collection.toArray(new Class<?>[collection.size()]);
+ }
+
+ /**
+ * Return all interfaces that the given instance implements as array,
+ * including ones implemented by superclasses.
+ *
+ * @param instance the instance to analyze for interfaces
+ * @return all interfaces that the given instance implements as array
+ */
+ public static Class<?>[] getAllInterfaces(Object instance) {
+ Objects.requireNonNull(instance, "Instance must not be null");
+ return getAllInterfacesForClass(instance.getClass());
+ }
+
+ /**
+ * Return all interfaces that the given class implements as array,
+ * including ones implemented by superclasses.
+ * <p>If the class itself is an interface, it gets returned as sole interface.
+ *
+ * @param clazz the class to analyze for interfaces
+ * @return all interfaces that the given object implements as array
+ */
+ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz) {
+ return getAllInterfacesForClass(clazz, null);
+ }
+
+ /**
+ * Return all interfaces that the given class implements as array,
+ * including ones implemented by superclasses.
+ * <p>If the class itself is an interface, it gets returned as sole interface.
+ *
+ * @param clazz the class to analyze for interfaces
+ * @param classLoader the ClassLoader that the interfaces need to be visible in
+ * (may be {@code null} when accepting all declared interfaces)
+ * @return all interfaces that the given object implements as array
+ */
+ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) {
+ Set<Class<?>> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
+ return ifcs.toArray(new Class<?>[ifcs.size()]);
+ }
+
+ /**
+ * Return all interfaces that the given instance implements as Set,
+ * including ones implemented by superclasses.
+ *
+ * @param instance the instance to analyze for interfaces
+ * @return all interfaces that the given instance implements as Set
+ */
+ public static Set<Class<?>> getAllInterfacesAsSet(Object instance) {
+ Objects.requireNonNull(instance, "Instance must not be null");
+ return getAllInterfacesForClassAsSet(instance.getClass());
+ }
+
+ /**
+ * Return all interfaces that the given class implements as Set,
+ * including ones implemented by superclasses.
+ * <p>If the class itself is an interface, it gets returned as sole interface.
+ *
+ * @param clazz the class to analyze for interfaces
+ * @return all interfaces that the given object implements as Set
+ */
+ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz) {
+ return getAllInterfacesForClassAsSet(clazz, null);
+ }
+
+ /**
+ * Return all interfaces that the given class implements as Set,
+ * including ones implemented by superclasses.
+ * <p>If the class itself is an interface, it gets returned as sole interface.
+ *
+ * @param clazz the class to analyze for interfaces
+ * @param classLoader the ClassLoader that the interfaces need to be visible in
+ * (may be {@code null} when accepting all declared interfaces)
+ * @return all interfaces that the given object implements as Set
+ */
+ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
Objects.requireNonNull(clazz, "Class must not be null");
- return getPackageName(clazz.getName());
- }
-
- /**
- * Determine the name current the package current the given fully-qualified class name,
- * e.g. "java.lang" for the {@code java.lang.String} class name.
- * @param fqClassName the fully-qualified class name
- * @return the package name, or the empty String if the class
- * is defined in the dObjects.requireNonNullefault package
- */
- public static String getPackageName(String fqClassName) {
- Objects.requireNonNull(fqClassName, "Class name must not be null");
- int lastDotIndex = fqClassName.lastIndexOf(PACKAGE_SEPARATOR);
- return (lastDotIndex != -1 ? fqClassName.substring(0, lastDotIndex) : "");
- }
-
- /**
- * Return a public static method current a class.
- * @param methodName the static method name
- * @param clazz the class which defines the method
- * @param args the parameter types to the method
- * @return the static method, or {@code null} if no static method was found
- * @throws IllegalArgumentException if the method name is blank or the clazz is null
- */
- public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>... args) {
- Objects.requireNonNull(clazz, "Class must not be null");
- Objects.requireNonNull(methodName, "Method name must not be null");
- try {
- Method method = clazz.getMethod(methodName, args);
- return Modifier.isStatic(method.getModifiers()) ? method : null;
- }
- catch (NoSuchMethodException ex) {
- return null;
- }
- }
-
-
- /**
- * Check if the given class represents a primitive wrapper,
- * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
- * @param clazz the class to check
- * @return whether the given class is a primitive wrapper class
- */
- public static boolean isPrimitiveWrapper(Class<?> clazz) {
- Objects.requireNonNull(clazz, "Class must not be null");
- return primitiveWrapperTypeMap.containsKey(clazz);
- }
-
- /**
- * Check if the given class represents a primitive (i.e. boolean, byte,
- * char, short, int, long, float, or double) or a primitive wrapper
- * (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double).
- * @param clazz the class to check
- * @return whether the given class is a primitive or primitive wrapper class
- */
- public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
- Objects.requireNonNull(clazz, "Class must not be null");
- return (clazz.isPrimitive() || isPrimitiveWrapper(clazz));
- }
-
- /**
- * Check if the given class represents an array current primitives,
- * i.e. boolean, byte, char, short, int, long, float, or double.
- * @param clazz the class to check
- * @return whether the given class is a primitive array class
- */
- public static boolean isPrimitiveArray(Class<?> clazz) {
- Objects.requireNonNull(clazz, "Class must not be null");
- return (clazz.isArray() && clazz.getComponentType().isPrimitive());
- }
-
- /**
- * Check if the given class represents an array current primitive wrappers,
- * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
- * @param clazz the class to check
- * @return whether the given class is a primitive wrapper array class
- */
- public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
- Objects.requireNonNull(clazz, "Class must not be null");
- return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType()));
- }
-
- /**
- * Resolve the given class if it is a primitive class,
- * returning the corresponding primitive wrapper type instead.
- * @param clazz the class to check
- * @return the original class, or a primitive wrapper for the original primitive type
- */
- public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
- Objects.requireNonNull(clazz, "Class must not be null");
- return (clazz.isPrimitive() && clazz != void.class? primitiveTypeToWrapperMap.get(clazz) : clazz);
- }
-
- /**
- * Check if the right-hand side type may be assigned to the left-hand side
- * type, assuming setting by reflection. Considers primitive wrapper
- * classes as assignable to the corresponding primitive types.
- * @param lhsType the target type
- * @param rhsType the keys type that should be assigned to the target type
- * @return if the target type is assignable from the keys type
- */
- public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
- Objects.requireNonNull(lhsType, "Left-hand side type must not be null");
- Objects.requireNonNull(rhsType, "Right-hand side type must not be null");
- if (lhsType.isAssignableFrom(rhsType)) {
- return true;
- }
- if (lhsType.isPrimitive()) {
- Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType);
- if (resolvedPrimitive != null && lhsType.equals(resolvedPrimitive)) {
- return true;
- }
- }
- else {
- Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType);
- if (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Determine if the given type is assignable from the given keys,
- * assuming setting by reflection. Considers primitive wrapper classes
- * as assignable to the corresponding primitive types.
- * @param type the target type
- * @param keys the keys that should be assigned to the type
- * @return if the type is assignable from the keys
- */
- public static boolean isAssignableValue(Class<?> type, Object keys) {
- Objects.requireNonNull(type, "Type must not be null");
- return (keys != null ? isAssignable(type, keys.getClass()) : !type.isPrimitive());
- }
-
-
- /**
- * Convert a "/"-based resource path to a "."-based fully qualified class name.
- * @param resourcePath the resource path pointing to a class
- * @return the corresponding fully qualified class name
- */
- public static String convertResourcePathToClassName(String resourcePath) {
- Objects.requireNonNull(resourcePath, "Resource path must not be null");
- return resourcePath.replace(PATH_SEPARATOR, PACKAGE_SEPARATOR);
- }
-
- /**
- * Convert a "."-based fully qualified class name to a "/"-based resource path.
- * @param className the fully qualified class name
- * @return the corresponding resource path, pointing to the class
- */
- public static String convertClassNameToResourcePath(String className) {
- Objects.requireNonNull(className, "Class name must not be null");
- return className.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
- }
-
- /**
- * Return a path suitable for use with {@code ClassLoader.getResource}
- * (also suitable for use with {@code Class.getResource} by prepending a
- * slash ('/') to the return keys). Built by taking the package current the specified
- * class file, converting all dots ('.') to slashes ('/'), adding a trailing slash
- * if necessary, and concatenating the specified resource name to this.
- * <br/>As such, this function may be used to build a path suitable for
- * loading a resource file that is in the same package as a class file,
- * although {@code org.springframework.core.io.ClassPathResource} is usually
- * even more convenient.
- * @param clazz the Class whose package will be used as the base
- * @param resourceName the resource name to append. A leading slash is optional.
- * @return the built-up resource path
- * @see ClassLoader#getResource
- * @see Class#getResource
- */
- public static String addResourcePathToPackagePath(Class<?> clazz, String resourceName) {
- Objects.requireNonNull(resourceName, "Resource name must not be null");
- if (!resourceName.startsWith("/")) {
- return classPackageAsResourcePath(clazz) + "/" + resourceName;
- }
- return classPackageAsResourcePath(clazz) + resourceName;
- }
-
- /**
- * Given an input class object, return a string which consists current the
- * class's package name as a pathname, i.e., all dots ('.') are replaced by
- * slashes ('/'). Neither a leading nor trailing slash is added. The result
- * could be concatenated with a slash and the name current a resource and fed
- * directly to {@code ClassLoader.getResource()}. For it to be fed to
- * {@code Class.getResource} instead, a leading slash would also have
- * to be prepended to the returned keys.
- * @param clazz the input class. A {@code null} keys or the default
- * (empty) package will result in an empty string ("") being returned.
- * @return a path which represents the package name
- * @see ClassLoader#getResource
- * @see Class#getResource
- */
- public static String classPackageAsResourcePath(Class<?> clazz) {
- if (clazz == null) {
- return "";
- }
- String className = clazz.getName();
- int packageEndIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
- if (packageEndIndex == -1) {
- return "";
- }
- String packageName = className.substring(0, packageEndIndex);
- return packageName.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
- }
-
- /**
- * Build a String that consists current the names current the classes/interfaces
- * in the given array.
- * <p>Basically like {@code AbstractCollection.toString()}, but stripping
- * the "class "/"interface " prefix before every class name.
- * @param classes a Collection current Class objects (may be {@code null})
- * @return a String current form "[com.foo.Bar, com.foo.Baz]"
- * @see java.util.AbstractCollection#toString()
- */
- public static String classNamesToString(Class<?>... classes) {
- return classNamesToString(Arrays.asList(classes));
- }
-
- /**
- * Build a String that consists current the names current the classes/interfaces
- * in the given collection.
- * <p>Basically like {@code AbstractCollection.toString()}, but stripping
- * the "class "/"interface " prefix before every class name.
- * @param classes a Collection current Class objects (may be {@code null})
- * @return a String current form "[com.foo.Bar, com.foo.Baz]"
- * @see java.util.AbstractCollection#toString()
- */
- public static String classNamesToString(Collection<Class<?>> classes) {
- if (classes.isEmpty()) {
- return "[]";
- }
- StringBuilder sb = new StringBuilder("[");
- for (Iterator<Class<?>> it = classes.iterator(); it.hasNext(); ) {
- Class<?> clazz = it.next();
- sb.append(clazz.getName());
- if (it.hasNext()) {
- sb.append(", ");
- }
- }
- sb.append("]");
- return sb.toString();
- }
-
- /**
- * Copy the given Collection into a Class array.
- * The Collection must contain Class elements only.
- * @param collection the Collection to copy
- * @return the Class array ({@code null} if the passed-in
- * Collection was {@code null})
- */
- public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
- if (collection == null) {
- return null;
- }
- return collection.toArray(new Class<?>[collection.size()]);
- }
-
- /**
- * Return all interfaces that the given instance implements as array,
- * including ones implemented by superclasses.
- * @param instance the instance to analyze for interfaces
- * @return all interfaces that the given instance implements as array
- */
- public static Class<?>[] getAllInterfaces(Object instance) {
- Objects.requireNonNull(instance, "Instance must not be null");
- return getAllInterfacesForClass(instance.getClass());
- }
-
- /**
- * Return all interfaces that the given class implements as array,
- * including ones implemented by superclasses.
- * <p>If the class itself is an interface, it gets returned as sole interface.
- * @param clazz the class to analyze for interfaces
- * @return all interfaces that the given object implements as array
- */
- public static Class<?>[] getAllInterfacesForClass(Class<?> clazz) {
- return getAllInterfacesForClass(clazz, null);
- }
-
- /**
- * Return all interfaces that the given class implements as array,
- * including ones implemented by superclasses.
- * <p>If the class itself is an interface, it gets returned as sole interface.
- * @param clazz the class to analyze for interfaces
- * @param classLoader the ClassLoader that the interfaces need to be visible in
- * (may be {@code null} when accepting all declared interfaces)
- * @return all interfaces that the given object implements as array
- */
- public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) {
- Set<Class<?>> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
- return ifcs.toArray(new Class<?>[ifcs.size()]);
- }
-
- /**
- * Return all interfaces that the given instance implements as Set,
- * including ones implemented by superclasses.
- * @param instance the instance to analyze for interfaces
- * @return all interfaces that the given instance implements as Set
- */
- public static Set<Class<?>> getAllInterfacesAsSet(Object instance) {
- Objects.requireNonNull(instance, "Instance must not be null");
- return getAllInterfacesForClassAsSet(instance.getClass());
- }
-
- /**
- * Return all interfaces that the given class implements as Set,
- * including ones implemented by superclasses.
- * <p>If the class itself is an interface, it gets returned as sole interface.
- * @param clazz the class to analyze for interfaces
- * @return all interfaces that the given object implements as Set
- */
- public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz) {
- return getAllInterfacesForClassAsSet(clazz, null);
- }
-
- /**
- * Return all interfaces that the given class implements as Set,
- * including ones implemented by superclasses.
- * <p>If the class itself is an interface, it gets returned as sole interface.
- * @param clazz the class to analyze for interfaces
- * @param classLoader the ClassLoader that the interfaces need to be visible in
- * (may be {@code null} when accepting all declared interfaces)
- * @return all interfaces that the given object implements as Set
- */
- public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
- Objects.requireNonNull(clazz, "Class must not be null");
- if (clazz.isInterface() && isVisible(clazz, classLoader)) {
- return Collections.<Class<?>>singleton(clazz);
- }
- Set<Class<?>> interfaces = new LinkedHashSet<>();
- while (clazz != null) {
- Class<?>[] ifcs = clazz.getInterfaces();
- for (Class<?> ifc : ifcs) {
- interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));
- }
- clazz = clazz.getSuperclass();
- }
- return interfaces;
- }
-
- /**
- * Create a composite interface Class for the given interfaces,
- * implementing the given interfaces in one single Class.
- * <p>This implementation builds a JDK proxy class for the given interfaces.
- * @param interfaces the interfaces to merge
- * @param classLoader the ClassLoader to of the composite Class in
- * @return the merged interface as Class
- * @see java.lang.reflect.Proxy#getProxyClass
- */
- public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) {
- if(interfaces.length==0) throw new IllegalArgumentException("Interfaces must not be empty");
- Objects.requireNonNull(classLoader, "ClassLoader must not be null");
- return Proxy.getProxyClass(classLoader, interfaces);
- }
-
- /**
- * Determine the common ancestor current the given classes, if any.
- * @param clazz1 the class to introspect
- * @param clazz2 the other class to introspect
- * @return the common ancestor (i.e. common superclass, one interface
- * extending the other), or {@code null} if none found. If any current the
- * given classes is {@code null}, the other class will be returned.
- * @since 3.2.6
- */
- public static Class<?> determineCommonAncestor(Class<?> clazz1, Class<?> clazz2) {
- if (clazz1 == null) {
- return clazz2;
- }
- if (clazz2 == null) {
- return clazz1;
- }
- if (clazz1.isAssignableFrom(clazz2)) {
- return clazz1;
- }
- if (clazz2.isAssignableFrom(clazz1)) {
- return clazz2;
- }
- Class<?> ancestor = clazz1;
- do {
- ancestor = ancestor.getSuperclass();
- if (ancestor == null || Object.class.equals(ancestor)) {
- return null;
- }
- }
- while (!ancestor.isAssignableFrom(clazz2));
- return ancestor;
- }
-
- /**
- * Check whether the given class is visible in the given ClassLoader.
- * @param clazz the class to check (typically an interface)
- * @param classLoader the ClassLoader to check against (may be {@code null},
- * in which case this method will always return {@code true})
- */
- public static boolean isVisible(Class<?> clazz, ClassLoader classLoader) {
- if (classLoader == null) {
- return true;
- }
- try {
- Class<?> actualClass = classLoader.loadClass(clazz.getName());
- return (clazz == actualClass);
- // Else: different interface class found...
- }
- catch (ClassNotFoundException ex) {
- // No interface class found...
- return false;
- }
- }
+ if (clazz.isInterface() && isVisible(clazz, classLoader)) {
+ return Collections.<Class<?>>singleton(clazz);
+ }
+ Set<Class<?>> interfaces = new LinkedHashSet<>();
+ while (clazz != null) {
+ Class<?>[] ifcs = clazz.getInterfaces();
+ for (Class<?> ifc : ifcs) {
+ interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));
+ }
+ clazz = clazz.getSuperclass();
+ }
+ return interfaces;
+ }
+
+ /**
+ * Create a composite interface Class for the given interfaces,
+ * implementing the given interfaces in one single Class.
+ * <p>This implementation builds a JDK proxy class for the given interfaces.
+ *
+ * @param interfaces the interfaces to merge
+ * @param classLoader the ClassLoader to of the composite Class in
+ * @return the merged interface as Class
+ * @see java.lang.reflect.Proxy#getProxyClass
+ */
+ public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) {
+ if (interfaces.length == 0) {
+ throw new IllegalArgumentException("Interfaces must not be empty");
+ }
+ Objects.requireNonNull(classLoader, "ClassLoader must not be null");
+ return Proxy.getProxyClass(classLoader, interfaces);
+ }
+
+ /**
+ * Determine the common ancestor current the given classes, if any.
+ *
+ * @param clazz1 the class to introspect
+ * @param clazz2 the other class to introspect
+ * @return the common ancestor (i.e. common superclass, one interface
+ * extending the other), or {@code null} if none found. If any current the
+ * given classes is {@code null}, the other class will be returned.
+ * @since 3.2.6
+ */
+ public static Class<?> determineCommonAncestor(Class<?> clazz1, Class<?> clazz2) {
+ if (clazz1 == null) {
+ return clazz2;
+ }
+ if (clazz2 == null) {
+ return clazz1;
+ }
+ if (clazz1.isAssignableFrom(clazz2)) {
+ return clazz1;
+ }
+ if (clazz2.isAssignableFrom(clazz1)) {
+ return clazz2;
+ }
+ Class<?> ancestor = clazz1;
+ do {
+ ancestor = ancestor.getSuperclass();
+ if (ancestor == null || Object.class.equals(ancestor)) {
+ return null;
+ }
+ }
+ while (!ancestor.isAssignableFrom(clazz2));
+ return ancestor;
+ }
+
+ /**
+ * Check whether the given class is visible in the given ClassLoader.
+ *
+ * @param clazz the class to check (typically an interface)
+ * @param classLoader the ClassLoader to check against (may be {@code null},
+ * in which case this method will always return {@code true})
+ */
+ public static boolean isVisible(Class<?> clazz, ClassLoader classLoader) {
+ if (classLoader == null) {
+ return true;
+ }
+ try {
+ Class<?> actualClass = classLoader.loadClass(clazz.getName());
+ return (clazz == actualClass);
+ // Else: different interface class found...
+ } catch (ClassNotFoundException ex) {
+ // No interface class found...
+ return false;
+ }
+ }
}
[25/27] incubator-tamaya git commit: Fixed checkstyle issues.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java
index e956670..11dc8ee 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/InputStreamResource.java
@@ -27,7 +27,7 @@ import java.util.Objects;
* be used if no specific Resource implementation is applicable.
* In particular, prefer {@code ByteArrayResource} or any current the
* file-based Resource implementations where possible.
- *
+ * <p>
* <p>In contrast to other Resource implementations, this is a descriptor
* for an <i>already opened</i> resource - therefore returning "true" from
* {@code isOpen()}. Do not use it if you need to keep the resource
@@ -38,85 +38,87 @@ import java.util.Objects;
*/
public class InputStreamResource implements Resource {
- private final InputStream inputStream;
-
- private final String description;
-
- private boolean read = false;
-
-
- /**
- * Create a new InputStreamResource.
- * @param inputStream the InputStream to use
- */
- public InputStreamResource(InputStream inputStream) {
- this(inputStream, "resource loaded through InputStream");
- }
-
- /**
- * Create a new InputStreamResource.
- * @param inputStream the InputStream to use
- * @param description where the InputStream comes from
- */
- public InputStreamResource(InputStream inputStream, String description) {
- this.inputStream = Objects.requireNonNull(inputStream);
- this.description = (description != null ? description : "");
- }
-
-
- /**
- * This implementation always returns {@code true}.
- */
- @Override
- public boolean exists() {
- return true;
- }
-
- /**
- * This implementation always returns {@code true}.
- */
- @Override
- public boolean isOpen() {
- return true;
- }
-
- /**
- * This implementation throws IllegalStateException if attempting to
- * read the underlying stream multiple times.
- */
- @Override
- public InputStream getInputStream() throws IOException {
- if (this.read) {
- throw new IllegalStateException("InputStream has already been read - " +
- "do not use InputStreamResource if a stream needs to be read multiple times");
- }
- this.read = true;
- return this.inputStream;
- }
-
- /**
- * This implementation returns the passed-in description, if any.
- */
- public String toString() {
- return this.description!=null?this.description:super.toString();
- }
-
-
- /**
- * This implementation compares the underlying InputStream.
- */
- @Override
- public boolean equals(Object obj) {
- return (obj == this ||
- (obj instanceof InputStreamResource && ((InputStreamResource) obj).inputStream.equals(this.inputStream)));
- }
-
- /**
- * This implementation returns the hash code current the underlying InputStream.
- */
- @Override
- public int hashCode() {
- return this.inputStream.hashCode();
- }
+ private final InputStream inputStream;
+
+ private final String description;
+
+ private boolean read = false;
+
+
+ /**
+ * Create a new InputStreamResource.
+ *
+ * @param inputStream the InputStream to use
+ */
+ public InputStreamResource(InputStream inputStream) {
+ this(inputStream, "resource loaded through InputStream");
+ }
+
+ /**
+ * Create a new InputStreamResource.
+ *
+ * @param inputStream the InputStream to use
+ * @param description where the InputStream comes from
+ */
+ public InputStreamResource(InputStream inputStream, String description) {
+ this.inputStream = Objects.requireNonNull(inputStream);
+ this.description = (description != null ? description : "");
+ }
+
+
+ /**
+ * This implementation always returns {@code true}.
+ */
+ @Override
+ public boolean exists() {
+ return true;
+ }
+
+ /**
+ * This implementation always returns {@code true}.
+ */
+ @Override
+ public boolean isOpen() {
+ return true;
+ }
+
+ /**
+ * This implementation throws IllegalStateException if attempting to
+ * read the underlying stream multiple times.
+ */
+ @Override
+ public InputStream getInputStream() throws IOException {
+ if (this.read) {
+ throw new IllegalStateException("InputStream has already been read - " +
+ "do not use InputStreamResource if a stream needs to be read multiple times");
+ }
+ this.read = true;
+ return this.inputStream;
+ }
+
+ /**
+ * This implementation returns the passed-in description, if any.
+ */
+ public String toString() {
+ return this.description != null ? this.description : super.toString();
+ }
+
+
+ /**
+ * This implementation compares the underlying InputStream.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return (obj == this ||
+ (obj instanceof InputStreamResource && ((InputStreamResource) obj).inputStream.equals(this.inputStream)));
+ }
+
+ /**
+ * This implementation returns the hash code current the underlying InputStream.
+ */
+ @Override
+ public int hashCode() {
+ return this.inputStream.hashCode();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java
index c70f04b..cf16762 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingDefaultResourceLoader.java
@@ -33,107 +33,110 @@ import java.util.Objects;
*/
class PathMatchingDefaultResourceLoader {
- /** Pseudo URL prefix for loading from the class path: "classpath:" */
+ /**
+ * Pseudo URL prefix for loading from the class path: "classpath:"
+ */
public static final String CLASSPATH_URL_PREFIX = "classpath:";
- private ClassLoader classLoader;
-
-
- /**
- * Create a new DefaultResourceLoader.
- * <p>ClassLoader access will happen using the thread context class loader
- * at the time current this ResourceLoader's initialization.
- * @see java.lang.Thread#getContextClassLoader()
- */
- public PathMatchingDefaultResourceLoader() {
- this.classLoader = ClassUtils.getDefaultClassLoader();
- }
-
- /**
- * Create a new DefaultResourceLoader.
- * @param classLoader the ClassLoader to load class path resources with, or {@code null}
- * for using the thread context class loader at the time current actual resource access
- */
- public PathMatchingDefaultResourceLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
-
- /**
- * Specify the ClassLoader to load class path resources with, or {@code null}
- * for using the thread context class loader at the time current actual resource access.
- * <p>The default is that ClassLoader access will happen using the thread context
- * class loader at the time current this ResourceLoader's initialization.
- */
- void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- /**
- * Return the ClassLoader to load class path resources with.
- * <p>Will get passed to ClassPathResource's constructor for all
- * ClassPathResource objects created by this resource loader.
- * @see ClassPathResource
- */
- public ClassLoader getClassLoader() {
- return (this.classLoader != null ? this.classLoader : ClassUtils.getDefaultClassLoader());
- }
-
-
- public Resource getResource(String location) {
- Objects.requireNonNull(location, "Location must not be null");
- if (location.startsWith("/")) {
- return getResourceByPath(location);
- }
- else if (location.startsWith(CLASSPATH_URL_PREFIX)) {
- return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());
- }
- else {
- try {
- // Try to parse the location as a URL...
- URL url = new URL(location);
- return new UrlResource(url);
- }
- catch (MalformedURLException ex) {
- // No URL -> resolve as resource path.
- return getResourceByPath(location);
- }
- }
- }
-
- /**
- * Return a Resource handle for the resource at the given path.
- * <p>The default implementation supports class path locations. This should
- * be appropriate for standalone implementations but can be overridden,
- * e.g. for implementations targeted at a Servlet container.
- * @param path the path to the resource
- * @return the corresponding Resource handle
- * @see ClassPathResource
- */
- protected Resource getResourceByPath(String path) {
- return new ClassPathContextResource(path, getClassLoader());
- }
-
-
- /**
- * ClassPathResource that explicitly expresses a context-relative path
- * through implementing the ContextResource interface.
- */
- protected static class ClassPathContextResource extends ClassPathResource {
-
- public ClassPathContextResource(String path, ClassLoader classLoader) {
- super(path, classLoader);
- }
-
- public String getPathWithinContext() {
- return getPath();
- }
-
- @Override
- public Resource createRelative(String relativePath) {
- String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
- return new ClassPathContextResource(pathToUse, getClassLoader());
- }
- }
+ private ClassLoader classLoader;
+
+
+ /**
+ * Create a new DefaultResourceLoader.
+ * <p>ClassLoader access will happen using the thread context class loader
+ * at the time current this ResourceLoader's initialization.
+ *
+ * @see java.lang.Thread#getContextClassLoader()
+ */
+ public PathMatchingDefaultResourceLoader() {
+ this.classLoader = ClassUtils.getDefaultClassLoader();
+ }
+
+ /**
+ * Create a new DefaultResourceLoader.
+ *
+ * @param classLoader the ClassLoader to load class path resources with, or {@code null}
+ * for using the thread context class loader at the time current actual resource access
+ */
+ public PathMatchingDefaultResourceLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+
+ /**
+ * Specify the ClassLoader to load class path resources with, or {@code null}
+ * for using the thread context class loader at the time current actual resource access.
+ * <p>The default is that ClassLoader access will happen using the thread context
+ * class loader at the time current this ResourceLoader's initialization.
+ */
+ void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ /**
+ * Return the ClassLoader to load class path resources with.
+ * <p>Will get passed to ClassPathResource's constructor for all
+ * ClassPathResource objects created by this resource loader.
+ *
+ * @see ClassPathResource
+ */
+ public ClassLoader getClassLoader() {
+ return (this.classLoader != null ? this.classLoader : ClassUtils.getDefaultClassLoader());
+ }
+
+
+ public Resource getResource(String location) {
+ Objects.requireNonNull(location, "Location must not be null");
+ if (location.startsWith("/")) {
+ return getResourceByPath(location);
+ } else if (location.startsWith(CLASSPATH_URL_PREFIX)) {
+ return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());
+ } else {
+ try {
+ // Try to parse the location as a URL...
+ URL url = new URL(location);
+ return new UrlResource(url);
+ } catch (MalformedURLException ex) {
+ // No URL -> resolve as resource path.
+ return getResourceByPath(location);
+ }
+ }
+ }
+
+ /**
+ * Return a Resource handle for the resource at the given path.
+ * <p>The default implementation supports class path locations. This should
+ * be appropriate for standalone implementations but can be overridden,
+ * e.g. for implementations targeted at a Servlet container.
+ *
+ * @param path the path to the resource
+ * @return the corresponding Resource handle
+ * @see ClassPathResource
+ */
+ protected Resource getResourceByPath(String path) {
+ return new ClassPathContextResource(path, getClassLoader());
+ }
+
+
+ /**
+ * ClassPathResource that explicitly expresses a context-relative path
+ * through implementing the ContextResource interface.
+ */
+ protected static class ClassPathContextResource extends ClassPathResource {
+
+ public ClassPathContextResource(String path, ClassLoader classLoader) {
+ super(path, classLoader);
+ }
+
+ public String getPathWithinContext() {
+ return getPath();
+ }
+
+ @Override
+ public Resource createRelative(String relativePath) {
+ String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
+ return new ClassPathContextResource(pathToUse, getClassLoader());
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java
index 005617b..b4cee0d 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/PathMatchingResourcePatternResolver.java
@@ -48,9 +48,9 @@ import java.util.stream.Collectors;
* internal Ant-style regular expressions (matched using Spring's
* {@code org.springframework.util.AntPathMatcher} utility).
* Both current the latter are effectively wildcards.
- *
+ * <p>
* <p><b>No Wildcards:</b>
- *
+ * <p>
* <p>In the simple case, if the specified location path does not start with the
* {@code "classpath*:}" prefix, and does not contain a PathMatcher pattern,
* this resolver will simply return a single resource via a
@@ -60,9 +60,9 @@ import java.util.stream.Collectors;
* such as "{@code /WEB-INF/context.xml}". The latter will resolve in a
* fashion specific to the underlying {@code ResourceLoader} (e.g.
* {@code ServletContextResource} for a {@code WebApplicationContext}).
- *
+ * <p>
* <p><b>Ant-style Patterns:</b>
- *
+ * <p>
* <p>When the path location contains an Ant-style pattern, e.g.:
* <pre class="code">
* /WEB-INF/*-context.xml
@@ -79,13 +79,13 @@ import java.util.stream.Collectors;
* either gets a {@code java.net.JarURLConnection} from it, or manually parses
* the jar URL, and then traverses the contents current the jar file, to resolve the
* wildcards.
- *
+ * <p>
* <p><b>Implications on portability:</b>
- *
+ * <p>
* <p>If the specified path is already a file URL (either explicitly, or
* implicitly because the base {@code ResourceLoader} is a filesystem one,
* then wildcarding is guaranteed to work in a completely portable fashion.
- *
+ * <p>
* <p>If the specified path is a classpath location, then the resolver must
* obtain the last non-wildcard path segment URL via a
* {@code Classloader.getResource()} call. Since this is just a
@@ -95,7 +95,7 @@ import java.util.stream.Collectors;
* the directory, where the classpath resource resolves to a filesystem
* location, or a jar URL current some sort, where the classpath resource resolves
* to a jar location. Still, there is a portability concern on this operation.
- *
+ * <p>
* <p>If a jar URL is obtained for the last non-wildcard segment, the resolver
* must be able to get a {@code java.net.JarURLConnection} from it, or
* manually parse the jar URL, to be able to walk the contents current the jar,
@@ -103,9 +103,9 @@ import java.util.stream.Collectors;
* fail in others, and it is strongly recommended that the wildcard
* resolution current resources coming from jars be thoroughly tested in your
* specific environment before you rely on it.
- *
+ * <p>
* <p><b>{@code classpath*:} Prefix:</b>
- *
+ * <p>
* <p>There is special support for retrieving multiple class path resources with
* the same name, via the "{@code classpath*:}" prefix. For example,
* "{@code classpath*:META-INF/beans.xml}" will find all "beans.xml"
@@ -113,7 +113,7 @@ import java.util.stream.Collectors;
* This is particularly useful for autodetecting config files current the same name
* at the same location within each jar file. Internally, this happens via a
* {@code ClassLoader.getResources()} call, and is completely portable.
- *
+ * <p>
* <p>The "classpath*:" prefix can also be combined with a PathMatcher pattern in
* the rest current the location path, for example "classpath*:META-INF/*-beans.xml".
* In this case, the resolution strategy is fairly simple: a
@@ -121,9 +121,9 @@ import java.util.stream.Collectors;
* path segment to get all the matching resources in the class loader hierarchy,
* and then off each resource the same PathMatcher resolution strategy described
* above is used for the wildcard subpath.
- *
+ * <p>
* <p><b>Other notes:</b>
- *
+ * <p>
* <p><b>WARNING:</b> Note that "{@code classpath*:}" when combined with
* Ant-style patterns will only work reliably with at least one root directory
* before the pattern starts, unless the actual target files reside in the file
@@ -132,16 +132,16 @@ import java.util.stream.Collectors;
* root current expanded directories. This originates from a limitation in the JDK's
* {@code ClassLoader.getResources()} method which only returns file system
* locations for a passed-in empty String (indicating potential roots to search).
- *
+ * <p>
* <p><b>WARNING:</b> Ant-style patterns with "classpath:" resources are not
* guaranteed to find matching resources if the root package to search is available
* in multiple class path locations. This is because a resource such as
* <pre class="code">
- * com/mycompany/package1/service-context.xml
+ * com/mycompany/package1/service-context.xml
* </pre>
* may be in only one location, but when a path such as
* <pre class="code">
- * classpath:com/mycompany/**/service-context.xml
+ * classpath:com/mycompany/**/service-context.xml
* </pre>
* is used to try to resolve it, the resolver will work off the (first) URL
* returned by {@code getResource("com/mycompany");}. If this base package
@@ -154,10 +154,10 @@ import java.util.stream.Collectors;
* @author Colin Sampaleanu
* @author Marius Bogoevici
* @author Costin Leau
- * @since 1.0.2
* @see ClassLoader#getResources(String)
+ * @since 1.0.2
*/
-public final class PathMatchingResourcePatternResolver{
+public final class PathMatchingResourcePatternResolver {
private static final Logger logger = Logger.getLogger(PathMatchingResourcePatternResolver.class.getName());
private static final java.lang.String CLASSPATH_ALL_URL_PREFIX = "classpath:";
@@ -171,8 +171,7 @@ public final class PathMatchingResourcePatternResolver{
PathMatchingResourcePatternResolver.class.getClassLoader());
equinoxResolveMethod = fileLocatorClass.getMethod("resolve", URL.class);
logger.finest("Found Equinox FileLocator for OSGi bundle URL resolution");
- }
- catch (Throwable ex) {
+ } catch (Throwable ex) {
equinoxResolveMethod = null;
}
}
@@ -184,7 +183,7 @@ public final class PathMatchingResourcePatternResolver{
private static Map<ClassLoader, PathMatchingResourcePatternResolver> resolvers = new ConcurrentHashMap<>();
- public static PathMatchingResourcePatternResolver of(ClassLoader loader){
+ public static PathMatchingResourcePatternResolver of(ClassLoader loader) {
return resolvers.computeIfAbsent(loader, PathMatchingResourcePatternResolver::new);
}
@@ -198,9 +197,10 @@ public final class PathMatchingResourcePatternResolver{
/**
* Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader.
+ *
* @param classLoader the ClassLoader to load classpath resources with,
- * or {@code null} for using the thread context class loader
- * at the time current actual resource access
+ * or {@code null} for using the thread context class loader
+ * at the time current actual resource access
* @see PathMatchingDefaultResourceLoader
*/
public PathMatchingResourcePatternResolver(ClassLoader classLoader) {
@@ -229,23 +229,20 @@ public final class PathMatchingResourcePatternResolver{
if (getPathMatcher().isPattern(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()))) {
// a class path resource pattern
return findPathMatchingResources(locationPattern);
- }
- else {
+ } else {
// all class path resources with the given name
return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()));
}
- }
- else {
+ } else {
// Only look for a pattern after a prefix here
// (to not get fooled by a pattern symbol in a strange prefix).
int prefixEnd = locationPattern.indexOf(':') + 1;
if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) {
// a file pattern
return findPathMatchingResources(locationPattern);
- }
- else {
+ } else {
// a single resource with the given name
- return new Resource[] {this.resourceLoader.getResource(locationPattern)};
+ return new Resource[]{this.resourceLoader.getResource(locationPattern)};
}
}
}
@@ -253,6 +250,7 @@ public final class PathMatchingResourcePatternResolver{
/**
* Find all class location resources with the given location via the ClassLoader.
* Delegates to {@link #doFindAllClassPathResources(String)}.
+ *
* @param location the absolute path within the classpath
* @return the result as Resource array
* @throws IOException in case current I/O errors
@@ -271,6 +269,7 @@ public final class PathMatchingResourcePatternResolver{
/**
* Find all class location resources with the given path via the ClassLoader.
* Called by {@link #findAllClassPathResources(String)}.
+ *
* @param path the absolute path within the classpath (never a leading slash)
* @return a mutable Set current matching Resource instances
*/
@@ -293,6 +292,7 @@ public final class PathMatchingResourcePatternResolver{
/**
* Convert the given URL as returned from the ClassLoader into a {@link Resource}.
* <p>The default implementation simply creates a {@link UrlResource} instance.
+ *
* @param url a URL as returned from the ClassLoader
* @return the corresponding Resource object
* @see java.lang.ClassLoader#getResources
@@ -305,8 +305,9 @@ public final class PathMatchingResourcePatternResolver{
/**
* Search all {@link URLClassLoader} URLs for jar file references and add them to the
* given set current resources in the form current pointers to the root current the jar file content.
+ *
* @param classLoader the ClassLoader to search (including its ancestors)
- * @param result the set current resources to add jar roots to
+ * @param result the set current resources to add jar roots to
*/
protected void addAllClassLoaderJarRoots(ClassLoader classLoader, Set<Resource> result) {
if (classLoader instanceof URLClassLoader) {
@@ -319,15 +320,13 @@ public final class PathMatchingResourcePatternResolver{
if (jarResource.exists()) {
result.add(jarResource);
}
- }
- catch (MalformedURLException ex) {
+ } catch (MalformedURLException ex) {
logger.finest(() -> "Cannot search for matching files underneath [" + url +
"] because it cannot be converted to a valid 'jar:' URL: " + ex.getMessage());
}
}
}
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
logger.finest(() -> "Cannot introspect jar files since ClassLoader [" + classLoader +
"] does not support 'getURLs()': " + ex);
}
@@ -335,8 +334,7 @@ public final class PathMatchingResourcePatternResolver{
if (classLoader != null) {
try {
addAllClassLoaderJarRoots(classLoader.getParent(), result);
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
logger.finest(() -> "Cannot introspect jar files in parent ClassLoader since [" + classLoader +
"] does not support 'getParent()': " + ex);
}
@@ -347,6 +345,7 @@ public final class PathMatchingResourcePatternResolver{
* Find all resources that match the given location pattern via the
* Ant-style PathMatcher. Supports resources in jar files and zip files
* and in the file system.
+ *
* @param locationPattern the location pattern to match
* @return the result as Resource array
* @throws IOException in case current I/O errors
@@ -362,11 +361,9 @@ public final class PathMatchingResourcePatternResolver{
rootDirResource = resolveRootDirResource(rootDirResource);
if (rootDirResource.toURL().getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
result.addAll(VfsResourceMatchingDelegate.findMatchingResources(rootDirResource, subPattern, getPathMatcher()));
- }
- else if (isJarResource(rootDirResource)) {
+ } else if (isJarResource(rootDirResource)) {
result.addAll(doFindPathMatchingJarResources(rootDirResource, subPattern));
- }
- else {
+ } else {
result.addAll(doFindPathMatchingFileResources(rootDirResource, subPattern));
}
}
@@ -382,6 +379,7 @@ public final class PathMatchingResourcePatternResolver{
* remainder current the location as pattern.
* <p>Will return "/WEB-INF/" for the pattern "/WEB-INF/*.xml",
* for example.
+ *
* @param location the location to check
* @return the part current the location that denotes the root directory
* @see #retrieveMatchingFiles
@@ -403,6 +401,7 @@ public final class PathMatchingResourcePatternResolver{
* <p>The default implementation detects an Equinox OSGi "bundleresource:"
* / "bundleentry:" URL and resolves it into a standard jar file URL that
* can be traversed using Spring's standard jar file traversal algorithm.
+ *
* @param original the resource to resolve
* @return the resolved resource (may be identical to the passed-in resource)
* @throws IOException in case current resolution failure
@@ -427,8 +426,9 @@ public final class PathMatchingResourcePatternResolver{
* <p>The default implementation checks against the URL protocols
* "jar", "zip" and "wsjar" (the latter are used by BEA WebLogic Server
* and IBM WebSphere, respectively, but can be treated like jar files).
+ *
* @param resource the resource handle to check
- * (usually the root directory to start path matching from)
+ * (usually the root directory to start path matching from)
* @see #doFindPathMatchingJarResources
* @see ResourceUtils#isJarURL
*/
@@ -439,8 +439,9 @@ public final class PathMatchingResourcePatternResolver{
/**
* Find all resources in jar files that match the given location pattern
* via the Ant-style PathMatcher.
+ *
* @param rootDirResource the root directory as Resource
- * @param subPattern the sub pattern to match (below the root directory)
+ * @param subPattern the sub pattern to match (below the root directory)
* @return a mutable Set current matching Resource instances
* @throws IOException in case current I/O errors
* @see java.net.JarURLConnection
@@ -462,8 +463,7 @@ public final class PathMatchingResourcePatternResolver{
jarFileUrl = jarCon.getJarFileURL().toExternalForm();
JarEntry jarEntry = jarCon.getJarEntry();
rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
- }
- else {
+ } else {
// No JarURLConnection -> need to resort to URL file parsing.
// We'll assume URLs current the format "jar:path!/entry", with the protocol
// being arbitrary as long as following the entry format.
@@ -474,8 +474,7 @@ public final class PathMatchingResourcePatternResolver{
jarFileUrl = urlFile.substring(0, separatorIndex);
rootEntryPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length());
jarFile = getJarFile(jarFileUrl);
- }
- else {
+ } else {
jarFile = new JarFile(urlFile);
jarFileUrl = urlFile;
rootEntryPath = "";
@@ -491,7 +490,7 @@ public final class PathMatchingResourcePatternResolver{
rootEntryPath = rootEntryPath + "/";
}
Set<Resource> result = new LinkedHashSet<>(8);
- for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
+ for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) {
JarEntry entry = entries.nextElement();
String entryPath = entry.getName();
if (entryPath.startsWith(rootEntryPath)) {
@@ -502,8 +501,7 @@ public final class PathMatchingResourcePatternResolver{
}
}
return result;
- }
- finally {
+ } finally {
// Close jar file, but only if freshly obtained -
// not from JarURLConnection, which might cache the file reference.
if (newJarFile) {
@@ -519,13 +517,11 @@ public final class PathMatchingResourcePatternResolver{
if (jarFileUrl.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
try {
return new JarFile(ResourceUtils.toURI(jarFileUrl).getSchemeSpecificPart());
- }
- catch (URISyntaxException ex) {
+ } catch (URISyntaxException ex) {
// Fallback for URLs that are not valid URIs (should hardly ever happen).
return new JarFile(jarFileUrl.substring(ResourceUtils.FILE_URL_PREFIX.length()));
}
- }
- else {
+ } else {
return new JarFile(jarFileUrl);
}
}
@@ -533,8 +529,9 @@ public final class PathMatchingResourcePatternResolver{
/**
* Find all resources in the file system that match the given location pattern
* via the Ant-style PathMatcher.
+ *
* @param rootDirResource the root directory as Resource
- * @param subPattern the sub pattern to match (below the root directory)
+ * @param subPattern the sub pattern to match (below the root directory)
* @return a mutable Set current matching Resource instances
* @throws IOException in case current I/O errors
* @see #retrieveMatchingFiles
@@ -545,10 +542,9 @@ public final class PathMatchingResourcePatternResolver{
File rootDir;
try {
rootDir = rootDirResource.toFile().getAbsoluteFile();
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
logger.log(Level.WARNING, ex, () -> "Cannot search for matching files underneath " + rootDirResource +
- " because it does not correspond to a directory in the file system");
+ " because it does not correspond to a directory in the file system");
return Collections.emptySet();
}
return doFindMatchingFileSystemResources(rootDir, subPattern);
@@ -557,7 +553,8 @@ public final class PathMatchingResourcePatternResolver{
/**
* Find all resources in the file system that match the given location pattern
* via the Ant-style PathMatcher.
- * @param rootDir the root directory in the file system
+ *
+ * @param rootDir the root directory in the file system
* @param subPattern the sub pattern to match (below the root directory)
* @return a mutable Set current matching Resource instances
* @throws IOException in case current I/O errors
@@ -574,9 +571,10 @@ public final class PathMatchingResourcePatternResolver{
/**
* Retrieve files that match the given path pattern,
* checking the given directory and its subdirectories.
+ *
* @param rootDir the directory to start from
* @param pattern the pattern to match against,
- * relative to the root directory
+ * relative to the root directory
* @return a mutable Set current matching Resource instances
* @throws IOException if directory contents could not be retrieved
*/
@@ -609,10 +607,11 @@ public final class PathMatchingResourcePatternResolver{
/**
* Recursively retrieve files that match the given pattern,
* adding them to the given result list.
+ *
* @param fullPattern the pattern to match against,
- * with prepended root directory path
- * @param dir the current directory
- * @param result the Set current matching File instances to add to
+ * with prepended root directory path
+ * @param dir the current directory
+ * @param result the Set current matching File instances to add to
* @throws IOException if directory contents could not be retrieved
*/
protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> result) throws IOException {
@@ -627,10 +626,9 @@ public final class PathMatchingResourcePatternResolver{
String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/");
if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) {
if (!content.canRead()) {
- logger.finest(() -> "Skipping subdirectory [" + dir.getAbsolutePath() +
- "] because the application is not allowed to read the directory");
- }
- else {
+ logger.finest(() -> "Skipping subdirectory [" + dir.getAbsolutePath() +
+ "] because the application is not allowed to read the directory");
+ } else {
doRetrieveMatchingFiles(fullPattern, content, result);
}
}
@@ -684,19 +682,15 @@ public final class PathMatchingResourcePatternResolver{
if (methodName.equals("equals")) {
// Only consider equal when proxies are identical.
return (proxy == args[0]);
- }
- else if (methodName.equals("hashCode")) {
+ } else if (methodName.equals("hashCode")) {
return System.identityHashCode(proxy);
}
- }
- else if ("getAttributes".equals(methodName)) {
+ } else if ("getAttributes".equals(methodName)) {
return getAttributes();
- }
- else if ("visit".equals(methodName)) {
+ } else if ("visit".equals(methodName)) {
visit(args[0]);
return null;
- }
- else if ("toString".equals(methodName)) {
+ } else if ("toString".equals(methodName)) {
return toString();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java
index 391f7e8..a638238 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java
@@ -25,168 +25,177 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
/**
-* Simple utility class for working with the reflection API and handling
-* reflection exceptions.
-*
-* <p>Only intended for internal use.
-*
-* @author Juergen Hoeller
-* @author Rob Harrop
-* @author Rod Johnson
-* @author Costin Leau
-* @author Sam Brannen
-* @author Chris Beams
-* @since 1.2.2
-*/
+ * Simple utility class for working with the reflection API and handling
+ * reflection exceptions.
+ * <p>
+ * <p>Only intended for internal use.
+ *
+ * @author Juergen Hoeller
+ * @author Rob Harrop
+ * @author Rod Johnson
+ * @author Costin Leau
+ * @author Sam Brannen
+ * @author Chris Beams
+ * @since 1.2.2
+ */
public abstract class ReflectionUtils {
- /**
- * Cache for {@link Class#getDeclaredMethods()}, allowing for fast resolution.
- */
- private static final Map<Class<?>, Method[]> declaredMethodsCache =
- new ConcurrentHashMap<>(256);
+ /**
+ * Cache for {@link Class#getDeclaredMethods()}, allowing for fast resolution.
+ */
+ private static final Map<Class<?>, Method[]> DECLARED_METHODS_CACHE =
+ new ConcurrentHashMap<>(256);
- /**
- * Attempt to find a {@link Field field} on the supplied {@link Class} with the
- * supplied {@code name}. Searches all superclasses up to {@link Object}.
- * @param clazz the class to introspect
- * @param name the name current the field
- * @return the corresponding Field object, or {@code null} if not found
- */
- public static Field findField(Class<?> clazz, String name) {
- return findField(clazz, name, null);
- }
+ /**
+ * Attempt to find a {@link Field field} on the supplied {@link Class} with the
+ * supplied {@code name}. Searches all superclasses up to {@link Object}.
+ *
+ * @param clazz the class to introspect
+ * @param name the name current the field
+ * @return the corresponding Field object, or {@code null} if not found
+ */
+ public static Field findField(Class<?> clazz, String name) {
+ return findField(clazz, name, null);
+ }
- /**
- * Attempt to find a {@link Field field} on the supplied {@link Class} with the
- * supplied {@code name} and/or {@link Class type}. Searches all superclasses
- * up to {@link Object}.
- * @param clazz the class to introspect
- * @param name the name current the field (may be {@code null} if type is specified)
- * @param type the type current the field (may be {@code null} if name is specified)
- * @return the corresponding Field object, or {@code null} if not found
- */
- public static Field findField(Class<?> clazz, String name, Class<?> type) {
- Objects.requireNonNull(clazz, "Class must not be null");
- if(name == null && type == null) throw new IllegalArgumentException("Either name or type current the field must be specified");
- Class<?> searchType = clazz;
- while (!Object.class.equals(searchType) && searchType != null) {
- Field[] fields = searchType.getDeclaredFields();
- for (Field field : fields) {
- if ((name == null || name.equals(field.getName())) && (type == null || type.equals(field.getType()))) {
- return field;
- }
- }
- searchType = searchType.getSuperclass();
- }
- return null;
- }
+ /**
+ * Attempt to find a {@link Field field} on the supplied {@link Class} with the
+ * supplied {@code name} and/or {@link Class type}. Searches all superclasses
+ * up to {@link Object}.
+ *
+ * @param clazz the class to introspect
+ * @param name the name current the field (may be {@code null} if type is specified)
+ * @param type the type current the field (may be {@code null} if name is specified)
+ * @return the corresponding Field object, or {@code null} if not found
+ */
+ public static Field findField(Class<?> clazz, String name, Class<?> type) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ if (name == null && type == null) {
+ throw new IllegalArgumentException("Either name or type current the field must be specified");
+ }
+ Class<?> searchType = clazz;
+ while (!Object.class.equals(searchType) && searchType != null) {
+ Field[] fields = searchType.getDeclaredFields();
+ for (Field field : fields) {
+ if ((name == null || name.equals(field.getName())) && (type == null || type.equals(field.getType()))) {
+ return field;
+ }
+ }
+ searchType = searchType.getSuperclass();
+ }
+ return null;
+ }
- /**
- * Attempt to find a {@link Method} on the supplied class with the supplied name
- * and no parameters. Searches all superclasses up to {@code Object}.
- * <p>Returns {@code null} if no {@link Method} can be found.
- * @param clazz the class to introspect
- * @param name the name current the method
- * @return the Method object, or {@code null} if none found
- */
- public static Method findMethod(Class<?> clazz, String name) {
- return findMethod(clazz, name, new Class<?>[0]);
- }
+ /**
+ * Attempt to find a {@link Method} on the supplied class with the supplied name
+ * and no parameters. Searches all superclasses up to {@code Object}.
+ * <p>Returns {@code null} if no {@link Method} can be found.
+ *
+ * @param clazz the class to introspect
+ * @param name the name current the method
+ * @return the Method object, or {@code null} if none found
+ */
+ public static Method findMethod(Class<?> clazz, String name) {
+ return findMethod(clazz, name, new Class<?>[0]);
+ }
- /**
- * Attempt to find a {@link Method} on the supplied class with the supplied name
- * and parameter types. Searches all superclasses up to {@code Object}.
- * <p>Returns {@code null} if no {@link Method} can be found.
- * @param clazz the class to introspect
- * @param name the name current the method
- * @param paramTypes the parameter types current the method
- * (may be {@code null} to indicate any signature)
- * @return the Method object, or {@code null} if none found
- */
- public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
- Objects.requireNonNull(clazz, "Class must not be null");
- Objects.requireNonNull(name, "Method name must not be null");
- Class<?> searchType = clazz;
- while (searchType != null) {
- Method[] methods = (searchType.isInterface() ? searchType.getMethods() : getDeclaredMethods(searchType));
- for (Method method : methods) {
- if (name.equals(method.getName()) &&
- (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) {
- return method;
- }
- }
- searchType = searchType.getSuperclass();
- }
- return null;
- }
+ /**
+ * Attempt to find a {@link Method} on the supplied class with the supplied name
+ * and parameter types. Searches all superclasses up to {@code Object}.
+ * <p>Returns {@code null} if no {@link Method} can be found.
+ *
+ * @param clazz the class to introspect
+ * @param name the name current the method
+ * @param paramTypes the parameter types current the method
+ * (may be {@code null} to indicate any signature)
+ * @return the Method object, or {@code null} if none found
+ */
+ public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(name, "Method name must not be null");
+ Class<?> searchType = clazz;
+ while (searchType != null) {
+ Method[] methods = (searchType.isInterface() ? searchType.getMethods() : getDeclaredMethods(searchType));
+ for (Method method : methods) {
+ if (name.equals(method.getName()) &&
+ (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) {
+ return method;
+ }
+ }
+ searchType = searchType.getSuperclass();
+ }
+ return null;
+ }
- /**
- * Handle the given reflection exception. Should only be called if no
- * checked exception is expected to be thrown by the target method.
- * <p>Throws the underlying RuntimeException or Error in case current an
- * InvocationTargetException with such a root cause. Throws an
- * IllegalStateException with an appropriate message else.
- * @param ex the reflection exception to handle
- */
- public static void handleReflectionException(Exception ex) {
- if (ex instanceof NoSuchMethodException) {
- throw new IllegalStateException("Method not found: " + ex.getMessage());
- }
- if (ex instanceof IllegalAccessException) {
- throw new IllegalStateException("Could not access method: " + ex.getMessage());
- }
- if (ex instanceof InvocationTargetException) {
- handleInvocationTargetException((InvocationTargetException) ex);
- }
- if (ex instanceof RuntimeException) {
- throw (RuntimeException) ex;
- }
- throw new UndeclaredThrowableException(ex);
- }
+ /**
+ * Handle the given reflection exception. Should only be called if no
+ * checked exception is expected to be thrown by the target method.
+ * <p>Throws the underlying RuntimeException or Error in case current an
+ * InvocationTargetException with such a root cause. Throws an
+ * IllegalStateException with an appropriate message else.
+ *
+ * @param ex the reflection exception to handle
+ */
+ public static void handleReflectionException(Exception ex) {
+ if (ex instanceof NoSuchMethodException) {
+ throw new IllegalStateException("Method not found: " + ex.getMessage());
+ }
+ if (ex instanceof IllegalAccessException) {
+ throw new IllegalStateException("Could not access method: " + ex.getMessage());
+ }
+ if (ex instanceof InvocationTargetException) {
+ handleInvocationTargetException((InvocationTargetException) ex);
+ }
+ if (ex instanceof RuntimeException) {
+ throw (RuntimeException) ex;
+ }
+ throw new UndeclaredThrowableException(ex);
+ }
- /**
- * Handle the given invocation target exception. Should only be called if no
- * checked exception is expected to be thrown by the target method.
- * <p>Throws the underlying RuntimeException or Error in case current such a root
- * cause. Throws an IllegalStateException else.
- * @param ex the invocation target exception to handle
- */
- public static void handleInvocationTargetException(InvocationTargetException ex) {
- rethrowRuntimeException(ex.getTargetException());
- }
+ /**
+ * Handle the given invocation target exception. Should only be called if no
+ * checked exception is expected to be thrown by the target method.
+ * <p>Throws the underlying RuntimeException or Error in case current such a root
+ * cause. Throws an IllegalStateException else.
+ *
+ * @param ex the invocation target exception to handle
+ */
+ public static void handleInvocationTargetException(InvocationTargetException ex) {
+ rethrowRuntimeException(ex.getTargetException());
+ }
- /**
- * Rethrow the given {@link Throwable exception}, which is presumably the
- * <em>target exception</em> current an {@link InvocationTargetException}. Should
- * only be called if no checked exception is expected to be thrown by the
- * target method.
- * <p>Rethrows the underlying exception cast to an {@link RuntimeException} or
- * {@link Error} if appropriate; otherwise, throws an
- * {@link IllegalStateException}.
- * @param ex the exception to rethrow
- * @throws RuntimeException the rethrown exception
- */
- public static void rethrowRuntimeException(Throwable ex) {
- if (ex instanceof RuntimeException) {
- throw (RuntimeException) ex;
- }
- if (ex instanceof Error) {
- throw (Error) ex;
- }
- throw new UndeclaredThrowableException(ex);
- }
+ /**
+ * Rethrow the given {@link Throwable exception}, which is presumably the
+ * <em>target exception</em> current an {@link InvocationTargetException}. Should
+ * only be called if no checked exception is expected to be thrown by the
+ * target method.
+ * <p>Rethrows the underlying exception cast to an {@link RuntimeException} or
+ * {@link Error} if appropriate; otherwise, throws an
+ * {@link IllegalStateException}.
+ *
+ * @param ex the exception to rethrow
+ * @throws RuntimeException the rethrown exception
+ */
+ public static void rethrowRuntimeException(Throwable ex) {
+ if (ex instanceof RuntimeException) {
+ throw (RuntimeException) ex;
+ }
+ if (ex instanceof Error) {
+ throw (Error) ex;
+ }
+ throw new UndeclaredThrowableException(ex);
+ }
- /**
- * This method retrieves {@link Class#getDeclaredMethods()} from a local cache
- * in order to avoid the JVM's SecurityManager check and defensive array copying.
- */
- private static Method[] getDeclaredMethods(Class<?> clazz) {
- Method[] result = declaredMethodsCache.get(clazz);
- if (result == null) {
- result = clazz.getDeclaredMethods();
- declaredMethodsCache.put(clazz, result);
- }
- return result;
- }
+ /**
+ * This method retrieves {@link Class#getDeclaredMethods()} from a local cache
+ * in order to avoid the JVM's SecurityManager check and defensive array copying.
+ */
+ private static Method[] getDeclaredMethods(Class<?> clazz) {
+ Method[] result = DECLARED_METHODS_CACHE.get(clazz);
+ if (result == null) {
+ result = clazz.getDeclaredMethods();
+ DECLARED_METHODS_CACHE.put(clazz, result);
+ }
+ return result;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java
index a9979f1..b79da71 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java
@@ -25,233 +25,264 @@ import java.net.URLConnection;
import java.util.Objects;
/**
-* Utility methods for resolving resource locations to files in the
-* file system. Mainly for internal use within the framework.
-*
-* <p>Consider using Spring's Resource abstraction in the core package
-* for handling all kinds current file resources in a uniform manner.
-* {@code org.springframework.core.io.ResourceLoader}'s {@code getResource()}
-* method can resolve any location to a {@code org.springframework.core.io.Resource}
-* object, which in turn allows one to obtain a {@code java.io.File} in the
-* file system through its {@code getFile()} method.
-*
-* <p>The main reason for these utility methods for resource location handling
-* is to support {@code Log4jConfigurer}, which must be able to resolve
-* resource locations <i>before the logging system has been initialized</i>.
-* Spring's {@code Resource} abstraction in the core package, on the other hand,
-* already expects the logging system to be available.
-*
-* @author Juergen Hoeller
-* @since 1.1.5
-*/
+ * Utility methods for resolving resource locations to files in the
+ * file system. Mainly for internal use within the framework.
+ * <p>
+ * <p>Consider using Spring's Resource abstraction in the core package
+ * for handling all kinds current file resources in a uniform manner.
+ * {@code org.springframework.core.io.ResourceLoader}'s {@code getResource()}
+ * method can resolve any location to a {@code org.springframework.core.io.Resource}
+ * object, which in turn allows one to obtain a {@code java.io.File} in the
+ * file system through its {@code getFile()} method.
+ * <p>
+ * <p>The main reason for these utility methods for resource location handling
+ * is to support {@code Log4jConfigurer}, which must be able to resolve
+ * resource locations <i>before the logging system has been initialized</i>.
+ * Spring's {@code Resource} abstraction in the core package, on the other hand,
+ * already expects the logging system to be available.
+ *
+ * @author Juergen Hoeller
+ * @since 1.1.5
+ */
final class ResourceUtils {
- /** URL prefix for loading from the file system: "file:" */
- public static final String FILE_URL_PREFIX = "file:";
+ /**
+ * URL prefix for loading from the file system: "file:"
+ */
+ public static final String FILE_URL_PREFIX = "file:";
- /** URL prefix for loading from the file system: "jar:" */
- public static final String JAR_URL_PREFIX = "jar:";
+ /**
+ * URL prefix for loading from the file system: "jar:"
+ */
+ public static final String JAR_URL_PREFIX = "jar:";
- /** URL protocol for a file in the file system: "file" */
- public static final String URL_PROTOCOL_FILE = "file";
+ /**
+ * URL protocol for a file in the file system: "file"
+ */
+ public static final String URL_PROTOCOL_FILE = "file";
- /** URL protocol for an entry from a jar file: "jar" */
- public static final String URL_PROTOCOL_JAR = "jar";
+ /**
+ * URL protocol for an entry from a jar file: "jar"
+ */
+ public static final String URL_PROTOCOL_JAR = "jar";
- /** URL protocol for an entry from a zip file: "zip" */
- public static final String URL_PROTOCOL_ZIP = "zip";
+ /**
+ * URL protocol for an entry from a zip file: "zip"
+ */
+ public static final String URL_PROTOCOL_ZIP = "zip";
- /** URL protocol for an entry from a WebSphere jar file: "wsjar" */
- public static final String URL_PROTOCOL_WSJAR = "wsjar";
+ /**
+ * URL protocol for an entry from a WebSphere jar file: "wsjar"
+ */
+ public static final String URL_PROTOCOL_WSJAR = "wsjar";
- /** URL protocol for an entry from a JBoss jar file: "vfszip" */
- public static final String URL_PROTOCOL_VFSZIP = "vfszip";
+ /**
+ * URL protocol for an entry from a JBoss jar file: "vfszip"
+ */
+ public static final String URL_PROTOCOL_VFSZIP = "vfszip";
- /** URL protocol for a JBoss file system resource: "vfsfile" */
- public static final String URL_PROTOCOL_VFSFILE = "vfsfile";
+ /**
+ * URL protocol for a JBoss file system resource: "vfsfile"
+ */
+ public static final String URL_PROTOCOL_VFSFILE = "vfsfile";
- /** URL protocol for a general JBoss VFS resource: "vfs" */
- public static final String URL_PROTOCOL_VFS = "vfs";
+ /**
+ * URL protocol for a general JBoss VFS resource: "vfs"
+ */
+ public static final String URL_PROTOCOL_VFS = "vfs";
- /** File extension for a regular jar file: ".jar" */
- public static final String JAR_FILE_EXTENSION = ".jar";
+ /**
+ * File extension for a regular jar file: ".jar"
+ */
+ public static final String JAR_FILE_EXTENSION = ".jar";
- /** Separator between JAR URL and file path within the JAR: "!/" */
- public static final String JAR_URL_SEPARATOR = "!/";
+ /**
+ * Separator between JAR URL and file path within the JAR: "!/"
+ */
+ public static final String JAR_URL_SEPARATOR = "!/";
/**
* Singleton constructor.
*/
- private ResourceUtils(){}
+ private ResourceUtils() {
+ }
- /**
- * Resolve the given resource URL to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUrl the resource URL to resolve
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- public static File getFile(URL resourceUrl) throws FileNotFoundException {
- return getFile(resourceUrl, "URL");
- }
+ /**
+ * Resolve the given resource URL to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ *
+ * @param resourceUrl the resource URL to resolve
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ public static File getFile(URL resourceUrl) throws FileNotFoundException {
+ return getFile(resourceUrl, "URL");
+ }
- /**
- * Resolve the given resource URL to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUrl the resource URL to resolve
- * @param description a description current the original resource that
- * the URL was created for (for example, a class path location)
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- public static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
- Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
- if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
- throw new FileNotFoundException(
- description + " cannot be resolved to absolute file path " +
- "because it does not reside in the file system: " + resourceUrl);
- }
- try {
- return new File(toURI(resourceUrl).getSchemeSpecificPart());
- }
- catch (URISyntaxException ex) {
- // Fallback for URLs that are not valid URIs (should hardly ever happen).
- return new File(resourceUrl.getFile());
- }
- }
+ /**
+ * Resolve the given resource URL to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ *
+ * @param resourceUrl the resource URL to resolve
+ * @param description a description current the original resource that
+ * the URL was created for (for example, a class path location)
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ public static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
+ Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
+ if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
+ throw new FileNotFoundException(
+ description + " cannot be resolved to absolute file path " +
+ "because it does not reside in the file system: " + resourceUrl);
+ }
+ try {
+ return new File(toURI(resourceUrl).getSchemeSpecificPart());
+ } catch (URISyntaxException ex) {
+ // Fallback for URLs that are not valid URIs (should hardly ever happen).
+ return new File(resourceUrl.getFile());
+ }
+ }
- /**
- * Resolve the given resource URI to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUri the resource URI to resolve
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- public static File getFile(URI resourceUri) throws FileNotFoundException {
- return getFile(resourceUri, "URI");
- }
+ /**
+ * Resolve the given resource URI to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ *
+ * @param resourceUri the resource URI to resolve
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ public static File getFile(URI resourceUri) throws FileNotFoundException {
+ return getFile(resourceUri, "URI");
+ }
- /**
- * Resolve the given resource URI to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUri the resource URI to resolve
- * @param description a description current the original resource that
- * the URI was created for (for example, a class path location)
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
- Objects.requireNonNull(resourceUri, "Resource URI must not be null");
- if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) {
- throw new FileNotFoundException(
- description + " cannot be resolved to absolute file path " +
- "because it does not reside in the file system: " + resourceUri);
- }
- return new File(resourceUri.getSchemeSpecificPart());
- }
+ /**
+ * Resolve the given resource URI to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ *
+ * @param resourceUri the resource URI to resolve
+ * @param description a description current the original resource that
+ * the URI was created for (for example, a class path location)
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
+ Objects.requireNonNull(resourceUri, "Resource URI must not be null");
+ if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) {
+ throw new FileNotFoundException(
+ description + " cannot be resolved to absolute file path " +
+ "because it does not reside in the file system: " + resourceUri);
+ }
+ return new File(resourceUri.getSchemeSpecificPart());
+ }
- /**
- * Determine whether the given URL points to a resource in the file system,
- * that is, has protocol "file", "vfsfile" or "vfs".
- * @param url the URL to check
- * @return whether the URL has been identified as a file system URL
- */
- public static boolean isFileURL(URL url) {
- String protocol = url.getProtocol();
- return (URL_PROTOCOL_FILE.equals(protocol) || URL_PROTOCOL_VFSFILE.equals(protocol) ||
- URL_PROTOCOL_VFS.equals(protocol));
- }
+ /**
+ * Determine whether the given URL points to a resource in the file system,
+ * that is, has protocol "file", "vfsfile" or "vfs".
+ *
+ * @param url the URL to check
+ * @return whether the URL has been identified as a file system URL
+ */
+ public static boolean isFileURL(URL url) {
+ String protocol = url.getProtocol();
+ return (URL_PROTOCOL_FILE.equals(protocol) || URL_PROTOCOL_VFSFILE.equals(protocol) ||
+ URL_PROTOCOL_VFS.equals(protocol));
+ }
- /**
- * Determine whether the given URL points to a resource in a jar file,
- * that is, has protocol "jar", "zip", "vfszip" or "wsjar".
- * @param url the URL to check
- * @return whether the URL has been identified as a JAR URL
- */
- public static boolean isJarURL(URL url) {
- String protocol = url.getProtocol();
- return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) ||
- URL_PROTOCOL_VFSZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol));
- }
+ /**
+ * Determine whether the given URL points to a resource in a jar file,
+ * that is, has protocol "jar", "zip", "vfszip" or "wsjar".
+ *
+ * @param url the URL to check
+ * @return whether the URL has been identified as a JAR URL
+ */
+ public static boolean isJarURL(URL url) {
+ String protocol = url.getProtocol();
+ return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) ||
+ URL_PROTOCOL_VFSZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol));
+ }
- /**
- * Determine whether the given URL points to a jar file itself,
- * that is, has protocol "file" and ends with the ".jar" extension.
- * @param url the URL to check
- * @return whether the URL has been identified as a JAR file URL
- * @since 4.1
- */
- public static boolean isJarFileURL(URL url) {
- return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
- url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
- }
+ /**
+ * Determine whether the given URL points to a jar file itself,
+ * that is, has protocol "file" and ends with the ".jar" extension.
+ *
+ * @param url the URL to check
+ * @return whether the URL has been identified as a JAR file URL
+ * @since 4.1
+ */
+ public static boolean isJarFileURL(URL url) {
+ return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
+ url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
+ }
- /**
- * Extract the URL for the actual jar file from the given URL
- * (which may point to a resource in a jar file or to a jar file itself).
- * @param jarUrl the original URL
- * @return the URL for the actual jar file
- * @throws MalformedURLException if no valid jar file URL could be extracted
- */
- public static URL extractJarFileURL(URL jarUrl) throws MalformedURLException {
- String urlFile = jarUrl.getFile();
- int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR);
- if (separatorIndex != -1) {
- String jarFile = urlFile.substring(0, separatorIndex);
- try {
- return new URL(jarFile);
- }
- catch (MalformedURLException ex) {
- // Probably no protocol in original jar URL, like "jar:C:/mypath/myjar.jar".
- // This usually indicates that the jar file resides in the file system.
- if (!jarFile.startsWith("/")) {
- jarFile = "/" + jarFile;
- }
- return new URL(FILE_URL_PREFIX + jarFile);
- }
- }
- else {
- return jarUrl;
- }
- }
+ /**
+ * Extract the URL for the actual jar file from the given URL
+ * (which may point to a resource in a jar file or to a jar file itself).
+ *
+ * @param jarUrl the original URL
+ * @return the URL for the actual jar file
+ * @throws MalformedURLException if no valid jar file URL could be extracted
+ */
+ public static URL extractJarFileURL(URL jarUrl) throws MalformedURLException {
+ String urlFile = jarUrl.getFile();
+ int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR);
+ if (separatorIndex != -1) {
+ String jarFile = urlFile.substring(0, separatorIndex);
+ try {
+ return new URL(jarFile);
+ } catch (MalformedURLException ex) {
+ // Probably no protocol in original jar URL, like "jar:C:/mypath/myjar.jar".
+ // This usually indicates that the jar file resides in the file system.
+ if (!jarFile.startsWith("/")) {
+ jarFile = "/" + jarFile;
+ }
+ return new URL(FILE_URL_PREFIX + jarFile);
+ }
+ } else {
+ return jarUrl;
+ }
+ }
- /**
- * Create a URI instance for the given URL,
- * replacing spaces with "%20" URI encoding first.
- * <p>Furthermore, this method works on JDK 1.4 as well,
- * in contrast to the {@code URL.toURI()} method.
- * @param url the URL to convert into a URI instance
- * @return the URI instance
- * @throws URISyntaxException if the URL wasn't a valid URI
- * @see java.net.URL#toURI()
- */
- public static URI toURI(URL url) throws URISyntaxException {
- return toURI(url.toString());
- }
+ /**
+ * Create a URI instance for the given URL,
+ * replacing spaces with "%20" URI encoding first.
+ * <p>Furthermore, this method works on JDK 1.4 as well,
+ * in contrast to the {@code URL.toURI()} method.
+ *
+ * @param url the URL to convert into a URI instance
+ * @return the URI instance
+ * @throws URISyntaxException if the URL wasn't a valid URI
+ * @see java.net.URL#toURI()
+ */
+ public static URI toURI(URL url) throws URISyntaxException {
+ return toURI(url.toString());
+ }
- /**
- * Create a URI instance for the given location String,
- * replacing spaces with "%20" URI encoding first.
- * @param location the location String to convert into a URI instance
- * @return the URI instance
- * @throws URISyntaxException if the location wasn't a valid URI
- */
- public static URI toURI(String location) throws URISyntaxException {
- return new URI(location.replaceAll(" ", "%20"));
- }
+ /**
+ * Create a URI instance for the given location String,
+ * replacing spaces with "%20" URI encoding first.
+ *
+ * @param location the location String to convert into a URI instance
+ * @return the URI instance
+ * @throws URISyntaxException if the location wasn't a valid URI
+ */
+ public static URI toURI(String location) throws URISyntaxException {
+ return new URI(location.replaceAll(" ", "%20"));
+ }
- /**
- * Set the {@link URLConnection#setUseCaches "useCaches"} flag on the
- * given connection, preferring {@code false} but leaving the
- * flag at {@code true} for JNLP based resources.
- * @param con the URLConnection to set the flag on
- */
- public static void useCachesIfNecessary(URLConnection con) {
- con.setUseCaches(con.getClass().getSimpleName().startsWith("JNLP"));
- }
+ /**
+ * Set the {@link URLConnection#setUseCaches "useCaches"} flag on the
+ * given connection, preferring {@code false} but leaving the
+ * flag at {@code true} for JNLP based resources.
+ *
+ * @param con the URLConnection to set the flag on
+ */
+ public static void useCachesIfNecessary(URLConnection con) {
+ con.setUseCaches(con.getClass().getSimpleName().startsWith("JNLP"));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java
index 6011109..4576aac 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java
@@ -35,8 +35,8 @@ import java.util.Objects;
* the "file:" protocol.
*
* @author Juergen Hoeller
- * @since 28.12.2003
* @see java.net.URL
+ * @since 28.12.2003
*/
public class UrlResource extends AbstractFileResolvingResource {
@@ -58,6 +58,7 @@ public class UrlResource extends AbstractFileResolvingResource {
/**
* Create a new UrlResource based on the given URI object.
+ *
* @param uri a URI
* @throws MalformedURLException if the given URL path is not valid
*/
@@ -70,6 +71,7 @@ public class UrlResource extends AbstractFileResolvingResource {
/**
* Create a new UrlResource based on the given URL object.
+ *
* @param url a URL
*/
public UrlResource(URL url) {
@@ -82,6 +84,7 @@ public class UrlResource extends AbstractFileResolvingResource {
/**
* Create a new UrlResource based on a URL path.
* <p>Note: The given path needs to be pre-encoded if necessary.
+ *
* @param path a URL path
* @throws MalformedURLException if the given URL path is not valid
* @see java.net.URL#URL(String)
@@ -96,36 +99,37 @@ public class UrlResource extends AbstractFileResolvingResource {
/**
* Create a new UrlResource based on a URI specification.
* <p>The given parts will automatically get encoded if necessary.
+ *
* @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon);
- * also known as "scheme"
+ * also known as "scheme"
* @param location the location (e.g. the file path within that protocol);
- * also known as "scheme-specific part"
+ * also known as "scheme-specific part"
* @throws MalformedURLException if the given URL specification is not valid
* @see java.net.URI#URI(String, String, String)
*/
- public UrlResource(String protocol, String location) throws MalformedURLException {
+ public UrlResource(String protocol, String location) throws MalformedURLException {
this(protocol, location, null);
}
/**
* Create a new UrlResource based on a URI specification.
* <p>The given parts will automatically get encoded if necessary.
+ *
* @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon);
- * also known as "scheme"
+ * also known as "scheme"
* @param location the location (e.g. the file path within that protocol);
- * also known as "scheme-specific part"
+ * also known as "scheme-specific part"
* @param fragment the fragment within that location (e.g. anchor on an HTML page,
- * as following after a "#" separator)
+ * as following after a "#" separator)
* @throws MalformedURLException if the given URL specification is not valid
* @see java.net.URI#URI(String, String, String)
*/
- public UrlResource(String protocol, String location, String fragment) throws MalformedURLException {
+ public UrlResource(String protocol, String location, String fragment) throws MalformedURLException {
try {
this.uri = new URI(protocol, location, fragment);
this.url = this.uri.toURL();
this.cleanedUrl = getCleanedUrl(this.url, this.uri.toString());
- }
- catch (URISyntaxException ex) {
+ } catch (URISyntaxException ex) {
MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
exToThrow.initCause(ex);
throw exToThrow;
@@ -134,15 +138,15 @@ public class UrlResource extends AbstractFileResolvingResource {
/**
* Determine a cleaned URL for the given original URL.
- * @param originalUrl the original URL
+ *
+ * @param originalUrl the original URL
* @param originalPath the original URL path
* @return the cleaned URL
*/
private URL getCleanedUrl(URL originalUrl, String originalPath) {
try {
return new URL(StringUtils.cleanPath(originalPath));
- }
- catch (MalformedURLException ex) {
+ } catch (MalformedURLException ex) {
// Cleaned URL path cannot be converted to URL
// -> take original URL.
return originalUrl;
@@ -154,19 +158,19 @@ public class UrlResource extends AbstractFileResolvingResource {
* This implementation opens an InputStream for the given URL.
* It sets the "UseCaches" flag to {@code false},
* mainly to avoid jar file locking on Windows.
+ *
* @see java.net.URL#openConnection()
* @see java.net.URLConnection#setUseCaches(boolean)
* @see java.net.URLConnection#getInputStream()
*/
@Override
- public InputStream getInputStream()throws IOException {
+ public InputStream getInputStream() throws IOException {
URLConnection con = null;
try {
con = this.url.openConnection();
useCachesIfNecessary(con);
return con.getInputStream();
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
// Close the HTTP connection (if applicable).
if (con instanceof HttpURLConnection) {
((HttpURLConnection) con).disconnect();
@@ -191,8 +195,7 @@ public class UrlResource extends AbstractFileResolvingResource {
public URI getURI() throws IOException {
if (this.uri != null) {
return this.uri;
- }
- else {
+ } else {
return super.getURI();
}
}
@@ -205,8 +208,7 @@ public class UrlResource extends AbstractFileResolvingResource {
public File toFile() throws IOException {
if (this.uri != null) {
return super.getFile(this.uri);
- }
- else {
+ } else {
return super.toFile();
}
}
@@ -214,6 +216,7 @@ public class UrlResource extends AbstractFileResolvingResource {
/**
* This implementation creates a UrlResource, applying the given path
* relative to the path current the underlying URL current this resource descriptor.
+ *
* @see java.net.URL#URL(java.net.URL, String)
*/
@Override
@@ -226,6 +229,7 @@ public class UrlResource extends AbstractFileResolvingResource {
/**
* This implementation returns the name current the file that this URL refers to.
+ *
* @see java.net.URL#getFile()
* @see java.io.File#getName()
*/
@@ -260,15 +264,16 @@ public class UrlResource extends AbstractFileResolvingResource {
return this.cleanedUrl.hashCode();
}
- /**
- * Set the {@link URLConnection#setUseCaches "useCaches"} flag on the
- * given connection, preferring {@code false} but leaving the
- * flag at {@code true} for JNLP based resources.
- * @param con the URLConnection to set the flag on
- */
- private void useCachesIfNecessary(URLConnection con) {
- con.setUseCaches(con.getClass().getSimpleName().startsWith("JNLP"));
- }
+ /**
+ * Set the {@link URLConnection#setUseCaches "useCaches"} flag on the
+ * given connection, preferring {@code false} but leaving the
+ * flag at {@code true} for JNLP based resources.
+ *
+ * @param con the URLConnection to set the flag on
+ */
+ private void useCachesIfNecessary(URLConnection con) {
+ con.setUseCaches(con.getClass().getSimpleName().startsWith("JNLP"));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java
index b39a907..7688a6f 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java
@@ -26,7 +26,7 @@ import java.util.Objects;
/**
* JBoss VFS based {@link Resource} implementation.
- *
+ * <p>
* <p>As current Spring 4.0, this class supports VFS 3.x on JBoss AS 6+ (package
* {@code org.jboss.vfs}) and is in particular compatible with JBoss AS 7 and
* WildFly 8.
@@ -38,97 +38,94 @@ import java.util.Objects;
*/
public class VfsResource implements Resource {
- private final Object resource;
+ private final Object resource;
- public VfsResource(Object resource) {
- Objects.requireNonNull(resource, "VirtualFile must not be null");
- this.resource = resource;
- }
+ public VfsResource(Object resource) {
+ Objects.requireNonNull(resource, "VirtualFile must not be null");
+ this.resource = resource;
+ }
- @Override
- public InputStream getInputStream()throws IOException {
+ @Override
+ public InputStream getInputStream() throws IOException {
return VfsUtils.getInputStream(this.resource);
}
- @Override
- public boolean exists() {
- return VfsUtils.exists(this.resource);
- }
-
- @Override
- public boolean isReadable() {
- return VfsUtils.isReadable(this.resource);
- }
-
- @Override
- public URL toURL() throws IOException {
- try {
- return VfsUtils.getURL(this.resource);
- }
- catch (Exception ex) {
- throw new IllegalStateException("Failed to obtain URL for file " + this.resource, ex);
- }
- }
-
- @Override
- public URI getURI() throws IOException {
- try {
- return VfsUtils.getURI(this.resource);
- }
- catch (Exception ex) {
- throw new IllegalStateException("Failed to obtain URI for " + this.resource, ex);
- }
- }
-
- @Override
- public File toFile() throws IOException {
- return VfsUtils.getFile(this.resource);
- }
-
- @Override
- public long contentLength() throws IOException {
- return VfsUtils.getSize(this.resource);
- }
-
- @Override
- public long lastModified() throws IOException {
- return VfsUtils.getLastModified(this.resource);
- }
-
- @Override
- public Resource createRelative(String relativePath) throws IOException {
- if (!relativePath.startsWith(".") && relativePath.contains("/")) {
- try {
- return new VfsResource(VfsUtils.getChild(this.resource, relativePath));
- }
- catch (IOException ex) {
- // fall back to getRelative
- }
- }
-
- return new VfsResource(VfsUtils.getRelative(new URL(toURL(), relativePath)));
- }
-
- @Override
- public String getDisplayName() {
- return VfsUtils.getName(this.resource);
- }
-
- @Override
- public String toString() {
- return this.resource.toString();
- }
-
- @Override
- public boolean equals(Object obj) {
- return (obj == this || (obj instanceof VfsResource && this.resource.equals(((VfsResource) obj).resource)));
- }
-
- @Override
- public int hashCode() {
- return this.resource.hashCode();
- }
+ @Override
+ public boolean exists() {
+ return VfsUtils.exists(this.resource);
+ }
+
+ @Override
+ public boolean isReadable() {
+ return VfsUtils.isReadable(this.resource);
+ }
+
+ @Override
+ public URL toURL() throws IOException {
+ try {
+ return VfsUtils.getURL(this.resource);
+ } catch (Exception ex) {
+ throw new IllegalStateException("Failed to obtain URL for file " + this.resource, ex);
+ }
+ }
+
+ @Override
+ public URI getURI() throws IOException {
+ try {
+ return VfsUtils.getURI(this.resource);
+ } catch (Exception ex) {
+ throw new IllegalStateException("Failed to obtain URI for " + this.resource, ex);
+ }
+ }
+
+ @Override
+ public File toFile() throws IOException {
+ return VfsUtils.getFile(this.resource);
+ }
+
+ @Override
+ public long contentLength() throws IOException {
+ return VfsUtils.getSize(this.resource);
+ }
+
+ @Override
+ public long lastModified() throws IOException {
+ return VfsUtils.getLastModified(this.resource);
+ }
+
+ @Override
+ public Resource createRelative(String relativePath) throws IOException {
+ if (!relativePath.startsWith(".") && relativePath.contains("/")) {
+ try {
+ return new VfsResource(VfsUtils.getChild(this.resource, relativePath));
+ } catch (IOException ex) {
+ // fall back to getRelative
+ }
+ }
+
+ return new VfsResource(VfsUtils.getRelative(new URL(toURL(), relativePath)));
+ }
+
+ @Override
+ public String getDisplayName() {
+ return VfsUtils.getName(this.resource);
+ }
+
+ @Override
+ public String toString() {
+ return this.resource.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return (obj == this || (obj instanceof VfsResource && this.resource.equals(((VfsResource) obj).resource)));
+ }
+
+ @Override
+ public int hashCode() {
+ return this.resource.hashCode();
+ }
}
[18/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
TAMAYA-19: Reorganized dormant part for better focus of future discussions.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b56817f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b56817f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b56817f7
Branch: refs/heads/master
Commit: b56817f7a2754d93aa143c848597e7280484a23f
Parents: 5f58e71
Author: anatole <an...@apache.org>
Authored: Sat Jan 3 09:43:40 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 3 09:43:43 2015 +0100
----------------------------------------------------------------------
.../core/internal/PropertyConverterManager.java | 240 ++++
.../logging/AbstractDelegatingLogger.java | 411 ++++++
.../core/internal/logging/Log4j2Logger.java | 97 ++
.../core/internal/logging/Log4jLogger.java | 200 +++
.../core/internal/logging/Slf4jLogger.java | 181 +++
.../resource/AbstractFileResolvingResource.java | 230 ++++
.../core/internal/resource/AntPathMatcher.java | 779 +++++++++++
.../internal/resource/ClassPathResource.java | 254 ++++
.../internal/resource/FileSystemResource.java | 220 ++++
.../internal/resource/InputStreamResource.java | 122 ++
.../PathMatchingDefaultResourceLoader.java | 139 ++
.../PathMatchingResourcePatternResolver.java | 731 +++++++++++
.../core/internal/resource/ReflectionUtils.java | 192 +++
.../core/internal/resource/ResourceUtils.java | 257 ++++
.../core/internal/resource/UrlResource.java | 274 ++++
.../core/internal/resource/VfsResource.java | 134 ++
.../tamaya/core/internal/resource/VfsUtils.java | 209 +++
.../core/resources/InputStreamSource.java | 46 +
.../apache/tamaya/core/resources/Resource.java | 186 +++
.../tamaya/core/resources/ResourceLoader.java | 87 ++
.../org/apache/tamaya/core/util/ClassUtils.java | 1074 +++++++++++++++
.../apache/tamaya/core/util/StringUtils.java | 463 +++++++
.../testdata/TestPropertySourceProvider.java | 32 +
dormant/api/PropertyMapSupplier.java | 37 +
.../java/org/apache/tamaya/ConfigQuery.java | 37 -
.../java/org/apache/tamaya/ConfiguredValue.java | 256 ----
.../java/org/apache/tamaya/DynamicValue.java | 500 -------
.../org/apache/tamaya/PropertyMapSupplier.java | 37 -
.../tamaya/annotation/ConfiguredProperties.java | 41 -
.../tamaya/annotation/ConfiguredProperty.java | 87 --
.../apache/tamaya/annotation/DefaultAreas.java | 43 -
.../apache/tamaya/annotation/DefaultValue.java | 41 -
.../apache/tamaya/annotation/LoadPolicy.java | 48 -
.../org/apache/tamaya/annotation/NoConfig.java | 32 -
.../tamaya/annotation/ObservesConfigChange.java | 38 -
.../tamaya/annotation/WithConfigOperator.java | 45 -
.../tamaya/annotation/WithLoadPolicy.java | 40 -
.../tamaya/annotation/WithPropertyAdapter.java | 45 -
.../tamaya/spi/ConfigurationFactorySpi.java | 60 -
.../org/apache/tamaya/spi/ConfigurationSpi.java | 98 --
.../apache/tamaya/spi/PropertyAdapterSpi.java | 72 -
.../test/java/annottext/AnnotatedConfig.java | 51 -
.../java/annottext/AnnotatedFullConfig.java | 52 -
.../tamaya/TestConfigServiceSingletonSpi.java | 90 --
.../TestPropertyAdaptersSingletonSpi.java | 99 --
.../api/src/test/resources/META-INF/beans.xml | 25 -
.../org.apache.tamaya.spi.ConfigurationSpi | 19 -
.../org.apache.tamaya.spi.PropertyAdapterSpi | 19 -
.../AbstractClasspathAwarePropertySource.java | 82 ++
.../main/java/old/AbstractPropertySource.java | 60 +
.../main/java/old/AggregatedPropertySource.java | 98 ++
.../src/main/java/old/AggregationPolicy.java | 133 ++
.../main/java/old/BuildablePropertySource.java | 60 +
.../src/main/java/old/ConfigurationBuilder.java | 375 ++++++
.../main/java/old/ConfigurationProviderSpi.java | 46 +
.../main/java/old/ContextualPropertySource.java | 142 ++
.../main/java/old/DefaultConfigurationSpi.java | 116 ++
.../main/java/old/DefaultServiceComparator.java | 85 ++
.../java/old/DefaultServiceContextProvider.java | 112 ++
.../main/java/old/DelegatingPropertySource.java | 80 ++
.../java/old/EnvPropertiesConfigProvider.java | 54 +
.../src/main/java/old/MappedConfiguration.java | 57 +
dormant/core/src/main/java/old/Orderable.java | 34 +
.../core/src/main/java/old/OrdinalProvider.java | 37 +
.../java/old/PropertyAdapterProviderSpi.java | 36 +
.../src/main/java/old/PropertyChangeSet.java | 169 +++
.../main/java/old/PropertyChangeSetBuilder.java | 347 +++++
.../java/old/SubtractingPropertySource.java | 56 +
.../old/SystemPropertiesConfigProvider.java | 54 +
.../core/config/AbstractConfiguration.java | 2 +-
.../tamaya/core/config/ConfigFunctions.java | 1 +
.../core/config/ConfigurationBuilder.java | 374 ------
.../tamaya/core/config/ConfigurationFormat.java | 111 --
.../core/config/FreezedConfiguration.java | 81 --
.../tamaya/core/config/FrozenConfiguration.java | 81 ++
.../tamaya/core/config/MappedConfiguration.java | 56 -
.../apache/tamaya/core/internal/MetaConfig.java | 20 +-
.../config/DefaultConfigurationSpi.java | 116 --
.../config/DefaultPropertyAdapterSpi.java | 168 ---
.../config/EnvPropertiesConfigProvider.java | 54 -
.../config/FallbackSimpleConfigProvider.java | 11 +-
.../internal/config/FileChangeListener.java | 2 +-
.../config/FilesPropertiesConfigProvider.java | 2 +-
.../config/SystemPropertiesConfigProvider.java | 54 -
.../internal/el/DefaultExpressionEvaluator.java | 144 --
.../el/EnvironmentPropertyResolver.java | 44 -
.../internal/el/SystemPropertyResolver.java | 44 -
.../format/DefaultConfigurationFormatSpi.java | 40 -
.../inject/ConfigChangeCallbackMethod.java | 67 -
.../inject/ConfigTemplateInvocationHandler.java | 76 --
.../internal/inject/ConfigurationInjector.java | 61 -
.../core/internal/inject/ConfiguredField.java | 126 --
.../internal/inject/ConfiguredSetterMethod.java | 136 --
.../core/internal/inject/ConfiguredType.java | 222 ----
.../core/internal/inject/InjectionUtils.java | 221 ----
.../inject/WeakConfigListenerManager.java | 117 --
.../logging/AbstractDelegatingLogger.java | 411 ------
.../core/internal/logging/Log4j2Logger.java | 97 --
.../core/internal/logging/Log4jLogger.java | 200 ---
.../core/internal/logging/Slf4jLogger.java | 181 ---
.../io/AbstractFileResolvingResource.java | 221 ----
.../internal/resources/io/AbstractResource.java | 217 ---
.../internal/resources/io/AntPathMatcher.java | 777 -----------
.../resources/io/ClassPathResource.java | 252 ----
.../core/internal/resources/io/ClassUtils.java | 1232 ------------------
.../resources/io/DefaultResourceLoader.java | 138 --
.../resources/io/FileSystemResource.java | 220 ----
.../resources/io/InputStreamResource.java | 121 --
.../io/PathMatchingResourcePatternResolver.java | 729 -----------
.../internal/resources/io/ReflectionUtils.java | 191 ---
.../internal/resources/io/ResourceUtils.java | 350 -----
.../core/internal/resources/io/StringUtils.java | 1165 -----------------
.../core/internal/resources/io/UrlResource.java | 263 ----
.../core/internal/resources/io/VfsResource.java | 134 --
.../core/internal/resources/io/VfsUtils.java | 209 ---
.../internal/resources/io/WritableResource.java | 54 -
.../AbstractClasspathAwarePropertySource.java | 82 --
.../core/properties/AbstractPropertySource.java | 96 --
.../properties/AggregatedPropertySource.java | 98 --
.../core/properties/AggregationPolicy.java | 133 --
.../properties/BuildablePropertySource.java | 60 -
.../core/properties/ConfigurationFormat.java | 111 --
.../properties/ContextualPropertySource.java | 142 --
.../properties/DelegatingPropertySource.java | 79 --
.../properties/EnvironmentPropertySource.java | 16 +-
.../properties/FileSystemPropertySource.java | 97 --
.../core/properties/FilteredPropertySource.java | 51 -
.../core/properties/FreezedPropertySource.java | 74 --
.../core/properties/FrozenPropertySource.java | 35 +-
.../properties/IntersectingPropertySource.java | 55 -
.../core/properties/MapBasedPropertySource.java | 72 +-
.../core/properties/MappedPropertySource.java | 53 -
.../properties/PathBasedPropertySource.java | 83 --
.../core/properties/PropertyChangeSet.java | 169 ---
.../properties/PropertyChangeSetBuilder.java | 347 -----
.../core/properties/PropertySourceBuilder.java | 477 -------
.../core/properties/PropertySourceFactory.java | 287 ----
.../properties/PropertySourceFunctions.java | 53 +
.../properties/ReplacingPropertySource.java | 75 --
.../properties/SubtractingPropertySource.java | 56 -
.../SystemPropertiesPropertySource.java | 25 +-
.../core/properties/URLBasedPropertySource.java | 81 --
.../properties/ValueFilteredPropertySource.java | 51 -
.../factories/PropertySourceFactory.java | 279 ++++
.../factories/PropertySourcesBuilder.java | 367 ++++++
.../ResourcePropertySourceProvider.java | 70 +
.../filtered/AggregatedPropertySource.java | 97 ++
.../filtered/FilteredPropertySource.java | 68 +
.../filtered/IntersectingPropertySource.java | 55 +
.../filtered/MappedPropertySource.java | 67 +
.../filtered/ValueFilteredPropertySource.java | 55 +
.../tamaya/core/resource/InputStreamSource.java | 55 -
.../apache/tamaya/core/resource/Resource.java | 124 --
.../tamaya/core/resource/ResourceLoader.java | 84 --
.../tamaya/core/spi/ConfigurationFormatSpi.java | 61 -
.../core/spi/ConfigurationProviderSpi.java | 46 -
.../core/spi/DefaultServiceComparator.java | 85 --
.../core/spi/DefaultServiceContextProvider.java | 112 --
.../tamaya/core/spi/ExpressionEvaluator.java | 38 -
.../tamaya/core/spi/ExpressionResolver.java | 55 -
.../org/apache/tamaya/core/spi/Orderable.java | 34 -
.../apache/tamaya/core/spi/OrdinalProvider.java | 37 -
.../core/spi/PropertyAdapterProviderSpi.java | 36 -
.../tamaya/core/spi/PropertyAdapterService.java | 64 -
.../services/old.ConfigurationProviderSpi | 20 +
.../org.apache.tamaya.core.ConfigurationFormat | 21 +
...e.tamaya.core.properties.ConfigurationFormat | 21 -
...g.apache.tamaya.core.resource.ResourceLoader | 20 -
....apache.tamaya.core.resources.ResourceLoader | 20 +
...che.tamaya.core.spi.ConfigurationProviderSpi | 20 -
.../org.apache.tamaya.spi.ConfigurationSpi | 2 +-
.../org.apache.tamaya.spi.PropertyAdapterSpi | 2 +-
...tionManagerSingletonSpiSingletonSpiTest.java | 6 +-
.../java/org/apache/tamaya/JavaOneDemo.java | 4 +-
.../tamaya/core/config/MutableConfigTest.java | 2 +-
.../FilesPropertiesConfigProviderTest.java | 2 +-
.../properties/PropertySourceBuilderTest.java | 4 +-
.../internal/MutableTestConfigProvider.java | 4 +-
.../tamaya/internal/TestConfigProvider.java | 6 +-
.../samples/annotations/ConfiguredClass.java | 8 +-
.../samples/devops/DeploymentProvider.java | 4 +-
.../simple/SimplePropertiesAndCLISample.java | 4 +-
.../apache/tamaya/ucs/UC1ReadProperties.java | 2 +-
.../apache/tamaya/ucs/UC2CombineProperties.java | 2 +-
.../services/old.ConfigurationProviderSpi | 19 +
...che.tamaya.core.spi.ConfigurationProviderSpi | 19 -
.../core/src/test/resources/cfg/autoloaded.xml | 2 +-
dormant/core/src/test/resources/cfg/test.xml | 2 +-
dormant/modules/integration/cdi/pom.xml | 178 ---
.../tamaya/integration/cdi/ConfiguredClass.java | 12 +-
.../integration/cdi/TestConfigProvider.java | 6 +-
dormant/modules/integration/managed/pom.xml | 71 -
.../management/ManagedEnvironmentMBean.java | 4 +-
dormant/modules/integration/pom.xml | 40 -
dormant/modules/metamodels/environment/pom.xml | 73 --
.../environment/EnvironmentManagerTest.java | 2 +-
dormant/modules/metamodels/pom.xml | 46 -
dormant/modules/metamodels/simple/pom.xml | 73 --
.../services/old.ConfigurationProviderSpi | 19 +
...che.tamaya.core.spi.ConfigurationProviderSpi | 19 -
dormant/modules/pom.xml | 60 -
modules/injection/pom.xml | 40 +
.../tamaya/inject/ConfiguredProperties.java | 41 +
.../tamaya/inject/ConfiguredProperty.java | 87 ++
.../org/apache/tamaya/inject/DefaultAreas.java | 43 +
.../org/apache/tamaya/inject/DefaultValue.java | 41 +
.../org/apache/tamaya/inject/DynamicValue.java | 500 +++++++
.../org/apache/tamaya/inject/LoadPolicy.java | 48 +
.../java/org/apache/tamaya/inject/NoConfig.java | 32 +
.../tamaya/inject/ObservesConfigChange.java | 38 +
.../tamaya/inject/WithConfigOperator.java | 45 +
.../apache/tamaya/inject/WithLoadPolicy.java | 40 +
.../tamaya/inject/WithPropertyAdapter.java | 45 +
.../internal/ConfigChangeCallbackMethod.java | 67 +
.../ConfigTemplateInvocationHandler.java | 76 ++
.../inject/internal/ConfigurationInjector.java | 61 +
.../tamaya/inject/internal/ConfiguredField.java | 126 ++
.../inject/internal/ConfiguredSetterMethod.java | 136 ++
.../tamaya/inject/internal/ConfiguredType.java | 222 ++++
.../tamaya/inject/internal/InjectionUtils.java | 221 ++++
.../internal/WeakConfigListenerManager.java | 117 ++
.../inject/spi/ConfigurationFactorySpi.java | 60 +
.../tamaya/inject/spi/ConfigurationSpi.java | 98 ++
.../tamaya/inject/spi/PropertyAdapterSpi.java | 72 +
.../test/java/annottext/AnnotatedConfig.java | 51 +
.../java/annottext/AnnotatedFullConfig.java | 52 +
.../tamaya/TestConfigServiceSingletonSpi.java | 90 ++
.../TestPropertyAdaptersSingletonSpi.java | 99 ++
.../src/test/resources/META-INF/beans.xml | 25 +
.../org.apache.tamaya.spi.ConfigurationSpi | 19 +
.../org.apache.tamaya.spi.PropertyAdapterSpi | 19 +
modules/integration/pom.xml | 39 +
modules/management/pom.xml | 41 +
modules/metamodels/environment/pom.xml | 34 +
modules/metamodels/pom.xml | 39 +
modules/metamodels/simple/pom.xml | 34 +
modules/pom.xml | 42 +
.../tamaya/resolver/ExpressionEvaluator.java | 38 +
.../internal/DefaultExpressionEvaluator.java | 144 ++
.../internal/EnvironmentPropertyResolver.java | 44 +
.../internal/SystemPropertyResolver.java | 44 +
.../tamaya/resolver/spi/ExpressionResolver.java | 53 +
242 files changed, 13435 insertions(+), 15690 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
new file mode 100644
index 0000000..a4d5ff6
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Currency;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.StampedLock;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyConverter;
+
+/**
+ * Manager that deals with {@link org.apache.tamaya.spi.PropertyConverter} instances.
+ */
+public class PropertyConverterManager {
+
+ private Map<Class<?>,List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
+ private StampedLock lock = new StampedLock();
+
+ /**
+ * Constructor.
+ */
+ public PropertyConverterManager(){
+ initDefaultConverters();
+ }
+
+ /**
+ * Registers the default converters provided out of the box.
+ */
+ protected void initDefaultConverters(){
+ // Add default converters
+ register(char.class, (s) -> s.charAt(0));
+ register(byte.class, Byte::parseByte);
+ register(short.class, Short::parseShort);
+ register(int.class, Integer::parseInt);
+ register(long.class, Long::parseLong);
+ register(boolean.class, Boolean::parseBoolean);
+ register(float.class, Float::parseFloat);
+ register(double.class, Double::parseDouble);
+
+ register(Character.class, (s) -> s.charAt(0));
+ register(Byte.class, Byte::valueOf);
+ register(Short.class, Short::valueOf);
+ register(Integer.class, Integer::valueOf);
+ register(Long.class, Long::valueOf);
+ register(Boolean.class, Boolean::valueOf);
+ register(Float.class, Float::valueOf);
+ register(Double.class, Double::valueOf);
+ register(BigDecimal.class, BigDecimal::new);
+ register(BigInteger.class, BigInteger::new);
+
+ register(Currency.class, Currency::getInstance);
+
+ register(LocalDate.class, LocalDate::parse);
+ register(LocalTime.class, LocalTime::parse);
+ register(LocalDateTime.class, LocalDateTime::parse);
+ register(ZoneId.class, ZoneId::of);
+ }
+
+ /**
+ * Registers a ew converter instance.
+ * @param targetType the target type, not null.
+ * @param converter the converter, not null.
+ * @param <T> the type.
+ */
+ public <T> void register(Class<T> targetType, PropertyConverter<T> converter){
+ Objects.requireNonNull(converter);
+ Lock writeLock = lock.asWriteLock();;
+ try{
+ writeLock.lock();
+ List<PropertyConverter<T>> converters = List.class.cast(this.converters.get(targetType));
+ List<PropertyConverter<T>> newConverters = new ArrayList<>();
+ if(converters != null){
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ this.converters.put(targetType, Collections.unmodifiableList(newConverters));
+ }
+ finally{
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Allows to evaluate if a given target type is supported.
+ * @param targetType the target type, not null.
+ * @return true, if a converter for the given type is registered, or a default one can be created.
+ */
+ public boolean isTargetTypeSupported(Class<?> targetType){
+ return converters.containsKey(targetType)
+ || createDefaultPropertyConverter(targetType)!=null;
+ }
+
+ /**
+ * Get a map of all property converters currently registered. This will not contain the converters that
+ * may be created, when an instance is adapted, which provides a String constructor or compatible
+ * factory methods taking a single String instance.
+ * @see #createDefaultPropertyConverter(Class)
+ * @return the current map of instantiated and registered converters.
+ */
+ public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters(){
+ Lock readLock = lock.asReadLock();
+ try{
+ readLock.lock();
+ return new HashMap<>(this.converters);
+ }
+ finally{
+ readLock.unlock();
+ }
+ }
+
+ /**
+ * Get the list of all current registered converters for the given target type.
+ * If not converters are registered, they component tries to create and register a dynamic
+ * converter based on String costructor or static factory methods available.
+ * @see #createDefaultPropertyConverter(Class)
+ * @param targetType the target type, not null.
+ * @param <T> the type class
+ * @return the ordered list of converters (may be empty for not convertible types).
+ */
+ public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType){
+ Lock readLock = lock.asReadLock();
+ List<PropertyConverter<T>> converters;
+ try{
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(targetType));
+ }
+ finally{
+ readLock.unlock();
+ }
+ if(converters!=null){
+ return converters;
+ }
+ PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
+ if(defaultConverter!=null){
+ register(targetType,defaultConverter);
+ try{
+ converters = List.class.cast(this.converters.get(targetType));
+ }
+ finally{
+ readLock.unlock();
+ }
+ }
+ if(converters!=null){
+ return converters;
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Creates a dynamic PropertyConverter for the given target type.
+ * @param targetType the target type
+ * @param <T> the type class
+ * @return a new converter, or null.
+ */
+ protected <T> PropertyConverter<T> createDefaultPropertyConverter(Class<T> targetType) {
+ PropertyConverter<T> converter = null;
+ Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "parse");
+ if(factoryMethod!=null){
+ converter = (s) -> {
+ try{
+ factoryMethod.setAccessible(true);
+ return targetType.cast(factoryMethod.invoke(s));
+ }
+ catch (Exception e){
+ throw new ConfigException("Failed to decode '"+s+"'", e);
+ }
+ };
+ }
+ if(converter==null) {
+ try {
+ Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
+ converter = (s) -> {
+ try{
+ constr.setAccessible(true);
+ return constr.newInstance(s);
+ }
+ catch (Exception e){
+ throw new ConfigException("Failed to decode '"+s+"'", e);
+ }
+ };
+ } catch (Exception e) {
+ //X ignore, TODO log finest
+ }
+ }
+ return converter;
+ }
+
+ /**
+ * Tries to evaluate a factory method that can be used to create an instance based on a String.
+ * @param type the target type
+ * @param methodNames the possible static method names
+ * @return the first method found, or null.
+ */
+ private Method getFactoryMethod(Class<?> type, String... methodNames) {
+ Method m;
+ for(String name:methodNames){
+ try{
+ m = type.getDeclaredMethod(name, String.class);
+ return m;
+ }
+ catch(Exception e){
+ //X ignore, TODO log finest
+ }
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
new file mode 100644
index 0000000..cc0ac45
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
@@ -0,0 +1,411 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.logging;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.logging.*;
+
+/**
+ * java.util.logging.Logger implementation delegating to another framework.
+ * All methods can be used except:
+ * setLevel
+ * addHandler / getHandlers
+ * setParent / getParent
+ * setUseParentHandlers / getUseParentHandlers
+ *
+ * @author gnodet
+ */
+public abstract class AbstractDelegatingLogger extends Logger {
+
+ protected AbstractDelegatingLogger(final String name, final String resourceBundleName) {
+ super(name, resourceBundleName);
+ }
+
+ public void log(final LogRecord record) {
+ if (isLoggable(record.getLevel())) {
+ doLog(record);
+ }
+ }
+
+ public void log(final Level level, final String msg) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ doLog(lr);
+ }
+ }
+
+ public void log(final Level level, final String msg, final Object param1) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ final Object[] params = {param1};
+ lr.setParameters(params);
+ doLog(lr);
+ }
+ }
+
+ public void log(final Level level, final String msg, final Object[] params) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setParameters(params);
+ doLog(lr);
+ }
+ }
+
+ public void log(final Level level, final String msg, final Throwable thrown) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setThrown(thrown);
+ doLog(lr);
+ }
+ }
+
+ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ doLog(lr);
+ }
+ }
+
+ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Object param1) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ final Object[] params = {param1};
+ lr.setParameters(params);
+ doLog(lr);
+ }
+ }
+
+ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Object[] params) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ lr.setParameters(params);
+ doLog(lr);
+ }
+ }
+
+ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Throwable thrown) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ lr.setThrown(thrown);
+ doLog(lr);
+ }
+ }
+
+ public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName, final String msg) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ doLog(lr, bundleName);
+ }
+ }
+
+ public void logrb(final Level level, final String sourceClass, final String sourceMethod,
+ final String bundleName, final String msg, final Object param1) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ final Object[] params = {param1};
+ lr.setParameters(params);
+ doLog(lr, bundleName);
+ }
+ }
+
+ public void logrb(final Level level, final String sourceClass, final String sourceMethod,
+ final String bundleName, final String msg, final Object[] params) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ lr.setParameters(params);
+ doLog(lr, bundleName);
+ }
+ }
+
+ public void logrb(final Level level, final String sourceClass, final String sourceMethod,
+ final String bundleName, final String msg, final Throwable thrown) {
+ if (isLoggable(level)) {
+ final LogRecord lr = new LogRecord(level, msg);
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ lr.setThrown(thrown);
+ doLog(lr, bundleName);
+ }
+ }
+
+ public void entering(final String sourceClass, final String sourceMethod) {
+ if (isLoggable(Level.FINER)) {
+ logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
+ }
+ }
+
+ public void entering(final String sourceClass, final String sourceMethod, final Object param1) {
+ if (isLoggable(Level.FINER)) {
+ final Object[] params = {param1};
+ logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
+ }
+ }
+
+ public void entering(final String sourceClass, final String sourceMethod, final Object[] params) {
+ if (isLoggable(Level.FINER)) {
+ final String msg = "ENTRY";
+ if (params == null) {
+ logp(Level.FINER, sourceClass, sourceMethod, msg);
+ return;
+ }
+ final StringBuilder builder = new StringBuilder(msg);
+ for (int i = 0; i < params.length; i++) {
+ builder.append(" {");
+ builder.append(Integer.toString(i));
+ builder.append("}");
+ }
+ logp(Level.FINER, sourceClass, sourceMethod, builder.toString(), params);
+ }
+ }
+
+ public void exiting(final String sourceClass, final String sourceMethod) {
+ if (isLoggable(Level.FINER)) {
+ logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
+ }
+ }
+
+ public void exiting(final String sourceClass, final String sourceMethod, final Object result) {
+ if (isLoggable(Level.FINER)) {
+ final Object[] params = {result};
+ logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", params);
+ }
+ }
+
+ public void throwing(final String sourceClass, final String sourceMethod, final Throwable thrown) {
+ if (isLoggable(Level.FINER)) {
+ final LogRecord lr = new LogRecord(Level.FINER, "THROW");
+ lr.setSourceClassName(sourceClass);
+ lr.setSourceMethodName(sourceMethod);
+ lr.setThrown(thrown);
+ doLog(lr);
+ }
+ }
+
+ public void severe(final String msg) {
+ if (isLoggable(Level.SEVERE)) {
+ final LogRecord lr = new LogRecord(Level.SEVERE, msg);
+ doLog(lr);
+ }
+ }
+
+ public void warning(final String msg) {
+ if (isLoggable(Level.WARNING)) {
+ final LogRecord lr = new LogRecord(Level.WARNING, msg);
+ doLog(lr);
+ }
+ }
+
+ public void info(final String msg) {
+ if (isLoggable(Level.INFO)) {
+ final LogRecord lr = new LogRecord(Level.INFO, msg);
+ doLog(lr);
+ }
+ }
+
+ public void config(final String msg) {
+ if (isLoggable(Level.CONFIG)) {
+ final LogRecord lr = new LogRecord(Level.CONFIG, msg);
+ doLog(lr);
+ }
+ }
+
+ public void fine(final String msg) {
+ if (isLoggable(Level.FINE)) {
+ final LogRecord lr = new LogRecord(Level.FINE, msg);
+ doLog(lr);
+ }
+ }
+
+ public void finer(final String msg) {
+ if (isLoggable(Level.FINER)) {
+ final LogRecord lr = new LogRecord(Level.FINER, msg);
+ doLog(lr);
+ }
+ }
+
+ public void finest(final String msg) {
+ if (isLoggable(Level.FINEST)) {
+ final LogRecord lr = new LogRecord(Level.FINEST, msg);
+ doLog(lr);
+ }
+ }
+
+ public void setLevel(final Level newLevel) throws SecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ public abstract Level getLevel();
+
+ public boolean isLoggable(final Level level) {
+ final Level l = getLevel();
+ return level.intValue() >= l.intValue() && l != Level.OFF;
+ }
+
+ protected boolean supportsHandlers() {
+ return false;
+ }
+
+ public synchronized void addHandler(final Handler handler) throws SecurityException {
+ if (supportsHandlers()) {
+ super.addHandler(handler);
+ return;
+ }
+ throw new UnsupportedOperationException();
+ }
+
+ public synchronized void removeHandler(final Handler handler) throws SecurityException {
+ if (supportsHandlers()) {
+ super.removeHandler(handler);
+ return;
+ }
+ throw new UnsupportedOperationException();
+ }
+
+ public synchronized Handler[] getHandlers() {
+ if (supportsHandlers()) {
+ return super.getHandlers();
+ }
+ throw new UnsupportedOperationException();
+ }
+
+ public synchronized void setUseParentHandlers(final boolean useParentHandlers) {
+ if (supportsHandlers()) {
+ super.setUseParentHandlers(useParentHandlers);
+ return;
+ }
+ throw new UnsupportedOperationException();
+ }
+
+ public synchronized boolean getUseParentHandlers() {
+ if (supportsHandlers()) {
+ return super.getUseParentHandlers();
+ }
+ throw new UnsupportedOperationException();
+ }
+
+ public Logger getParent() {
+ return null;
+ }
+
+ public void setParent(final Logger parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void doLog(final LogRecord lr) {
+ lr.setLoggerName(getName());
+ final String rbname = getResourceBundleName();
+ if (rbname != null) {
+ lr.setResourceBundleName(rbname);
+ lr.setResourceBundle(getResourceBundle());
+ }
+ internalLog(lr);
+ }
+
+ protected void doLog(final LogRecord lr, final String rbname) {
+ lr.setLoggerName(getName());
+ if (rbname != null) {
+ lr.setResourceBundleName(rbname);
+ lr.setResourceBundle(loadResourceBundle(rbname));
+ }
+ internalLog(lr);
+ }
+
+ protected void internalLog(final LogRecord record) {
+ final Filter filter = getFilter();
+ if (filter != null && !filter.isLoggable(record)) {
+ return;
+ }
+ final String msg = formatMessage(record);
+ internalLogFormatted(msg, record);
+ }
+
+ protected abstract void internalLogFormatted(String msg, LogRecord record);
+
+ protected String formatMessage(final LogRecord record) {
+ String format = record.getMessage();
+ final ResourceBundle catalog = record.getResourceBundle();
+ if (catalog != null) {
+ try {
+ format = catalog.getString(record.getMessage());
+ } catch (final MissingResourceException ex) {
+ format = record.getMessage();
+ }
+ }
+ try {
+ final Object[] parameters = record.getParameters();
+ if (parameters == null || parameters.length == 0) {
+ return format;
+ }
+ if (format.contains("{0") || format.contains("{1")
+ || format.contains("{2") || format.contains("{3")) {
+ return MessageFormat.format(format, parameters);
+ }
+ return format;
+ } catch (final Exception ex) {
+ return format;
+ }
+ }
+
+ /**
+ * Load the specified resource bundle
+ *
+ * @param resourceBundleName the name current the resource bundle to load, cannot be null
+ * @return the loaded resource bundle.
+ * @throws MissingResourceException If the specified resource bundle can not be loaded.
+ */
+ static ResourceBundle loadResourceBundle(final String resourceBundleName) {
+ // try context class loader to load the resource
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (null != cl) {
+ try {
+ return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
+ } catch (final MissingResourceException e) {
+ // Failed to load using context classloader, ignore
+ }
+ }
+ // try system class loader to load the resource
+ cl = ClassLoader.getSystemClassLoader();
+ if (null != cl) {
+ try {
+ return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
+ } catch (final MissingResourceException e) {
+ // Failed to load using system classloader, ignore
+ }
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
new file mode 100644
index 0000000..35ae4ab
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.logging;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+public class Log4j2Logger extends AbstractDelegatingLogger {
+ private static final Map<Level, org.apache.logging.log4j.Level> TO_LOG4J = new HashMap<>();
+
+ private final Logger log;
+
+ static {
+ //older versions current log4j don't have TRACE, use debug
+// org.apache.logging.log4j.Level t = org.apache.logging.log4j.Level.DEBUG;
+
+ TO_LOG4J.put(Level.ALL, org.apache.logging.log4j.Level.ALL);
+ TO_LOG4J.put(Level.SEVERE, org.apache.logging.log4j.Level.ERROR);
+ TO_LOG4J.put(Level.WARNING, org.apache.logging.log4j.Level.WARN);
+ TO_LOG4J.put(Level.INFO, org.apache.logging.log4j.Level.INFO);
+ TO_LOG4J.put(Level.CONFIG, org.apache.logging.log4j.Level.DEBUG);
+ TO_LOG4J.put(Level.FINE, org.apache.logging.log4j.Level.DEBUG);
+ TO_LOG4J.put(Level.FINER, org.apache.logging.log4j.Level.TRACE);
+ TO_LOG4J.put(Level.FINEST, org.apache.logging.log4j.Level.TRACE);
+ TO_LOG4J.put(Level.OFF, org.apache.logging.log4j.Level.OFF);
+ }
+
+ public Log4j2Logger(final String name, final String resourceBundleName) {
+ super(name, resourceBundleName);
+ log = LogManager.getLogger(name);
+ }
+
+ public Level getLevel() {
+ final org.apache.logging.log4j.Level l = log.getLevel();
+ if (l != null) {
+ return fromL4J(l);
+ }
+ return null;
+ }
+
+ protected void internalLogFormatted(final String msg, final LogRecord record) {
+ log.log(TO_LOG4J.get(record.getLevel()), msg, record.getThrown());
+ }
+
+
+ private Level fromL4J(final org.apache.logging.log4j.Level l) {
+ Level l2 = null;
+ switch (l.getStandardLevel()) {
+ case ALL:
+ l2 = Level.ALL;
+ break;
+ case FATAL:
+ l2 = Level.SEVERE;
+ break;
+ case ERROR:
+ l2 = Level.SEVERE;
+ break;
+ case WARN:
+ l2 = Level.WARNING;
+ break;
+ case INFO:
+ l2 = Level.INFO;
+ break;
+ case DEBUG:
+ l2 = Level.FINE;
+ break;
+ case OFF:
+ l2 = Level.OFF;
+ break;
+ case TRACE:
+ l2 = Level.FINEST;
+ break;
+ default:
+ l2 = Level.FINE;
+ }
+ return l2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
new file mode 100644
index 0000000..224378c
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.logging;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.apache.log4j.spi.LoggingEvent;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+/**
+ * java.util.logging.Logger implementation delegating to Log4j.
+ * All methods can be used except:
+ * setLevel
+ * addHandler / getHandlers
+ * setParent / getParent
+ * setUseParentHandlers / getUseParentHandlers
+ *
+ * @author gnodet
+ */
+public class Log4jLogger extends AbstractDelegatingLogger {
+ private static final Map<Level, org.apache.log4j.Level> TO_LOG4J = new HashMap<>();
+ private static final org.apache.log4j.Level TRACE;
+
+ private final Logger log;
+
+ static {
+ //older versions current log4j don't have TRACE, use debug
+ org.apache.log4j.Level t = org.apache.log4j.Level.DEBUG;
+ try {
+ final Field f = org.apache.log4j.Level.class.getField("TRACE");
+ t = (org.apache.log4j.Level) f.get(null);
+ } catch (final Throwable ex) {
+ //ignore, assume old version current log4j
+ }
+ TRACE = t;
+
+ TO_LOG4J.put(Level.ALL, org.apache.log4j.Level.ALL);
+ TO_LOG4J.put(Level.SEVERE, org.apache.log4j.Level.ERROR);
+ TO_LOG4J.put(Level.WARNING, org.apache.log4j.Level.WARN);
+ TO_LOG4J.put(Level.INFO, org.apache.log4j.Level.INFO);
+ TO_LOG4J.put(Level.CONFIG, org.apache.log4j.Level.DEBUG);
+ TO_LOG4J.put(Level.FINE, org.apache.log4j.Level.DEBUG);
+ TO_LOG4J.put(Level.FINER, TRACE);
+ TO_LOG4J.put(Level.FINEST, TRACE);
+ TO_LOG4J.put(Level.OFF, org.apache.log4j.Level.OFF);
+ }
+
+ public Log4jLogger(final String name, final String resourceBundleName) {
+ super(name, resourceBundleName);
+ log = LogManager.getLogger(name);
+ }
+
+ public Level getLevel() {
+ final org.apache.log4j.Level l = log.getEffectiveLevel();
+ if (l != null) {
+ return fromL4J(l);
+ }
+ return null;
+ }
+
+ public void setLevel(final Level newLevel) throws SecurityException {
+ log.setLevel(TO_LOG4J.get(newLevel));
+ }
+
+ public synchronized void addHandler(final Handler handler) throws SecurityException {
+ log.addAppender(new HandlerWrapper(handler));
+ }
+
+ public synchronized void removeHandler(final Handler handler) throws SecurityException {
+ log.removeAppender("HandlerWrapper-" + handler.hashCode());
+ }
+
+ public synchronized Handler[] getHandlers() {
+ final List<Handler> ret = new ArrayList<>();
+ final Enumeration<?> en = log.getAllAppenders();
+ while (en.hasMoreElements()) {
+ final Appender ap = (Appender) en.nextElement();
+ if (ap instanceof HandlerWrapper) {
+ ret.add(((HandlerWrapper) ap).getHandler());
+ }
+ }
+ return ret.toArray(new Handler[ret.size()]);
+ }
+
+ protected void internalLogFormatted(final String msg, final LogRecord record) {
+ log.log(AbstractDelegatingLogger.class.getName(),
+ TO_LOG4J.get(record.getLevel()),
+ msg,
+ record.getThrown());
+ }
+
+
+ private Level fromL4J(final org.apache.log4j.Level l) {
+ Level l2 = null;
+ switch (l.toInt()) {
+ case org.apache.log4j.Level.ALL_INT:
+ l2 = Level.ALL;
+ break;
+ case org.apache.log4j.Level.FATAL_INT:
+ l2 = Level.SEVERE;
+ break;
+ case org.apache.log4j.Level.ERROR_INT:
+ l2 = Level.SEVERE;
+ break;
+ case org.apache.log4j.Level.WARN_INT:
+ l2 = Level.WARNING;
+ break;
+ case org.apache.log4j.Level.INFO_INT:
+ l2 = Level.INFO;
+ break;
+ case org.apache.log4j.Level.DEBUG_INT:
+ l2 = Level.FINE;
+ break;
+ case org.apache.log4j.Level.OFF_INT:
+ l2 = Level.OFF;
+ break;
+ default:
+ if (l.toInt() == TRACE.toInt()) {
+ l2 = Level.FINEST;
+ }
+ }
+ return l2;
+ }
+
+
+ private class HandlerWrapper extends AppenderSkeleton {
+ Handler handler;
+
+ public HandlerWrapper(final Handler h) {
+ handler = h;
+ name = "HandlerWrapper-" + h.hashCode();
+ }
+
+ public Handler getHandler() {
+ return handler;
+ }
+
+ @Override
+ protected void append(final LoggingEvent event) {
+ final LogRecord lr = new LogRecord(fromL4J(event.getLevel()),
+ event.getMessage().toString());
+ lr.setLoggerName(event.getLoggerName());
+ if (event.getThrowableInformation() != null) {
+ lr.setThrown(event.getThrowableInformation().getThrowable());
+ }
+ final String rbname = getResourceBundleName();
+ if (rbname != null) {
+ lr.setResourceBundleName(rbname);
+ lr.setResourceBundle(getResourceBundle());
+ }
+ handler.publish(lr);
+ }
+
+ public void close() {
+ handler.close();
+ closed = true;
+ }
+
+ public boolean requiresLayout() {
+ return false;
+ }
+
+ @Override
+ public Priority getThreshold() {
+ return TO_LOG4J.get(handler.getLevel());
+ }
+
+ @Override
+ public boolean isAsSevereAsThreshold(final Priority priority) {
+ final Priority p = getThreshold();
+ return p == null || priority.isGreaterOrEqual(p);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
new file mode 100644
index 0000000..a580128
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.logging;
+
+import org.slf4j.spi.LocationAwareLogger;
+
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+/**
+ * <p>
+ * java.util.logging.Logger implementation delegating to SLF4J.
+ * </p>
+ * <p>
+ * Methods {@link java.util.logging.Logger#setParent(Logger)}, {@link java.util.logging.Logger#getParent()},
+ * {@link java.util.logging.Logger#setUseParentHandlers(boolean)} and
+ * {@link java.util.logging.Logger#getUseParentHandlers()} are not overrriden.
+ * </p>
+ * <p>
+ * Level annotation inspired by {@link org.slf4j.bridge.SLF4JBridgeHandler}:
+ * </p>
+ * <p/>
+ * <pre>
+ * FINEST -> TRACE
+ * FINER -> DEBUG
+ * FINE -> DEBUG
+ * CONFIG -> DEBUG
+ * INFO -> INFO
+ * WARN ING -> WARN
+ * SEVER -> ERROR
+ * </pre>
+ */
+public class Slf4jLogger extends AbstractDelegatingLogger {
+
+ private static final String FQCN = AbstractDelegatingLogger.class.getName();
+
+ private final org.slf4j.Logger logger;
+ private LocationAwareLogger locationAwareLogger;
+
+
+ public Slf4jLogger(final String name, final String resourceBundleName) {
+ super(name, resourceBundleName);
+ logger = org.slf4j.LoggerFactory.getLogger(name);
+ if (logger instanceof LocationAwareLogger) {
+ locationAwareLogger = (LocationAwareLogger) logger;
+ }
+ }
+
+ @Override
+ protected boolean supportsHandlers() {
+ return true;
+ }
+
+ @Override
+ public Level getLevel() {
+ final Level level;
+ // Verify fromMap the wider (trace) to the narrower (error)
+ if (logger.isTraceEnabled()) {
+ level = Level.FINEST;
+ } else if (logger.isDebugEnabled()) {
+ // map to the lowest between FINER, FINE and CONFIG
+ level = Level.FINER;
+ } else if (logger.isInfoEnabled()) {
+ level = Level.INFO;
+ } else if (logger.isWarnEnabled()) {
+ level = Level.WARNING;
+ } else if (logger.isErrorEnabled()) {
+ level = Level.SEVERE;
+ } else {
+ level = Level.OFF;
+ }
+ return level;
+ }
+
+ @Override
+ public boolean isLoggable(final Level level) {
+ final int i = level.intValue();
+ if (i == Level.OFF.intValue()) {
+ return false;
+ } else if (i >= Level.SEVERE.intValue()) {
+ return logger.isErrorEnabled();
+ } else if (i >= Level.WARNING.intValue()) {
+ return logger.isWarnEnabled();
+ } else if (i >= Level.INFO.intValue()) {
+ return logger.isInfoEnabled();
+ } else if (i >= Level.FINER.intValue()) {
+ return logger.isDebugEnabled();
+ }
+ return logger.isTraceEnabled();
+ }
+
+
+ @Override
+ protected void internalLogFormatted(final String msg, final LogRecord record) {
+
+ final Level level = record.getLevel();
+ final Throwable t = record.getThrown();
+
+ final Handler[] targets = getHandlers();
+ if (targets != null) {
+ for (final Handler h : targets) {
+ h.publish(record);
+ }
+ }
+ if (!getUseParentHandlers()) {
+ return;
+ }
+
+ /*
+ * As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order current the
+ * comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc
+ */
+ if (Level.FINE.equals(level)) {
+ if (locationAwareLogger == null) {
+ logger.debug(msg, t);
+ } else {
+ locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
+ }
+ } else if (Level.INFO.equals(level)) {
+ if (locationAwareLogger == null) {
+ logger.info(msg, t);
+ } else {
+ locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, t);
+ }
+ } else if (Level.WARNING.equals(level)) {
+ if (locationAwareLogger == null) {
+ logger.warn(msg, t);
+ } else {
+ locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, t);
+ }
+ } else if (Level.FINER.equals(level)) {
+ if (locationAwareLogger == null) {
+ logger.trace(msg, t);
+ } else {
+ locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
+ }
+ } else if (Level.FINEST.equals(level)) {
+ if (locationAwareLogger == null) {
+ logger.trace(msg, t);
+ } else {
+ locationAwareLogger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, t);
+ }
+ } else if (Level.ALL.equals(level)) {
+ // should never occur, all is used to configure java.util.logging
+ // but not accessible by the API Logger.xxx() API
+ if (locationAwareLogger == null) {
+ logger.error(msg, t);
+ } else {
+ locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
+ }
+ } else if (Level.SEVERE.equals(level)) {
+ if (locationAwareLogger == null) {
+ logger.error(msg, t);
+ } else {
+ locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
+ }
+ } else if (Level.CONFIG.equals(level)) {
+ if (locationAwareLogger == null) {
+ logger.debug(msg, t);
+ } else {
+ locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
+ }
+ }
+ // don't log if Level.OFF
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
new file mode 100644
index 0000000..5860923
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
@@ -0,0 +1,230 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.resources.Resource;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Objects;
+
+/**
+ * Abstract base class for resources which resolve URLs into File references,
+ * such as {@code UrlResource} or {@link ClassPathResource}.
+ *
+ * <p>Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs,
+ * resolving file system references accordingly.
+ *
+ * @author Juergen Hoeller
+ * @since 3.0
+ */
+abstract class AbstractFileResolvingResource implements Resource {
+
+ /**
+ * This implementation returns a File reference for the underlying class path
+ * resource, provided that it refers to a file in the file system.
+ */
+ @Override
+ public File toFile() throws IOException {
+ URL url = toURL();
+ return ResourceUtils.getFile(url);
+ }
+
+ /**
+ * This implementation determines the underlying File
+ * (or jar file, in case current a resource in a jar/zip).
+ */
+ protected File getFileForLastModifiedCheck() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isJarURL(url)) {
+ URL actualUrl = ResourceUtils.extractJarFileURL(url);
+ return ResourceUtils.getFile(actualUrl, "Jar URL");
+ }
+ else {
+ return toFile();
+ }
+ }
+
+ /**
+ * This implementation returns a File reference for the underlying class path
+ * resource, provided that it refers to a file in the file system.
+ * @see ResourceUtils#getFile(java.net.URI, String)
+ */
+ protected File getFile(URI uri) throws IOException {
+ return ResourceUtils.getFile(uri);
+ }
+
+
+ @Override
+ public boolean exists() {
+ try {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ return toFile().exists();
+ }
+ else {
+ // Try a URL connection content-length header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ HttpURLConnection httpCon =
+ (con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
+ if (httpCon != null) {
+ int code = httpCon.getResponseCode();
+ if (code == HttpURLConnection.HTTP_OK) {
+ return true;
+ }
+ else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
+ return false;
+ }
+ }
+ if (con.getContentLength() >= 0) {
+ return true;
+ }
+ if (httpCon != null) {
+ // no HTTP OK status, and no content-length header: give up
+ httpCon.disconnect();
+ return false;
+ }
+ else {
+ // Fall back to stream existence: can we open the stream?
+ InputStream is = getInputStream();
+ is.close();
+ return true;
+ }
+ }
+ }
+ catch (IOException ex) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isReadable() {
+ try {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ File file = toFile();
+ return (file.canRead() && !file.isDirectory());
+ }
+ else {
+ return true;
+ }
+ }
+ catch (IOException ex) {
+ return false;
+ }
+ }
+
+ @Override
+ public long contentLength() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ return toFile().length();
+ }
+ else {
+ // Try a URL connection content-length header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ return con.getContentLength();
+ }
+ }
+
+ @Override
+ public long lastModified() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
+ // Proceed with file system resolution...
+ long lastModified = getFileForLastModifiedCheck().lastModified();
+ if (lastModified == 0L) {
+ throw new FileNotFoundException(getDisplayName() +
+ " cannot be resolved in the file system for resolving its last-modified timestamp");
+ }
+ return lastModified;
+ }
+ else {
+ // Try a URL connection last-modified header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ return con.getLastModified();
+ }
+ }
+
+
+ /**
+ * Customize the given {@link URLConnection}, obtained in the course current an
+ * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
+ * <p>Calls {@link ResourceUtils#useCachesIfNecessary(URLConnection)} and
+ * delegates to {@link #customizeConnection(HttpURLConnection)} if possible.
+ * Can be overridden in subclasses.
+ * @param con the URLConnection to customize
+ * @throws IOException if thrown from URLConnection methods
+ */
+ protected void customizeConnection(URLConnection con) throws IOException {
+ ResourceUtils.useCachesIfNecessary(con);
+ if (con instanceof HttpURLConnection) {
+ customizeConnection((HttpURLConnection) con);
+ }
+ }
+
+ /**
+ * Customize the given {@link HttpURLConnection}, obtained in the course current an
+ * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
+ * <p>Sets request method "HEAD" by default. Can be overridden in subclasses.
+ * @param con the HttpURLConnection to customize
+ * @throws IOException if thrown from HttpURLConnection methods
+ */
+ protected void customizeConnection(HttpURLConnection con) throws IOException {
+ con.setRequestMethod("HEAD");
+ }
+
+ /**
+ * Resolve the given resource URL to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ * @param resourceUrl the resource URL to resolve
+ * @param description a description current the original resource that
+ * the URL was created for (for example, a class path location)
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ private File getFile(URL resourceUrl, String description) throws FileNotFoundException {
+ Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
+ if (!"file".equals(resourceUrl.getProtocol())) {
+ throw new FileNotFoundException(
+ description + " cannot be resolved to absolute file path " +
+ "because it does not reside in the file system: " + resourceUrl);
+ }
+ try {
+ return new File(ResourceUtils.toURI(resourceUrl).getSchemeSpecificPart());
+ }
+ catch (URISyntaxException ex) {
+ // Fallback for URLs that are not valid URIs (should hardly ever happen).
+ return new File(resourceUrl.getFile());
+ }
+ }
+
+
+}
[16/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java
new file mode 100644
index 0000000..391f7e8
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/ReflectionUtils.java
@@ -0,0 +1,192 @@
+/*
+* Copyright 2002-2014 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.tamaya.core.internal.resource;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+* Simple utility class for working with the reflection API and handling
+* reflection exceptions.
+*
+* <p>Only intended for internal use.
+*
+* @author Juergen Hoeller
+* @author Rob Harrop
+* @author Rod Johnson
+* @author Costin Leau
+* @author Sam Brannen
+* @author Chris Beams
+* @since 1.2.2
+*/
+public abstract class ReflectionUtils {
+ /**
+ * Cache for {@link Class#getDeclaredMethods()}, allowing for fast resolution.
+ */
+ private static final Map<Class<?>, Method[]> declaredMethodsCache =
+ new ConcurrentHashMap<>(256);
+
+
+ /**
+ * Attempt to find a {@link Field field} on the supplied {@link Class} with the
+ * supplied {@code name}. Searches all superclasses up to {@link Object}.
+ * @param clazz the class to introspect
+ * @param name the name current the field
+ * @return the corresponding Field object, or {@code null} if not found
+ */
+ public static Field findField(Class<?> clazz, String name) {
+ return findField(clazz, name, null);
+ }
+
+ /**
+ * Attempt to find a {@link Field field} on the supplied {@link Class} with the
+ * supplied {@code name} and/or {@link Class type}. Searches all superclasses
+ * up to {@link Object}.
+ * @param clazz the class to introspect
+ * @param name the name current the field (may be {@code null} if type is specified)
+ * @param type the type current the field (may be {@code null} if name is specified)
+ * @return the corresponding Field object, or {@code null} if not found
+ */
+ public static Field findField(Class<?> clazz, String name, Class<?> type) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ if(name == null && type == null) throw new IllegalArgumentException("Either name or type current the field must be specified");
+ Class<?> searchType = clazz;
+ while (!Object.class.equals(searchType) && searchType != null) {
+ Field[] fields = searchType.getDeclaredFields();
+ for (Field field : fields) {
+ if ((name == null || name.equals(field.getName())) && (type == null || type.equals(field.getType()))) {
+ return field;
+ }
+ }
+ searchType = searchType.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * Attempt to find a {@link Method} on the supplied class with the supplied name
+ * and no parameters. Searches all superclasses up to {@code Object}.
+ * <p>Returns {@code null} if no {@link Method} can be found.
+ * @param clazz the class to introspect
+ * @param name the name current the method
+ * @return the Method object, or {@code null} if none found
+ */
+ public static Method findMethod(Class<?> clazz, String name) {
+ return findMethod(clazz, name, new Class<?>[0]);
+ }
+
+ /**
+ * Attempt to find a {@link Method} on the supplied class with the supplied name
+ * and parameter types. Searches all superclasses up to {@code Object}.
+ * <p>Returns {@code null} if no {@link Method} can be found.
+ * @param clazz the class to introspect
+ * @param name the name current the method
+ * @param paramTypes the parameter types current the method
+ * (may be {@code null} to indicate any signature)
+ * @return the Method object, or {@code null} if none found
+ */
+ public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(name, "Method name must not be null");
+ Class<?> searchType = clazz;
+ while (searchType != null) {
+ Method[] methods = (searchType.isInterface() ? searchType.getMethods() : getDeclaredMethods(searchType));
+ for (Method method : methods) {
+ if (name.equals(method.getName()) &&
+ (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) {
+ return method;
+ }
+ }
+ searchType = searchType.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * Handle the given reflection exception. Should only be called if no
+ * checked exception is expected to be thrown by the target method.
+ * <p>Throws the underlying RuntimeException or Error in case current an
+ * InvocationTargetException with such a root cause. Throws an
+ * IllegalStateException with an appropriate message else.
+ * @param ex the reflection exception to handle
+ */
+ public static void handleReflectionException(Exception ex) {
+ if (ex instanceof NoSuchMethodException) {
+ throw new IllegalStateException("Method not found: " + ex.getMessage());
+ }
+ if (ex instanceof IllegalAccessException) {
+ throw new IllegalStateException("Could not access method: " + ex.getMessage());
+ }
+ if (ex instanceof InvocationTargetException) {
+ handleInvocationTargetException((InvocationTargetException) ex);
+ }
+ if (ex instanceof RuntimeException) {
+ throw (RuntimeException) ex;
+ }
+ throw new UndeclaredThrowableException(ex);
+ }
+
+ /**
+ * Handle the given invocation target exception. Should only be called if no
+ * checked exception is expected to be thrown by the target method.
+ * <p>Throws the underlying RuntimeException or Error in case current such a root
+ * cause. Throws an IllegalStateException else.
+ * @param ex the invocation target exception to handle
+ */
+ public static void handleInvocationTargetException(InvocationTargetException ex) {
+ rethrowRuntimeException(ex.getTargetException());
+ }
+
+ /**
+ * Rethrow the given {@link Throwable exception}, which is presumably the
+ * <em>target exception</em> current an {@link InvocationTargetException}. Should
+ * only be called if no checked exception is expected to be thrown by the
+ * target method.
+ * <p>Rethrows the underlying exception cast to an {@link RuntimeException} or
+ * {@link Error} if appropriate; otherwise, throws an
+ * {@link IllegalStateException}.
+ * @param ex the exception to rethrow
+ * @throws RuntimeException the rethrown exception
+ */
+ public static void rethrowRuntimeException(Throwable ex) {
+ if (ex instanceof RuntimeException) {
+ throw (RuntimeException) ex;
+ }
+ if (ex instanceof Error) {
+ throw (Error) ex;
+ }
+ throw new UndeclaredThrowableException(ex);
+ }
+
+ /**
+ * This method retrieves {@link Class#getDeclaredMethods()} from a local cache
+ * in order to avoid the JVM's SecurityManager check and defensive array copying.
+ */
+ private static Method[] getDeclaredMethods(Class<?> clazz) {
+ Method[] result = declaredMethodsCache.get(clazz);
+ if (result == null) {
+ result = clazz.getDeclaredMethods();
+ declaredMethodsCache.put(clazz, result);
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java
new file mode 100644
index 0000000..a9979f1
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/ResourceUtils.java
@@ -0,0 +1,257 @@
+/*
+* Copyright 2002-2014 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.tamaya.core.internal.resource;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Objects;
+
+/**
+* Utility methods for resolving resource locations to files in the
+* file system. Mainly for internal use within the framework.
+*
+* <p>Consider using Spring's Resource abstraction in the core package
+* for handling all kinds current file resources in a uniform manner.
+* {@code org.springframework.core.io.ResourceLoader}'s {@code getResource()}
+* method can resolve any location to a {@code org.springframework.core.io.Resource}
+* object, which in turn allows one to obtain a {@code java.io.File} in the
+* file system through its {@code getFile()} method.
+*
+* <p>The main reason for these utility methods for resource location handling
+* is to support {@code Log4jConfigurer}, which must be able to resolve
+* resource locations <i>before the logging system has been initialized</i>.
+* Spring's {@code Resource} abstraction in the core package, on the other hand,
+* already expects the logging system to be available.
+*
+* @author Juergen Hoeller
+* @since 1.1.5
+*/
+final class ResourceUtils {
+
+ /** URL prefix for loading from the file system: "file:" */
+ public static final String FILE_URL_PREFIX = "file:";
+
+ /** URL prefix for loading from the file system: "jar:" */
+ public static final String JAR_URL_PREFIX = "jar:";
+
+ /** URL protocol for a file in the file system: "file" */
+ public static final String URL_PROTOCOL_FILE = "file";
+
+ /** URL protocol for an entry from a jar file: "jar" */
+ public static final String URL_PROTOCOL_JAR = "jar";
+
+ /** URL protocol for an entry from a zip file: "zip" */
+ public static final String URL_PROTOCOL_ZIP = "zip";
+
+ /** URL protocol for an entry from a WebSphere jar file: "wsjar" */
+ public static final String URL_PROTOCOL_WSJAR = "wsjar";
+
+ /** URL protocol for an entry from a JBoss jar file: "vfszip" */
+ public static final String URL_PROTOCOL_VFSZIP = "vfszip";
+
+ /** URL protocol for a JBoss file system resource: "vfsfile" */
+ public static final String URL_PROTOCOL_VFSFILE = "vfsfile";
+
+ /** URL protocol for a general JBoss VFS resource: "vfs" */
+ public static final String URL_PROTOCOL_VFS = "vfs";
+
+ /** File extension for a regular jar file: ".jar" */
+ public static final String JAR_FILE_EXTENSION = ".jar";
+
+ /** Separator between JAR URL and file path within the JAR: "!/" */
+ public static final String JAR_URL_SEPARATOR = "!/";
+
+ /**
+ * Singleton constructor.
+ */
+ private ResourceUtils(){}
+
+ /**
+ * Resolve the given resource URL to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ * @param resourceUrl the resource URL to resolve
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ public static File getFile(URL resourceUrl) throws FileNotFoundException {
+ return getFile(resourceUrl, "URL");
+ }
+
+ /**
+ * Resolve the given resource URL to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ * @param resourceUrl the resource URL to resolve
+ * @param description a description current the original resource that
+ * the URL was created for (for example, a class path location)
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ public static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
+ Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
+ if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
+ throw new FileNotFoundException(
+ description + " cannot be resolved to absolute file path " +
+ "because it does not reside in the file system: " + resourceUrl);
+ }
+ try {
+ return new File(toURI(resourceUrl).getSchemeSpecificPart());
+ }
+ catch (URISyntaxException ex) {
+ // Fallback for URLs that are not valid URIs (should hardly ever happen).
+ return new File(resourceUrl.getFile());
+ }
+ }
+
+ /**
+ * Resolve the given resource URI to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ * @param resourceUri the resource URI to resolve
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ public static File getFile(URI resourceUri) throws FileNotFoundException {
+ return getFile(resourceUri, "URI");
+ }
+
+ /**
+ * Resolve the given resource URI to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ * @param resourceUri the resource URI to resolve
+ * @param description a description current the original resource that
+ * the URI was created for (for example, a class path location)
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
+ Objects.requireNonNull(resourceUri, "Resource URI must not be null");
+ if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) {
+ throw new FileNotFoundException(
+ description + " cannot be resolved to absolute file path " +
+ "because it does not reside in the file system: " + resourceUri);
+ }
+ return new File(resourceUri.getSchemeSpecificPart());
+ }
+
+ /**
+ * Determine whether the given URL points to a resource in the file system,
+ * that is, has protocol "file", "vfsfile" or "vfs".
+ * @param url the URL to check
+ * @return whether the URL has been identified as a file system URL
+ */
+ public static boolean isFileURL(URL url) {
+ String protocol = url.getProtocol();
+ return (URL_PROTOCOL_FILE.equals(protocol) || URL_PROTOCOL_VFSFILE.equals(protocol) ||
+ URL_PROTOCOL_VFS.equals(protocol));
+ }
+
+ /**
+ * Determine whether the given URL points to a resource in a jar file,
+ * that is, has protocol "jar", "zip", "vfszip" or "wsjar".
+ * @param url the URL to check
+ * @return whether the URL has been identified as a JAR URL
+ */
+ public static boolean isJarURL(URL url) {
+ String protocol = url.getProtocol();
+ return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) ||
+ URL_PROTOCOL_VFSZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol));
+ }
+
+ /**
+ * Determine whether the given URL points to a jar file itself,
+ * that is, has protocol "file" and ends with the ".jar" extension.
+ * @param url the URL to check
+ * @return whether the URL has been identified as a JAR file URL
+ * @since 4.1
+ */
+ public static boolean isJarFileURL(URL url) {
+ return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
+ url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
+ }
+
+ /**
+ * Extract the URL for the actual jar file from the given URL
+ * (which may point to a resource in a jar file or to a jar file itself).
+ * @param jarUrl the original URL
+ * @return the URL for the actual jar file
+ * @throws MalformedURLException if no valid jar file URL could be extracted
+ */
+ public static URL extractJarFileURL(URL jarUrl) throws MalformedURLException {
+ String urlFile = jarUrl.getFile();
+ int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR);
+ if (separatorIndex != -1) {
+ String jarFile = urlFile.substring(0, separatorIndex);
+ try {
+ return new URL(jarFile);
+ }
+ catch (MalformedURLException ex) {
+ // Probably no protocol in original jar URL, like "jar:C:/mypath/myjar.jar".
+ // This usually indicates that the jar file resides in the file system.
+ if (!jarFile.startsWith("/")) {
+ jarFile = "/" + jarFile;
+ }
+ return new URL(FILE_URL_PREFIX + jarFile);
+ }
+ }
+ else {
+ return jarUrl;
+ }
+ }
+
+ /**
+ * Create a URI instance for the given URL,
+ * replacing spaces with "%20" URI encoding first.
+ * <p>Furthermore, this method works on JDK 1.4 as well,
+ * in contrast to the {@code URL.toURI()} method.
+ * @param url the URL to convert into a URI instance
+ * @return the URI instance
+ * @throws URISyntaxException if the URL wasn't a valid URI
+ * @see java.net.URL#toURI()
+ */
+ public static URI toURI(URL url) throws URISyntaxException {
+ return toURI(url.toString());
+ }
+
+ /**
+ * Create a URI instance for the given location String,
+ * replacing spaces with "%20" URI encoding first.
+ * @param location the location String to convert into a URI instance
+ * @return the URI instance
+ * @throws URISyntaxException if the location wasn't a valid URI
+ */
+ public static URI toURI(String location) throws URISyntaxException {
+ return new URI(location.replaceAll(" ", "%20"));
+ }
+
+ /**
+ * Set the {@link URLConnection#setUseCaches "useCaches"} flag on the
+ * given connection, preferring {@code false} but leaving the
+ * flag at {@code true} for JNLP based resources.
+ * @param con the URLConnection to set the flag on
+ */
+ public static void useCachesIfNecessary(URLConnection con) {
+ con.setUseCaches(con.getClass().getSimpleName().startsWith("JNLP"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java
new file mode 100644
index 0000000..6011109
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/UrlResource.java
@@ -0,0 +1,274 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.util.StringUtils;
+import org.apache.tamaya.core.resources.Resource;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Objects;
+
+/**
+ * {@link Resource} implementation for {@code java.net.URL} locators.
+ * Obviously supports resolution as URL, and also as File in case current
+ * the "file:" protocol.
+ *
+ * @author Juergen Hoeller
+ * @since 28.12.2003
+ * @see java.net.URL
+ */
+public class UrlResource extends AbstractFileResolvingResource {
+
+ /**
+ * Original URI, if available; used for URI and File access.
+ */
+ private final URI uri;
+
+ /**
+ * Original URL, used for actual access.
+ */
+ private final URL url;
+
+ /**
+ * Cleaned URL (with normalized path), used for comparisons.
+ */
+ private final URL cleanedUrl;
+
+
+ /**
+ * Create a new UrlResource based on the given URI object.
+ * @param uri a URI
+ * @throws MalformedURLException if the given URL path is not valid
+ */
+ public UrlResource(URI uri) throws MalformedURLException {
+ Objects.requireNonNull(uri, "URI must not be null");
+ this.uri = uri;
+ this.url = uri.toURL();
+ this.cleanedUrl = getCleanedUrl(this.url, uri.toString());
+ }
+
+ /**
+ * Create a new UrlResource based on the given URL object.
+ * @param url a URL
+ */
+ public UrlResource(URL url) {
+ Objects.requireNonNull(url, "URL must not be null");
+ this.url = url;
+ this.cleanedUrl = getCleanedUrl(this.url, url.toString());
+ this.uri = null;
+ }
+
+ /**
+ * Create a new UrlResource based on a URL path.
+ * <p>Note: The given path needs to be pre-encoded if necessary.
+ * @param path a URL path
+ * @throws MalformedURLException if the given URL path is not valid
+ * @see java.net.URL#URL(String)
+ */
+ public UrlResource(String path) throws MalformedURLException {
+ Objects.requireNonNull(path, "Path must not be null");
+ this.uri = null;
+ this.url = new URL(path);
+ this.cleanedUrl = getCleanedUrl(this.url, path);
+ }
+
+ /**
+ * Create a new UrlResource based on a URI specification.
+ * <p>The given parts will automatically get encoded if necessary.
+ * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon);
+ * also known as "scheme"
+ * @param location the location (e.g. the file path within that protocol);
+ * also known as "scheme-specific part"
+ * @throws MalformedURLException if the given URL specification is not valid
+ * @see java.net.URI#URI(String, String, String)
+ */
+ public UrlResource(String protocol, String location) throws MalformedURLException {
+ this(protocol, location, null);
+ }
+
+ /**
+ * Create a new UrlResource based on a URI specification.
+ * <p>The given parts will automatically get encoded if necessary.
+ * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon);
+ * also known as "scheme"
+ * @param location the location (e.g. the file path within that protocol);
+ * also known as "scheme-specific part"
+ * @param fragment the fragment within that location (e.g. anchor on an HTML page,
+ * as following after a "#" separator)
+ * @throws MalformedURLException if the given URL specification is not valid
+ * @see java.net.URI#URI(String, String, String)
+ */
+ public UrlResource(String protocol, String location, String fragment) throws MalformedURLException {
+ try {
+ this.uri = new URI(protocol, location, fragment);
+ this.url = this.uri.toURL();
+ this.cleanedUrl = getCleanedUrl(this.url, this.uri.toString());
+ }
+ catch (URISyntaxException ex) {
+ MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
+ exToThrow.initCause(ex);
+ throw exToThrow;
+ }
+ }
+
+ /**
+ * Determine a cleaned URL for the given original URL.
+ * @param originalUrl the original URL
+ * @param originalPath the original URL path
+ * @return the cleaned URL
+ */
+ private URL getCleanedUrl(URL originalUrl, String originalPath) {
+ try {
+ return new URL(StringUtils.cleanPath(originalPath));
+ }
+ catch (MalformedURLException ex) {
+ // Cleaned URL path cannot be converted to URL
+ // -> take original URL.
+ return originalUrl;
+ }
+ }
+
+
+ /**
+ * This implementation opens an InputStream for the given URL.
+ * It sets the "UseCaches" flag to {@code false},
+ * mainly to avoid jar file locking on Windows.
+ * @see java.net.URL#openConnection()
+ * @see java.net.URLConnection#setUseCaches(boolean)
+ * @see java.net.URLConnection#getInputStream()
+ */
+ @Override
+ public InputStream getInputStream()throws IOException {
+ URLConnection con = null;
+ try {
+ con = this.url.openConnection();
+ useCachesIfNecessary(con);
+ return con.getInputStream();
+ }
+ catch (IOException ex) {
+ // Close the HTTP connection (if applicable).
+ if (con instanceof HttpURLConnection) {
+ ((HttpURLConnection) con).disconnect();
+ }
+ throw ex;
+ }
+ }
+
+ /**
+ * This implementation returns the underlying URL reference.
+ */
+ @Override
+ public URL toURL() throws IOException {
+ return this.url;
+ }
+
+ /**
+ * This implementation returns the underlying URI directly,
+ * if possible.
+ */
+ @Override
+ public URI getURI() throws IOException {
+ if (this.uri != null) {
+ return this.uri;
+ }
+ else {
+ return super.getURI();
+ }
+ }
+
+ /**
+ * This implementation returns a File reference for the underlying URL/URI,
+ * provided that it refers to a file in the file system.
+ */
+ @Override
+ public File toFile() throws IOException {
+ if (this.uri != null) {
+ return super.getFile(this.uri);
+ }
+ else {
+ return super.toFile();
+ }
+ }
+
+ /**
+ * This implementation creates a UrlResource, applying the given path
+ * relative to the path current the underlying URL current this resource descriptor.
+ * @see java.net.URL#URL(java.net.URL, String)
+ */
+ @Override
+ public Resource createRelative(String relativePath) throws MalformedURLException {
+ if (relativePath.startsWith("/")) {
+ relativePath = relativePath.substring(1);
+ }
+ return new UrlResource(new URL(this.url, relativePath));
+ }
+
+ /**
+ * This implementation returns the name current the file that this URL refers to.
+ * @see java.net.URL#getFile()
+ * @see java.io.File#getName()
+ */
+ @Override
+ public String getDisplayName() {
+ return new File(this.url.getFile()).getName();
+ }
+
+ /**
+ * This implementation returns a description that includes the URL.
+ */
+ @Override
+ public String toString() {
+ return "URL [" + this.url + "]";
+ }
+
+
+ /**
+ * This implementation compares the underlying URL references.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return (obj == this ||
+ (obj instanceof UrlResource && this.cleanedUrl.equals(((UrlResource) obj).cleanedUrl)));
+ }
+
+ /**
+ * This implementation returns the hash code current the underlying URL reference.
+ */
+ @Override
+ public int hashCode() {
+ return this.cleanedUrl.hashCode();
+ }
+
+ /**
+ * Set the {@link URLConnection#setUseCaches "useCaches"} flag on the
+ * given connection, preferring {@code false} but leaving the
+ * flag at {@code true} for JNLP based resources.
+ * @param con the URLConnection to set the flag on
+ */
+ private void useCachesIfNecessary(URLConnection con) {
+ con.setUseCaches(con.getClass().getSimpleName().startsWith("JNLP"));
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java
new file mode 100644
index 0000000..b39a907
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsResource.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.resources.Resource;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.Objects;
+
+/**
+ * JBoss VFS based {@link Resource} implementation.
+ *
+ * <p>As current Spring 4.0, this class supports VFS 3.x on JBoss AS 6+ (package
+ * {@code org.jboss.vfs}) and is in particular compatible with JBoss AS 7 and
+ * WildFly 8.
+ *
+ * @author Ales Justin
+ * @author Juergen Hoeller
+ * @author Costin Leau
+ * @since 3.0
+ */
+public class VfsResource implements Resource {
+
+ private final Object resource;
+
+
+ public VfsResource(Object resource) {
+ Objects.requireNonNull(resource, "VirtualFile must not be null");
+ this.resource = resource;
+ }
+
+
+ @Override
+ public InputStream getInputStream()throws IOException {
+ return VfsUtils.getInputStream(this.resource);
+ }
+
+ @Override
+ public boolean exists() {
+ return VfsUtils.exists(this.resource);
+ }
+
+ @Override
+ public boolean isReadable() {
+ return VfsUtils.isReadable(this.resource);
+ }
+
+ @Override
+ public URL toURL() throws IOException {
+ try {
+ return VfsUtils.getURL(this.resource);
+ }
+ catch (Exception ex) {
+ throw new IllegalStateException("Failed to obtain URL for file " + this.resource, ex);
+ }
+ }
+
+ @Override
+ public URI getURI() throws IOException {
+ try {
+ return VfsUtils.getURI(this.resource);
+ }
+ catch (Exception ex) {
+ throw new IllegalStateException("Failed to obtain URI for " + this.resource, ex);
+ }
+ }
+
+ @Override
+ public File toFile() throws IOException {
+ return VfsUtils.getFile(this.resource);
+ }
+
+ @Override
+ public long contentLength() throws IOException {
+ return VfsUtils.getSize(this.resource);
+ }
+
+ @Override
+ public long lastModified() throws IOException {
+ return VfsUtils.getLastModified(this.resource);
+ }
+
+ @Override
+ public Resource createRelative(String relativePath) throws IOException {
+ if (!relativePath.startsWith(".") && relativePath.contains("/")) {
+ try {
+ return new VfsResource(VfsUtils.getChild(this.resource, relativePath));
+ }
+ catch (IOException ex) {
+ // fall back to getRelative
+ }
+ }
+
+ return new VfsResource(VfsUtils.getRelative(new URL(toURL(), relativePath)));
+ }
+
+ @Override
+ public String getDisplayName() {
+ return VfsUtils.getName(this.resource);
+ }
+
+ @Override
+ public String toString() {
+ return this.resource.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return (obj == this || (obj instanceof VfsResource && this.resource.equals(((VfsResource) obj).resource)));
+ }
+
+ @Override
+ public int hashCode() {
+ return this.resource.hashCode();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java
new file mode 100644
index 0000000..60fc452
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.internal.resource;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.*;
+import java.net.URI;
+import java.net.URL;
+
+/**
+ * Utility for detecting and accessing JBoss VFS in the classpath.
+ *
+ * <p>As current Spring 4.0, this class supports VFS 3.x on JBoss AS 6+ (package
+ * {@code org.jboss.vfs}) and is in particular compatible with JBoss AS 7 and
+ * WildFly 8.
+ *
+ * <p>Thanks go to Marius Bogoevici for the initial patch.
+ * <b>Note:</b> This is an internal class and should not be used outside the framework.
+ *
+ * @author Costin Leau
+ * @author Juergen Hoeller
+ * @since 3.0.3
+ */
+class VfsUtils {
+
+ private static final String VFS3_PKG = "org.jboss.vfs.";
+ private static final String VFS_NAME = "VFS";
+
+ private static Method VFS_METHOD_GET_ROOT_URL = null;
+ private static Method VFS_METHOD_GET_ROOT_URI = null;
+
+ private static Method VIRTUAL_FILE_METHOD_EXISTS = null;
+ private static Method VIRTUAL_FILE_METHOD_GET_INPUT_STREAM;
+ private static Method VIRTUAL_FILE_METHOD_GET_SIZE;
+ private static Method VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED;
+ private static Method VIRTUAL_FILE_METHOD_TO_URL;
+ private static Method VIRTUAL_FILE_METHOD_TO_URI;
+ private static Method VIRTUAL_FILE_METHOD_GET_NAME;
+ private static Method VIRTUAL_FILE_METHOD_GET_PATH_NAME;
+ private static Method VIRTUAL_FILE_METHOD_GET_CHILD;
+
+ protected static Class<?> VIRTUAL_FILE_VISITOR_INTERFACE;
+ protected static Method VIRTUAL_FILE_METHOD_VISIT;
+
+ private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null;
+ private static Method GET_PHYSICAL_FILE = null;
+
+ static {
+ ClassLoader loader = VfsUtils.class.getClassLoader();
+ try {
+ Class<?> vfsClass = loader.loadClass(VFS3_PKG + VFS_NAME);
+ VFS_METHOD_GET_ROOT_URL = ReflectionUtils.findMethod(vfsClass, "getChild", URL.class);
+ VFS_METHOD_GET_ROOT_URI = ReflectionUtils.findMethod(vfsClass, "getChild", URI.class);
+
+ Class<?> virtualFile = loader.loadClass(VFS3_PKG + "VirtualFile");
+ VIRTUAL_FILE_METHOD_EXISTS = ReflectionUtils.findMethod(virtualFile, "exists");
+ VIRTUAL_FILE_METHOD_GET_INPUT_STREAM = ReflectionUtils.findMethod(virtualFile, "openStream");
+ VIRTUAL_FILE_METHOD_GET_SIZE = ReflectionUtils.findMethod(virtualFile, "getSize");
+ VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED = ReflectionUtils.findMethod(virtualFile, "getLastModified");
+ VIRTUAL_FILE_METHOD_TO_URI = ReflectionUtils.findMethod(virtualFile, "toURI");
+ VIRTUAL_FILE_METHOD_TO_URL = ReflectionUtils.findMethod(virtualFile, "toURL");
+ VIRTUAL_FILE_METHOD_GET_NAME = ReflectionUtils.findMethod(virtualFile, "getName");
+ VIRTUAL_FILE_METHOD_GET_PATH_NAME = ReflectionUtils.findMethod(virtualFile, "getPathName");
+ GET_PHYSICAL_FILE = ReflectionUtils.findMethod(virtualFile, "getPhysicalFile");
+ VIRTUAL_FILE_METHOD_GET_CHILD = ReflectionUtils.findMethod(virtualFile, "getChild", String.class);
+
+ VIRTUAL_FILE_VISITOR_INTERFACE = loader.loadClass(VFS3_PKG + "VirtualFileVisitor");
+ VIRTUAL_FILE_METHOD_VISIT = ReflectionUtils.findMethod(virtualFile, "visit", VIRTUAL_FILE_VISITOR_INTERFACE);
+
+ Class<?> visitorAttributesClass = loader.loadClass(VFS3_PKG + "VisitorAttributes");
+ VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
+ }
+ catch (ClassNotFoundException ex) {
+ throw new IllegalStateException("Could not detect JBoss VFS infrastructure", ex);
+ }
+ }
+
+ private VfsUtils(){}
+
+ static void visit(Object resource, InvocationHandler visitor) throws IOException {
+ Object visitorProxy = Proxy.newProxyInstance(
+ VIRTUAL_FILE_VISITOR_INTERFACE.getClassLoader(),
+ new Class<?>[]{VIRTUAL_FILE_VISITOR_INTERFACE}, visitor);
+ invokeVfsMethod(VIRTUAL_FILE_METHOD_VISIT, resource, visitorProxy);
+ }
+
+ protected static Object invokeVfsMethod(Method method, Object target, Object... args) throws IOException {
+ try {
+ return method.invoke(target, args);
+ }
+ catch (InvocationTargetException ex) {
+ Throwable targetEx = ex.getTargetException();
+ if (targetEx instanceof IOException) {
+ throw (IOException) targetEx;
+ }
+ ReflectionUtils.handleInvocationTargetException(ex);
+ }
+ catch (Exception ex) {
+ ReflectionUtils.handleReflectionException(ex);
+ }
+
+ throw new IllegalStateException("Invalid code path reached");
+ }
+
+ static boolean exists(Object vfsResource) {
+ try {
+ return (Boolean) invokeVfsMethod(VIRTUAL_FILE_METHOD_EXISTS, vfsResource);
+ }
+ catch (IOException ex) {
+ return false;
+ }
+ }
+
+ static boolean isReadable(Object vfsResource) {
+ try {
+ return ((Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_SIZE, vfsResource) > 0);
+ }
+ catch (IOException ex) {
+ return false;
+ }
+ }
+
+ static long getSize(Object vfsResource) throws IOException {
+ return (Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_SIZE, vfsResource);
+ }
+
+ static long getLastModified(Object vfsResource) throws IOException {
+ return (Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED, vfsResource);
+ }
+
+ static InputStream getInputStream(Object vfsResource) throws IOException {
+ return (InputStream) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_INPUT_STREAM, vfsResource);
+ }
+
+ static URL getURL(Object vfsResource) throws IOException {
+ return (URL) invokeVfsMethod(VIRTUAL_FILE_METHOD_TO_URL, vfsResource);
+ }
+
+ static URI getURI(Object vfsResource) throws IOException {
+ return (URI) invokeVfsMethod(VIRTUAL_FILE_METHOD_TO_URI, vfsResource);
+ }
+
+ static String getName(Object vfsResource) {
+ try {
+ return (String) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_NAME, vfsResource);
+ }
+ catch (IOException ex) {
+ throw new IllegalStateException("Cannot get resource name", ex);
+ }
+ }
+
+ static Object getRelative(URL url) throws IOException {
+ return invokeVfsMethod(VFS_METHOD_GET_ROOT_URL, null, url);
+ }
+
+ static Object getChild(Object vfsResource, String path) throws IOException {
+ return invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_CHILD, vfsResource, path);
+ }
+
+ static File getFile(Object vfsResource) throws IOException {
+ return (File) invokeVfsMethod(GET_PHYSICAL_FILE, vfsResource);
+ }
+
+ static Object getRoot(URI url) throws IOException {
+ return invokeVfsMethod(VFS_METHOD_GET_ROOT_URI, null, url);
+ }
+
+ // protected methods used by the support sub-package
+
+ protected static Object getRoot(URL url) throws IOException {
+ return invokeVfsMethod(VFS_METHOD_GET_ROOT_URL, null, url);
+ }
+
+ protected static Object getVisitorAttribute() {
+ try{
+ return VISITOR_ATTRIBUTES_FIELD_RECURSE.get(null);
+ }
+ catch(Exception e){
+ ReflectionUtils.handleReflectionException(e);
+ return null; // never called
+ }
+ }
+
+ protected static String getPath(Object resource) {
+ try{
+ return (String) VIRTUAL_FILE_METHOD_GET_PATH_NAME.invoke(resource);
+ }
+ catch(Exception e){
+ ReflectionUtils.handleReflectionException(e);
+ return null; // never called
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java b/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java
new file mode 100644
index 0000000..dfe6cf7
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java
@@ -0,0 +1,46 @@
+/*
+* Copyright 2002-2012 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.tamaya.core.resources;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+* Simple interface for objects that are sources for an {@link InputStream}.
+*
+* <p>This is the base interface for the more extensive {@link Resource} interface.
+*
+* @author Juergen Hoeller
+* @since 20.01.2004
+* @see java.io.InputStream
+* @see Resource
+*/
+@FunctionalInterface
+public interface InputStreamSource {
+
+ /**
+ * Return an {@link InputStream}.
+ * <p>It is expected that each call creates a <i>fresh</i> stream.
+ * <p>This requirement is particularly important when you consider an API such
+ * as JavaMail, which needs to be able to read the stream multiple times when
+ * creating mail attachments. For such a use case, it is <i>required</i>
+ * that each {@code getInputStreamSupplier()} call returns a fresh stream.
+ * @return the input stream for the underlying resource (must not be {@code null})
+ * @throws IOException if the stream could not be opened
+ */
+ InputStream getInputStream() throws IOException;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/resources/Resource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resources/Resource.java b/core/src/main/java/org/apache/tamaya/core/resources/Resource.java
new file mode 100644
index 0000000..7ab27dc
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/resources/Resource.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.resources;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Objects;
+
+/**
+ * Interface for a resource descriptor that abstracts from the actual
+ * type current underlying resource, such as a file or class path resource.
+ *
+ * <p>An InputStream can be opened for every resource if it exists in
+ * physical form, but a URL or File handle can just be returned for
+ * certain resources. The actual behavior is implementation-specific.
+ *
+ * @author Juergen Hoeller
+ * @since 28.12.2003
+ * @see #getInputStream()
+ * @see #toURL()
+ * @see #getURI()
+ * @see #toFile()
+ */
+public interface Resource extends InputStreamSource {
+
+ /**
+ * Return whether this resource actually exists in physical form.
+ * <p>This method performs a definitive existence check, whereas the
+ * existence current a {@code Resource} handle only guarantees a
+ * valid descriptor handle.
+ */
+ default boolean exists() {
+ // Try file existence: can we find the file in the file system?
+ try {
+ return toFile().exists();
+ }
+ catch (IOException ex) {
+ // Fall back to stream existence: can we open the stream?
+ try {
+ InputStream is = getInputStream();
+ is.close();
+ return true;
+ }
+ catch (Throwable isEx) {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Return whether the contents current this resource can be read,
+ * e.g. via {@link #getInputStream()} or {@link #toFile()}.
+ * <p>Will be {@code true} for typical resource descriptors;
+ * note that actual content reading may still fail when attempted.
+ * However, a keys current {@code false} is a definitive indication
+ * that the resource content cannot be read.
+ * @see #getInputStream()
+ */
+ default boolean isReadable(){return true;}
+
+ /**
+ * Return whether this resource represents a handle with an open
+ * stream. If true, the InputStream cannot be read multiple times,
+ * and must be read and closed to avoid resource leaks.
+ * <p>Will be {@code false} for typical resource descriptors.
+ */
+ default boolean isOpen(){return false;}
+
+ /**
+ * Return a URL handle for this resource.
+ * @throws IOException if the resource cannot be resolved as URL,
+ * i.e. if the resource is not available as descriptor
+ */
+ default URL toURL() throws IOException{
+ return getURI().toURL();
+ }
+
+ /**
+ * Return a URI handle for this resource.
+ * @throws IOException if the resource cannot be resolved as URI,
+ * i.e. if the resource is not available as descriptor
+ */
+ default URI getURI() throws IOException{
+ URL url = toURL();
+ try {
+ return new URI(url.toString().replaceAll(" ", "%20"));
+ }
+ catch (URISyntaxException ex) {
+ throw new IllegalStateException("Invalid URI [" + url + "]", ex);
+ }
+ }
+
+ /**
+ * Return a File handle for this resource.
+ * @throws IOException if the resource cannot be resolved as absolute
+ * file path, i.e. if the resource is not available in a file system
+ */
+ default File toFile() throws IOException{
+ return new File(getURI());
+ }
+
+ /**
+ * Determine the content length for this resource.
+ * @throws IOException if the resource cannot be resolved
+ * (in the file system or as some other known physical resource type)
+ */
+ default long contentLength() throws IOException{
+ InputStream is = this.getInputStream();
+ Objects.requireNonNull(is, "resource input stream must not be null");
+ try {
+ long size = 0;
+ byte[] buf = new byte[255];
+ int read;
+ while ((read = is.read(buf)) != -1) {
+ size += read;
+ }
+ return size;
+ }
+ finally {
+ try {
+ is.close();
+ }
+ catch (IOException ex) {
+ }
+ }
+ }
+
+ /**
+ * Determine the last-modified timestamp for this resource.
+ * @throws IOException if the resource cannot be resolved
+ * (in the file system or as some other known physical resource type)
+ */
+ default long lastModified() throws IOException {
+ long lastModified = toFile().lastModified();
+ if (lastModified == 0L) {
+ throw new FileNotFoundException(getDisplayName() +
+ " cannot be resolved in the file system for resolving its last-modified timestamp");
+ }
+ return lastModified;
+ }
+
+ /**
+ * Create a resource relative to this resource.
+ * @param relativePath the relative path (relative to this resource)
+ * @return the resource handle for the relative resource
+ * @throws IOException if the relative resource cannot be determined
+ */
+ default Resource createRelative(String relativePath) throws IOException{
+ throw new FileNotFoundException("Cannot of a relative resource for " + getDisplayName());
+ }
+
+ /**
+ * Determine a filename for this resource, i.e. typically the last
+ * part current the path: for example, "myfile.txt".
+ * <p>Returns {@code null} if this type current resource does not
+ * have a filename.
+ */
+ default String getDisplayName(){
+ try{
+ return getURI().toString();
+ }
+ catch(Exception e){
+ return toString();
+ }
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java
new file mode 100644
index 0000000..ca071ca
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.resources;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Interface to be implemented by containers that decouples loading current resources from the effective
+ * classloader architecture. Implementations of this class encapsulate the mechanism of
+ * determining the concrete resources available base on an expression defining the configuration
+ * locations. A an example the expression {@code cfg/global/*.xml} defines a
+ * location for reading global configuration in the classpath. A resources
+ * interprets this expression and evaluates the concrete resources to be read,
+ * e.g. {@code cfg/global/default.xml, cfg/global/myApp.xml}.
+ */
+public interface ResourceLoader{
+
+ /**
+ * Called, when a given expression has to be resolved.
+ *
+ * @param expressions the expressions to be resolved, not empty.
+ * @return the corresponding collection current {@link java.net.URI}s defining the
+ * concrete resources to be read.
+ * .
+ */
+ default List<Resource> getResources(String... expressions) {
+ return getResources(Arrays.asList(expressions));
+ }
+
+
+ /**
+ * Called, when a given expression has to be resolved.
+ *
+ * @param expressions the expressions to be resolved, not empty.
+ * @return the corresponding collection current {@link java.net.URI}s defining the
+ * concrete resources to be read.
+ * .
+ */
+ default List<Resource> getResources(Collection<String> expressions) {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl==null){
+ cl = getClass().getClassLoader();
+ }
+ return getResources(cl, expressions);
+ }
+
+ /**
+ * Called, when a given expression has to be resolved.
+ *
+ * @param expressions the expressions to be resolved, not empty.
+ * @return the corresponding collection current {@link java.net.URI}s defining the
+ * concrete resources to be read.
+ * .
+ */
+ default List<Resource> getResources(ClassLoader classLoader, String... expressions) {
+ return getResources(classLoader, Arrays.asList(expressions));
+ }
+
+ /**
+ * Called, when a given expression has to be resolved.
+ *
+ * @param expressions the expressions to be resolved, not empty.
+ * @return the corresponding collection current {@link org.apache.tamaya.core.resources.Resource}s defining the
+ * concrete resources to be read.
+ * .
+ */
+ List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions);
+
+}
[05/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
deleted file mode 100644
index 1c41820..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-import org.apache.tamaya.core.properties.ConfigurationFormat;
-import org.apache.tamaya.core.resource.Resource;
-
-import java.util.Collection;
-
-/**
- * Created by Anatole on 17.09.2014.
- */
-public interface ConfigurationFormatSpi {
- /**
- * Access a {@link org.apache.tamaya.core.properties.ConfigurationFormat}.
- *
- * @param formatName the format name
- * @return the corresponding {@link org.apache.tamaya.core.properties.ConfigurationFormat}, or {@code null}, if
- * not available for the given environment.
- */
- ConfigurationFormat getFormat(String formatName);
-
- /**
- * Get a collection current the keys current the registered {@link org.apache.tamaya.core.properties.ConfigurationFormat} instances.
- *
- * @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
- */
- Collection<String> getFormatNames();
-
- /**
- * Evaluate the matching format for a given resource.
- *
- * @param resource The resource
- * @return a matching configuration format, or {@code null} if no matching format could be determined.
- */
- ConfigurationFormat getFormat(Resource resource);
-
- default ConfigurationFormat getPropertiesFormat(){
- return getFormat("properties");
- }
-
- default ConfigurationFormat getXmlPropertiesFormat(){
- return getFormat("xml-properties");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationProviderSpi.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationProviderSpi.java
deleted file mode 100644
index e60a53d..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationProviderSpi.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-import org.apache.tamaya.Configuration;
-
-/**
-* This configuration provider SPI allows to register the effective factory logic to of and manage a configuration
-* instance. Hereby the qualifiers determine the type current configuration. By default
-*/
-public interface ConfigurationProviderSpi{
-
- /**
- * Returns the name current the configuration provided.
- * @return the name current the configuration provided, not empty.
- */
- String getConfigName();
-
- /**
- * Get the {@link Configuration}, if available.
- * @return according configuration, or null, if none is available for the given environment.
- */
- Configuration getConfiguration();
-
- /**
- * Reloads the provider for the current context.
- */
- void reload();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/DefaultServiceComparator.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/DefaultServiceComparator.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/DefaultServiceComparator.java
deleted file mode 100644
index 2fb719c..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/DefaultServiceComparator.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-import java.util.*;
-
-/**
- * Simple comparator based on a Collection of {@link OrdinalProvider} instances.
- */
-final class DefaultServiceComparator implements Comparator<Object>{
-
- /**
- * List of ordinal providers loaded.
- */
- private List<OrdinalProvider> ordinalProviders = new ArrayList<>();
-
- DefaultServiceComparator(Collection<? extends OrdinalProvider> providers){
- ordinalProviders.addAll(Objects.requireNonNull(providers));
- ordinalProviders.sort(this::compare);
- }
-
- private int compare(OrdinalProvider provider1, OrdinalProvider provider2){
- int o1 = getOrdinal(provider1);
- int o2 = getOrdinal(provider2);
- int order = o1-o2;
- if(order < 0){
- return -1;
- }
- else if(order > 0){
- return 1;
- }
- return 0;
- }
-
- private int getOrdinal(OrdinalProvider provider){
- if(provider instanceof Orderable){
- return ((Orderable)provider).order();
- }
- return 0;
- }
-
- public int getOrdinal(Object service){
- for(OrdinalProvider provider: ordinalProviders){
- OptionalInt ord = provider.getOrdinal(service.getClass());
- if(ord.isPresent()){
- return ord.getAsInt();
- }
- }
- if(service instanceof Orderable){
- return ((Orderable)service).order();
- }
- return 0;
- }
-
-
- @Override
- public int compare(Object o1, Object o2) {
- int ord1 = getOrdinal(o1);
- int ord2 = getOrdinal(o2);
- int order = ord1-ord2;
- if(order < 0){
- return -1;
- }
- else if(order > 0){
- return 1;
- }
- return 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/DefaultServiceContextProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/DefaultServiceContextProvider.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/DefaultServiceContextProvider.java
deleted file mode 100644
index 9a2fb1b..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/DefaultServiceContextProvider.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
- * {@link java.util.ServiceLoader} to load the services required.
- */
-@SuppressWarnings({"rawtypes", "unchecked"})
-class DefaultServiceContextProvider implements ServiceContext {
- /** List current services loaded, per class. */
- private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
- /** Singletons. */
- private final ConcurrentHashMap<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
- /** Comparator for ordering of multiple services found. */
- private DefaultServiceComparator serviceComparator;
-
- public DefaultServiceContextProvider(){
- serviceComparator = new DefaultServiceComparator(getServices(OrdinalProvider.class, Collections.emptyList()));
- }
-
- @Override
- public <T> Optional<T> getService(Class<T> serviceType) {
- Optional<T> cached = (Optional<T>)singletons.get(serviceType);
- if(cached==null) {
- List<? extends T> services = getServices(serviceType, Collections.emptyList());
- if (services.isEmpty()) {
- cached = Optional.empty();
- }
- else{
- cached = Optional.of(services.get(0));
- }
- singletons.put(serviceType, cached);
- }
- return cached;
- }
-
- /**
- * Loads and registers services.
- *
- * @param serviceType
- * The service type.
- * @param <T>
- * the concrete type.
- * @param defaultList
- * the list current items returned, if no services were found.
- * @return the items found, never {@code null}.
- */
- @Override
- public <T> List<? extends T> getServices(final Class<T> serviceType, final List<? extends T> defaultList) {
- List<T> found = (List<T>) servicesLoaded.get(serviceType);
- if (found != null) {
- return found;
- }
- return loadServices(serviceType, defaultList);
- }
-
- /**
- * Loads and registers services.
- *
- * @param serviceType The service type.
- * @param <T> the concrete type.
- * @param defaultList the list current items returned, if no services were found.
- *
- * @return the items found, never {@code null}.
- */
- private <T> List<? extends T> loadServices(final Class<T> serviceType, final List<? extends T> defaultList) {
- try {
- List<T> services = new ArrayList<>();
- for (T t : ServiceLoader.load(serviceType)) {
- services.add(t);
- }
- if(services.isEmpty()){
- services.addAll(defaultList);
- }
- if(!serviceType.equals(OrdinalProvider.class)) {
- services.sort(serviceComparator);
- }
- services = Collections.unmodifiableList(services);
- final List<T> previousServices = (List<T>) servicesLoaded.putIfAbsent(serviceType, (List<Object>)services);
- return previousServices != null ? previousServices : services;
- } catch (Exception e) {
- Logger.getLogger(DefaultServiceContextProvider.class.getName()).log(Level.WARNING,
- "Error loading services current type " + serviceType, e);
- return defaultList;
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java
deleted file mode 100644
index 5baa956..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-import org.apache.tamaya.Configuration;
-
-/**
- * This interfaces provides a model for expression evaluation. This enables transparently plugin expression languages
- * as needed. In a Java EE context full fledged EL may be used, whereas in ME only simple replacement mechanisms
- * are better suited to the runtime requirements.
- */
-@FunctionalInterface
-public interface ExpressionEvaluator {
- /**
- * Evaluates the given expression.
- * @param expression the expression to be evaluated, not null.
- * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
- * If no items are passed, the default configuration is used.
- * @return the evaluated expression.
- */
- String evaluate(String expression, Configuration... configurations);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java
deleted file mode 100644
index a6ba9bb..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-import org.apache.tamaya.Configuration;
-
-/**
- * This interface defines a small plugin for resolving current expressions within configuration.
- * Resolver expression always have the form current <code>${resolverId:expression}</code>. The
- * {@code resolverId} hereby references the resolver to be used to replace the according
- * {@code expression}. Also it is well possible to mix different resolvers, e.g. using
- * an expression like <code>${ref1:expression1} bla bla ${ref2:expression2}</code>.
- * Finally when no resolver id is passed, the default resolver should be used.
- */
-public interface ExpressionResolver {
-
- /**
- * Get a (unique) resolver id used as a prefix for qualifying the resolver to be used for
- * resolving an expression.
- *
- * @return the (unique) resolver id, never null, not empty.
- */
- String getResolverId();
-
- /**
- * Resolve the expression. The expression should be stripped fromMap any surrounding parts.
- * E.g. <code>${myresolver:blabla to be interpreted AND executed.}</code> should be passed
- * as {@code blabla to be interpreted AND executed.} only.
- *
- * @param expression the stripped expression.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
- * If no such config is passed, the default configurations provided by the current
- * registered providers are used.
- * @return the resolved expression.
- * @throws org.apache.tamaya.ConfigException when the expression passed is not resolvable, e.g. due to syntax issues
- * or data not present or valid.
- */
- String resolve(String expression, Configuration... configurations);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/Orderable.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/Orderable.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/Orderable.java
deleted file mode 100644
index 5397776..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/Orderable.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-/**
- * Interface that can be optionally implemented by SPI components to be loaded into
- * the Tamaya's ServiceContext. The ordinal provided will be used to determine
- * priority and precedence, when multiple components implement the same
- * service interface.
- */
-@FunctionalInterface
-public interface Orderable {
- /**
- * Get the ordinal keys for the component, by default 0.
- * @return the ordinal keys
- */
- int order();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/OrdinalProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/OrdinalProvider.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/OrdinalProvider.java
deleted file mode 100644
index 2d7f057..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/OrdinalProvider.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-import java.util.OptionalInt;
-
-/**
- * The ordinal provider is an optional component that provides an abstraction for ordering/prioritizing
- * services loaded. This can be used to determine, which SPI should be used, if multiple instances are
- * available, or for ordering chain of services.
- * @see org.apache.tamaya.spi.ServiceContext
- */
-public interface OrdinalProvider {
- /**
- * Evaluate the ordinal number for the given type.
- * @param type the target type, not null.
- * @return the ordinal, if not defined, 0 should be returned.
- */
- OptionalInt getOrdinal(Class<?> type);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterProviderSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterProviderSpi.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterProviderSpi.java
deleted file mode 100644
index b8e7122..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterProviderSpi.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.spi;
-
-import org.apache.tamaya.PropertyAdapter;
-
-/**
- * This service provides different {@link org.apache.tamaya.PropertyAdapter} instances for types.
- */
-public interface PropertyAdapterProviderSpi {
-
- /**
- * Called, when a given {@link org.apache.tamaya.Configuration} has to be evaluated.
- *
- * @return the corresponding {@link java.util.function.Function<String, T>}, or {@code null}, if
- * not available for the given target type.
- */
- <T> PropertyAdapter<T> getPropertyAdapter(Class<T> type);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java b/dormant/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
deleted file mode 100644
index 9270636..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
+++ /dev/null
@@ -1,64 +0,0 @@
-///*
-// * Licensed to the Apache Software Foundation (ASF) under one
-// * or more contributor license agreements. See the NOTICE file
-// * distributed with this work for additional information
-// * regarding copyright ownership. The ASF licenses this file
-// * to you under the Apache License, Version 2.0 (the
-// * "License"); you may not use this file except in compliance
-// * with the License. You may obtain a copy of the License at
-// *
-// * http://www.apache.org/licenses/LICENSE-2.0
-// *
-// * Unless required by applicable law or agreed to in writing,
-// * software distributed under the License is distributed on an
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// * KIND, either express or implied. See the License for the
-// * specific language governing permissions and limitations
-// * under the License.
-// */
-//package org.apache.tamaya.core.spi;
-//
-//import java.io.File;
-//import java.io.InputStream;
-//import java.net.URL;
-//import java.util.List;
-//import java.util.Map;
-//import java.util.Set;
-//
-//import org.apache.tamaya.Codec;
-//
-//@SuppressWarnings("unchecked")
-//public interface PropertyAdapterService{
-//
-// public default Codec<URL> getURLAdapter(){
-// return Codec.class.cast(getClassAdapter(URL.class));
-// }
-//
-// public default Codec<InputStream> getClasspathResourceAdapter(){
-// return Codec.class.cast(getClassAdapter(InputStream.class));
-// }
-//
-// public default Codec<File> getFileAdapter(){
-// return Codec.class.cast(getClassAdapter(File.class));
-// }
-//
-// public default Codec<Set<String>> getSetAdapter(){
-// return Codec.class.cast(getClassAdapter(Set.class));
-// }
-//
-// public default Codec<Map<String, String>> getMapAdapter(){
-// return Codec.class.cast(getClassAdapter(Map.class));
-// }
-//
-// public default Codec<List<String>> getListAdapter(){
-// return Codec.class.cast(getClassAdapter(List.class));
-// }
-//
-// public default <T> Codec<Class<? extends T>> getClassAdapter(Class<T> requiredType){
-// return getClassAdapter(requiredType, Thread.currentThread().getContextClassLoader());
-// }
-//
-// public <T> Codec<Class<? extends T>> getClassAdapter(Class<T> requiredType,
-// ClassLoader... classLoaders);
-//
-//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/resources/META-INF/services/old.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/resources/META-INF/services/old.ConfigurationProviderSpi b/dormant/core/src/main/resources/META-INF/services/old.ConfigurationProviderSpi
new file mode 100644
index 0000000..4c964b9
--- /dev/null
+++ b/dormant/core/src/main/resources/META-INF/services/old.ConfigurationProviderSpi
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+old.SystemPropertiesConfigProvider
+old.EnvPropertiesConfigProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.ConfigurationFormat b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.ConfigurationFormat
new file mode 100644
index 0000000..7aa2407
--- /dev/null
+++ b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.ConfigurationFormat
@@ -0,0 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.format.PropertiesFormat
+org.apache.tamaya.core.internal.format.PropertiesXmlFormat
+org.apache.tamaya.core.internal.format.IniFormat
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat
deleted file mode 100644
index 7aa2407..0000000
--- a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.format.PropertiesFormat
-org.apache.tamaya.core.internal.format.PropertiesXmlFormat
-org.apache.tamaya.core.internal.format.IniFormat
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader
deleted file mode 100644
index c245d54..0000000
--- a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resource.ResourceLoader
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.resources.DefaultResourceLoader
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
new file mode 100644
index 0000000..c245d54
--- /dev/null
+++ b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.resources.DefaultResourceLoader
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
deleted file mode 100644
index 9865949..0000000
--- a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.config.SystemPropertiesConfigProvider
-org.apache.tamaya.core.internal.config.EnvPropertiesConfigProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
index 2764092..1c7d005 100644
--- a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
+++ b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.core.internal.config.DefaultConfigurationSpi
\ No newline at end of file
+old.DefaultConfigurationSpi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
index 0554453..0f48c84 100644
--- a/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
+++ b/dormant/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.core.internal.config.DefaultPropertyAdapterSpi
+org.apache.tamaya.core.internal.DefaultPropertyAdapterSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java b/dormant/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java
index 2ee83a9..514cda6 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/DefaultConfigurationManagerSingletonSpiSingletonSpiTest.java
@@ -25,11 +25,11 @@ import static org.junit.Assert.assertTrue;
import org.apache.tamaya.annotation.ConfiguredProperty;
import org.apache.tamaya.annotation.DefaultValue;
-import org.apache.tamaya.core.internal.config.DefaultConfigurationSpi;
+import old.DefaultConfigurationSpi;
import org.junit.Test;
/**
- * Test class for {@link org.apache.tamaya.core.internal.config.DefaultConfigurationSpi}.
+ * Test class for {@link old.DefaultConfigurationSpi}.
*/
public class DefaultConfigurationManagerSingletonSpiSingletonSpiTest {
@@ -60,7 +60,7 @@ public class DefaultConfigurationManagerSingletonSpiSingletonSpiTest {
@Test
public void testIsConfigurationDefined() {
- assertTrue(Configuration.isAvailable("test"));
+ assertTrue(Configuration.isAvailable("testdata"));
assertFalse(Configuration.isAvailable("sdksajdsajdlkasj dlkjaslkd"));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/JavaOneDemo.java b/dormant/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
index 77cbf94..27ae481 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
@@ -44,7 +44,7 @@ public class JavaOneDemo {
@Test
public void testProgrammatixPropertySet() {
- System.out.println(PropertySourceBuilder.of("test").addPaths("test", "classpath:test.properties"));
+ System.out.println(PropertySourceBuilder.of("testdata").addPaths("testdata", "classpath:testdata.properties"));
}
@Test
@@ -54,7 +54,7 @@ public class JavaOneDemo {
cfgMap.put("param1", "value1");
cfgMap.put("a", "Adrian"); // overrides Anatole
Configuration config = Configuration.from(PropertySourceBuilder.of("myTestConfig").addPaths(
- "classpath:test.properties").addPaths("classpath:cfg/test.xml")
+ "classpath:testdata.properties").addPaths("classpath:cfg/testdata.xml")
.addArgs(new String[]{"-arg1", "--fullarg", "fullValue", "-myflag"})
.addMap(cfgMap).build());
System.out.println(config.query(ConfigurationFunctions.getAreas()));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java b/dormant/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
index b02a58f..644ef0a 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
@@ -28,7 +28,7 @@
//import static org.junit.Assert.assertFalse;
//
///**
-// * Simple test for a mutable Configuration instance.
+// * Simple testdata for a mutable Configuration instance.
// */
//public class MutableConfigTest {
//
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProviderTest.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProviderTest.java b/dormant/core/src/test/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProviderTest.java
index 5aeeec5..276d16e 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProviderTest.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProviderTest.java
@@ -15,7 +15,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+import old.ConfigurationProviderSpi;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/core/properties/PropertySourceBuilderTest.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/core/properties/PropertySourceBuilderTest.java b/dormant/core/src/test/java/org/apache/tamaya/core/properties/PropertySourceBuilderTest.java
index 4a846f9..f7e73f3 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/core/properties/PropertySourceBuilderTest.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/core/properties/PropertySourceBuilderTest.java
@@ -33,7 +33,7 @@ public class PropertySourceBuilderTest {
@Test
public void testFromEnvironmentProperties(){
- PropertySource prov = PropertySourceBuilder.of("test").addEnvironmentProperties().build();
+ PropertySource prov = PropertySourceBuilder.of("testdata").addEnvironmentProperties().build();
assertNotNull(prov);
for(Map.Entry<String,String> en:System.getenv().entrySet()){
assertEquals(en.getValue(), prov.get(en.getKey()).get());
@@ -42,7 +42,7 @@ public class PropertySourceBuilderTest {
@Test
public void testFromSystemProperties(){
- PropertySource prov = PropertySourceBuilder.of("test").addSystemProperties().build();
+ PropertySource prov = PropertySourceBuilder.of("testdata").addSystemProperties().build();
assertNotNull(prov);
for(Map.Entry<Object,Object> en:System.getProperties().entrySet()){
assertEquals(en.getValue(), prov.get(en.getKey().toString()).get());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java b/dormant/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
index bf8d709..41140ab 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
@@ -24,10 +24,10 @@
//import java.util.concurrent.ConcurrentHashMap;
//
//import org.apache.tamaya.Configuration;
-//import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+//import old.ConfigurationProviderSpi;
//
///**
-// * Simple test provider that creates a mutable instance of a configuration, just using a simple map instance.
+// * Simple testdata provider that creates a mutable instance of a configuration, just using a simple map instance.
// */
//public class MutableTestConfigProvider implements ConfigurationProviderSpi{
// /** The config name. */
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java b/dormant/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
index ddbe4af..e8ec52a 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.internal;
import org.apache.tamaya.PropertySource;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+import old.ConfigurationProviderSpi;
import org.apache.tamaya.Configuration;
@@ -48,13 +48,13 @@ public class TestConfigProvider implements ConfigurationProviderSpi{
config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
config.put("testProperty", "keys current testProperty");
config.put("runtimeVersion", "${java.version}");
- testConfig = Configuration.from(PropertySourceBuilder.of("test").addMap(
+ testConfig = Configuration.from(PropertySourceBuilder.of("testdata").addMap(
config).build());
}
@Override
public String getConfigName(){
- return "test";
+ return "testdata";
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java b/dormant/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java
index c01ee63..70e18cf 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java
@@ -39,7 +39,7 @@ public class ConfiguredClass{
@DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
String value1;
- @ConfiguredProperty(config="test", keys = "foo")
+ @ConfiguredProperty(config="testdata", keys = "foo")
@ConfiguredProperty(keys = "a.b.c.key2")
private String value2;
@@ -55,13 +55,13 @@ public class ConfiguredClass{
@DefaultValue("5")
private Integer int1;
- @ConfiguredProperty(config = "test")
+ @ConfiguredProperty(config = "testdata")
private int int2;
- @ConfiguredProperty(config = "test")
+ @ConfiguredProperty(config = "testdata")
private boolean booleanT;
- @ConfiguredProperty(config="test", keys ="BD")
+ @ConfiguredProperty(config="testdata", keys ="BD")
private BigDecimal bigNumber;
@ObservesConfigChange
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/samples/devops/DeploymentProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/samples/devops/DeploymentProvider.java b/dormant/core/src/test/java/org/apache/tamaya/samples/devops/DeploymentProvider.java
index 18e6705..97371e3 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/samples/devops/DeploymentProvider.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/samples/devops/DeploymentProvider.java
@@ -28,8 +28,8 @@ public class DeploymentProvider {
// System.out.println(service.getCurrentContext());
// // Access default configuration for current environment
// DefaultEnvironment myTarget = new DefaultEnvironment();
- // myTarget.setAttribute("domain", "com.test.mydom:domain1:1.0.1");
- // myTarget.setAttribute("application", "com.test.mydom:app1:1.0.1");
+ // myTarget.setAttribute("domain", "com.testdata.mydom:domain1:1.0.1");
+ // myTarget.setAttribute("application", "com.testdata.mydom:app1:1.0.1");
// myTarget.setAttribute("env", "localTest");
// myTarget.setStage(Stage.UnitTest);
// Configuration deploymentConfig =
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java b/dormant/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
index e0351b2..711ce5f 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
@@ -38,7 +38,7 @@ public class SimplePropertiesAndCLISample {
@Test
public void testProgrammatixPropertySet() {
- System.out.println(PropertySourceBuilder.of("test").addPaths("test", "classpath:test.properties").build());
+ System.out.println(PropertySourceBuilder.of("testdata").addPaths("testdata", "classpath:testdata.properties").build());
}
@Test
@@ -48,7 +48,7 @@ public class SimplePropertiesAndCLISample {
cfgMap.put("param1", "value1");
cfgMap.put("a", "Adrian"); // overrides Anatole
Configuration config = Configuration.from(PropertySourceBuilder.of("myTestConfig").addPaths(
- "classpath:test.properties").addPaths("classpath:cfg/test.xml")
+ "classpath:testdata.properties").addPaths("classpath:cfg/testdata.xml")
.addArgs(new String[]{"-arg1", "--fullarg", "fullValue", "-myflag"}).addMap(cfgMap)
.build());
System.out.println(config.query(ConfigurationFunctions.getAreas()));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java b/dormant/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
index e7f2049..423ec94 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
@@ -61,7 +61,7 @@ public class UC1ReadProperties {
@Test
public void example() {
- Configuration config = Configuration.from(PropertySourceBuilder.of("test")
+ Configuration config = Configuration.from(PropertySourceBuilder.of("testdata")
.addPaths("classpath:ucs/UC1ReadProperties/UC1ReadPropertiesTest.properties").build());
// String name = config.get("name").orElse("Anatole");
// BigDecimal bigNum = config.get("num.BD", BigDecimal.class).orElseThrow(() -> new IllegalStateException("Sorry"));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java b/dormant/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
index 60ab6ea..76c6132 100644
--- a/dormant/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
+++ b/dormant/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
@@ -27,7 +27,7 @@ import org.junit.Test;
/**
* Configuration is organized as key/keys pairs. This basically can be modeled as {@code Map<String,String>}
* Configuration should be as simple as possible. Advanced use cases can often easily implemented by combining
- * multiple property maps and applying hereby some combination policy. This test class demonstrates the different
+ * multiple property maps and applying hereby some combination policy. This testdata class demonstrates the different
* options Tamaya is providing and the according mechanisms.
*/
public class UC2CombineProperties {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/resources/META-INF/services/old.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/resources/META-INF/services/old.ConfigurationProviderSpi b/dormant/core/src/test/resources/META-INF/services/old.ConfigurationProviderSpi
new file mode 100644
index 0000000..c4ba801
--- /dev/null
+++ b/dormant/core/src/test/resources/META-INF/services/old.ConfigurationProviderSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.internal.TestConfigProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi b/dormant/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
deleted file mode 100644
index c4ba801..0000000
--- a/dormant/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.internal.TestConfigProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/resources/cfg/autoloaded.xml
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/resources/cfg/autoloaded.xml b/dormant/core/src/test/resources/cfg/autoloaded.xml
index b64cb76..07f6c13 100644
--- a/dormant/core/src/test/resources/cfg/autoloaded.xml
+++ b/dormant/core/src/test/resources/cfg/autoloaded.xml
@@ -23,7 +23,7 @@ under the License.
<entry key="b">Bill</entry>
<entry key="a.compound.area.entry">myCompundAreaVlaueFromXml</entry>
<entry key="an.area.entry">myCompundAreaVlaueFromXml2</entry>
- <!-- DirectMapping test -->
+ <!-- DirectMapping testdata -->
<entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.value1">This \${JAVA_HOME} is cool!</entry>
<entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.value2">Should not be set because @NoConfig !</entry>
<entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.testProperty">a test property value</entry>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/test/resources/cfg/test.xml
----------------------------------------------------------------------
diff --git a/dormant/core/src/test/resources/cfg/test.xml b/dormant/core/src/test/resources/cfg/test.xml
index b64cb76..07f6c13 100644
--- a/dormant/core/src/test/resources/cfg/test.xml
+++ b/dormant/core/src/test/resources/cfg/test.xml
@@ -23,7 +23,7 @@ under the License.
<entry key="b">Bill</entry>
<entry key="a.compound.area.entry">myCompundAreaVlaueFromXml</entry>
<entry key="an.area.entry">myCompundAreaVlaueFromXml2</entry>
- <!-- DirectMapping test -->
+ <!-- DirectMapping testdata -->
<entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.value1">This \${JAVA_HOME} is cool!</entry>
<entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.value2">Should not be set because @NoConfig !</entry>
<entry key="org.apache.tamaya.samples.annotations.AutoConfiguredClass.testProperty">a test property value</entry>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/integration/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/dormant/modules/integration/cdi/pom.xml b/dormant/modules/integration/cdi/pom.xml
deleted file mode 100644
index 1909bcc..0000000
--- a/dormant/modules/integration/cdi/pom.xml
+++ /dev/null
@@ -1,178 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.integration</groupId>
- <artifactId>tamaya-integration-all</artifactId>
- <version>0.1-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>tamaya-cdi</artifactId>
- <name>Apache Tamaya Modules Integration - CDI</name>
- <packaging>jar</packaging>
-
- <properties>
- <owb.version>1.5.0-SNAPSHOT</owb.version>
- <weld.version>2.2.7.Final</weld.version>
- <geronimo-jcdi-1.1-spec.version>1.0-SNAPSHOT</geronimo-jcdi-1.1-spec.version>
- <geronimo-interceptor-1.2-spec.version>1.0-SNAPSHOT</geronimo-interceptor-1.2-spec.version>
- <geronimo-atinject-1.0-spec.version>1.0</geronimo-atinject-1.0-spec.version>
- <bval.version>0.5</bval.version>
- <ds.version>1.1.0</ds.version>
- </properties>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>prepare-agent</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jcdi_1.1_spec</artifactId>
- <version>${geronimo-jcdi-1.1-spec.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.deltaspike.modules</groupId>
- <artifactId>deltaspike-test-control-module-api</artifactId>
- <version>${ds.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.deltaspike.modules</groupId>
- <artifactId>deltaspike-test-control-module-impl</artifactId>
- <version>${ds.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <profiles>
- <profile>
- <id>OWB</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <dependencies>
- <!-- OWB specific dependencies-->
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-atinject_1.0_spec</artifactId>
- <version>${geronimo-atinject-1.0-spec.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-interceptor_1.2_spec</artifactId>
- <version>${geronimo-interceptor-1.2-spec.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-annotation_1.2_spec</artifactId>
- <version>1.0.MR2-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-el_2.2_spec</artifactId>
- <version>1.0.2</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.openwebbeans</groupId>
- <artifactId>openwebbeans-impl</artifactId>
- <version>${owb.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.openwebbeans</groupId>
- <artifactId>openwebbeans-spi</artifactId>
- <version>${owb.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.openwebbeans</groupId>
- <artifactId>openwebbeans-resource</artifactId>
- <version>${owb.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.bval</groupId>
- <artifactId>bval-jsr303</artifactId>
- <version>${bval.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.deltaspike.cdictrl</groupId>
- <artifactId>deltaspike-cdictrl-owb</artifactId>
- <version>${ds.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </profile>
- <profile>
- <id>Weld</id>
- <dependencies>
- <dependency>
- <groupId>org.jboss.weld.se</groupId>
- <artifactId>weld-se</artifactId>
- <version>${weld.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.deltaspike.cdictrl</groupId>
- <artifactId>deltaspike-cdictrl-weld</artifactId>
- <version>${ds.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </profile>
- </profiles>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
----------------------------------------------------------------------
diff --git a/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java b/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
index ea47dd6..ba92b3e 100644
--- a/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
+++ b/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
@@ -35,7 +35,7 @@ import org.apache.tamaya.annotation.ObservesConfigChange;
@Singleton
public class ConfiguredClass{
-// @WithConfig("test")
+// @WithConfig("testdata")
@ConfiguredProperty
private String testProperty;
@@ -45,7 +45,7 @@ public class ConfiguredClass{
@DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
String value1;
-// @WithConfig("test")
+// @WithConfig("testdata")
@ConfiguredProperty(keys = "foo")
@ConfiguredProperty(keys = "a.b.c.key2")
private String value2;
@@ -62,19 +62,19 @@ public class ConfiguredClass{
@DefaultValue("5")
private Integer int1;
-// @WithConfig("test")
+// @WithConfig("testdata")
@ConfiguredProperty
private int int2;
-// @WithConfig("test")
+// @WithConfig("testdata")
@ConfiguredProperty
private boolean booleanT;
-// @WithConfig("test")
+// @WithConfig("testdata")
@ConfiguredProperty(keys = "BD")
private BigDecimal bigNumber;
-// @WithConfig("test")
+// @WithConfig("testdata")
@ConfiguredProperty(keys = "double1")
private double doubleValue;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java b/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java
index a0de005..a10422c 100644
--- a/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java
+++ b/dormant/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.integration.cdi;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+import old.ConfigurationProviderSpi;
import java.util.HashMap;
import java.util.Map;
@@ -49,12 +49,12 @@ public class TestConfigProvider implements ConfigurationProviderSpi
config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
config.put("testProperty", "keys current testProperty");
config.put("runtimeVersion", "${java.version}");
- testConfig = PropertySourceBuilder.of("test").addMap(config).build().toConfiguration();
+ testConfig = PropertySourceBuilder.of("testdata").addMap(config).build().toConfiguration();
}
@Override
public String getConfigName(){
- return "test";
+ return "testdata";
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/integration/managed/pom.xml
----------------------------------------------------------------------
diff --git a/dormant/modules/integration/managed/pom.xml b/dormant/modules/integration/managed/pom.xml
deleted file mode 100644
index 3b4f5bc..0000000
--- a/dormant/modules/integration/managed/pom.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.integration</groupId>
- <artifactId>tamaya-integration-all</artifactId>
- <version>0.1-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>tamaya-integration-managed</artifactId>
- <name>Apache Tamaya Modules Integration - Java Management Extensions</name>
- <packaging>jar</packaging>
-
- <properties>
- </properties>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>prepare-agent</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java
----------------------------------------------------------------------
diff --git a/dormant/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java b/dormant/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java
index ef3b861..b7cdfc3 100644
--- a/dormant/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java
+++ b/dormant/modules/integration/managed/src/main/java/org/apache/tamaya/management/ManagedEnvironmentMBean.java
@@ -39,7 +39,7 @@ public interface ManagedEnvironmentMBean {
* Get the common environment information in JSON format, which has the following form:
* <pre>
* Environment {
- * id: "system:VM,domain:test",
+ * id: "system:VM,domain:testdata",
* metaInfo {
* a: "aValue",
* b: "bValue"
@@ -74,7 +74,7 @@ public interface ManagedEnvironmentMBean {
* typeHierarchy: {"system", "domain", "ear", "war", "saas-scope", "tenant"}
* environments {
* Environment {
- * id: "system:VM,domain:test",
+ * id: "system:VM,domain:testdata",
* ...
* },
* ...
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/integration/pom.xml
----------------------------------------------------------------------
diff --git a/dormant/modules/integration/pom.xml b/dormant/modules/integration/pom.xml
deleted file mode 100644
index 33deee1..0000000
--- a/dormant/modules/integration/pom.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>tamaya-ext-all</artifactId>
- <groupId>org.apache.tamaya.ext</groupId>
- <version>0.1-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <packaging>pom</packaging>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.tamaya.integration</groupId>
- <artifactId>tamaya-integration-all</artifactId>
-
- <modules>
- <module>managed</module>
- <module>cdi</module>
- <module>se</module>
- </modules>
-
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/metamodels/environment/pom.xml
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/pom.xml b/dormant/modules/metamodels/environment/pom.xml
deleted file mode 100644
index cf8fd91..0000000
--- a/dormant/modules/metamodels/environment/pom.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.metamodels</groupId>
- <artifactId>tamaya-metamodels-all</artifactId>
- <version>0.1-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>tamaya-metamodel-environment</artifactId>
- <name>Apache Tamaya Modules Metamodels - environment</name>
- <description>Environment Tamaya Metamodel</description>
- <packaging>jar</packaging>
-
- <properties>
- <jdkVersion>1.8</jdkVersion>
- <maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
- <maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
- </properties>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>prepare-agent</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>${maven.compile.sourceLevel}</source>
- <target>${maven.compile.targetLevel}</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java b/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
index 5abdd8e..e9ff31b 100644
--- a/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
+++ b/dormant/modules/metamodels/environment/src/test/java/org/apache/tamaya/metamodel/environment/EnvironmentManagerTest.java
@@ -54,7 +54,7 @@ public class EnvironmentManagerTest {
Environment env2 = Environment.current();
assertNotNull(env1);
assertNotNull(env2);
- // within this test environment these are always the same
+ // within this testdata environment these are always the same
assertEquals(env1, env2);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/metamodels/pom.xml
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/pom.xml b/dormant/modules/metamodels/pom.xml
deleted file mode 100644
index 74b338f..0000000
--- a/dormant/modules/metamodels/pom.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-ext-all</artifactId>
- <version>0.1-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <groupId>org.apache.tamaya.metamodels</groupId>
- <artifactId>tamaya-metamodels-all</artifactId>
- <name>Apache Tamaya Modules Metamodels</name>
- <packaging>pom</packaging>
-
- <properties>
- <github.global.server>github</github.global.server>
- <jdkVersion>1.8</jdkVersion>
- <maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
- <maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
- </properties>
-
- <modules>
- <module>simple</module>
- <module>environment</module>
- </modules>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/metamodels/simple/pom.xml
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/simple/pom.xml b/dormant/modules/metamodels/simple/pom.xml
deleted file mode 100644
index 792a045..0000000
--- a/dormant/modules/metamodels/simple/pom.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.metamodels</groupId>
- <artifactId>tamaya-metamodels-all</artifactId>
- <version>0.1-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>tamaya-metamodel-simple</artifactId>
- <name>Apache Tamaya Modules Metamodels - Simple</name>
- <description>Simple Tamaya Metamodel, e.g. feasible for SE commandline tools and simple use cases.</description>
- <packaging>jar</packaging>
-
- <properties>
- <jdkVersion>1.8</jdkVersion>
- <maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
- <maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
- </properties>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>prepare-agent</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>${maven.compile.sourceLevel}</source>
- <target>${maven.compile.targetLevel}</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/old.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/old.ConfigurationProviderSpi b/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/old.ConfigurationProviderSpi
new file mode 100644
index 0000000..b3a2634
--- /dev/null
+++ b/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/old.ConfigurationProviderSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.metamodel.simple.SimpleConfigProvider
\ No newline at end of file
[06/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java
deleted file mode 100644
index 3f8a0b1..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFactory.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import java.net.URL;
-import java.time.Instant;
-import java.util.*;
-import java.util.function.BiFunction;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
-
-import org.apache.tamaya.PropertySource;
-
-/**
- * Default implementation current the singleton backing bean for the {@link org.apache.tamaya.core.properties.PropertySourceBuilder}.
- */
-public final class PropertySourceFactory {
-
- private static final PropertySource EMPTY_PROPERTYSOURCE = fromMap("<empty>", Collections.emptyMap());
- private static final PropertySource ENV_PROPERTYSOURCE = new EnvironmentPropertySource();
-
-
- /**
- * Singleton constructor.
- */
- private PropertySourceFactory(){}
-
- public static PropertySource fromArgs(String name, String... args) {
- if(name==null){
- name ="<CLI> " + Arrays.toString(args);
- }
- // TODO read the CLI with some better library, e.g. move parsing service to ext. service SPI
- Map<String, String> properties = new HashMap<>();
- for (int base = 0; base < args.length; base++) {
- if (args[base].startsWith("--")) {
- String argKey = args[base].substring(2);
- String value = "true"; // flag only
- if (base != args.length - 1) {
- if (args[base + 1].startsWith("-")) {
- base++;
- int eqIndex = argKey.indexOf('=');
- if (eqIndex > 0) {
- value = argKey.substring(eqIndex + 1);
- argKey = argKey.substring(0, eqIndex);
- }
- } else {
- value = args[base + 1];
- base += 2;
- }
- }
- properties.put(argKey, value);
- } else if (args[base].startsWith("-")) {
- String argKey = args[base].substring(1);
- String value = "true"; // flag only
- if (base != args.length - 1) {
- if (args[base + 1].startsWith("-")) {
- base++;
- int eqIndex = argKey.indexOf('=');
- if (eqIndex > 0) {
- value = argKey.substring(eqIndex + 1);
- argKey = argKey.substring(0, eqIndex);
- }
- } else {
- value = args[base + 1];
- base += 2;
- }
- }
- properties.put(argKey, value);
- }
- }
- return fromMap(name, properties);
- }
-
- public static PropertySource fromPaths(String name, AggregationPolicy aggregationPolicy, List<String> paths) {
- if(name==null){
- name ="<Paths> " + paths.toString();
- }
- return new PathBasedPropertySource(name, paths, aggregationPolicy);
- }
-
- public static PropertySource fromURLs(String name, AggregationPolicy aggregationPolicy, List<URL> urls) {
- if(name==null){
- name ="<URLs> " + urls.toString();
- }
- return new URLBasedPropertySource(name, urls, aggregationPolicy);
- }
-
- public static PropertySource fromMap(String name, Map<String, String> map) {
- if(name==null){
- name ="<Map> " + map.toString();
- }
- return new MapBasedPropertySource(name, map);
- }
-
- public static PropertySource empty(String name) {
- if(name==null) {
- return EMPTY_PROPERTYSOURCE;
- }
- return fromMap(name, Collections.emptyMap());
- }
-
- /**
- * Returns a read-only {@link org.apache.tamaya.PropertySource} reflecting the current runtime environment properties.
- *
- * @return a new read-only {@link org.apache.tamaya.PropertySource} instance based on the current runtime environment properties.
- */
- public static PropertySource fromEnvironmentProperties() {
- return ENV_PROPERTYSOURCE;
- }
-
- /**
- * Creates a new read-only {@link org.apache.tamaya.PropertySource} reflecting the current system properties.
- *
- * @return a new read-only {@link org.apache.tamaya.PropertySource} instance based on the current system properties.
- */
- public static PropertySource fromSystemProperties() {
- return new SystemPropertiesPropertySource();
- }
-
- public static PropertySource freezed(String name, PropertySource source) {
- if(name==null){
- name ="<Freezed> source=" + source.toString()+", at="+Instant.now().toString();
- }
- return FreezedPropertySource.of(name, source);
- }
-
- /**
- * Creates a new {@link org.apache.tamaya.PropertySource} containing all property maps given, hereby using the given AggregationPolicy.
- *
- * @param policy the AggregationPolicy to be used, not null.
- * @param providers the maps to be included, not null.
- * @return the aggregated instance containing all given maps.
- */
- public static PropertySource aggregate(String name, AggregationPolicy policy, List<PropertySource> providers) {
- if(name==null){
- name ="<Aggregate> policy=" + policy.toString()+", providers="+providers.toString();
- }
- return new AggregatedPropertySource(name, null, policy, providers);
- }
-
- /**
- * Creates a new {@link org.apache.tamaya.PropertySource} that is mutable by adding a map based instance that overrides
- * values fromMap the original map.
- * @param provider the provider to be made mutable, not null.
- * @return the mutable instance.
- */
- public static PropertySource mutable(String name, PropertySource provider) {
- if(name==null){
- name ="<Mutable> provider="+provider.getName();
- }
- PropertySource mutableProvider = fromMap(name,new HashMap<>());
- List<PropertySource> providers = new ArrayList<>(2);
- providers.add(provider);
- providers.add(mutableProvider);
- return new AggregatedPropertySource(name, mutableProvider, AggregationPolicy.OVERRIDE, providers);
- }
-
- /**
- * Creates a new {@link org.apache.tamaya.PropertySource} containing only properties that are shared by all given maps,
- * hereby later maps in the array override properties fromMap previous instances.
- * @param aggregationPolicy the policy to resolve aggregation conflicts.
- * @param providers the maps to be included, not null.
- * @return the intersecting instance containing all given maps.
- */
- public static PropertySource intersected(String name, AggregationPolicy aggregationPolicy, List<PropertySource> providers) {
- return new IntersectingPropertySource(name, aggregationPolicy, providers);
- }
-
- /**
- * Creates a new {@link org.apache.tamaya.PropertySource} containing only properties fromMap the target instance, that are not contained
- * in one current the other maps passed.
- *
- * @param target the base map, not null.
- * @param subtrahendSets the maps to be subtracted, not null.
- * @return the intersecting instance containing all given maps.
- */
- public static PropertySource subtracted(String name, PropertySource target, List<PropertySource> subtrahendSets) {
- return new SubtractingPropertySource(name, target,subtrahendSets);
- }
-
-
- /**
- * Creates a filtered {@link org.apache.tamaya.PropertySource} (a view) current a given base {@link }PropertyMap}. The filter hereby is
- * applied dynamically on access, so also runtime changes current the base map are reflected appropriately.
- *
- * @param name the base map instance, not null.
- * @param filter the filtger to be applied, not null.
- * @return the new filtering instance.
- */
- public static PropertySource filtered(String name, Predicate<String> filter, PropertySource source) {
- if(name==null){
- name ="<Filtered> filter="+filter+", source="+source.getName();
- }
- return new FilteredPropertySource(name, source, filter);
- }
-
- /**
- * Creates a new contextual {@link org.apache.tamaya.PropertySource}. Contextual maps delegate to different instances current PropertyMap depending
- * on the keys returned fromMap the isolationP
- *
- * @param name the base name instance, not null.
- * @param mapSupplier the supplier creating new provider instances
- * @param isolationKeySupplier the supplier providing contextual keys based on the current environment.
- */
- public static PropertySource contextual(String name, Supplier<PropertySource> mapSupplier,
- Supplier<String> isolationKeySupplier) {
- if(name==null){
- name ="<Contextual> mapSupplier="+mapSupplier+", isolationKeyProvider="+isolationKeySupplier;
- }
- return new ContextualPropertySource(name, mapSupplier, isolationKeySupplier);
- }
-
-
- /**
- * Creates a filtered {@link org.apache.tamaya.PropertySource} (a view) current a given base {@link }PropertyMap}. The filter hereby is
- * applied dynamically on access, so also runtime changes current the base map are reflected appropriately.
- *
- * @param name the base name instance, not null.
- * @param source the main map instance, not null.
- * @param parentMap the delegated parent map instance, not null.
- * @return the new delegating instance.
- */
- public static PropertySource delegating(String name, PropertySource source, Map<String, String> parentMap) {
- if(name==null){
- name ="<Delegating> source="+source+", delegates="+parentMap;
- }
- return new DelegatingPropertySource(name, source, parentMap);
- }
-
- /**
- * Creates a {@link org.apache.tamaya.PropertySource} where all keys current a current map,
- * existing in another map are replaced
- * with the ones fromMap the other {@link org.apache.tamaya.PropertySource}. The filter hereby is
- * applied dynamically on access, so also runtime changes current the base map are reflected appropriately.
- * Keys not existing in the {@code mainMap}, but present in {@code replacementMao} will be hidden.
- *
- * @param name the base name instance, not null.
- * @param source the main source instance, which keys, present in {@code replacementMap} will be replaced
- * with the ones
- * in {@code replacementMap}, not null.
- * @param replacementMap the map instance, that will replace all corresponding entries in {@code mainMap}, not null.
- * @return the new delegating instance.
- */
- public static PropertySource replacing(String name, PropertySource source, Map<String, String> replacementMap) {
- if(name==null){
- name ="<Replacement> source="+source+", replacements="+replacementMap;
- }
- return new ReplacingPropertySource(name, source, replacementMap);
- }
-
- /**
- * Creates a new {@link org.apache.tamaya.PropertySource} given an existing one, and an alternate
- * meta-info.
- * @param name the new meta-information, not null.
- * @param baseProvider the property source, not null.
- * @return the new property source.never null.
- */
- public static PropertySource build(String name, PropertySource baseProvider) {
- return new BuildablePropertySource(name, baseProvider);
- }
-
- /**
- * Creates a new filtered {@link org.apache.tamaya.PropertySource} using the given filter.
- * @param name the base name instance, not null.
- * @param valueFilter the value filter function, null result will remove the given entries.
- * @param current the source to be filtered
- */
- public static PropertySource filterValues(String name, BiFunction<String, String, String> valueFilter, PropertySource current) {
- return new ValueFilteredPropertySource(name, valueFilter, current);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
index 5fcf895..c081c94 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
@@ -62,4 +62,57 @@ public final class PropertySourceFunctions {
return (c) -> new MappedPropertySource(c, keyMapper);
}
+
+
+ /**
+ * Intersetcs the current properties with the given {@link org.apache.tamaya.PropertySource} instance.
+ *
+ * @param providers the maps to be intersected, not null.
+ * @return the builder for chaining.
+ */
+ public UnaryOperator<PropertySource> intersect(PropertySource... providers) {
+ if (providers.length == 0) {
+ return this;
+ }
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<intersection> -> " + Arrays.toString(providers);
+ }
+ return addPropertySources(PropertySourceFactory.intersected(name, aggregationPolicy, Arrays.asList(providers)));
+ }
+
+
+ /**
+ * Filters the current properties based on the given predicate..
+ *
+ * @param filter the filter to be applied, not null.
+ * @return the new filtering instance.
+ */
+ public UnaryOperator<PropertySource> filter(Predicate<String> filter) {
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<filtered> -> " + filter;
+ }
+ current = PropertySourceFactory.filtered(name, filter, current);
+ this.currentName = null;
+ return this;
+ }
+
+
+ /**
+ * Replaces all keys in the current provider by the given map.
+ *
+ * @param replacementMap the map instance, that will replace all corresponding entries in {@code mainMap}, not null.
+ * @return the new delegating instance.
+ */
+ public PropertySourceBuilder replace(Map<String, String> replacementMap) {
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<replacement> -> current=" + current.getName() + " with =" + replacementMap;
+ }
+ current = PropertySourceFactory.replacing(name, current, replacementMap);
+ this.currentName = null;
+ return this;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
deleted file mode 100644
index 85100e3..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.PropertySource;
-
-import java.util.*;
-
-/**
- * Implementation for a {@link org.apache.tamaya.PropertySource} that is an aggregate current
- * multiple child instances, where all existing key/values in a replacementMap will
- * replace values in a main map, if present there.
- */
-class ReplacingPropertySource implements PropertySource {
-
- private PropertySource mainMap;
- private Map<String,String> replacingMap;
- private String name;
-
- /**
- * Creates a mew instance, with aggregation polilcy
- * {@code AggregationPolicy.OVERRIDE}.
- *
- * @param mainMap The main ConfigMap.
- * @param replacingMap The replacing ConfigMap.
- */
- public ReplacingPropertySource(String name, PropertySource mainMap, Map<String, String> replacingMap){
- this.replacingMap = Objects.requireNonNull(replacingMap);
- this.mainMap = Objects.requireNonNull(mainMap);
- this.name = Objects.requireNonNull(name);
- }
-
- @Override
- public Map<String,String> getProperties(){
- Map<String,String> result = new HashMap<>(replacingMap);
- mainMap.getProperties().entrySet().stream().filter(en -> !replacingMap.containsKey(en.getKey())).forEach(en ->
- result.put(en.getKey(), en.getValue()));
- return result;
- }
-
- @Override
- public String getName(){
- return this.name;
- }
-
- @Override
- public Optional<String> get(String key){
- String val = replacingMap.get(key);
- if(val == null){
- return mainMap.get(key);
- }
- return Optional.ofNullable(val);
- }
-
- @Override
- public String toString(){
- return super.toString() + "(mainMap=" + mainMap + ", replacingMap=" + replacingMap + ")";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
deleted file mode 100644
index f78ceb9..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.PropertySource;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-class SubtractingPropertySource extends AbstractPropertySource {
-
- private static final long serialVersionUID = 4301042530074932562L;
- private PropertySource unit;
- private List<PropertySource> subtrahends;
-
- public SubtractingPropertySource(String name, PropertySource configuration, List<PropertySource> subtrahends){
- super(name);
- Objects.requireNonNull(configuration);
- this.unit = configuration;
- this.subtrahends = new ArrayList<>(subtrahends);
- }
-
- private boolean filter(Map.Entry<String,String> entry){
- for(PropertySource prov: subtrahends){
- if(prov.get(entry.getKey()).isPresent()){
- return false;
- }
- }
- return true;
- }
-
- @Override
- public Map<String,String> getProperties(){
- return this.unit.getProperties().entrySet().stream().filter(this::filter).collect(Collectors.toMap(
- Map.Entry::getKey,
- Map.Entry::getValue
- ));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java
index f66c4f8..1964b16 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/SystemPropertiesPropertySource.java
@@ -21,36 +21,35 @@ package org.apache.tamaya.core.properties;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Properties;
-class SystemPropertiesPropertySource extends AbstractPropertySource {
+public class SystemPropertiesPropertySource implements PropertySource {
private static final long serialVersionUID = -5935940312707001199L;
+ private int ordinal;
+
+ private String name;
+
/**
* Constructor.
*/
- protected SystemPropertiesPropertySource() {
- super("<System.getProperties()>");
+ public SystemPropertiesPropertySource(int ordinal, String name) {
+ this.ordinal = ordinal;
+ this.name = Objects.requireNonNull(name);
+
}
@Override
public Map<String,String> getProperties(){
- Properties sysProps = System.getProperties();
-// if(sysProps instanceof ConfiguredSystemProperties){
-// sysProps = ((ConfiguredSystemProperties)sysProps).getInitialProperties();
-// }
- Map<String,String> props = new HashMap<>();
- for (Map.Entry<Object,Object> en : sysProps.entrySet()) {
- props.put(en.getKey().toString(), en.getValue().toString());
- }
- return Collections.unmodifiableMap(props);
+ return Collections.unmodifiableMap(System.getProperties());
}
@Override
public String toString(){
- return "SystemPropertiesPropertyProvider[" + System.getProperties().size() + " system properties]";
+ return "PropertySource[System Properties]";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
deleted file mode 100644
index f690ef9..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.core.internal.resources.io.UrlResource;
-import org.apache.tamaya.core.resource.Resource;
-
-import java.net.URL;
-import java.util.*;
-
-/**
- * Created by Anatole on 16.10.2014.
- */
-final class URLBasedPropertySource extends AbstractPropertySource {
-
- private static final long serialVersionUID = 648272283683183532L;
- private List<URL> resources = new ArrayList<>();
- private Map<String,String> properties = new HashMap<>();
- private AggregationPolicy aggregationPolicy;
-
- public URLBasedPropertySource(String name, List<URL> resources, AggregationPolicy aggregationPolicy) {
- super(name);
- this.resources.addAll(Objects.requireNonNull(resources));
- this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
- init();
- }
-
- private void init(){
- List<String> sources = new ArrayList<>();
- for(URL url : resources){
- Resource res = new UrlResource(url);
- ConfigurationFormat format = ConfigurationFormat.from(res);
- if(format != null){
- try{
- Map<String, String> read = format.readConfiguration(res);
- sources.add(res.toString());
- read.forEach((k, v) -> {
- String newValue = aggregationPolicy.aggregate(k, properties.get(k), v);
- if(newValue==null) {
- properties.remove(k);
- }
- else {
- properties.put(k, newValue);
- }
- });
- }
- catch(ConfigException e){
- throw e;
- }
- catch(Exception e){
- e.printStackTrace();
- }
- }
- }
-// MetaInfoBuilder metaInfoBuilder = MetaInfoBuilder.of(getMetaInfo());
-// metaInfo = metaInfoBuilder
-// .setSources(sources.toString()).build();
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/ValueFilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/ValueFilteredPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/ValueFilteredPropertySource.java
deleted file mode 100644
index db17d21..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/ValueFilteredPropertySource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.PropertySource;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.BiFunction;
-
-/**
- * Property source which filters any key/values dynamically.
- */
-class ValueFilteredPropertySource implements PropertySource{
-
- private String name;
- private BiFunction<String, String, String> valueFilter;
- private PropertySource source;
-
- public ValueFilteredPropertySource(String name, BiFunction<String, String, String> valueFilter, PropertySource current) {
- this.name = Optional.ofNullable(name).orElse("<valueFiltered> -> name="+current.getName()+", valueFilter="+valueFilter.toString());
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Optional<String> get(String key) {
- String value = this.source.get(key).orElse(null);
- value = valueFilter.apply(key, value);
- return Optional.ofNullable(value);
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(source.getProperties());
- map.replaceAll(valueFilter);
- return map;
- }
-
- @Override
- public String toString() {
- return "ValueFilteredPropertySource{" +
- "source=" + source.getName() +
- ", name='" + name + '\'' +
- ", valueFilter=" + valueFilter +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/PropertySourceFactory.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/PropertySourceFactory.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/PropertySourceFactory.java
new file mode 100644
index 0000000..b7d985c
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/PropertySourceFactory.java
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import java.net.URL;
+import java.time.Instant;
+import java.util.*;
+import java.util.function.BiFunction;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+import org.apache.tamaya.PropertySource;
+
+/**
+ * Default implementation current the singleton backing bean for the {@link org.apache.tamaya.core.properties.PropertySourceBuilder}.
+ */
+public final class PropertySourceFactory {
+
+ private static final PropertySource ENV_PROPERTYSOURCE = new EnvironmentPropertySource();
+
+
+ /**
+ * Singleton constructor.
+ */
+ private PropertySourceFactory(){}
+
+ public static PropertySource fromArgs(int ordinal, String name, String... args) {
+ if(name==null){
+ name ="<CLI> " + Arrays.toString(args);
+ }
+ //X TODO read the CLI with some better library, e.g. move parsing service to ext. service SPI
+ Map<String, String> properties = new HashMap<>();
+ for (int base = 0; base < args.length; base++) {
+ if (args[base].startsWith("--")) {
+ String argKey = args[base].substring(2);
+ String value = "true"; // flag only
+ if (base != args.length - 1) {
+ if (args[base + 1].startsWith("-")) {
+ base++;
+ int eqIndex = argKey.indexOf('=');
+ if (eqIndex > 0) {
+ value = argKey.substring(eqIndex + 1);
+ argKey = argKey.substring(0, eqIndex);
+ }
+ } else {
+ value = args[base + 1];
+ base += 2;
+ }
+ }
+ properties.put(argKey, value);
+ } else if (args[base].startsWith("-")) {
+ String argKey = args[base].substring(1);
+ String value = "true"; // flag only
+ if (base != args.length - 1) {
+ if (args[base + 1].startsWith("-")) {
+ base++;
+ int eqIndex = argKey.indexOf('=');
+ if (eqIndex > 0) {
+ value = argKey.substring(eqIndex + 1);
+ argKey = argKey.substring(0, eqIndex);
+ }
+ } else {
+ value = args[base + 1];
+ base += 2;
+ }
+ }
+ properties.put(argKey, value);
+ }
+ }
+ return fromMap(ordinal, name, properties);
+ }
+
+ public static Collection<PropertySource> fromPaths(int ordinal, String name, List<String> paths) {
+ if(name==null){
+ name ="<Paths> " + paths.toString();
+ }
+ return new PathBasedPropertySource(ordinal, name, paths);
+ }
+
+ public static Collection<PropertySource> fromURLs(int ordinal, String name, List<URL> urls) {
+ if(name==null){
+ name ="<URLs> " + urls.toString();
+ }
+ return new URLBasedPropertySource(ordinal, name, urls);
+ }
+
+ public static PropertySource fromMap(int ordinal, String name, Map<String, String> map) {
+ if(name==null){
+ name ="<Map> " + map.toString();
+ }
+ return new MapBasedPropertySource(name, map);
+ }
+
+ /**
+ * Returns a read-only {@link org.apache.tamaya.PropertySource} reflecting the current runtime environment properties.
+ *
+ * @return a new read-only {@link org.apache.tamaya.PropertySource} instance based on the current runtime environment properties.
+ */
+ public static PropertySource fromEnvironmentProperties() {
+ return ENV_PROPERTYSOURCE;
+ }
+
+ /**
+ * Creates a new read-only {@link org.apache.tamaya.PropertySource} reflecting the current system properties.
+ *
+ * @return a new read-only {@link org.apache.tamaya.PropertySource} instance based on the current system properties.
+ */
+ public static PropertySource fromSystemProperties() {
+ return new SystemPropertiesPropertySource();
+ }
+
+ public static PropertySource freezed(String name, PropertySource source) {
+ if(name==null){
+ name ="<Freezed> source=" + source.toString()+", at="+Instant.now().toString();
+ }
+ return FreezedPropertySource.of(name, source);
+ }
+
+ /**
+ * Creates a new {@link org.apache.tamaya.PropertySource} containing all property maps given, hereby using the given AggregationPolicy.
+ *
+ * @param policy the AggregationPolicy to be used, not null.
+ * @param providers the maps to be included, not null.
+ * @return the aggregated instance containing all given maps.
+ */
+ public static PropertySource aggregate(String name, AggregationPolicy policy, List<PropertySource> providers) {
+ if(name==null){
+ name ="<Aggregate> policy=" + policy.toString()+", providers="+providers.toString();
+ }
+ return new AggregatedPropertySource(name, null, policy, providers);
+ }
+
+ /**
+ * Creates a new {@link org.apache.tamaya.PropertySource} that is mutable by adding a map based instance that overrides
+ * values fromMap the original map.
+ * @param provider the provider to be made mutable, not null.
+ * @return the mutable instance.
+ */
+ public static PropertySource mutable(String name, PropertySource provider) {
+ if(name==null){
+ name ="<Mutable> provider="+provider.getName();
+ }
+ PropertySource mutableProvider = fromMap(name,new HashMap<>());
+ List<PropertySource> providers = new ArrayList<>(2);
+ providers.add(provider);
+ providers.add(mutableProvider);
+ return new AggregatedPropertySource(name, mutableProvider, AggregationPolicy.OVERRIDE, providers);
+ }
+
+ /**
+ * Creates a new {@link org.apache.tamaya.PropertySource} containing only properties that are shared by all given maps,
+ * hereby later maps in the array override properties fromMap previous instances.
+ * @param aggregationPolicy the policy to resolve aggregation conflicts.
+ * @param providers the maps to be included, not null.
+ * @return the intersecting instance containing all given maps.
+ */
+ public static PropertySource intersected(String name, AggregationPolicy aggregationPolicy, List<PropertySource> providers) {
+ return new IntersectingPropertySource(name, aggregationPolicy, providers);
+ }
+
+ /**
+ * Creates a new {@link org.apache.tamaya.PropertySource} containing only properties fromMap the target instance, that are not contained
+ * in one current the other maps passed.
+ *
+ * @param target the base map, not null.
+ * @param subtrahendSets the maps to be subtracted, not null.
+ * @return the intersecting instance containing all given maps.
+ */
+ public static PropertySource subtracted(String name, PropertySource target, List<PropertySource> subtrahendSets) {
+ return new SubtractingPropertySource(name, target,subtrahendSets);
+ }
+
+
+ /**
+ * Creates a filtered {@link org.apache.tamaya.PropertySource} (a view) current a given base {@link }PropertyMap}. The filter hereby is
+ * applied dynamically on access, so also runtime changes current the base map are reflected appropriately.
+ *
+ * @param name the base map instance, not null.
+ * @param filter the filtger to be applied, not null.
+ * @return the new filtering instance.
+ */
+ public static PropertySource filtered(String name, Predicate<String> filter, PropertySource source) {
+ if(name==null){
+ name ="<Filtered> filter="+filter+", source="+source.getName();
+ }
+ return new FilteredPropertySource(name, source, filter);
+ }
+
+ /**
+ * Creates a new contextual {@link org.apache.tamaya.PropertySource}. Contextual maps delegate to different instances current PropertyMap depending
+ * on the keys returned fromMap the isolationP
+ *
+ * @param name the base name instance, not null.
+ * @param mapSupplier the supplier creating new provider instances
+ * @param isolationKeySupplier the supplier providing contextual keys based on the current environment.
+ */
+ public static PropertySource contextual(String name, Supplier<PropertySource> mapSupplier,
+ Supplier<String> isolationKeySupplier) {
+ if(name==null){
+ name ="<Contextual> mapSupplier="+mapSupplier+", isolationKeyProvider="+isolationKeySupplier;
+ }
+ return new ContextualPropertySource(name, mapSupplier, isolationKeySupplier);
+ }
+
+
+ /**
+ * Creates a filtered {@link org.apache.tamaya.PropertySource} (a view) current a given base {@link }PropertyMap}. The filter hereby is
+ * applied dynamically on access, so also runtime changes current the base map are reflected appropriately.
+ *
+ * @param name the base name instance, not null.
+ * @param source the main map instance, not null.
+ * @param parentMap the delegated parent map instance, not null.
+ * @return the new delegating instance.
+ */
+ public static PropertySource delegating(String name, PropertySource source, Map<String, String> parentMap) {
+ if(name==null){
+ name ="<Delegating> source="+source+", delegates="+parentMap;
+ }
+ return new DelegatingPropertySource(name, source, parentMap);
+ }
+
+ /**
+ * Creates a {@link org.apache.tamaya.PropertySource} where all keys current a current map,
+ * existing in another map are replaced
+ * with the ones fromMap the other {@link org.apache.tamaya.PropertySource}. The filter hereby is
+ * applied dynamically on access, so also runtime changes current the base map are reflected appropriately.
+ * Keys not existing in the {@code mainMap}, but present in {@code replacementMao} will be hidden.
+ *
+ * @param name the base name instance, not null.
+ * @param source the main source instance, which keys, present in {@code replacementMap} will be replaced
+ * with the ones
+ * in {@code replacementMap}, not null.
+ * @param replacementMap the map instance, that will replace all corresponding entries in {@code mainMap}, not null.
+ * @return the new delegating instance.
+ */
+ public static PropertySource replacing(String name, PropertySource source, Map<String, String> replacementMap) {
+ if(name==null){
+ name ="<Replacement> source="+source+", replacements="+replacementMap;
+ }
+ return new ReplacingPropertySource(name, source, replacementMap);
+ }
+
+ /**
+ * Creates a new {@link org.apache.tamaya.PropertySource} given an existing one, and an alternate
+ * meta-info.
+ * @param name the new meta-information, not null.
+ * @param baseProvider the property source, not null.
+ * @return the new property source.never null.
+ */
+ public static PropertySource build(String name, PropertySource baseProvider) {
+ return new BuildablePropertySource(name, baseProvider);
+ }
+
+ /**
+ * Creates a new filtered {@link org.apache.tamaya.PropertySource} using the given filter.
+ * @param name the base name instance, not null.
+ * @param valueFilter the value filter function, null result will remove the given entries.
+ * @param current the source to be filtered
+ */
+ public static PropertySource filterValues(String name, BiFunction<String, String, String> valueFilter, PropertySource current) {
+ return new ValueFilteredPropertySource(name, valueFilter, current);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/PropertySourcesBuilder.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/PropertySourcesBuilder.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/PropertySourcesBuilder.java
new file mode 100644
index 0000000..712e3f6
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/PropertySourcesBuilder.java
@@ -0,0 +1,367 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.tamaya.core.properties.factories;
+
+import java.lang.IllegalArgumentException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.tamaya.core.properties.AggregationPolicy;
+import org.apache.tamaya.core.properties.PropertySourceFactory;
+import org.apache.tamaya.spi.PropertySource;
+
+/**
+ * Builder for assembling non trivial property providers.
+ */
+public final class PropertySourcesBuilder {
+
+ /**
+ * Name used for the final result.
+ */
+ private Map<String, PropertySource> propertySources = new HashMap<>();
+
+ /**
+ * The current aggregation policy used, when aggregating providers.
+ */
+ private AggregationPolicy aggregationPolicy = AggregationPolicy.OVERRIDE;
+
+ /**
+ * The current ordinal used for creating property source instances.
+ */
+ private int currentOrdinal;
+ /** The increment added to {@code currentOrdinal}, when new property sources are added and no
+ * explcit ordinal is used. */
+ private int ordinalIncrement;
+
+ /** The name to be used for the next PropertySource constructed, or null, for creating a defau,t name. */
+ private String currentName;
+
+ /**
+ * Private singleton constructor.
+ */
+ private PropertySourcesBuilder(int ordinal, int ordinalIncrement) {
+ this.ordinalIncrement = ordinalIncrement;
+ this.currentOrdinal = ordinal;
+ }
+
+ /**
+ * Creates a new builder instance.
+ *
+ * @param ordinal The initial starting ordinal to be used when new property sources are created and added.
+ * @param ordinalIncrement the ordinal increment to be added when no new property sources are created and added.
+ * @return a new builder instance, never null.
+ */
+ public static PropertySourcesBuilder of(int ordinal, int ordinalIncrement) {
+ return new PropertySourcesBuilder(ordinal, ordinalIncrement);
+ }
+
+ /**
+ * Creates a new builder instance.
+ *
+ * @param ordinal The initial starting ordinal to be used when new property sources are created and added.
+ * The default ordinal increment used is 10.
+ * @return a new builder instance, never null.
+ */
+ public static PropertySourcesBuilder of(int ordinal) {
+ return new PropertySourceBuilder(ordinal, 10);
+ }
+
+
+ /**
+ * Creates a new builder instance, starting with ordinal of 1 and an ordinal increment of 10.
+ *
+ * @param name the provider name, not null.
+ * @return a new builder instance, never null.
+ */
+ public static PropertySourcesBuilder of() {
+ return new PropertySourceBuilder(1, 10);
+ }
+
+ /**
+ * Sets the current ordinal used, when additional property sets are added. The ordinal will normally implicitly
+ * incresed for each property set by {@code ordinalIncrement}. If the ordinal is passed explcitly to a method
+ * all created sources will have the same ordinal.
+ *
+ * @param ordinal the ordinal to be used.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder withOrdinal(int ordinal) {
+ this.currentOrdinal = ordinal;
+ return this;
+ }
+
+ /**
+ * Sets the current name used, when the next property sets is added. If set to null a default name will be
+ * constructed.
+ *
+ * @param name the name to be used for the next property set created, or null.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder withName(String name) {
+ this.currentName = name;
+ return this;
+ }
+
+ /**
+ * Aggregates the given {@code sources} (at least 2) into a new
+ * {@link PropertySource} and adds it with the given current ordinal and name.
+ *
+ * @param aggregationPolicy the aggregation policy, not null.
+ * @param sources the property sources to be aggregated.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addAggregation(AggregationPolicy aggregationPolicy, PropertySource... sources) {
+ this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
+ String name = this.currentName;
+ if(name==null){
+ name = "Aggregate["+ Arrays.stream(sources).map(s -> s.getName()).collect(
+ () -> "",
+ (s,o) -> s + ',' + o,
+ (s1, s2) -> s1 + ',' + s2) +"]"
+ }
+ ProperttySource source = new new AggregatedPropertySource(currentOrdinal, name, aggregationPolicy, sources);
+ this.propertySources.put(source.getName(), source);
+ this.currentOrdinal += ordinalIncrement;
+ return this;
+ }
+
+ /**
+ * Adds the given providers with the current active {@link AggregationPolicy}. By
+ * default {@link AggregationPolicy#OVERRIDE} is used.
+ *
+ * @param propertySources the property sources to be added, not null.
+ * @return the builder for chaining.
+ * @see #withAggregationPolicy(AggregationPolicy)
+ */
+ public PropertySourcesBuilder addPropertySources(PropertySource... propertySources) {
+ if (propertySources.length == 0) {
+ return this;
+ }
+ return addPropertySources(Arrays.asList(propertySources));
+ }
+
+ /**
+ * Adds the given providers with the current active {@link AggregationPolicy}. By
+ * default {@link AggregationPolicy#OVERRIDE} is used.
+ *
+ * @param providers providers to be added, not null.
+ * @return the builder for chaining.
+ * @see #withAggregationPolicy(AggregationPolicy)
+ */
+ public PropertySourcesBuilder addPropertySources(List<PropertySource> providers) {
+ if (providers.isEmpty()) {
+ return this;
+ }
+ for (PropertySource src : providers) {
+ PropertySource current = this.propertySources.get(src.getName());
+ if (src != null) {
+ throw new IllegalArgumentException("PropertySource with that name is already existing: " + src.getName())
+ }
+ }
+ for (PropertySource src : providers) {
+ this.propertySources.put(sec.getName(), src);
+ }
+ return this;
+ }
+
+ /**
+ * Creates a new {@link PropertySource} using the given command line arguments and adds it
+ * using the current aggregation policy in place.
+ *
+ * @param args the command line arguments, not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addArgs(String... args) {
+ if (args.length == 0) {
+ return this;
+ }
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "CLI-Args";
+ }
+ PropertySource argProvider = PropertySourceFactory.fromArgs(currentOrdinal, name, args);
+ currentOrdinal+=ordinalIncrement;
+ return addPropertySources(argProvider);
+ }
+
+ /**
+ * Creates a new read-only {@link PropertySource} by reading the according path resources. The effective resources read
+ * hereby are determined by the {@code PathResolverService} configured into the {@code Bootstrap} SPI.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param paths the paths to be resolved by the {@code PathResolverService} , not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addPaths(String... paths) {
+ if (paths.length == 0) {
+ return this;
+ }
+ return addPaths(Arrays.asList(paths));
+ }
+
+
+ /**
+ * Creates a new read-only {@link PropertySource} by reading the according path resources. The effective resources read
+ * hereby are determined by the {@code PathResolverService} configured into the {@code Bootstrap} SPI.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param paths the paths to be resolved by the {@code PathResolverService} , not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addPaths(List<String> paths) {
+ if (paths.isEmpty()) {
+ return this;
+ }
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "paths=" + paths.toString();
+ }
+ addPropertySources(PropertySourceFactory.fromPaths(currentOrdinal, name, paths));
+ }
+
+ /**
+ * Creates a new read-only {@link PropertySource} by reading the according URL resources.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param urls the urls to be read, not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addURLs(URL... urls) {
+ if (urls.length == 0) {
+ return this;
+ }
+ return addURLs(Arrays.asList(urls));
+ }
+
+ /**
+ * Creates a new read-only {@link PropertySource} by reading the according URL resources.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param urls the urls to be read, not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addURLs(List<URL> urls) {
+ if (urls.isEmpty()) {
+ return this;
+ }
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "URL: =" + urls;
+ }
+ return addPropertySources(PropertySourceFactory.fromURLs(name, this.aggregationPolicy, urls));
+ }
+
+
+ /**
+ * Creates a new read-only {@link PropertySource} based on the given map.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param map the map to be added, not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addMap(Map<String, String> map) {
+ if (map.isEmpty()) {
+ return this;
+ }
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "Map;
+ }
+ return addPropertySources(PropertySourceFactory.fromMap(currentOrdinal, name, map));
+ }
+
+
+ /**
+ * Add the current environment properties. Aggregation is based on the current {@link AggregationPolicy} acvtive.
+ *
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addEnvironmentProperties() {
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "Environment-Properties";
+ }
+ return addPropertySources(PropertySourceFactory.fromEnvironmentProperties());
+ }
+
+ /**
+ * Add the current system properties. Aggregation is based on the current {@link AggregationPolicy} acvtive.
+ *
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder addSystemProperties() {
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "System-Properties";
+ }
+ return addPropertySources(PropertySourceFactory.fromSystemProperties());
+ }
+
+
+//
+// /**
+// * Filters the current {@link org.apache.tamaya.PropertySource} with the given valueFilter.
+// *
+// * @param valueFilter the value filter, not null.
+// * @return the (dynamically) filtered source instance, never null.
+// */
+// public PropertySourceBuilder filterValues(BiFunction<String, String, String> valueFilter) {
+// String name = this.currentName;
+// if (currentName == null) {
+// name = "<filteredValues> -> " + valueFilter;
+// }
+// this.current = PropertySourceFactory.filterValues(name, valueFilter, this.current);
+// return this;
+// }
+
+
+ /**
+ * Subtracts with the given {@link org.apache.tamaya.PropertySource} instance from the current properties.
+ *
+ * @param providers the maps to be subtracted, not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourcesBuilder subtract(PropertySource... providers) {
+ if (providers.length == 0) {
+ return this;
+ }
+ String name = this.currentName;
+ if (currentName == null) {
+ name = "<subtraction> -> " + Arrays.toString(providers);
+ }
+ current = PropertySourceFactory.subtracted(name, current, Arrays.asList(providers));
+ return this;
+ }
+
+
+ /**
+ * Build a new property provider based on the input.
+ *
+ * @return a new property provider, or null.
+ */
+ public Collection<PropertySource> build() {
+ return this.propertySources.values();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/ResourcePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/ResourcePropertySourceProvider.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/ResourcePropertySourceProvider.java
new file mode 100644
index 0000000..6dae705
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/factories/ResourcePropertySourceProvider.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.Override;
+import java.lang.String;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class ResourcePropertySourceProvider implements PropertySourceProvider {
+
+ private static final Logger LOG = Logger.getLogger(ResourcePropertySourceProvider.class.getName());
+
+ private int baseOrdinal;
+
+ private Collection<PropertySource> propertySources;
+
+ private Resource resource;
+
+ public ResourcePropertySourceProvider(int baseOrdinal, String baseName, Resource resource) {
+ this.resource = Objects.requireNonNull(resource);
+ this.baseOrdinal = baseOrdinal;
+ List<ConfigFormat> formats = ConfigFormat.getFormats(resource);
+ for(ConfigFormat format: formats){
+ try{
+ propertySources = format.readConfiguration(baseOrdinal, baseName, resource);
+ }
+ catch(Exception e){
+ LOG.info(() -> "Format was not matching: " + format.getFormatName() + " for resource: " + resource.getName());
+ }
+ }
+ }
+
+ public Resource getResource(){
+ return this.resource;
+ }
+
+
+ @Override
+ public String toString() {
+ return "ResourcePropertySourceProvider{" +
+ "resource=" + resource +
+ ", propertySources=" + propertySources +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/AggregatedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/AggregatedPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/AggregatedPropertySource.java
new file mode 100644
index 0000000..e62a9a6
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/AggregatedPropertySource.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties.filtered;
+
+import org.apache.tamaya.core.properties.AggregationPolicy;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.*;
+
+/**
+ * Implementation for a {@link org.apache.tamaya.spi.PropertySource} that is an aggregate current
+ * multiple child instances.
+ */
+public class AggregatedPropertySource implements PropertySource {
+
+ private PropertySource baseSource;
+ private PropertySource aggregatedSource;
+ private String name;
+ private int ordinal;
+ private AggregationPolicy aggregationPolicy;
+
+ /**
+ * Creates a mew instance, with aggregation polilcy
+ * {@code AggregationPolicy.OVERRIDE}.
+ *
+ * @param ordinal the ordinal
+ * @param name The name to be used, not null.
+ * @param aggregationPolicy the {@link org.apache.tamaya.core.properties.AggregationPolicy} to be applied
+ * @param baseSource the base property source, not null
+ * @param aggregatedSource the aggregatesd property source, not null
+ */
+ public AggregatedPropertySource(int ordinal, String name, AggregationPolicy aggregationPolicy,
+ PropertySource baseSource, PropertySource aggregatedSource) {
+ this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
+ this.name = Objects.requireNonNull(name);
+ this.ordinal = ordinal;
+ this.baseSource = Objects.requireNonNull(baseSource);
+ this.aggregatedSource = Objects.requireNonNull(aggregatedSource);
+ }
+
+ @Override
+ public int getOrdinal() {
+ return this.ordinal;
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> result = new HashMap<>();
+ Set<String> keySet = new HashSet<>(this.baseSource.getProperties().keySet());
+ keySet.addAll(this.aggregatedSource.getProperties().keySet());
+ for (String key : keySet) {
+ String value = this.aggregationPolicy.aggregate(
+ key,
+ baseSource.get(key).orElse(null),
+ aggregatedSource.get(key).orElse(null));
+ if (value != null) {
+ result.put(key, value);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ String value1 = this.baseSource.get(key).orElse(null);
+ String value2 = this.aggregatedSource.get(key).orElse(null);
+ return Optional.ofNullable(aggregationPolicy.aggregate(key, value1, value2));
+ }
+
+ @Override
+ public String toString() {
+ return "Aggregate(baseSource=" + baseSource +
+ ", aggregatedSource=" + aggregatedSource.getName() +
+ ", aggregationPolicy=" + aggregationPolicy + ")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/FilteredPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/FilteredPropertySource.java
new file mode 100644
index 0000000..ecf2950
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/FilteredPropertySource.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.PropertySource;
+
+import java.lang.Override;
+import java.lang.String;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+class FilteredPropertySource implements PropertySource {
+
+ private PropertySource baseSource;
+ private Predicate<String> filter;
+
+ public FilteredPropertySource(PropertySource baseSource, Predicate<String> filter){
+ this.baseSource = Objects.requireNonNull(baseSource);
+ this.filter = Objects.requireNonNull(filter);
+ }
+
+ @Override
+ public int ordinal(){
+ return baseSource.ordinal();
+ }
+
+ @Override
+ public String getName(){
+ return baseSource + "(filtered)";
+ }
+
+ @Override
+ public Map<String,String> getProperties(){
+ final Map<String,String> result = new HashMap<>();
+ this.unit.getProperties().entrySet().forEach(e -> {
+ if(filter.test(e.getKey())){
+ result.put(e.getKey(), e.getValue());
+ }
+ });
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "FilteredPropertySource{" +
+ "baseSource=" + baseSource +
+ ", filter=" + filter +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/IntersectingPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/IntersectingPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/IntersectingPropertySource.java
new file mode 100644
index 0000000..e441985
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/IntersectingPropertySource.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties.filtered;
+
+import org.apache.tamaya.*;
+import org.apache.tamaya.core.properties.filtered.AggregatedPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * Provider implementation that combines multiple other config by intersecting
+ * the key/values common to one source.
+ */
+class IntersectingPropertySource extends AggregatedPropertySource {
+
+
+ /**
+ * Creates a mew instance, with aggregation polilcy
+ * {@code AggregationPolicy.OVERRIDE}.
+ *
+ * @param ordinal the ordinal
+ * @param name The name to be used, not null.
+ * @param baseSource the base property source, not null
+ * @param aggregatedSource the aggregatesd property source, not null
+ */
+ public IntersectingPropertySource(int ordinal, String name,
+ PropertySource baseSource, PropertySource aggregatedSource) {
+ super(ordinal, name, (k,v1,v2) -> {
+ if(v1!=null && v2!=null && v1.equals(v2)){
+ return v1;
+ }
+ return null;
+ }, baseSource, aggregatedSource);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/MappedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/MappedPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/MappedPropertySource.java
new file mode 100644
index 0000000..0db716d
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/MappedPropertySource.java
@@ -0,0 +1,67 @@
+package org.apache.tamaya.core.properties.filtered;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.UnaryOperator;
+
+import org.apache.tamaya.PropertySource;
+import org.apache.tamaya.spi.PropertySource;
+
+/**
+ * PropertySource implementation that maps certain parts (defined by an {@code UnaryOperator<String>}) to alternate areas.
+ */
+class MappedPropertySource implements PropertySource {
+
+ private static final long serialVersionUID = 8690637705511432083L;
+
+ /** The mapping operator. */
+ private UnaryOperator<String> keyMapper;
+ /** The base configuration. */
+ private PropertySource propertySource;
+
+ /**
+ * Creates a new instance.
+ * @param config the base configuration, not null
+ * @param keyMapper The mapping operator, not null
+ */
+ public MappedPropertySource(PropertySource config, UnaryOperator<String> keyMapper) {
+ this.propertySource = Objects.requireNonNull(config);
+ this.keyMapper = Objects.requireNonNull(keyMapper);
+ }
+
+ @Override
+ public int getOrdinal(){
+ return this.propertySource.getOrdinal();
+ }
+
+ @Override
+ public String getName(){
+ return this.propertySource.getName()+"[mapped]";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> result = new HashMap<>();
+ Map<String, String> map = this.propertySource.getProperties();
+ map.forEach((k,v) -> {
+ String targetKey = keyMapper.apply(k);
+ if(targetKey!=null){
+ result.put(targetKey, v);
+ }
+ });
+ return result;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ return Optional.of(getProperties().get(key));
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.propertySource.isEmpty();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/ValueFilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/ValueFilteredPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/ValueFilteredPropertySource.java
new file mode 100644
index 0000000..8eb0f60
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/filtered/ValueFilteredPropertySource.java
@@ -0,0 +1,55 @@
+package org.apache.tamaya.core.properties.filtered;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.BiFunction;
+
+/**
+ * Property source which filters any key/values dynamically.
+ */
+class ValueFilteredPropertySource implements PropertySource{
+
+ private String name;
+ private BiFunction<String, String, String> valueFilter;
+ private PropertySource source;
+
+ public ValueFilteredPropertySource(String name, BiFunction<String, String, String> valueFilter, PropertySource current) {
+ this.name = Optional.ofNullable(name).orElse("<valueFiltered> -> name="+current.getName()+", valueFilter="+valueFilter.toString());
+ }
+
+ @Override
+ public int getOrdinal() {
+ return source.getOrdinal();
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ String value = this.source.get(key).orElse(null);
+ value = valueFilter.apply(key, value);
+ return Optional.ofNullable(value);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(source.getProperties());
+ map.replaceAll(valueFilter);
+ return map;
+ }
+
+ @Override
+ public String toString() {
+ return "ValueFilteredPropertySource{" +
+ "source=" + source.getName() +
+ ", name='" + name + '\'' +
+ ", valueFilter=" + valueFilter +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/resource/InputStreamSource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/resource/InputStreamSource.java b/dormant/core/src/main/java/org/apache/tamaya/core/resource/InputStreamSource.java
deleted file mode 100644
index 102337d..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/resource/InputStreamSource.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
-* Copyright 2002-2012 the original author or authors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.tamaya.core.resource;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
-* Simple interface for objects that are sources for an {@link InputStream}.
-*
-* <p>This is the base interface for Spring's more extensive {@link Resource} interface.
-*
-* <p>For single-use streams, {@link org.apache.tamaya.core.internal.resources.io.InputStreamResource} can be used for any
-* given {@code InputStream}. Spring's {@code ByteArrayResource} or any
-* file-based {@code Resource} implementation can be used as a concrete
-* instance, allowing one to read the underlying content stream multiple times.
-* This makes this interface useful as an abstract content source for mail
-* attachments, for example.
-*
-* @author Juergen Hoeller
-* @since 20.01.2004
-* @see java.io.InputStream
-* @see Resource
-* @see org.apache.tamaya.core.internal.resources.io.InputStreamResource
-*/
-@FunctionalInterface
-public interface InputStreamSource {
-
- /**
- * Return an {@link InputStream}.
- * <p>It is expected that each call creates a <i>fresh</i> stream.
- * <p>This requirement is particularly important when you consider an API such
- * as JavaMail, which needs to be able to read the stream multiple times when
- * creating mail attachments. For such a use case, it is <i>required</i>
- * that each {@code getInputStreamSupplier()} call returns a fresh stream.
- * @return the input stream for the underlying resource (must not be {@code null})
- * @throws IOException if the stream could not be opened
- */
- InputStream getInputStream() throws IOException;
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/resource/Resource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/resource/Resource.java b/dormant/core/src/main/java/org/apache/tamaya/core/resource/Resource.java
deleted file mode 100644
index ca76974..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/resource/Resource.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright 2002-2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.resource;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-
-/**
- * Interface for a resource descriptor that abstracts from the actual
- * type current underlying resource, such as a file or class path resource.
- *
- * <p>An InputStream can be opened for every resource if it exists in
- * physical form, but a URL or File handle can just be returned for
- * certain resources. The actual behavior is implementation-specific.
- *
- * @author Juergen Hoeller
- * @since 28.12.2003
- * @see #getInputStream()
- * @see #getURL()
- * @see #getURI()
- * @see #getFile()
- */
-public interface Resource extends InputStreamSource {
-
- /**
- * Return whether this resource actually exists in physical form.
- * <p>This method performs a definitive existence check, whereas the
- * existence current a {@code Resource} handle only guarantees a
- * valid descriptor handle.
- */
- boolean exists();
-
- /**
- * Return whether the contents current this resource can be read,
- * e.g. via {@link #getInputStream()} or {@link #getFile()}.
- * <p>Will be {@code true} for typical resource descriptors;
- * note that actual content reading may still fail when attempted.
- * However, a keys current {@code false} is a definitive indication
- * that the resource content cannot be read.
- * @see #getInputStream()
- */
- boolean isReadable();
-
- /**
- * Return whether this resource represents a handle with an open
- * stream. If true, the InputStream cannot be read multiple times,
- * and must be read and closed to avoid resource leaks.
- * <p>Will be {@code false} for typical resource descriptors.
- */
- boolean isOpen();
-
- /**
- * Return a URL handle for this resource.
- * @throws IOException if the resource cannot be resolved as URL,
- * i.e. if the resource is not available as descriptor
- */
- URL getURL() throws IOException;
-
- /**
- * Return a URI handle for this resource.
- * @throws IOException if the resource cannot be resolved as URI,
- * i.e. if the resource is not available as descriptor
- */
- URI getURI() throws IOException;
-
- /**
- * Return a File handle for this resource.
- * @throws IOException if the resource cannot be resolved as absolute
- * file path, i.e. if the resource is not available in a file system
- */
- File getFile() throws IOException;
-
- /**
- * Determine the content length for this resource.
- * @throws IOException if the resource cannot be resolved
- * (in the file system or as some other known physical resource type)
- */
- long contentLength() throws IOException;
-
- /**
- * Determine the last-modified timestamp for this resource.
- * @throws IOException if the resource cannot be resolved
- * (in the file system or as some other known physical resource type)
- */
- long lastModified() throws IOException;
-
- /**
- * Create a resource relative to this resource.
- * @param relativePath the relative path (relative to this resource)
- * @return the resource handle for the relative resource
- * @throws IOException if the relative resource cannot be determined
- */
- Resource createRelative(String relativePath) throws IOException;
-
- /**
- * Determine a filename for this resource, i.e. typically the last
- * part current the path: for example, "myfile.txt".
- * <p>Returns {@code null} if this type current resource does not
- * have a filename.
- */
- String getFilename();
-
- /**
- * Get a description of the resource.
- * @return the description.
- */
- String getDescription();
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java b/dormant/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
deleted file mode 100644
index 1c55e55..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.resource;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Interface to be implemented by containers that decouples loading current classpath resources fromMap the effective
- * classloader architecture current a runtime environment. Implementations current this class encapsulate the mechanism current
- * determining the
- * concrete resources available base on an expression defining the configuration
- * locations. A an example the expression {@code cfg/global/*.xml} defines a
- * location for reading global configuration in the classpath. A resources
- * interprets this expression and evaluates the concrete resources to be read,
- * e.g. {@code cfg/global/default.xml, cfg/global/myApp.xml}.
- * Created by Anatole on 16.06.2014.
- */
-public interface ResourceLoader{
-
- /**
- * Get the prefixes supportedby this loader.
- *
- * @return the supported prefixes, not empty.
- */
- Collection<String> getResolverIds();
-
- /**
- * Called, when a given expression has to be resolved.
- *
- * @param expressions the expressions to be resolved, not empty.
- * @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
- * .
- */
- List<Resource> getResources(String... expressions);
-
- /**
- * Called, when a given expression has to be resolved.
- *
- * @param expressions the expressions to be resolved, not empty.
- * @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
- * .
- */
- List<Resource> getResources(Collection<String> expressions);
-
- /**
- * Called, when a given expression has to be resolved.
- *
- * @param expressions the expressions to be resolved, not empty.
- * @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
- * .
- */
- List<Resource> getResources(ClassLoader classLoader, String... expressions);
-
- /**
- * Called, when a given expression has to be resolved.
- *
- * @param expressions the expressions to be resolved, not empty.
- * @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
- * .
- */
- List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions);
-
-}
[04/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi b/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
deleted file mode 100644
index b3a2634..0000000
--- a/dormant/modules/metamodels/simple/src/main/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.metamodel.simple.SimpleConfigProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/modules/pom.xml
----------------------------------------------------------------------
diff --git a/dormant/modules/pom.xml b/dormant/modules/pom.xml
deleted file mode 100644
index e012023..0000000
--- a/dormant/modules/pom.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-all</artifactId>
- <version>0.1-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>tamaya-ext-all</artifactId>
- <groupId>org.apache.tamaya.ext</groupId>
- <name>Apache Tamaya Modules</name>
- <packaging>pom</packaging>
-
- <properties>
- <github.global.server>github</github.global.server>
- <jdkVersion>1.8</jdkVersion>
- <maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
- <maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.openejb</groupId>
- <artifactId>mbean-annotation-api</artifactId>
- <version>4.7.1</version>
- </dependency>
- </dependencies>
-
- <modules>
- <module>metamodels</module>
- <module>integration</module>
- <!-- <module>environment</module> -->
- </modules>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection/pom.xml b/modules/injection/pom.xml
new file mode 100644
index 0000000..90f0b59
--- /dev/null
+++ b/modules/injection/pom.xml
@@ -0,0 +1,40 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.integration</groupId>
+ <artifactId>tamaya-extensions-all</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-injection</artifactId>
+ <name>Apache Tamaya Injection Support</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperties.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperties.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperties.java
new file mode 100644
index 0000000..e1d773d
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperties.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation container to enable injection current multiple {@link org.apache.tamaya.annotation.ConfiguredProperty}
+ * annotations. Hereby the ordering current annotations imply the defaulting. The first keys that
+ * could be resolved successfully in the chain current annotations will be used.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface ConfiguredProperties {
+
+ /**
+ * Get the different configuration keys to be looked up, in order current precedence. The first non null keys
+ * found will be used.
+ */
+ ConfiguredProperty[] value() default {};
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java
new file mode 100644
index 0000000..21d4e3a
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * Annotation to enable injection current a configured property or define the returned data for
+ * a configuration template method. Hereby this annotation can be used in multiple ways and combined
+ * with other annotations such as {@link org.apache.tamaya.annotation.DefaultValue},
+ * {@link org.apache.tamaya.annotation.WithLoadPolicy}, {@link org.apache.tamaya.annotation.WithConfig},
+ * {@link org.apache.tamaya.annotation.WithConfigOperator}, {@link WithPropertyAdapter}.
+ *
+ * Below the most simple variant current a configured class is given:
+ * {@code
+ * pubic class ConfiguredItem{
+ *
+ * @ConfiguredProperty
+ * private String aValue;
+ * }
+ * When this class is configured, e.g. by passing it to {@link org.apache.tamaya.Configuration#configure(Object)},
+ * the following is happening:
+ * <ul>
+ * <li>The current valid Configuration is evaluated by calling {@code Configuration cfg = Configuration.current();}</li>
+ * <li>The current property String keys is evaluated by calling {@code cfg.get("aValue");}</li>
+ * <li>if not successful, an error is thrown ({@link org.apache.tamaya.ConfigException}.</li>
+ * <li>On success, since no type conversion is involved, the keys is injected.</li>
+ * <li>The configured bean is registered as a weak change listener in the config system's underlying
+ * configuration, so future config changes can be propagated (controlled by {@link org.apache.tamaya.annotation.WithLoadPolicy}
+ * annotations).</li>
+ * </ul>
+ *
+ * In the next example we explicitly define the property keys:
+ * {@code
+ * pubic class ConfiguredItem{
+ *
+ * @ConfiguredProperty
+ * @ConfiguredProperty({"a.b.value", "a.b.deprecated.keys", "${env:java.version}"})
+ * @ConfiguredProperty(configuration={"a", "b"}
+ * @ConfiguredProperty(configuration={"a", "b", keys={"a.b.keys", "a.b.deprecated.keys", "${env:java.version}"}}
+ * private String aValue;
+ * }
+ *
+ * Within this example we evaluate multiple possible keys. Evaluation is aborted if a key could be successfully
+ * resolved. Hereby the ordering current the annotations define the ordering current resolution, so in the example above
+ * resolution equals to {@code "aValue", "a.b.keys", "a.b.deprecated.keys"}. If no keys could be read
+ * fromMap the configuration, it uses the keys fromMap the {@code DefaultValue} annotation. Interesting here
+ * is that this keys is not static, it is evaluated by calling
+ * {@link org.apache.tamaya.Configuration#evaluateValue(String, org.apache.tamaya.Configuration...)}.
+ */
+@Repeatable(ConfiguredProperties.class)
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface ConfiguredProperty {
+
+ /**
+ * Annotation to reference an explicit {@link org.apache.tamaya.Configuration} to be used to
+ * resolve the required properties. the configured keys is passed to {@code Configuration.current(String)}
+ * to evaluate the required configuration required.
+ * @return the configurations to be looked up for the given keys.
+ */
+ String config() default "";
+
+ /**
+ * Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys.
+ *
+ * @return the property names, not null. If missing the field or method name being injected is used by default.
+ */
+ String[] keys() default {};
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/DefaultAreas.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/DefaultAreas.java b/modules/injection/src/main/java/org/apache/tamaya/inject/DefaultAreas.java
new file mode 100644
index 0000000..63ea137
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/DefaultAreas.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to control injection and resolution current a configured bean. The configuration keys
+ * to be resolved are basically determined by the {@link org.apache.tamaya.annotation.ConfiguredProperty}
+ * annotation(s). Nevertheless these annotations can also have relative key names. This annotation allows
+ * to define a configuration area that is prefixed to all relative configuration keys within the
+ * corresponding class/template interface.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.TYPE })
+public @interface DefaultAreas {
+
+ /**
+ * Allows to declare an operator that should be applied before injecting values into the bean.
+ * @return the operator class to be used.
+ */
+ String[] value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/DefaultValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/DefaultValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/DefaultValue.java
new file mode 100644
index 0000000..c4b2e3a
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/DefaultValue.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to define a default keys to be returned, when no configured keys could be
+ * determined for a property/template accessor. The keys hereby can also contain a
+ * dynamic expression that is evaluated by the configuration system.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface DefaultValue {
+
+ /**
+ * The default keys to be injected, if no such configuration entry was found. If keys was found and no default
+ * is defined, it is handled as a deployment error.
+ */
+ String value() default "";
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
new file mode 100644
index 0000000..b8e0cf5
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
@@ -0,0 +1,500 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+import java.beans.PropertyChangeEvent;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.ref.WeakReference;
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import java.util.logging.Logger;
+
+/**
+ * A accessor for a single configured value. This can be used to support values that may change during runtime, reconfigured or
+ * final. Hereby external code (could be Tamaya configuration listners or client code), can set a new value. Depending on the
+ * {@link org.apache.tamaya.DynamicValue.UpdatePolicy} the new value is immedeately active or it requires an active commit
+ * by client code. Similarly an instance also can ignore all later changes to the value.
+ * <h3>Implementation Details</h3>
+ * This class is
+ * <ul>
+ * <li>Serializable, when also the item stored is serializable</li>
+ * <li>Thread safe</li>
+ * </ul>
+ */
+public final class DynamicValue<T> implements Serializable{
+
+ /**
+ * Policy to control how new values are applied to this instance.
+ */
+ enum UpdatePolicy{
+ /** New values are applied immedately and registered listeners are informed about the change. */
+ IMMEDIATE,
+ /** New values or not applied, but stored in the newValue property. Explcit call to #commit
+ of #commitAndGet are required to accept the change and inform the listeners about the change.
+ */
+ EXPLCIT,
+ /**
+ * New values are always immedately discarded.
+ */
+ NEVER,
+ /**
+ * Changes are logged before the are discarded.
+ */
+ LOG_AND_DISCARD
+ }
+
+
+ /** The property name of the entry. */
+ private String propertyName;
+ /**
+ * Policy that defines how new values are applied, be default it is applied initially once, but never updated anymore.
+ */
+ private UpdatePolicy updatePolicy = UpdatePolicy.NEVER;
+ /** The current value, never null. */
+ private transient Optional<T> value;
+ /** The new value, or null. */
+ private transient Optional<T> newValue;
+ /** List of listeners that listen for changes. */
+ private transient WeakList<Consumer<PropertyChangeEvent>> listeners;
+
+ /**
+ * Returns an empty {@code Optional} instance. No value is present for this
+ * Optional.
+ *
+ * @apiNote Though it may be tempting to do so, avoid testing if an object
+ * is empty by comparing with {@code ==} against instances returned by
+ * {@code Option.empty()}. There is no guarantee that it is a singleton.
+ * Instead, use {@link #isPresent()}.
+ *
+ * @param <T> Type of the non-existent value
+ * @return an empty {@code Optional}
+ */
+ public static <T> DynamicValue<T> empty(String propertyName) {
+ DynamicValue v = new DynamicValue<T>(propertyName, null);
+ return v;
+ }
+
+ /**
+ * Constructor.
+ * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
+ * @param item the initial value.
+ */
+ private DynamicValue(String propertyName, Optional<T> item){
+ this.propertyName = Objects.requireNonNull(propertyName);
+ this.value = item;
+ }
+
+ /**
+ * Creates a new instance.
+ * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
+ * @param value the initial value, not null.
+ * @param <T> the type
+ * @return a new instance, never null
+ */
+ public static <T> DynamicValue<T> of(String propertyName, T value){
+ return new DynamicValue(propertyName, Optional.of(value));
+ }
+
+ /**
+ * Creates a new instance.
+ * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
+ * @param value the initial value
+ * @param <T> the target type.
+ * @return a new instance, never null
+ */
+ public static <T> DynamicValue<T> ofNullable(String propertyName, T value){
+ return value == null ? empty(propertyName) : of(propertyName, value);
+ }
+
+ /**
+ * Performs a commit, if necessary and returns the current value.
+ * otherwise throws {@code ConfigException}.
+ *
+ * @return the non-null value held by this {@code Optional}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ *
+ * @see DynamicValue#isPresent()
+ */
+ public T commitAndGet(){
+ commit();
+ return get();
+ }
+
+ /**
+ * Commits a new value that has not been committed yet, make it the new value of the instance. On change any registered listeners will be triggered.
+ */
+ public void commit(){
+ synchronized (value){
+ if(newValue!=null){
+ PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, value.orElse(null), newValue.orElse(null));
+ value = newValue;
+ newValue = null;
+ for(Consumer<PropertyChangeEvent> consumer: listeners.get()){
+ consumer.accept(evt);
+ }
+ }
+ }
+ }
+
+ /**
+ * Discards a new value that was published. No listeners will be informed.
+ */
+ public void discard(){
+ newValue = null;
+ }
+
+
+
+ /**
+ * Access the {@link UpdatePolicy} used for updating this value.
+ * @return the update policy, never null.
+ */
+ public UpdatePolicy getUpdatePolicy() {
+ return updatePolicy;
+ }
+
+ /**
+ * Add a listener to be called as weak reference, when this value has been changed.
+ * @param l the listner, not null
+ */
+ public void addListener(Consumer<PropertyChangeEvent> l) {
+ if(listeners==null){
+ listeners = new WeakList<>();
+ }
+ listeners.add(l);
+ }
+
+ /**
+ * Removes a listener to be called, when this value has been changed.
+ * @param l the listner to be removed, not null
+ */
+ public void removeListener(Consumer<PropertyChangeEvent> l) {
+ if(listeners!=null){
+ listeners.remove(l);
+ }
+ }
+
+ /**
+ * If a value is present in this {@code ConfiguredValue}, returns the value,
+ * otherwise throws {@code ConfigException}.
+ *
+ * @return the non-null value held by this {@code Optional}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ *
+ * @see DynamicValue#isPresent()
+ */
+ public T get() {
+ return value.get();
+ }
+
+ /**
+ * Method to apply a new value. Depending on the {@link org.apache.tamaya.DynamicValue.UpdatePolicy}
+ * the value is immediately or deferred visible (or it may even be ignored completely).
+ * @param newValue the new value, may also be null.
+ */
+ public void setNewValue(T newValue){
+ switch(this.updatePolicy){
+ case IMMEDIATE:
+ this.newValue = Optional.ofNullable(newValue);
+ commit();
+ break;
+ case EXPLCIT:
+ this.newValue = Optional.ofNullable(newValue);
+ break;
+ case LOG_AND_DISCARD:
+ Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", newValue="+newValue);
+ this.newValue = null;
+ break;
+ case NEVER:
+ this.newValue = null;
+ break;
+ }
+
+ }
+
+ /**
+ * Sets a new {@link org.apache.tamaya.DynamicValue.UpdatePolicy}.
+ * @param updatePolicy the new policy, not null.
+ */
+ public void setUpdatePolicy(UpdatePolicy updatePolicy){
+ this.updatePolicy = Objects.requireNonNull(updatePolicy);
+ }
+
+ /**
+ * Access a new value that has not yet been committed.
+ * @return the uncommitted new value, or null.
+ */
+ public T getNewValue(){
+ Optional<T> nv = newValue;
+ if(nv!=null){
+ return nv.orElse(null);
+ }
+ return null;
+ }
+
+ /**
+ * Return {@code true} if there is a value present, otherwise {@code false}.
+ *
+ * @return {@code true} if there is a value present, otherwise {@code false}
+ */
+ public boolean isPresent() {
+ return value.isPresent();
+ }
+
+ /**
+ * If a value is present, invoke the specified consumer with the value,
+ * otherwise do nothing.
+ *
+ * @param consumer block to be executed if a value is present
+ * @throws NullPointerException if value is present and {@code consumer} is
+ * null
+ */
+ public void ifPresent(Consumer<? super T> consumer) {
+ value.ifPresent(consumer);
+ }
+
+ /**
+ * If a value is present, and the value matches the given predicate,
+ * return an {@code Optional} describing the value, otherwise return an
+ * empty {@code Optional}.
+ *
+ * @param predicate a predicate to apply to the value, if present
+ * @return an {@code Optional} describing the value of this {@code Optional}
+ * if a value is present and the value matches the given predicate,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the predicate is null
+ */
+ public DynamicValue<T> filter(Predicate<? super T> predicate) {
+ Objects.requireNonNull(predicate);
+ if (!isPresent())
+ return this;
+ else
+ return predicate.test(value.get()) ? this : empty(propertyName);
+ }
+
+ /**
+ * If a value is present, apply the provided mapping function to it,
+ * and if the result is non-null, return an {@code Optional} describing the
+ * result. Otherwise return an empty {@code Optional}.
+ *
+ * @apiNote This method supports post-processing on optional values, without
+ * the need to explicitly check for a return status. For example, the
+ * following code traverses a stream of file names, selects one that has
+ * not yet been processed, and then opens that file, returning an
+ * {@code Optional<FileInputStream>}:
+ *
+ * <pre>{@code
+ * Optional<FileInputStream> fis =
+ * names.stream().filter(name -> !isProcessedYet(name))
+ * .findFirst()
+ * .map(name -> new FileInputStream(name));
+ * }</pre>
+ *
+ * Here, {@code findFirst} returns an {@code Optional<String>}, and then
+ * {@code map} returns an {@code Optional<FileInputStream>} for the desired
+ * file if one exists.
+ *
+ * @param <U> The type of the result of the mapping function
+ * @param mapper a mapping function to apply to the value, if present
+ * @return an {@code Optional} describing the result of applying a mapping
+ * function to the value of this {@code Optional}, if a value is present,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the mapping function is null
+ */
+ public <U> DynamicValue<U> map(Function<? super T, ? extends U> mapper) {
+ Objects.requireNonNull(mapper);
+ if (!isPresent())
+ return empty(propertyName);
+ else {
+ return DynamicValue.ofNullable(propertyName, mapper.apply(value.get()));
+ }
+ }
+
+ /**
+ * If a value is present, apply the provided {@code Optional}-bearing
+ * mapping function to it, return that result, otherwise return an empty
+ * {@code Optional}. This method is similar to {@link #map(Function)},
+ * but the provided mapper is one whose result is already an {@code Optional},
+ * and if invoked, {@code flatMap} does not wrap it with an additional
+ * {@code Optional}.
+ *
+ * @param <U> The type parameter to the {@code Optional} returned by
+ * @param mapper a mapping function to apply to the value, if present
+ * the mapping function
+ * @return the result of applying an {@code Optional}-bearing mapping
+ * function to the value of this {@code Optional}, if a value is present,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the mapping function is null or returns
+ * a null result
+ */
+ public <U> DynamicValue<U> flatMap(Function<? super T, DynamicValue<U>> mapper) {
+ Objects.requireNonNull(mapper);
+ if (!isPresent())
+ return empty(propertyName);
+ else {
+ return Objects.requireNonNull(mapper.apply(value.get()));
+ }
+ }
+
+ /**
+ * Return the value if present, otherwise return {@code other}.
+ *
+ * @param other the value to be returned if there is no value present, may
+ * be null
+ * @return the value, if present, otherwise {@code other}
+ */
+ public T orElse(T other) {
+ return value.orElse(other);
+ }
+
+ /**
+ * Return the value if present, otherwise invoke {@code other} and return
+ * the result of that invocation.
+ *
+ * @param other a {@code Supplier} whose result is returned if no value
+ * is present
+ * @return the value if present otherwise the result of {@code other.get()}
+ * @throws NullPointerException if value is not present and {@code other} is
+ * null
+ */
+ public T orElseGet(Supplier<? extends T> other) {
+ return value.orElseGet(other);
+ }
+
+ /**
+ * Return the contained value, if present, otherwise throw an exception
+ * to be created by the provided supplier.
+ *
+ * @apiNote A method reference to the exception constructor with an empty
+ * argument list can be used as the supplier. For example,
+ * {@code IllegalStateException::new}
+ *
+ * @param <X> Type of the exception to be thrown
+ * @param exceptionSupplier The supplier which will return the exception to
+ * be thrown
+ * @return the present value
+ * @throws X if there is no value present
+ * @throws NullPointerException if no value is present and
+ * {@code exceptionSupplier} is null
+ */
+ public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
+ return value.orElseThrow(exceptionSupplier);
+ }
+
+ /**
+ * Converts the instance to an {@link java.util.Optional} instance.
+ * @return the corresponding Optional value.
+ */
+ public Optional<T> toOptional(){
+ return value;
+ }
+
+ /**
+ * Serialization implementation that strips away the non serializable Optional part.
+ * @param oos the output stream
+ * @throws IOException if serialization fails.
+ */
+ private void writeObject(ObjectOutputStream oos)throws IOException {
+ oos.writeObject(updatePolicy);
+ if(isPresent()) {
+ oos.writeObject(this.value.get());
+ }
+ else{
+ oos.writeObject(null);
+ }
+ }
+
+ /**
+ * Reads an instance from the input stream.
+ * @param ois the object input stream
+ * @throws IOException if deserialization fails.
+ * @throws ClassNotFoundException
+ */
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ this.updatePolicy = (UpdatePolicy)ois.readObject();
+ if(isPresent()) {
+ this.value = Optional.of((T) ois.readObject());
+ }
+ newValue = null;
+ }
+
+
+ /**
+ * Simple helper that allows keeping the listeners registered as weak references, hereby avoiding any
+ * memory leaks.
+ * @param <T> the type
+ */
+ private class WeakList<T>{
+ List<WeakReference<T>> refs = new LinkedList<>();
+
+ /**
+ * Adds a new instance.
+ * @param t the new instance, not null.
+ */
+ void add(T t){
+ refs.add(new WeakReference(t));
+ }
+
+ /**
+ * Removes a instance.
+ * @param t the instance to be removed.
+ */
+ void remove(T t){
+ synchronized (refs){
+ for(Iterator<WeakReference<T>> iterator = refs.iterator();iterator.hasNext();){
+ WeakReference<T> ref = iterator.next();
+ T instance = ref.get();
+ if(instance==null || instance == t){
+ iterator.remove();
+ break;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Access a list (copy) of the current instances that were not discarded by the GC.
+ * @return the list of accessible items.
+ */
+ public List<T> get() {
+ synchronized (refs) {
+ List<T> res = new ArrayList<>();
+ for (Iterator<WeakReference<T>> iterator = refs.iterator(); iterator.hasNext(); ) {
+ WeakReference<T> ref = iterator.next();
+ T instance = ref.get();
+ if(instance==null){
+ iterator.remove();
+ }
+ else{
+ res.add(instance);
+ }
+ }
+ return res;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/LoadPolicy.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/LoadPolicy.java b/modules/injection/src/main/java/org/apache/tamaya/inject/LoadPolicy.java
new file mode 100644
index 0000000..116a2c1
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/LoadPolicy.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+/**
+ * Available policies that describe how changes affecting configured values are published/reinjected.
+ * The policy also affects the cases were any configured listeners/listener methods are called for
+ * propagation current configuration changes.
+ */
+public enum LoadPolicy {
+ /**
+ * The configuration keys is evaluated once, when the owning component is loaded/configured, but never updated later.
+ */
+ INITIAL,
+ /**
+ * The configuration keys is evaluated exactly once on its first use lazily, but never updated later.
+ * This feature is not applicable on field injection, but only on configuration template methods.
+ */
+ LAZY,
+ /**
+ * The configuration keys is evaluated once, when the owning component is loaded/configured.
+ * Later changes on this configuration entry will be reinjected/updated and additionally triggered
+ * as {@link java.beans.PropertyChangeEvent}.
+ */
+ MANAGED,
+ /**
+ * The configuration keys is evaluated once, when the owning component is loaded/configured.
+ * Later changes on this configuration entry will be reinjected/updated, but no {@link java.beans.PropertyChangeEvent}
+ * will be triggered.
+ */
+ SILENT
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java b/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
new file mode 100644
index 0000000..845ec4c
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * This is a small marker annotations to inform Tamaya that the annotated element should never be injected with
+ * configured data. This is useful because by default Tamaya tries to lookup and inject configuration also by
+ * using property or method names without annotations. With that annotation none of these will be happen.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface NoConfig {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/ObservesConfigChange.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ObservesConfigChange.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ObservesConfigChange.java
new file mode 100644
index 0000000..ef92b25
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/ObservesConfigChange.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to annotate a method on a class to be informed on config changes.
+ * The exact behaviour, when configuration change events are sent can be configured
+ * on each configured property/method by adding the {@link org.apache.tamaya.annotation.WithLoadPolicy}
+ * annotation. By default listeners are informed on all changes of configurations that were used as
+ * input configurations for configuring a class/instance. Additionally {@link org.apache.tamaya.annotation.ConfiguredProperty}
+ * annotations can be added that allows to constrain changes to some limited properties.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.METHOD })
+public @interface ObservesConfigChange {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/WithConfigOperator.java b/modules/injection/src/main/java/org/apache/tamaya/inject/WithConfigOperator.java
new file mode 100644
index 0000000..9f6c4f5
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/WithConfigOperator.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import org.apache.tamaya.Configuration;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.function.UnaryOperator;
+
+/**
+ * Annotation to define an configuration operator to be used before accessing a configured keys.
+ * This allows filtering current configuration, e.g. for realizing views or ensuring security
+ * constraints.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
+public @interface WithConfigOperator {
+
+ /**
+ * Define a custom adapter that should be used to adapt the configuration entry injected. This overrides any
+ * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is
+ * registered, it is handled as a deployment error.
+ */
+ Class<? extends UnaryOperator<Configuration>> value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/WithLoadPolicy.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/WithLoadPolicy.java b/modules/injection/src/main/java/org/apache/tamaya/inject/WithLoadPolicy.java
new file mode 100644
index 0000000..e469f5a
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/WithLoadPolicy.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to define how config changes are handled for a type or per property/template method.
+ * @see org.apache.tamaya.annotation.LoadPolicy
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
+public @interface WithLoadPolicy {
+
+ /**
+ * The load policy to be used. If this annotation is present a load policy must be defined.
+ * @return The load policy to be used, not null.
+ */
+ LoadPolicy value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyAdapter.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyAdapter.java b/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyAdapter.java
new file mode 100644
index 0000000..fa9cfdf
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyAdapter.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import org.apache.tamaya.PropertyAdapter;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to define a type adapter to be used before injecting a configured keys, or for applying changes.
+ * This will override any other adapter for performing the type conversion before
+ * injecting the field keys.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface WithPropertyAdapter {
+
+ /**
+ * Define a custom adapter or codec that should be used to adapt the configuration entry injected. This overrides any
+ * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is
+ * registered, it is handled as a deployment error.
+ */
+ @SuppressWarnings("rawtypes")
+ Class<? extends PropertyAdapter> value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
new file mode 100644
index 0000000..f929f8e
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import org.apache.tamaya.core.properties.PropertyChangeSet;
+import org.apache.tamaya.Configuration;
+
+import java.lang.reflect.Method;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class holds a method object that is annotated to be a callback method to be called on configuration
+ * changes.
+ */
+public final class ConfigChangeCallbackMethod {
+
+ private static final Logger LOG = Logger.getLogger(ConfigChangeCallbackMethod.class.getName());
+
+ private Method callbackMethod;
+
+ public ConfigChangeCallbackMethod(Method callbackMethod) {
+ this.callbackMethod = Optional.of(callbackMethod).filter(
+ (m) -> void.class.equals(m.getReturnType()) &&
+ m.getParameterCount() == 1 &&
+ m.getParameterTypes()[0].equals(PropertyChangeSet.class)).get();
+ }
+
+ public Consumer<PropertyChangeSet> createConsumer(Object instance, Configuration... configurations){
+ // TODO consider also environment !
+ return event -> {
+ for(Configuration cfg:configurations){
+ if(event.getPropertySource().getName().equals(cfg.getName())){
+ return;
+ }
+ }
+ call(instance, event);
+ };
+ }
+
+ public void call(Object instance, PropertyChangeSet configChangeEvent) {
+ try {
+ callbackMethod.setAccessible(true);
+ callbackMethod.invoke(instance, configChangeEvent);
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, e, () -> "Error calling ConfigChange callback method " + callbackMethod.getDeclaringClass().getName() + '.' + callbackMethod.getName() + " on " + instance);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
new file mode 100644
index 0000000..ff2c309
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.internal.inject.ConfiguredType;
+import org.apache.tamaya.core.internal.inject.InjectionUtils;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.Objects;
+
+/**
+ * Invocation handler that handles request against a configuration template.
+ */
+public final class ConfigTemplateInvocationHandler implements InvocationHandler {
+
+ /*
+ TODO
+ the given method (in case of a template) can use different caching strategies:
+ 1) no caching (always evaluate the values completely) - slow.
+ 2) instance caching (a cache per instance).
+ 3) classloader caching...
+ 4) global shared cache.
+ */
+
+
+ /**
+ * Any overriding configurations.
+ */
+ private Configuration[] configurations;
+ /**
+ * The configured type.
+ */
+ private ConfiguredType type;
+
+ /**
+ * Creates a new handler instance.
+ * @param type the target type, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ */
+ public ConfigTemplateInvocationHandler(Class<?> type, Configuration... configurations) {
+ this.configurations = Objects.requireNonNull(configurations).clone();
+ this.type = new ConfiguredType(Objects.requireNonNull(type));
+ if (!type.isInterface()) {
+ throw new IllegalArgumentException("Can only proxy interfaces as configuration templates.");
+ }
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ("toString".equals(method.getName())) {
+ return "Configured Proxy -> " + this.type.getType().getName();
+ }
+ String configValue = InjectionUtils.getConfigValue(method, configurations);
+ return InjectionUtils.adaptValue(method, method.getReturnType(), configValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigurationInjector.java
new file mode 100644
index 0000000..8a51375
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigurationInjector.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import org.apache.tamaya.Configuration;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Simple injector singleton that also registers instances configured using weak references.
+ */
+@SuppressWarnings("rawtypes")
+public final class ConfigurationInjector {
+
+ private static final ConfigurationInjector INSTANCE = new ConfigurationInjector();
+
+ private Map<Class, ConfiguredType> configuredTypes = new ConcurrentHashMap<>();
+
+ /**
+ * Extract the configuration annotation config and registers it per class, for later reuse.
+ * @param type the type to be configured.
+ * @return the configured type registered.
+ */
+ public static ConfiguredType registerType(Class<?> type){
+ return INSTANCE.configuredTypes.computeIfAbsent(type, ConfiguredType::new);
+ }
+
+ /**
+ * Configured the current instance and reigsterd necessary listener to forward config change events as
+ * defined by the current annotations in place.
+ * @param instance the instance to be configured
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ */
+ public static void configure(Object instance, Configuration... configurations){
+ Class type = Objects.requireNonNull(instance).getClass();
+ ConfiguredType configuredType = registerType(type);
+ Objects.requireNonNull(configuredType).configure(instance, configurations);
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
new file mode 100644
index 0000000..51c3904
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.annotation.ConfiguredProperties;
+import org.apache.tamaya.annotation.ConfiguredProperty;
+import org.apache.tamaya.annotation.DefaultAreas;
+import org.apache.tamaya.core.internal.Utils;
+
+/**
+ * Small class that contains and manages all information anc access to a configured field and a concrete instance current
+ * it (referenced by a weak reference). It also implements all aspects current keys filtering, converting any applying the
+ * final keys by reflection.
+ */
+public class ConfiguredField {
+
+
+ /**
+ * The configured field instance.
+ */
+ private Field annotatedField;
+
+ /**
+ * Models a configured field and provides mechanisms for injection.
+ *
+ * @param field the field instance.
+ */
+ public ConfiguredField(Field field) {
+ Objects.requireNonNull(field);
+ this.annotatedField = field;
+ }
+
+ /**
+ * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
+ *
+ * @param target the target instance.
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ * @throws ConfigException if evaluation or conversion failed.
+ */
+ public void applyInitialValue(Object target, Configuration... configurations) throws ConfigException {
+ String configValue = InjectionUtils.getConfigValue(this.annotatedField, configurations);
+ applyValue(target, configValue, false, configurations);
+ }
+
+
+ /**
+ * This method reapplies a changed configuration keys to the field.
+ *
+ * @param target the target instance, not null.
+ * @param configValue the new keys to be applied, null will trigger the evaluation current the configured default keys.
+ * @param resolve set to true, if expression resolution should be applied on the keys passed.
+ * @throws ConfigException if the configuration required could not be resolved or converted.
+ */
+ public void applyValue(Object target, String configValue, boolean resolve, Configuration... configurations) throws ConfigException {
+ Objects.requireNonNull(target);
+ try {
+ if (resolve && configValue != null) {
+ // net step perform exression resolution, if any
+ configValue = Configuration.evaluateValue(configValue, configurations);
+ }
+ // Check for adapter/filter
+ Object value = InjectionUtils.adaptValue(this.annotatedField, this.annotatedField.getType(), configValue);
+ annotatedField.setAccessible(true);
+ annotatedField.set(target, value);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to annotation configured field: " + this.annotatedField.getDeclaringClass()
+ .getName() + '.' + annotatedField.getName(), e);
+ }
+ }
+
+
+ /**
+ * This method checks if the given (qualified) configuration key is referenced fromMap this field.
+ * This is useful to determine, if a key changed in a configuration should trigger any change events
+ * on the related instances.
+ *
+ * @param key the (qualified) configuration key, not null.
+ * @return true, if the key is referenced.
+ */
+ public boolean matchesKey(String configName, String key) {
+ Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(this.annotatedField, ConfiguredProperty.class,
+ ConfiguredProperties.class );
+ for(ConfiguredProperty prop: configuredProperties){
+ String currentName = prop.config().trim();
+ if(currentName.isEmpty()){
+ if(!"default".equals(configName)){
+ continue;
+ }
+ }
+ else if(!currentName.equals(configName)){
+ continue;
+ }
+ DefaultAreas areasAnnot = this.annotatedField.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ List<String> keys = InjectionUtils.evaluateKeys(this.annotatedField, areasAnnot, prop);
+ if( keys.contains(key)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
new file mode 100644
index 0000000..90497ae
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+import org.apache.tamaya.core.properties.PropertyChangeSet;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.annotation.*;
+import org.apache.tamaya.core.internal.Utils;
+
+/**
+ * Small class that contains and manages all information and access to a configured field and a concrete instance current
+ * it (referenced by a weak reference). It also implements all aspects current keys filtering, conversions any applying the
+ * final keys by reflection.
+ */
+public class ConfiguredSetterMethod {
+
+ /**
+ * The configured field instance.
+ */
+ private Method setterMethod;
+
+ /**
+ * Models a configured field and provides mechanisms for injection.
+ *
+ * @param method the method instance.
+ */
+ public ConfiguredSetterMethod(Method method) {
+ this.setterMethod = Optional.of(method).filter(
+ (m) -> void.class.equals(m.getReturnType()) &&
+ m.getParameterCount() == 1).get();
+ }
+
+ public Consumer<PropertyChangeSet> createConsumer(Object instance, Configuration... configurations){
+ // TODO consider environment as well
+ return event -> {
+ for(Configuration cfg:configurations){
+ if(event.getPropertySource().getName().equals(cfg.getName())){
+ // ignore these changes, since this config is overridden.
+ return;
+ }
+ }
+ String configValue = InjectionUtils.getConfigValue(setterMethod, configurations);
+ applyValue(instance,configValue, false, configurations);
+ };
+ }
+
+
+ /**
+ * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
+ *
+ * @param target the target instance.
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ * @throws ConfigException if evaluation or conversion failed.
+ */
+ public void applyInitialValue(Object target, Configuration... configurations) throws ConfigException {
+ String configValue = InjectionUtils.getConfigValue(this.setterMethod, configurations);
+ applyValue(target, configValue, false, configurations);
+ }
+
+ /**
+ * This method reapplies a changed configuration keys to the field.
+ *
+ * @param target the target instance, not null.
+ * @param configValue the new keys to be applied, null will trigger the evaluation current the configured default keys.
+ * @param resolve set to true, if expression resolution should be applied on the keys passed.
+ * @throws org.apache.tamaya.ConfigException if the configuration required could not be resolved or converted.
+ */
+ public void applyValue(Object target, String configValue, boolean resolve, Configuration... configurations) throws ConfigException {
+ Objects.requireNonNull(target);
+ try {
+ if (resolve && configValue != null) {
+ // net step perform exression resolution, if any
+ configValue = Configuration.evaluateValue(configValue, configurations);
+ }
+ // Check for adapter/filter
+ Object value = InjectionUtils.adaptValue(this.setterMethod, this.setterMethod.getParameterTypes()[0], configValue);
+ setterMethod.setAccessible(true);
+ setterMethod.invoke(target, value);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to annotation configured method: " + this.setterMethod.getDeclaringClass()
+ .getName() + '.' + setterMethod.getName(), e);
+ }
+ }
+
+
+
+ /**
+ * This method checks if the given (qualified) configuration key is referenced fromMap this field.
+ * This is useful to determine, if a key changed in a configuration should trigger any change events
+ * on the related instances.
+ *
+ * @param key the (qualified) configuration key, not null.
+ * @return true, if the key is referenced.
+ */
+ public boolean matchesKey(String key) {
+ DefaultAreas areasAnnot = this.setterMethod.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ Collection<ConfiguredProperty> configuredProperties =
+ Utils.getAnnotations(this.setterMethod, ConfiguredProperty.class, ConfiguredProperties.class);
+ for(ConfiguredProperty prop: configuredProperties) {
+ if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot, prop).contains(key)) {
+ return true;
+ }
+ }
+ if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot).contains(key)) {
+ return true;
+ }
+ return false;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
new file mode 100644
index 0000000..879d54a
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
+
+import org.apache.tamaya.core.properties.PropertyChangeSet;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertySource;
+import org.apache.tamaya.annotation.*;
+import org.apache.tamaya.core.internal.Utils;
+
+/**
+ * Structure that contains and manages configuration related things for a configured type registered.
+ * Created by Anatole on 03.10.2014.
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class ConfiguredType {
+ /**
+ * A list with all annotated instance variables.
+ */
+ private List<ConfiguredField> configuredFields = new ArrayList<>();
+ /**
+ * A list with all annotated methods (templates).
+ */
+ private List<ConfiguredSetterMethod> configuredSetterMethods = new ArrayList<>();
+ /**
+ * A list with all callback methods listening to config changes.
+ */
+ private List<ConfigChangeCallbackMethod> callbackMethods = new ArrayList<>();
+ /**
+ * The basic type.
+ */
+ private Class type;
+
+ /**
+ * Creates an instance of this class hereby evaluating the config annotations given for later effective
+ * injection (configuration) of instances.
+ *
+ * @param type the instance type.
+ */
+
+ public ConfiguredType(Class type) {
+ this.type = Objects.requireNonNull(type);
+ initFields(type);
+ initMethods(type);
+ }
+
+ private void initFields(Class type) {
+ for (Field f : type.getDeclaredFields()) {
+ if (f.isAnnotationPresent(NoConfig.class)) {
+ continue;
+ }
+ try {
+ ConfiguredField configuredField = new ConfiguredField(f);
+ configuredFields.add(configuredField);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured field: " +
+ f.getDeclaringClass().getName() + '.' + f.getName(), e);
+ }
+ }
+ }
+
+ private void initMethods(Class type) {
+ // TODO revisit this logic here...
+ for (Method m : type.getDeclaredMethods()) {
+ if (m.isAnnotationPresent(NoConfig.class)) {
+ continue;
+ }
+ ObservesConfigChange mAnnot = m.getAnnotation(ObservesConfigChange.class);
+ Collection<ConfiguredProperty> propertiesAnnots = Utils.getAnnotations(m, ConfiguredProperty.class, ConfiguredProperties.class);
+ if (type.isInterface()) {
+ // it is a template
+ if (mAnnot != null) {
+ if (m.isDefault()) {
+ addObserverMethod(m);
+ }
+ } else {
+ if (m.isDefault()) {
+ addPropertySetter(m, propertiesAnnots);
+ }
+ }
+ } else {
+ if (mAnnot != null) {
+ addObserverMethod(m);
+ } else {
+ addPropertySetter(m, propertiesAnnots);
+ }
+ }
+ }
+ }
+
+ private boolean addPropertySetter(Method m, Collection<ConfiguredProperty> propertiesAnnots) {
+ if (!propertiesAnnots.isEmpty()) {
+ if (m.getParameterTypes().length == 0) {
+ // getter method
+ Class<?> returnType = m.getReturnType();
+ if (!void.class.equals(returnType)) {
+ try {
+ configuredSetterMethods.add(new ConfiguredSetterMethod(m));
+ return true;
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured setter method: " +
+ m.getDeclaringClass().getName() + '.' + m.getName(), e);
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+
+
+ private void addObserverMethod(Method m) {
+ if (m.getParameterTypes().length != 1) {
+ return;
+ }
+ if (!m.getParameterTypes()[0].equals(PropertyChangeSet.class)) {
+ return;
+ }
+ if (!void.class.equals(m.getReturnType())) {
+ return;
+ }
+ try {
+ this.callbackMethods.add(new ConfigChangeCallbackMethod(m));
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured callback method: " +
+ m.getDeclaringClass().getName() + '.' + m.getName(), e);
+ }
+ }
+
+
+ /**
+ * Method called to configure an instance.
+ *
+ * @param instance The instance to be configured.
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ */
+ public void configure(Object instance, Configuration... configurations) {
+ for (ConfiguredField field : configuredFields) {
+ field.applyInitialValue(instance, configurations);
+ }
+ for (ConfiguredSetterMethod method : configuredSetterMethods) {
+ method.applyInitialValue(instance, configurations);
+ // TODO, if method should be recalled on changes, corresponding callbacks could be registered here
+ WeakConfigListenerManager.of().registerConsumer(instance, method.createConsumer(instance, configurations));
+ }
+ // Register callbacks for this intance (weakly)
+ for (ConfigChangeCallbackMethod callback : callbackMethods) {
+ WeakConfigListenerManager.of().registerConsumer(instance, callback.createConsumer(instance, configurations));
+ }
+ }
+
+
+ private String getName(Object source) {
+ if (source instanceof PropertySource) {
+ PropertySource ps = (PropertySource) source;
+ return ps.getName();
+ }
+ return "N/A";
+ }
+
+
+ public boolean isConfiguredBy(Configuration configuration) {
+ // TODO implement this
+ return true;
+ }
+
+ public static boolean isConfigured(Class type) {
+ if (type.getAnnotation(DefaultAreas.class) != null) {
+ return true;
+ }
+ // if no class level annotation is there we might have field level annotations only
+ for (Field field : type.getDeclaredFields()) {
+ if (field.isAnnotationPresent(ConfiguredProperties.class)) {
+ return true;
+ }
+ }
+ // if no class level annotation is there we might have method level annotations only
+ for (Method method : type.getDeclaredMethods()) {
+ if (method.isAnnotationPresent(ConfiguredProperties.class)) {
+ return true;
+ }
+ }
+ for (Field field : type.getDeclaredFields()) {
+ if (field.isAnnotationPresent(ConfiguredProperty.class)) {
+ return true;
+ }
+ }
+ // if no class level annotation is there we might have method level annotations only
+ for (Method method : type.getDeclaredMethods()) {
+ if (method.isAnnotationPresent(ConfiguredProperty.class)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Class getType() {
+ return this.type;
+ }
+}
[12/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java b/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
deleted file mode 100644
index f8b1c95..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.tamaya.core.config;
-
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.BiFunction;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.core.properties.AggregationPolicy;
-import org.apache.tamaya.core.properties.PropertySourceBuilder;
-
-/**
-* Builder for assembling non trivial {@link org.apache.tamaya.Configuration} instances.
-*/
-public final class ConfigurationBuilder {
-
- /**
- * The final meta info to be used, or null, if a default should be generated.
- */
- private PropertySourceBuilder builderDelegate;
-
- /**
- * Private singleton constructor.
- */
- private ConfigurationBuilder(String name) {
- this.builderDelegate = PropertySourceBuilder.of(name);
- }
-
- /**
- * Private singleton constructor.
- */
- private ConfigurationBuilder(String name, PropertySource source) {
- this.builderDelegate = PropertySourceBuilder.of(name, source);
- }
-
- /**
- * Private singleton constructor.
- */
- private ConfigurationBuilder(PropertySource source) {
- this.builderDelegate = PropertySourceBuilder.of(source);
- }
-
-
- /**
- * Creates a new builder instance.
- *
- * @param provider the base provider to be used, not null.
- * @return a new builder instance, never null.
- */
- public static ConfigurationBuilder of(PropertySource provider) {
- return new ConfigurationBuilder(provider);
- }
-
- /**
- * Creates a new builder instance.
- *
- * @param name the provider name, not null.
- * @return a new builder instance, never null.
- */
- public static ConfigurationBuilder of(String name) {
- return new ConfigurationBuilder(Objects.requireNonNull(name));
- }
-
- /**
- * Creates a new builder instance.
- *
- * @return a new builder instance, never null.
- */
- public static ConfigurationBuilder of() {
- return new ConfigurationBuilder("<noname>");
- }
-
-
-
-
- /**
- * Sets the aggregation policy to be used, when adding additional property sets. The policy will
- * be active a slong as the builder is used or it is reset to another keys.
- *
- * @param aggregationPolicy the aggregation policy, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder withAggregationPolicy(AggregationPolicy aggregationPolicy) {
- this.builderDelegate.withAggregationPolicy(aggregationPolicy);
- return this;
- }
-
- /**
- * Sets the meta info to be used for the next operation.
- *
- * @param name the name, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder withName(String name) {
- this.builderDelegate.withName(name);
- return this;
- }
-
- /**
- * Adds the given providers with the current active {@link AggregationPolicy}. By
- * default {@link AggregationPolicy#OVERRIDE} is used.
- * @see #withAggregationPolicy(AggregationPolicy)
- * @param providers providers to be added, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addProviders(PropertySource... providers) {
- this.builderDelegate.addProviders(providers);
- return this;
- }
-
- /**
- * Adds the given providers with the current active {@link AggregationPolicy}. By
- * default {@link AggregationPolicy#OVERRIDE} is used.
- * @see #withAggregationPolicy(AggregationPolicy)
- * @param providers providers to be added, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addProviders(List<PropertySource> providers) {
- this.builderDelegate.addProviders(providers);
- return this;
- }
-
-
- /**
- * Creates a new {@link org.apache.tamaya.PropertySource} using the given command line arguments and adds it
- * using the current aggregation policy in place.
- *
- * @param args the command line arguments, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addArgs(String... args) {
- this.builderDelegate.addArgs(args);
- return this;
- }
-
- /**
- * Creates a new read-only {@link org.apache.tamaya.PropertySource} by reading the according path resources. The effective resources read
- * hereby are determined by the {@code PathResolverService} configured into the {@code Bootstrap} SPI.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param paths the paths to be resolved by the {@code PathResolverService} , not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addPaths(String... paths) {
- this.builderDelegate.addPaths(paths);
- return this;
- }
-
-
- /**
- * Creates a new read-only {@link org.apache.tamaya.PropertySource} by reading the according path resources. The effective resources read
- * hereby are determined by the {@code PathResolverService} configured into the {@code Bootstrap} SPI.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param paths the paths to be resolved by the {@code PathResolverService} , not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addPaths(List<String> paths) {
- this.builderDelegate.addPaths(paths);
- return this;
- }
-
- /**
- * Creates a new read-only {@link org.apache.tamaya.PropertySource} by reading the according URL resources.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param urls the urls to be read, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addURLs(URL... urls) {
- this.builderDelegate.addURLs(urls);
- return this;
- }
-
- /**
- * Creates a new read-only {@link org.apache.tamaya.PropertySource} by reading the according URL resources.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param urls the urls to be read, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addURLs(List<URL> urls) {
- this.builderDelegate.addURLs(urls);
- return this;
- }
-
-
- /**
- * Creates a new read-only {@link org.apache.tamaya.PropertySource} based on the given map.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param map the map to be added, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addMap(Map<String, String> map) {
- this.builderDelegate.addMap(map);
- return this;
- }
-
-
- /**
- * Add the current environment properties. Aggregation is based on the current {@link AggregationPolicy} acvtive.
- *
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addEnvironmentProperties() {
- this.builderDelegate.addEnvironmentProperties();
- return this;
- }
-
- /**
- * Add the current system properties. Aggregation is based on the current {@link AggregationPolicy} acvtive.
- *
- * @return the builder for chaining.
- */
- public ConfigurationBuilder addSystemProperties() {
- this.builderDelegate.addSystemProperties();
- return this;
- }
-
- /**
- * Adds the given {@link org.apache.tamaya.PropertySource} instances using the current {@link AggregationPolicy}
- * active.
- *
- * @param providers the maps to be included, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder aggregate(PropertySource... providers) {
- this.builderDelegate.aggregate(providers);
- return this;
- }
-
-
- /**
- * Adds the given {@link org.apache.tamaya.PropertySource} instances using the current {@link AggregationPolicy}
- * active.
- *
- * @param providers the maps to be included, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder aggregate(List<PropertySource> providers) {
- this.builderDelegate.aggregate(providers);
- return this;
- }
-
-
- /**
- * Intersetcs the current properties with the given {@link org.apache.tamaya.PropertySource} instance.
- *
- * @param providers the maps to be intersected, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder intersect(PropertySource... providers) {
- this.builderDelegate.intersect(providers);
- return this;
- }
-
-
- /**
- * Subtracts with the given {@link org.apache.tamaya.PropertySource} instance from the current properties.
- *
- * @param providers the maps to be subtracted, not null.
- * @return the builder for chaining.
- */
- public ConfigurationBuilder subtract(PropertySource... providers) {
- this.builderDelegate.subtract(providers);
- return this;
- }
-
-
- /**
- * Filters the current properties based on the given predicate..
- *
- * @param filter the filter to be applied, not null.
- * @return the new filtering instance.
- */
- public ConfigurationBuilder filter(Predicate<String> filter) {
- this.builderDelegate.filter(filter);
- return this;
- }
-
- /**
- * Filters the current {@link org.apache.tamaya.Configuration} with the given valueFilter.
- * @param valueFilter the value filter, not null.
- * @return the (dynamically) filtered source instance, never null.
- */
- public ConfigurationBuilder filterValues(BiFunction<String, String, String> valueFilter){
- this.builderDelegate.filterValues(valueFilter);
- return this;
- }
-
- /**
- * Creates a new contextual {@link org.apache.tamaya.PropertySource}. Contextual maps delegate to different instances current PropertyMap depending
- * on the keys returned fromMap the isolationP
- *
- * @param mapSupplier the supplier creating new provider instances
- * @param isolationKeySupplier the supplier providing contextual keys based on the current environment.
- */
- public ConfigurationBuilder addContextual(Supplier<PropertySource> mapSupplier,
- Supplier<String> isolationKeySupplier) {
- this.builderDelegate.addContextual(mapSupplier, isolationKeySupplier);
- return this;
- }
-
- /**
- * Replaces all keys in the current provider by the given map.
- *
- * @param replacementMap the map instance, that will replace all corresponding entries in {@code mainMap}, not null.
- * @return the new delegating instance.
- */
- public ConfigurationBuilder replace(Map<String, String> replacementMap) {
- this.builderDelegate.replace(replacementMap);
- return this;
- }
-
- /**
- * Build a new property provider based on the input.
- * @return a new property provider, or null.
- */
- public PropertySource buildPropertySource(){
- return this.builderDelegate.build();
- }
-
- /**
- * Build a new property provider based on the input.
- * @return a new property provider, or null.
- */
- public Configuration build(){
- return this.buildPropertySource().toConfiguration();
- }
-
- /**
- * Creates a {@link org.apache.tamaya.PropertySource} instance that is serializable and immutable,
- * so it can be sent over a network connection.
- *
- * @return the freezed instance, never null.
- */
- public PropertySource buildFreezedPropertySource() {
- return this.builderDelegate.buildFrozen();
- }
-
- /**
- * Creates a {@link org.apache.tamaya.PropertySource} instance that is serializable and immutable,
- * so it can be sent over a network connection.
- *
- * @return the freezed instance, never null.
- */
- public Configuration buildFreezed() {
- return FreezedConfiguration.of(this.buildFreezedPropertySource().toConfiguration());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java b/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java
deleted file mode 100644
index 8feaf6a..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.config;
-
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.spi.ConfigurationFormatSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Implementations current this class encapsulate the mechanism how to read a
- * resource URI including interpreting the format correctly (e.g. xml vs.
- * properties).
- */
-public interface ConfigurationFormat{
-
- /**
- * Returns a unique identifier that identifies each format.
- *
- * @return the unique format id, mever null.
- */
- public String getFormatName();
-
- /**
- * Check if the given {@link java.net.URI} and path xpression qualify that this format should be
- * able to read them, e.g. checking for compatible file endings.
- *
- * @param resource the configuration location, not null
- * @return {@code true} if the given resource is in a format supported by
- * this instance.
- */
- boolean isAccepted(Resource resource);
-
- /**
- * Reads a {@link org.apache.tamaya.PropertySource} fromMap the given URI, using this format.
- *
- * @param resource the configuration location, not null
- * @return the corresponding {@link java.util.Map}, never {@code null}.
- */
- Map<String,String> readConfiguration(Resource resource);
-
- /**
- * Access a {@link ConfigurationFormat}.
- *
- * @param formatName the format name
- * @return the corresponding {@link ConfigurationFormat}, or {@code null}, if
- * not available for the given environment.
- */
- public static ConfigurationFormat of(String formatName){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormat(formatName);
- }
-
- /**
- * Get a collection current the keys current the registered {@link ConfigurationFormat} instances.
- *
- * @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
- */
- public static Collection<String> getFormatNames(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormatNames();
- }
-
- /**
- * Evaluate the matching format for a given resource.
- *
- * @param resource The resource
- * @return a matching configuration format, or {@code null} if no matching format could be determined.
- */
- public static ConfigurationFormat from(Resource resource){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormat(resource);
-
- }
-
- /**
- * Get an instance for reading configuration fromMap a {@code .properties} file,
- * as defined by {@link java.util.Properties#load(java.io.InputStream)}.
- *
- * @return a format instance for reading configuration fromMap a {@code .properties} file, never null.
- */
- public static ConfigurationFormat getPropertiesFormat(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getPropertiesFormat();
- }
-
- /**
- * Get an instance for reading configuration fromMap a {@code .xml} properties file,
- * as defined by {@link java.util.Properties#loadFromXML(java.io.InputStream)}.
- *
- * @return a format instance for reading configuration fromMap a {@code .xml} properties file, never null.
- */
- public static ConfigurationFormat getXmlPropertiesFormat(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getXmlPropertiesFormat();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java b/dormant/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
deleted file mode 100644
index 43d6957..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.config;
-
-import org.apache.tamaya.*;
-import org.apache.tamaya.core.properties.PropertySourceBuilder;
-
-import java.io.Serializable;
-import java.util.Map;
-
-/**
- * Configuration implementation that stores all current values current a given (possibly dynamic, contextual and non remote
- * capable instance) and is fully serializable.
- */
-final class FreezedConfiguration extends AbstractConfiguration implements Serializable{
- private static final long serialVersionUID = -6373137316556444171L;
-
- private PropertySource properties;
-
- /**
- * Constructor.
- * @param config The base configuration.
- */
- private FreezedConfiguration(Configuration config){
- super(config.getName());
- this.properties = PropertySourceBuilder.of(config).buildFrozen();
- }
-
- public static final Configuration of(Configuration config){
- if(config instanceof FreezedConfiguration){
- return config;
- }
- return new FreezedConfiguration(config);
- }
-
- @Override
- public Map<String,String> getProperties(){
- return properties.getProperties();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- FreezedConfiguration that = (FreezedConfiguration) o;
-
- if (!properties.equals(that.properties)) return false;
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = properties.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return "FreezedConfiguration{" +
- "properties=" + properties +
- ", name=" + name +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/config/FrozenConfiguration.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/config/FrozenConfiguration.java b/dormant/core/src/main/java/org/apache/tamaya/core/config/FrozenConfiguration.java
new file mode 100644
index 0000000..43d6957
--- /dev/null
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/config/FrozenConfiguration.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.config;
+
+import org.apache.tamaya.*;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * Configuration implementation that stores all current values current a given (possibly dynamic, contextual and non remote
+ * capable instance) and is fully serializable.
+ */
+final class FreezedConfiguration extends AbstractConfiguration implements Serializable{
+ private static final long serialVersionUID = -6373137316556444171L;
+
+ private PropertySource properties;
+
+ /**
+ * Constructor.
+ * @param config The base configuration.
+ */
+ private FreezedConfiguration(Configuration config){
+ super(config.getName());
+ this.properties = PropertySourceBuilder.of(config).buildFrozen();
+ }
+
+ public static final Configuration of(Configuration config){
+ if(config instanceof FreezedConfiguration){
+ return config;
+ }
+ return new FreezedConfiguration(config);
+ }
+
+ @Override
+ public Map<String,String> getProperties(){
+ return properties.getProperties();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ FreezedConfiguration that = (FreezedConfiguration) o;
+
+ if (!properties.equals(that.properties)) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = properties.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "FreezedConfiguration{" +
+ "properties=" + properties +
+ ", name=" + name +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java b/dormant/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
deleted file mode 100644
index 736b33e..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.apache.tamaya.core.config;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.UnaryOperator;
-
-import org.apache.tamaya.Configuration;
-
-/**
- * Configuration implementation that maps certain parts (defined by an {@code UnaryOperator<String>}) to alternate areas.
- */
-class MappedConfiguration extends AbstractConfiguration implements Configuration {
-
- private static final long serialVersionUID = 8690637705511432083L;
-
- /** The mapping operator. */
- private UnaryOperator<String> keyMapper;
- /** The base configuration. */
- private Configuration config;
-
- /**
- * Creates a new instance.
- * @param config the base configuration, not null
- * @param keyMapper The mapping operator, not null
- */
- public MappedConfiguration(Configuration config, UnaryOperator<String> keyMapper) {
- super(config.getName());
- this.config = Objects.requireNonNull(config);
- this.keyMapper = Objects.requireNonNull(keyMapper);
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> result = new HashMap<>();
- Map<String, String> map = this.config.getProperties();
- map.forEach((k,v) -> {
- String targetKey = keyMapper.apply(k);
- if(targetKey!=null){
- result.put(targetKey, v);
- }
- });
- return result;
- }
-
- @Override
- public boolean isEmpty() {
- return this.config.isEmpty();
- }
-
- @Override
- public Configuration toConfiguration() {
- return this;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
index 8d3ad15..6233a93 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
@@ -18,9 +18,9 @@
*/
package org.apache.tamaya.core.internal;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
@@ -44,16 +44,18 @@ public final class MetaConfig {
private Map<String,String> properties = new HashMap<>();
private MetaConfig(){
- List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(MetaConfig.class.getClassLoader(),
+ List<Resource> resources = ServiceContext.getInstance().getService(ResourceLoader.class).get().getResources(MetaConfig.class.getClassLoader(),
"classpath:META-INF/config.properties");
for(Resource res:resources){
- try{
- ConfigurationFormat format = ConfigurationFormat.from(res);
- Map<String,String> read = format.readConfiguration(res);
- properties.putAll(read);
- }
- catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error reading meta configuration fromMap " + res);
+ List<ConfigurationFormat> formats = ConfigurationFormat.getFormats(res);
+ for(ConfigurationFormat format:formats) {
+ try {
+
+ Map<String, String> read = format.readConfiguration(res);
+ properties.putAll(read);
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, e, () -> "Error reading meta configuration fromMap " + res);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
deleted file mode 100644
index 8b7180c..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.config;
-
-import java.lang.reflect.Proxy;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.internal.el.DefaultExpressionEvaluator;
-import org.apache.tamaya.core.internal.inject.ConfigTemplateInvocationHandler;
-import org.apache.tamaya.core.internal.inject.ConfigurationInjector;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
-import org.apache.tamaya.core.spi.ExpressionEvaluator;
-import org.apache.tamaya.spi.ConfigurationSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-
-/**
- * Default SPI that implements the behaviour of {@link org.apache.tamaya.spi.ConfigurationSpi}.
- */
-@SuppressWarnings("unchecked")
-public class DefaultConfigurationSpi implements ConfigurationSpi {
-
- private static final String DEFAULT_CONFIG_NAME = "default";
-
- private Map<String, ConfigurationProviderSpi> configProviders = new ConcurrentHashMap<>();
-
- private ExpressionEvaluator expressionEvaluator = loadEvaluator();
-
- private ExpressionEvaluator loadEvaluator() {
- ExpressionEvaluator eval = ServiceContext.getInstance().getService(ExpressionEvaluator.class).orElse(null);
- if (eval == null) {
- eval = new DefaultExpressionEvaluator();
- }
- return eval;
- }
-
- public DefaultConfigurationSpi() {
- if(configProviders.isEmpty()) {
- for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
- configProviders.put(spi.getConfigName(), spi);
- }
- }
- }
-
- @Override
- public <T> T createTemplate(Class<T> type, Configuration... configurations) {
- ClassLoader cl = Optional.ofNullable(Thread.currentThread()
- .getContextClassLoader()).orElse(getClass().getClassLoader());
- return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, configurations));
- }
-
- /**
- *
- * @param instance the instance with configuration annotations, not null.
- * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
- * If no items are passed, the default configuration is used.
- */
- @Override
- public void configure(Object instance, Configuration... configurations) {
- ConfigurationInjector.configure(instance, configurations);
- }
-
-
- @Override
- public String evaluateValue(String expression, Configuration... configurations) {
- return expressionEvaluator.evaluate(expression, configurations);
- }
-
- @Override
- public boolean isConfigurationAvailable(String name) {
- ConfigurationProviderSpi spi = this.configProviders.get(name);
- return spi != null;
- }
-
- @Override
- public Configuration getConfiguration(String name) {
- ConfigurationProviderSpi provider = configProviders.get(name);
- if (provider == null) {
- if (DEFAULT_CONFIG_NAME.equals(name)) {
- provider = new FallbackSimpleConfigProvider();
- configProviders.put(DEFAULT_CONFIG_NAME, provider);
- } else {
- throw new ConfigException("No such config: " + name);
- }
- }
- Configuration config = provider.getConfiguration();
- if (config == null) {
- throw new ConfigException("No such config: " + name);
- }
- return config;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultPropertyAdapterSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultPropertyAdapterSpi.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultPropertyAdapterSpi.java
deleted file mode 100644
index f1b14e0..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultPropertyAdapterSpi.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.config;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZoneId;
-import java.util.Currency;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.PropertyAdapter;
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-import org.apache.tamaya.spi.PropertyAdapterSpi;
-
-/**
- * Default codecs singleton, which provides default codesc for all kind of classes out of the box, which will be
- * instantiatable from configuration, if one of the following is given:
- * <ul>
- * <li>static factory methods using a String as simgle argument, called {@code of, valueOf, getInstance, instance, parse}</li>
- * <li>have constructors taking a single String</li>
- * </ul>
- */
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class DefaultPropertyAdapterSpi implements PropertyAdapterSpi {
-
-
- private Map<Class,PropertyAdapter> adapters = new ConcurrentHashMap<>();
-
- public DefaultPropertyAdapterSpi(){
- // Add default adapters
- register(char.class, (s) -> s.charAt(0));
- register(byte.class, Byte::parseByte);
- register(short.class, Short::parseShort);
- register(int.class, Integer::parseInt);
- register(long.class, Long::parseLong);
- register(boolean.class, Boolean::parseBoolean);
- register(float.class, Float::parseFloat);
- register(double.class, Double::parseDouble);
-
- register(Character.class, (s) -> s.charAt(0));
- register(Byte.class, Byte::valueOf);
- register(Short.class, Short::valueOf);
- register(Integer.class, Integer::valueOf);
- register(Long.class, Long::valueOf);
- register(Boolean.class, Boolean::valueOf);
- register(Float.class, Float::valueOf);
- register(Double.class, Double::valueOf);
- register(BigDecimal.class, BigDecimal::new);
- register(BigInteger.class, BigInteger::new);
-
- register(Currency.class, Currency::getInstance);
-
- register(LocalDate.class, LocalDate::parse);
- register(LocalTime.class, LocalTime::parse);
- register(LocalDateTime.class, LocalDateTime::parse);
- register(ZoneId.class, ZoneId::of);
- }
-
- @Override
- public <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter){
- return adapters.put(targetType, adapter);
- }
-
- @Override
- public <T> PropertyAdapter<T> getPropertyAdapter(Class<T> targetType, WithPropertyAdapter adapterAnnot){
- PropertyAdapter codec = null;
- Class<? extends PropertyAdapter> configuredCodec = null;
- if(adapterAnnot != null){
- configuredCodec = adapterAnnot.value();
- if(!configuredCodec.equals(PropertyAdapter.class)){
- try{
- codec = configuredCodec.newInstance();
- }
- catch(Exception e){
- throw new ConfigException("Invalid codec configured.", e);
- }
- }
- }
- if(codec == null){
- codec = adapters.get(targetType);
- }
- if(codec == null){
- codec = getDefaultPropertyAdapter(targetType);
- }
- if(codec == null){
- throw new ConfigException("No Codec found for " + targetType.getName());
- }
- return codec;
- }
-
- private <T> PropertyAdapter getDefaultPropertyAdapter(Class<T> targetType) {
- PropertyAdapter<T> decoder = null;
- Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "parse");
- if(factoryMethod!=null){
- decoder = (s) -> {
- try{
- factoryMethod.setAccessible(true);
- return targetType.cast(factoryMethod.invoke(s));
- }
- catch (Exception e){
- throw new ConfigException("Failed to decode '"+s+"'", e);
- }
- };
- }
- if(decoder==null) {
- try {
- Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
- decoder = (s) -> {
- try{
- constr.setAccessible(true);
- return constr.newInstance(s);
- }
- catch (Exception e){
- throw new ConfigException("Failed to decode '"+s+"'", e);
- }
- };
- } catch (Exception e) {
- // ignore, TODO log finest
- }
- }
- if(decoder!=null) {
- return register(targetType, decoder);
- }
- return null;
- }
-
- private Method getFactoryMethod(Class<?> type, String... methodNames) {
- Method m;
- for(String name:methodNames){
- try{
- m = type.getDeclaredMethod(name, String.class);
- return m;
- }
- catch(Exception e){
- // ignore, TODO log finest
- }
- }
- return null;
- }
-
- @Override
- public boolean isTargetTypeSupported(Class<?> targetType){
- return adapters.containsKey(targetType);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
deleted file mode 100644
index 6fd4672..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.config;
-
-import org.apache.tamaya.core.properties.PropertySourceBuilder;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
-
-import org.apache.tamaya.Configuration;
-
-/**
- * Provides a {@link org.apache.tamaya.Configuration} named 'environment.properties'
- * containing the current environment properties.
- *
- * Created by Anatole on 29.09.2014.
- */
-public class EnvPropertiesConfigProvider implements ConfigurationProviderSpi{
-
- private Configuration envConfig;
-
- public EnvPropertiesConfigProvider(){
- envConfig = Configuration.from(PropertySourceBuilder.of("environment.properties").addEnvironmentProperties().build());
- }
-
- @Override
- public String getConfigName(){
- return "environment.properties";
- }
-
- @Override
- public Configuration getConfiguration(){
- return envConfig;
- }
-
- @Override
- public void reload() {
- // nothing todo here
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
index 7bcfb77..240fc8a 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
@@ -3,10 +3,11 @@ package org.apache.tamaya.core.internal.config;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.core.properties.AggregationPolicy;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+import old.ConfigurationProviderSpi;
+import org.apache.tamaya.core.properties.PropertySourcesBuilder;
/**
- * Implementation of a default config provider used as fallback, if no {@link org.apache.tamaya.core.spi.ConfigurationProviderSpi}
+ * Implementation of a default config provider used as fallback, if no {@link old.ConfigurationProviderSpi}
* instance is registered for providing the {@code default} {@link org.apache.tamaya.Configuration}. The providers loads the follwing
* config resources:
* <ul>
@@ -44,12 +45,10 @@ public class FallbackSimpleConfigProvider implements ConfigurationProviderSpi {
@Override
public void reload() {
this.configuration = Configuration.from(
- PropertySourceBuilder.of(DEFAULT_CONFIG_NAME)
- .addProviders(PropertySourceBuilder.of("CL default")
- .withAggregationPolicy(AggregationPolicy.LOG_ERROR)
+ PropertySourcesBuilder.of()
.addPaths("META-INF/cfg/default/**/*.xml", "META-INF/cfg/default/**/*.properties", "META-INF/cfg/default/**/*.ini")
.build())
- .addProviders(PropertySourceBuilder.of("CL default")
+ .addProviders(PropertySourcesBuilder.of("CL default")
.withAggregationPolicy(AggregationPolicy.LOG_ERROR)
.addPaths("META-INF/cfg/config/**/*.xml", "META-INF/cfg/config/**/*.properties", "META-INF/cfg/config/**/*.ini")
.build())
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
index afd1199..cdb7b33 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
@@ -17,7 +17,7 @@ import java.util.Objects;
import org.apache.log4j.Logger;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+import old.ConfigurationProviderSpi;
/**
* Class that has the responsibility to watch the folder and then commit the {@link ConfigurationProviderSpi}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
index c2cf7fa..b171d39 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
@@ -15,7 +15,7 @@ import java.util.concurrent.Executors;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+import old.ConfigurationProviderSpi;
/**
* This implementation run in a folder and once found xml and properties files
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
deleted file mode 100644
index cdd90b2..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.config;
-
-import org.apache.tamaya.core.properties.PropertySourceBuilder;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
-
-import org.apache.tamaya.Configuration;
-
-/**
- * Provides a {@link org.apache.tamaya.Configuration} named 'system.properties'
- * containing the current system properties.
- *
- * Created by Anatole on 29.09.2014.
- */
-public class SystemPropertiesConfigProvider implements ConfigurationProviderSpi{
-
- private Configuration systemConfig;
-
- public SystemPropertiesConfigProvider(){
- systemConfig = Configuration.from(PropertySourceBuilder.of("system.properties").addSystemProperties().build());
- }
-
- @Override
- public String getConfigName(){
- return "system.properties";
- }
-
- @Override
- public Configuration getConfiguration(){
- return systemConfig;
- }
-
- @Override
- public void reload() {
- // nothing todo here
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java
deleted file mode 100644
index 457aa6c..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.el;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.spi.ExpressionEvaluator;
-import org.apache.tamaya.core.spi.ExpressionResolver;
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Default expression evaluator that manages several instances of {@link org.apache.tamaya.core.spi.ExpressionResolver}.
- * Each resolver is identified by a resolver id. Each expression passed has the form resolverId:resolverExpression, which
- * has the advantage that different resolvers can be active in parallel.
- */
-public final class DefaultExpressionEvaluator implements ExpressionEvaluator{
-
- private Map<String, ExpressionResolver> resolvers = new ConcurrentHashMap<>();
-
- private ExpressionResolver defaultResolver;
-
- public DefaultExpressionEvaluator() {
- for(ExpressionResolver resolver: ServiceContext.getInstance().getServices(ExpressionResolver.class)){
- resolvers.put(resolver.getResolverId(), resolver);
- }
- defaultResolver = ServiceContext.getInstance().getSingleton(ExpressionResolver.class);
- }
-
- /**
- * Resolves an expression in the form current <code>${resolverId:expression}</code>. The expression can be
- * part current any type current literal text. Also multiple expression, with different resolver ids are supported.
- * All control characters (${}\) can be escaped.<br>
- * So all the following are valid expressions:
- * <ul>
- * <li><code>${resolverId:expression}</code></li>
- * <li><code>bla bla ${resolverId:expression}</code></li>
- * <li><code>${resolverId:expression} bla bla</code></li>
- * <li><code>bla bla ${resolverId:expression} bla bla</code></li>
- * <li><code>${resolverId:expression}${resolverId2:expression2}</code></li>
- * <li><code>foo ${resolverId:expression}${resolverId2:expression2}</code></li>
- * <li><code>foo ${resolverId:expression} bar ${resolverId2:expression2}</code></li>
- * <li><code>${resolverId:expression}foo${resolverId2:expression2}bar</code></li>
- * <li><code>foor${resolverId:expression}bar${resolverId2:expression2}more</code></li>
- * <li><code>\${resolverId:expression}foo${resolverId2:expression2}bar</code> (first expression is escaped).</li>
- * </ul>
- *
- * @param expression the expression to be evaluated, not null
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
- * If no such config is passed, the default configurations provided by the current
- * registered providers are used.
- * @return the evaluated expression.
- * @throws org.apache.tamaya.ConfigException if resolution fails.
- */
- @Override
- public String evaluate(String expression, Configuration... configurations) {
- StringTokenizer tokenizer = new StringTokenizer(expression, "${}\\", true);
- boolean escaped = false;
- StringBuilder resolvedValue = new StringBuilder();
- StringBuilder current = new StringBuilder();
- while (tokenizer.hasMoreTokens()) {
- String token = tokenizer.nextToken();
- if (escaped) {
- switch (token) {
- case "n":
- current.append("\n");
- break;
- case "r":
- current.append("\r");
- break;
- case "t":
- current.append("\t");
- break;
- default:
- current.append(token);
- break;
- }
- escaped = false;
- continue;
- }
- switch (token) {
- case "\\":
- escaped = true;
- break;
- case "$":
- if (current.length() > 0) {
- resolvedValue.append(current);
- current.setLength(0);
- }
- if (!"{".equals(tokenizer.nextToken())) {
- throw new ConfigException("Invalid expression encountered: " + expression);
- }
- String subExpression = tokenizer.nextToken();
- if (!"}".equals(tokenizer.nextToken())) {
- throw new ConfigException("Invalid expression encountered: " + expression);
- }
- // evaluate sub-expression
- current.append(evaluteInternal(subExpression));
- break;
- default:
- current.append(token);
- }
- }
- if (current.length() > 0) {
- resolvedValue.append(current);
- }
- return resolvedValue.toString();
- }
-
- private String evaluteInternal(String subExpression) {
- int sepPos = subExpression.indexOf(':');
- if (sepPos > 0) {
- String refID = subExpression.substring(0, sepPos);
- String expression = subExpression.substring(sepPos + 1);
- return Optional.ofNullable(this.resolvers.get(refID)).orElseThrow(
- () -> new ConfigException("Resolver not found: " + refID + " in " + subExpression)
- ).resolve(expression);
- } else {
- return Optional.ofNullable(this.defaultResolver).orElseThrow(
- () -> new ConfigException("No default Resolver set, but required by " + subExpression)
- ).resolve(subExpression);
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java
deleted file mode 100644
index 68d37a4..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.el;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.spi.ExpressionResolver;
-
-import java.util.Optional;
-
-/**
- * Property resolver implementation that interprets the resolver expressions as environment properties.
- */
-public final class EnvironmentPropertyResolver implements ExpressionResolver{
-
- @Override
- public String getResolverId() {
- return "env";
- }
-
- @Override
- public String resolve(String expression, Configuration... configurations){
- return Optional.ofNullable(System.getenv(expression)).orElseThrow(
- () -> new ConfigException("No such environment property: " + expression)
- );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
deleted file mode 100644
index c6eb298..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.el;
-
-import java.util.Optional;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.spi.ExpressionResolver;
-
-/**
- * Property resolver implementation that interprets the resolver expression as system property name.
- */
-public final class SystemPropertyResolver implements ExpressionResolver{
-
- @Override
- public String getResolverId() {
- return "sys";
- }
-
- @Override
- public String resolve(String expression, Configuration... configurations){
- return Optional.ofNullable(System.getProperty(expression)).orElseThrow(
- () -> new ConfigException("No such system property: " + expression)
- );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
index eac0a3b..c4b7ad2 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
@@ -32,47 +32,7 @@ import org.apache.tamaya.spi.ServiceContext;
*/
public final class DefaultConfigurationFormatSpi implements ConfigurationFormatSpi {
- public ConfigurationFormat getFormat(String formatName){
- Objects.requireNonNull(formatName);
- try {
- for (ConfigurationFormat configFormat : ServiceContext.getInstance().getServices(ConfigurationFormat.class)) {
- if(formatName.equals(configFormat.getFormatName())){
- return configFormat;
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- return null;
- }
- public Collection<String> getFormatNames(){
- Set<String> result = new HashSet<>();
- try {
- result.addAll(ServiceContext.getInstance().getServices(ConfigurationFormat.class).stream().map(ConfigurationFormat::getFormatName)
- .collect(Collectors.toList()));
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- return result;
- }
-
- public ConfigurationFormat getFormat(Resource resource) {
- Objects.requireNonNull(resource);
- try {
- for (ConfigurationFormat configFormat : ServiceContext.getInstance().getServices(ConfigurationFormat.class)) {
- if(configFormat.isAccepted(resource)){
- return configFormat;
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- return null;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
deleted file mode 100644
index f929f8e..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.inject;
-
-import org.apache.tamaya.core.properties.PropertyChangeSet;
-import org.apache.tamaya.Configuration;
-
-import java.lang.reflect.Method;
-import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class holds a method object that is annotated to be a callback method to be called on configuration
- * changes.
- */
-public final class ConfigChangeCallbackMethod {
-
- private static final Logger LOG = Logger.getLogger(ConfigChangeCallbackMethod.class.getName());
-
- private Method callbackMethod;
-
- public ConfigChangeCallbackMethod(Method callbackMethod) {
- this.callbackMethod = Optional.of(callbackMethod).filter(
- (m) -> void.class.equals(m.getReturnType()) &&
- m.getParameterCount() == 1 &&
- m.getParameterTypes()[0].equals(PropertyChangeSet.class)).get();
- }
-
- public Consumer<PropertyChangeSet> createConsumer(Object instance, Configuration... configurations){
- // TODO consider also environment !
- return event -> {
- for(Configuration cfg:configurations){
- if(event.getPropertySource().getName().equals(cfg.getName())){
- return;
- }
- }
- call(instance, event);
- };
- }
-
- public void call(Object instance, PropertyChangeSet configChangeEvent) {
- try {
- callbackMethod.setAccessible(true);
- callbackMethod.invoke(instance, configChangeEvent);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, e, () -> "Error calling ConfigChange callback method " + callbackMethod.getDeclaringClass().getName() + '.' + callbackMethod.getName() + " on " + instance);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java
deleted file mode 100644
index ff2c309..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.inject;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.internal.inject.ConfiguredType;
-import org.apache.tamaya.core.internal.inject.InjectionUtils;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.Objects;
-
-/**
- * Invocation handler that handles request against a configuration template.
- */
-public final class ConfigTemplateInvocationHandler implements InvocationHandler {
-
- /*
- TODO
- the given method (in case of a template) can use different caching strategies:
- 1) no caching (always evaluate the values completely) - slow.
- 2) instance caching (a cache per instance).
- 3) classloader caching...
- 4) global shared cache.
- */
-
-
- /**
- * Any overriding configurations.
- */
- private Configuration[] configurations;
- /**
- * The configured type.
- */
- private ConfiguredType type;
-
- /**
- * Creates a new handler instance.
- * @param type the target type, not null.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- */
- public ConfigTemplateInvocationHandler(Class<?> type, Configuration... configurations) {
- this.configurations = Objects.requireNonNull(configurations).clone();
- this.type = new ConfiguredType(Objects.requireNonNull(type));
- if (!type.isInterface()) {
- throw new IllegalArgumentException("Can only proxy interfaces as configuration templates.");
- }
- }
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if ("toString".equals(method.getName())) {
- return "Configured Proxy -> " + this.type.getType().getName();
- }
- String configValue = InjectionUtils.getConfigValue(method, configurations);
- return InjectionUtils.adaptValue(method, method.getReturnType(), configValue);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
deleted file mode 100644
index 8a51375..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.inject;
-
-import org.apache.tamaya.Configuration;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Simple injector singleton that also registers instances configured using weak references.
- */
-@SuppressWarnings("rawtypes")
-public final class ConfigurationInjector {
-
- private static final ConfigurationInjector INSTANCE = new ConfigurationInjector();
-
- private Map<Class, ConfiguredType> configuredTypes = new ConcurrentHashMap<>();
-
- /**
- * Extract the configuration annotation config and registers it per class, for later reuse.
- * @param type the type to be configured.
- * @return the configured type registered.
- */
- public static ConfiguredType registerType(Class<?> type){
- return INSTANCE.configuredTypes.computeIfAbsent(type, ConfiguredType::new);
- }
-
- /**
- * Configured the current instance and reigsterd necessary listener to forward config change events as
- * defined by the current annotations in place.
- * @param instance the instance to be configured
- * @param configurations Configuration instances that replace configuration served by services. This allows
- * more easily testing and adaption.
- */
- public static void configure(Object instance, Configuration... configurations){
- Class type = Objects.requireNonNull(instance).getClass();
- ConfiguredType configuredType = registerType(type);
- Objects.requireNonNull(configuredType).configure(instance, configurations);
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
deleted file mode 100644
index 51c3904..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.inject;
-
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.annotation.ConfiguredProperties;
-import org.apache.tamaya.annotation.ConfiguredProperty;
-import org.apache.tamaya.annotation.DefaultAreas;
-import org.apache.tamaya.core.internal.Utils;
-
-/**
- * Small class that contains and manages all information anc access to a configured field and a concrete instance current
- * it (referenced by a weak reference). It also implements all aspects current keys filtering, converting any applying the
- * final keys by reflection.
- */
-public class ConfiguredField {
-
-
- /**
- * The configured field instance.
- */
- private Field annotatedField;
-
- /**
- * Models a configured field and provides mechanisms for injection.
- *
- * @param field the field instance.
- */
- public ConfiguredField(Field field) {
- Objects.requireNonNull(field);
- this.annotatedField = field;
- }
-
- /**
- * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
- *
- * @param target the target instance.
- * @param configurations Configuration instances that replace configuration served by services. This allows
- * more easily testing and adaption.
- * @throws ConfigException if evaluation or conversion failed.
- */
- public void applyInitialValue(Object target, Configuration... configurations) throws ConfigException {
- String configValue = InjectionUtils.getConfigValue(this.annotatedField, configurations);
- applyValue(target, configValue, false, configurations);
- }
-
-
- /**
- * This method reapplies a changed configuration keys to the field.
- *
- * @param target the target instance, not null.
- * @param configValue the new keys to be applied, null will trigger the evaluation current the configured default keys.
- * @param resolve set to true, if expression resolution should be applied on the keys passed.
- * @throws ConfigException if the configuration required could not be resolved or converted.
- */
- public void applyValue(Object target, String configValue, boolean resolve, Configuration... configurations) throws ConfigException {
- Objects.requireNonNull(target);
- try {
- if (resolve && configValue != null) {
- // net step perform exression resolution, if any
- configValue = Configuration.evaluateValue(configValue, configurations);
- }
- // Check for adapter/filter
- Object value = InjectionUtils.adaptValue(this.annotatedField, this.annotatedField.getType(), configValue);
- annotatedField.setAccessible(true);
- annotatedField.set(target, value);
- } catch (Exception e) {
- throw new ConfigException("Failed to annotation configured field: " + this.annotatedField.getDeclaringClass()
- .getName() + '.' + annotatedField.getName(), e);
- }
- }
-
-
- /**
- * This method checks if the given (qualified) configuration key is referenced fromMap this field.
- * This is useful to determine, if a key changed in a configuration should trigger any change events
- * on the related instances.
- *
- * @param key the (qualified) configuration key, not null.
- * @return true, if the key is referenced.
- */
- public boolean matchesKey(String configName, String key) {
- Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(this.annotatedField, ConfiguredProperty.class,
- ConfiguredProperties.class );
- for(ConfiguredProperty prop: configuredProperties){
- String currentName = prop.config().trim();
- if(currentName.isEmpty()){
- if(!"default".equals(configName)){
- continue;
- }
- }
- else if(!currentName.equals(configName)){
- continue;
- }
- DefaultAreas areasAnnot = this.annotatedField.getDeclaringClass().getAnnotation(DefaultAreas.class);
- List<String> keys = InjectionUtils.evaluateKeys(this.annotatedField, areasAnnot, prop);
- if( keys.contains(key)){
- return true;
- }
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
deleted file mode 100644
index 90497ae..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.inject;
-
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Consumer;
-
-import org.apache.tamaya.core.properties.PropertyChangeSet;
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.annotation.*;
-import org.apache.tamaya.core.internal.Utils;
-
-/**
- * Small class that contains and manages all information and access to a configured field and a concrete instance current
- * it (referenced by a weak reference). It also implements all aspects current keys filtering, conversions any applying the
- * final keys by reflection.
- */
-public class ConfiguredSetterMethod {
-
- /**
- * The configured field instance.
- */
- private Method setterMethod;
-
- /**
- * Models a configured field and provides mechanisms for injection.
- *
- * @param method the method instance.
- */
- public ConfiguredSetterMethod(Method method) {
- this.setterMethod = Optional.of(method).filter(
- (m) -> void.class.equals(m.getReturnType()) &&
- m.getParameterCount() == 1).get();
- }
-
- public Consumer<PropertyChangeSet> createConsumer(Object instance, Configuration... configurations){
- // TODO consider environment as well
- return event -> {
- for(Configuration cfg:configurations){
- if(event.getPropertySource().getName().equals(cfg.getName())){
- // ignore these changes, since this config is overridden.
- return;
- }
- }
- String configValue = InjectionUtils.getConfigValue(setterMethod, configurations);
- applyValue(instance,configValue, false, configurations);
- };
- }
-
-
- /**
- * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
- *
- * @param target the target instance.
- * @param configurations Configuration instances that replace configuration served by services. This allows
- * more easily testing and adaption.
- * @throws ConfigException if evaluation or conversion failed.
- */
- public void applyInitialValue(Object target, Configuration... configurations) throws ConfigException {
- String configValue = InjectionUtils.getConfigValue(this.setterMethod, configurations);
- applyValue(target, configValue, false, configurations);
- }
-
- /**
- * This method reapplies a changed configuration keys to the field.
- *
- * @param target the target instance, not null.
- * @param configValue the new keys to be applied, null will trigger the evaluation current the configured default keys.
- * @param resolve set to true, if expression resolution should be applied on the keys passed.
- * @throws org.apache.tamaya.ConfigException if the configuration required could not be resolved or converted.
- */
- public void applyValue(Object target, String configValue, boolean resolve, Configuration... configurations) throws ConfigException {
- Objects.requireNonNull(target);
- try {
- if (resolve && configValue != null) {
- // net step perform exression resolution, if any
- configValue = Configuration.evaluateValue(configValue, configurations);
- }
- // Check for adapter/filter
- Object value = InjectionUtils.adaptValue(this.setterMethod, this.setterMethod.getParameterTypes()[0], configValue);
- setterMethod.setAccessible(true);
- setterMethod.invoke(target, value);
- } catch (Exception e) {
- throw new ConfigException("Failed to annotation configured method: " + this.setterMethod.getDeclaringClass()
- .getName() + '.' + setterMethod.getName(), e);
- }
- }
-
-
-
- /**
- * This method checks if the given (qualified) configuration key is referenced fromMap this field.
- * This is useful to determine, if a key changed in a configuration should trigger any change events
- * on the related instances.
- *
- * @param key the (qualified) configuration key, not null.
- * @return true, if the key is referenced.
- */
- public boolean matchesKey(String key) {
- DefaultAreas areasAnnot = this.setterMethod.getDeclaringClass().getAnnotation(DefaultAreas.class);
- Collection<ConfiguredProperty> configuredProperties =
- Utils.getAnnotations(this.setterMethod, ConfiguredProperty.class, ConfiguredProperties.class);
- for(ConfiguredProperty prop: configuredProperties) {
- if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot, prop).contains(key)) {
- return true;
- }
- }
- if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot).contains(key)) {
- return true;
- }
- return false;
- }
-
-
-
-}
[07/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java
deleted file mode 100644
index cf94d99..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.spi.ConfigurationFormatSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Implementations current this class encapsulate the mechanism how to read a
- * resource URI including interpreting the format correctly (e.g. xml vs.
- * properties).
- */
-public interface ConfigurationFormat{
-
- /**
- * Returns a unique identifier that identifies each format.
- *
- * @return the unique format id, mever null.
- */
- public String getFormatName();
-
- /**
- * Check if the given {@link java.net.URI} and path xpression qualify that this format should be
- * able to read them, e.g. checking for compatible file endings.
- *
- * @param resource the configuration location, not null
- * @return {@code true} if the given resource is in a format supported by
- * this instance.
- */
- boolean isAccepted(Resource resource);
-
- /**
- * Reads a {@link org.apache.tamaya.PropertySource} fromMap the given URI, using this format.
- *
- * @param resource the configuration location, not null
- * @return the corresponding {@link java.util.Map}, never {@code null}.
- */
- Map<String,String> readConfiguration(Resource resource);
-
- /**
- * Access a {@link ConfigurationFormat}.
- *
- * @param formatName the format name
- * @return the corresponding {@link ConfigurationFormat}, or {@code null}, if
- * not available for the given environment.
- */
- public static ConfigurationFormat of(String formatName){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormat(formatName);
- }
-
- /**
- * Get a collection current the keys current the registered {@link ConfigurationFormat} instances.
- *
- * @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
- */
- public static Collection<String> getFormatNames(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormatNames();
- }
-
- /**
- * Evaluate the matching format for a given resource.
- *
- * @param resource The resource
- * @return a matching configuration format, or {@code null} if no matching format could be determined.
- */
- public static ConfigurationFormat from(Resource resource){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormat(resource);
-
- }
-
- /**
- * Get an instance for reading configuration fromMap a {@code .properties} file,
- * as defined by {@link java.util.Properties#load(java.io.InputStream)}.
- *
- * @return a format instance for reading configuration fromMap a {@code .properties} file, never null.
- */
- public static ConfigurationFormat getPropertiesFormat(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getPropertiesFormat();
- }
-
- /**
- * Get an instance for reading configuration fromMap a {@code .xml} properties file,
- * as defined by {@link java.util.Properties#loadFromXML(java.io.InputStream)}.
- *
- * @return a format instance for reading configuration fromMap a {@code .xml} properties file, never null.
- */
- public static ConfigurationFormat getXmlPropertiesFormat(){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getXmlPropertiesFormat();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
deleted file mode 100644
index 6290706..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.*;
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Supplier;
-
-/**
- * Created by Anatole on 12.04.2014.
- */
-class ContextualPropertySource implements PropertySource {
-
- private volatile Map<String,PropertySource> cachedMaps = new ConcurrentHashMap<>();
-
- private Supplier<PropertySource> mapSupplier;
- private Supplier<String> isolationKeySupplier;
- private String name;
-
-
- /**
- * Creates a new contextual PropertyMap. Contextual maps delegate to different instances current PropertyMap depending
- * on the keys returned fromMap the isolationP
- *
- * @param mapSupplier
- * @param isolationKeySupplier
- */
- public ContextualPropertySource(String name, Supplier<PropertySource> mapSupplier, Supplier<String> isolationKeySupplier){
- this.name = Optional.ofNullable(name).orElse("<noname>");
- Objects.requireNonNull(mapSupplier);
- Objects.requireNonNull(isolationKeySupplier);
- this.mapSupplier = mapSupplier;
- this.isolationKeySupplier = isolationKeySupplier;
- }
-
- /**
- * This method provides the contextual Map for the current environment. Hereby, ba default, for each different
- * key returned by the #isolationKeySupplier a separate PropertyMap instance is acquired fromMap the #mapSupplier.
- * If the map supplier returns an instance it is cached in the local #cachedMaps.
- *
- * @return the current contextual PropertyMap.
- */
- protected PropertySource getContextualMap(){
- String environmentKey = this.isolationKeySupplier.get();
- if(environmentKey == null){
- return PropertySource.EMPTY_PROPERTYSOURCE;
- }
- PropertySource map = this.cachedMaps.get(environmentKey);
- if(map == null){
- synchronized(cachedMaps){
- map = this.cachedMaps.get(environmentKey);
- if(map == null){
- map = this.mapSupplier.get();
- if(map == null){
- return PropertySource.EMPTY_PROPERTYSOURCE;
- }
- this.cachedMaps.put(environmentKey, map);
- }
- }
- }
- return map;
- }
-
- @Override
- public Map<String,String> getProperties(){
- return getContextualMap().getProperties();
- }
-
- @Override
- public String getName(){
- return this.name;
- }
-
- @Override
- public Optional<String> get(String key){
- return getContextualMap().get(key);
- }
-
- /**
- * Access a cached PropertyMap.
- *
- * @param key the target environment key as returned by the environment key supplier, not null.
- * @return the corresponding PropertyMap, or null.
- */
- public PropertySource getCachedMap(String key){
- return this.cachedMaps.get(key);
- }
-
- /**
- * Access the set current currently loaded/cached maps.
- *
- * @return the set current cached map keys, never null.
- */
- public Set<String> getCachedMapKeys(){
- return this.cachedMaps.keySet();
- }
-
- /**
- * Access the supplier for environment key, determining map isolation.
- *
- * @return the environment key supplier instance, not null.
- */
- public Supplier<String> getIsolationKeySupplier(){
- return this.isolationKeySupplier;
- }
-
- /**
- * Access the supplier for new PropertyMap instances.
- *
- * @return the PropertyMap supplier instance, not null.
- */
- public Supplier<PropertySource> getMapSupplier(){
- return this.mapSupplier;
- }
-
- @Override
- public String toString(){
- return "ContextualMap{" +
- "cachedMaps(key)=" + cachedMaps.keySet() +
- ", mapSupplier=" + mapSupplier +
- ", isolationKeySupplier=" + isolationKeySupplier +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
deleted file mode 100644
index c4bfc92..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.PropertySource;
-
-import java.util.*;
-
-/**
- * Implementation for a {@link org.apache.tamaya.PropertySource} that is an aggregate current
- * multiple child instances. Controlled by an {@link org.apache.tamaya.AggregationPolicy} the
- * following aggregations are supported:
- * <ul>
- * <li><b>IGNORE_DUPLICATES: </b>Ignore all overrides.</li>
- * <li><b>: </b></li>
- * <li><b>: </b></li>
- * <li><b>: </b></li>
- * </ul>
- */
-class DelegatingPropertySource implements PropertySource {
-
- private PropertySource mainMap;
- private Map<String,String> parentMap;
- private String name;
-
-
- /**
- * Creates a mew instance, with aggregation polilcy
- * {@code AggregationPolicy.OVERRIDE}.
- *
- * @param mainMap The main ConfigMap.
- * @param parentMap The delegated parent ConfigMap.
- */
- public DelegatingPropertySource(String name, PropertySource mainMap, Map<String, String> parentMap){
- this.name = Optional.of(name).orElse("<noname>");
- this.parentMap = Objects.requireNonNull(parentMap);
- this.parentMap = Objects.requireNonNull(parentMap);
- }
-
- @Override
- public Map<String,String> getProperties(){
- return null;
- }
-
- @Override
- public String getName(){
- return this.name;
- }
-
- @Override
- public Optional<String> get(String key){
- Optional<String> val = mainMap.get(key);
- if(!val.isPresent()){
- return Optional.ofNullable(parentMap.get(key));
- }
- return val;
- }
-
- @Override
- public String toString(){
- return super.toString() + "(mainMap=" + mainMap + ", delegate=" + parentMap + ")";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
index d0b2172..f74bcb4 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
@@ -20,21 +20,29 @@ package org.apache.tamaya.core.properties;
import java.util.Map;
-class EnvironmentPropertySource extends AbstractPropertySource {
+public class EnvironmentPropertySource implements PropertySource {
private static final long serialVersionUID = 4753258482658331010L;
+ private int ordinal;
+
public Map<String,String> getProperties(){
return System.getenv();
}
- public EnvironmentPropertySource(){
- super("<System.getenv()>");
+ @Override
+ public int getOrdinal(){
+ return ordinal;
+ }
+
+ @Override
+ public String getName(){
+ return "<System.getenv()>";
}
@Override
public String toString(){
- return "EnvironmentPropertyProvider[" + System.getenv().size() + " environment properties]";
+ return "PropertySource(System Environment)";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertySource.java
deleted file mode 100644
index b3aca71..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertySource.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class FileSystemPropertySource extends AbstractClasspathAwarePropertySource {
-
- private static final Logger LOG = Logger.getLogger(FileSystemPropertySource.class.getName());
- private static final long serialVersionUID = -2016119697552480056L;
- private Map<String, Map<String, String>> propMetaInfo = new HashMap<>();
-
- public FileSystemPropertySource(String resourcePath, ClassLoader classLoader,
- AbstractClasspathAwarePropertySource parentConfig) {
- super(classLoader, parentConfig, resourcePath);
- }
-
- public FileSystemPropertySource(String resourcePath, AbstractClasspathAwarePropertySource parentConfig) {
- super(getCurrentClassLoader(), parentConfig, resourcePath);
- }
-
- public FileSystemPropertySource(String resourcePath) {
- super(getCurrentClassLoader(), null, resourcePath);
- }
-
-
- @Override
- protected void readSource(Map<String, String> targetMap, String src) {
- try (InputStream is = getClassLoader().getResource(
- src).openStream()) {
- Properties props = new Properties();
- URL resource = getClassLoader().getResource(
- src);
-// if (isSourceRead(resource.toString())) {
-// // continue;
-// return;
-// }
- addSource(resource.toString());
- Map<String, String> mi = new HashMap<>();
- mi.put("source", resource.toString());
- if (Thread.currentThread().getContextClassLoader() != null) {
- mi.put("classloader", Thread.currentThread()
- .getContextClassLoader().toString());
- }
- props.load(is);
- for (Map.Entry<Object, Object> en : props.entrySet()) {
- targetMap.put(en.getKey().toString(),
- en.getValue().toString());
- propMetaInfo.put(en.getKey().toString(),
- mi);
- }
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error loading config unit.", e);
- }
- }
-
- protected Map<String, String> getMetaInfo(String key, String value) {
- Map<String, String> mi = propMetaInfo.get(key);
- if (mi != null) {
- return mi;
- }
- return Collections.emptyMap();
- }
-
- private static ClassLoader getCurrentClassLoader() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- return FileSystemPropertySource.class.getClassLoader();
- }
- return cl;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
deleted file mode 100644
index a0c1a53..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.PropertySource;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.Predicate;
-
-class FilteredPropertySource extends AbstractPropertySource {
-
- private static final long serialVersionUID = 4301042530074932562L;
- private PropertySource unit;
- private Predicate<String> filter;
-
- public FilteredPropertySource(String name, PropertySource configuration, Predicate<String> filter){
- super(name==null?Objects.requireNonNull(configuration).getName():name);
- this.unit = configuration;
- this.filter = filter;
- }
-
- @Override
- public Map<String,String> getProperties(){
- final Map<String,String> result = new HashMap<>();
- this.unit.getProperties().entrySet().forEach(e -> {
- if(filter.test(e.getKey())){
- result.put(e.getKey(), e.getValue());
- }
- });
- return result;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
deleted file mode 100644
index f0e5eec..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import java.io.Serializable;
-import java.util.*;
-
-import org.apache.tamaya.PropertySource;
-
-/**
- * This class models a freezed instance current an {@link org.apache.tamaya.PropertySource}.
- * Created by Anatole on 28.03.14.
- */
-final class FreezedPropertySource implements PropertySource, Serializable{
-
- private static final long serialVersionUID = 3365413090311267088L;
- private String name;
- private Map<String,String> properties = new HashMap<>();
-
- private FreezedPropertySource(String name, PropertySource propertyMap) {
- Map<String, String> map = propertyMap.getProperties();
- this.properties.putAll(map);
- this.properties = Collections.unmodifiableMap(this.properties);
- this.name = Optional.ofNullable(name).orElse(propertyMap.getName()+"(freezed)");
- }
-
- public static PropertySource of(String name, PropertySource propertyProvider){
- if(propertyProvider instanceof FreezedPropertySource){
- return propertyProvider;
- }
- return new FreezedPropertySource(name, propertyProvider);
- }
-
- public int size(){
- return properties.size();
- }
-
- public boolean isEmpty(){
- return properties.isEmpty();
- }
-
- @Override
- public Map<String,String> getProperties(){
- return Collections.unmodifiableMap(this.properties);
- }
-
- @Override
- public String getName(){
- return this.name;
- }
-
- @Override
- public Optional<String> get(String key){
- return Optional.ofNullable(properties.get(key));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
index 743655e..94da0f5 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
@@ -21,36 +21,41 @@ package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
import java.io.Serializable;
+import java.lang.Override;
+import java.util.Collections;
import java.util.Map;
/**
* Configuration implementation that stores all current values current a given (possibly dynamic, contextual and non remote
* capable instance) and is fully serializable.
*/
-final class FrozenPropertySource extends AbstractPropertySource implements Serializable{
+public final class FrozenPropertySource implements PropertySource, Serializable{
private static final long serialVersionUID = -6373137316556444171L;
- private PropertySource properties;
+ private int ordinal;
+ private String name;
+ private Map<String,String> properties;
/**
* Constructor.
- * @param config The base configuration.
+ * @param propertySource The base configuration.
*/
- private FrozenPropertySource(PropertySource config){
- super(config.getName());
- this.properties = PropertySourceBuilder.of(config).buildFrozen();
+ private FrozenPropertySource(PropertySource propertySource){
+ this.name = propertySource.getName();
+ this.ordinal = propertySource.ordinal();
+ this.properties = Collections.unmodifiableMap(new HashMap<>(propertySource.getProperties()));
}
- public static final PropertySource of(PropertySource config){
- if(config instanceof FrozenPropertySource){
- return config;
+ public static final FrozenPropertySource of(PropertySource propertySource){
+ if(propertySource instanceof FrozenPropertySource){
+ return propertySource;
}
- return new FrozenPropertySource(config);
+ return new FrozenPropertySource(propertySource);
}
@Override
public Map<String,String> getProperties(){
- return properties.getProperties();
+ return properties;
}
@Override
@@ -60,20 +65,22 @@ final class FrozenPropertySource extends AbstractPropertySource implements Seria
FrozenPropertySource that = (FrozenPropertySource) o;
+ if (!name.equals(that.name)) return false;
if (!properties.equals(that.properties)) return false;
+
return true;
}
@Override
public int hashCode() {
- int result = properties.hashCode();
+ int result = name.hashCode();
+ result = 31 * result + properties.hashCode();
return result;
}
@Override
public String toString() {
- return "FreezedConfiguration{" +
- "properties=" + properties +
+ return "FrozenPropertySource{" +
", name=" + name +
'}';
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
deleted file mode 100644
index d7c46d2..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.*;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * Provider implementation that combines multiple other config by intersecting
- * the key/values common to all config, conflicting keys are resolved using an
- * {@link org.apache.tamaya.AggregationPolicy}.
- */
-class IntersectingPropertySource extends AbstractPropertySource {
-
- private static final long serialVersionUID = -1492990130201110889L;
- private List<PropertySource> providers;
- private PropertySource aggregatedDelegate;
-
- public IntersectingPropertySource(String name, AggregationPolicy policy, List<PropertySource> providers) {
- super(name);
- this.providers = new ArrayList<>(providers);
- aggregatedDelegate = PropertySourceBuilder.of(name).withAggregationPolicy(policy)
- .addProviders(this.providers).build();
- }
-
- @Override
- public Optional<String> get(String key) {
- return aggregatedDelegate.get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return aggregatedDelegate.getProperties().entrySet().stream().filter(en -> get(en.getKey()).isPresent()).collect(
- Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
index 41b730e..26a8114 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
@@ -18,6 +18,8 @@
*/
package org.apache.tamaya.core.properties;
+import java.lang.Override;
+import java.lang.String;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
@@ -25,51 +27,73 @@ import java.util.logging.Logger;
/**
* Models a {@link org.apache.tamaya.PropertySource} that can be build using a builder pattern.
*/
-class MapBasedPropertySource extends AbstractPropertySource {
+public class MapBasedPropertySource implements PropertySource {
private static final long serialVersionUID = 7601389831472839249L;
private static final Logger LOG = Logger.getLogger(MapBasedPropertySource.class.getName());
+
+ private int ordinal;
+
+
+ private String name;
/**
* The unit's entries.
*/
- private Map<String,String> entries = new ConcurrentHashMap<>();
+ private Map<String,String> entries = new HashMap<>();
/**
* Constructor.
*
* @param entries the config entries, not null.
*/
- MapBasedPropertySource(String name, Map<String, String> entries){
- super(name);
- Objects.requireNonNull(entries, "entries required.");
- this.entries.putAll(entries);
+ public MapBasedPropertySource(int ordinal, String name, Map<String, String> entries){
+ this.name = Objects.requireNonNull(name);
+ this.ordinal = ordinal;
+ this.entries.putAll(Objects.requireNonNull(entries, "entries required."));
+ this.entries = Collections.unmodifiableMap(this.entries);
}
+ @Override
+ public Map<String, String> getProperties() {
+ return this.entries;
+ }
- /**
- * Constructor.
- *
- * @param entries the entries
- * @param sources the sources
- * @param errors the errors
- */
- MapBasedPropertySource(String name, Map<String, String> entries, Set<String> sources,
- Collection<Throwable> errors){
- super(name);
- Objects.requireNonNull(entries, "entries required.");
- this.entries.putAll(entries);
- addSources(sources);
+ @Override
+ public int getOrdinal(){
+ return ordinal;
}
- MapBasedPropertySource(String name, Set<String> sources){
- super(name);
- addSources(sources);
+ @Override
+ public String getName(){
+ return name;
}
@Override
- public Map<String, String> getProperties() {
- return new HashMap<>(this.entries);
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ MapBasedPropertySource that = (MapBasedPropertySource) o;
+
+ if (!entries.equals(that.entries)) return false;
+ if (!name.equals(that.name)) return false;
+
+ return true;
}
+ @Override
+ public int hashCode() {
+ int result = name.hashCode();
+ result = 31 * result + entries.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "MapBasedPropertySource{" +
+ "name=" + name +
+ ", ordinal=" + ordinal +
+ '}';
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
deleted file mode 100644
index 160d6c4..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.apache.tamaya.core.properties;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.UnaryOperator;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.core.properties.AbstractPropertySource;
-
-/**
- * PropertySource implementation that maps certain parts (defined by an {@code UnaryOperator<String>}) to alternate areas.
- */
-class MappedPropertySource extends AbstractPropertySource {
-
- private static final long serialVersionUID = 8690637705511432083L;
-
- /** The mapping operator. */
- private UnaryOperator<String> keyMapper;
- /** The base configuration. */
- private PropertySource config;
-
- /**
- * Creates a new instance.
- * @param config the base configuration, not null
- * @param keyMapper The mapping operator, not null
- */
- public MappedPropertySource(PropertySource config, UnaryOperator<String> keyMapper) {
- super(config.getName());
- this.config = Objects.requireNonNull(config);
- this.keyMapper = Objects.requireNonNull(keyMapper);
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> result = new HashMap<>();
- Map<String, String> map = this.config.getProperties();
- map.forEach((k,v) -> {
- String targetKey = keyMapper.apply(k);
- if(targetKey!=null){
- result.put(targetKey, v);
- }
- });
- return result;
- }
-
- @Override
- public boolean isEmpty() {
- return this.config.isEmpty();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
deleted file mode 100644
index 80184d1..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.*;
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.resource.ResourceLoader;
-
-import java.util.*;
-
-/**
- * Implementation of a PropertySource that reads configuration from some given resource paths.
- */
-final class PathBasedPropertySource extends AbstractPropertySource {
-
- private static final long serialVersionUID = 5147019699905042582L;
- private List<String> paths = new ArrayList<>();
- private Map<String, String> properties = new HashMap<>();
- private AggregationPolicy aggregationPolicy;
-
- public PathBasedPropertySource(String name, Collection<String> paths, AggregationPolicy aggregationPolicy) {
- super(name);
- this.paths.addAll(Objects.requireNonNull(paths));
- this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
- init();
- }
-
- @Override
- public Map<String, String> getProperties() {
- return this.properties;
- }
-
- private void init() {
- List<String> sources = new ArrayList<>();
- List<String> effectivePaths = new ArrayList<>();
- paths.forEach((path) -> {
- effectivePaths.add(path);
- for (Resource res : ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(path)) {
- ConfigurationFormat format = ConfigurationFormat.from(res);
- if (format != null) {
- try {
- Map<String, String> read = format.readConfiguration(res);
- sources.add(res.toString());
- read.forEach((k, v) -> {
- String valueToAdd = aggregationPolicy.aggregate(k,properties.get(k),v);
- if(valueToAdd==null) {
- properties.remove(k);
- }
- else{
- properties.put(k, valueToAdd);
- }
- });
- }
- catch(ConfigException e){
- throw e;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- });
-// metaInfo = MetaInfoBuilder.of(getMetaInfo())
-// .setSourceExpressions(new String[effectivePaths.size()])
-// .set("sources", sources.toString()).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java
deleted file mode 100644
index 3cf6b31..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.PropertySource;
-
-import java.beans.PropertyChangeEvent;
-import java.io.Serializable;
-import java.util.*;
-
-/**
- * Event that contains a set current changes that were applied or could be applied.
- * This class is immutable and thread-safe. To create instances use
- * {@link PropertyChangeSetBuilder}.
- *
- * Created by Anatole on 22.10.2014.
- */
-public final class PropertyChangeSet implements Serializable{
-
- private static final long serialVersionUID = 1l;
- /** The base property provider/configuration. */
- private PropertySource propertySource;
- /** The base version, usable for optimistic locking. */
- private String baseVersion;
- /** The recorded changes. */
- private Map<String,PropertyChangeEvent> changes = new HashMap<>();
-
- /**
- * Get an empty change set for the given provider.
- * @param propertyProvider The base property provider/configuration, not null.
- * @return an empty ConfigChangeSet instance.
- */
- public static PropertyChangeSet emptyChangeSet(PropertySource propertyProvider){
- return new PropertyChangeSet(propertyProvider, Collections.emptySet());
- }
-
- /**
- * Constructor used by {@link PropertyChangeSetBuilder}.
- * @param propertySource The base property provider/configuration, not null.
- * @param changes The recorded changes, not null.
- */
- PropertyChangeSet(PropertySource propertySource, Collection<PropertyChangeEvent> changes) {
- this.propertySource = Objects.requireNonNull(propertySource);
- changes.forEach((c) -> this.changes.put(c.getPropertyName(), c));
- }
-
- /**
- * Get the underlying property provider/configuration.
- * @return the underlying property provider/configuration, never null.
- */
- public PropertySource getPropertySource(){
- return this.propertySource;
- }
-
- /**
- * Get the base version, usable for optimistic locking.
- * @return the base version.
- */
- public String getBaseVersion(){
- return baseVersion;
- }
-
- /**
- * Get the changes recorded.
- * @return the recorded changes, never null.
- */
- public Collection<PropertyChangeEvent> getEvents(){
- return Collections.unmodifiableCollection(this.changes.values());
- }
-
- /**
- * Access the number current removed entries.
- * @return the number current removed entries.
- */
- public int getRemovedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
- }
-
- /**
- * Access the number current added entries.
- * @return the number current added entries.
- */
- public int getAddedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null).count();
- }
-
- /**
- * Access the number current updated entries.
- * @return the number current updated entries.
- */
- public int getUpdatedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
- }
-
-
- /**
- * Checks if the given key was removed.
- * @param key the target key, not null.
- * @return true, if the given key was removed.
- */
- public boolean isRemoved(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getNewValue() == null;
- }
-
- /**
- * Checks if the given key was added.
- * @param key the target key, not null.
- * @return true, if the given key was added.
- */
- public boolean isAdded(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getOldValue() == null;
- }
-
- /**
- * Checks if the given key was updated.
- * @param key the target key, not null.
- * @return true, if the given key was updated.
- */
- public boolean isUpdated(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getOldValue() != null && change.getNewValue() != null;
- }
-
- /**
- * Checks if the given key is added, or updated AND NOT removed.
- * @param key the target key, not null.
- * @return true, if the given key was added, or updated BUT NOT removed.
- */
- public boolean containsKey(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getNewValue() != null;
- }
-
- /**
- * CHecks if the current change set does not contain any changes.
- * @return tru, if the change set is empty.
- */
- public boolean isEmpty(){
- return this.changes.isEmpty();
- }
-
-
- @Override
- public String toString() {
- return "ConfigChangeSet{" +
- "properties=" + propertySource +
- ", baseVersion=" + baseVersion +
- ", changes=" + changes +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java
deleted file mode 100644
index b6e22f8..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.properties;
-
-import org.apache.tamaya.PropertySource;
-
-import java.beans.PropertyChangeEvent;
-import java.util.*;
-import java.util.function.Function;
-
-/**
- * Models a set current changes to be applied to a configuration/property provider. Such a set can be applied
- * to any {@link org.apache.tamaya.PropertySource} instance. If the provider is mutable it may check the
- * version given and applyChanges the changes to the provider/configuration, including triggering current regarding
- * change events.
- * <p>
- * For appropriate conversion a {@code Function<String, Codec>} can be applied, which performs correct conversion,
- * when changed values are set. This function enables connecting e.g. setters on a configuration template with
- * the corresponding conversion logic, so the template calls are correctly converted back.
- */
-public final class PropertyChangeSetBuilder {
- /**
- * The recorded changes.
- */
- final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>();
- /**
- * The underlying configuration/provider.
- */
- PropertySource source;
-
- /**
- * Constructor.
- *
- * @param source the underlying configuration/provider, not null.
- */
- private PropertyChangeSetBuilder(PropertySource source) {
- this.source = Objects.requireNonNull(source);
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @param source the underlying property provider/configuration, not null.
- * @return the builder for chaining.
- */
- public static PropertyChangeSetBuilder of(PropertySource source) {
- return new PropertyChangeSetBuilder(source);
- }
-
- /**
- * This method records all changes to be applied to the base property provider/configuration to
- * achieve the given target state.
- *
- * @param newState the new target state, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder addChanges(PropertySource newState) {
- compare(newState, this.source).forEach((c) -> this.delta.put(c.getPropertyName(), c));
- return this;
- }
-
- /**
- * Get the current values, also considering any changes recorded within this change set.
- *
- * @param key the key current the entry, not null.
- * @return the keys, or null.
- */
- public String get(String key) {
- PropertyChangeEvent change = this.delta.get(key);
- if (change != null && !(change.getNewValue() == null)) {
- return (String) change.getNewValue();
- }
- return null;
- }
-
- /**
- * Marks the given key(s) fromMap the configuration/properties to be removed.
- *
- * @param key the key current the entry, not null.
- * @param otherKeys additional keys to be removed (convenience), not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder remove(String key, String... otherKeys) {
- String oldValue = this.source.get(key).orElse(null);
- if (oldValue == null) {
- this.delta.remove(key);
- }
- this.delta.put(key, new PropertyChangeEvent(this.source, key, oldValue, null));
- for (String addKey : otherKeys) {
- oldValue = this.source.get(addKey).orElse(null);
- if (oldValue == null) {
- this.delta.remove(addKey);
- }
- this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue, null));
- }
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, boolean value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
- /**
- s* Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, byte value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, char value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, short value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, int value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, long value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, float value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, double value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder put(String key, String value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @return the builder for chaining.
- * @throws org.apache.tamaya.ConfigException if no matching Codec could be found.
- */
- public <T> PropertyChangeSetBuilder put(String key, Class<T> type, T value) {
- put(key, type, value, null);
- return this;
- }
-
- /**
- * Applies the given keys.
- *
- * @param key the key current the entry, not null.
- * @param value the keys to be applied, not null.
- * @param adapter the codec to be used, if set overrides any other codecs that may apply. If null an appropriate
- * codec is tried to be evaluated as needed.
- * @return the builder for chaining.
- * @throws org.apache.tamaya.ConfigException if no matching Codec could be found.
- */
- public <T> PropertyChangeSetBuilder put(String key, Class<T> type, T value, Function<T,String> adapter) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), adapter.apply(Objects.requireNonNull(value))));
- return this;
- }
-
-
- /**
- * Apply all the given values to the base configuration/properties.
- * Note that all values passed must be convertible to String, either
- * <ul>
- * <li>the registered codecs provider provides codecs for the corresponding keys, or </li>
- * <li>default codecs are present for the given type, or</li>
- * <li>the value is an instanceof String</li>
- * </ul>
- *
- * @param changes the changes to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder putAll(Map<String, String> changes) {
- changes.putAll(changes);
- return this;
- }
-
- /**
- * This method will create a change set that clears all entries fromMap the given base configuration/properties.
- *
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder deleteAll() {
- this.delta.clear();
- this.source.getProperties().forEach((k, v) ->
- this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
- return this;
- }
-
- /**
- * Checks if the change set is empty, i.e. does not contain any changes.
- *
- * @return true, if the set is empty.
- */
- public boolean isEmpty() {
- return this.delta.isEmpty();
- }
-
- /**
- * Resets this change set instance. This will clear all changes done to this builder, so the
- * set will be empty.
- */
- public void reset() {
- this.delta.clear();
- }
-
- /**
- * Builds the corresponding change set.
- *
- * @return the new change set, never null.
- */
- public PropertyChangeSet build() {
- return new PropertyChangeSet(this.source, Collections.unmodifiableCollection(this.delta.values()));
- }
-
- /**
- * Compares the two property config/configurations and creates a collection current all changes
- * that must be appied to render {@code map1} into {@code map2}.
- *
- * @param map1 the source map, not null.
- * @param map2 the target map, not null.
- * @return a collection current change events, never null.
- */
- public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
- List<PropertyChangeEvent> changes = new ArrayList<>();
- for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
- Optional<String> val = map2.get(en.getKey());
- if (!val.isPresent()) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
- } else if (!val.get().equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
- }
- }
- for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
- Optional<String> val = map1.get(en.getKey());
- if (!val.isPresent()) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
- } else if (!val.equals(Optional.ofNullable(en.getValue()))) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
- }
- }
- return changes;
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "PropertyChangeEventBuilder [source=" + source + ", " +
- ", delta=" + delta + "]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java b/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
deleted file mode 100644
index b099230..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.tamaya.core.properties;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.BiFunction;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
-
-import org.apache.tamaya.PropertySource;
-
-/**
-* Builder for assembling non trivial property providers.
-*/
-public final class PropertySourceBuilder {
-
- /**
- * Name used for the final result.
- */
- private String name;
-
- /**
- * Name used for the next operation.
- */
- private String currentName;
-
- /**
- * the current property provider, or null.
- */
- private PropertySource current;
- /**
- * The current aggregation policy used, when aggregating providers.
- */
- private AggregationPolicy aggregationPolicy = AggregationPolicy.OVERRIDE;
-
- /**
- * Private singleton constructor.
- */
- private PropertySourceBuilder(String name) {
- this.name = Objects.requireNonNull(name);
- }
-
- /**
- * Private singleton constructor.
- */
- private PropertySourceBuilder(String name, PropertySource propertySource) {
- this.name = Objects.requireNonNull(name);
- this.current = propertySource;
- }
-
- /**
- * Creates a new builder instance.
- *
- * @param name the provider name, not null.
- * @param provider the base provider to be used, not null.
- * @return a new builder instance, never null.
- */
- public static PropertySourceBuilder of(String name, PropertySource provider) {
- return new PropertySourceBuilder(name, provider);
- }
-
- /**
- * Creates a new builder instance.
- *
- * @param provider the base provider to be used, not null.
- * @return a new builder instance, never null.
- */
- public static PropertySourceBuilder of(PropertySource provider) {
- return new PropertySourceBuilder(provider.getName(), provider);
- }
-
-
- /**
- * Creates a new builder instance.
- *
- * @param name the provider name, not null.
- * @return a new builder instance, never null.
- */
- public static PropertySourceBuilder of(String name) {
- return new PropertySourceBuilder(Objects.requireNonNull(name));
- }
-
- /**
- * Creates a new builder instance.
- *
- * @return a new builder instance, never null.
- */
- public static PropertySourceBuilder of() {
- return new PropertySourceBuilder("<noname>");
- }
-
-
-
-
- /**
- * Sets the aggregation policy to be used, when adding additional property sets. The policy will
- * be active a slong as the builder is used or it is reset to another keys.
- *
- * @param aggregationPolicy the aggregation policy, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder withAggregationPolicy(AggregationPolicy aggregationPolicy) {
- this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
- return this;
- }
-
- /**
- * Adds the given providers with the current active {@link AggregationPolicy}. By
- * default {@link AggregationPolicy#OVERRIDE} is used.
- * @see #withAggregationPolicy(AggregationPolicy)
- * @param providers providers to be added, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addProviders(PropertySource... providers) {
- if(providers.length==0){
- return this;
- }
- return addProviders(Arrays.asList(providers));
- }
-
- /**
- * Adds the given providers with the current active {@link AggregationPolicy}. By
- * default {@link AggregationPolicy#OVERRIDE} is used.
- * @see #withAggregationPolicy(AggregationPolicy)
- * @param providers providers to be added, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addProviders(List<PropertySource> providers) {
- if(providers.isEmpty()){
- return this;
- }
- List<PropertySource> allProviders = new ArrayList<>(providers);
- if (this.current != null) {
- allProviders.add(0, this.current);
- }
- StringBuilder b = new StringBuilder();
- providers.forEach(p -> b.append(p.getName()).append(','));
- b.setLength(b.length()-1);
- String source = b.toString();
- String name = this.currentName;
- if (currentName == null) {
- name = "<aggregate> -> source=" + source;
- }
- this.current = PropertySourceFactory.aggregate(name, this.aggregationPolicy, allProviders);
- this.currentName = null;
- return this;
- }
-
- /**
- * Creates a new {@link PropertySource} using the given command line arguments and adds it
- * using the current aggregation policy in place.
- *
- * @param args the command line arguments, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addArgs(String... args) {
- if(args.length==0){
- return this;
- }
- String name = this.currentName;
- if (currentName == null) {
- name = "<CLI-args>";
- }
- PropertySource argProvider = PropertySourceFactory.fromArgs(name, args);
- return addProviders(argProvider);
- }
-
- /**
- * Creates a new read-only {@link PropertySource} by reading the according path resources. The effective resources read
- * hereby are determined by the {@code PathResolverService} configured into the {@code Bootstrap} SPI.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param paths the paths to be resolved by the {@code PathResolverService} , not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addPaths(String... paths) {
- if(paths.length==0){
- return this;
- }
- return addPaths(Arrays.asList(paths));
- }
-
-
- /**
- * Creates a new read-only {@link PropertySource} by reading the according path resources. The effective resources read
- * hereby are determined by the {@code PathResolverService} configured into the {@code Bootstrap} SPI.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param paths the paths to be resolved by the {@code PathResolverService} , not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addPaths(List<String> paths) {
- if(paths.isEmpty()){
- return this;
- }
- String name = this.currentName;
- if (currentName == null) {
- name = "<aggregate> -> paths=" + paths.toString();
- }
- return addProviders(PropertySourceFactory.fromPaths(name, aggregationPolicy, paths));
- }
-
- /**
- * Creates a new read-only {@link PropertySource} by reading the according URL resources.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param urls the urls to be read, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addURLs(URL... urls) {
- if(urls.length==0){
- return this;
- }
- return addURLs(Arrays.asList(urls));
- }
-
- /**
- * Creates a new read-only {@link PropertySource} by reading the according URL resources.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param urls the urls to be read, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addURLs(List<URL> urls) {
- if(urls.isEmpty()){
- return this;
- }
- String name = this.currentName;
- if (currentName == null) {
- name = "<aggregate> -> urls=" + urls;
- }
- return addProviders(PropertySourceFactory.fromURLs(name, this.aggregationPolicy, urls));
- }
-
-
- /**
- * Creates a new read-only {@link PropertySource} based on the given map.
- * Properties read are aggregated using the current aggregation policy active.
- *
- * @param map the map to be added, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addMap(Map<String, String> map) {
- if(map.isEmpty()){
- return this;
- }
- String name = this.currentName;
- if (currentName == null) {
- name = "<Map> -> map=" + map;
- }
- return addProviders(PropertySourceFactory.fromMap(name, map));
- }
-
-
- /**
- * Add the current environment properties. Aggregation is based on the current {@link AggregationPolicy} acvtive.
- *
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addEnvironmentProperties() {
- String name = this.currentName;
- if (currentName == null) {
- name = "<System.getenv()>";
- }
- return addProviders(PropertySourceFactory.fromEnvironmentProperties());
- }
-
- /**
- * Add the current system properties. Aggregation is based on the current {@link AggregationPolicy} acvtive.
- *
- * @return the builder for chaining.
- */
- public PropertySourceBuilder addSystemProperties() {
- String name = this.currentName;
- if (currentName == null) {
- name = "<System.getProperties()>";
- }
- return addProviders(PropertySourceFactory.fromSystemProperties());
- }
-
- /**
- * Add the name used for the next aggregation/adding operation on this builder.
- * @param name the name to be used, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder withName(String name) {
- this. currentName = Objects.requireNonNull(name);
- return this;
- }
-
- /**
- * Adds the given {@link org.apache.tamaya.PropertySource} instances using the current {@link AggregationPolicy}
- * active.
- *
- * @param providers the maps to be included, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder aggregate(PropertySource... providers) {
- if(providers.length==0){
- return this;
- }
- String name = this.currentName;
- if (currentName == null) {
- name = "<aggregate> -> " + Arrays.toString(providers);
- }
- return addProviders(PropertySourceFactory.aggregate(name, aggregationPolicy, Arrays.asList(providers)));
- }
-
-
- /**
- * Adds the given {@link org.apache.tamaya.PropertySource} instances using the current {@link AggregationPolicy}
- * active.
- *
- * @param providers the maps to be included, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder aggregate(List<PropertySource> providers) {
- if(providers.isEmpty()){
- return this;
- }
- String name = this.currentName;
- if (currentName == null) {
- name = "<aggregate> -> " + providers;
- }
- return addProviders(PropertySourceFactory.aggregate(name, aggregationPolicy, providers));
- }
-
-
- /**
- * Filters the current {@link org.apache.tamaya.PropertySource} with the given valueFilter.
- * @param valueFilter the value filter, not null.
- * @return the (dynamically) filtered source instance, never null.
- */
- public PropertySourceBuilder filterValues(BiFunction<String, String, String> valueFilter){
- String name = this.currentName;
- if (currentName == null) {
- name = "<filteredValues> -> " + valueFilter;
- }
- this.current = PropertySourceFactory.filterValues(name, valueFilter, this.current);
- return this;
- }
-
-
- /**
- * Intersetcs the current properties with the given {@link org.apache.tamaya.PropertySource} instance.
- *
- * @param providers the maps to be intersected, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder intersect(PropertySource... providers) {
- if(providers.length==0){
- return this;
- }
- String name = this.currentName;
- if (currentName == null) {
- name = "<intersection> -> " + Arrays.toString(providers);
- }
- return addProviders(PropertySourceFactory.intersected(name, aggregationPolicy, Arrays.asList(providers)));
- }
-
-
- /**
- * Subtracts with the given {@link org.apache.tamaya.PropertySource} instance from the current properties.
- *
- * @param providers the maps to be subtracted, not null.
- * @return the builder for chaining.
- */
- public PropertySourceBuilder subtract(PropertySource... providers) {
- if(providers.length==0){
- return this;
- }
- String name = this.currentName;
- if (currentName == null) {
- name = "<subtraction> -> " + Arrays.toString(providers);
- }
- current = PropertySourceFactory.subtracted(name, current, Arrays.asList(providers));
- return this;
- }
-
-
- /**
- * Filters the current properties based on the given predicate..
- *
- * @param filter the filter to be applied, not null.
- * @return the new filtering instance.
- */
- public PropertySourceBuilder filter(Predicate<String> filter) {
- String name = this.currentName;
- if (currentName == null) {
- name = "<filtered> -> " + filter;
- }
- current = PropertySourceFactory.filtered(name, filter, current);
- this.currentName = null;
- return this;
- }
-
- /**
- * Creates a new contextual {@link org.apache.tamaya.PropertySource}. Contextual maps delegate to different instances current PropertyMap depending
- * on the keys returned fromMap the isolationP
- *
- * @param mapSupplier the supplier creating new provider instances
- * @param isolationKeySupplier the supplier providing contextual keys based on the current environment.
- */
- public PropertySourceBuilder addContextual(Supplier<PropertySource> mapSupplier,
- Supplier<String> isolationKeySupplier) {
- String name = this.currentName;
- if (currentName == null) {
- name = "<contextual> -> map="+mapSupplier+",isolationKeySupplier="+isolationKeySupplier;
- }
- return addProviders(PropertySourceFactory.contextual(name, mapSupplier, isolationKeySupplier));
- }
-
- /**
- * Replaces all keys in the current provider by the given map.
- *
- * @param replacementMap the map instance, that will replace all corresponding entries in {@code mainMap}, not null.
- * @return the new delegating instance.
- */
- public PropertySourceBuilder replace(Map<String, String> replacementMap) {
- String name = this.currentName;
- if (currentName == null) {
- name = "<replacement> -> current="+current.getName()+" with ="+replacementMap;
- }
- current = PropertySourceFactory.replacing(name, current, replacementMap);
- this.currentName = null;
- return this;
- }
-
- /**
- * Build a new property provider based on the input.
- * @return a new property provider, or null.
- */
- public PropertySource build(){
- if (current != null) {
- return PropertySourceFactory.build(name, current);
- }
- return PropertySourceFactory.empty(name);
- }
-
- /**
- * Creates a {@link PropertySource} instance that is serializable and immutable,
- * so it can be sent over a network connection.
- *
- * @return the freezed instance, never null.
- */
- public PropertySource buildFrozen() {
- String name = this.currentName;
- if (currentName == null) {
- name = "<freezed> -> source="+current.getName();
- }
- PropertySource prov = PropertySourceFactory.freezed(name, current);
- this.currentName = null;
- return prov;
- }
-
-}
[03/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
new file mode 100644
index 0000000..d80ee80
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
@@ -0,0 +1,221 @@
+package org.apache.tamaya.core.internal.inject;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertyAdapter;
+import org.apache.tamaya.annotation.*;
+import org.apache.tamaya.annotation.WithPropertyAdapter;
+import org.apache.tamaya.core.internal.Utils;
+import org.apache.tamaya.spi.PropertyAdapterSpi;
+
+/**
+ * Created by Anatole on 19.12.2014.
+ */
+@SuppressWarnings("unchecked")
+final class InjectionUtils {
+
+ private InjectionUtils(){}
+
+ /**
+ * This method evaluates the {@link org.apache.tamaya.Configuration} that currently is valid for the given target field/method.
+ *
+ * @return the {@link org.apache.tamaya.Configuration} instance to be used, never null.
+ */
+ public static Configuration getConfiguration(ConfiguredProperty prop, Configuration... configuration) {
+ String name = prop.config();
+ if (name != null && !name.trim().isEmpty()) {
+ return Configuration.current(name.trim());
+ }
+ return Configuration.current();
+ }
+
+ /**
+ * Evaluates all absolute configuration key based on the annotations found on a class.
+ *
+ * @param areasAnnot the (optional) annotation definining areas to be looked up.
+ * @param propertyAnnotation the annotation on field/method level that may defined one or
+ * several keys to be looked up (in absolute or relative form).
+ * @return the list current keys in order how they should be processed/looked up.
+ */
+ public static List<String> evaluateKeys(Member member, DefaultAreas areasAnnot, ConfiguredProperty propertyAnnotation) {
+ List<String> keys = new ArrayList<>(Arrays.asList(propertyAnnotation.keys()));
+ if (keys.isEmpty()) //noinspection UnusedAssignment
+ keys.add(member.getName());
+ ListIterator<String> iterator = keys.listIterator();
+ while (iterator.hasNext()) {
+ String next = iterator.next();
+ if (next.startsWith("[") && next.endsWith("]")) {
+ // absolute key, strip away brackets, take key as is
+ iterator.set(next.substring(1, next.length() - 1));
+ } else {
+ if (areasAnnot != null) {
+ // Remove original entry, since it will be replaced with prefixed entries
+ iterator.remove();
+ // Add prefixed entries, including absolute (root) entry for "" area keys.
+ for (String area : areasAnnot.value()) {
+ iterator.add(area.isEmpty() ? next : area + '.' + next);
+ }
+ }
+ }
+ }
+ return keys;
+ }
+
+ /**
+ * Evaluates all absolute configuration key based on the member name found.
+ *
+ * @param areasAnnot the (optional) annotation definining areas to be looked up.
+ * @return the list current keys in order how they should be processed/looked up.
+ */
+ public static List<String> evaluateKeys(Member member, DefaultAreas areasAnnot) {
+ List<String> keys = new ArrayList<>();
+ String name = member.getName();
+ String mainKey;
+ if(name.startsWith("get") || name.startsWith("set")){
+ mainKey = Character.toLowerCase(name.charAt(3)) + name.substring(4);
+ }
+ else{
+ mainKey = Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ }
+ keys.add(mainKey);
+ if (areasAnnot != null) {
+ // Add prefixed entries, including absolute (root) entry for "" area keys.
+ for (String area : areasAnnot.value()) {
+ if(!area.isEmpty()) {
+ keys.add(area + '.' + mainKey);
+ }
+ }
+ }
+ else{ // add package name
+ keys.add(member.getDeclaringClass().getName()+'.'+mainKey);
+ }
+ return keys;
+ }
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ public static String getConfigValue(Method method, Configuration... configurations) {
+ DefaultAreas areasAnnot = method.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ WithLoadPolicy loadPolicy = Utils.getAnnotation(WithLoadPolicy.class, method, method.getDeclaringClass());
+ return getConfigValueInternal(method, areasAnnot, loadPolicy, configurations);
+ }
+
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ public static String getConfigValue(Field field, Configuration... configurations) {
+ DefaultAreas areasAnnot = field.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ WithLoadPolicy loadPolicy = Utils.getAnnotation(WithLoadPolicy.class, field, field.getDeclaringClass());
+ return getConfigValueInternal(field, areasAnnot, loadPolicy, configurations);
+ }
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ private static String getConfigValueInternal(AnnotatedElement element, DefaultAreas areasAnnot, WithLoadPolicy loadPolicy, Configuration... configurations) {
+ Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(
+ element, ConfiguredProperty.class, ConfiguredProperties.class);
+ DefaultValue defaultAnnot = element.getAnnotation(DefaultValue.class);
+ String configValue = null;
+ if(configuredProperties.isEmpty()){
+ List<String> keys = InjectionUtils.evaluateKeys((Member)element, areasAnnot);
+ Configuration config = InjectionUtils.getConfiguration("default", configurations);
+ configValue = evaluteConfigValue(configValue, keys, config);
+ }
+ else {
+ for (ConfiguredProperty prop : configuredProperties) {
+ List<String> keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot, prop);
+ Configuration config = InjectionUtils.getConfiguration(prop, configurations);
+ configValue = evaluteConfigValue(configValue, keys, config);
+ }
+ }
+ if (configValue == null && defaultAnnot != null) {
+ return defaultAnnot.value();
+ }
+ return configValue;
+ }
+
+ private static String evaluteConfigValue(String configValue, List<String> keys, Configuration config) {
+ for (String key : keys) {
+ configValue = config.get(key).orElse(null);
+ if (configValue != null) {
+ break;
+ }
+ }
+ if (configValue != null) {
+ // net step perform expression resolution, if any
+ configValue = Configuration.evaluateValue(configValue, config);
+ }
+ return configValue;
+ }
+
+
+ @SuppressWarnings("rawtypes")
+ public static <T> T adaptValue(AnnotatedElement element, Class<T> targetType, String configValue){
+ try {
+ // Check for adapter/filter
+// T adaptedValue = null;
+ WithPropertyAdapter codecAnnot = element.getAnnotation(WithPropertyAdapter.class);
+ Class<? extends PropertyAdapter> codecType;
+ if (codecAnnot != null) {
+ codecType = codecAnnot.value();
+ if (!codecType.equals(PropertyAdapter.class)) {
+ // TODO cache here...
+// Codec<String> codec = codecType.newInstance();
+// adaptedValue = (T) codec.adapt(configValue);
+ }
+ }
+ if (String.class.equals(targetType)) {
+ return (T)configValue;
+ } else {
+ PropertyAdapter<?> adapter = PropertyAdapter.getInstance(targetType);
+ return (T)adapter.adapt(configValue);
+ }
+ } catch (Exception e) {
+ throw new ConfigException("Failed to annotate configured member: " + element, e);
+ }
+ }
+
+ /**
+ * This method evaluates the {@link Configuration} that currently is valid for the given target field/method.
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ * @return the {@link Configuration} instance to be used, never null.
+ */
+ public static Configuration getConfiguration(String name, Configuration... configurations) {
+ if(name!=null) {
+ for(Configuration conf: configurations){
+ if(name.equals(conf.getName())){
+ return conf;
+ }
+ }
+ return Configuration.current(name);
+ }
+ else{
+ for(Configuration conf: configurations){
+ if("default".equals(conf.getName())){
+ return conf;
+ }
+ }
+ }
+ return Configuration.current();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
new file mode 100644
index 0000000..e9b9ec3
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import org.apache.tamaya.core.properties.PropertyChangeSet;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.StampedLock;
+import java.util.function.Consumer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Simple listener container that only holds weak references on the listeners.
+ */
+public final class WeakConfigListenerManager{
+
+ private static final WeakConfigListenerManager INSTANCE = new WeakConfigListenerManager();
+
+ private static final Logger LOG = Logger.getLogger(WeakConfigListenerManager.class.getName());
+ private StampedLock lock = new StampedLock();
+ private Map<Object,Consumer<PropertyChangeSet>> listenerReferences = new WeakHashMap<>();
+
+ /** Private singleton constructor. */
+ private WeakConfigListenerManager(){}
+
+ public static WeakConfigListenerManager of(){
+ return INSTANCE;
+ }
+
+ /**
+ * Registers the given consumer for the instance. If a consumer already exists for this instance the given
+ * consumer is appended.
+ * @param instance the instance, not null.
+ * @param listener the consumer.
+ */
+ public void registerConsumer(Object instance, Consumer<PropertyChangeSet> listener){
+ Lock writeLock = lock.asWriteLock();
+ try {
+ writeLock.lock();
+ Consumer<PropertyChangeSet> l = listenerReferences.get(instance);
+ if (l == null) {
+ listenerReferences.put(instance, listener);
+ } else {
+ listenerReferences.put(instance, l.andThen(listener));
+ }
+ }
+ finally{
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Unregisters all consumers for the given instance.
+ * @param instance the instance, not null.
+ */
+ public void unregisterConsumer(Object instance) {
+ Lock writeLock = lock.asWriteLock();
+ try {
+ writeLock.lock();
+ listenerReferences.remove(instance);
+ }
+ finally{
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Publishes a change event to all consumers registered.
+ * @param change the change event, not null.
+ */
+ public void publishChangeEvent(PropertyChangeSet change){
+ Lock readLock = lock.asReadLock();
+ try{
+ readLock.lock();
+ listenerReferences.values().parallelStream().forEach(l -> {
+ try{
+ l.accept(change);
+ }
+ catch(Exception e){
+ LOG.log(Level.SEVERE, "ConfigChangeListener failed: " + l.getClass().getName(), e);
+ }
+ });
+ }
+ finally{
+ readLock.unlock();
+ }
+ }
+
+
+ @Override
+ public String toString(){
+ return "WeakConfigListenerManager{" +
+ "listenerReferences=" + listenerReferences +
+ '}';
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/spi/ConfigurationFactorySpi.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/spi/ConfigurationFactorySpi.java b/modules/injection/src/main/java/org/apache/tamaya/inject/spi/ConfigurationFactorySpi.java
new file mode 100644
index 0000000..3b167cc
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/spi/ConfigurationFactorySpi.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertySource;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Factory to create configurations from property sources. If not defines a default is used.
+ */
+public interface ConfigurationFactorySpi {
+ /**
+ * Creates a configuration from a {@link org.apache.tamaya.PropertySource}.
+ *
+ * @param propertySource the property source
+ * @return the corresponding Configuration instance, never null.
+ */
+ default Configuration from(PropertySource propertySource){
+ return new Configuration() {
+ @Override
+ public String getName() {
+ return propertySource.getName();
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return propertySource.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return propertySource.getProperties();
+ }
+
+ @Override
+ public String toString(){
+ return "Configuration, based on " + propertySource;
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/spi/ConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/spi/ConfigurationSpi.java b/modules/injection/src/main/java/org/apache/tamaya/inject/spi/ConfigurationSpi.java
new file mode 100644
index 0000000..5891dc2
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/spi/ConfigurationSpi.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertyAdapter;
+import org.apache.tamaya.PropertySource;
+import org.apache.tamaya.annotation.WithPropertyAdapter;
+
+import java.util.Map;
+import java.util.Optional;
+
+
+/**
+ * Manager for {@link org.apache.tamaya.Configuration} instances. Implementations must register an instance
+ * using the {@link ServiceContextManager} mechanism in place (by default this is based on the {@link java.util.ServiceLoader}.
+ * The {@link org.apache.tamaya.Configuration} Singleton in the API delegates its corresponding calls to the
+ * instance returned by the current bootstrap service in place.
+ *
+ * @see org.apache.tamaya.Configuration
+ * @see ServiceContextManager
+ */
+public interface ConfigurationSpi {
+
+ /**
+ * Allows to check if a configuration with a given name is defined.
+ * @param name the configuration's name, not null, not empty.
+ * @return true, if such a configuration is defined.
+ */
+ boolean isConfigurationAvailable(String name);
+
+ /**
+ * Access a configuration by name.
+ * @param name the configuration's name, not null, not empty.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ Configuration getConfiguration(String name);
+
+ /**
+ * Access the default configuration.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ default Configuration getConfiguration(){
+ return getConfiguration("default");
+ }
+
+ /**
+ * Configures an instance, by resolving and injecting the configuration
+ * entries.
+ *
+ * @param instance the instance with configuration annotations, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @throws org.apache.tamaya.ConfigException if any required configuration could not be resolved/injected.
+ */
+ void configure(Object instance, Configuration... configurations);
+
+ /**
+ * Access a configuration by name.
+ *
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ <T> T createTemplate(Class<T> template, Configuration... configurations);
+
+ /**
+ * Evaluate the current expression based on the current configuration valid.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @param expression the expression, not null.
+ * @return the evaluated config expression.
+ */
+ String evaluateValue(String expression, Configuration... configurations);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/main/java/org/apache/tamaya/inject/spi/PropertyAdapterSpi.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/spi/PropertyAdapterSpi.java b/modules/injection/src/main/java/org/apache/tamaya/inject/spi/PropertyAdapterSpi.java
new file mode 100644
index 0000000..a1222a4
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/spi/PropertyAdapterSpi.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertyAdapter;
+import org.apache.tamaya.annotation.WithPropertyAdapter;
+
+
+/**
+ * Manager for {@link org.apache.tamaya.Configuration} instances. Implementations must register an instance
+ * using the {@link org.apache.tamaya.spi.ServiceContextManager} mechanism in place (by default this is based on the {@link java.util.ServiceLoader}.
+ * The {@link org.apache.tamaya.Configuration} Singleton in the API delegates its corresponding calls to the
+ * instance returned by the current bootstrap service in place.
+ *
+ * @see org.apache.tamaya.Configuration
+ * @see org.apache.tamaya.spi.ServiceContextManager
+ */
+public interface PropertyAdapterSpi {
+
+
+ /**
+ * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
+ * this type.
+ * @param targetType The target class, not null.
+ * @param adapter The adapter, not null.
+ * @param <T> The target type
+ * @return any adapter replaced with the new adapter, or null.
+ */
+ <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter);
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ default <T> PropertyAdapter<T> getAdapter(Class<T> targetType){
+ return getPropertyAdapter(targetType, null);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @param <T> the target type
+ * @return the corresponding adapter, never null.
+ * @throws org.apache.tamaya.ConfigException if the target type is not supported.
+ */
+ <T> PropertyAdapter<T> getPropertyAdapter(Class<T> targetType, WithPropertyAdapter annotation);
+
+ /**
+ * Checks if the given target type is supported, i.e. a adapter is registered and accessible.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ boolean isTargetTypeSupported(Class<?> targetType);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/test/java/annottext/AnnotatedConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedConfig.java b/modules/injection/src/test/java/annottext/AnnotatedConfig.java
new file mode 100644
index 0000000..b9160e3
--- /dev/null
+++ b/modules/injection/src/test/java/annottext/AnnotatedConfig.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package annottext;
+
+import org.apache.tamaya.annotation.ConfiguredProperty;
+import org.apache.tamaya.annotation.WithLoadPolicy;
+import org.apache.tamaya.annotation.DefaultValue;
+import org.apache.tamaya.annotation.LoadPolicy;
+
+/**
+ * An example showing some basic annotations, using an interface to be proxied by the
+ * configuration system.
+ * Created by Anatole on 15.02.14.
+ */
+@WithLoadPolicy(LoadPolicy.INITIAL)
+public interface AnnotatedConfig {
+
+ @ConfiguredProperty(keys = "foo.bar.myprop")
+ @ConfiguredProperty(keys = "mp")
+ @ConfiguredProperty(keys = "common.testdata.myProperty")
+ @DefaultValue("myValue_$[env.stage]")
+ // @ConfigLoadPolicy(listener = MyListener.class)
+ String myParameter();
+
+ @ConfiguredProperty(keys = "simple_value")
+ @WithLoadPolicy(LoadPolicy.LAZY)
+ String simpleValue();
+
+ @ConfiguredProperty
+ String simplestValue();
+
+ @ConfiguredProperty(keys = "env.host.name")
+ String hostName();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/test/java/annottext/AnnotatedFullConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedFullConfig.java b/modules/injection/src/test/java/annottext/AnnotatedFullConfig.java
new file mode 100644
index 0000000..c59fb82
--- /dev/null
+++ b/modules/injection/src/test/java/annottext/AnnotatedFullConfig.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package annottext;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.annotation.ConfiguredProperty;
+import org.apache.tamaya.annotation.WithLoadPolicy;
+import org.apache.tamaya.annotation.DefaultValue;
+import org.apache.tamaya.annotation.LoadPolicy;
+
+/**
+ * An example showing some basic annotations, using an interface to be proxied by the
+ * configuration system, nevertheless extending the overall Configuration interface.
+ * Created by Anatole on 15.02.14.
+ */
+@WithLoadPolicy(LoadPolicy.INITIAL)
+public interface AnnotatedFullConfig extends Configuration{
+
+ @ConfiguredProperty(keys = "foo.bar.myprop")
+ @ConfiguredProperty(keys = "mp")
+ @ConfiguredProperty(keys = "common.testdata.myProperty")
+ @DefaultValue("myValue_$[env.stage]")
+ // @ConfigLoadPolicy(listener = MyListener.class)
+ String myParameter();
+
+ @ConfiguredProperty(keys = "simple_value")
+ @WithLoadPolicy(LoadPolicy.LAZY)
+ String simpleValue();
+
+ @ConfiguredProperty
+ String simplestValue();
+
+ @ConfiguredProperty(keys = "env.host.name")
+ String hostName();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java b/modules/injection/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
new file mode 100644
index 0000000..3245877
--- /dev/null
+++ b/modules/injection/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Consumer;
+
+import org.apache.tamaya.spi.ConfigurationSpi;
+
+/**
+ * Created by Anatole on 09.09.2014.
+ */
+public class TestConfigServiceSingletonSpi implements ConfigurationSpi {
+
+
+ private Map<String, Configuration> configs = new ConcurrentHashMap<>();
+
+ public TestConfigServiceSingletonSpi(){
+ Map<String,String> config = new HashMap<>();
+ config.put("a.b.c.key1", "keys current a.b.c.key1");
+ config.put("a.b.c.key2", "keys current a.b.c.key2");
+ config.put("a.b.key3", "keys current a.b.key3");
+ config.put("a.b.key4", "keys current a.b.key4");
+ config.put("a.key5", "keys current a.key5");
+ config.put("a.key6", "keys current a.key6");
+ config.put("int1", "123456");
+ config.put("int2", "111222");
+ config.put("booleanT", "true");
+ config.put("double1", "1234.5678");
+ config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
+ config.put("testProperty", "keys current testProperty");
+ config.put("runtimeVersion", "${java.version}");
+ // configs.put("testdata", new MapConfiguration(MetaInfoBuilder.current().setName("testdata").build(), config));
+ }
+
+
+
+ @Override
+ public boolean isConfigurationAvailable(String name){
+ return configs.containsKey(name);
+ }
+
+ @Override
+ public Configuration getConfiguration(String name) {
+ // TODO
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public <T> T createTemplate(Class<T> type, Configuration... configurations) {
+ // TODO
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void configure(Object instance, Configuration... configurations) {
+ // TODO
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public String evaluateValue(String expression, Configuration... configurations) {
+ // TODO improve this ugly implementation...
+ for (Configuration config : configurations) {
+ for (Map.Entry<String, String> en : config.getProperties().entrySet()) {
+ expression = expression.replaceAll("\\$\\{" + en.getKey() + "\\}", en.getValue());
+ }
+ }
+ return expression;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java b/modules/injection/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
new file mode 100644
index 0000000..65e6c1d
--- /dev/null
+++ b/modules/injection/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.util.Currency;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tamaya.annotation.WithPropertyAdapter;
+import org.apache.tamaya.spi.PropertyAdapterSpi;
+
+/**
+ * Test implementation current {@link org.apache.tamaya.spi.PropertyAdapterSpi}, which provides propertyAdapters
+ * for some basic types.
+ */
+@SuppressWarnings({"unchecked", "rawtypes"})
+public final class TestPropertyAdaptersSingletonSpi implements PropertyAdapterSpi {
+
+ private Map<Class, PropertyAdapter<?>> propertyAdapters = new ConcurrentHashMap<>();
+
+ private TestPropertyAdaptersSingletonSpi(){
+ register(char.class, (s) -> s.charAt(0));
+ register(int.class, Integer::parseInt);
+ register(byte.class, Byte::parseByte);
+ register(short.class, Short::parseShort);
+ register(boolean.class, Boolean::parseBoolean);
+ register(float.class, Float::parseFloat);
+ register(double.class, Double::parseDouble);
+
+ register(Character.class, (s) -> s.charAt(0));
+ register(Integer.class, Integer::valueOf);
+ register(Byte.class, Byte::valueOf);
+ register(Short.class, Short::valueOf);
+ register(Boolean.class, Boolean::valueOf);
+ register(Float.class, Float::valueOf);
+ register(Double.class, Double::valueOf);
+ register(BigDecimal.class, BigDecimal::new);
+ register(BigInteger.class, BigInteger::new);
+
+ register(Currency.class, Currency::getInstance);
+
+ register(LocalDate.class, LocalDate::parse);
+ register(LocalTime.class, LocalTime::parse);
+ register(LocalDateTime.class, LocalDateTime::parse);
+ register(ZoneId.class, ZoneId::of);
+ }
+
+
+ @Override
+ public <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> codec){
+ Objects.requireNonNull(targetType);
+ Objects.requireNonNull(codec);
+ return (PropertyAdapter<T>) propertyAdapters.put(targetType, codec);
+ }
+
+ @Override
+ public <T> PropertyAdapter<T> getPropertyAdapter(Class<T> targetType, WithPropertyAdapter annotation){
+ if(annotation!=null){
+ Class<?> adapterType = annotation.value();
+ if(!adapterType.equals(PropertyAdapter.class)){
+ try{
+ return (PropertyAdapter<T>)adapterType.newInstance();
+ }
+ catch(Exception e){
+ throw new ConfigException("Failed to load PropertyAdapter: " + adapterType, e);
+ }
+ }
+ }
+ return (PropertyAdapter<T>) propertyAdapters.get(targetType);
+ }
+
+ @Override
+ public boolean isTargetTypeSupported(Class<?> targetType){
+ return propertyAdapters.containsKey(targetType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/test/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/resources/META-INF/beans.xml b/modules/injection/src/test/resources/META-INF/beans.xml
new file mode 100644
index 0000000..5207c9a
--- /dev/null
+++ b/modules/injection/src/test/resources/META-INF/beans.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi b/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
new file mode 100644
index 0000000..1b0cdd4
--- /dev/null
+++ b/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.TestConfigServiceSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi b/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
new file mode 100644
index 0000000..e9b04b4
--- /dev/null
+++ b/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.TestPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/integration/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml
new file mode 100644
index 0000000..efc019d
--- /dev/null
+++ b/modules/integration/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>tamaya-extensions-all</artifactId>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <version>0.1-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <packaging>pom</packaging>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tamaya.ext.integration</groupId>
+ <artifactId>tamaya-integrations</artifactId>
+
+ <modules>
+ <module>cdi</module>
+ <module>se</module>
+ </modules>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/management/pom.xml
----------------------------------------------------------------------
diff --git a/modules/management/pom.xml b/modules/management/pom.xml
new file mode 100644
index 0000000..6d6e441
--- /dev/null
+++ b/modules/management/pom.xml
@@ -0,0 +1,41 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-extensions</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-management</artifactId>
+ <name>Apache Tamaya Modules Integration - Java Management Extensions</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/metamodels/environment/pom.xml
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/pom.xml b/modules/metamodels/environment/pom.xml
new file mode 100644
index 0000000..85a45ee
--- /dev/null
+++ b/modules/metamodels/environment/pom.xml
@@ -0,0 +1,34 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext.metamodels</groupId>
+ <artifactId>tamaya-metamodels</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-metamodel-environment</artifactId>
+ <name>Apache Tamaya Modules Metamodels - environment</name>
+ <description>Environment Tamaya Metamodel</description>
+ <packaging>jar</packaging>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/metamodels/pom.xml
----------------------------------------------------------------------
diff --git a/modules/metamodels/pom.xml b/modules/metamodels/pom.xml
new file mode 100644
index 0000000..2631d94
--- /dev/null
+++ b/modules/metamodels/pom.xml
@@ -0,0 +1,39 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-extensions</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <groupId>org.apache.tamaya.ext.metamodels</groupId>
+ <artifactId>tamaya-metamodels</artifactId>
+ <name>Apache Tamaya Extension Modules: Metamodels</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>simple</module>
+ <module>environment</module>
+ </modules>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/metamodels/simple/pom.xml
----------------------------------------------------------------------
diff --git a/modules/metamodels/simple/pom.xml b/modules/metamodels/simple/pom.xml
new file mode 100644
index 0000000..898ab2f
--- /dev/null
+++ b/modules/metamodels/simple/pom.xml
@@ -0,0 +1,34 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext.metamodels</groupId>
+ <artifactId>tamaya-metamodels</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-metamodel-simple</artifactId>
+ <name>Apache Tamaya Modules Metamodels - Simple</name>
+ <description>Simple Tamaya Metamodel, e.g. feasible for SE commandline tools and simple use cases.</description>
+ <packaging>jar</packaging>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/pom.xml
----------------------------------------------------------------------
diff --git a/modules/pom.xml b/modules/pom.xml
new file mode 100644
index 0000000..c2aa0b2
--- /dev/null
+++ b/modules/pom.xml
@@ -0,0 +1,42 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-all</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-extensions</artifactId>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <name>Apache Tamaya Extension Modules</name>
+ <description>This project contains the several extensions that can be used with Tamaya.</description>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>injection</module>
+ <module>resolver</module>
+ <module>metamodels</module>
+ <module>integration</module>
+ </modules>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/resolver/src/main/java/org/apache/tamaya/resolver/ExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/ExpressionEvaluator.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/ExpressionEvaluator.java
new file mode 100644
index 0000000..5baa956
--- /dev/null
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/ExpressionEvaluator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.spi;
+
+import org.apache.tamaya.Configuration;
+
+/**
+ * This interfaces provides a model for expression evaluation. This enables transparently plugin expression languages
+ * as needed. In a Java EE context full fledged EL may be used, whereas in ME only simple replacement mechanisms
+ * are better suited to the runtime requirements.
+ */
+@FunctionalInterface
+public interface ExpressionEvaluator {
+ /**
+ * Evaluates the given expression.
+ * @param expression the expression to be evaluated, not null.
+ * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no items are passed, the default configuration is used.
+ * @return the evaluated expression.
+ */
+ String evaluate(String expression, Configuration... configurations);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
new file mode 100644
index 0000000..457aa6c
--- /dev/null
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.el;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.core.spi.ExpressionEvaluator;
+import org.apache.tamaya.core.spi.ExpressionResolver;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Default expression evaluator that manages several instances of {@link org.apache.tamaya.core.spi.ExpressionResolver}.
+ * Each resolver is identified by a resolver id. Each expression passed has the form resolverId:resolverExpression, which
+ * has the advantage that different resolvers can be active in parallel.
+ */
+public final class DefaultExpressionEvaluator implements ExpressionEvaluator{
+
+ private Map<String, ExpressionResolver> resolvers = new ConcurrentHashMap<>();
+
+ private ExpressionResolver defaultResolver;
+
+ public DefaultExpressionEvaluator() {
+ for(ExpressionResolver resolver: ServiceContext.getInstance().getServices(ExpressionResolver.class)){
+ resolvers.put(resolver.getResolverId(), resolver);
+ }
+ defaultResolver = ServiceContext.getInstance().getSingleton(ExpressionResolver.class);
+ }
+
+ /**
+ * Resolves an expression in the form current <code>${resolverId:expression}</code>. The expression can be
+ * part current any type current literal text. Also multiple expression, with different resolver ids are supported.
+ * All control characters (${}\) can be escaped.<br>
+ * So all the following are valid expressions:
+ * <ul>
+ * <li><code>${resolverId:expression}</code></li>
+ * <li><code>bla bla ${resolverId:expression}</code></li>
+ * <li><code>${resolverId:expression} bla bla</code></li>
+ * <li><code>bla bla ${resolverId:expression} bla bla</code></li>
+ * <li><code>${resolverId:expression}${resolverId2:expression2}</code></li>
+ * <li><code>foo ${resolverId:expression}${resolverId2:expression2}</code></li>
+ * <li><code>foo ${resolverId:expression} bar ${resolverId2:expression2}</code></li>
+ * <li><code>${resolverId:expression}foo${resolverId2:expression2}bar</code></li>
+ * <li><code>foor${resolverId:expression}bar${resolverId2:expression2}more</code></li>
+ * <li><code>\${resolverId:expression}foo${resolverId2:expression2}bar</code> (first expression is escaped).</li>
+ * </ul>
+ *
+ * @param expression the expression to be evaluated, not null
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no such config is passed, the default configurations provided by the current
+ * registered providers are used.
+ * @return the evaluated expression.
+ * @throws org.apache.tamaya.ConfigException if resolution fails.
+ */
+ @Override
+ public String evaluate(String expression, Configuration... configurations) {
+ StringTokenizer tokenizer = new StringTokenizer(expression, "${}\\", true);
+ boolean escaped = false;
+ StringBuilder resolvedValue = new StringBuilder();
+ StringBuilder current = new StringBuilder();
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ if (escaped) {
+ switch (token) {
+ case "n":
+ current.append("\n");
+ break;
+ case "r":
+ current.append("\r");
+ break;
+ case "t":
+ current.append("\t");
+ break;
+ default:
+ current.append(token);
+ break;
+ }
+ escaped = false;
+ continue;
+ }
+ switch (token) {
+ case "\\":
+ escaped = true;
+ break;
+ case "$":
+ if (current.length() > 0) {
+ resolvedValue.append(current);
+ current.setLength(0);
+ }
+ if (!"{".equals(tokenizer.nextToken())) {
+ throw new ConfigException("Invalid expression encountered: " + expression);
+ }
+ String subExpression = tokenizer.nextToken();
+ if (!"}".equals(tokenizer.nextToken())) {
+ throw new ConfigException("Invalid expression encountered: " + expression);
+ }
+ // evaluate sub-expression
+ current.append(evaluteInternal(subExpression));
+ break;
+ default:
+ current.append(token);
+ }
+ }
+ if (current.length() > 0) {
+ resolvedValue.append(current);
+ }
+ return resolvedValue.toString();
+ }
+
+ private String evaluteInternal(String subExpression) {
+ int sepPos = subExpression.indexOf(':');
+ if (sepPos > 0) {
+ String refID = subExpression.substring(0, sepPos);
+ String expression = subExpression.substring(sepPos + 1);
+ return Optional.ofNullable(this.resolvers.get(refID)).orElseThrow(
+ () -> new ConfigException("Resolver not found: " + refID + " in " + subExpression)
+ ).resolve(expression);
+ } else {
+ return Optional.ofNullable(this.defaultResolver).orElseThrow(
+ () -> new ConfigException("No default Resolver set, but required by " + subExpression)
+ ).resolve(subExpression);
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/EnvironmentPropertyResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/EnvironmentPropertyResolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/EnvironmentPropertyResolver.java
new file mode 100644
index 0000000..68d37a4
--- /dev/null
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/EnvironmentPropertyResolver.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.el;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.spi.ExpressionResolver;
+
+import java.util.Optional;
+
+/**
+ * Property resolver implementation that interprets the resolver expressions as environment properties.
+ */
+public final class EnvironmentPropertyResolver implements ExpressionResolver{
+
+ @Override
+ public String getResolverId() {
+ return "env";
+ }
+
+ @Override
+ public String resolve(String expression, Configuration... configurations){
+ return Optional.ofNullable(System.getenv(expression)).orElseThrow(
+ () -> new ConfigException("No such environment property: " + expression)
+ );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/SystemPropertyResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/SystemPropertyResolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/SystemPropertyResolver.java
new file mode 100644
index 0000000..c6eb298
--- /dev/null
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/SystemPropertyResolver.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.el;
+
+import java.util.Optional;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.spi.ExpressionResolver;
+
+/**
+ * Property resolver implementation that interprets the resolver expression as system property name.
+ */
+public final class SystemPropertyResolver implements ExpressionResolver{
+
+ @Override
+ public String getResolverId() {
+ return "sys";
+ }
+
+ @Override
+ public String resolve(String expression, Configuration... configurations){
+ return Optional.ofNullable(System.getProperty(expression)).orElseThrow(
+ () -> new ConfigException("No such system property: " + expression)
+ );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionResolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionResolver.java
new file mode 100644
index 0000000..5ec7b52
--- /dev/null
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionResolver.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.spi;
+
+import org.apache.tamaya.Configuration;
+
+/**
+ * This interface defines a small plugin for resolving current expressions within configuration.
+ * Resolver expression always have the form current <code>${resolverId:expression}</code>. The
+ * {@code resolverId} hereby references the resolver to be used to replace the according
+ * {@code expression}. Also it is well possible to mix different resolvers, e.g. using
+ * an expression like <code>${ref1:expression1} bla bla ${ref2:expression2}</code>.
+ * Finally when no resolver id is passed, the default resolver should be used.
+ */
+public interface ExpressionResolver {
+
+ /**
+ * Get a (unique) resolver id used as a prefix for qualifying the resolver to be used for
+ * resolving an expression.
+ *
+ * @return the (unique) resolver id, never null, not empty.
+ */
+ String getResolverId();
+
+ /**
+ * Resolve the expression. The expression should be stripped fromMap any surrounding parts.
+ * E.g. <code>${myresolver:blabla to be interpreted AND executed.}</code> should be passed
+ * as {@code blabla to be interpreted AND executed.} only.
+ *
+ * @param expression the stripped expression.
+ * @param configuration the configuration for which the value must be resolved.
+ * @return the resolved expression.
+ * @throws org.apache.tamaya.ConfigException when the expression passed is not resolvable, e.g. due to syntax issues
+ * or data not present or valid.
+ */
+ String resolve(String expression, Configuration configuration);
+}
[24/27] incubator-tamaya git commit: Fixed checkstyle issues.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java
index 60fc452..ba07c7b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/VfsUtils.java
@@ -18,17 +18,21 @@ package org.apache.tamaya.core.internal.resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.net.URI;
import java.net.URL;
/**
* Utility for detecting and accessing JBoss VFS in the classpath.
- *
+ * <p>
* <p>As current Spring 4.0, this class supports VFS 3.x on JBoss AS 6+ (package
* {@code org.jboss.vfs}) and is in particular compatible with JBoss AS 7 and
* WildFly 8.
- *
+ * <p>
* <p>Thanks go to Marius Bogoevici for the initial patch.
* <b>Note:</b> This is an internal class and should not be used outside the framework.
*
@@ -38,172 +42,165 @@ import java.net.URL;
*/
class VfsUtils {
- private static final String VFS3_PKG = "org.jboss.vfs.";
- private static final String VFS_NAME = "VFS";
-
- private static Method VFS_METHOD_GET_ROOT_URL = null;
- private static Method VFS_METHOD_GET_ROOT_URI = null;
-
- private static Method VIRTUAL_FILE_METHOD_EXISTS = null;
- private static Method VIRTUAL_FILE_METHOD_GET_INPUT_STREAM;
- private static Method VIRTUAL_FILE_METHOD_GET_SIZE;
- private static Method VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED;
- private static Method VIRTUAL_FILE_METHOD_TO_URL;
- private static Method VIRTUAL_FILE_METHOD_TO_URI;
- private static Method VIRTUAL_FILE_METHOD_GET_NAME;
- private static Method VIRTUAL_FILE_METHOD_GET_PATH_NAME;
- private static Method VIRTUAL_FILE_METHOD_GET_CHILD;
-
- protected static Class<?> VIRTUAL_FILE_VISITOR_INTERFACE;
- protected static Method VIRTUAL_FILE_METHOD_VISIT;
-
- private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null;
- private static Method GET_PHYSICAL_FILE = null;
-
- static {
- ClassLoader loader = VfsUtils.class.getClassLoader();
- try {
- Class<?> vfsClass = loader.loadClass(VFS3_PKG + VFS_NAME);
- VFS_METHOD_GET_ROOT_URL = ReflectionUtils.findMethod(vfsClass, "getChild", URL.class);
- VFS_METHOD_GET_ROOT_URI = ReflectionUtils.findMethod(vfsClass, "getChild", URI.class);
-
- Class<?> virtualFile = loader.loadClass(VFS3_PKG + "VirtualFile");
- VIRTUAL_FILE_METHOD_EXISTS = ReflectionUtils.findMethod(virtualFile, "exists");
- VIRTUAL_FILE_METHOD_GET_INPUT_STREAM = ReflectionUtils.findMethod(virtualFile, "openStream");
- VIRTUAL_FILE_METHOD_GET_SIZE = ReflectionUtils.findMethod(virtualFile, "getSize");
- VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED = ReflectionUtils.findMethod(virtualFile, "getLastModified");
- VIRTUAL_FILE_METHOD_TO_URI = ReflectionUtils.findMethod(virtualFile, "toURI");
- VIRTUAL_FILE_METHOD_TO_URL = ReflectionUtils.findMethod(virtualFile, "toURL");
- VIRTUAL_FILE_METHOD_GET_NAME = ReflectionUtils.findMethod(virtualFile, "getName");
- VIRTUAL_FILE_METHOD_GET_PATH_NAME = ReflectionUtils.findMethod(virtualFile, "getPathName");
- GET_PHYSICAL_FILE = ReflectionUtils.findMethod(virtualFile, "getPhysicalFile");
- VIRTUAL_FILE_METHOD_GET_CHILD = ReflectionUtils.findMethod(virtualFile, "getChild", String.class);
-
- VIRTUAL_FILE_VISITOR_INTERFACE = loader.loadClass(VFS3_PKG + "VirtualFileVisitor");
- VIRTUAL_FILE_METHOD_VISIT = ReflectionUtils.findMethod(virtualFile, "visit", VIRTUAL_FILE_VISITOR_INTERFACE);
-
- Class<?> visitorAttributesClass = loader.loadClass(VFS3_PKG + "VisitorAttributes");
- VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
- }
- catch (ClassNotFoundException ex) {
- throw new IllegalStateException("Could not detect JBoss VFS infrastructure", ex);
- }
- }
-
- private VfsUtils(){}
+ private static final String VFS3_PACKAGE = "org.jboss.vfs.";
+ private static final String VFS_NAME = "VFS";
+
+ private static Method vfsMethodGetRootUrl = null;
+ private static Method vfsMethodGetRootUri = null;
+
+ private static Method virtualFileMethodExists = null;
+ private static Method virtualFileMethodGetInputStream;
+ private static Method virtualFileMethodGetSize;
+ private static Method virtualFileMethodGetLastModified;
+ private static Method virtualFileMethodToUrl;
+ private static Method virtualFileMethodToUri;
+ private static Method virtualFileMethodGetName;
+ private static Method virtualFileMethodGetPathName;
+ private static Method virtualFileMethodGetChild;
+
+ protected static Class<?> virtualFileVisitorInterface;
+ protected static Method virtualFileMethodVisit;
+
+ private static Field visitorAttributesFieldRecurse = null;
+ private static Method getPhysicalFile = null;
+
+ static {
+ ClassLoader loader = VfsUtils.class.getClassLoader();
+ try {
+ Class<?> vfsClass = loader.loadClass(VFS3_PACKAGE + VFS_NAME);
+ vfsMethodGetRootUrl = ReflectionUtils.findMethod(vfsClass, "getChild", URL.class);
+ vfsMethodGetRootUri = ReflectionUtils.findMethod(vfsClass, "getChild", URI.class);
+
+ Class<?> virtualFile = loader.loadClass(VFS3_PACKAGE + "VirtualFile");
+ virtualFileMethodExists = ReflectionUtils.findMethod(virtualFile, "exists");
+ virtualFileMethodGetInputStream = ReflectionUtils.findMethod(virtualFile, "openStream");
+ virtualFileMethodGetSize = ReflectionUtils.findMethod(virtualFile, "getSize");
+ virtualFileMethodGetLastModified = ReflectionUtils.findMethod(virtualFile, "getLastModified");
+ virtualFileMethodToUri = ReflectionUtils.findMethod(virtualFile, "toURI");
+ virtualFileMethodToUrl = ReflectionUtils.findMethod(virtualFile, "toURL");
+ virtualFileMethodGetName = ReflectionUtils.findMethod(virtualFile, "getName");
+ virtualFileMethodGetPathName = ReflectionUtils.findMethod(virtualFile, "getPathName");
+ getPhysicalFile = ReflectionUtils.findMethod(virtualFile, "getPhysicalFile");
+ virtualFileMethodGetChild = ReflectionUtils.findMethod(virtualFile, "getChild", String.class);
+
+ virtualFileVisitorInterface = loader.loadClass(VFS3_PACKAGE + "VirtualFileVisitor");
+ virtualFileMethodVisit = ReflectionUtils.findMethod(virtualFile, "visit", virtualFileVisitorInterface);
+
+ Class<?> visitorAttributesClass = loader.loadClass(VFS3_PACKAGE + "VisitorAttributes");
+ visitorAttributesFieldRecurse = ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
+ } catch (ClassNotFoundException ex) {
+ throw new IllegalStateException("Could not detect JBoss VFS infrastructure", ex);
+ }
+ }
+
+ private VfsUtils() {
+ }
static void visit(Object resource, InvocationHandler visitor) throws IOException {
Object visitorProxy = Proxy.newProxyInstance(
- VIRTUAL_FILE_VISITOR_INTERFACE.getClassLoader(),
- new Class<?>[]{VIRTUAL_FILE_VISITOR_INTERFACE}, visitor);
- invokeVfsMethod(VIRTUAL_FILE_METHOD_VISIT, resource, visitorProxy);
- }
-
- protected static Object invokeVfsMethod(Method method, Object target, Object... args) throws IOException {
- try {
- return method.invoke(target, args);
- }
- catch (InvocationTargetException ex) {
- Throwable targetEx = ex.getTargetException();
- if (targetEx instanceof IOException) {
- throw (IOException) targetEx;
- }
- ReflectionUtils.handleInvocationTargetException(ex);
- }
- catch (Exception ex) {
- ReflectionUtils.handleReflectionException(ex);
- }
-
- throw new IllegalStateException("Invalid code path reached");
- }
-
- static boolean exists(Object vfsResource) {
- try {
- return (Boolean) invokeVfsMethod(VIRTUAL_FILE_METHOD_EXISTS, vfsResource);
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- static boolean isReadable(Object vfsResource) {
- try {
- return ((Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_SIZE, vfsResource) > 0);
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- static long getSize(Object vfsResource) throws IOException {
- return (Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_SIZE, vfsResource);
- }
-
- static long getLastModified(Object vfsResource) throws IOException {
- return (Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED, vfsResource);
- }
-
- static InputStream getInputStream(Object vfsResource) throws IOException {
- return (InputStream) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_INPUT_STREAM, vfsResource);
- }
-
- static URL getURL(Object vfsResource) throws IOException {
- return (URL) invokeVfsMethod(VIRTUAL_FILE_METHOD_TO_URL, vfsResource);
- }
-
- static URI getURI(Object vfsResource) throws IOException {
- return (URI) invokeVfsMethod(VIRTUAL_FILE_METHOD_TO_URI, vfsResource);
- }
-
- static String getName(Object vfsResource) {
- try {
- return (String) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_NAME, vfsResource);
- }
- catch (IOException ex) {
- throw new IllegalStateException("Cannot get resource name", ex);
- }
- }
-
- static Object getRelative(URL url) throws IOException {
- return invokeVfsMethod(VFS_METHOD_GET_ROOT_URL, null, url);
- }
-
- static Object getChild(Object vfsResource, String path) throws IOException {
- return invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_CHILD, vfsResource, path);
- }
-
- static File getFile(Object vfsResource) throws IOException {
- return (File) invokeVfsMethod(GET_PHYSICAL_FILE, vfsResource);
- }
-
- static Object getRoot(URI url) throws IOException {
- return invokeVfsMethod(VFS_METHOD_GET_ROOT_URI, null, url);
- }
-
- // protected methods used by the support sub-package
-
- protected static Object getRoot(URL url) throws IOException {
- return invokeVfsMethod(VFS_METHOD_GET_ROOT_URL, null, url);
- }
-
- protected static Object getVisitorAttribute() {
- try{
- return VISITOR_ATTRIBUTES_FIELD_RECURSE.get(null);
+ virtualFileVisitorInterface.getClassLoader(),
+ new Class<?>[]{virtualFileVisitorInterface}, visitor);
+ invokeVfsMethod(virtualFileMethodVisit, resource, visitorProxy);
+ }
+
+ protected static Object invokeVfsMethod(Method method, Object target, Object... args) throws IOException {
+ try {
+ return method.invoke(target, args);
+ } catch (InvocationTargetException ex) {
+ Throwable targetEx = ex.getTargetException();
+ if (targetEx instanceof IOException) {
+ throw (IOException) targetEx;
+ }
+ ReflectionUtils.handleInvocationTargetException(ex);
+ } catch (Exception ex) {
+ ReflectionUtils.handleReflectionException(ex);
+ }
+
+ throw new IllegalStateException("Invalid code path reached");
+ }
+
+ static boolean exists(Object vfsResource) {
+ try {
+ return (Boolean) invokeVfsMethod(virtualFileMethodExists, vfsResource);
+ } catch (IOException ex) {
+ return false;
+ }
+ }
+
+ static boolean isReadable(Object vfsResource) {
+ try {
+ return ((Long) invokeVfsMethod(virtualFileMethodGetSize, vfsResource) > 0);
+ } catch (IOException ex) {
+ return false;
+ }
+ }
+
+ static long getSize(Object vfsResource) throws IOException {
+ return (Long) invokeVfsMethod(virtualFileMethodGetSize, vfsResource);
+ }
+
+ static long getLastModified(Object vfsResource) throws IOException {
+ return (Long) invokeVfsMethod(virtualFileMethodGetLastModified, vfsResource);
+ }
+
+ static InputStream getInputStream(Object vfsResource) throws IOException {
+ return (InputStream) invokeVfsMethod(virtualFileMethodGetInputStream, vfsResource);
+ }
+
+ static URL getURL(Object vfsResource) throws IOException {
+ return (URL) invokeVfsMethod(virtualFileMethodToUrl, vfsResource);
+ }
+
+ static URI getURI(Object vfsResource) throws IOException {
+ return (URI) invokeVfsMethod(virtualFileMethodToUri, vfsResource);
+ }
+
+ static String getName(Object vfsResource) {
+ try {
+ return (String) invokeVfsMethod(virtualFileMethodGetName, vfsResource);
+ } catch (IOException ex) {
+ throw new IllegalStateException("Cannot get resource name", ex);
}
- catch(Exception e){
+ }
+
+ static Object getRelative(URL url) throws IOException {
+ return invokeVfsMethod(vfsMethodGetRootUrl, null, url);
+ }
+
+ static Object getChild(Object vfsResource, String path) throws IOException {
+ return invokeVfsMethod(virtualFileMethodGetChild, vfsResource, path);
+ }
+
+ static File getFile(Object vfsResource) throws IOException {
+ return (File) invokeVfsMethod(getPhysicalFile, vfsResource);
+ }
+
+ static Object getRoot(URI url) throws IOException {
+ return invokeVfsMethod(vfsMethodGetRootUri, null, url);
+ }
+
+ // protected methods used by the support sub-package
+
+ protected static Object getRoot(URL url) throws IOException {
+ return invokeVfsMethod(vfsMethodGetRootUrl, null, url);
+ }
+
+ protected static Object getVisitorAttribute() {
+ try {
+ return visitorAttributesFieldRecurse.get(null);
+ } catch (Exception e) {
ReflectionUtils.handleReflectionException(e);
return null; // never called
}
- }
+ }
- protected static String getPath(Object resource) {
- try{
- return (String) VIRTUAL_FILE_METHOD_GET_PATH_NAME.invoke(resource);
- }
- catch(Exception e){
+ protected static String getPath(Object resource) {
+ try {
+ return (String) virtualFileMethodGetPathName.invoke(resource);
+ } catch (Exception e) {
ReflectionUtils.handleReflectionException(e);
return null; // never called
}
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java b/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java
index dfe6cf7..3d95269 100644
--- a/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java
+++ b/core/src/main/java/org/apache/tamaya/core/resources/InputStreamSource.java
@@ -19,28 +19,29 @@ import java.io.IOException;
import java.io.InputStream;
/**
-* Simple interface for objects that are sources for an {@link InputStream}.
-*
-* <p>This is the base interface for the more extensive {@link Resource} interface.
-*
-* @author Juergen Hoeller
-* @since 20.01.2004
-* @see java.io.InputStream
-* @see Resource
-*/
+ * Simple interface for objects that are sources for an {@link InputStream}.
+ * <p>
+ * <p>This is the base interface for the more extensive {@link Resource} interface.
+ *
+ * @author Juergen Hoeller
+ * @see java.io.InputStream
+ * @see Resource
+ * @since 20.01.2004
+ */
@FunctionalInterface
public interface InputStreamSource {
- /**
- * Return an {@link InputStream}.
- * <p>It is expected that each call creates a <i>fresh</i> stream.
- * <p>This requirement is particularly important when you consider an API such
- * as JavaMail, which needs to be able to read the stream multiple times when
- * creating mail attachments. For such a use case, it is <i>required</i>
- * that each {@code getInputStreamSupplier()} call returns a fresh stream.
- * @return the input stream for the underlying resource (must not be {@code null})
- * @throws IOException if the stream could not be opened
- */
- InputStream getInputStream() throws IOException;
+ /**
+ * Return an {@link InputStream}.
+ * <p>It is expected that each call creates a <i>fresh</i> stream.
+ * <p>This requirement is particularly important when you consider an API such
+ * as JavaMail, which needs to be able to read the stream multiple times when
+ * creating mail attachments. For such a use case, it is <i>required</i>
+ * that each {@code getInputStreamSupplier()} call returns a fresh stream.
+ *
+ * @return the input stream for the underlying resource (must not be {@code null})
+ * @throws IOException if the stream could not be opened
+ */
+ InputStream getInputStream() throws IOException;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/resources/Resource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resources/Resource.java b/core/src/main/java/org/apache/tamaya/core/resources/Resource.java
index 7ab27dc..14966e9 100644
--- a/core/src/main/java/org/apache/tamaya/core/resources/Resource.java
+++ b/core/src/main/java/org/apache/tamaya/core/resources/Resource.java
@@ -27,105 +27,110 @@ import java.util.Objects;
/**
* Interface for a resource descriptor that abstracts from the actual
* type current underlying resource, such as a file or class path resource.
- *
+ * <p>
* <p>An InputStream can be opened for every resource if it exists in
* physical form, but a URL or File handle can just be returned for
* certain resources. The actual behavior is implementation-specific.
*
* @author Juergen Hoeller
- * @since 28.12.2003
* @see #getInputStream()
* @see #toURL()
* @see #getURI()
* @see #toFile()
+ * @since 28.12.2003
*/
public interface Resource extends InputStreamSource {
- /**
- * Return whether this resource actually exists in physical form.
- * <p>This method performs a definitive existence check, whereas the
- * existence current a {@code Resource} handle only guarantees a
- * valid descriptor handle.
- */
+ /**
+ * Return whether this resource actually exists in physical form.
+ * <p>This method performs a definitive existence check, whereas the
+ * existence current a {@code Resource} handle only guarantees a
+ * valid descriptor handle.
+ */
default boolean exists() {
// Try file existence: can we find the file in the file system?
try {
return toFile().exists();
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
// Fall back to stream existence: can we open the stream?
try {
InputStream is = getInputStream();
is.close();
return true;
- }
- catch (Throwable isEx) {
+ } catch (Throwable isEx) {
return false;
}
}
}
- /**
- * Return whether the contents current this resource can be read,
- * e.g. via {@link #getInputStream()} or {@link #toFile()}.
- * <p>Will be {@code true} for typical resource descriptors;
- * note that actual content reading may still fail when attempted.
- * However, a keys current {@code false} is a definitive indication
- * that the resource content cannot be read.
- * @see #getInputStream()
- */
- default boolean isReadable(){return true;}
+ /**
+ * Return whether the contents current this resource can be read,
+ * e.g. via {@link #getInputStream()} or {@link #toFile()}.
+ * <p>Will be {@code true} for typical resource descriptors;
+ * note that actual content reading may still fail when attempted.
+ * However, a keys current {@code false} is a definitive indication
+ * that the resource content cannot be read.
+ *
+ * @see #getInputStream()
+ */
+ default boolean isReadable() {
+ return true;
+ }
- /**
- * Return whether this resource represents a handle with an open
- * stream. If true, the InputStream cannot be read multiple times,
- * and must be read and closed to avoid resource leaks.
- * <p>Will be {@code false} for typical resource descriptors.
- */
- default boolean isOpen(){return false;}
+ /**
+ * Return whether this resource represents a handle with an open
+ * stream. If true, the InputStream cannot be read multiple times,
+ * and must be read and closed to avoid resource leaks.
+ * <p>Will be {@code false} for typical resource descriptors.
+ */
+ default boolean isOpen() {
+ return false;
+ }
- /**
- * Return a URL handle for this resource.
- * @throws IOException if the resource cannot be resolved as URL,
- * i.e. if the resource is not available as descriptor
- */
- default URL toURL() throws IOException{
+ /**
+ * Return a URL handle for this resource.
+ *
+ * @throws IOException if the resource cannot be resolved as URL,
+ * i.e. if the resource is not available as descriptor
+ */
+ default URL toURL() throws IOException {
return getURI().toURL();
}
- /**
- * Return a URI handle for this resource.
- * @throws IOException if the resource cannot be resolved as URI,
- * i.e. if the resource is not available as descriptor
- */
- default URI getURI() throws IOException{
+ /**
+ * Return a URI handle for this resource.
+ *
+ * @throws IOException if the resource cannot be resolved as URI,
+ * i.e. if the resource is not available as descriptor
+ */
+ default URI getURI() throws IOException {
URL url = toURL();
try {
return new URI(url.toString().replaceAll(" ", "%20"));
- }
- catch (URISyntaxException ex) {
+ } catch (URISyntaxException ex) {
throw new IllegalStateException("Invalid URI [" + url + "]", ex);
}
}
- /**
- * Return a File handle for this resource.
- * @throws IOException if the resource cannot be resolved as absolute
- * file path, i.e. if the resource is not available in a file system
- */
- default File toFile() throws IOException{
+ /**
+ * Return a File handle for this resource.
+ *
+ * @throws IOException if the resource cannot be resolved as absolute
+ * file path, i.e. if the resource is not available in a file system
+ */
+ default File toFile() throws IOException {
return new File(getURI());
}
- /**
- * Determine the content length for this resource.
- * @throws IOException if the resource cannot be resolved
- * (in the file system or as some other known physical resource type)
- */
- default long contentLength() throws IOException{
- InputStream is = this.getInputStream();
- Objects.requireNonNull(is, "resource input stream must not be null");
- try {
+ /**
+ * Determine the content length for this resource.
+ *
+ * @throws IOException if the resource cannot be resolved
+ * (in the file system or as some other known physical resource type)
+ */
+ default long contentLength() throws IOException {
+ try(InputStream is = this.getInputStream();) {
+ Objects.requireNonNull(is, "resource input stream must not be null");
long size = 0;
byte[] buf = new byte[255];
int read;
@@ -134,21 +139,15 @@ public interface Resource extends InputStreamSource {
}
return size;
}
- finally {
- try {
- is.close();
- }
- catch (IOException ex) {
- }
- }
}
- /**
- * Determine the last-modified timestamp for this resource.
- * @throws IOException if the resource cannot be resolved
- * (in the file system or as some other known physical resource type)
- */
- default long lastModified() throws IOException {
+ /**
+ * Determine the last-modified timestamp for this resource.
+ *
+ * @throws IOException if the resource cannot be resolved
+ * (in the file system or as some other known physical resource type)
+ */
+ default long lastModified() throws IOException {
long lastModified = toFile().lastModified();
if (lastModified == 0L) {
throw new FileNotFoundException(getDisplayName() +
@@ -157,27 +156,27 @@ public interface Resource extends InputStreamSource {
return lastModified;
}
- /**
- * Create a resource relative to this resource.
- * @param relativePath the relative path (relative to this resource)
- * @return the resource handle for the relative resource
- * @throws IOException if the relative resource cannot be determined
- */
- default Resource createRelative(String relativePath) throws IOException{
+ /**
+ * Create a resource relative to this resource.
+ *
+ * @param relativePath the relative path (relative to this resource)
+ * @return the resource handle for the relative resource
+ * @throws IOException if the relative resource cannot be determined
+ */
+ default Resource createRelative(String relativePath) throws IOException {
throw new FileNotFoundException("Cannot of a relative resource for " + getDisplayName());
}
- /**
- * Determine a filename for this resource, i.e. typically the last
- * part current the path: for example, "myfile.txt".
- * <p>Returns {@code null} if this type current resource does not
- * have a filename.
- */
- default String getDisplayName(){
- try{
+ /**
+ * Determine a filename for this resource, i.e. typically the last
+ * part current the path: for example, "myfile.txt".
+ * <p>Returns {@code null} if this type current resource does not
+ * have a filename.
+ */
+ default String getDisplayName() {
+ try {
return getURI().toString();
- }
- catch(Exception e){
+ } catch (Exception e) {
return toString();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java
index ca071ca..849f136 100644
--- a/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java
+++ b/core/src/main/java/org/apache/tamaya/core/resources/ResourceLoader.java
@@ -31,7 +31,7 @@ import java.util.List;
* interprets this expression and evaluates the concrete resources to be read,
* e.g. {@code cfg/global/default.xml, cfg/global/myApp.xml}.
*/
-public interface ResourceLoader{
+public interface ResourceLoader {
/**
* Called, when a given expression has to be resolved.
@@ -56,7 +56,7 @@ public interface ResourceLoader{
*/
default List<Resource> getResources(Collection<String> expressions) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
+ if (cl == null) {
cl = getClass().getClassLoader();
}
return getResources(cl, expressions);
[22/27] incubator-tamaya git commit: Fixed checkstyle issues.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java b/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java
index 49c3291..d74c63f 100644
--- a/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java
+++ b/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java
@@ -17,447 +17,457 @@ package org.apache.tamaya.core.util;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Properties;
import java.util.StringTokenizer;
/**
-* Miscellaneous {@link String} utility methods.
-*
-* <p>Mainly for internal use within the framework; consider
-* <a href="http://jakarta.apache.org/commons/lang/">Jakarta's Commons Lang</a>
-* for a more comprehensive suite current String utilities.
-*
-* <p>This class delivers some simple functionality that should really
-* be provided by the core Java {@code String} and {@link StringBuilder}
-* classes, such as the ability to {@code replace} all occurrences current a given
-* substring in a target string. It also provides easy-to-use methods to convert
-* between delimited strings, such as CSV strings, and collections and arrays.
-*
-* @author Rod Johnson
-* @author Juergen Hoeller
-* @author Keith Donald
-* @author Rob Harrop
-* @author Rick Evans
-* @author Arjen Poutsma
-* @since 16 April 2001
-*/
+ * Miscellaneous {@link String} utility methods.
+ * <p>
+ * <p>Mainly for internal use within the framework; consider
+ * <a href="http://jakarta.apache.org/commons/lang/">Jakarta's Commons Lang</a>
+ * for a more comprehensive suite current String utilities.
+ * <p>
+ * <p>This class delivers some simple functionality that should really
+ * be provided by the core Java {@code String} and {@link StringBuilder}
+ * classes, such as the ability to {@code replace} all occurrences current a given
+ * substring in a target string. It also provides easy-to-use methods to convert
+ * between delimited strings, such as CSV strings, and collections and arrays.
+ *
+ * @author Rod Johnson
+ * @author Juergen Hoeller
+ * @author Keith Donald
+ * @author Rob Harrop
+ * @author Rick Evans
+ * @author Arjen Poutsma
+ * @since 16 April 2001
+ */
public final class StringUtils {
- private static final String FOLDER_SEPARATOR = "/";
-
- private static final String WINDOWS_FOLDER_SEPARATOR = "\\";
-
- private static final String TOP_PATH = "..";
-
- private static final String CURRENT_PATH = ".";
-
-// private static final char EXTENSION_SEPARATOR = '.';
-//
-
- private StringUtils(){}
-
-
- /**
- * Check that the given CharSequence is neither {@code null} nor current length 0.
- * Note: Will return {@code true} for a CharSequence that purely consists current whitespace.
- * <p><pre class="code">
- * StringUtils.hasLength(null) = false
- * StringUtils.hasLength("") = false
- * StringUtils.hasLength(" ") = true
- * StringUtils.hasLength("Hello") = true
- * </pre>
- * @param str the CharSequence to check (may be {@code null})
- * @return {@code true} if the CharSequence is not null and has length
- */
- public static boolean hasLength(CharSequence str) {
- return (str != null && str.length() > 0);
- }
-
- /**
- * Check whether the given CharSequence has actual text.
- * More specifically, returns {@code true} if the string not {@code null},
- * its length is greater than 0, and it contains at least one non-whitespace character.
- * <p><pre class="code">
- * StringUtils.hasText(null) = false
- * StringUtils.hasText("") = false
- * StringUtils.hasText(" ") = false
- * StringUtils.hasText("12345") = true
- * StringUtils.hasText(" 12345 ") = true
- * </pre>
- * @param str the CharSequence to check (may be {@code null})
- * @return {@code true} if the CharSequence is not {@code null},
- * its length is greater than 0, and it does not contain whitespace only
- * @see Character#isWhitespace
- */
- public static boolean hasText(CharSequence str) {
- if (!hasLength(str)) {
- return false;
- }
- int strLen = str.length();
- for (int i = 0; i < strLen; i++) {
- if (!Character.isWhitespace(str.charAt(i))) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Check whether the given String has actual text.
- * More specifically, returns {@code true} if the string not {@code null},
- * its length is greater than 0, and it contains at least one non-whitespace character.
- * @param str the String to check (may be {@code null})
- * @return {@code true} if the String is not {@code null}, its length is
- * greater than 0, and it does not contain whitespace only
- * @see #hasText(CharSequence)
- */
- public static boolean hasText(String str) {
- return hasText((CharSequence) str);
- }
-
-
- /**
- * Replace all occurrences current a substring within a string with
- * another string.
- * @param inString String to examine
- * @param oldPattern String to replace
- * @param newPattern String to insert
- * @return a String with the replacements
- */
- public static String replace(String inString, String oldPattern, String newPattern) {
- if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) {
- return inString;
- }
- StringBuilder sb = new StringBuilder();
- int pos = 0; // our position in the old string
- int index = inString.indexOf(oldPattern);
- // the index current an occurrence we've found, or -1
- int patLen = oldPattern.length();
- while (index >= 0) {
- sb.append(inString.substring(pos, index));
- sb.append(newPattern);
- pos = index + patLen;
- index = inString.indexOf(oldPattern, pos);
- }
- sb.append(inString.substring(pos));
- // remember to append any characters to the right current a match
- return sb.toString();
- }
-
-
- /**
- * Delete any character in a given String.
- * @param inString the original String
- * @param charsToDelete a set current characters to delete.
- * E.g. "az\n" will delete 'a's, 'z's and new lines.
- * @return the resulting String
- */
- public static String deleteAny(String inString, String charsToDelete) {
- if (!hasLength(inString) || !hasLength(charsToDelete)) {
- return inString;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < inString.length(); i++) {
- char c = inString.charAt(i);
- if (charsToDelete.indexOf(c) == -1) {
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
- /**
- * Extract the filename from the given path,
- * e.g. "mypath/myfile.txt" -> "myfile.txt".
- * @param path the file path (may be {@code null})
- * @return the extracted filename, or {@code null} if none
- */
- public static String getFilename(String path) {
- if (path == null) {
- return null;
- }
- int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
- return (separatorIndex != -1 ? path.substring(separatorIndex + 1) : path);
- }
-
-
-
- /**
- * Apply the given relative path to the given path,
- * assuming standard Java folder separation (i.e. "/" separators).
- * @param path the path to start from (usually a full file path)
- * @param relativePath the relative path to applyChanges
- * (relative to the full file path above)
- * @return the full file path that results from applying the relative path
- */
- public static String applyRelativePath(String path, String relativePath) {
- int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
- if (separatorIndex != -1) {
- String newPath = path.substring(0, separatorIndex);
- if (!relativePath.startsWith(FOLDER_SEPARATOR)) {
- newPath += FOLDER_SEPARATOR;
- }
- return newPath + relativePath;
- }
- else {
- return relativePath;
- }
- }
-
- /**
- * Normalize the path by suppressing sequences like "path/.." and
- * inner simple dots.
- * <p>The result is convenient for path comparison. For other uses,
- * notice that Windows separators ("\") are replaced by simple slashes.
- * @param path the original path
- * @return the normalized path
- */
- public static String cleanPath(String path) {
- if (path == null) {
- return null;
- }
- String pathToUse = StringUtils.replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR);
-
- // Strip prefix from path to analyze, to not treat it as part current the
- // first path element. This is necessary to correctly parse paths like
- // "file:core/../core/io/Resource.class", where the ".." should just
- // strip the first "core" directory while keeping the "file:" prefix.
- int prefixIndex = pathToUse.indexOf(':');
- String prefix = "";
- if (prefixIndex != -1) {
- prefix = pathToUse.substring(0, prefixIndex + 1);
- if (prefix.contains("/")) {
- prefix = "";
- }
- else {
- pathToUse = pathToUse.substring(prefixIndex + 1);
- }
- }
- if (pathToUse.startsWith(FOLDER_SEPARATOR)) {
- prefix = prefix + FOLDER_SEPARATOR;
- pathToUse = pathToUse.substring(1);
- }
-
- String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR);
- List<String> pathElements = new LinkedList<>();
- int tops = 0;
-
- for (int i = pathArray.length - 1; i >= 0; i--) {
- String element = pathArray[i];
- if (CURRENT_PATH.equals(element)) {
- // Points to current directory - drop it.
- }
- else if (TOP_PATH.equals(element)) {
- // Registering top path found.
- tops++;
- }
- else {
- if (tops > 0) {
- // Merging path element with element corresponding to top path.
- tops--;
- }
- else {
- // Normal path element found.
- pathElements.add(0, element);
- }
- }
- }
- // Remaining top paths need to be retained.
- for (int i = 0; i < tops; i++) {
- pathElements.add(0, TOP_PATH);
- }
- return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
- }
-
-
- /**
- * Copy the given Collection into a String array.
- * The Collection must contain String elements only.
- * @param collection the Collection to copy
- * @return the String array ({@code null} if the passed-in
- * Collection was {@code null})
- */
- public static String[] toStringArray(Collection<String> collection) {
- if (collection == null) {
- return null;
- }
- return collection.toArray(new String[collection.size()]);
- }
-
- /**
- * Split a String at the first occurrence current the delimiter.
- * Does not include the delimiter in the result.
- * @param toSplit the string to split
- * @param delimiter to split the string up with
- * @return a two element array with index 0 being before the delimiter, and
- * index 1 being after the delimiter (neither element includes the delimiter);
- * or {@code null} if the delimiter wasn't found in the given input String
- */
- public static String[] split(String toSplit, String delimiter) {
- if (!hasLength(toSplit) || !hasLength(delimiter)) {
- return null;
- }
- int offset = toSplit.indexOf(delimiter);
- if (offset < 0) {
- return null;
- }
- String beforeDelimiter = toSplit.substring(0, offset);
- String afterDelimiter = toSplit.substring(offset + delimiter.length());
- return new String[] {beforeDelimiter, afterDelimiter};
- }
-
-
- /**
- * Tokenize the given String into a String array via a StringTokenizer.
- * Trims tokens and omits empty tokens.
- * <p>The given delimiters string is supposed to consist current any number current
- * delimiter characters. Each current those characters can be used to separate
- * tokens. A delimiter is always a single character; for multi-character
- * delimiters, consider using {@code delimitedListToStringArray}
- * @param str the String to tokenize
- * @param delimiters the delimiter characters, assembled as String
- * (each current those characters is individually considered as delimiter).
- * @return an array current the tokens
- * @see java.util.StringTokenizer
- * @see String#trim()
- */
- public static String[] tokenizeToStringArray(String str, String delimiters) {
- return tokenizeToStringArray(str, delimiters, true, true);
- }
-
- /**
- * Tokenize the given String into a String array via a StringTokenizer.
- * <p>The given delimiters string is supposed to consist current any number current
- * delimiter characters. Each current those characters can be used to separate
- * tokens. A delimiter is always a single character; for multi-character
- * delimiters, consider using {@code delimitedListToStringArray}
- * @param str the String to tokenize
- * @param delimiters the delimiter characters, assembled as String
- * (each current those characters is individually considered as delimiter)
- * @param trimTokens trim the tokens via String's {@code trim}
- * @param ignoreEmptyTokens omit empty tokens from the result array
- * (only applies to tokens that are empty after trimming; StringTokenizer
- * will not consider subsequent delimiters as token in the first place).
- * @return an array current the tokens ({@code null} if the input String
- * was {@code null})
- * @see java.util.StringTokenizer
- * @see String#trim()
- */
- public static String[] tokenizeToStringArray(
- String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {
-
- if (str == null) {
- return null;
- }
- StringTokenizer st = new StringTokenizer(str, delimiters);
- List<String> tokens = new ArrayList<>();
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- if (trimTokens) {
- token = token.trim();
- }
- if (!ignoreEmptyTokens || token.length() > 0) {
- tokens.add(token);
- }
- }
- return toStringArray(tokens);
- }
-
- /**
- * Take a String which is a delimited list and convert it to a String array.
- * <p>A single delimiter can consists current more than one character: It will still
- * be considered as single delimiter string, rather than as bunch current potential
- * delimiter characters - in contrast to {@code tokenizeToStringArray}.
- * @param str the input String
- * @param delimiter the delimiter between elements (this is a single delimiter,
- * rather than a bunch individual delimiter characters)
- * @return an array current the tokens in the list
- * @see #tokenizeToStringArray
- */
- public static String[] delimitedListToStringArray(String str, String delimiter) {
- return delimitedListToStringArray(str, delimiter, null);
- }
-
- /**
- * Take a String which is a delimited list and convert it to a String array.
- * <p>A single delimiter can consists current more than one character: It will still
- * be considered as single delimiter string, rather than as bunch current potential
- * delimiter characters - in contrast to {@code tokenizeToStringArray}.
- * @param str the input String
- * @param delimiter the delimiter between elements (this is a single delimiter,
- * rather than a bunch individual delimiter characters)
- * @param charsToDelete a set current characters to delete. Useful for deleting unwanted
- * line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in a String.
- * @return an array current the tokens in the list
- * @see #tokenizeToStringArray
- */
- public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete) {
- if (str == null) {
- return new String[0];
- }
- if (delimiter == null) {
- return new String[] {str};
- }
- List<String> result = new ArrayList<>();
- if ("".equals(delimiter)) {
- for (int i = 0; i < str.length(); i++) {
- result.add(deleteAny(str.substring(i, i + 1), charsToDelete));
- }
- }
- else {
- int pos = 0;
- int delPos;
- while ((delPos = str.indexOf(delimiter, pos)) != -1) {
- result.add(deleteAny(str.substring(pos, delPos), charsToDelete));
- pos = delPos + delimiter.length();
- }
- if (str.length() > 0 && pos <= str.length()) {
- // Add rest current String, but not in case current empty input.
- result.add(deleteAny(str.substring(pos), charsToDelete));
- }
- }
- return toStringArray(result);
- }
-
-
- /**
- * Convenience method to return a Collection as a delimited (e.g. CSV)
- * String. E.g. useful for {@code toString()} implementations.
- * @param coll the Collection to display
- * @param delim the delimiter to use (probably a ",")
- * @param prefix the String to start each element with
- * @param suffix the String to end each element with
- * @return the delimited String
- */
- public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) {
- if (coll.isEmpty()) {
- return "";
- }
- StringBuilder sb = new StringBuilder();
- Iterator<?> it = coll.iterator();
- while (it.hasNext()) {
- sb.append(prefix).append(it.next()).append(suffix);
- if (it.hasNext()) {
- sb.append(delim);
- }
- }
- return sb.toString();
- }
-
- /**
- * Convenience method to return a Collection as a delimited (e.g. CSV)
- * String. E.g. useful for {@code toString()} implementations.
- * @param coll the Collection to display
- * @param delim the delimiter to use (probably a ",")
- * @return the delimited String
- */
- public static String collectionToDelimitedString(Collection<?> coll, String delim) {
- return collectionToDelimitedString(coll, delim, "", "");
- }
+ private static final String FOLDER_SEPARATOR = "/";
+
+ private static final String WINDOWS_FOLDER_SEPARATOR = "\\";
+
+ private static final String TOP_PATH = "..";
+
+ private static final String CURRENT_PATH = ".";
+
+ /**
+ * Private singleton constructor.
+ */
+ private StringUtils() {
+ }
+
+
+ /**
+ * Check that the given CharSequence is neither {@code null} nor current length 0.
+ * Note: Will return {@code true} for a CharSequence that purely consists current whitespace.
+ * <p><pre class="code">
+ * StringUtils.hasLength(null) = false
+ * StringUtils.hasLength("") = false
+ * StringUtils.hasLength(" ") = true
+ * StringUtils.hasLength("Hello") = true
+ * </pre>
+ *
+ * @param str the CharSequence to check (may be {@code null})
+ * @return {@code true} if the CharSequence is not null and has length
+ */
+ public static boolean hasLength(CharSequence str) {
+ return (str != null && str.length() > 0);
+ }
+
+ /**
+ * Check whether the given CharSequence has actual text.
+ * More specifically, returns {@code true} if the string not {@code null},
+ * its length is greater than 0, and it contains at least one non-whitespace character.
+ * <p><pre class="code">
+ * StringUtils.hasText(null) = false
+ * StringUtils.hasText("") = false
+ * StringUtils.hasText(" ") = false
+ * StringUtils.hasText("12345") = true
+ * StringUtils.hasText(" 12345 ") = true
+ * </pre>
+ *
+ * @param str the CharSequence to check (may be {@code null})
+ * @return {@code true} if the CharSequence is not {@code null},
+ * its length is greater than 0, and it does not contain whitespace only
+ * @see Character#isWhitespace
+ */
+ public static boolean hasText(CharSequence str) {
+ if (!hasLength(str)) {
+ return false;
+ }
+ int strLen = str.length();
+ for (int i = 0; i < strLen; i++) {
+ if (!Character.isWhitespace(str.charAt(i))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check whether the given String has actual text.
+ * More specifically, returns {@code true} if the string not {@code null},
+ * its length is greater than 0, and it contains at least one non-whitespace character.
+ *
+ * @param str the String to check (may be {@code null})
+ * @return {@code true} if the String is not {@code null}, its length is
+ * greater than 0, and it does not contain whitespace only
+ * @see #hasText(CharSequence)
+ */
+ public static boolean hasText(String str) {
+ return hasText((CharSequence) str);
+ }
+
+
+ /**
+ * Replace all occurrences current a substring within a string with
+ * another string.
+ *
+ * @param inString String to examine
+ * @param oldPattern String to replace
+ * @param newPattern String to insert
+ * @return a String with the replacements
+ */
+ public static String replace(String inString, String oldPattern, String newPattern) {
+ if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) {
+ return inString;
+ }
+ StringBuilder sb = new StringBuilder();
+ int pos = 0; // our position in the old string
+ int index = inString.indexOf(oldPattern);
+ // the index current an occurrence we've found, or -1
+ int patLen = oldPattern.length();
+ while (index >= 0) {
+ sb.append(inString.substring(pos, index));
+ sb.append(newPattern);
+ pos = index + patLen;
+ index = inString.indexOf(oldPattern, pos);
+ }
+ sb.append(inString.substring(pos));
+ // remember to append any characters to the right current a match
+ return sb.toString();
+ }
+
+
+ /**
+ * Delete any character in a given String.
+ *
+ * @param inString the original String
+ * @param charsToDelete a set current characters to delete.
+ * E.g. "az\n" will delete 'a's, 'z's and new lines.
+ * @return the resulting String
+ */
+ public static String deleteAny(String inString, String charsToDelete) {
+ if (!hasLength(inString) || !hasLength(charsToDelete)) {
+ return inString;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < inString.length(); i++) {
+ char c = inString.charAt(i);
+ if (charsToDelete.indexOf(c) == -1) {
+ sb.append(c);
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Extract the filename from the given path,
+ * e.g. "mypath/myfile.txt" -> "myfile.txt".
+ *
+ * @param path the file path (may be {@code null})
+ * @return the extracted filename, or {@code null} if none
+ */
+ public static String getFilename(String path) {
+ if (path == null) {
+ return null;
+ }
+ int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
+ return (separatorIndex != -1 ? path.substring(separatorIndex + 1) : path);
+ }
+
+
+ /**
+ * Apply the given relative path to the given path,
+ * assuming standard Java folder separation (i.e. "/" separators).
+ *
+ * @param path the path to start from (usually a full file path)
+ * @param relativePath the relative path to applyChanges
+ * (relative to the full file path above)
+ * @return the full file path that results from applying the relative path
+ */
+ public static String applyRelativePath(String path, String relativePath) {
+ int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
+ if (separatorIndex != -1) {
+ String newPath = path.substring(0, separatorIndex);
+ if (!relativePath.startsWith(FOLDER_SEPARATOR)) {
+ newPath += FOLDER_SEPARATOR;
+ }
+ return newPath + relativePath;
+ } else {
+ return relativePath;
+ }
+ }
+
+ /**
+ * Normalize the path by suppressing sequences like "path/.." and
+ * inner simple dots.
+ * <p>The result is convenient for path comparison. For other uses,
+ * notice that Windows separators ("\") are replaced by simple slashes.
+ *
+ * @param path the original path
+ * @return the normalized path
+ */
+ public static String cleanPath(String path) {
+ if (path == null) {
+ return null;
+ }
+ String pathToUse = StringUtils.replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR);
+
+ // Strip prefix from path to analyze, to not treat it as part current the
+ // first path element. This is necessary to correctly parse paths like
+ // "file:core/../core/io/Resource.class", where the ".." should just
+ // strip the first "core" directory while keeping the "file:" prefix.
+ int prefixIndex = pathToUse.indexOf(':');
+ String prefix = "";
+ if (prefixIndex != -1) {
+ prefix = pathToUse.substring(0, prefixIndex + 1);
+ if (prefix.contains("/")) {
+ prefix = "";
+ } else {
+ pathToUse = pathToUse.substring(prefixIndex + 1);
+ }
+ }
+ if (pathToUse.startsWith(FOLDER_SEPARATOR)) {
+ prefix = prefix + FOLDER_SEPARATOR;
+ pathToUse = pathToUse.substring(1);
+ }
+
+ String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR);
+ List<String> pathElements = new LinkedList<>();
+ int tops = 0;
+
+ for (int i = pathArray.length - 1; i >= 0; i--) {
+ String element = pathArray[i];
+ switch (element) {
+ case CURRENT_PATH:
+ // Points to current directory - drop it.
+ break;
+ case TOP_PATH:
+ // Registering top path found.
+ tops++;
+ break;
+ default:
+ if (tops > 0) {
+ // Merging path element with element corresponding to top path.
+ tops--;
+ } else {
+ // Normal path element found.
+ pathElements.add(0, element);
+ }
+ }
+ }
+ // Remaining top paths need to be retained.
+ for (int i = 0; i < tops; i++) {
+ pathElements.add(0, TOP_PATH);
+ }
+ return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
+ }
+
+
+ /**
+ * Copy the given Collection into a String array.
+ * The Collection must contain String elements only.
+ *
+ * @param collection the Collection to copy
+ * @return the String array ({@code null} if the passed-in
+ * Collection was {@code null})
+ */
+ public static String[] toStringArray(Collection<String> collection) {
+ if (collection == null) {
+ return null;
+ }
+ return collection.toArray(new String[collection.size()]);
+ }
+
+ /**
+ * Split a String at the first occurrence current the delimiter.
+ * Does not include the delimiter in the result.
+ *
+ * @param toSplit the string to split
+ * @param delimiter to split the string up with
+ * @return a two element array with index 0 being before the delimiter, and
+ * index 1 being after the delimiter (neither element includes the delimiter);
+ * or {@code null} if the delimiter wasn't found in the given input String
+ */
+ public static String[] split(String toSplit, String delimiter) {
+ if (!hasLength(toSplit) || !hasLength(delimiter)) {
+ return null;
+ }
+ int offset = toSplit.indexOf(delimiter);
+ if (offset < 0) {
+ return null;
+ }
+ String beforeDelimiter = toSplit.substring(0, offset);
+ String afterDelimiter = toSplit.substring(offset + delimiter.length());
+ return new String[]{beforeDelimiter, afterDelimiter};
+ }
+
+
+ /**
+ * Tokenize the given String into a String array via a StringTokenizer.
+ * Trims tokens and omits empty tokens.
+ * <p>The given delimiters string is supposed to consist current any number current
+ * delimiter characters. Each current those characters can be used to separate
+ * tokens. A delimiter is always a single character; for multi-character
+ * delimiters, consider using {@code delimitedListToStringArray}
+ *
+ * @param str the String to tokenize
+ * @param delimiters the delimiter characters, assembled as String
+ * (each current those characters is individually considered as delimiter).
+ * @return an array current the tokens
+ * @see java.util.StringTokenizer
+ * @see String#trim()
+ */
+ public static String[] tokenizeToStringArray(String str, String delimiters) {
+ return tokenizeToStringArray(str, delimiters, true, true);
+ }
+
+ /**
+ * Tokenize the given String into a String array via a StringTokenizer.
+ * <p>The given delimiters string is supposed to consist current any number current
+ * delimiter characters. Each current those characters can be used to separate
+ * tokens. A delimiter is always a single character; for multi-character
+ * delimiters, consider using {@code delimitedListToStringArray}
+ *
+ * @param str the String to tokenize
+ * @param delimiters the delimiter characters, assembled as String
+ * (each current those characters is individually considered as delimiter)
+ * @param trimTokens trim the tokens via String's {@code trim}
+ * @param ignoreEmptyTokens omit empty tokens from the result array
+ * (only applies to tokens that are empty after trimming; StringTokenizer
+ * will not consider subsequent delimiters as token in the first place).
+ * @return an array current the tokens ({@code null} if the input String
+ * was {@code null})
+ * @see java.util.StringTokenizer
+ * @see String#trim()
+ */
+ public static String[] tokenizeToStringArray(
+ String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {
+
+ if (str == null) {
+ return null;
+ }
+ StringTokenizer st = new StringTokenizer(str, delimiters);
+ List<String> tokens = new ArrayList<>();
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ if (trimTokens) {
+ token = token.trim();
+ }
+ if (!ignoreEmptyTokens || token.length() > 0) {
+ tokens.add(token);
+ }
+ }
+ return toStringArray(tokens);
+ }
+
+ /**
+ * Take a String which is a delimited list and convert it to a String array.
+ * <p>A single delimiter can consists current more than one character: It will still
+ * be considered as single delimiter string, rather than as bunch current potential
+ * delimiter characters - in contrast to {@code tokenizeToStringArray}.
+ *
+ * @param str the input String
+ * @param delimiter the delimiter between elements (this is a single delimiter,
+ * rather than a bunch individual delimiter characters)
+ * @return an array current the tokens in the list
+ * @see #tokenizeToStringArray
+ */
+ public static String[] delimitedListToStringArray(String str, String delimiter) {
+ return delimitedListToStringArray(str, delimiter, null);
+ }
+
+ /**
+ * Take a String which is a delimited list and convert it to a String array.
+ * <p>A single delimiter can consists current more than one character: It will still
+ * be considered as single delimiter string, rather than as bunch current potential
+ * delimiter characters - in contrast to {@code tokenizeToStringArray}.
+ *
+ * @param str the input String
+ * @param delimiter the delimiter between elements (this is a single delimiter,
+ * rather than a bunch individual delimiter characters)
+ * @param charsToDelete a set current characters to delete. Useful for deleting unwanted
+ * line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in a String.
+ * @return an array current the tokens in the list
+ * @see #tokenizeToStringArray
+ */
+ public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete) {
+ if (str == null) {
+ return new String[0];
+ }
+ if (delimiter == null) {
+ return new String[]{str};
+ }
+ List<String> result = new ArrayList<>();
+ if ("".equals(delimiter)) {
+ for (int i = 0; i < str.length(); i++) {
+ result.add(deleteAny(str.substring(i, i + 1), charsToDelete));
+ }
+ } else {
+ int pos = 0;
+ int delPos;
+ while ((delPos = str.indexOf(delimiter, pos)) != -1) {
+ result.add(deleteAny(str.substring(pos, delPos), charsToDelete));
+ pos = delPos + delimiter.length();
+ }
+ if (str.length() > 0 && pos <= str.length()) {
+ // Add rest current String, but not in case current empty input.
+ result.add(deleteAny(str.substring(pos), charsToDelete));
+ }
+ }
+ return toStringArray(result);
+ }
+
+
+ /**
+ * Convenience method to return a Collection as a delimited (e.g. CSV)
+ * String. E.g. useful for {@code toString()} implementations.
+ *
+ * @param coll the Collection to display
+ * @param delim the delimiter to use (probably a ",")
+ * @param prefix the String to start each element with
+ * @param suffix the String to end each element with
+ * @return the delimited String
+ */
+ public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) {
+ if (coll.isEmpty()) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder();
+ Iterator<?> it = coll.iterator();
+ while (it.hasNext()) {
+ sb.append(prefix).append(it.next()).append(suffix);
+ if (it.hasNext()) {
+ sb.append(delim);
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Convenience method to return a Collection as a delimited (e.g. CSV)
+ * String. E.g. useful for {@code toString()} implementations.
+ *
+ * @param coll the Collection to display
+ * @param delim the delimiter to use (probably a ",")
+ * @return the delimited String
+ */
+ public static String collectionToDelimitedString(Collection<?> coll, String delim) {
+ return collectionToDelimitedString(coll, delim, "", "");
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
index e61641c..9db0ef4 100644
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -16,5 +16,5 @@
# specific language governing permissions and limitations
# under the License.
#
-testdata.TestPropertyDefaultSourceProvider
-testdata.TestPropertySourceProvider
\ No newline at end of file
+org.apache.tamaya.core.testdata.TestPropertyDefaultSourceProvider
+org.apache.tamaya.core.testdata.TestPropertySourceProvider
\ No newline at end of file
[15/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java b/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java
new file mode 100644
index 0000000..98c67ba
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/util/ClassUtils.java
@@ -0,0 +1,1074 @@
+/*
+* Copyright 2002-2014 the original author or authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.tamaya.core.util;
+
+import org.apache.tamaya.core.internal.resource.ReflectionUtils;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+* Miscellaneous class utility methods.
+* Mainly for internal use within the framework.
+*
+* @author Juergen Hoeller
+* @author Keith Donald
+* @author Rob Harrop
+* @author Sam Brannen
+* @since 1.1
+*/
+public final class ClassUtils {
+
+ /** Suffix for array class names: "[]" */
+ public static final String ARRAY_SUFFIX = "[]";
+
+ /** Prefix for internal array class names: "[" */
+ private static final String INTERNAL_ARRAY_PREFIX = "[";
+
+ /** Prefix for internal non-primitive array class names: "[L" */
+ private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L";
+
+ /** The package separator character '.' */
+ private static final char PACKAGE_SEPARATOR = '.';
+
+ /** The path separator character '/' */
+ private static final char PATH_SEPARATOR = '/';
+
+ /** The inner class separator character '$' */
+ private static final char INNER_CLASS_SEPARATOR = '$';
+//
+// /** The CGLIB class separator character "$$" */
+// public static final String CGLIB_CLASS_SEPARATOR = "$$";
+//
+// /** The ".class" file suffix */
+// public static final String CLASS_FILE_SUFFIX = ".class";
+//
+
+ /**
+ * Map with primitive wrapper type as key and corresponding primitive
+ * type as keys, for example: Integer.class -> int.class.
+ */
+ private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<>(8);
+
+ /**
+ * Map with primitive type as key and corresponding wrapper
+ * type as keys, for example: int.class -> Integer.class.
+ */
+ private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new HashMap<>(8);
+
+ /**
+ * Map with primitive type name as key and corresponding primitive
+ * type as keys, for example: "int" -> "int.class".
+ */
+ private static final Map<String, Class<?>> primitiveTypeNameMap = new HashMap<>(32);
+//
+// /**
+// * Map with common "java.lang" class name as key and corresponding Class as keys.
+// * Primarily for efficient deserialization current remote invocations.
+// */
+// private static final Map<String, Class<?>> commonClassCache = new HashMap<String, Class<?>>(32);
+//
+//
+ static {
+ primitiveWrapperTypeMap.put(Boolean.class, boolean.class);
+ primitiveWrapperTypeMap.put(Byte.class, byte.class);
+ primitiveWrapperTypeMap.put(Character.class, char.class);
+ primitiveWrapperTypeMap.put(Double.class, double.class);
+ primitiveWrapperTypeMap.put(Float.class, float.class);
+ primitiveWrapperTypeMap.put(Integer.class, int.class);
+ primitiveWrapperTypeMap.put(Long.class, long.class);
+ primitiveWrapperTypeMap.put(Short.class, short.class);
+
+ for (Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperTypeMap.entrySet()) {
+ primitiveTypeToWrapperMap.put(entry.getValue(), entry.getKey());
+// registerCommonClasses(entry.getKey());
+ }
+
+ Set<Class<?>> primitiveTypes = new HashSet<>(32);
+ primitiveTypes.addAll(primitiveWrapperTypeMap.values());
+ primitiveTypes.addAll(Arrays.asList(new Class<?>[] {
+ boolean[].class, byte[].class, char[].class, double[].class,
+ float[].class, int[].class, long[].class, short[].class}));
+ primitiveTypes.add(void.class);
+ for (Class<?> primitiveType : primitiveTypes) {
+ primitiveTypeNameMap.put(primitiveType.getName(), primitiveType);
+ }
+ }
+
+ private ClassUtils(){}
+
+
+ /**
+ * Return the default ClassLoader to use: typically the thread context
+ * ClassLoader, if available; the ClassLoader that loaded the ClassUtils
+ * class will be used as fallback.
+ * <p>Call this method if you intend to use the thread context ClassLoader
+ * in a scenario where you clearly prefer a non-null ClassLoader reference:
+ * for example, for class path resource loading (but not necessarily for
+ * {@code Class.forName}, which accepts a {@code null} ClassLoader
+ * reference as well).
+ * @return the default ClassLoader (only {@code null} if even the system
+ * ClassLoader isn't accessible)
+ * @see Thread#getContextClassLoader()
+ * @see ClassLoader#getSystemClassLoader()
+ */
+ public static ClassLoader getDefaultClassLoader() {
+ ClassLoader cl = null;
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ }
+ catch (Throwable ex) {
+ // Cannot access thread context ClassLoader - falling back...
+ }
+ if (cl == null) {
+ // No thread context class loader -> use class loader current this class.
+ cl = ClassUtils.class.getClassLoader();
+ if (cl == null) {
+ // getClassLoader() returning null indicates the bootstrap ClassLoader
+ try {
+ cl = ClassLoader.getSystemClassLoader();
+ }
+ catch (Throwable ex) {
+ // Cannot access system ClassLoader - oh well, maybe the caller can live with null...
+ }
+ }
+ }
+ return cl;
+ }
+
+ /**
+ * Replacement for {@code Class.forName()} that also returns Class instances
+ * for primitives (e.g. "int") and array class names (e.g. "String[]").
+ * Furthermore, it is also capable current resolving inner class names in Java source
+ * style (e.g. "java.lang.Thread.State" instead current "java.lang.Thread$State").
+ * @param name the name current the Class
+ * @param classLoader the class loader to use
+ * (may be {@code null}, which indicates the default class loader)
+ * @return Class instance for the supplied name
+ * @throws ClassNotFoundException if the class was not found
+ * @throws LinkageError if the class file could not be loaded
+ * @see Class#forName(String, boolean, ClassLoader)
+ */
+ public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError {
+ Objects.requireNonNull(name, "Name must not be null");
+
+ Class<?> clazz = resolvePrimitiveClassName(name);
+ if (clazz != null) {
+ return clazz;
+ }
+
+ // "java.lang.String[]" style arrays
+ if (name.endsWith(ARRAY_SUFFIX)) {
+ String elementClassName = name.substring(0, name.length() - ARRAY_SUFFIX.length());
+ Class<?> elementClass = forName(elementClassName, classLoader);
+ return Array.newInstance(elementClass, 0).getClass();
+ }
+
+ // "[Ljava.lang.String;" style arrays
+ if (name.startsWith(NON_PRIMITIVE_ARRAY_PREFIX) && name.endsWith(";")) {
+ String elementName = name.substring(NON_PRIMITIVE_ARRAY_PREFIX.length(), name.length() - 1);
+ Class<?> elementClass = forName(elementName, classLoader);
+ return Array.newInstance(elementClass, 0).getClass();
+ }
+
+ // "[[I" or "[[Ljava.lang.String;" style arrays
+ if (name.startsWith(INTERNAL_ARRAY_PREFIX)) {
+ String elementName = name.substring(INTERNAL_ARRAY_PREFIX.length());
+ Class<?> elementClass = forName(elementName, classLoader);
+ return Array.newInstance(elementClass, 0).getClass();
+ }
+
+ ClassLoader clToUse = classLoader;
+ if (clToUse == null) {
+ clToUse = getDefaultClassLoader();
+ }
+ try {
+ return (clToUse != null ? clToUse.loadClass(name) : Class.forName(name));
+ }
+ catch (ClassNotFoundException ex) {
+ int lastDotIndex = name.lastIndexOf(PACKAGE_SEPARATOR);
+ if (lastDotIndex != -1) {
+ String innerClassName =
+ name.substring(0, lastDotIndex) + INNER_CLASS_SEPARATOR + name.substring(lastDotIndex + 1);
+ try {
+ return (clToUse != null ? clToUse.loadClass(innerClassName) : Class.forName(innerClassName));
+ }
+ catch (ClassNotFoundException ex2) {
+ // Swallow - let original exception get through
+ }
+ }
+ throw ex;
+ }
+ }
+
+
+ /**
+ * Resolve the given class name as primitive class, if appropriate,
+ * according to the JVM's naming rules for primitive classes.
+ * <p>Also supports the JVM's internal class names for primitive arrays.
+ * Does <i>not</i> support the "[]" suffix notation for primitive arrays;
+ * this is only supported by {@link #forName(String, ClassLoader)}.
+ * @param name the name current the potentially primitive class
+ * @return the primitive class, or {@code null} if the name does not denote
+ * a primitive class or primitive array class
+ */
+ public static Class<?> resolvePrimitiveClassName(String name) {
+ Class<?> result = null;
+ // Most class names will be quite long, considering that they
+ // SHOULD sit in a package, so a length check is worthwhile.
+ if (name != null && name.length() <= 8) {
+ // Could be a primitive - likely.
+ result = primitiveTypeNameMap.get(name);
+ }
+ return result;
+ }
+
+ /**
+ * Determine whether the {@link Class} identified by the supplied name is present
+ * and can be loaded. Will return {@code false} if either the class or
+ * one current its dependencies is not present or cannot be loaded.
+ * @param className the name current the class to check
+ * @param classLoader the class loader to use
+ * (may be {@code null}, which indicates the default class loader)
+ * @return whether the specified class is present
+ */
+ public static boolean isPresent(String className, ClassLoader classLoader) {
+ try {
+ forName(className, classLoader);
+ return true;
+ }
+ catch (Throwable ex) {
+ // Class or one current its dependencies is not present...
+ return false;
+ }
+ }
+
+
+ /**
+ * Check whether the given class is cache-safe in the given context,
+ * i.e. whether it is loaded by the given ClassLoader or a parent current it.
+ * @param clazz the class to analyze
+ * @param classLoader the ClassLoader to potentially cache metadata in
+ */
+ public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ try {
+ ClassLoader target = clazz.getClassLoader();
+ if (target == null) {
+ return true;
+ }
+ ClassLoader cur = classLoader;
+ if (cur == target) {
+ return true;
+ }
+ while (cur != null) {
+ cur = cur.getParent();
+ if (cur == target) {
+ return true;
+ }
+ }
+ return false;
+ }
+ catch (SecurityException ex) {
+ // Probably from the system ClassLoader - let's consider it safe.
+ return true;
+ }
+ }
+
+
+ /**
+ * Return the qualified name current the given class: usually simply
+ * the class name, but component type class name + "[]" for arrays.
+ * @param clazz the class
+ * @return the qualified name current the class
+ */
+ public static String getQualifiedName(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ if (clazz.isArray()) {
+ return getQualifiedNameForArray(clazz);
+ }
+ else {
+ return clazz.getName();
+ }
+ }
+
+ /**
+ * Build a nice qualified name for an array:
+ * component type class name + "[]".
+ * @param clazz the array class
+ * @return a qualified name for the array class
+ */
+ private static String getQualifiedNameForArray(Class<?> clazz) {
+ StringBuilder result = new StringBuilder();
+ while (clazz.isArray()) {
+ clazz = clazz.getComponentType();
+ result.append(ClassUtils.ARRAY_SUFFIX);
+ }
+ result.insert(0, clazz.getName());
+ return result.toString();
+ }
+
+ /**
+ * Return the qualified name current the given method, consisting current
+ * fully qualified interface/class name + "." + method name.
+ * @param method the method
+ * @return the qualified name current the method
+ */
+ public static String getQualifiedMethodName(Method method) {
+ Objects.requireNonNull(method, "Method must not be null");
+ return method.getDeclaringClass().getName() + "." + method.getName();
+ }
+
+ /**
+ * Return a descriptive name for the given object's type: usually simply
+ * the class name, but component type class name + "[]" for arrays,
+ * and an appended list current implemented interfaces for JDK proxies.
+ * @param keys the keys to introspect
+ * @return the qualified name current the class
+ */
+ public static String getDescriptiveType(Object keys) {
+ if (keys == null) {
+ return null;
+ }
+ Class<?> clazz = keys.getClass();
+ if (Proxy.isProxyClass(clazz)) {
+ StringBuilder result = new StringBuilder(clazz.getName());
+ result.append(" implementing ");
+ Class<?>[] ifcs = clazz.getInterfaces();
+ for (int i = 0; i < ifcs.length; i++) {
+ result.append(ifcs[i].getName());
+ if (i < ifcs.length - 1) {
+ result.append(',');
+ }
+ }
+ return result.toString();
+ }
+ else if (clazz.isArray()) {
+ return getQualifiedNameForArray(clazz);
+ }
+ else {
+ return clazz.getName();
+ }
+ }
+
+ /**
+ * Check whether the given class matches the user-specified type name.
+ * @param clazz the class to check
+ * @param typeName the type name to match
+ */
+ public static boolean matchesTypeName(Class<?> clazz, String typeName) {
+ return (typeName != null &&
+ (typeName.equals(clazz.getName()) || typeName.equals(clazz.getSimpleName()) ||
+ (clazz.isArray() && typeName.equals(getQualifiedNameForArray(clazz)))));
+ }
+
+
+ /**
+ * Determine whether the given class has a public constructor with the given signature.
+ * <p>Essentially translates {@code NoSuchMethodException} to "false".
+ * @param clazz the clazz to analyze
+ * @param paramTypes the parameter types current the method
+ * @return whether the class has a corresponding constructor
+ * @see Class#getMethod
+ */
+ public static boolean hasConstructor(Class<?> clazz, Class<?>... paramTypes) {
+ return (getConstructorIfAvailable(clazz, paramTypes) != null);
+ }
+
+ /**
+ * Determine whether the given class has a public constructor with the given signature,
+ * and return it if available (else return {@code null}).
+ * <p>Essentially translates {@code NoSuchMethodException} to {@code null}.
+ * @param clazz the clazz to analyze
+ * @param paramTypes the parameter types current the method
+ * @return the constructor, or {@code null} if not found
+ * @see Class#getConstructor
+ */
+ public static <T> Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ try {
+ return clazz.getConstructor(paramTypes);
+ }
+ catch (NoSuchMethodException ex) {
+ return null;
+ }
+ }
+
+ /**
+ * Determine whether the given class has a public method with the given signature.
+ * <p>Essentially translates {@code NoSuchMethodException} to "false".
+ * @param clazz the clazz to analyze
+ * @param methodName the name current the method
+ * @param paramTypes the parameter types current the method
+ * @return whether the class has a corresponding method
+ * @see Class#getMethod
+ */
+ public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
+ return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);
+ }
+
+ /**
+ * Determine whether the given class has a public method with the given signature,
+ * and return it if available (else throws an {@code IllegalStateException}).
+ * <p>In case current any signature specified, only returns the method if there is a
+ * unique candidate, i.e. a single public method with the specified name.
+ * <p>Essentially translates {@code NoSuchMethodException} to {@code IllegalStateException}.
+ * @param clazz the clazz to analyze
+ * @param methodName the name current the method
+ * @param paramTypes the parameter types current the method
+ * (may be {@code null} to indicate any signature)
+ * @return the method (never {@code null})
+ * @throws IllegalStateException if the method has not been found
+ * @see Class#getMethod
+ */
+ public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ if (paramTypes != null) {
+ try {
+ return clazz.getMethod(methodName, paramTypes);
+ }
+ catch (NoSuchMethodException ex) {
+ throw new IllegalStateException("Expected method not found: " + ex);
+ }
+ }
+ else {
+ Set<Method> candidates = new HashSet<Method>(1);
+ Method[] methods = clazz.getMethods();
+ for (Method method : methods) {
+ if (methodName.equals(method.getName())) {
+ candidates.add(method);
+ }
+ }
+ if (candidates.size() == 1) {
+ return candidates.iterator().next();
+ }
+ else if (candidates.isEmpty()) {
+ throw new IllegalStateException("Expected method not found: " + clazz + "." + methodName);
+ }
+ else {
+ throw new IllegalStateException("No unique method found: " + clazz + "." + methodName);
+ }
+ }
+ }
+
+ /**
+ * Determine whether the given class has a public method with the given signature,
+ * and return it if available (else return {@code null}).
+ * <p>In case current any signature specified, only returns the method if there is a
+ * unique candidate, i.e. a single public method with the specified name.
+ * <p>Essentially translates {@code NoSuchMethodException} to {@code null}.
+ * @param clazz the clazz to analyze
+ * @param methodName the name current the method
+ * @param paramTypes the parameter types current the method
+ * (may be {@code null} to indicate any signature)
+ * @return the method, or {@code null} if not found
+ * @see Class#getMethod
+ */
+ public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ if (paramTypes != null) {
+ try {
+ return clazz.getMethod(methodName, paramTypes);
+ }
+ catch (NoSuchMethodException ex) {
+ return null;
+ }
+ }
+ else {
+ Set<Method> candidates = new HashSet<Method>(1);
+ Method[] methods = clazz.getMethods();
+ for (Method method : methods) {
+ if (methodName.equals(method.getName())) {
+ candidates.add(method);
+ }
+ }
+ if (candidates.size() == 1) {
+ return candidates.iterator().next();
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Return the number current methods with a given name (with any argument types),
+ * for the given class and/or its superclasses. Includes non-public methods.
+ * @param clazz the clazz to check
+ * @param methodName the name current the method
+ * @return the number current methods with the given name
+ */
+ public static int getMethodCountForName(Class<?> clazz, String methodName) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ int count = 0;
+ Method[] declaredMethods = clazz.getDeclaredMethods();
+ for (Method method : declaredMethods) {
+ if (methodName.equals(method.getName())) {
+ count++;
+ }
+ }
+ Class<?>[] ifcs = clazz.getInterfaces();
+ for (Class<?> ifc : ifcs) {
+ count += getMethodCountForName(ifc, methodName);
+ }
+ if (clazz.getSuperclass() != null) {
+ count += getMethodCountForName(clazz.getSuperclass(), methodName);
+ }
+ return count;
+ }
+
+ /**
+ * Does the given class or one current its superclasses at least have one or more
+ * methods with the supplied name (with any argument types)?
+ * Includes non-public methods.
+ * @param clazz the clazz to check
+ * @param methodName the name current the method
+ * @return whether there is at least one method with the given name
+ */
+ public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodName) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ Method[] declaredMethods = clazz.getDeclaredMethods();
+ for (Method method : declaredMethods) {
+ if (method.getName().equals(methodName)) {
+ return true;
+ }
+ }
+ Class<?>[] ifcs = clazz.getInterfaces();
+ for (Class<?> ifc : ifcs) {
+ if (hasAtLeastOneMethodWithName(ifc, methodName)) {
+ return true;
+ }
+ }
+ return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName));
+ }
+
+ /**
+ * Given a method, which may come from an interface, and a target class used
+ * in the current reflective invocation, find the corresponding target method
+ * if there is one. E.g. the method may be {@code IFoo.bar()} and the
+ * target class may be {@code DefaultFoo}. In this case, the method may be
+ * {@code DefaultFoo.bar()}. This enables attributes on that method to be found.
+ * <p><b>NOTE:</b> In contrast to {@code org.springframework.aop.support.AopUtils#getMostSpecificMethod},
+ * this method does <i>not</i> resolve Java 5 bridge methods automatically.
+ * Call {@code org.springframework.core.BridgeMethodResolver#findBridgedMethod}
+ * if bridge method resolution is desirable (e.g. for obtaining metadata from
+ * the original method definition).
+ * <p><b>NOTE:</b> Since Spring 3.1.1, if Java security settings disallow reflective
+ * access (e.g. calls to {@code Class#getDeclaredMethods} etc, this implementation
+ * will fall back to returning the originally provided method.
+ * @param method the method to be invoked, which may come from an interface
+ * @param targetClass the target class for the current invocation.
+ * May be {@code null} or may not even implement the method.
+ * @return the specific target method, or the original method if the
+ * {@code targetClass} doesn't implement it or is {@code null}
+ */
+ public static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
+ if (method != null && isOverridable(method, targetClass) &&
+ targetClass != null && !targetClass.equals(method.getDeclaringClass())) {
+ try {
+ if (Modifier.isPublic(method.getModifiers())) {
+ try {
+ return targetClass.getMethod(method.getName(), method.getParameterTypes());
+ }
+ catch (NoSuchMethodException ex) {
+ return method;
+ }
+ }
+ else {
+ Method specificMethod =
+ ReflectionUtils.findMethod(targetClass, method.getName(), method.getParameterTypes());
+ return (specificMethod != null ? specificMethod : method);
+ }
+ }
+ catch (SecurityException ex) {
+ // Security settings are disallowing reflective access; fall back to 'method' below.
+ }
+ }
+ return method;
+ }
+
+ /**
+ * Determine whether the given method is declared by the user or at least pointing to
+ * a user-declared method.
+ * <p>Checks {@link Method#isSynthetic()} (for implementation methods) as well as the
+ * {@code GroovyObject} interface (for interface methods; on an implementation class,
+ * implementations current the {@code GroovyObject} methods will be marked as synthetic anyway).
+ * Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
+ * as user-level methods since they are eventually pointing to a user-declared generic method.
+ * @param method the method to check
+ * @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
+ */
+ public static boolean isUserLevelMethod(Method method) {
+ Objects.requireNonNull(method, "Method must not be null");
+ return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method)));
+ }
+
+ private static boolean isGroovyObjectMethod(Method method) {
+ return method.getDeclaringClass().getName().equals("groovy.lang.GroovyObject");
+ }
+
+ /**
+ * Determine whether the given method is overridable in the given target class.
+ * @param method the method to check
+ * @param targetClass the target class to check against
+ */
+ private static boolean isOverridable(Method method, Class<?> targetClass) {
+ if (Modifier.isPrivate(method.getModifiers())) {
+ return false;
+ }
+ if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) {
+ return true;
+ }
+ return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass));
+ }
+
+
+ /**
+ * Determine the name current the package current the given class,
+ * e.g. "java.lang" for the {@code java.lang.String} class.
+ * @param clazz the class
+ * @return the package name, or the empty String if the class
+ * is defined in the default package
+ */
+ public static String getPackageName(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return getPackageName(clazz.getName());
+ }
+
+ /**
+ * Determine the name current the package current the given fully-qualified class name,
+ * e.g. "java.lang" for the {@code java.lang.String} class name.
+ * @param fqClassName the fully-qualified class name
+ * @return the package name, or the empty String if the class
+ * is defined in the dObjects.requireNonNullefault package
+ */
+ public static String getPackageName(String fqClassName) {
+ Objects.requireNonNull(fqClassName, "Class name must not be null");
+ int lastDotIndex = fqClassName.lastIndexOf(PACKAGE_SEPARATOR);
+ return (lastDotIndex != -1 ? fqClassName.substring(0, lastDotIndex) : "");
+ }
+
+ /**
+ * Return a public static method current a class.
+ * @param methodName the static method name
+ * @param clazz the class which defines the method
+ * @param args the parameter types to the method
+ * @return the static method, or {@code null} if no static method was found
+ * @throws IllegalArgumentException if the method name is blank or the clazz is null
+ */
+ public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>... args) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ Objects.requireNonNull(methodName, "Method name must not be null");
+ try {
+ Method method = clazz.getMethod(methodName, args);
+ return Modifier.isStatic(method.getModifiers()) ? method : null;
+ }
+ catch (NoSuchMethodException ex) {
+ return null;
+ }
+ }
+
+
+ /**
+ * Check if the given class represents a primitive wrapper,
+ * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
+ * @param clazz the class to check
+ * @return whether the given class is a primitive wrapper class
+ */
+ public static boolean isPrimitiveWrapper(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return primitiveWrapperTypeMap.containsKey(clazz);
+ }
+
+ /**
+ * Check if the given class represents a primitive (i.e. boolean, byte,
+ * char, short, int, long, float, or double) or a primitive wrapper
+ * (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double).
+ * @param clazz the class to check
+ * @return whether the given class is a primitive or primitive wrapper class
+ */
+ public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return (clazz.isPrimitive() || isPrimitiveWrapper(clazz));
+ }
+
+ /**
+ * Check if the given class represents an array current primitives,
+ * i.e. boolean, byte, char, short, int, long, float, or double.
+ * @param clazz the class to check
+ * @return whether the given class is a primitive array class
+ */
+ public static boolean isPrimitiveArray(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return (clazz.isArray() && clazz.getComponentType().isPrimitive());
+ }
+
+ /**
+ * Check if the given class represents an array current primitive wrappers,
+ * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
+ * @param clazz the class to check
+ * @return whether the given class is a primitive wrapper array class
+ */
+ public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType()));
+ }
+
+ /**
+ * Resolve the given class if it is a primitive class,
+ * returning the corresponding primitive wrapper type instead.
+ * @param clazz the class to check
+ * @return the original class, or a primitive wrapper for the original primitive type
+ */
+ public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ return (clazz.isPrimitive() && clazz != void.class? primitiveTypeToWrapperMap.get(clazz) : clazz);
+ }
+
+ /**
+ * Check if the right-hand side type may be assigned to the left-hand side
+ * type, assuming setting by reflection. Considers primitive wrapper
+ * classes as assignable to the corresponding primitive types.
+ * @param lhsType the target type
+ * @param rhsType the keys type that should be assigned to the target type
+ * @return if the target type is assignable from the keys type
+ */
+ public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
+ Objects.requireNonNull(lhsType, "Left-hand side type must not be null");
+ Objects.requireNonNull(rhsType, "Right-hand side type must not be null");
+ if (lhsType.isAssignableFrom(rhsType)) {
+ return true;
+ }
+ if (lhsType.isPrimitive()) {
+ Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType);
+ if (resolvedPrimitive != null && lhsType.equals(resolvedPrimitive)) {
+ return true;
+ }
+ }
+ else {
+ Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType);
+ if (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Determine if the given type is assignable from the given keys,
+ * assuming setting by reflection. Considers primitive wrapper classes
+ * as assignable to the corresponding primitive types.
+ * @param type the target type
+ * @param keys the keys that should be assigned to the type
+ * @return if the type is assignable from the keys
+ */
+ public static boolean isAssignableValue(Class<?> type, Object keys) {
+ Objects.requireNonNull(type, "Type must not be null");
+ return (keys != null ? isAssignable(type, keys.getClass()) : !type.isPrimitive());
+ }
+
+
+ /**
+ * Convert a "/"-based resource path to a "."-based fully qualified class name.
+ * @param resourcePath the resource path pointing to a class
+ * @return the corresponding fully qualified class name
+ */
+ public static String convertResourcePathToClassName(String resourcePath) {
+ Objects.requireNonNull(resourcePath, "Resource path must not be null");
+ return resourcePath.replace(PATH_SEPARATOR, PACKAGE_SEPARATOR);
+ }
+
+ /**
+ * Convert a "."-based fully qualified class name to a "/"-based resource path.
+ * @param className the fully qualified class name
+ * @return the corresponding resource path, pointing to the class
+ */
+ public static String convertClassNameToResourcePath(String className) {
+ Objects.requireNonNull(className, "Class name must not be null");
+ return className.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
+ }
+
+ /**
+ * Return a path suitable for use with {@code ClassLoader.getResource}
+ * (also suitable for use with {@code Class.getResource} by prepending a
+ * slash ('/') to the return keys). Built by taking the package current the specified
+ * class file, converting all dots ('.') to slashes ('/'), adding a trailing slash
+ * if necessary, and concatenating the specified resource name to this.
+ * <br/>As such, this function may be used to build a path suitable for
+ * loading a resource file that is in the same package as a class file,
+ * although {@code org.springframework.core.io.ClassPathResource} is usually
+ * even more convenient.
+ * @param clazz the Class whose package will be used as the base
+ * @param resourceName the resource name to append. A leading slash is optional.
+ * @return the built-up resource path
+ * @see ClassLoader#getResource
+ * @see Class#getResource
+ */
+ public static String addResourcePathToPackagePath(Class<?> clazz, String resourceName) {
+ Objects.requireNonNull(resourceName, "Resource name must not be null");
+ if (!resourceName.startsWith("/")) {
+ return classPackageAsResourcePath(clazz) + "/" + resourceName;
+ }
+ return classPackageAsResourcePath(clazz) + resourceName;
+ }
+
+ /**
+ * Given an input class object, return a string which consists current the
+ * class's package name as a pathname, i.e., all dots ('.') are replaced by
+ * slashes ('/'). Neither a leading nor trailing slash is added. The result
+ * could be concatenated with a slash and the name current a resource and fed
+ * directly to {@code ClassLoader.getResource()}. For it to be fed to
+ * {@code Class.getResource} instead, a leading slash would also have
+ * to be prepended to the returned keys.
+ * @param clazz the input class. A {@code null} keys or the default
+ * (empty) package will result in an empty string ("") being returned.
+ * @return a path which represents the package name
+ * @see ClassLoader#getResource
+ * @see Class#getResource
+ */
+ public static String classPackageAsResourcePath(Class<?> clazz) {
+ if (clazz == null) {
+ return "";
+ }
+ String className = clazz.getName();
+ int packageEndIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
+ if (packageEndIndex == -1) {
+ return "";
+ }
+ String packageName = className.substring(0, packageEndIndex);
+ return packageName.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
+ }
+
+ /**
+ * Build a String that consists current the names current the classes/interfaces
+ * in the given array.
+ * <p>Basically like {@code AbstractCollection.toString()}, but stripping
+ * the "class "/"interface " prefix before every class name.
+ * @param classes a Collection current Class objects (may be {@code null})
+ * @return a String current form "[com.foo.Bar, com.foo.Baz]"
+ * @see java.util.AbstractCollection#toString()
+ */
+ public static String classNamesToString(Class<?>... classes) {
+ return classNamesToString(Arrays.asList(classes));
+ }
+
+ /**
+ * Build a String that consists current the names current the classes/interfaces
+ * in the given collection.
+ * <p>Basically like {@code AbstractCollection.toString()}, but stripping
+ * the "class "/"interface " prefix before every class name.
+ * @param classes a Collection current Class objects (may be {@code null})
+ * @return a String current form "[com.foo.Bar, com.foo.Baz]"
+ * @see java.util.AbstractCollection#toString()
+ */
+ public static String classNamesToString(Collection<Class<?>> classes) {
+ if (classes.isEmpty()) {
+ return "[]";
+ }
+ StringBuilder sb = new StringBuilder("[");
+ for (Iterator<Class<?>> it = classes.iterator(); it.hasNext(); ) {
+ Class<?> clazz = it.next();
+ sb.append(clazz.getName());
+ if (it.hasNext()) {
+ sb.append(", ");
+ }
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+ /**
+ * Copy the given Collection into a Class array.
+ * The Collection must contain Class elements only.
+ * @param collection the Collection to copy
+ * @return the Class array ({@code null} if the passed-in
+ * Collection was {@code null})
+ */
+ public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
+ if (collection == null) {
+ return null;
+ }
+ return collection.toArray(new Class<?>[collection.size()]);
+ }
+
+ /**
+ * Return all interfaces that the given instance implements as array,
+ * including ones implemented by superclasses.
+ * @param instance the instance to analyze for interfaces
+ * @return all interfaces that the given instance implements as array
+ */
+ public static Class<?>[] getAllInterfaces(Object instance) {
+ Objects.requireNonNull(instance, "Instance must not be null");
+ return getAllInterfacesForClass(instance.getClass());
+ }
+
+ /**
+ * Return all interfaces that the given class implements as array,
+ * including ones implemented by superclasses.
+ * <p>If the class itself is an interface, it gets returned as sole interface.
+ * @param clazz the class to analyze for interfaces
+ * @return all interfaces that the given object implements as array
+ */
+ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz) {
+ return getAllInterfacesForClass(clazz, null);
+ }
+
+ /**
+ * Return all interfaces that the given class implements as array,
+ * including ones implemented by superclasses.
+ * <p>If the class itself is an interface, it gets returned as sole interface.
+ * @param clazz the class to analyze for interfaces
+ * @param classLoader the ClassLoader that the interfaces need to be visible in
+ * (may be {@code null} when accepting all declared interfaces)
+ * @return all interfaces that the given object implements as array
+ */
+ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) {
+ Set<Class<?>> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
+ return ifcs.toArray(new Class<?>[ifcs.size()]);
+ }
+
+ /**
+ * Return all interfaces that the given instance implements as Set,
+ * including ones implemented by superclasses.
+ * @param instance the instance to analyze for interfaces
+ * @return all interfaces that the given instance implements as Set
+ */
+ public static Set<Class<?>> getAllInterfacesAsSet(Object instance) {
+ Objects.requireNonNull(instance, "Instance must not be null");
+ return getAllInterfacesForClassAsSet(instance.getClass());
+ }
+
+ /**
+ * Return all interfaces that the given class implements as Set,
+ * including ones implemented by superclasses.
+ * <p>If the class itself is an interface, it gets returned as sole interface.
+ * @param clazz the class to analyze for interfaces
+ * @return all interfaces that the given object implements as Set
+ */
+ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz) {
+ return getAllInterfacesForClassAsSet(clazz, null);
+ }
+
+ /**
+ * Return all interfaces that the given class implements as Set,
+ * including ones implemented by superclasses.
+ * <p>If the class itself is an interface, it gets returned as sole interface.
+ * @param clazz the class to analyze for interfaces
+ * @param classLoader the ClassLoader that the interfaces need to be visible in
+ * (may be {@code null} when accepting all declared interfaces)
+ * @return all interfaces that the given object implements as Set
+ */
+ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
+ Objects.requireNonNull(clazz, "Class must not be null");
+ if (clazz.isInterface() && isVisible(clazz, classLoader)) {
+ return Collections.<Class<?>>singleton(clazz);
+ }
+ Set<Class<?>> interfaces = new LinkedHashSet<>();
+ while (clazz != null) {
+ Class<?>[] ifcs = clazz.getInterfaces();
+ for (Class<?> ifc : ifcs) {
+ interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));
+ }
+ clazz = clazz.getSuperclass();
+ }
+ return interfaces;
+ }
+
+ /**
+ * Create a composite interface Class for the given interfaces,
+ * implementing the given interfaces in one single Class.
+ * <p>This implementation builds a JDK proxy class for the given interfaces.
+ * @param interfaces the interfaces to merge
+ * @param classLoader the ClassLoader to of the composite Class in
+ * @return the merged interface as Class
+ * @see java.lang.reflect.Proxy#getProxyClass
+ */
+ public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) {
+ if(interfaces.length==0) throw new IllegalArgumentException("Interfaces must not be empty");
+ Objects.requireNonNull(classLoader, "ClassLoader must not be null");
+ return Proxy.getProxyClass(classLoader, interfaces);
+ }
+
+ /**
+ * Determine the common ancestor current the given classes, if any.
+ * @param clazz1 the class to introspect
+ * @param clazz2 the other class to introspect
+ * @return the common ancestor (i.e. common superclass, one interface
+ * extending the other), or {@code null} if none found. If any current the
+ * given classes is {@code null}, the other class will be returned.
+ * @since 3.2.6
+ */
+ public static Class<?> determineCommonAncestor(Class<?> clazz1, Class<?> clazz2) {
+ if (clazz1 == null) {
+ return clazz2;
+ }
+ if (clazz2 == null) {
+ return clazz1;
+ }
+ if (clazz1.isAssignableFrom(clazz2)) {
+ return clazz1;
+ }
+ if (clazz2.isAssignableFrom(clazz1)) {
+ return clazz2;
+ }
+ Class<?> ancestor = clazz1;
+ do {
+ ancestor = ancestor.getSuperclass();
+ if (ancestor == null || Object.class.equals(ancestor)) {
+ return null;
+ }
+ }
+ while (!ancestor.isAssignableFrom(clazz2));
+ return ancestor;
+ }
+
+ /**
+ * Check whether the given class is visible in the given ClassLoader.
+ * @param clazz the class to check (typically an interface)
+ * @param classLoader the ClassLoader to check against (may be {@code null},
+ * in which case this method will always return {@code true})
+ */
+ public static boolean isVisible(Class<?> clazz, ClassLoader classLoader) {
+ if (classLoader == null) {
+ return true;
+ }
+ try {
+ Class<?> actualClass = classLoader.loadClass(clazz.getName());
+ return (clazz == actualClass);
+ // Else: different interface class found...
+ }
+ catch (ClassNotFoundException ex) {
+ // No interface class found...
+ return false;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java b/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java
new file mode 100644
index 0000000..49c3291
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/util/StringUtils.java
@@ -0,0 +1,463 @@
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.core.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+/**
+* Miscellaneous {@link String} utility methods.
+*
+* <p>Mainly for internal use within the framework; consider
+* <a href="http://jakarta.apache.org/commons/lang/">Jakarta's Commons Lang</a>
+* for a more comprehensive suite current String utilities.
+*
+* <p>This class delivers some simple functionality that should really
+* be provided by the core Java {@code String} and {@link StringBuilder}
+* classes, such as the ability to {@code replace} all occurrences current a given
+* substring in a target string. It also provides easy-to-use methods to convert
+* between delimited strings, such as CSV strings, and collections and arrays.
+*
+* @author Rod Johnson
+* @author Juergen Hoeller
+* @author Keith Donald
+* @author Rob Harrop
+* @author Rick Evans
+* @author Arjen Poutsma
+* @since 16 April 2001
+*/
+public final class StringUtils {
+
+ private static final String FOLDER_SEPARATOR = "/";
+
+ private static final String WINDOWS_FOLDER_SEPARATOR = "\\";
+
+ private static final String TOP_PATH = "..";
+
+ private static final String CURRENT_PATH = ".";
+
+// private static final char EXTENSION_SEPARATOR = '.';
+//
+
+ private StringUtils(){}
+
+
+ /**
+ * Check that the given CharSequence is neither {@code null} nor current length 0.
+ * Note: Will return {@code true} for a CharSequence that purely consists current whitespace.
+ * <p><pre class="code">
+ * StringUtils.hasLength(null) = false
+ * StringUtils.hasLength("") = false
+ * StringUtils.hasLength(" ") = true
+ * StringUtils.hasLength("Hello") = true
+ * </pre>
+ * @param str the CharSequence to check (may be {@code null})
+ * @return {@code true} if the CharSequence is not null and has length
+ */
+ public static boolean hasLength(CharSequence str) {
+ return (str != null && str.length() > 0);
+ }
+
+ /**
+ * Check whether the given CharSequence has actual text.
+ * More specifically, returns {@code true} if the string not {@code null},
+ * its length is greater than 0, and it contains at least one non-whitespace character.
+ * <p><pre class="code">
+ * StringUtils.hasText(null) = false
+ * StringUtils.hasText("") = false
+ * StringUtils.hasText(" ") = false
+ * StringUtils.hasText("12345") = true
+ * StringUtils.hasText(" 12345 ") = true
+ * </pre>
+ * @param str the CharSequence to check (may be {@code null})
+ * @return {@code true} if the CharSequence is not {@code null},
+ * its length is greater than 0, and it does not contain whitespace only
+ * @see Character#isWhitespace
+ */
+ public static boolean hasText(CharSequence str) {
+ if (!hasLength(str)) {
+ return false;
+ }
+ int strLen = str.length();
+ for (int i = 0; i < strLen; i++) {
+ if (!Character.isWhitespace(str.charAt(i))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check whether the given String has actual text.
+ * More specifically, returns {@code true} if the string not {@code null},
+ * its length is greater than 0, and it contains at least one non-whitespace character.
+ * @param str the String to check (may be {@code null})
+ * @return {@code true} if the String is not {@code null}, its length is
+ * greater than 0, and it does not contain whitespace only
+ * @see #hasText(CharSequence)
+ */
+ public static boolean hasText(String str) {
+ return hasText((CharSequence) str);
+ }
+
+
+ /**
+ * Replace all occurrences current a substring within a string with
+ * another string.
+ * @param inString String to examine
+ * @param oldPattern String to replace
+ * @param newPattern String to insert
+ * @return a String with the replacements
+ */
+ public static String replace(String inString, String oldPattern, String newPattern) {
+ if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) {
+ return inString;
+ }
+ StringBuilder sb = new StringBuilder();
+ int pos = 0; // our position in the old string
+ int index = inString.indexOf(oldPattern);
+ // the index current an occurrence we've found, or -1
+ int patLen = oldPattern.length();
+ while (index >= 0) {
+ sb.append(inString.substring(pos, index));
+ sb.append(newPattern);
+ pos = index + patLen;
+ index = inString.indexOf(oldPattern, pos);
+ }
+ sb.append(inString.substring(pos));
+ // remember to append any characters to the right current a match
+ return sb.toString();
+ }
+
+
+ /**
+ * Delete any character in a given String.
+ * @param inString the original String
+ * @param charsToDelete a set current characters to delete.
+ * E.g. "az\n" will delete 'a's, 'z's and new lines.
+ * @return the resulting String
+ */
+ public static String deleteAny(String inString, String charsToDelete) {
+ if (!hasLength(inString) || !hasLength(charsToDelete)) {
+ return inString;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < inString.length(); i++) {
+ char c = inString.charAt(i);
+ if (charsToDelete.indexOf(c) == -1) {
+ sb.append(c);
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Extract the filename from the given path,
+ * e.g. "mypath/myfile.txt" -> "myfile.txt".
+ * @param path the file path (may be {@code null})
+ * @return the extracted filename, or {@code null} if none
+ */
+ public static String getFilename(String path) {
+ if (path == null) {
+ return null;
+ }
+ int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
+ return (separatorIndex != -1 ? path.substring(separatorIndex + 1) : path);
+ }
+
+
+
+ /**
+ * Apply the given relative path to the given path,
+ * assuming standard Java folder separation (i.e. "/" separators).
+ * @param path the path to start from (usually a full file path)
+ * @param relativePath the relative path to applyChanges
+ * (relative to the full file path above)
+ * @return the full file path that results from applying the relative path
+ */
+ public static String applyRelativePath(String path, String relativePath) {
+ int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
+ if (separatorIndex != -1) {
+ String newPath = path.substring(0, separatorIndex);
+ if (!relativePath.startsWith(FOLDER_SEPARATOR)) {
+ newPath += FOLDER_SEPARATOR;
+ }
+ return newPath + relativePath;
+ }
+ else {
+ return relativePath;
+ }
+ }
+
+ /**
+ * Normalize the path by suppressing sequences like "path/.." and
+ * inner simple dots.
+ * <p>The result is convenient for path comparison. For other uses,
+ * notice that Windows separators ("\") are replaced by simple slashes.
+ * @param path the original path
+ * @return the normalized path
+ */
+ public static String cleanPath(String path) {
+ if (path == null) {
+ return null;
+ }
+ String pathToUse = StringUtils.replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR);
+
+ // Strip prefix from path to analyze, to not treat it as part current the
+ // first path element. This is necessary to correctly parse paths like
+ // "file:core/../core/io/Resource.class", where the ".." should just
+ // strip the first "core" directory while keeping the "file:" prefix.
+ int prefixIndex = pathToUse.indexOf(':');
+ String prefix = "";
+ if (prefixIndex != -1) {
+ prefix = pathToUse.substring(0, prefixIndex + 1);
+ if (prefix.contains("/")) {
+ prefix = "";
+ }
+ else {
+ pathToUse = pathToUse.substring(prefixIndex + 1);
+ }
+ }
+ if (pathToUse.startsWith(FOLDER_SEPARATOR)) {
+ prefix = prefix + FOLDER_SEPARATOR;
+ pathToUse = pathToUse.substring(1);
+ }
+
+ String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR);
+ List<String> pathElements = new LinkedList<>();
+ int tops = 0;
+
+ for (int i = pathArray.length - 1; i >= 0; i--) {
+ String element = pathArray[i];
+ if (CURRENT_PATH.equals(element)) {
+ // Points to current directory - drop it.
+ }
+ else if (TOP_PATH.equals(element)) {
+ // Registering top path found.
+ tops++;
+ }
+ else {
+ if (tops > 0) {
+ // Merging path element with element corresponding to top path.
+ tops--;
+ }
+ else {
+ // Normal path element found.
+ pathElements.add(0, element);
+ }
+ }
+ }
+ // Remaining top paths need to be retained.
+ for (int i = 0; i < tops; i++) {
+ pathElements.add(0, TOP_PATH);
+ }
+ return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
+ }
+
+
+ /**
+ * Copy the given Collection into a String array.
+ * The Collection must contain String elements only.
+ * @param collection the Collection to copy
+ * @return the String array ({@code null} if the passed-in
+ * Collection was {@code null})
+ */
+ public static String[] toStringArray(Collection<String> collection) {
+ if (collection == null) {
+ return null;
+ }
+ return collection.toArray(new String[collection.size()]);
+ }
+
+ /**
+ * Split a String at the first occurrence current the delimiter.
+ * Does not include the delimiter in the result.
+ * @param toSplit the string to split
+ * @param delimiter to split the string up with
+ * @return a two element array with index 0 being before the delimiter, and
+ * index 1 being after the delimiter (neither element includes the delimiter);
+ * or {@code null} if the delimiter wasn't found in the given input String
+ */
+ public static String[] split(String toSplit, String delimiter) {
+ if (!hasLength(toSplit) || !hasLength(delimiter)) {
+ return null;
+ }
+ int offset = toSplit.indexOf(delimiter);
+ if (offset < 0) {
+ return null;
+ }
+ String beforeDelimiter = toSplit.substring(0, offset);
+ String afterDelimiter = toSplit.substring(offset + delimiter.length());
+ return new String[] {beforeDelimiter, afterDelimiter};
+ }
+
+
+ /**
+ * Tokenize the given String into a String array via a StringTokenizer.
+ * Trims tokens and omits empty tokens.
+ * <p>The given delimiters string is supposed to consist current any number current
+ * delimiter characters. Each current those characters can be used to separate
+ * tokens. A delimiter is always a single character; for multi-character
+ * delimiters, consider using {@code delimitedListToStringArray}
+ * @param str the String to tokenize
+ * @param delimiters the delimiter characters, assembled as String
+ * (each current those characters is individually considered as delimiter).
+ * @return an array current the tokens
+ * @see java.util.StringTokenizer
+ * @see String#trim()
+ */
+ public static String[] tokenizeToStringArray(String str, String delimiters) {
+ return tokenizeToStringArray(str, delimiters, true, true);
+ }
+
+ /**
+ * Tokenize the given String into a String array via a StringTokenizer.
+ * <p>The given delimiters string is supposed to consist current any number current
+ * delimiter characters. Each current those characters can be used to separate
+ * tokens. A delimiter is always a single character; for multi-character
+ * delimiters, consider using {@code delimitedListToStringArray}
+ * @param str the String to tokenize
+ * @param delimiters the delimiter characters, assembled as String
+ * (each current those characters is individually considered as delimiter)
+ * @param trimTokens trim the tokens via String's {@code trim}
+ * @param ignoreEmptyTokens omit empty tokens from the result array
+ * (only applies to tokens that are empty after trimming; StringTokenizer
+ * will not consider subsequent delimiters as token in the first place).
+ * @return an array current the tokens ({@code null} if the input String
+ * was {@code null})
+ * @see java.util.StringTokenizer
+ * @see String#trim()
+ */
+ public static String[] tokenizeToStringArray(
+ String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {
+
+ if (str == null) {
+ return null;
+ }
+ StringTokenizer st = new StringTokenizer(str, delimiters);
+ List<String> tokens = new ArrayList<>();
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ if (trimTokens) {
+ token = token.trim();
+ }
+ if (!ignoreEmptyTokens || token.length() > 0) {
+ tokens.add(token);
+ }
+ }
+ return toStringArray(tokens);
+ }
+
+ /**
+ * Take a String which is a delimited list and convert it to a String array.
+ * <p>A single delimiter can consists current more than one character: It will still
+ * be considered as single delimiter string, rather than as bunch current potential
+ * delimiter characters - in contrast to {@code tokenizeToStringArray}.
+ * @param str the input String
+ * @param delimiter the delimiter between elements (this is a single delimiter,
+ * rather than a bunch individual delimiter characters)
+ * @return an array current the tokens in the list
+ * @see #tokenizeToStringArray
+ */
+ public static String[] delimitedListToStringArray(String str, String delimiter) {
+ return delimitedListToStringArray(str, delimiter, null);
+ }
+
+ /**
+ * Take a String which is a delimited list and convert it to a String array.
+ * <p>A single delimiter can consists current more than one character: It will still
+ * be considered as single delimiter string, rather than as bunch current potential
+ * delimiter characters - in contrast to {@code tokenizeToStringArray}.
+ * @param str the input String
+ * @param delimiter the delimiter between elements (this is a single delimiter,
+ * rather than a bunch individual delimiter characters)
+ * @param charsToDelete a set current characters to delete. Useful for deleting unwanted
+ * line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in a String.
+ * @return an array current the tokens in the list
+ * @see #tokenizeToStringArray
+ */
+ public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete) {
+ if (str == null) {
+ return new String[0];
+ }
+ if (delimiter == null) {
+ return new String[] {str};
+ }
+ List<String> result = new ArrayList<>();
+ if ("".equals(delimiter)) {
+ for (int i = 0; i < str.length(); i++) {
+ result.add(deleteAny(str.substring(i, i + 1), charsToDelete));
+ }
+ }
+ else {
+ int pos = 0;
+ int delPos;
+ while ((delPos = str.indexOf(delimiter, pos)) != -1) {
+ result.add(deleteAny(str.substring(pos, delPos), charsToDelete));
+ pos = delPos + delimiter.length();
+ }
+ if (str.length() > 0 && pos <= str.length()) {
+ // Add rest current String, but not in case current empty input.
+ result.add(deleteAny(str.substring(pos), charsToDelete));
+ }
+ }
+ return toStringArray(result);
+ }
+
+
+ /**
+ * Convenience method to return a Collection as a delimited (e.g. CSV)
+ * String. E.g. useful for {@code toString()} implementations.
+ * @param coll the Collection to display
+ * @param delim the delimiter to use (probably a ",")
+ * @param prefix the String to start each element with
+ * @param suffix the String to end each element with
+ * @return the delimited String
+ */
+ public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) {
+ if (coll.isEmpty()) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder();
+ Iterator<?> it = coll.iterator();
+ while (it.hasNext()) {
+ sb.append(prefix).append(it.next()).append(suffix);
+ if (it.hasNext()) {
+ sb.append(delim);
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Convenience method to return a Collection as a delimited (e.g. CSV)
+ * String. E.g. useful for {@code toString()} implementations.
+ * @param coll the Collection to display
+ * @param delim the delimiter to use (probably a ",")
+ * @return the delimited String
+ */
+ public static String collectionToDelimitedString(Collection<?> coll, String delim) {
+ return collectionToDelimitedString(coll, delim, "", "");
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
new file mode 100644
index 0000000..56413ca
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.core.PathBasedPropertySourceProvider;
+import org.apache.tamaya.core.formats.PropertiesFormat;
+
+/**
+ * Test provider reading properties from classpath:cfg/final/**.properties.
+ */
+public class TestPropertySourceProvider extends PathBasedPropertySourceProvider{
+
+ public TestPropertySourceProvider() {
+ super("final-testdata-properties", PropertiesFormat.of(200), "classpath:cfg/final/**/*.properties");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/PropertyMapSupplier.java
----------------------------------------------------------------------
diff --git a/dormant/api/PropertyMapSupplier.java b/dormant/api/PropertyMapSupplier.java
new file mode 100644
index 0000000..69dd308
--- /dev/null
+++ b/dormant/api/PropertyMapSupplier.java
@@ -0,0 +1,37 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.tamaya;
+
+import java.util.Map;
+
+/**
+ * Supplier for a property map.
+ */
+@FunctionalInterface
+public interface PropertyMapSupplier {
+
+ /**
+ * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
+ * when the underlying storage does not support iteration of its entries.
+ *
+ * @return the a corresponding map, never null.
+ */
+ Map<String,String> getProperties();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/ConfigQuery.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/ConfigQuery.java b/dormant/api/src/main/java/org/apache/tamaya/ConfigQuery.java
deleted file mode 100644
index 58d8742..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/ConfigQuery.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-
-/**
- * Interface for an query that converts a Configuration into another object. One typical
- * use cases would creating a complex configuration parameter type fromMap a Configuration instance or
- * constraint views on configuration.
- */
-@FunctionalInterface
-public interface ConfigQuery<T>{
-
- /**
- * Queries the given configuration.
- * @param config the configuration to be wuiried, not null.
- * @return the result T.
- */
- T query(Configuration config);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/ConfiguredValue.java b/dormant/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
deleted file mode 100644
index e75cd51..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-import org.apache.tamaya.annotation.LoadPolicy;
-
-import java.beans.PropertyChangeEvent;
-import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
-
-/**
- * A accessor for a single configured value. This can be used to support values that may be reinjected, reconfigured or
- * final.
- * <h3>Implementation Requirements</h3>
- * Instances of this class must be
- * <ul>
- * <li>Serializable</li>
- * <li>Immutable</li>
- * <li>Thread safe</li>
- * </ul>
- */
-public interface ConfiguredValue<T> {
-
- /**
- * Access the {@link org.apache.tamaya.annotation.LoadPolicy} used for updating this value.
- * @return the load policy, never null.
- */
- LoadPolicy getLoadPolicy();
-
- /**
- * get the UTC timestamp in ms of the last access to a value, using get().
- * @return the UTC timestamp of the last access
- */
- long getLastAccess();
-
- /**
- * get the UTC timestamp in ms of the last update to the value,.
- * @return the UTC timestamp of the last update
- */
- long getLastUpdate();
-
- /**
- * Access if this instance has been updated since the given UTC timestamp in ms.
- * @param timestamp
- * @return true, if his instance has been updated since the given UTC timestamp in ms.
- */
- boolean isUpdatedSince(long timestamp);
-
- /**
- * Access if this instance has been accessed since the given UTC timestamp in ms.
- * @param timestamp
- * @return true, if his instance has been accessed since the given UTC timestamp in ms.
- */
- boolean isAccessedSince(long timestamp);
-
- /**
- * Add a listener to be called, when this value is changed.
- * @param l the listner, not null
- */
- void addListener(Consumer<PropertyChangeEvent> l);
-
- /**
- * Removes a listener to be called, when this value is changed.
- * @param l the listner to be removed, not null
- */
- void removeListener(Consumer<PropertyChangeEvent> l);
-
- /**
- * Evaluate if the item value has been updated since the last access.
- * @return true, if item value has been updated since the last access.
- */
- default boolean isUpdated(){
- return isUpdatedSince(getLastAccess());
- }
-
- /**
- * If a value is present in this {@code ConfiguredValue}, returns the value,
- * otherwise throws {@code ConfigException}.
- *
- * @return the non-null value held by this {@code Optional}
- * @throws org.apache.tamaya.ConfigException if there is no value present
- *
- * @see ConfiguredValue#isPresent()
- */
- T get();
-
- /**
- * If a value is present in this {@code ConfiguredValue}, returns the value,
- * otherwise throws {@code ConfigException}.
- *
- * @return the non-null value held by this {@code Optional}
- * @throws org.apache.tamaya.ConfigException if there is no value present
- *
- * @see ConfiguredValue#isPresent()
- */
- default T updateAndGet(){
- update();
- return get();
- }
-
- /**
- * Reevaluates the current value based on the instance's settings from the underlying configurations
- * and applies the new value to its internal state. On change any registered listeners will be triggered.
- */
- void update();
-
- /**
- * Return {@code true} if there is a value present, otherwise {@code false}.
- *
- * @return {@code true} if there is a value present, otherwise {@code false}
- */
- boolean isPresent();
-
- /**
- * If a value is present, invoke the specified consumer with the value,
- * otherwise do nothing.
- *
- * @param consumer block to be executed if a value is present
- * @throws NullPointerException if value is present and {@code consumer} is
- * null
- */
- void ifPresent(Consumer<? super T> consumer);
-
- /**
- * If a value is present, and the value matches the given predicate,
- * return an {@code Optional} describing the value, otherwise return an
- * empty {@code Optional}.
- *
- * @param predicate a predicate to apply to the value, if present
- * @return an {@code Optional} describing the value of this {@code Optional}
- * if a value is present and the value matches the given predicate,
- * otherwise an empty {@code Optional}
- * @throws NullPointerException if the predicate is null
- */
- ConfiguredValue<T> filter(Predicate<? super T> predicate);
-
- /**
- * If a value is present, apply the provided mapping function to it,
- * and if the result is non-null, return an {@code Optional} describing the
- * result. Otherwise return an empty {@code Optional}.
- *
- * @apiNote This method supports post-processing on optional values, without
- * the need to explicitly check for a return status. For example, the
- * following code traverses a stream of file names, selects one that has
- * not yet been processed, and then opens that file, returning an
- * {@code Optional<FileInputStream>}:
- *
- * <pre>{@code
- * Optional<FileInputStream> fis =
- * names.stream().filter(name -> !isProcessedYet(name))
- * .findFirst()
- * .map(name -> new FileInputStream(name));
- * }</pre>
- *
- * Here, {@code findFirst} returns an {@code Optional<String>}, and then
- * {@code map} returns an {@code Optional<FileInputStream>} for the desired
- * file if one exists.
- *
- * @param <U> The type of the result of the mapping function
- * @param mapper a mapping function to apply to the value, if present
- * @return an {@code Optional} describing the result of applying a mapping
- * function to the value of this {@code Optional}, if a value is present,
- * otherwise an empty {@code Optional}
- * @throws NullPointerException if the mapping function is null
- */
- <U> ConfiguredValue<U> map(Function<? super T, ? extends U> mapper);
-
- /**
- * If a value is present, apply the provided {@code Optional}-bearing
- * mapping function to it, return that result, otherwise return an empty
- * {@code Optional}. This method is similar to {@link #map(Function)},
- * but the provided mapper is one whose result is already an {@code Optional},
- * and if invoked, {@code flatMap} does not wrap it with an additional
- * {@code Optional}.
- *
- * @param <U> The type parameter to the {@code Optional} returned by
- * @param mapper a mapping function to apply to the value, if present
- * the mapping function
- * @return the result of applying an {@code Optional}-bearing mapping
- * function to the value of this {@code Optional}, if a value is present,
- * otherwise an empty {@code Optional}
- * @throws NullPointerException if the mapping function is null or returns
- * a null result
- */
- <U> ConfiguredValue<U> flatMap(Function<? super T, ConfiguredValue<U>> mapper);
-
- /**
- * Return the value if present, otherwise return {@code other}.
- *
- * @param other the value to be returned if there is no value present, may
- * be null
- * @return the value, if present, otherwise {@code other}
- */
- T orElse(T other);
-
- /**
- * Return the value if present, otherwise invoke {@code other} and return
- * the result of that invocation.
- *
- * @param other a {@code Supplier} whose result is returned if no value
- * is present
- * @return the value if present otherwise the result of {@code other.get()}
- * @throws NullPointerException if value is not present and {@code other} is
- * null
- */
- T orElseGet(Supplier<? extends T> other);
-
- /**
- * Return the contained value, if present, otherwise throw an exception
- * to be created by the provided supplier.
- *
- * @apiNote A method reference to the exception constructor with an empty
- * argument list can be used as the supplier. For example,
- * {@code IllegalStateException::new}
- *
- * @param <X> Type of the exception to be thrown
- * @param exceptionSupplier The supplier which will return the exception to
- * be thrown
- * @return the present value
- * @throws X if there is no value present
- * @throws NullPointerException if no value is present and
- * {@code exceptionSupplier} is null
- */
- <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X;
-
- /**
- * Converts this value to an {@link java.util.Optional} instance.
- * @return an {@link java.util.Optional} instance, never null.
- */
- default Optional<T> toOptional(){
- if(isPresent()){
- return Optional.of(get());
- }
- return Optional.empty();
- }
-
-}
[27/27] incubator-tamaya git commit: Fixed checkstyle issues.
Posted by an...@apache.org.
Fixed checkstyle issues.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/95885781
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/95885781
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/95885781
Branch: refs/heads/master
Commit: 95885781ef28a3c0dea0ab44275c068eac5f650c
Parents: 6feab0d
Author: anatole <an...@apache.org>
Authored: Sat Jan 3 12:58:55 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 3 12:58:55 2015 +0100
----------------------------------------------------------------------
.../apache/tamaya/spi/ConfigurationContext.java | 1 -
.../core/PathBasedPropertySourceProvider.java | 9 +-
.../core/formats/ConfigurationFormat.java | 7 +-
.../tamaya/core/formats/PropertiesFormat.java | 42 +-
.../core/formats/PropertiesXmlFormat.java | 2 +-
.../core/internal/DefaultConfiguration.java | 17 +-
.../internal/DefaultConfigurationContext.java | 47 +-
.../core/internal/DefaultServiceContext.java | 26 +-
.../core/internal/PropertyConverterManager.java | 95 +-
.../logging/AbstractDelegatingLogger.java | 6 +-
.../resource/AbstractFileResolvingResource.java | 350 ++-
.../core/internal/resource/AntPathMatcher.java | 1444 ++++++------
.../internal/resource/ClassPathResource.java | 422 ++--
.../resource/DefaultResourceLoader.java | 47 +-
.../internal/resource/FileSystemResource.java | 370 ++--
.../internal/resource/InputStreamResource.java | 164 +-
.../PathMatchingDefaultResourceLoader.java | 203 +-
.../PathMatchingResourcePatternResolver.java | 144 +-
.../core/internal/resource/ReflectionUtils.java | 317 +--
.../core/internal/resource/ResourceUtils.java | 433 ++--
.../core/internal/resource/UrlResource.java | 63 +-
.../core/internal/resource/VfsResource.java | 169 +-
.../tamaya/core/internal/resource/VfsUtils.java | 315 ++-
.../core/resources/InputStreamSource.java | 41 +-
.../apache/tamaya/core/resources/Resource.java | 175 +-
.../tamaya/core/resources/ResourceLoader.java | 4 +-
.../org/apache/tamaya/core/util/ClassUtils.java | 2092 +++++++++---------
.../apache/tamaya/core/util/StringUtils.java | 878 ++++----
...org.apache.tamaya.spi.PropertySourceProvider | 4 +-
29 files changed, 3989 insertions(+), 3898 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index 21d08da..27bc52e 100644
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.spi;
import java.util.List;
import java.util.Map;
-import java.util.function.UnaryOperator;
/**
* Central SPI for programmatically dealing with the setup of the configuration system.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java b/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
index aba7a9f..53d6760 100644
--- a/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
@@ -56,16 +56,15 @@ public class PathBasedPropertySourceProvider implements PropertySourceProvider {
}
@Override
- public Collection<PropertySource> getPropertySources(){
+ public Collection<PropertySource> getPropertySources() {
List<PropertySource> propertySources = new ArrayList<>();
paths.forEach((path) -> {
for (Resource res : ServiceContext.getInstance().getService(ResourceLoader.class).get().getResources(path)) {
- try{
- for(ConfigurationFormat format:configFormats){
+ try {
+ for (ConfigurationFormat format : configFormats) {
propertySources.addAll(format.readConfiguration(res));
}
- }
- catch(Exception e){
+ } catch (Exception e) {
LOG.log(Level.WARNING, "Failed to add resource based config: " + res.getDisplayName(), e);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
index e9308c7..c8353a8 100644
--- a/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
@@ -33,14 +33,15 @@ import java.util.Collection;
* {@link PropertySource} instance.
*/
@FunctionalInterface
-public interface ConfigurationFormat{
+public interface ConfigurationFormat {
/**
* Reads a list {@link org.apache.tamaya.spi.PropertySource} instances from a resource, using this format.
* Hereby the ordinal given is used as a base ordinal
- * @param resource the configuration resource, not null
+ *
+ * @param resource the configuration resource, not null
* @return the corresponding {@link java.util.Map}, never {@code null}.
*/
- Collection<PropertySource> readConfiguration(Resource resource)throws IOException;
+ Collection<PropertySource> readConfiguration(Resource resource) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
index dc3d9bb..6ca4f3d 100644
--- a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
@@ -35,43 +35,47 @@ import java.util.logging.Logger;
/**
* Implementation of a configuration format for -properties files.
*/
-public class PropertiesFormat implements ConfigurationFormat{
+public class PropertiesFormat implements ConfigurationFormat {
private final static Logger LOG = Logger.getLogger(PropertiesFormat.class.getName());
- /** The target ordinal. */
+ /**
+ * The target ordinal.
+ */
private int ordinal;
/**
* Creates a new ordinal.
+ *
* @param ordinal the target ordinal.
*/
- private PropertiesFormat(int ordinal){
+ private PropertiesFormat(int ordinal) {
this.ordinal = ordinal;
}
- public static PropertiesFormat of(int ordinal){
+ public static PropertiesFormat of(int ordinal) {
// TODO caching...
return new PropertiesFormat(ordinal);
}
/**
* Get the target ordinal, produced by this format.
+ *
* @return the target ordinal
*/
- public int getOrdinal(){
+ public int getOrdinal() {
return ordinal;
}
- @SuppressWarnings("unchecked")
- @Override
- public Collection<PropertySource> readConfiguration(Resource resource) {
- if (resource.exists()) {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Collection<PropertySource> readConfiguration(Resource resource) {
+ if (resource.exists()) {
List<PropertySource> propertySources = new ArrayList<>();
- try (InputStream is = resource.getInputStream()) {
- final Properties p = new Properties();
- p.load(is);
- propertySources.add(new PropertySource(){
+ try (InputStream is = resource.getInputStream()) {
+ final Properties p = new Properties();
+ p.load(is);
+ propertySources.add(new PropertySource() {
@Override
public int getOrdinal() {
return ordinal;
@@ -92,13 +96,13 @@ public class PropertiesFormat implements ConfigurationFormat{
return Map.class.cast(p);
}
});
- return propertySources;
- } catch (Exception e) {
+ return propertySources;
+ } catch (Exception e) {
LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + resource);
- }
- }
- return Collections.emptyList();
- }
+ }
+ }
+ return Collections.emptyList();
+ }
@Override
public String toString() {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
index 625dd32..98e26f3 100644
--- a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
@@ -51,7 +51,7 @@ public class PropertiesXmlFormat implements ConfigurationFormat {
this.ordinal = ordinal;
}
- public static PropertiesXmlFormat of(int ordinal){
+ public static PropertiesXmlFormat of(int ordinal) {
// TODO caching...
return new PropertiesXmlFormat(ordinal);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index ef27c87..e6c0c44 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -31,14 +31,14 @@ import java.util.Optional;
/**
* Implementation of the Configuration API.
*/
-public class DefaultConfiguration implements Configuration{
+public class DefaultConfiguration implements Configuration {
@Override
public Optional<String> get(String key) {
List<PropertySource> propertySources = ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertySources();
- for(PropertySource propertySource:propertySources){
+ for (PropertySource propertySource : propertySources) {
Optional<String> value = propertySource.get(key);
- if(value.isPresent()){
+ if (value.isPresent()) {
return value;
}
}
@@ -48,16 +48,15 @@ public class DefaultConfiguration implements Configuration{
@Override
public <T> Optional<T> get(String key, Class<T> type) {
Optional<String> value = get(key);
- if(value.isPresent()){
+ if (value.isPresent()) {
List<PropertyConverter<T>> converters = ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertyConverters(type);
- for(PropertyConverter<T> converter:converters){
- try{
+ for (PropertyConverter<T> converter : converters) {
+ try {
T t = converter.convert(value.get());
- if(t!=null){
+ if (t != null) {
return Optional.of(t);
}
- }
- catch(Exception e){
+ } catch (Exception e) {
// TODO LOG
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
index 90b1d16..08e55a7 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -33,12 +33,11 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.StampedLock;
-import java.util.stream.Stream;
/**
* Default Implementation of a simple ConfigurationContext.
*/
-public class DefaultConfigurationContext implements ConfigurationContext{
+public class DefaultConfigurationContext implements ConfigurationContext {
private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
@@ -53,59 +52,55 @@ public class DefaultConfigurationContext implements ConfigurationContext{
@Override
public void addPropertySources(PropertySource... propertySourcesToAdd) {
Lock writeLock = propertySourceLock.asWriteLock();
- try{
+ try {
writeLock.lock();
List<PropertySource> newPropertySources = new ArrayList<>(this.propertySources);
newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
Collections.sort(newPropertySources, this::comparePropertySources);
this.propertySources = newPropertySources;
- }
- finally{
+ } finally {
writeLock.unlock();
}
}
/**
* Order property source reversely, the most important come first.
+ *
* @param source1
* @param source2
* @return
*/
- private int comparePropertySources(PropertySource source1, PropertySource source2){
- if(source1.getOrdinal() < source2.getOrdinal()){
+ private int comparePropertySources(PropertySource source1, PropertySource source2) {
+ if (source1.getOrdinal() < source2.getOrdinal()) {
return 1;
- }
- else if(source1.getOrdinal()>source2.getOrdinal()){
+ } else if (source1.getOrdinal() > source2.getOrdinal()) {
return -1;
- }
- else{
+ } else {
return source2.getClass().getName().compareTo(source1.getClass().getName());
}
}
- private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2){
+ private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
- int ord1 = prio1!=null?prio1.value():0;
- int ord2 = prio2!=null?prio2.value():0;
- if(ord1 < ord2){
+ int ord1 = prio1 != null ? prio1.value() : 0;
+ int ord2 = prio2 != null ? prio2.value() : 0;
+ if (ord1 < ord2) {
return -1;
- }
- else if(ord1>ord2){
+ } else if (ord1 > ord2) {
return 1;
- }
- else{
+ } else {
return filter1.getClass().getName().compareTo(filter2.getClass().getName());
}
}
@Override
public List<PropertySource> getPropertySources() {
- if(!loaded){
+ if (!loaded) {
Lock writeLock = propertySourceLock.asWriteLock();
- try{
+ try {
writeLock.lock();
- if(!loaded) {
+ if (!loaded) {
this.propertySources.addAll(ServiceContext.getInstance().getServices(PropertySource.class));
this.propertySourceProviders.addAll(ServiceContext.getInstance().getServices(PropertySourceProvider.class));
for (PropertySourceProvider prov : this.propertySourceProviders) {
@@ -120,17 +115,15 @@ public class DefaultConfigurationContext implements ConfigurationContext{
Collections.sort(this.propertyFilters, this::comparePropertyFilters);
loaded = true;
}
- }
- finally{
+ } finally {
writeLock.unlock();
}
}
Lock readLock = propertySourceLock.asReadLock();
- try{
+ try {
readLock.lock();
return Collections.unmodifiableList(propertySources);
- }
- finally{
+ } finally {
readLock.unlock();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
index e86ca17..8e27d4a 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -36,20 +35,23 @@ import java.util.logging.Logger;
* {@link java.util.ServiceLoader} to load the services required.
*/
public final class DefaultServiceContext implements ServiceContext {
- /** List current services loaded, per class. */
- private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
- /** Singletons. */
+ /**
+ * List current services loaded, per class.
+ */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+ /**
+ * Singletons.
+ */
private final Map<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
@Override
public <T> Optional<T> getService(Class<T> serviceType) {
- Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
- if(cached==null) {
+ Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
+ if (cached == null) {
List<? extends T> services = getServices(serviceType);
if (services.isEmpty()) {
cached = Optional.empty();
- }
- else{
+ } else {
cached = Optional.of(services.get(0));
}
singletons.put(serviceType, cached);
@@ -60,10 +62,8 @@ public final class DefaultServiceContext implements ServiceContext {
/**
* Loads and registers services.
*
- * @param serviceType
- * The service type.
- * @param <T>
- * the concrete type.
+ * @param serviceType The service type.
+ * @param <T> the concrete type.
* @return the items found, never {@code null}.
*/
@Override
@@ -82,7 +82,7 @@ public final class DefaultServiceContext implements ServiceContext {
Logger.getLogger(DefaultServiceContext.class.getName()).log(Level.WARNING,
"Error loading services current type " + serviceType, e);
}
- final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>)services));
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
return previousServices != null ? previousServices : services;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
index a4d5ff6..4f8118b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -45,20 +45,20 @@ import org.apache.tamaya.spi.PropertyConverter;
*/
public class PropertyConverterManager {
- private Map<Class<?>,List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
+ private Map<Class<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
private StampedLock lock = new StampedLock();
/**
* Constructor.
*/
- public PropertyConverterManager(){
+ public PropertyConverterManager() {
initDefaultConverters();
}
/**
* Registers the default converters provided out of the box.
*/
- protected void initDefaultConverters(){
+ protected void initDefaultConverters() {
// Add default converters
register(char.class, (s) -> s.charAt(0));
register(byte.class, Byte::parseByte);
@@ -90,52 +90,53 @@ public class PropertyConverterManager {
/**
* Registers a ew converter instance.
+ *
* @param targetType the target type, not null.
- * @param converter the converter, not null.
- * @param <T> the type.
+ * @param converter the converter, not null.
+ * @param <T> the type.
*/
- public <T> void register(Class<T> targetType, PropertyConverter<T> converter){
+ public <T> void register(Class<T> targetType, PropertyConverter<T> converter) {
Objects.requireNonNull(converter);
- Lock writeLock = lock.asWriteLock();;
- try{
+ Lock writeLock = lock.asWriteLock();
+ try {
writeLock.lock();
List<PropertyConverter<T>> converters = List.class.cast(this.converters.get(targetType));
List<PropertyConverter<T>> newConverters = new ArrayList<>();
- if(converters != null){
+ if (converters != null) {
newConverters.addAll(converters);
}
newConverters.add(converter);
this.converters.put(targetType, Collections.unmodifiableList(newConverters));
- }
- finally{
+ } finally {
writeLock.unlock();
}
}
/**
* Allows to evaluate if a given target type is supported.
+ *
* @param targetType the target type, not null.
* @return true, if a converter for the given type is registered, or a default one can be created.
*/
- public boolean isTargetTypeSupported(Class<?> targetType){
+ public boolean isTargetTypeSupported(Class<?> targetType) {
return converters.containsKey(targetType)
- || createDefaultPropertyConverter(targetType)!=null;
+ || createDefaultPropertyConverter(targetType) != null;
}
/**
* Get a map of all property converters currently registered. This will not contain the converters that
* may be created, when an instance is adapted, which provides a String constructor or compatible
* factory methods taking a single String instance.
- * @see #createDefaultPropertyConverter(Class)
+ *
* @return the current map of instantiated and registered converters.
+ * @see #createDefaultPropertyConverter(Class)
*/
- public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters(){
+ public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
Lock readLock = lock.asReadLock();
- try{
+ try {
readLock.lock();
return new HashMap<>(this.converters);
- }
- finally{
+ } finally {
readLock.unlock();
}
}
@@ -144,35 +145,34 @@ public class PropertyConverterManager {
* Get the list of all current registered converters for the given target type.
* If not converters are registered, they component tries to create and register a dynamic
* converter based on String costructor or static factory methods available.
- * @see #createDefaultPropertyConverter(Class)
+ *
* @param targetType the target type, not null.
- * @param <T> the type class
+ * @param <T> the type class
* @return the ordered list of converters (may be empty for not convertible types).
+ * @see #createDefaultPropertyConverter(Class)
*/
- public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType){
+ public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
Lock readLock = lock.asReadLock();
List<PropertyConverter<T>> converters;
- try{
+ try {
readLock.lock();
converters = List.class.cast(this.converters.get(targetType));
- }
- finally{
+ } finally {
readLock.unlock();
}
- if(converters!=null){
+ if (converters != null) {
return converters;
}
PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
- if(defaultConverter!=null){
- register(targetType,defaultConverter);
- try{
+ if (defaultConverter != null) {
+ register(targetType, defaultConverter);
+ try {
converters = List.class.cast(this.converters.get(targetType));
- }
- finally{
+ } finally {
readLock.unlock();
}
}
- if(converters!=null){
+ if (converters != null) {
return converters;
}
return Collections.emptyList();
@@ -180,34 +180,33 @@ public class PropertyConverterManager {
/**
* Creates a dynamic PropertyConverter for the given target type.
+ *
* @param targetType the target type
- * @param <T> the type class
+ * @param <T> the type class
* @return a new converter, or null.
*/
protected <T> PropertyConverter<T> createDefaultPropertyConverter(Class<T> targetType) {
PropertyConverter<T> converter = null;
Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "parse");
- if(factoryMethod!=null){
+ if (factoryMethod != null) {
converter = (s) -> {
- try{
+ try {
factoryMethod.setAccessible(true);
return targetType.cast(factoryMethod.invoke(s));
- }
- catch (Exception e){
- throw new ConfigException("Failed to decode '"+s+"'", e);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + s + "'", e);
}
};
}
- if(converter==null) {
+ if (converter == null) {
try {
Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
converter = (s) -> {
- try{
+ try {
constr.setAccessible(true);
return constr.newInstance(s);
- }
- catch (Exception e){
- throw new ConfigException("Failed to decode '"+s+"'", e);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + s + "'", e);
}
};
} catch (Exception e) {
@@ -219,18 +218,18 @@ public class PropertyConverterManager {
/**
* Tries to evaluate a factory method that can be used to create an instance based on a String.
- * @param type the target type
+ *
+ * @param type the target type
* @param methodNames the possible static method names
* @return the first method found, or null.
*/
private Method getFactoryMethod(Class<?> type, String... methodNames) {
Method m;
- for(String name:methodNames){
- try{
- m = type.getDeclaredMethod(name, String.class);
+ for (String name : methodNames) {
+ try {
+ m = type.getDeclaredMethod(name, String.class);
return m;
- }
- catch(Exception e){
+ } catch (Exception e) {
//X ignore, TODO log finest
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
index cc0ac45..30c2d2e 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
@@ -22,7 +22,11 @@ import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import java.util.logging.*;
+import java.util.logging.Filter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
/**
* java.util.logging.Logger implementation delegating to another framework.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
index 5860923..2679659 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
@@ -31,7 +31,7 @@ import java.util.Objects;
/**
* Abstract base class for resources which resolve URLs into File references,
* such as {@code UrlResource} or {@link ClassPathResource}.
- *
+ * <p>
* <p>Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs,
* resolving file system references accordingly.
*
@@ -40,191 +40,185 @@ import java.util.Objects;
*/
abstract class AbstractFileResolvingResource implements Resource {
- /**
- * This implementation returns a File reference for the underlying class path
- * resource, provided that it refers to a file in the file system.
- */
- @Override
- public File toFile() throws IOException {
- URL url = toURL();
- return ResourceUtils.getFile(url);
- }
-
- /**
- * This implementation determines the underlying File
- * (or jar file, in case current a resource in a jar/zip).
- */
- protected File getFileForLastModifiedCheck() throws IOException {
- URL url = toURL();
- if (ResourceUtils.isJarURL(url)) {
- URL actualUrl = ResourceUtils.extractJarFileURL(url);
- return ResourceUtils.getFile(actualUrl, "Jar URL");
- }
- else {
- return toFile();
- }
- }
-
- /**
- * This implementation returns a File reference for the underlying class path
- * resource, provided that it refers to a file in the file system.
- * @see ResourceUtils#getFile(java.net.URI, String)
- */
- protected File getFile(URI uri) throws IOException {
- return ResourceUtils.getFile(uri);
- }
-
-
- @Override
- public boolean exists() {
- try {
- URL url = toURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- return toFile().exists();
- }
- else {
- // Try a URL connection content-length header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- HttpURLConnection httpCon =
- (con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
- if (httpCon != null) {
- int code = httpCon.getResponseCode();
- if (code == HttpURLConnection.HTTP_OK) {
- return true;
- }
- else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
- return false;
- }
- }
- if (con.getContentLength() >= 0) {
- return true;
- }
- if (httpCon != null) {
- // no HTTP OK status, and no content-length header: give up
- httpCon.disconnect();
- return false;
- }
- else {
- // Fall back to stream existence: can we open the stream?
- InputStream is = getInputStream();
- is.close();
- return true;
- }
- }
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- @Override
- public boolean isReadable() {
- try {
- URL url = toURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- File file = toFile();
- return (file.canRead() && !file.isDirectory());
- }
- else {
- return true;
- }
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- @Override
- public long contentLength() throws IOException {
- URL url = toURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- return toFile().length();
- }
- else {
- // Try a URL connection content-length header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- return con.getContentLength();
- }
- }
-
- @Override
- public long lastModified() throws IOException {
- URL url = toURL();
- if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
- // Proceed with file system resolution...
+ /**
+ * This implementation returns a File reference for the underlying class path
+ * resource, provided that it refers to a file in the file system.
+ */
+ @Override
+ public File toFile() throws IOException {
+ URL url = toURL();
+ return ResourceUtils.getFile(url);
+ }
+
+ /**
+ * This implementation determines the underlying File
+ * (or jar file, in case current a resource in a jar/zip).
+ */
+ protected File getFileForLastModifiedCheck() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isJarURL(url)) {
+ URL actualUrl = ResourceUtils.extractJarFileURL(url);
+ return ResourceUtils.getFile(actualUrl, "Jar URL");
+ } else {
+ return toFile();
+ }
+ }
+
+ /**
+ * This implementation returns a File reference for the underlying class path
+ * resource, provided that it refers to a file in the file system.
+ *
+ * @see ResourceUtils#getFile(java.net.URI, String)
+ */
+ protected File getFile(URI uri) throws IOException {
+ return ResourceUtils.getFile(uri);
+ }
+
+
+ @Override
+ public boolean exists() {
+ try {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ return toFile().exists();
+ } else {
+ // Try a URL connection content-length header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ HttpURLConnection httpCon =
+ (con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
+ if (httpCon != null) {
+ int code = httpCon.getResponseCode();
+ if (code == HttpURLConnection.HTTP_OK) {
+ return true;
+ } else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
+ return false;
+ }
+ }
+ if (con.getContentLength() >= 0) {
+ return true;
+ }
+ if (httpCon != null) {
+ // no HTTP OK status, and no content-length header: give up
+ httpCon.disconnect();
+ return false;
+ } else {
+ // Fall back to stream existence: can we open the stream?
+ InputStream is = getInputStream();
+ is.close();
+ return true;
+ }
+ }
+ } catch (IOException ex) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isReadable() {
+ try {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ File file = toFile();
+ return (file.canRead() && !file.isDirectory());
+ } else {
+ return true;
+ }
+ } catch (IOException ex) {
+ return false;
+ }
+ }
+
+ @Override
+ public long contentLength() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ return toFile().length();
+ } else {
+ // Try a URL connection content-length header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ return con.getContentLength();
+ }
+ }
+
+ @Override
+ public long lastModified() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
+ // Proceed with file system resolution...
long lastModified = getFileForLastModifiedCheck().lastModified();
if (lastModified == 0L) {
throw new FileNotFoundException(getDisplayName() +
" cannot be resolved in the file system for resolving its last-modified timestamp");
}
return lastModified;
- }
- else {
- // Try a URL connection last-modified header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- return con.getLastModified();
- }
- }
-
-
- /**
- * Customize the given {@link URLConnection}, obtained in the course current an
- * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
- * <p>Calls {@link ResourceUtils#useCachesIfNecessary(URLConnection)} and
- * delegates to {@link #customizeConnection(HttpURLConnection)} if possible.
- * Can be overridden in subclasses.
- * @param con the URLConnection to customize
- * @throws IOException if thrown from URLConnection methods
- */
- protected void customizeConnection(URLConnection con) throws IOException {
- ResourceUtils.useCachesIfNecessary(con);
- if (con instanceof HttpURLConnection) {
- customizeConnection((HttpURLConnection) con);
- }
- }
-
- /**
- * Customize the given {@link HttpURLConnection}, obtained in the course current an
- * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
- * <p>Sets request method "HEAD" by default. Can be overridden in subclasses.
- * @param con the HttpURLConnection to customize
- * @throws IOException if thrown from HttpURLConnection methods
- */
- protected void customizeConnection(HttpURLConnection con) throws IOException {
- con.setRequestMethod("HEAD");
- }
+ } else {
+ // Try a URL connection last-modified header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ return con.getLastModified();
+ }
+ }
+
+
+ /**
+ * Customize the given {@link URLConnection}, obtained in the course current an
+ * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
+ * <p>Calls {@link ResourceUtils#useCachesIfNecessary(URLConnection)} and
+ * delegates to {@link #customizeConnection(HttpURLConnection)} if possible.
+ * Can be overridden in subclasses.
+ *
+ * @param con the URLConnection to customize
+ * @throws IOException if thrown from URLConnection methods
+ */
+ protected void customizeConnection(URLConnection con) throws IOException {
+ ResourceUtils.useCachesIfNecessary(con);
+ if (con instanceof HttpURLConnection) {
+ customizeConnection((HttpURLConnection) con);
+ }
+ }
+
+ /**
+ * Customize the given {@link HttpURLConnection}, obtained in the course current an
+ * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
+ * <p>Sets request method "HEAD" by default. Can be overridden in subclasses.
+ *
+ * @param con the HttpURLConnection to customize
+ * @throws IOException if thrown from HttpURLConnection methods
+ */
+ protected void customizeConnection(HttpURLConnection con) throws IOException {
+ con.setRequestMethod("HEAD");
+ }
/**
- * Resolve the given resource URL to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUrl the resource URL to resolve
- * @param description a description current the original resource that
- * the URL was created for (for example, a class path location)
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- private File getFile(URL resourceUrl, String description) throws FileNotFoundException {
- Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
- if (!"file".equals(resourceUrl.getProtocol())) {
- throw new FileNotFoundException(
- description + " cannot be resolved to absolute file path " +
- "because it does not reside in the file system: " + resourceUrl);
- }
- try {
- return new File(ResourceUtils.toURI(resourceUrl).getSchemeSpecificPart());
- }
- catch (URISyntaxException ex) {
- // Fallback for URLs that are not valid URIs (should hardly ever happen).
- return new File(resourceUrl.getFile());
- }
- }
+ * Resolve the given resource URL to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ *
+ * @param resourceUrl the resource URL to resolve
+ * @param description a description current the original resource that
+ * the URL was created for (for example, a class path location)
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ private File getFile(URL resourceUrl, String description) throws FileNotFoundException {
+ Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
+ if (!"file".equals(resourceUrl.getProtocol())) {
+ throw new FileNotFoundException(
+ description + " cannot be resolved to absolute file path " +
+ "because it does not reside in the file system: " + resourceUrl);
+ }
+ try {
+ return new File(ResourceUtils.toURI(resourceUrl).getSchemeSpecificPart());
+ } catch (URISyntaxException ex) {
+ // Fallback for URLs that are not valid URIs (should hardly ever happen).
+ return new File(resourceUrl.getFile());
+ }
+ }
}
[09/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java
deleted file mode 100644
index d8fa274..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Objects;
-
-/**
- * <p>Will return a {@code UrlResource} if the location keys is a URL,
- * and a {@code ClassPathResource} if it is a non-URL path or a
- * "classpath:" pseudo-URL.
- *
- * @author Juergen Hoeller
- * @since 10.03.2004
- */
-class DefaultResourceLoader {
-
- /** Pseudo URL prefix for loading from the class path: "classpath:" */
- public static final String CLASSPATH_URL_PREFIX = "classpath:";
-
- private ClassLoader classLoader;
-
-
- /**
- * Create a new DefaultResourceLoader.
- * <p>ClassLoader access will happen using the thread context class loader
- * at the time current this ResourceLoader's initialization.
- * @see java.lang.Thread#getContextClassLoader()
- */
- public DefaultResourceLoader() {
- this.classLoader = ClassUtils.getDefaultClassLoader();
- }
-
- /**
- * Create a new DefaultResourceLoader.
- * @param classLoader the ClassLoader to load class path resources with, or {@code null}
- * for using the thread context class loader at the time current actual resource access
- */
- public DefaultResourceLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
-
- /**
- * Specify the ClassLoader to load class path resources with, or {@code null}
- * for using the thread context class loader at the time current actual resource access.
- * <p>The default is that ClassLoader access will happen using the thread context
- * class loader at the time current this ResourceLoader's initialization.
- */
- void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- /**
- * Return the ClassLoader to load class path resources with.
- * <p>Will get passed to ClassPathResource's constructor for all
- * ClassPathResource objects created by this resource loader.
- * @see ClassPathResource
- */
- public ClassLoader getClassLoader() {
- return (this.classLoader != null ? this.classLoader : ClassUtils.getDefaultClassLoader());
- }
-
-
- public Resource getResource(String location) {
- Objects.requireNonNull(location, "Location must not be null");
- if (location.startsWith("/")) {
- return getResourceByPath(location);
- }
- else if (location.startsWith(CLASSPATH_URL_PREFIX)) {
- return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());
- }
- else {
- try {
- // Try to parse the location as a URL...
- URL url = new URL(location);
- return new UrlResource(url);
- }
- catch (MalformedURLException ex) {
- // No URL -> resolve as resource path.
- return getResourceByPath(location);
- }
- }
- }
-
- /**
- * Return a Resource handle for the resource at the given path.
- * <p>The default implementation supports class path locations. This should
- * be appropriate for standalone implementations but can be overridden,
- * e.g. for implementations targeted at a Servlet container.
- * @param path the path to the resource
- * @return the corresponding Resource handle
- * @see ClassPathResource
- */
- protected Resource getResourceByPath(String path) {
- return new ClassPathContextResource(path, getClassLoader());
- }
-
-
- /**
- * ClassPathResource that explicitly expresses a context-relative path
- * through implementing the ContextResource interface.
- */
- protected static class ClassPathContextResource extends ClassPathResource {
-
- public ClassPathContextResource(String path, ClassLoader classLoader) {
- super(path, classLoader);
- }
-
- public String getPathWithinContext() {
- return getPath();
- }
-
- @Override
- public Resource createRelative(String relativePath) {
- String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
- return new ClassPathContextResource(pathToUse, getClassLoader());
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java
deleted file mode 100644
index dd466f4..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URI;
-import java.net.URL;
-import java.util.Objects;
-
-/**
- * {@link org.apache.tamaya.core.resource.Resource} implementation for {@code java.io.File} handles.
- * Obviously supports resolution as File, and also as URL.
- *
- * @author Juergen Hoeller
- * @since 28.12.2003
- * @see java.io.File
- */
-public class FileSystemResource extends AbstractResource {
-
- private final File file;
-
- private final String path;
-
-
- /**
- * Create a new {@code FileSystemResource} from a {@link File} handle.
- * <p>Note: When building relative resources via {@link #createRelative},
- * the relative path will applyChanges <i>at the same directory level</i>:
- * e.g. new File("C:/dir1"), relative path "dir2" -> "C:/dir2"!
- * If you prefer to have relative paths built underneath the given root
- * directory, use the {@link #FileSystemResource(String) constructor with a file path}
- * to append a trailing slash to the root path: "C:/dir1/", which
- * indicates this directory as root for all relative paths.
- * @param file a File handle
- */
- public FileSystemResource(File file) {
- Objects.requireNonNull(file, "File must not be null");
- this.file = file;
- this.path = StringUtils.cleanPath(file.getPath());
- }
-
- /**
- * Create a new {@code FileSystemResource} from a file path.
- * <p>Note: When building relative resources via {@link #createRelative},
- * it makes a difference whether the specified resource base path here
- * ends with a slash or not. In the case current "C:/dir1/", relative paths
- * will be built underneath that root: e.g. relative path "dir2" ->
- * "C:/dir1/dir2". In the case current "C:/dir1", relative paths will applyChanges
- * at the same directory level: relative path "dir2" -> "C:/dir2".
- * @param path a file path
- */
- public FileSystemResource(String path) {
- Objects.requireNonNull(path, "Path must not be null");
- this.file = new File(path);
- this.path = StringUtils.cleanPath(path);
- }
-
-
- /**
- * Return the file path for this resource.
- */
- public final String getPath() {
- return this.path;
- }
-
-
- /**
- * This implementation returns whether the underlying file exists.
- * @see java.io.File#exists()
- */
- @Override
- public boolean exists() {
- return this.file.exists();
- }
-
- /**
- * This implementation checks whether the underlying file is marked as readable
- * (and corresponds to an actual file with content, not to a directory).
- * @see java.io.File#canRead()
- * @see java.io.File#isDirectory()
- */
- @Override
- public boolean isReadable() {
- return (this.file.canRead() && !this.file.isDirectory());
- }
-
- /**
- * This implementation opens a FileInputStream for the underlying file.
- * @see java.io.FileInputStream
- */
- @Override
- public InputStream getInputStream() throws IOException {
- return new FileInputStream(this.file);
- }
-
- /**
- * This implementation returns a URL for the underlying file.
- * @see java.io.File#toURI()
- */
- @Override
- public URL getURL() throws IOException {
- return this.file.toURI().toURL();
- }
-
- /**
- * This implementation returns a URI for the underlying file.
- * @see java.io.File#toURI()
- */
- @Override
- public URI getURI() throws IOException {
- return this.file.toURI();
- }
-
- /**
- * This implementation returns the underlying File reference.
- */
- @Override
- public File getFile() {
- return this.file;
- }
-
- /**
- * This implementation returns the underlying File's length.
- */
- @Override
- public long contentLength() throws IOException {
- return this.file.length();
- }
-
- /**
- * This implementation creates a FileSystemResource, applying the given path
- * relative to the path current the underlying file current this resource descriptor.
- * @see StringUtils#applyRelativePath(String, String)
- */
- @Override
- public Resource createRelative(String relativePath) {
- String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
- return new FileSystemResource(pathToUse);
- }
-
- /**
- * This implementation returns the name current the file.
- * @see java.io.File#getName()
- */
- @Override
- public String getFilename() {
- return this.file.getName();
- }
-
- /**
- * This implementation returns a description that includes the absolute
- * path current the file.
- * @see java.io.File#getAbsolutePath()
- */
- @Override
- public String getDescription() {
- return "file [" + this.file.getAbsolutePath() + "]";
- }
-
-
- // implementation current WritableResource
-
- /**
- * This implementation checks whether the underlying file is marked as writable
- * (and corresponds to an actual file with content, not to a directory).
- * @see java.io.File#canWrite()
- * @see java.io.File#isDirectory()
- */
- public boolean isWritable() {
- return (this.file.canWrite() && !this.file.isDirectory());
- }
-
- /**
- * This implementation opens a FileOutputStream for the underlying file.
- * @see java.io.FileOutputStream
- */
- public OutputStream getOutputStream() throws IOException {
- return new FileOutputStream(this.file);
- }
-
-
- /**
- * This implementation compares the underlying File references.
- */
- @Override
- public boolean equals(Object obj) {
- return (obj == this ||
- (obj instanceof FileSystemResource && this.path.equals(((FileSystemResource) obj).path)));
- }
-
- /**
- * This implementation returns the hash code current the underlying File reference.
- */
- @Override
- public int hashCode() {
- return this.path.hashCode();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/InputStreamResource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/InputStreamResource.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/InputStreamResource.java
deleted file mode 100644
index 97a4ad9..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/InputStreamResource.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright 2002-2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tamaya.core.internal.resources.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Objects;
-
-/**
- * {@link org.apache.tamaya.core.resource.Resource} implementation for a given InputStream. Should only
- * be used if no specific Resource implementation is applicable.
- * In particular, prefer {@code ByteArrayResource} or any current the
- * file-based Resource implementations where possible.
- *
- * <p>In contrast to other Resource implementations, this is a descriptor
- * for an <i>already opened</i> resource - therefore returning "true" from
- * {@code isOpen()}. Do not use it if you need to keep the resource
- * descriptor somewhere, or if you need to read a stream multiple times.
- *
- * @author Juergen Hoeller
- * @since 28.12.2003
- */
-public class InputStreamResource extends AbstractResource {
-
- private final InputStream inputStream;
-
- private final String description;
-
- private boolean read = false;
-
-
- /**
- * Create a new InputStreamResource.
- * @param inputStream the InputStream to use
- */
- public InputStreamResource(InputStream inputStream) {
- this(inputStream, "resource loaded through InputStream");
- }
-
- /**
- * Create a new InputStreamResource.
- * @param inputStream the InputStream to use
- * @param description where the InputStream comes from
- */
- public InputStreamResource(InputStream inputStream, String description) {
- this.inputStream = Objects.requireNonNull(inputStream);
- this.description = (description != null ? description : "");
- }
-
-
- /**
- * This implementation always returns {@code true}.
- */
- @Override
- public boolean exists() {
- return true;
- }
-
- /**
- * This implementation always returns {@code true}.
- */
- @Override
- public boolean isOpen() {
- return true;
- }
-
- /**
- * This implementation throws IllegalStateException if attempting to
- * read the underlying stream multiple times.
- */
- @Override
- public InputStream getInputStream() throws IOException {
- if (this.read) {
- throw new IllegalStateException("InputStream has already been read - " +
- "do not use InputStreamResource if a stream needs to be read multiple times");
- }
- this.read = true;
- return this.inputStream;
- }
-
- /**
- * This implementation returns the passed-in description, if any.
- */
- @Override
- public String getDescription() {
- return this.description;
- }
-
-
- /**
- * This implementation compares the underlying InputStream.
- */
- @Override
- public boolean equals(Object obj) {
- return (obj == this ||
- (obj instanceof InputStreamResource && ((InputStreamResource) obj).inputStream.equals(this.inputStream)));
- }
-
- /**
- * This implementation returns the hash code current the underlying InputStream.
- */
- @Override
- public int hashCode() {
- return this.inputStream.hashCode();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/PathMatchingResourcePatternResolver.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/PathMatchingResourcePatternResolver.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/PathMatchingResourcePatternResolver.java
deleted file mode 100644
index 900a53f..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/PathMatchingResourcePatternResolver.java
+++ /dev/null
@@ -1,729 +0,0 @@
-/*
- * Copyright 2002-2008 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.JarURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import java.lang.reflect.InvocationHandler;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URLClassLoader;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-
-/**
- * A {@code ResourcePatternResolver} implementation that is able to resolve a
- * specified resource location path into one or more matching Resources.
- * The source path may be a simple path which has a one-to-one annotation to a
- * target {@code org.springframework.core.io.Resource}, or alternatively
- * may contain the special "{@code classpath*:}" prefix and/or
- * internal Ant-style regular expressions (matched using Spring's
- * {@code org.springframework.util.AntPathMatcher} utility).
- * Both current the latter are effectively wildcards.
- *
- * <p><b>No Wildcards:</b>
- *
- * <p>In the simple case, if the specified location path does not start with the
- * {@code "classpath*:}" prefix, and does not contain a PathMatcher pattern,
- * this resolver will simply return a single resource via a
- * {@code getResource()} call on the underlying {@code ResourceLoader}.
- * Examples are real URLs such as "{@code file:C:/context.xml}", pseudo-URLs
- * such as "{@code classpath:/context.xml}", and simple unprefixed paths
- * such as "{@code /WEB-INF/context.xml}". The latter will resolve in a
- * fashion specific to the underlying {@code ResourceLoader} (e.g.
- * {@code ServletContextResource} for a {@code WebApplicationContext}).
- *
- * <p><b>Ant-style Patterns:</b>
- *
- * <p>When the path location contains an Ant-style pattern, e.g.:
- * <pre class="code">
- * /WEB-INF/*-context.xml
- * com/mycompany/**/applicationContext.xml
- * file:C:/some/path/*-context.xml
- * classpath:com/mycompany/**/applicationContext.xml</pre>
- * the resolver follows a more complex but defined procedure to try to resolve
- * the wildcard. It produces a {@code Resource} for the path up to the last
- * non-wildcard segment and obtains a {@code URL} from it. If this URL is
- * not a "{@code jar:}" URL or container-specific variant (e.g.
- * "{@code zip:}" in WebLogic, "{@code wsjar}" in WebSphere", etc.),
- * then a {@code java.io.File} is obtained from it, and used to resolve the
- * wildcard by walking the filesystem. In the case current a jar URL, the resolver
- * either gets a {@code java.net.JarURLConnection} from it, or manually parses
- * the jar URL, and then traverses the contents current the jar file, to resolve the
- * wildcards.
- *
- * <p><b>Implications on portability:</b>
- *
- * <p>If the specified path is already a file URL (either explicitly, or
- * implicitly because the base {@code ResourceLoader} is a filesystem one,
- * then wildcarding is guaranteed to work in a completely portable fashion.
- *
- * <p>If the specified path is a classpath location, then the resolver must
- * obtain the last non-wildcard path segment URL via a
- * {@code Classloader.getResource()} call. Since this is just a
- * node current the path (not the file at the end) it is actually undefined
- * (in the ClassLoader Javadocs) exactly what sort current a URL is returned in
- * this case. In practice, it is usually a {@code java.io.File} representing
- * the directory, where the classpath resource resolves to a filesystem
- * location, or a jar URL current some sort, where the classpath resource resolves
- * to a jar location. Still, there is a portability concern on this operation.
- *
- * <p>If a jar URL is obtained for the last non-wildcard segment, the resolver
- * must be able to get a {@code java.net.JarURLConnection} from it, or
- * manually parse the jar URL, to be able to walk the contents current the jar,
- * and resolve the wildcard. This will work in most environments, but will
- * fail in others, and it is strongly recommended that the wildcard
- * resolution current resources coming from jars be thoroughly tested in your
- * specific environment before you rely on it.
- *
- * <p><b>{@code classpath*:} Prefix:</b>
- *
- * <p>There is special support for retrieving multiple class path resources with
- * the same name, via the "{@code classpath*:}" prefix. For example,
- * "{@code classpath*:META-INF/beans.xml}" will find all "beans.xml"
- * files in the class path, be it in "classes" directories or in JAR files.
- * This is particularly useful for autodetecting config files current the same name
- * at the same location within each jar file. Internally, this happens via a
- * {@code ClassLoader.getResources()} call, and is completely portable.
- *
- * <p>The "classpath*:" prefix can also be combined with a PathMatcher pattern in
- * the rest current the location path, for example "classpath*:META-INF/*-beans.xml".
- * In this case, the resolution strategy is fairly simple: a
- * {@code ClassLoader.getResources()} call is used on the last non-wildcard
- * path segment to get all the matching resources in the class loader hierarchy,
- * and then off each resource the same PathMatcher resolution strategy described
- * above is used for the wildcard subpath.
- *
- * <p><b>Other notes:</b>
- *
- * <p><b>WARNING:</b> Note that "{@code classpath*:}" when combined with
- * Ant-style patterns will only work reliably with at least one root directory
- * before the pattern starts, unless the actual target files reside in the file
- * system. This means that a pattern like "{@code classpath*:*.xml}" will
- * <i>not</i> retrieve files from the root current jar files but rather only from the
- * root current expanded directories. This originates from a limitation in the JDK's
- * {@code ClassLoader.getResources()} method which only returns file system
- * locations for a passed-in empty String (indicating potential roots to search).
- *
- * <p><b>WARNING:</b> Ant-style patterns with "classpath:" resources are not
- * guaranteed to find matching resources if the root package to search is available
- * in multiple class path locations. This is because a resource such as
- * <pre class="code">
- * com/mycompany/package1/service-context.xml
- * </pre>
- * may be in only one location, but when a path such as
- * <pre class="code">
- * classpath:com/mycompany/**/service-context.xml
- * </pre>
- * is used to try to resolve it, the resolver will work off the (first) URL
- * returned by {@code getResource("com/mycompany");}. If this base package
- * node exists in multiple classloader locations, the actual end resource may
- * not be underneath. Therefore, preferably, use "{@code classpath*:}" with the same
- * Ant-style pattern in such a case, which will search <i>all</i> class path
- * locations that contain the root package.
- *
- * @author Juergen Hoeller
- * @author Colin Sampaleanu
- * @author Marius Bogoevici
- * @author Costin Leau
- * @since 1.0.2
- * @see ClassLoader#getResources(String)
- */
-public final class PathMatchingResourcePatternResolver{
-
- private static final Logger logger = Logger.getLogger(PathMatchingResourcePatternResolver.class.getName());
- private static final java.lang.String CLASSPATH_ALL_URL_PREFIX = "classpath:";
-
- private static Method equinoxResolveMethod;
-
- static {
- try {
- // Detect Equinox OSGi (e.g. on WebSphere 6.1)
- Class<?> fileLocatorClass = ClassUtils.forName("org.eclipse.core.runtime.FileLocator",
- PathMatchingResourcePatternResolver.class.getClassLoader());
- equinoxResolveMethod = fileLocatorClass.getMethod("resolve", URL.class);
- logger.finest("Found Equinox FileLocator for OSGi bundle URL resolution");
- }
- catch (Throwable ex) {
- equinoxResolveMethod = null;
- }
- }
-
-
- private final DefaultResourceLoader resourceLoader;
-
- private AntPathMatcher pathMatcher = new AntPathMatcher();
-
- private static Map<ClassLoader, PathMatchingResourcePatternResolver> resolvers = new ConcurrentHashMap<>();
-
- public static PathMatchingResourcePatternResolver of(ClassLoader loader){
- return resolvers.computeIfAbsent(loader, PathMatchingResourcePatternResolver::new);
- }
-
- /**
- * Create a new PathMatchingResourcePatternResolver.
- * <p>ClassLoader access will happen via the thread context class loader.
- */
- public PathMatchingResourcePatternResolver() {
- this.resourceLoader = new DefaultResourceLoader();
- }
-
- /**
- * Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader.
- * @param classLoader the ClassLoader to load classpath resources with,
- * or {@code null} for using the thread context class loader
- * at the time current actual resource access
- * @see DefaultResourceLoader
- */
- public PathMatchingResourcePatternResolver(ClassLoader classLoader) {
- this.resourceLoader = new DefaultResourceLoader(classLoader);
- }
-
- public ClassLoader getClassLoader() {
- return resourceLoader.getClassLoader();
- }
-
- /**
- * Return the PathMatcher that this resource pattern resolver uses.
- */
- public AntPathMatcher getPathMatcher() {
- return this.pathMatcher;
- }
-
- public Resource getResource(String location) {
- return resourceLoader.getResource(location);
- }
-
- public Resource[] getResources(String locationPattern) throws IOException {
- Objects.requireNonNull(locationPattern, "Location pattern must not be null");
- if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) {
- // a class path resource (multiple resources for same name possible)
- if (getPathMatcher().isPattern(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()))) {
- // a class path resource pattern
- return findPathMatchingResources(locationPattern);
- }
- else {
- // all class path resources with the given name
- return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()));
- }
- }
- else {
- // Only look for a pattern after a prefix here
- // (to not get fooled by a pattern symbol in a strange prefix).
- int prefixEnd = locationPattern.indexOf(':') + 1;
- if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) {
- // a file pattern
- return findPathMatchingResources(locationPattern);
- }
- else {
- // a single resource with the given name
- return new Resource[] {this.resourceLoader.getResource(locationPattern)};
- }
- }
- }
-
- /**
- * Find all class location resources with the given location via the ClassLoader.
- * Delegates to {@link #doFindAllClassPathResources(String)}.
- * @param location the absolute path within the classpath
- * @return the result as Resource array
- * @throws IOException in case current I/O errors
- * @see java.lang.ClassLoader#getResources
- * @see #convertClassLoaderURL
- */
- protected Resource[] findAllClassPathResources(String location) throws IOException {
- String path = location;
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
- Set<Resource> result = doFindAllClassPathResources(path);
- return result.toArray(new Resource[result.size()]);
- }
-
- /**
- * Find all class location resources with the given path via the ClassLoader.
- * Called by {@link #findAllClassPathResources(String)}.
- * @param path the absolute path within the classpath (never a leading slash)
- * @return a mutable Set current matching Resource instances
- */
- protected Set<Resource> doFindAllClassPathResources(String path) throws IOException {
- Set<Resource> result = new LinkedHashSet<>(16);
- ClassLoader cl = getClassLoader();
- Enumeration<URL> resourceUrls = (cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path));
- while (resourceUrls.hasMoreElements()) {
- URL url = resourceUrls.nextElement();
- result.add(convertClassLoaderURL(url));
- }
- if ("".equals(path)) {
- // The above result is likely to be incomplete, i.e. only containing file system references.
- // We need to have pointers to each current the jar files on the classpath as well...
- addAllClassLoaderJarRoots(cl, result);
- }
- return result;
- }
-
- /**
- * Convert the given URL as returned from the ClassLoader into a {@link Resource}.
- * <p>The default implementation simply creates a {@link UrlResource} instance.
- * @param url a URL as returned from the ClassLoader
- * @return the corresponding Resource object
- * @see java.lang.ClassLoader#getResources
- * @see Resource
- */
- protected Resource convertClassLoaderURL(URL url) {
- return new UrlResource(url);
- }
-
- /**
- * Search all {@link URLClassLoader} URLs for jar file references and add them to the
- * given set current resources in the form current pointers to the root current the jar file content.
- * @param classLoader the ClassLoader to search (including its ancestors)
- * @param result the set current resources to add jar roots to
- */
- protected void addAllClassLoaderJarRoots(ClassLoader classLoader, Set<Resource> result) {
- if (classLoader instanceof URLClassLoader) {
- try {
- for (URL url : ((URLClassLoader) classLoader).getURLs()) {
- if (ResourceUtils.isJarFileURL(url)) {
- try {
- UrlResource jarResource = new UrlResource(
- ResourceUtils.JAR_URL_PREFIX + url.toString() + ResourceUtils.JAR_URL_SEPARATOR);
- if (jarResource.exists()) {
- result.add(jarResource);
- }
- }
- catch (MalformedURLException ex) {
- logger.finest(() -> "Cannot search for matching files underneath [" + url +
- "] because it cannot be converted to a valid 'jar:' URL: " + ex.getMessage());
- }
- }
- }
- }
- catch (Exception ex) {
- logger.finest(() -> "Cannot introspect jar files since ClassLoader [" + classLoader +
- "] does not support 'getURLs()': " + ex);
- }
- }
- if (classLoader != null) {
- try {
- addAllClassLoaderJarRoots(classLoader.getParent(), result);
- }
- catch (Exception ex) {
- logger.finest(() -> "Cannot introspect jar files in parent ClassLoader since [" + classLoader +
- "] does not support 'getParent()': " + ex);
- }
- }
- }
-
- /**
- * Find all resources that match the given location pattern via the
- * Ant-style PathMatcher. Supports resources in jar files and zip files
- * and in the file system.
- * @param locationPattern the location pattern to match
- * @return the result as Resource array
- * @throws IOException in case current I/O errors
- * @see #doFindPathMatchingJarResources
- * @see #doFindPathMatchingFileResources
- */
- protected Resource[] findPathMatchingResources(String locationPattern) throws IOException {
- String rootDirPath = determineRootDir(locationPattern);
- String subPattern = locationPattern.substring(rootDirPath.length());
- Resource[] rootDirResources = getResources(rootDirPath);
- Set<Resource> result = new LinkedHashSet<>(16);
- for (Resource rootDirResource : rootDirResources) {
- rootDirResource = resolveRootDirResource(rootDirResource);
- if (rootDirResource.getURL().getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
- result.addAll(VfsResourceMatchingDelegate.findMatchingResources(rootDirResource, subPattern, getPathMatcher()));
- }
- else if (isJarResource(rootDirResource)) {
- result.addAll(doFindPathMatchingJarResources(rootDirResource, subPattern));
- }
- else {
- result.addAll(doFindPathMatchingFileResources(rootDirResource, subPattern));
- }
- }
- logger.finest(() -> "Resolved location pattern [" + locationPattern + "] to resources " + result);
- return result.toArray(new Resource[result.size()]);
- }
-
- /**
- * Determine the root directory for the given location.
- * <p>Used for determining the starting point for file matching,
- * resolving the root directory location to a {@code java.io.File}
- * and passing it into {@code retrieveMatchingFiles}, with the
- * remainder current the location as pattern.
- * <p>Will return "/WEB-INF/" for the pattern "/WEB-INF/*.xml",
- * for example.
- * @param location the location to check
- * @return the part current the location that denotes the root directory
- * @see #retrieveMatchingFiles
- */
- protected String determineRootDir(String location) {
- int prefixEnd = location.indexOf(':') + 1;
- int rootDirEnd = location.length();
- while (rootDirEnd > prefixEnd && getPathMatcher().isPattern(location.substring(prefixEnd, rootDirEnd))) {
- rootDirEnd = location.lastIndexOf('/', rootDirEnd - 2) + 1;
- }
- if (rootDirEnd == 0) {
- rootDirEnd = prefixEnd;
- }
- return location.substring(0, rootDirEnd);
- }
-
- /**
- * Resolve the specified resource for path matching.
- * <p>The default implementation detects an Equinox OSGi "bundleresource:"
- * / "bundleentry:" URL and resolves it into a standard jar file URL that
- * can be traversed using Spring's standard jar file traversal algorithm.
- * @param original the resource to resolve
- * @return the resolved resource (may be identical to the passed-in resource)
- * @throws IOException in case current resolution failure
- */
- protected Resource resolveRootDirResource(Resource original) throws IOException {
- if (equinoxResolveMethod != null) {
- URL url = original.getURL();
- if (url.getProtocol().startsWith("bundle")) {
- try {
- return new UrlResource((URL) equinoxResolveMethod.invoke(url));
- } catch (Exception e) {
- ReflectionUtils.handleReflectionException(e);
- }
- }
- }
- return original;
- }
-
- /**
- * Return whether the given resource handle indicates a jar resource
- * that the {@code doFindPathMatchingJarResources} method can handle.
- * <p>The default implementation checks against the URL protocols
- * "jar", "zip" and "wsjar" (the latter are used by BEA WebLogic Server
- * and IBM WebSphere, respectively, but can be treated like jar files).
- * @param resource the resource handle to check
- * (usually the root directory to start path matching from)
- * @see #doFindPathMatchingJarResources
- * @see ResourceUtils#isJarURL
- */
- protected boolean isJarResource(Resource resource) throws IOException {
- return ResourceUtils.isJarURL(resource.getURL());
- }
-
- /**
- * Find all resources in jar files that match the given location pattern
- * via the Ant-style PathMatcher.
- * @param rootDirResource the root directory as Resource
- * @param subPattern the sub pattern to match (below the root directory)
- * @return a mutable Set current matching Resource instances
- * @throws IOException in case current I/O errors
- * @see java.net.JarURLConnection
- */
- protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource, String subPattern)
- throws IOException {
-
- URLConnection con = rootDirResource.getURL().openConnection();
- JarFile jarFile;
- String jarFileUrl;
- String rootEntryPath;
- boolean newJarFile = false;
-
- if (con instanceof JarURLConnection) {
- // Should usually be the case for traditional JAR files.
- JarURLConnection jarCon = (JarURLConnection) con;
- ResourceUtils.useCachesIfNecessary(jarCon);
- jarFile = jarCon.getJarFile();
- jarFileUrl = jarCon.getJarFileURL().toExternalForm();
- JarEntry jarEntry = jarCon.getJarEntry();
- rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
- }
- else {
- // No JarURLConnection -> need to resort to URL file parsing.
- // We'll assume URLs current the format "jar:path!/entry", with the protocol
- // being arbitrary as long as following the entry format.
- // We'll also handle paths with and without leading "file:" prefix.
- String urlFile = rootDirResource.getURL().getFile();
- int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
- if (separatorIndex != -1) {
- jarFileUrl = urlFile.substring(0, separatorIndex);
- rootEntryPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length());
- jarFile = getJarFile(jarFileUrl);
- }
- else {
- jarFile = new JarFile(urlFile);
- jarFileUrl = urlFile;
- rootEntryPath = "";
- }
- newJarFile = true;
- }
-
- try {
- logger.finest("Looking for matching resources in jar file [" + jarFileUrl + "]");
- if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) {
- // Root entry path must end with slash to allow for proper matching.
- // The Sun JRE does not return a slash here, but BEA JRockit does.
- rootEntryPath = rootEntryPath + "/";
- }
- Set<Resource> result = new LinkedHashSet<>(8);
- for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
- JarEntry entry = entries.nextElement();
- String entryPath = entry.getName();
- if (entryPath.startsWith(rootEntryPath)) {
- String relativePath = entryPath.substring(rootEntryPath.length());
- if (getPathMatcher().match(subPattern, relativePath)) {
- result.add(rootDirResource.createRelative(relativePath));
- }
- }
- }
- return result;
- }
- finally {
- // Close jar file, but only if freshly obtained -
- // not from JarURLConnection, which might cache the file reference.
- if (newJarFile) {
- jarFile.close();
- }
- }
- }
-
- /**
- * Resolve the given jar file URL into a JarFile object.
- */
- protected JarFile getJarFile(String jarFileUrl) throws IOException {
- if (jarFileUrl.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
- try {
- return new JarFile(ResourceUtils.toURI(jarFileUrl).getSchemeSpecificPart());
- }
- catch (URISyntaxException ex) {
- // Fallback for URLs that are not valid URIs (should hardly ever happen).
- return new JarFile(jarFileUrl.substring(ResourceUtils.FILE_URL_PREFIX.length()));
- }
- }
- else {
- return new JarFile(jarFileUrl);
- }
- }
-
- /**
- * Find all resources in the file system that match the given location pattern
- * via the Ant-style PathMatcher.
- * @param rootDirResource the root directory as Resource
- * @param subPattern the sub pattern to match (below the root directory)
- * @return a mutable Set current matching Resource instances
- * @throws IOException in case current I/O errors
- * @see #retrieveMatchingFiles
- */
- protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
- throws IOException {
-
- File rootDir;
- try {
- rootDir = rootDirResource.getFile().getAbsoluteFile();
- }
- catch (IOException ex) {
- logger.log(Level.WARNING, ex, () -> "Cannot search for matching files underneath " + rootDirResource +
- " because it does not correspond to a directory in the file system");
- return Collections.emptySet();
- }
- return doFindMatchingFileSystemResources(rootDir, subPattern);
- }
-
- /**
- * Find all resources in the file system that match the given location pattern
- * via the Ant-style PathMatcher.
- * @param rootDir the root directory in the file system
- * @param subPattern the sub pattern to match (below the root directory)
- * @return a mutable Set current matching Resource instances
- * @throws IOException in case current I/O errors
- * @see #retrieveMatchingFiles
- */
- protected Set<Resource> doFindMatchingFileSystemResources(File rootDir, String subPattern) throws IOException {
- logger.finest(() -> "Looking for matching resources in directory tree [" + rootDir.getPath() + "]");
- Set<File> matchingFiles = retrieveMatchingFiles(rootDir, subPattern);
- Set<Resource> result = new LinkedHashSet<>(matchingFiles.size());
- result.addAll(matchingFiles.stream().map(FileSystemResource::new).collect(Collectors.toList()));
- return result;
- }
-
- /**
- * Retrieve files that match the given path pattern,
- * checking the given directory and its subdirectories.
- * @param rootDir the directory to start from
- * @param pattern the pattern to match against,
- * relative to the root directory
- * @return a mutable Set current matching Resource instances
- * @throws IOException if directory contents could not be retrieved
- */
- protected Set<File> retrieveMatchingFiles(File rootDir, String pattern) throws IOException {
- if (!rootDir.exists()) {
- // Silently skip non-existing directories.
- logger.finest(() -> "Skipping [" + rootDir.getAbsolutePath() + "] because it does not exist");
- return Collections.emptySet();
- }
- if (!rootDir.isDirectory()) {
- // Complain louder if it exists but is no directory.
- logger.log(Level.WARNING, () -> "Skipping [" + rootDir.getAbsolutePath() + "] because it does not denote a directory");
- return Collections.emptySet();
- }
- if (!rootDir.canRead()) {
- logger.log(Level.WARNING, () -> "Cannot search for matching files underneath directory [" + rootDir.getAbsolutePath() +
- "] because the application is not allowed to read the directory");
- return Collections.emptySet();
- }
- String fullPattern = StringUtils.replace(rootDir.getAbsolutePath(), File.separator, "/");
- if (!pattern.startsWith("/")) {
- fullPattern += "/";
- }
- fullPattern = fullPattern + StringUtils.replace(pattern, File.separator, "/");
- Set<File> result = new LinkedHashSet<>(8);
- doRetrieveMatchingFiles(fullPattern, rootDir, result);
- return result;
- }
-
- /**
- * Recursively retrieve files that match the given pattern,
- * adding them to the given result list.
- * @param fullPattern the pattern to match against,
- * with prepended root directory path
- * @param dir the current directory
- * @param result the Set current matching File instances to add to
- * @throws IOException if directory contents could not be retrieved
- */
- protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> result) throws IOException {
- logger.finest(() -> "Searching directory [" + dir.getAbsolutePath() +
- "] for files matching pattern [" + fullPattern + "]");
- File[] dirContents = dir.listFiles();
- if (dirContents == null) {
- logger.log(Level.WARNING, () -> "Could not retrieve contents current directory [" + dir.getAbsolutePath() + "]");
- return;
- }
- for (File content : dirContents) {
- String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/");
- if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) {
- if (!content.canRead()) {
- logger.finest(() -> "Skipping subdirectory [" + dir.getAbsolutePath() +
- "] because the application is not allowed to read the directory");
- }
- else {
- doRetrieveMatchingFiles(fullPattern, content, result);
- }
- }
- if (getPathMatcher().match(fullPattern, currPath)) {
- result.add(content);
- }
- }
- }
-
-
- /**
- * Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
- */
- private static class VfsResourceMatchingDelegate {
-
- public static Set<Resource> findMatchingResources(
- Resource rootResource, String locationPattern, AntPathMatcher pathMatcher) throws IOException {
- Object root = VfsUtils.getRoot(rootResource.getURL());
- PatternVirtualFileVisitor visitor =
- new PatternVirtualFileVisitor(VfsUtils.getPath(root), locationPattern, pathMatcher);
- VfsUtils.visit(root, visitor);
- return visitor.getResources();
- }
- }
-
-
- /**
- * VFS visitor for path matching purposes.
- */
- @SuppressWarnings("unused")
- private static class PatternVirtualFileVisitor implements InvocationHandler {
-
- private final String subPattern;
-
- private final AntPathMatcher pathMatcher;
-
- private final String rootPath;
-
- private final Set<Resource> resources = new LinkedHashSet<>();
-
- public PatternVirtualFileVisitor(String rootPath, String subPattern, AntPathMatcher pathMatcher) {
- this.subPattern = subPattern;
- this.pathMatcher = pathMatcher;
- this.rootPath = (rootPath.length() == 0 || rootPath.endsWith("/") ? rootPath : rootPath + "/");
- }
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- String methodName = method.getName();
- if (Object.class.equals(method.getDeclaringClass())) {
- if (methodName.equals("equals")) {
- // Only consider equal when proxies are identical.
- return (proxy == args[0]);
- }
- else if (methodName.equals("hashCode")) {
- return System.identityHashCode(proxy);
- }
- }
- else if ("getAttributes".equals(methodName)) {
- return getAttributes();
- }
- else if ("visit".equals(methodName)) {
- visit(args[0]);
- return null;
- }
- else if ("toString".equals(methodName)) {
- return toString();
- }
-
- throw new IllegalStateException("Unexpected method invocation: " + method);
- }
-
- public void visit(Object vfsResource) {
- if (this.pathMatcher.match(this.subPattern,
- VfsUtils.getPath(vfsResource).substring(this.rootPath.length()))) {
- this.resources.add(new VfsResource(vfsResource));
- }
- }
-
- public Object getAttributes() {
- return VfsUtils.getVisitorAttribute();
- }
-
- public Set<Resource> getResources() {
- return this.resources;
- }
-
- public int size() {
- return this.resources.size();
- }
-
- @Override
- public String toString() {
- return "sub-pattern: " + this.subPattern + ", resources: " + this.resources;
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ReflectionUtils.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ReflectionUtils.java
deleted file mode 100644
index 4b50d3d..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ReflectionUtils.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
-* Copyright 2002-2014 the original author or authors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.tamaya.core.internal.resources.io;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
-* Simple utility class for working with the reflection API and handling
-* reflection exceptions.
-*
-* <p>Only intended for internal use.
-*
-* @author Juergen Hoeller
-* @author Rob Harrop
-* @author Rod Johnson
-* @author Costin Leau
-* @author Sam Brannen
-* @author Chris Beams
-* @since 1.2.2
-*/
-public abstract class ReflectionUtils {
- /**
- * Cache for {@link Class#getDeclaredMethods()}, allowing for fast resolution.
- */
- private static final Map<Class<?>, Method[]> declaredMethodsCache =
- new ConcurrentHashMap<>(256);
-
-
- /**
- * Attempt to find a {@link Field field} on the supplied {@link Class} with the
- * supplied {@code name}. Searches all superclasses up to {@link Object}.
- * @param clazz the class to introspect
- * @param name the name current the field
- * @return the corresponding Field object, or {@code null} if not found
- */
- public static Field findField(Class<?> clazz, String name) {
- return findField(clazz, name, null);
- }
-
- /**
- * Attempt to find a {@link Field field} on the supplied {@link Class} with the
- * supplied {@code name} and/or {@link Class type}. Searches all superclasses
- * up to {@link Object}.
- * @param clazz the class to introspect
- * @param name the name current the field (may be {@code null} if type is specified)
- * @param type the type current the field (may be {@code null} if name is specified)
- * @return the corresponding Field object, or {@code null} if not found
- */
- public static Field findField(Class<?> clazz, String name, Class<?> type) {
- Objects.requireNonNull(clazz, "Class must not be null");
- if(name == null && type == null) throw new IllegalArgumentException("Either name or type current the field must be specified");
- Class<?> searchType = clazz;
- while (!Object.class.equals(searchType) && searchType != null) {
- Field[] fields = searchType.getDeclaredFields();
- for (Field field : fields) {
- if ((name == null || name.equals(field.getName())) && (type == null || type.equals(field.getType()))) {
- return field;
- }
- }
- searchType = searchType.getSuperclass();
- }
- return null;
- }
-
- /**
- * Attempt to find a {@link Method} on the supplied class with the supplied name
- * and no parameters. Searches all superclasses up to {@code Object}.
- * <p>Returns {@code null} if no {@link Method} can be found.
- * @param clazz the class to introspect
- * @param name the name current the method
- * @return the Method object, or {@code null} if none found
- */
- public static Method findMethod(Class<?> clazz, String name) {
- return findMethod(clazz, name, new Class<?>[0]);
- }
-
- /**
- * Attempt to find a {@link Method} on the supplied class with the supplied name
- * and parameter types. Searches all superclasses up to {@code Object}.
- * <p>Returns {@code null} if no {@link Method} can be found.
- * @param clazz the class to introspect
- * @param name the name current the method
- * @param paramTypes the parameter types current the method
- * (may be {@code null} to indicate any signature)
- * @return the Method object, or {@code null} if none found
- */
- public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
- Objects.requireNonNull(clazz, "Class must not be null");
- Objects.requireNonNull(name, "Method name must not be null");
- Class<?> searchType = clazz;
- while (searchType != null) {
- Method[] methods = (searchType.isInterface() ? searchType.getMethods() : getDeclaredMethods(searchType));
- for (Method method : methods) {
- if (name.equals(method.getName()) &&
- (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) {
- return method;
- }
- }
- searchType = searchType.getSuperclass();
- }
- return null;
- }
-
- /**
- * Handle the given reflection exception. Should only be called if no
- * checked exception is expected to be thrown by the target method.
- * <p>Throws the underlying RuntimeException or Error in case current an
- * InvocationTargetException with such a root cause. Throws an
- * IllegalStateException with an appropriate message else.
- * @param ex the reflection exception to handle
- */
- public static void handleReflectionException(Exception ex) {
- if (ex instanceof NoSuchMethodException) {
- throw new IllegalStateException("Method not found: " + ex.getMessage());
- }
- if (ex instanceof IllegalAccessException) {
- throw new IllegalStateException("Could not access method: " + ex.getMessage());
- }
- if (ex instanceof InvocationTargetException) {
- handleInvocationTargetException((InvocationTargetException) ex);
- }
- if (ex instanceof RuntimeException) {
- throw (RuntimeException) ex;
- }
- throw new UndeclaredThrowableException(ex);
- }
-
- /**
- * Handle the given invocation target exception. Should only be called if no
- * checked exception is expected to be thrown by the target method.
- * <p>Throws the underlying RuntimeException or Error in case current such a root
- * cause. Throws an IllegalStateException else.
- * @param ex the invocation target exception to handle
- */
- public static void handleInvocationTargetException(InvocationTargetException ex) {
- rethrowRuntimeException(ex.getTargetException());
- }
-
- /**
- * Rethrow the given {@link Throwable exception}, which is presumably the
- * <em>target exception</em> current an {@link InvocationTargetException}. Should
- * only be called if no checked exception is expected to be thrown by the
- * target method.
- * <p>Rethrows the underlying exception cast to an {@link RuntimeException} or
- * {@link Error} if appropriate; otherwise, throws an
- * {@link IllegalStateException}.
- * @param ex the exception to rethrow
- * @throws RuntimeException the rethrown exception
- */
- public static void rethrowRuntimeException(Throwable ex) {
- if (ex instanceof RuntimeException) {
- throw (RuntimeException) ex;
- }
- if (ex instanceof Error) {
- throw (Error) ex;
- }
- throw new UndeclaredThrowableException(ex);
- }
-
- /**
- * This method retrieves {@link Class#getDeclaredMethods()} from a local cache
- * in order to avoid the JVM's SecurityManager check and defensive array copying.
- */
- private static Method[] getDeclaredMethods(Class<?> clazz) {
- Method[] result = declaredMethodsCache.get(clazz);
- if (result == null) {
- result = clazz.getDeclaredMethods();
- declaredMethodsCache.put(clazz, result);
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ResourceUtils.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ResourceUtils.java
deleted file mode 100644
index 480f4b4..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ResourceUtils.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
-* Copyright 2002-2014 the original author or authors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.tamaya.core.internal.resources.io;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Objects;
-
-/**
-* Utility methods for resolving resource locations to files in the
-* file system. Mainly for internal use within the framework.
-*
-* <p>Consider using Spring's Resource abstraction in the core package
-* for handling all kinds current file resources in a uniform manner.
-* {@code org.springframework.core.io.ResourceLoader}'s {@code getResource()}
-* method can resolve any location to a {@code org.springframework.core.io.Resource}
-* object, which in turn allows one to obtain a {@code java.io.File} in the
-* file system through its {@code getFile()} method.
-*
-* <p>The main reason for these utility methods for resource location handling
-* is to support {@code Log4jConfigurer}, which must be able to resolve
-* resource locations <i>before the logging system has been initialized</i>.
-* Spring's {@code Resource} abstraction in the core package, on the other hand,
-* already expects the logging system to be available.
-*
-* @author Juergen Hoeller
-* @since 1.1.5
-*/
-public abstract class ResourceUtils {
-
- /** URL prefix for loading from the file system: "file:" */
- public static final String FILE_URL_PREFIX = "file:";
-
- /** URL prefix for loading from the file system: "jar:" */
- public static final String JAR_URL_PREFIX = "jar:";
-
- /** URL protocol for a file in the file system: "file" */
- public static final String URL_PROTOCOL_FILE = "file";
-
- /** URL protocol for an entry from a jar file: "jar" */
- public static final String URL_PROTOCOL_JAR = "jar";
-
- /** URL protocol for an entry from a zip file: "zip" */
- public static final String URL_PROTOCOL_ZIP = "zip";
-
- /** URL protocol for an entry from a WebSphere jar file: "wsjar" */
- public static final String URL_PROTOCOL_WSJAR = "wsjar";
-
- /** URL protocol for an entry from a JBoss jar file: "vfszip" */
- public static final String URL_PROTOCOL_VFSZIP = "vfszip";
-
- /** URL protocol for a JBoss file system resource: "vfsfile" */
- public static final String URL_PROTOCOL_VFSFILE = "vfsfile";
-
- /** URL protocol for a general JBoss VFS resource: "vfs" */
- public static final String URL_PROTOCOL_VFS = "vfs";
-
- /** File extension for a regular jar file: ".jar" */
- public static final String JAR_FILE_EXTENSION = ".jar";
-
- /** Separator between JAR URL and file path within the JAR: "!/" */
- public static final String JAR_URL_SEPARATOR = "!/";
-
-
- /**
- * Return whether the given resource location is a URL:
- * either a special "classpath" pseudo URL or a standard URL.
- * @param resourceLocation the location String to check
- * @return whether the location qualifies as a URL
- * @see DefaultResourceLoader#CLASSPATH_URL_PREFIX
- * @see java.net.URL
- */
- public static boolean isUrl(String resourceLocation) {
- if (resourceLocation == null) {
- return false;
- }
- if (resourceLocation.startsWith(DefaultResourceLoader.CLASSPATH_URL_PREFIX)) {
- return true;
- }
- try {
- new URL(resourceLocation);
- return true;
- }
- catch (MalformedURLException ex) {
- return false;
- }
- }
-
- /**
- * Resolve the given resource location to a {@code java.net.URL}.
- * <p>Does not check whether the URL actually exists; simply returns
- * the URL that the given location would correspond to.
- * @param resourceLocation the resource location to resolve: either a
- * "classpath:" pseudo URL, a "file:" URL, or a plain file path
- * @return a corresponding URL object
- * @throws FileNotFoundException if the resource cannot be resolved to a URL
- */
- public static URL getURL(String resourceLocation) throws FileNotFoundException {
- Objects.requireNonNull(resourceLocation, "Resource location must not be null");
- if (resourceLocation.startsWith(DefaultResourceLoader.CLASSPATH_URL_PREFIX)) {
- String path = resourceLocation.substring(DefaultResourceLoader.CLASSPATH_URL_PREFIX.length());
- ClassLoader cl = ClassUtils.getDefaultClassLoader();
- URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path));
- if (url == null) {
- String description = "class path resource [" + path + "]";
- throw new FileNotFoundException(description +
- " cannot be resolved to URL because it does not exist");
- }
- return url;
- }
- try {
- // try URL
- return new URL(resourceLocation);
- }
- catch (MalformedURLException ex) {
- // no URL -> treat as file path
- try {
- return new File(resourceLocation).toURI().toURL();
- }
- catch (MalformedURLException ex2) {
- throw new FileNotFoundException("Resource location [" + resourceLocation +
- "] is neither a URL not a well-formed file path");
- }
- }
- }
-
- /**
- * Resolve the given resource location to a {@code java.io.File},
- * i.e. to a file in the file system.
- * <p>Does not check whether the file actually exists; simply returns
- * the File that the given location would correspond to.
- * @param resourceLocation the resource location to resolve: either a
- * "classpath:" pseudo URL, a "file:" URL, or a plain file path
- * @return a corresponding File object
- * @throws FileNotFoundException if the resource cannot be resolved to
- * a file in the file system
- */
- public static File getFile(String resourceLocation) throws FileNotFoundException {
- Objects.requireNonNull(resourceLocation, "Resource location must not be null");
- if (resourceLocation.startsWith(DefaultResourceLoader.CLASSPATH_URL_PREFIX)) {
- String path = resourceLocation.substring(DefaultResourceLoader.CLASSPATH_URL_PREFIX.length());
- String description = "class path resource [" + path + "]";
- ClassLoader cl = ClassUtils.getDefaultClassLoader();
- URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path));
- if (url == null) {
- throw new FileNotFoundException(description +
- " cannot be resolved to absolute file path because it does not exist");
- }
- return getFile(url, description);
- }
- try {
- // try URL
- return getFile(new URL(resourceLocation));
- }
- catch (MalformedURLException ex) {
- // no URL -> treat as file path
- return new File(resourceLocation);
- }
- }
-
- /**
- * Resolve the given resource URL to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUrl the resource URL to resolve
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- public static File getFile(URL resourceUrl) throws FileNotFoundException {
- return getFile(resourceUrl, "URL");
- }
-
- /**
- * Resolve the given resource URL to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUrl the resource URL to resolve
- * @param description a description current the original resource that
- * the URL was created for (for example, a class path location)
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- public static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
- Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
- if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
- throw new FileNotFoundException(
- description + " cannot be resolved to absolute file path " +
- "because it does not reside in the file system: " + resourceUrl);
- }
- try {
- return new File(toURI(resourceUrl).getSchemeSpecificPart());
- }
- catch (URISyntaxException ex) {
- // Fallback for URLs that are not valid URIs (should hardly ever happen).
- return new File(resourceUrl.getFile());
- }
- }
-
- /**
- * Resolve the given resource URI to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUri the resource URI to resolve
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- public static File getFile(URI resourceUri) throws FileNotFoundException {
- return getFile(resourceUri, "URI");
- }
-
- /**
- * Resolve the given resource URI to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUri the resource URI to resolve
- * @param description a description current the original resource that
- * the URI was created for (for example, a class path location)
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
- Objects.requireNonNull(resourceUri, "Resource URI must not be null");
- if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) {
- throw new FileNotFoundException(
- description + " cannot be resolved to absolute file path " +
- "because it does not reside in the file system: " + resourceUri);
- }
- return new File(resourceUri.getSchemeSpecificPart());
- }
-
- /**
- * Determine whether the given URL points to a resource in the file system,
- * that is, has protocol "file", "vfsfile" or "vfs".
- * @param url the URL to check
- * @return whether the URL has been identified as a file system URL
- */
- public static boolean isFileURL(URL url) {
- String protocol = url.getProtocol();
- return (URL_PROTOCOL_FILE.equals(protocol) || URL_PROTOCOL_VFSFILE.equals(protocol) ||
- URL_PROTOCOL_VFS.equals(protocol));
- }
-
- /**
- * Determine whether the given URL points to a resource in a jar file,
- * that is, has protocol "jar", "zip", "vfszip" or "wsjar".
- * @param url the URL to check
- * @return whether the URL has been identified as a JAR URL
- */
- public static boolean isJarURL(URL url) {
- String protocol = url.getProtocol();
- return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) ||
- URL_PROTOCOL_VFSZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol));
- }
-
- /**
- * Determine whether the given URL points to a jar file itself,
- * that is, has protocol "file" and ends with the ".jar" extension.
- * @param url the URL to check
- * @return whether the URL has been identified as a JAR file URL
- * @since 4.1
- */
- public static boolean isJarFileURL(URL url) {
- return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
- url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
- }
-
- /**
- * Extract the URL for the actual jar file from the given URL
- * (which may point to a resource in a jar file or to a jar file itself).
- * @param jarUrl the original URL
- * @return the URL for the actual jar file
- * @throws MalformedURLException if no valid jar file URL could be extracted
- */
- public static URL extractJarFileURL(URL jarUrl) throws MalformedURLException {
- String urlFile = jarUrl.getFile();
- int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR);
- if (separatorIndex != -1) {
- String jarFile = urlFile.substring(0, separatorIndex);
- try {
- return new URL(jarFile);
- }
- catch (MalformedURLException ex) {
- // Probably no protocol in original jar URL, like "jar:C:/mypath/myjar.jar".
- // This usually indicates that the jar file resides in the file system.
- if (!jarFile.startsWith("/")) {
- jarFile = "/" + jarFile;
- }
- return new URL(FILE_URL_PREFIX + jarFile);
- }
- }
- else {
- return jarUrl;
- }
- }
-
- /**
- * Create a URI instance for the given URL,
- * replacing spaces with "%20" URI encoding first.
- * <p>Furthermore, this method works on JDK 1.4 as well,
- * in contrast to the {@code URL.toURI()} method.
- * @param url the URL to convert into a URI instance
- * @return the URI instance
- * @throws URISyntaxException if the URL wasn't a valid URI
- * @see java.net.URL#toURI()
- */
- public static URI toURI(URL url) throws URISyntaxException {
- return toURI(url.toString());
- }
-
- /**
- * Create a URI instance for the given location String,
- * replacing spaces with "%20" URI encoding first.
- * @param location the location String to convert into a URI instance
- * @return the URI instance
- * @throws URISyntaxException if the location wasn't a valid URI
- */
- public static URI toURI(String location) throws URISyntaxException {
- return new URI(location.replaceAll(" ", "%20"));
- }
-
- /**
- * Set the {@link URLConnection#setUseCaches "useCaches"} flag on the
- * given connection, preferring {@code false} but leaving the
- * flag at {@code true} for JNLP based resources.
- * @param con the URLConnection to set the flag on
- */
- public static void useCachesIfNecessary(URLConnection con) {
- con.setUseCaches(con.getClass().getSimpleName().startsWith("JNLP"));
- }
-
-}
[19/27] incubator-tamaya git commit: TAMAYA-42, 43,
44: Added initial implementation of Configuration, ConfigurationContext,
ResourceLoading and ConfigurationFormat.
Posted by an...@apache.org.
TAMAYA-42,43,44: Added initial implementation of Configuration, ConfigurationContext, ResourceLoading and ConfigurationFormat.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/8b2cc9b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/8b2cc9b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/8b2cc9b1
Branch: refs/heads/master
Commit: 8b2cc9b15c95470ea430bea899ba5854d4ce434c
Parents: b56817f
Author: anatole <an...@apache.org>
Authored: Sat Jan 3 09:44:57 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 3 09:44:57 2015 +0100
----------------------------------------------------------------------
core/pom.xml | 36 +++++
.../core/PathBasedPropertySourceProvider.java | 76 +++++++++
.../core/ResourcePropertySourceProvider.java | 83 ++++++++++
.../core/formats/ConfigurationFormat.java | 46 ++++++
.../tamaya/core/formats/PropertiesFormat.java | 109 +++++++++++++
.../core/formats/PropertiesXmlFormat.java | 111 +++++++++++++
.../core/internal/DefaultConfiguration.java | 68 ++++++++
.../internal/DefaultConfigurationContext.java | 158 +++++++++++++++++++
.../core/internal/DefaultServiceContext.java | 89 +++++++++++
.../resource/DefaultResourceLoader.java | 94 +++++++++++
.../services/org.apache.tamaya.Configuration | 19 +++
....apache.tamaya.core.resources.ResourceLoader | 19 +++
.../org.apache.tamaya.spi.ConfigurationContext | 19 +++
.../org.apache.tamaya.spi.ServiceContext | 19 +++
.../apache/tamaya/core/ConfigurationTest.java | 53 +++++++
.../TestPropertyDefaultSourceProvider.java | 32 ++++
...org.apache.tamaya.spi.PropertySourceProvider | 20 +++
.../resources/cfg/defaults/test1.properties | 20 +++
.../cfg/final/anotherTestFile.properties | 22 +++
19 files changed, 1093 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index 26ccce0..64c868a 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -30,12 +30,48 @@ under the License.
<artifactId>tamaya-core</artifactId>
+ <properties>
+ <slf4j.version>1.7.2</slf4j.version>
+ <log4j.version>1.2.17</log4j.version>
+ <log4j2.version>2.1</log4j2.version>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- Deps for logging backends -->
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <version>${log4j2.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java b/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
new file mode 100644
index 0000000..aba7a9f
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core;
+
+import org.apache.tamaya.core.formats.ConfigurationFormat;
+import org.apache.tamaya.core.resources.Resource;
+import org.apache.tamaya.core.resources.ResourceLoader;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.*;
+import java.util.ArrayList;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Implementation of a PropertySourceProvider that reads configuration from some given resource paths
+ * and using the goven formats.
+ */
+public class PathBasedPropertySourceProvider implements PropertySourceProvider {
+
+ private static final Logger LOG = Logger.getLogger(PathBasedPropertySourceProvider.class.getName());
+
+ private String baseName;
+ private List<ConfigurationFormat> configFormats = new ArrayList<>();
+ private List<String> paths = new ArrayList<>();
+
+ public PathBasedPropertySourceProvider(String baseName, List<ConfigurationFormat> formats, String... paths) {
+ this.baseName = Objects.requireNonNull(baseName);
+ this.configFormats.addAll(Objects.requireNonNull(formats));
+ this.paths.addAll(Arrays.asList(Objects.requireNonNull(paths)));
+ }
+
+ public PathBasedPropertySourceProvider(String baseName, ConfigurationFormat format, String... paths) {
+ this.baseName = Objects.requireNonNull(baseName);
+ this.configFormats.add(Objects.requireNonNull(format));
+ this.paths.addAll(Arrays.asList(Objects.requireNonNull(paths)));
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources(){
+ List<PropertySource> propertySources = new ArrayList<>();
+ paths.forEach((path) -> {
+ for (Resource res : ServiceContext.getInstance().getService(ResourceLoader.class).get().getResources(path)) {
+ try{
+ for(ConfigurationFormat format:configFormats){
+ propertySources.addAll(format.readConfiguration(res));
+ }
+ }
+ catch(Exception e){
+ LOG.log(Level.WARNING, "Failed to add resource based config: " + res.getDisplayName(), e);
+ }
+ }
+ });
+ return propertySources;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/ResourcePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/ResourcePropertySourceProvider.java b/core/src/main/java/org/apache/tamaya/core/ResourcePropertySourceProvider.java
new file mode 100644
index 0000000..978ab9a
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/ResourcePropertySourceProvider.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core;
+
+import org.apache.tamaya.core.formats.ConfigurationFormat;
+import org.apache.tamaya.core.resources.Resource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+public class ResourcePropertySourceProvider implements PropertySourceProvider {
+
+ private static final Logger LOG = Logger.getLogger(ResourcePropertySourceProvider.class.getName());
+
+ private List<ConfigurationFormat> formats = new ArrayList<>();
+
+ private Resource resource;
+
+ public ResourcePropertySourceProvider(Resource resource, ConfigurationFormat... formats) {
+ this.resource = Objects.requireNonNull(resource);
+ this.formats.addAll(Arrays.asList(formats));
+ }
+
+ public ResourcePropertySourceProvider(Resource resource, List<ConfigurationFormat> formats) {
+ this.resource = Objects.requireNonNull(resource);
+ this.formats.addAll(formats);
+ }
+
+
+ /**
+ * Get the underlying resource.
+ *
+ * @return
+ */
+ public Resource getResource() {
+ return this.resource;
+ }
+
+
+ @Override
+ public String toString() {
+ return "ResourcePropertySourceProvider{" +
+ "resource=" + resource +
+ ", formats=+" + formats +
+ '}';
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ List<PropertySource> propertySources = new ArrayList<>();
+ for (ConfigurationFormat format : formats) {
+ try {
+ propertySources.addAll(format.readConfiguration(resource));
+ } catch (Exception e) {
+ LOG.info(() -> "Format was not matching: " + format + " for resource: " + resource.getDisplayName());
+ }
+ }
+ return propertySources;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
new file mode 100644
index 0000000..e9308c7
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.formats;
+
+import org.apache.tamaya.core.resources.Resource;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.io.IOException;
+import java.util.Collection;
+
+/**
+ * Implementations current this class encapsulate the mechanism how to read a
+ * resource including interpreting the format correctly (e.g. xml vs.
+ * properties). In most cases file only contains entries of the same priority, which would then
+ * result in only one {@link PropertySource}. Complex file formats, hoiwever, may contain entries
+ * of different priorities. In this cases, each ordinal type found must be returned as a separate
+ * {@link PropertySource} instance.
+ */
+@FunctionalInterface
+public interface ConfigurationFormat{
+
+ /**
+ * Reads a list {@link org.apache.tamaya.spi.PropertySource} instances from a resource, using this format.
+ * Hereby the ordinal given is used as a base ordinal
+ * @param resource the configuration resource, not null
+ * @return the corresponding {@link java.util.Map}, never {@code null}.
+ */
+ Collection<PropertySource> readConfiguration(Resource resource)throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
new file mode 100644
index 0000000..dc3d9bb
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.formats;
+
+import org.apache.tamaya.core.resources.Resource;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Implementation of a configuration format for -properties files.
+ */
+public class PropertiesFormat implements ConfigurationFormat{
+
+ private final static Logger LOG = Logger.getLogger(PropertiesFormat.class.getName());
+
+ /** The target ordinal. */
+ private int ordinal;
+
+ /**
+ * Creates a new ordinal.
+ * @param ordinal the target ordinal.
+ */
+ private PropertiesFormat(int ordinal){
+ this.ordinal = ordinal;
+ }
+
+ public static PropertiesFormat of(int ordinal){
+ // TODO caching...
+ return new PropertiesFormat(ordinal);
+ }
+
+ /**
+ * Get the target ordinal, produced by this format.
+ * @return the target ordinal
+ */
+ public int getOrdinal(){
+ return ordinal;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Collection<PropertySource> readConfiguration(Resource resource) {
+ if (resource.exists()) {
+ List<PropertySource> propertySources = new ArrayList<>();
+ try (InputStream is = resource.getInputStream()) {
+ final Properties p = new Properties();
+ p.load(is);
+ propertySources.add(new PropertySource(){
+ @Override
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ @Override
+ public String getName() {
+ return resource.getDisplayName();
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return Optional.ofNullable(p.getProperty(key));
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Map.class.cast(p);
+ }
+ });
+ return propertySources;
+ } catch (Exception e) {
+ LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + resource);
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String toString() {
+ return "PropertiesFormat{" +
+ "ordinal=" + ordinal +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
new file mode 100644
index 0000000..625dd32
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.formats;
+
+import org.apache.tamaya.core.resources.Resource;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+public class PropertiesXmlFormat implements ConfigurationFormat {
+
+ private final static Logger LOG = Logger.getLogger(PropertiesXmlFormat.class.getName());
+
+ /**
+ * The target ordinal.
+ */
+ private int ordinal;
+
+ /**
+ * Creates a new ordinal.
+ *
+ * @param ordinal the target ordinal.
+ */
+ private PropertiesXmlFormat(int ordinal) {
+ this.ordinal = ordinal;
+ }
+
+ public static PropertiesXmlFormat of(int ordinal){
+ // TODO caching...
+ return new PropertiesXmlFormat(ordinal);
+ }
+
+ /**
+ * Get the target ordinal, produced by this format.
+ *
+ * @return the target ordinal
+ */
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Collection<PropertySource> readConfiguration(Resource resource) {
+ if (resource.exists()) {
+ List<PropertySource> propertySources = new ArrayList<>();
+ try (InputStream is = resource.getInputStream()) {
+ final Properties p = new Properties();
+ p.loadFromXML(is);
+ propertySources.add(new PropertySource() {
+ @Override
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ @Override
+ public String getName() {
+ return resource.getDisplayName();
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return Optional.ofNullable(p.getProperty(key));
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Map.class.cast(p);
+ }
+ });
+ return propertySources;
+ } catch (Exception e) {
+ LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + resource);
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String toString() {
+ return "PropertiesXmlFormat{" +
+ "ordinal=" + ordinal +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
new file mode 100644
index 0000000..ef27c87
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Implementation of the Configuration API.
+ */
+public class DefaultConfiguration implements Configuration{
+
+ @Override
+ public Optional<String> get(String key) {
+ List<PropertySource> propertySources = ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertySources();
+ for(PropertySource propertySource:propertySources){
+ Optional<String> value = propertySource.get(key);
+ if(value.isPresent()){
+ return value;
+ }
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public <T> Optional<T> get(String key, Class<T> type) {
+ Optional<String> value = get(key);
+ if(value.isPresent()){
+ List<PropertyConverter<T>> converters = ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertyConverters(type);
+ for(PropertyConverter<T> converter:converters){
+ try{
+ T t = converter.convert(value.get());
+ if(t!=null){
+ return Optional.of(t);
+ }
+ }
+ catch(Exception e){
+ // TODO LOG
+ }
+ }
+ throw new ConfigException("Unparseable config value for type: " + type.getName() + ": " + key);
+ }
+ return Optional.empty();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
new file mode 100644
index 0000000..90b1d16
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.ServiceContext;
+
+import javax.annotation.Priority;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.StampedLock;
+import java.util.stream.Stream;
+
+/**
+ * Default Implementation of a simple ConfigurationContext.
+ */
+public class DefaultConfigurationContext implements ConfigurationContext{
+
+ private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
+
+ private List<PropertySource> propertySources = new ArrayList<>();
+ private List<PropertySourceProvider> propertySourceProviders = new ArrayList<>();
+ private List<PropertyFilter> propertyFilters = new ArrayList<>();
+ private boolean loaded = false;
+
+ private StampedLock propertySourceLock = new StampedLock();
+
+
+ @Override
+ public void addPropertySources(PropertySource... propertySourcesToAdd) {
+ Lock writeLock = propertySourceLock.asWriteLock();
+ try{
+ writeLock.lock();
+ List<PropertySource> newPropertySources = new ArrayList<>(this.propertySources);
+ newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
+ Collections.sort(newPropertySources, this::comparePropertySources);
+ this.propertySources = newPropertySources;
+ }
+ finally{
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Order property source reversely, the most important come first.
+ * @param source1
+ * @param source2
+ * @return
+ */
+ private int comparePropertySources(PropertySource source1, PropertySource source2){
+ if(source1.getOrdinal() < source2.getOrdinal()){
+ return 1;
+ }
+ else if(source1.getOrdinal()>source2.getOrdinal()){
+ return -1;
+ }
+ else{
+ return source2.getClass().getName().compareTo(source1.getClass().getName());
+ }
+ }
+
+ private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2){
+ Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
+ Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
+ int ord1 = prio1!=null?prio1.value():0;
+ int ord2 = prio2!=null?prio2.value():0;
+ if(ord1 < ord2){
+ return -1;
+ }
+ else if(ord1>ord2){
+ return 1;
+ }
+ else{
+ return filter1.getClass().getName().compareTo(filter2.getClass().getName());
+ }
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ if(!loaded){
+ Lock writeLock = propertySourceLock.asWriteLock();
+ try{
+ writeLock.lock();
+ if(!loaded) {
+ this.propertySources.addAll(ServiceContext.getInstance().getServices(PropertySource.class));
+ this.propertySourceProviders.addAll(ServiceContext.getInstance().getServices(PropertySourceProvider.class));
+ for (PropertySourceProvider prov : this.propertySourceProviders) {
+ try {
+ this.propertySources.addAll(prov.getPropertySources());
+ } catch (Exception e) {
+ //X TODO Log!
+ }
+ }
+ Collections.sort(this.propertySources, this::comparePropertySources);
+ this.propertyFilters.addAll(ServiceContext.getInstance().getServices(PropertyFilter.class));
+ Collections.sort(this.propertyFilters, this::comparePropertyFilters);
+ loaded = true;
+ }
+ }
+ finally{
+ writeLock.unlock();
+ }
+ }
+ Lock readLock = propertySourceLock.asReadLock();
+ try{
+ readLock.lock();
+ return Collections.unmodifiableList(propertySources);
+ }
+ finally{
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public <T> void addPropertyConverter(Class<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ propertyConverterManager.register(typeToConvert, propertyConverter);
+ }
+
+ @Override
+ public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return propertyConverterManager.getPropertyConverters();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
+ return propertyConverterManager.getPropertyConverters(targetType);
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return Collections.unmodifiableList(this.propertyFilters);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
new file mode 100644
index 0000000..e86ca17
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
+ * {@link java.util.ServiceLoader} to load the services required.
+ */
+public final class DefaultServiceContext implements ServiceContext {
+ /** List current services loaded, per class. */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+ /** Singletons. */
+ private final Map<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
+
+ @Override
+ public <T> Optional<T> getService(Class<T> serviceType) {
+ Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
+ if(cached==null) {
+ List<? extends T> services = getServices(serviceType);
+ if (services.isEmpty()) {
+ cached = Optional.empty();
+ }
+ else{
+ cached = Optional.of(services.get(0));
+ }
+ singletons.put(serviceType, cached);
+ }
+ return cached;
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param serviceType
+ * The service type.
+ * @param <T>
+ * the concrete type.
+ * @return the items found, never {@code null}.
+ */
+ @Override
+ public <T> List<T> getServices(final Class<T> serviceType) {
+ List<T> found = List.class.cast(servicesLoaded.get(serviceType));
+ if (found != null) {
+ return found;
+ }
+ List<T> services = new ArrayList<>();
+ try {
+ for (T t : ServiceLoader.load(serviceType)) {
+ services.add(t);
+ }
+ services = Collections.unmodifiableList(services);
+ } catch (Exception e) {
+ Logger.getLogger(DefaultServiceContext.class.getName()).log(Level.WARNING,
+ "Error loading services current type " + serviceType, e);
+ }
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>)services));
+ return previousServices != null ? previousServices : services;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java
new file mode 100644
index 0000000..c65be65
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/DefaultResourceLoader.java
@@ -0,0 +1,94 @@
+package org.apache.tamaya.core.internal.resource;
+
+import org.apache.tamaya.core.resources.Resource;
+import org.apache.tamaya.core.resources.ResourceLoader;
+
+import javax.annotation.Priority;
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.WeakHashMap;
+import java.util.logging.Logger;
+
+/**
+ * Simple default implementation of the resource loader.
+ */
+@Priority(0)
+public class DefaultResourceLoader implements ResourceLoader{
+
+ private static final Logger LOG = Logger.getLogger(DefaultResourceLoader.class.getName());
+
+ private WeakHashMap<ClassLoader, PathMatchingResourcePatternResolver> resourceLoaders = new WeakHashMap<>();
+
+ @Override
+ public List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions) {
+ List<Resource> resources = new ArrayList<>();
+ for(String expression:expressions){
+ if(tryClassPath(classLoader, expression, resources) || tryFile(expression, resources) || tryURL(expression, resources)
+ || tryAntPath(classLoader, expression, resources)){
+ continue;
+ }
+ LOG.warning("Failed to resolve resource: " + expression);
+ }
+ return resources;
+ }
+
+ private boolean tryClassPath(ClassLoader classLoader, String expression, List<Resource> resources) {
+ try{
+ Enumeration<URL> urls = classLoader.getResources(expression);
+ while(urls.hasMoreElements()){
+ URL url = urls.nextElement();
+ resources.add(new UrlResource(url));
+ }
+ return !resources.isEmpty();
+ }
+ catch(Exception e){
+ LOG.finest(() -> "Failed to load resource from CP: " + expression);
+ }
+ return false;
+ }
+
+ private boolean tryFile(String expression, List<Resource> resources) {
+ try{
+ File file = new File(expression);
+ if(file.exists()) {
+ resources.add(new FileSystemResource(file));
+ return true;
+ }
+ }
+ catch(Exception e){
+ LOG.finest(() -> "Failed to load resource from file: " + expression);
+ }
+ return false;
+ }
+
+ private boolean tryURL(String expression, List<Resource> resources) {
+ try{
+ URL url = new URL(expression);
+ resources.add(new UrlResource(url));
+ return true;
+ }
+ catch(Exception e){
+ LOG.finest(() -> "Failed to load resource from file: " + expression);
+ }
+ return false;
+
+ }
+
+ private boolean tryAntPath(ClassLoader classLoader, String expression, List<Resource> resources) {
+ PathMatchingResourcePatternResolver loader = resourceLoaders.computeIfAbsent(classLoader, cl -> new PathMatchingResourcePatternResolver(cl));
+ try{
+ resources.addAll(Arrays.asList(loader.getResources(expression)));
+ return !resources.isEmpty();
+ }
+ catch(Exception e){
+ LOG.finest(() -> "Failed to load resources from pattern: " + expression);
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration b/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
new file mode 100644
index 0000000..0db8402
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
new file mode 100644
index 0000000..08c9577
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.resource.DefaultResourceLoader
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
new file mode 100644
index 0000000..32b4302
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultConfigurationContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..2721eff
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
new file mode 100644
index 0000000..9c7b894
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core;
+
+import org.apache.tamaya.Configuration;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * This tests checks if the combination of 2 prioritized PropertySource return valid results on the final Configuration.
+ */
+public class ConfigurationTest {
+
+ @Test
+ public void testAccess(){
+ assertNotNull(Configuration.current());
+ }
+
+ @Test
+ public void testContent(){
+ assertEquals("Robin", Configuration.current().get("name").get());
+ assertEquals("Sabine", Configuration.current().get("name2").get()); // from default
+ assertEquals("Lukas", Configuration.current().get("name3").get()); // oderridden default
+ assertEquals("Sereina", Configuration.current().get("name4").get()); // final only
+ assertEquals("Benjamin", Configuration.current().get("name5").get()); // final only
+
+ System.out.println("name : " + Configuration.current().get("name").get());
+ System.out.println("name2: " + Configuration.current().get("name2").get());
+ System.out.println("name3: " + Configuration.current().get("name3").get());
+ System.out.println("name4: " + Configuration.current().get("name4").get());
+ System.out.println("name5: " + Configuration.current().get("name5").get());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSourceProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSourceProvider.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSourceProvider.java
new file mode 100644
index 0000000..ebd28f7
--- /dev/null
+++ b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSourceProvider.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.core.PathBasedPropertySourceProvider;
+import org.apache.tamaya.core.formats.PropertiesFormat;
+
+/**
+ * Test provider reading properties from classpath:cfg/defaults/**.properties.
+ */
+public class TestPropertyDefaultSourceProvider extends PathBasedPropertySourceProvider{
+
+ public TestPropertyDefaultSourceProvider() {
+ super("default-testdata-properties", PropertiesFormat.of(100), "classpath:cfg/defaults/**/*.properties");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..e61641c
--- /dev/null
+++ b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+testdata.TestPropertyDefaultSourceProvider
+testdata.TestPropertySourceProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/test/resources/cfg/defaults/test1.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/cfg/defaults/test1.properties b/core/src/test/resources/cfg/defaults/test1.properties
new file mode 100644
index 0000000..17a854d
--- /dev/null
+++ b/core/src/test/resources/cfg/defaults/test1.properties
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+name=Anatole
+name2=Sabine
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b2cc9b1/core/src/test/resources/cfg/final/anotherTestFile.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/cfg/final/anotherTestFile.properties b/core/src/test/resources/cfg/final/anotherTestFile.properties
new file mode 100644
index 0000000..9e405f6
--- /dev/null
+++ b/core/src/test/resources/cfg/final/anotherTestFile.properties
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+name=Robin
+name3=Lukas
+name4=Sereina
+name5=Benjamin
\ No newline at end of file
[20/27] incubator-tamaya git commit: TAMAYA-45,
46: Added initial module for resultion.
Posted by an...@apache.org.
TAMAYA-45,46: Added initial module for resultion.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/fa704372
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/fa704372
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/fa704372
Branch: refs/heads/master
Commit: fa7043725bce2d16bcbb532c381011e02ce898b8
Parents: 8b2cc9b
Author: anatole <an...@apache.org>
Authored: Sat Jan 3 09:48:00 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 3 09:48:00 2015 +0100
----------------------------------------------------------------------
modules/resolver/pom.xml | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/fa704372/modules/resolver/pom.xml
----------------------------------------------------------------------
diff --git a/modules/resolver/pom.xml b/modules/resolver/pom.xml
new file mode 100644
index 0000000..fb33e38
--- /dev/null
+++ b/modules/resolver/pom.xml
@@ -0,0 +1,40 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-extensions</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-resolver</artifactId>
+ <name>Apache Tamaya Resolver Services</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
[10/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java
deleted file mode 100644
index 43d2a20..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java
+++ /dev/null
@@ -1,777 +0,0 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.resources.io;
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * PathMatcher implementation for Ant-style path patterns. Examples are provided below.
- *
- * <p>Part current this annotation code has been kindly borrowed from <a href="http://ant.apache.org">Apache Ant</a>.
- *
- * <p>The annotation matches URLs using the following rules:<br> <ul> <li>? matches one character</li> <li>* matches zero
- * or more characters</li> <li>** matches zero or more 'directories' in a path</li> </ul>
- *
- * <p>Some examples:<br> <ul> <li>{@code com/t?st.jsp} - matches {@code com/test.jsp} but also
- * {@code com/tast.jsp} or {@code com/txst.jsp}</li> <li>{@code com/*.jsp} - matches all
- * {@code .jsp} files in the {@code com} directory</li> <li>{@code com/**/test.jsp} - matches all
- * {@code test.jsp} files underneath the {@code com} path</li> <li>{@code org/springframework/**/*.jsp}
- * - matches all {@code .jsp} files underneath the {@code org/springframework} path</li>
- * <li>{@code org/**/servlet/bla.jsp} - matches {@code org/springframework/servlet/bla.jsp} but also
- * {@code org/springframework/testing/servlet/bla.jsp} and {@code org/servlet/bla.jsp}</li> </ul>
- *
- * @author Alef Arendsen
- * @author Juergen Hoeller
- * @author Rob Harrop
- * @author Arjen Poutsma
- * @author Rossen Stoyanchev
- * @since 16.07.2003
- */
-class AntPathMatcher {
-
- /** Default path separator: "/" */
- public static final String DEFAULT_PATH_SEPARATOR = "/";
-
- private static final int CACHE_TURNOFF_THRESHOLD = 65536;
-
- private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
-
-
- private String pathSeparator;
-
- private PathSeparatorPatternCache pathSeparatorPatternCache;
-
- private boolean trimTokens = true;
-
- private volatile Boolean cachePatterns;
-
- private final Map<String, String[]> tokenizedPatternCache = new ConcurrentHashMap<>(256);
-
- final Map<String, AntPathStringMatcher> stringMatcherCache = new ConcurrentHashMap<>(256);
-
-
- /**
- * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
- */
- public AntPathMatcher() {
- this.pathSeparator = DEFAULT_PATH_SEPARATOR;
- this.pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR);
- }
-
- /**
- * A convenience alternative constructor to use with a custom path separator.
- * @param pathSeparator the path separator to use, must not be {@code null}.
- * @since 4.1
- */
- public AntPathMatcher(String pathSeparator) {
- Objects.requireNonNull(pathSeparator, "'pathSeparator' is required");
- this.pathSeparator = pathSeparator;
- this.pathSeparatorPatternCache = new PathSeparatorPatternCache(pathSeparator);
- }
-
-
- /**
- * Set the path separator to use for pattern parsing.
- * Default is "/", as in Ant.
- */
- public void setPathSeparator(String pathSeparator) {
- this.pathSeparator = (pathSeparator != null ? pathSeparator : DEFAULT_PATH_SEPARATOR);
- this.pathSeparatorPatternCache = new PathSeparatorPatternCache(this.pathSeparator);
- }
-
- /**
- * Specify whether to trim tokenized paths and patterns.
- * Default is {@code true}.
- */
- public void setTrimTokens(boolean trimTokens) {
- this.trimTokens = trimTokens;
- }
-
- /**
- * Specify whether to cache parsed pattern metadata for patterns passed
- * into this matcher's {@link #match} method. A keys current {@code true}
- * activates an unlimited pattern cache; a keys current {@code false} turns
- * the pattern cache off completely.
- * <p>Default is for the cache to be on, but with the variant to automatically
- * turn it off when encountering too many patterns to cache at runtime
- * (the threshold is 65536), assuming that arbitrary permutations current patterns
- * are coming in, with little chance for encountering a reoccurring pattern.
- * @see #getStringMatcher(String)
- */
- public void setCachePatterns(boolean cachePatterns) {
- this.cachePatterns = cachePatterns;
- }
-
- private void deactivatePatternCache() {
- this.cachePatterns = false;
- this.tokenizedPatternCache.clear();
- this.stringMatcherCache.clear();
- }
-
-
- public boolean isPattern(String path) {
- return (path.indexOf('*') != -1 || path.indexOf('?') != -1);
- }
-
- public boolean match(String pattern, String path) {
- return doMatch(pattern, path, true, null);
- }
-
- public boolean matchStart(String pattern, String path) {
- return doMatch(pattern, path, false, null);
- }
-
- /**
- * Actually match the given {@code path} against the given {@code pattern}.
- * @param pattern the pattern to match against
- * @param path the path String to test
- * @param fullMatch whether a full pattern match is required (else a pattern match
- * as far as the given base path goes is sufficient)
- * @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't
- */
- protected boolean doMatch(String pattern, String path, boolean fullMatch, Map<String, String> uriTemplateVariables) {
- if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
- return false;
- }
-
- String[] pattDirs = tokenizePattern(pattern);
- String[] pathDirs = tokenizePath(path);
-
- int pattIdxStart = 0;
- int pattIdxEnd = pattDirs.length - 1;
- int pathIdxStart = 0;
- int pathIdxEnd = pathDirs.length - 1;
-
- // Match all elements up to the first **
- while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
- String pattDir = pattDirs[pattIdxStart];
- if ("**".equals(pattDir)) {
- break;
- }
- if (!matchStrings(pattDir, pathDirs[pathIdxStart], uriTemplateVariables)) {
- return false;
- }
- pattIdxStart++;
- pathIdxStart++;
- }
-
- if (pathIdxStart > pathIdxEnd) {
- // Path is exhausted, only match if rest current pattern is * or **'s
- if (pattIdxStart > pattIdxEnd) {
- return (pattern.endsWith(this.pathSeparator) ? path.endsWith(this.pathSeparator) :
- !path.endsWith(this.pathSeparator));
- }
- if (!fullMatch) {
- return true;
- }
- if (pattIdxStart == pattIdxEnd && pattDirs[pattIdxStart].equals("*") && path.endsWith(this.pathSeparator)) {
- return true;
- }
- for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
- if (!pattDirs[i].equals("**")) {
- return false;
- }
- }
- return true;
- }
- else if (pattIdxStart > pattIdxEnd) {
- // String not exhausted, but pattern is. Failure.
- return false;
- }
- else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) {
- // Path start definitely matches due to "**" part in pattern.
- return true;
- }
-
- // up to last '**'
- while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
- String pattDir = pattDirs[pattIdxEnd];
- if (pattDir.equals("**")) {
- break;
- }
- if (!matchStrings(pattDir, pathDirs[pathIdxEnd], uriTemplateVariables)) {
- return false;
- }
- pattIdxEnd--;
- pathIdxEnd--;
- }
- if (pathIdxStart > pathIdxEnd) {
- // String is exhausted
- for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
- if (!pattDirs[i].equals("**")) {
- return false;
- }
- }
- return true;
- }
-
- while (pattIdxStart != pattIdxEnd && pathIdxStart <= pathIdxEnd) {
- int patIdxTmp = -1;
- for (int i = pattIdxStart + 1; i <= pattIdxEnd; i++) {
- if (pattDirs[i].equals("**")) {
- patIdxTmp = i;
- break;
- }
- }
- if (patIdxTmp == pattIdxStart + 1) {
- // '**/**' situation, so skip one
- pattIdxStart++;
- continue;
- }
- // Find the pattern between padIdxStart & padIdxTmp in str between
- // strIdxStart & strIdxEnd
- int patLength = (patIdxTmp - pattIdxStart - 1);
- int strLength = (pathIdxEnd - pathIdxStart + 1);
- int foundIdx = -1;
-
- strLoop:
- for (int i = 0; i <= strLength - patLength; i++) {
- for (int j = 0; j < patLength; j++) {
- String subPat = pattDirs[pattIdxStart + j + 1];
- String subStr = pathDirs[pathIdxStart + i + j];
- if (!matchStrings(subPat, subStr, uriTemplateVariables)) {
- continue strLoop;
- }
- }
- foundIdx = pathIdxStart + i;
- break;
- }
-
- if (foundIdx == -1) {
- return false;
- }
-
- pattIdxStart = patIdxTmp;
- pathIdxStart = foundIdx + patLength;
- }
-
- for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
- if (!pattDirs[i].equals("**")) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Tokenize the given path pattern into parts, based on this matcher's settings.
- * <p>Performs caching based on {@link #setCachePatterns}, delegating to
- * {@link #tokenizePath(String)} for the actual tokenization algorithm.
- * @param pattern the pattern to tokenize
- * @return the tokenized pattern parts
- */
- protected String[] tokenizePattern(String pattern) {
- String[] tokenized = null;
- Boolean cachePatterns = this.cachePatterns;
- if (cachePatterns == null || cachePatterns) {
- tokenized = this.tokenizedPatternCache.get(pattern);
- }
- if (tokenized == null) {
- tokenized = tokenizePath(pattern);
- if (cachePatterns == null && this.tokenizedPatternCache.size() >= CACHE_TURNOFF_THRESHOLD) {
- // Try to adapt to the runtime situation that we're encountering:
- // There are obviously too many different patterns coming in here...
- // So let's turn off the cache since the patterns are unlikely to be reoccurring.
- deactivatePatternCache();
- return tokenized;
- }
- if (cachePatterns == null || cachePatterns) {
- this.tokenizedPatternCache.put(pattern, tokenized);
- }
- }
- return tokenized;
- }
-
- /**
- * Tokenize the given path String into parts, based on this matcher's settings.
- * @param path the path to tokenize
- * @return the tokenized path parts
- */
- protected String[] tokenizePath(String path) {
- return StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
- }
-
- /**
- * Tests whether or not a string matches against a pattern.
- * @param pattern the pattern to match against (never {@code null})
- * @param str the String which must be matched against the pattern (never {@code null})
- * @return {@code true} if the string matches against the pattern, or {@code false} otherwise
- */
- private boolean matchStrings(String pattern, String str, Map<String, String> uriTemplateVariables) {
- return getStringMatcher(pattern).matchStrings(str, uriTemplateVariables);
- }
-
- /**
- * Build or retrieve an {@link AntPathStringMatcher} for the given pattern.
- * <p>The default implementation checks this AntPathMatcher's internal cache
- * (see {@link #setCachePatterns}), creating a new AntPathStringMatcher instance
- * if no cached copy is found.
- * When encountering too many patterns to cache at runtime (the threshold is 65536),
- * it turns the default cache off, assuming that arbitrary permutations current patterns
- * are coming in, with little chance for encountering a reoccurring pattern.
- * <p>This method may get overridden to implement a custom cache strategy.
- * @param pattern the pattern to match against (never {@code null})
- * @return a corresponding AntPathStringMatcher (never {@code null})
- * @see #setCachePatterns
- */
- protected AntPathStringMatcher getStringMatcher(String pattern) {
- AntPathStringMatcher matcher = null;
- Boolean cachePatterns = this.cachePatterns;
- if (cachePatterns == null || cachePatterns) {
- matcher = this.stringMatcherCache.get(pattern);
- }
- if (matcher == null) {
- matcher = new AntPathStringMatcher(pattern);
- if (cachePatterns == null && this.stringMatcherCache.size() >= CACHE_TURNOFF_THRESHOLD) {
- // Try to adapt to the runtime situation that we're encountering:
- // There are obviously too many different patterns coming in here...
- // So let's turn off the cache since the patterns are unlikely to be reoccurring.
- deactivatePatternCache();
- return matcher;
- }
- if (cachePatterns == null || cachePatterns) {
- this.stringMatcherCache.put(pattern, matcher);
- }
- }
- return matcher;
- }
-
- /**
- * Given a pattern and a full path, determine the pattern-mapped part. <p>For example: <ul>
- * <li>'{@code /docs/cvs/commit.html}' and '{@code /docs/cvs/commit.html} -> ''</li>
- * <li>'{@code /docs/*}' and '{@code /docs/cvs/commit} -> '{@code cvs/commit}'</li>
- * <li>'{@code /docs/cvs/*.html}' and '{@code /docs/cvs/commit.html} -> '{@code commit.html}'</li>
- * <li>'{@code /docs/**}' and '{@code /docs/cvs/commit} -> '{@code cvs/commit}'</li>
- * <li>'{@code /docs/**\/*.html}' and '{@code /docs/cvs/commit.html} -> '{@code cvs/commit.html}'</li>
- * <li>'{@code /*.html}' and '{@code /docs/cvs/commit.html} -> '{@code docs/cvs/commit.html}'</li>
- * <li>'{@code *.html}' and '{@code /docs/cvs/commit.html} -> '{@code /docs/cvs/commit.html}'</li>
- * <li>'{@code *}' and '{@code /docs/cvs/commit.html} -> '{@code /docs/cvs/commit.html}'</li> </ul>
- * <p>Assumes that {@link #match} returns {@code true} for '{@code pattern}' and '{@code path}', but
- * does <strong>not</strong> enforce this.
- */
- public String extractPathWithinPattern(String pattern, String path) {
- String[] patternParts = StringUtils.tokenizeToStringArray(pattern, this.pathSeparator, this.trimTokens, true);
- String[] pathParts = StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
- StringBuilder builder = new StringBuilder();
- boolean pathStarted = false;
-
- for (int segment = 0; segment < patternParts.length; segment++) {
- String patternPart = patternParts[segment];
- if (patternPart.indexOf('*') > -1 || patternPart.indexOf('?') > -1) {
- for (; segment < pathParts.length; segment++) {
- if (pathStarted || (segment == 0 && !pattern.startsWith(this.pathSeparator))) {
- builder.append(this.pathSeparator);
- }
- builder.append(pathParts[segment]);
- pathStarted = true;
- }
- }
- }
-
- return builder.toString();
- }
-
- public Map<String, String> extractUriTemplateVariables(String pattern, String path) {
- Map<String, String> variables = new LinkedHashMap<>();
- boolean result = doMatch(pattern, path, true, variables);
- if(!result){
- throw new IllegalArgumentException("Pattern \"" + pattern + "\" is not a match for \"" + path + "\"");
- }
- return variables;
- }
-
- /**
- * Combines two patterns into a new pattern that is returned.
- * <p>This implementation simply concatenates the two patterns, unless the first pattern
- * contains a file extension match (such as {@code *.html}. In that case, the second pattern
- * should be included in the first, or an {@code IllegalArgumentException} is thrown.
- * <p>For example: <table>
- * <tr><th>Pattern 1</th><th>Pattern 2</th><th>Result</th></tr> <tr><td>/hotels</td><td>{@code
- * null}</td><td>/hotels</td></tr> <tr><td>{@code null}</td><td>/hotels</td><td>/hotels</td></tr>
- * <tr><td>/hotels</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels</td><td>bookings</td><td>/hotels/bookings</td></tr>
- * <tr><td>/hotels/*</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels/**</td><td>/bookings</td><td>/hotels/**/bookings</td></tr>
- * <tr><td>/hotels</td><td>{hotel}</td><td>/hotels/{hotel}</td></tr> <tr><td>/hotels/*</td><td>{hotel}</td><td>/hotels/{hotel}</td></tr>
- * <tr><td>/hotels/**</td><td>{hotel}</td><td>/hotels/**/{hotel}</td></tr>
- * <tr><td>/*.html</td><td>/hotels.html</td><td>/hotels.html</td></tr> <tr><td>/*.html</td><td>/hotels</td><td>/hotels.html</td></tr>
- * <tr><td>/*.html</td><td>/*.txt</td><td>IllegalArgumentException</td></tr> </table>
- * @param pattern1 the first pattern
- * @param pattern2 the second pattern
- * @return the combination current the two patterns
- * @throws IllegalArgumentException when the two patterns cannot be combined
- */
- public String combine(String pattern1, String pattern2) {
- if (!StringUtils.hasText(pattern1) && !StringUtils.hasText(pattern2)) {
- return "";
- }
- if (!StringUtils.hasText(pattern1)) {
- return pattern2;
- }
- if (!StringUtils.hasText(pattern2)) {
- return pattern1;
- }
-
- boolean pattern1ContainsUriVar = pattern1.indexOf('{') != -1;
- if (!pattern1.equals(pattern2) && !pattern1ContainsUriVar && match(pattern1, pattern2)) {
- // /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
- // However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
- return pattern2;
- }
-
- // /hotels/* + /booking -> /hotels/booking
- // /hotels/* + booking -> /hotels/booking
- if (pattern1.endsWith(this.pathSeparatorPatternCache.getEndsOnWildCard())) {
- return concat(pattern1.substring(0, pattern1.length() - 2), pattern2);
- }
-
- // /hotels/** + /booking -> /hotels/**/booking
- // /hotels/** + booking -> /hotels/**/booking
- if (pattern1.endsWith(this.pathSeparatorPatternCache.getEndsOnDoubleWildCard())) {
- return concat(pattern1, pattern2);
- }
-
- int starDotPos1 = pattern1.indexOf("*.");
- if (pattern1ContainsUriVar || starDotPos1 == -1 || this.pathSeparator.equals(".")) {
- // simply concatenate the two patterns
- return concat(pattern1, pattern2);
- }
- String extension1 = pattern1.substring(starDotPos1 + 1);
- int dotPos2 = pattern2.indexOf('.');
- String fileName2 = (dotPos2 == -1 ? pattern2 : pattern2.substring(0, dotPos2));
- String extension2 = (dotPos2 == -1 ? "" : pattern2.substring(dotPos2));
- String extension = extension1.startsWith("*") ? extension2 : extension1;
- return fileName2 + extension;
- }
-
- private String concat(String path1, String path2) {
- if (path1.endsWith(this.pathSeparator) || path2.startsWith(this.pathSeparator)) {
- return path1 + path2;
- }
- return path1 + this.pathSeparator + path2;
- }
-
- /**
- * Given a full path, returns a {@link Comparator} suitable for sorting patterns in order current explicitness.
- * <p>The returned {@code Comparator} will {@linkplain java.util.Collections#sort(java.util.List,
- * java.util.Comparator) sort} a list so that more specific patterns (without uri templates or wild cards) come before
- * generic patterns. So given a list with the following patterns: <ol> <li>{@code /hotels/new}</li>
- * <li>{@code /hotels/{hotel}}</li> <li>{@code /hotels/*}</li> </ol> the returned comparator will sort this
- * list so that the order will be as indicated.
- * <p>The full path given as parameter is used to test for exact matches. So when the given path is {@code /hotels/2},
- * the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
- * @param path the full path to use for comparison
- * @return a comparator capable current sorting patterns in order current explicitness
- */
- public Comparator<String> getPatternComparator(String path) {
- return new AntPatternComparator(path);
- }
-
-
- /**
- * Tests whether or not a string matches against a pattern via a {@link Pattern}.
- * <p>The pattern may contain special characters: '*' means zero or more characters; '?' means one and
- * only one character; '{' and '}' indicate a URI template pattern. For example <tt>/users/{user}</tt>.
- */
- protected static class AntPathStringMatcher {
-
- private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?\\}|[^/{}]|\\\\[{}])+?)\\}");
-
- private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";
-
- private final Pattern pattern;
-
- private final List<String> variableNames = new LinkedList<>();
-
- public AntPathStringMatcher(String pattern) {
- StringBuilder patternBuilder = new StringBuilder();
- Matcher m = GLOB_PATTERN.matcher(pattern);
- int end = 0;
- while (m.find()) {
- patternBuilder.append(quote(pattern, end, m.start()));
- String match = m.group();
- if ("?".equals(match)) {
- patternBuilder.append('.');
- }
- else if ("*".equals(match)) {
- patternBuilder.append(".*");
- }
- else if (match.startsWith("{") && match.endsWith("}")) {
- int colonIdx = match.indexOf(':');
- if (colonIdx == -1) {
- patternBuilder.append(DEFAULT_VARIABLE_PATTERN);
- this.variableNames.add(m.group(1));
- }
- else {
- String variablePattern = match.substring(colonIdx + 1, match.length() - 1);
- patternBuilder.append('(');
- patternBuilder.append(variablePattern);
- patternBuilder.append(')');
- String variableName = match.substring(1, colonIdx);
- this.variableNames.add(variableName);
- }
- }
- end = m.end();
- }
- patternBuilder.append(quote(pattern, end, pattern.length()));
- this.pattern = Pattern.compile(patternBuilder.toString());
- }
-
- private String quote(String s, int start, int end) {
- if (start == end) {
- return "";
- }
- return Pattern.quote(s.substring(start, end));
- }
-
- /**
- * Main entry point.
- * @return {@code true} if the string matches against the pattern, or {@code false} otherwise.
- */
- public boolean matchStrings(String str, Map<String, String> uriTemplateVariables) {
- Matcher matcher = this.pattern.matcher(str);
- if (matcher.matches()) {
- if (uriTemplateVariables != null) {
- // SPR-8455
- if(!(this.variableNames.size() == matcher.groupCount())) {
- throw new IllegalStateException(
- "The number current capturing groups in the pattern segment " + this.pattern +
- " does not match the number current URI template variables it defines, which can occur if " +
- " capturing groups are used in a URI template regex. Use non-capturing groups instead.");
- }
- for (int i = 1; i <= matcher.groupCount(); i++) {
- String name = this.variableNames.get(i - 1);
- String value = matcher.group(i);
- uriTemplateVariables.put(name, value);
- }
- }
- return true;
- }
- else {
- return false;
- }
- }
- }
-
-
- /**
- * The default {@link Comparator} implementation returned by
- * {@link #getPatternComparator(String)}.
- * <p>In order, the most "generic" pattern is determined by the following:
- * <ul>
- * <li>if it's null or a capture all pattern (i.e. it is equal to "/**")</li>
- * <li>if the other pattern is an actual match</li>
- * <li>if it's a catch-all pattern (i.e. it ends with "**"</li>
- * <li>if it's got more "*" than the other pattern</li>
- * <li>if it's got more "{foo}" than the other pattern</li>
- * <li>if it's shorter than the other pattern</li>
- * </ul>
- */
- protected static class AntPatternComparator implements Comparator<String> {
-
- private final String path;
-
- public AntPatternComparator(String path) {
- this.path = path;
- }
-
- /**
- * Compare two patterns to determine which should match first, i.e. which
- * is the most specific regarding the current path.
- * @return a negative integer, zero, or a positive integer as pattern1 is
- * more specific, equally specific, or less specific than pattern2.
- */
- @Override
- public int compare(String pattern1, String pattern2) {
- PatternInfo info1 = new PatternInfo(pattern1);
- PatternInfo info2 = new PatternInfo(pattern2);
-
- if (info1.isLeastSpecific() && info2.isLeastSpecific()) {
- return 0;
- }
- else if (info1.isLeastSpecific()) {
- return 1;
- }
- else if (info2.isLeastSpecific()) {
- return -1;
- }
-
- boolean pattern1EqualsPath = pattern1.equals(path);
- boolean pattern2EqualsPath = pattern2.equals(path);
- if (pattern1EqualsPath && pattern2EqualsPath) {
- return 0;
- }
- else if (pattern1EqualsPath) {
- return -1;
- }
- else if (pattern2EqualsPath) {
- return 1;
- }
-
- if (info1.isPrefixPattern() && info2.getDoubleWildcards() == 0) {
- return 1;
- }
- else if (info2.isPrefixPattern() && info1.getDoubleWildcards() == 0) {
- return -1;
- }
-
- if (info1.getTotalCount() != info2.getTotalCount()) {
- return info1.getTotalCount() - info2.getTotalCount();
- }
-
- if (info1.getLength() != info2.getLength()) {
- return info2.getLength() - info1.getLength();
- }
-
- if (info1.getSingleWildcards() < info2.getSingleWildcards()) {
- return -1;
- }
- else if (info2.getSingleWildcards() < info1.getSingleWildcards()) {
- return 1;
- }
-
- if (info1.getUriVars() < info2.getUriVars()) {
- return -1;
- }
- else if (info2.getUriVars() < info1.getUriVars()) {
- return 1;
- }
-
- return 0;
- }
-
-
- /**
- * Value class that holds information about the pattern, e.g. number current
- * occurrences current "*", "**", and "{" pattern elements.
- */
- private static class PatternInfo {
-
- private final String pattern;
-
- private int uriVars;
-
- private int singleWildcards;
-
- private int doubleWildcards;
-
- private boolean catchAllPattern;
-
- private boolean prefixPattern;
-
- private Integer length;
-
- public PatternInfo(String pattern) {
- this.pattern = pattern;
- if (this.pattern != null) {
- initCounters();
- this.catchAllPattern = this.pattern.equals("/**");
- this.prefixPattern = !this.catchAllPattern && this.pattern.endsWith("/**");
- }
- if (this.uriVars == 0) {
- this.length = (this.pattern != null ? this.pattern.length() : 0);
- }
- }
-
- protected void initCounters() {
- int pos = 0;
- while (pos < this.pattern.length()) {
- if (this.pattern.charAt(pos) == '{') {
- this.uriVars++;
- pos++;
- }
- else if (this.pattern.charAt(pos) == '*') {
- if (pos + 1 < this.pattern.length() && this.pattern.charAt(pos + 1) == '*') {
- this.doubleWildcards++;
- pos += 2;
- }
- else if (!this.pattern.substring(pos - 1).equals(".*")) {
- this.singleWildcards++;
- pos++;
- }
- else {
- pos++;
- }
- }
- else {
- pos++;
- }
- }
- }
-
- public int getUriVars() {
- return this.uriVars;
- }
-
- public int getSingleWildcards() {
- return this.singleWildcards;
- }
-
- public int getDoubleWildcards() {
- return this.doubleWildcards;
- }
-
- public boolean isLeastSpecific() {
- return (this.pattern == null || this.catchAllPattern);
- }
-
- public boolean isPrefixPattern() {
- return this.prefixPattern;
- }
-
- public int getTotalCount() {
- return this.uriVars + this.singleWildcards + (2 * this.doubleWildcards);
- }
-
- /**
- * Returns the length current the given pattern, where template variables are considered to be 1 long.
- */
- public int getLength() {
- if (this.length == null) {
- this.length = VARIABLE_PATTERN.matcher(this.pattern).replaceAll("#").length();
- }
- return this.length;
- }
- }
- }
-
-
- /**
- * A simple cache for patterns that depend on the configured path separator.
- */
- private static class PathSeparatorPatternCache {
-
- private final String endsOnWildCard;
-
- private final String endsOnDoubleWildCard;
-
- public PathSeparatorPatternCache(String pathSeparator) {
- this.endsOnWildCard = pathSeparator + "*";
- this.endsOnDoubleWildCard = pathSeparator + "**";
- }
-
- public String getEndsOnWildCard() {
- return this.endsOnWildCard;
- }
-
- public String getEndsOnDoubleWildCard() {
- return this.endsOnDoubleWildCard;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassPathResource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassPathResource.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassPathResource.java
deleted file mode 100644
index 65c30aa..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassPathResource.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Objects;
-
-/**
- * {@link org.apache.tamaya.core.resource.Resource} implementation for class path resources.
- * Uses either a given ClassLoader or a given Class for loading resources.
- *
- * <p>Supports resolution as {@code java.io.File} if the class path
- * resource resides in the file system, but not for resources in a JAR.
- * Always supports resolution as URL.
- *
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @since 28.12.2003
- * @see ClassLoader#getResourceAsStream(String)
- * @see Class#getResourceAsStream(String)
- */
-public class ClassPathResource extends AbstractFileResolvingResource {
-
- private final String path;
-
- private ClassLoader classLoader;
-
- private Class<?> clazz;
-
-
- /**
- * Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
- * A leading slash will be removed, as the ClassLoader resource access
- * methods will not accept it.
- * <p>The thread context class loader will be used for
- * loading the resource.
- * @param path the absolute path within the class path
- * @see java.lang.ClassLoader#getResourceAsStream(String)
- */
- public ClassPathResource(String path) {
- this(path, (ClassLoader) null);
- }
-
- /**
- * Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
- * A leading slash will be removed, as the ClassLoader resource access
- * methods will not accept it.
- * @param path the absolute path within the classpath
- * @param classLoader the class loader to load the resource with,
- * or {@code null} for the thread context class loader
- * @see ClassLoader#getResourceAsStream(String)
- */
- public ClassPathResource(String path, ClassLoader classLoader) {
- Objects.requireNonNull(path, "Path must not be null");
- String pathToUse = StringUtils.cleanPath(path);
- if (pathToUse.startsWith("/")) {
- pathToUse = pathToUse.substring(1);
- }
- this.path = pathToUse;
- this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
- }
-
- /**
- * Create a new {@code ClassPathResource} for {@code Class} usage.
- * The path can be relative to the given class, or absolute within
- * the classpath via a leading slash.
- * @param path relative or absolute path within the class path
- * @param clazz the class to load resources with
- * @see java.lang.Class#getResourceAsStream
- */
- public ClassPathResource(String path, Class<?> clazz) {
- Objects.requireNonNull(path, "Path must not be null");
- this.path = StringUtils.cleanPath(path);
- this.clazz = clazz;
- }
-
- /**
- * Create a new {@code ClassPathResource} with optional {@code ClassLoader}
- * and {@code Class}. Only for internal usage.
- * @param path relative or absolute path within the classpath
- * @param classLoader the class loader to load the resource with, if any
- * @param clazz the class to load resources with, if any
- */
- protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) {
- this.path = StringUtils.cleanPath(path);
- this.classLoader = classLoader;
- this.clazz = clazz;
- }
-
-
- /**
- * Return the path for this resource (as resource path within the class path).
- */
- public final String getPath() {
- return this.path;
- }
-
- /**
- * Return the ClassLoader that this resource will be obtained from.
- */
- public final ClassLoader getClassLoader() {
- return (this.clazz != null ? this.clazz.getClassLoader() : this.classLoader);
- }
-
-
- /**
- * This implementation checks for the resolution current a resource URL.
- * @see java.lang.ClassLoader#getResource(String)
- * @see java.lang.Class#getResource(String)
- */
- @Override
- public boolean exists() {
- return (resolveURL() != null);
- }
-
- /**
- * Resolves a URL for the underlying class path resource.
- * @return the resolved URL, or {@code null} if not resolvable
- */
- protected URL resolveURL() {
- if (this.clazz != null) {
- return this.clazz.getResource(this.path);
- }
- else if (this.classLoader != null) {
- return this.classLoader.getResource(this.path);
- }
- else {
- return ClassLoader.getSystemResource(this.path);
- }
- }
-
- /**
- * This implementation opens an InputStream for the given class path resource.
- * @see java.lang.ClassLoader#getResourceAsStream(String)
- * @see java.lang.Class#getResourceAsStream(String)
- */
- @Override
- public InputStream getInputStream()throws IOException {
- InputStream is;
- if (this.clazz != null) {
- is = this.clazz.getResourceAsStream(this.path);
- }
- else if (this.classLoader != null) {
- is = this.classLoader.getResourceAsStream(this.path);
- }
- else {
- is = ClassLoader.getSystemResourceAsStream(this.path);
- }
- if (is == null) {
- throw new IOException(getDescription() + " cannot be opened because it does not exist");
- }
- return is;
- }
-
- /**
- * This implementation returns a URL for the underlying class path resource,
- * if available.
- * @see java.lang.ClassLoader#getResource(String)
- * @see java.lang.Class#getResource(String)
- */
- @Override
- public URL getURL() throws IOException {
- URL url = resolveURL();
- if (url == null) {
- throw new FileNotFoundException(getDescription() + " cannot be resolved to URL because it does not exist");
- }
- return url;
- }
-
- /**
- * This implementation creates a ClassPathResource, applying the given path
- * relative to the path current the underlying resource current this descriptor.
- */
- @Override
- public Resource createRelative(String relativePath) {
- String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
- return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
- }
-
- /**
- * This implementation returns the name current the file that this class path
- * resource refers to.
- */
- @Override
- public String getFilename() {
- return StringUtils.getFilename(this.path);
- }
-
- /**
- * This implementation returns a description that includes the class path location.
- */
- @Override
- public String getDescription() {
- StringBuilder builder = new StringBuilder("class path resource [");
- String pathToUse = path;
- if (this.clazz != null && !pathToUse.startsWith("/")) {
- builder.append(ClassUtils.classPackageAsResourcePath(this.clazz));
- builder.append('/');
- }
- if (pathToUse.startsWith("/")) {
- pathToUse = pathToUse.substring(1);
- }
- builder.append(pathToUse);
- builder.append(']');
- return builder.toString();
- }
-
- /**
- * This implementation compares the underlying class path locations.
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (obj instanceof ClassPathResource) {
- ClassPathResource otherRes = (ClassPathResource) obj;
- return (this.path.equals(otherRes.path) &&
- Objects.equals(this.classLoader, otherRes.classLoader) &&
- Objects.equals(this.clazz, otherRes.clazz));
- }
- return false;
- }
-
- /**
- * This implementation returns the hash code current the underlying
- * class path location.
- */
- @Override
- public int hashCode() {
- return this.path.hashCode();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java
deleted file mode 100644
index 7b6efec..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java
+++ /dev/null
@@ -1,1232 +0,0 @@
-/*
-* Copyright 2002-2014 the original author or authors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.tamaya.core.internal.resources.io;
-
-import java.lang.reflect.Array;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-
-/**
-* Miscellaneous class utility methods.
-* Mainly for internal use within the framework.
-*
-* @author Juergen Hoeller
-* @author Keith Donald
-* @author Rob Harrop
-* @author Sam Brannen
-* @since 1.1
-*/
-public class ClassUtils {
-
- /** Suffix for array class names: "[]" */
- public static final String ARRAY_SUFFIX = "[]";
-
- /** Prefix for internal array class names: "[" */
- private static final String INTERNAL_ARRAY_PREFIX = "[";
-
- /** Prefix for internal non-primitive array class names: "[L" */
- private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L";
-
- /** The package separator character '.' */
- private static final char PACKAGE_SEPARATOR = '.';
-
- /** The path separator character '/' */
- private static final char PATH_SEPARATOR = '/';
-
- /** The inner class separator character '$' */
- private static final char INNER_CLASS_SEPARATOR = '$';
-//
-// /** The CGLIB class separator character "$$" */
-// public static final String CGLIB_CLASS_SEPARATOR = "$$";
-//
-// /** The ".class" file suffix */
-// public static final String CLASS_FILE_SUFFIX = ".class";
-//
-
- /**
- * Map with primitive wrapper type as key and corresponding primitive
- * type as keys, for example: Integer.class -> int.class.
- */
- private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<>(8);
-
- /**
- * Map with primitive type as key and corresponding wrapper
- * type as keys, for example: int.class -> Integer.class.
- */
- private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new HashMap<>(8);
-
- /**
- * Map with primitive type name as key and corresponding primitive
- * type as keys, for example: "int" -> "int.class".
- */
- private static final Map<String, Class<?>> primitiveTypeNameMap = new HashMap<>(32);
-//
-// /**
-// * Map with common "java.lang" class name as key and corresponding Class as keys.
-// * Primarily for efficient deserialization current remote invocations.
-// */
-// private static final Map<String, Class<?>> commonClassCache = new HashMap<String, Class<?>>(32);
-//
-//
- static {
- primitiveWrapperTypeMap.put(Boolean.class, boolean.class);
- primitiveWrapperTypeMap.put(Byte.class, byte.class);
- primitiveWrapperTypeMap.put(Character.class, char.class);
- primitiveWrapperTypeMap.put(Double.class, double.class);
- primitiveWrapperTypeMap.put(Float.class, float.class);
- primitiveWrapperTypeMap.put(Integer.class, int.class);
- primitiveWrapperTypeMap.put(Long.class, long.class);
- primitiveWrapperTypeMap.put(Short.class, short.class);
-
- for (Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperTypeMap.entrySet()) {
- primitiveTypeToWrapperMap.put(entry.getValue(), entry.getKey());
-// registerCommonClasses(entry.getKey());
- }
-
- Set<Class<?>> primitiveTypes = new HashSet<>(32);
- primitiveTypes.addAll(primitiveWrapperTypeMap.values());
- primitiveTypes.addAll(Arrays.asList(new Class<?>[] {
- boolean[].class, byte[].class, char[].class, double[].class,
- float[].class, int[].class, long[].class, short[].class}));
- primitiveTypes.add(void.class);
- for (Class<?> primitiveType : primitiveTypes) {
- primitiveTypeNameMap.put(primitiveType.getName(), primitiveType);
- }
-
-// registerCommonClasses(Boolean[].class, Byte[].class, Character[].class, Double[].class,
-// Float[].class, Integer[].class, Long[].class, Short[].class);
-// registerCommonClasses(Number.class, Number[].class, String.class, String[].class,
-// Object.class, Object[].class, Class.class, Class[].class);
-// registerCommonClasses(Throwable.class, Exception.class, RuntimeException.class,
-// Error.class, StackTraceElement.class, StackTraceElement[].class);
- }
-//
-// private ClassUtils(){}
-//
-// /**
-// * Register the given common classes with the ClassUtils cache.
-// */
-// private static void registerCommonClasses(Class<?>... commonClasses) {
-// for (Class<?> clazz : commonClasses) {
-// commonClassCache.put(clazz.getName(), clazz);
-// }
-// }
-//
- /**
- * Return the default ClassLoader to use: typically the thread context
- * ClassLoader, if available; the ClassLoader that loaded the ClassUtils
- * class will be used as fallback.
- * <p>Call this method if you intend to use the thread context ClassLoader
- * in a scenario where you clearly prefer a non-null ClassLoader reference:
- * for example, for class path resource loading (but not necessarily for
- * {@code Class.forName}, which accepts a {@code null} ClassLoader
- * reference as well).
- * @return the default ClassLoader (only {@code null} if even the system
- * ClassLoader isn't accessible)
- * @see Thread#getContextClassLoader()
- * @see ClassLoader#getSystemClassLoader()
- */
- public static ClassLoader getDefaultClassLoader() {
- ClassLoader cl = null;
- try {
- cl = Thread.currentThread().getContextClassLoader();
- }
- catch (Throwable ex) {
- // Cannot access thread context ClassLoader - falling back...
- }
- if (cl == null) {
- // No thread context class loader -> use class loader current this class.
- cl = ClassUtils.class.getClassLoader();
- if (cl == null) {
- // getClassLoader() returning null indicates the bootstrap ClassLoader
- try {
- cl = ClassLoader.getSystemClassLoader();
- }
- catch (Throwable ex) {
- // Cannot access system ClassLoader - oh well, maybe the caller can live with null...
- }
- }
- }
- return cl;
- }
-
-// /**
-// * Override the thread context ClassLoader with the environment's bean ClassLoader
-// * if necessary, i.e. if the bean ClassLoader is not equivalent to the thread
-// * context ClassLoader already.
-// * @param classLoaderToUse the actual ClassLoader to use for the thread context
-// * @return the original thread context ClassLoader, or {@code null} if not overridden
-// */
-// public static ClassLoader overrideThreadContextClassLoader(ClassLoader classLoaderToUse) {
-// Thread currentThread = Thread.currentThread();
-// ClassLoader threadContextClassLoader = currentThread.getContextClassLoader();
-// if (classLoaderToUse != null && !classLoaderToUse.equals(threadContextClassLoader)) {
-// currentThread.setContextClassLoader(classLoaderToUse);
-// return threadContextClassLoader;
-// }
-// else {
-// return null;
-// }
-// }
-
- /**
- * Replacement for {@code Class.forName()} that also returns Class instances
- * for primitives (e.g. "int") and array class names (e.g. "String[]").
- * Furthermore, it is also capable current resolving inner class names in Java source
- * style (e.g. "java.lang.Thread.State" instead current "java.lang.Thread$State").
- * @param name the name current the Class
- * @param classLoader the class loader to use
- * (may be {@code null}, which indicates the default class loader)
- * @return Class instance for the supplied name
- * @throws ClassNotFoundException if the class was not found
- * @throws LinkageError if the class file could not be loaded
- * @see Class#forName(String, boolean, ClassLoader)
- */
- public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError {
- Objects.requireNonNull(name, "Name must not be null");
-
- Class<?> clazz = resolvePrimitiveClassName(name);
-// if (clazz == null) {
-// clazz = commonClassCache.get(name);
-// }
- if (clazz != null) {
- return clazz;
- }
-
- // "java.lang.String[]" style arrays
- if (name.endsWith(ARRAY_SUFFIX)) {
- String elementClassName = name.substring(0, name.length() - ARRAY_SUFFIX.length());
- Class<?> elementClass = forName(elementClassName, classLoader);
- return Array.newInstance(elementClass, 0).getClass();
- }
-
- // "[Ljava.lang.String;" style arrays
- if (name.startsWith(NON_PRIMITIVE_ARRAY_PREFIX) && name.endsWith(";")) {
- String elementName = name.substring(NON_PRIMITIVE_ARRAY_PREFIX.length(), name.length() - 1);
- Class<?> elementClass = forName(elementName, classLoader);
- return Array.newInstance(elementClass, 0).getClass();
- }
-
- // "[[I" or "[[Ljava.lang.String;" style arrays
- if (name.startsWith(INTERNAL_ARRAY_PREFIX)) {
- String elementName = name.substring(INTERNAL_ARRAY_PREFIX.length());
- Class<?> elementClass = forName(elementName, classLoader);
- return Array.newInstance(elementClass, 0).getClass();
- }
-
- ClassLoader clToUse = classLoader;
- if (clToUse == null) {
- clToUse = getDefaultClassLoader();
- }
- try {
- return (clToUse != null ? clToUse.loadClass(name) : Class.forName(name));
- }
- catch (ClassNotFoundException ex) {
- int lastDotIndex = name.lastIndexOf(PACKAGE_SEPARATOR);
- if (lastDotIndex != -1) {
- String innerClassName =
- name.substring(0, lastDotIndex) + INNER_CLASS_SEPARATOR + name.substring(lastDotIndex + 1);
- try {
- return (clToUse != null ? clToUse.loadClass(innerClassName) : Class.forName(innerClassName));
- }
- catch (ClassNotFoundException ex2) {
- // Swallow - let original exception get through
- }
- }
- throw ex;
- }
- }
-
-// /**
-// * Resolve the given class name into a Class instance. Supports
-// * primitives (like "int") and array class names (like "String[]").
-// * <p>This is effectively equivalent to the {@code forName}
-// * method with the same arguments, with the only difference being
-// * the exceptions thrown in case current class loading failure.
-// * @param className the name current the Class
-// * @param classLoader the class loader to use
-// * (may be {@code null}, which indicates the default class loader)
-// * @return Class instance for the supplied name
-// * @throws IllegalArgumentException if the class name was not resolvable
-// * (that is, the class could not be found or the class file could not be loaded)
-// * @see #forName(String, ClassLoader)
-// */
-// public static Class<?> resolveClassName(String className, ClassLoader classLoader) throws IllegalArgumentException {
-// try {
-// return forName(className, classLoader);
-// }
-// catch (ClassNotFoundException ex) {
-// throw new IllegalArgumentException("Cannot find class [" + className + "]", ex);
-// }
-// catch (LinkageError ex) {
-// throw new IllegalArgumentException(
-// "Error loading class [" + className + "]: problem with class file or dependent class.", ex);
-// }
-// }
-
- /**
- * Resolve the given class name as primitive class, if appropriate,
- * according to the JVM's naming rules for primitive classes.
- * <p>Also supports the JVM's internal class names for primitive arrays.
- * Does <i>not</i> support the "[]" suffix notation for primitive arrays;
- * this is only supported by {@link #forName(String, ClassLoader)}.
- * @param name the name current the potentially primitive class
- * @return the primitive class, or {@code null} if the name does not denote
- * a primitive class or primitive array class
- */
- public static Class<?> resolvePrimitiveClassName(String name) {
- Class<?> result = null;
- // Most class names will be quite long, considering that they
- // SHOULD sit in a package, so a length check is worthwhile.
- if (name != null && name.length() <= 8) {
- // Could be a primitive - likely.
- result = primitiveTypeNameMap.get(name);
- }
- return result;
- }
-
-// /**
-// * Determine whether the {@link Class} identified by the supplied name is present
-// * and can be loaded. Will return {@code false} if either the class or
-// * one current its dependencies is not present or cannot be loaded.
-// * @param className the name current the class to check
-// * @param classLoader the class loader to use
-// * (may be {@code null}, which indicates the default class loader)
-// * @return whether the specified class is present
-// */
-// public static boolean isPresent(String className, ClassLoader classLoader) {
-// try {
-// forName(className, classLoader);
-// return true;
-// }
-// catch (Throwable ex) {
-// // Class or one current its dependencies is not present...
-// return false;
-// }
-// }
-//
-// /**
-// * Return the user-defined class for the given instance: usually simply
-// * the class current the given instance, but the original class in case current a
-// * CGLIB-generated subclass.
-// * @param instance the instance to check
-// * @return the user-defined class
-// */
-// public static Class<?> getUserClass(Object instance) {
-// Objects.requireNonNull(instance, "Instance must not be null");
-// return getUserClass(instance.getClass());
-// }
-//
-// /**
-// * Return the user-defined class for the given class: usually simply the given
-// * class, but the original class in case current a CGLIB-generated subclass.
-// * @param clazz the class to check
-// * @return the user-defined class
-// */
-// public static Class<?> getUserClass(Class<?> clazz) {
-// if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
-// Class<?> superClass = clazz.getSuperclass();
-// if (superClass != null && !Object.class.equals(superClass)) {
-// return superClass;
-// }
-// }
-// return clazz;
-// }
-//
-// /**
-// * Check whether the given class is cache-safe in the given context,
-// * i.e. whether it is loaded by the given ClassLoader or a parent current it.
-// * @param clazz the class to analyze
-// * @param classLoader the ClassLoader to potentially cache metadata in
-// */
-// public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// try {
-// ClassLoader target = clazz.getClassLoader();
-// if (target == null) {
-// return true;
-// }
-// ClassLoader cur = classLoader;
-// if (cur == target) {
-// return true;
-// }
-// while (cur != null) {
-// cur = cur.getParent();
-// if (cur == target) {
-// return true;
-// }
-// }
-// return false;
-// }
-// catch (SecurityException ex) {
-// // Probably from the system ClassLoader - let's consider it safe.
-// return true;
-// }
-// }
-//
-//
-// /**
-// * Get the class name without the qualified package name.
-// * @param className the className to get the short name for
-// * @return the class name current the class without the package name
-// * @throws IllegalArgumentException if the className is empty
-// */
-// public static String getShortName(String className) {
-// Objects.requireNonNull(className, "Class name must not be empty");
-// int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
-// int nameEndIndex = className.indexOf(CGLIB_CLASS_SEPARATOR);
-// if (nameEndIndex == -1) {
-// nameEndIndex = className.length();
-// }
-// String shortName = className.substring(lastDotIndex + 1, nameEndIndex);
-// shortName = shortName.replace(INNER_CLASS_SEPARATOR, PACKAGE_SEPARATOR);
-// return shortName;
-// }
-//
-// /**
-// * Get the class name without the qualified package name.
-// * @param clazz the class to get the short name for
-// * @return the class name current the class without the package name
-// */
-// public static String getShortName(Class<?> clazz) {
-// return getShortName(getQualifiedName(clazz));
-// }
-//
-// /**
-// * Return the short string name current a Java class in uncapitalized JavaBeans
-// * property format. Strips the outer class name in case current an inner class.
-// * @param clazz the class
-// * @return the short name rendered in a standard JavaBeans property format
-// * @see java.beans.Introspector#decapitalize(String)
-// */
-// public static String getShortNameAsProperty(Class<?> clazz) {
-// String shortName = ClassUtils.getShortName(clazz);
-// int dotIndex = shortName.lastIndexOf(PACKAGE_SEPARATOR);
-// shortName = (dotIndex != -1 ? shortName.substring(dotIndex + 1) : shortName);
-// return Introspector.decapitalize(shortName);
-// }
-//
-// /**
-// * Determine the name current the class file, relative to the containing
-// * package: e.g. "String.class"
-// * @param clazz the class
-// * @return the file name current the ".class" file
-// */
-// public static String getClassFileName(Class<?> clazz) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// String className = clazz.getName();
-// int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
-// return className.substring(lastDotIndex + 1) + CLASS_FILE_SUFFIX;
-// }
-//
-// /**
-// * Determine the name current the package current the given class,
-// * e.g. "java.lang" for the {@code java.lang.String} class.
-// * @param clazz the class
-// * @return the package name, or the empty String if the class
-// * is defined in the default package
-// */
-// public static String getPackageName(Class<?> clazz) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// return getPackageName(clazz.getName());
-// }
-//
-// /**
-// * Determine the name current the package current the given fully-qualified class name,
-// * e.g. "java.lang" for the {@code java.lang.String} class name.
-// * @param fqClassName the fully-qualified class name
-// * @return the package name, or the empty String if the class
-// * is defined in the dObjects.requireNonNullefault package
-// */
-// public static String getPackageName(String fqClassName) {
-// Objects.requireNonNull(fqClassName, "Class name must not be null");
-// int lastDotIndex = fqClassName.lastIndexOf(PACKAGE_SEPARATOR);
-// return (lastDotIndex != -1 ? fqClassName.substring(0, lastDotIndex) : "");
-// }
-//
-// /**
-// * Return the qualified name current the given class: usually simply
-// * the class name, but component type class name + "[]" for arrays.
-// * @param clazz the class
-// * @return the qualified name current the class
-// */
-// public static String getQualifiedName(Class<?> clazz) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// if (clazz.isArray()) {
-// return getQualifiedNameForArray(clazz);
-// }
-// else {
-// return clazz.getName();
-// }
-// }
-//
-// /**
-// * Build a nice qualified name for an array:
-// * component type class name + "[]".
-// * @param clazz the array class
-// * @return a qualified name for the array class
-// */
-// private static String getQualifiedNameForArray(Class<?> clazz) {
-// StringBuilder result = new StringBuilder();
-// while (clazz.isArray()) {
-// clazz = clazz.getComponentType();
-// result.append(ClassUtils.ARRAY_SUFFIX);
-// }
-// result.insert(0, clazz.getName());
-// return result.toString();
-// }
-//
-// /**
-// * Return the qualified name current the given method, consisting current
-// * fully qualified interface/class name + "." + method name.
-// * @param method the method
-// * @return the qualified name current the method
-// */
-// public static String getQualifiedMethodName(Method method) {
-// Objects.requireNonNull(method, "Method must not be null");
-// return method.getDeclaringClass().getName() + "." + method.getName();
-// }
-//
-// /**
-// * Return a descriptive name for the given object's type: usually simply
-// * the class name, but component type class name + "[]" for arrays,
-// * and an appended list current implemented interfaces for JDK proxies.
-// * @param keys the keys to introspect
-// * @return the qualified name current the class
-// */
-// public static String getDescriptiveType(Object keys) {
-// if (keys == null) {
-// return null;
-// }
-// Class<?> clazz = keys.getClass();
-// if (Proxy.isProxyClass(clazz)) {
-// StringBuilder result = new StringBuilder(clazz.getName());
-// result.append(" implementing ");
-// Class<?>[] ifcs = clazz.getInterfaces();
-// for (int i = 0; i < ifcs.length; i++) {
-// result.append(ifcs[i].getName());
-// if (i < ifcs.length - 1) {
-// result.append(',');
-// }
-// }
-// return result.toString();
-// }
-// else if (clazz.isArray()) {
-// return getQualifiedNameForArray(clazz);
-// }
-// else {
-// return clazz.getName();
-// }
-// }
-//
-// /**
-// * Check whether the given class matches the user-specified type name.
-// * @param clazz the class to check
-// * @param typeName the type name to match
-// */
-// public static boolean matchesTypeName(Class<?> clazz, String typeName) {
-// return (typeName != null &&
-// (typeName.equals(clazz.getName()) || typeName.equals(clazz.getSimpleName()) ||
-// (clazz.isArray() && typeName.equals(getQualifiedNameForArray(clazz)))));
-// }
-//
-//
-// /**
-// * Determine whether the given class has a public constructor with the given signature.
-// * <p>Essentially translates {@code NoSuchMethodException} to "false".
-// * @param clazz the clazz to analyze
-// * @param paramTypes the parameter types current the method
-// * @return whether the class has a corresponding constructor
-// * @see Class#getMethod
-// */
-// public static boolean hasConstructor(Class<?> clazz, Class<?>... paramTypes) {
-// return (getConstructorIfAvailable(clazz, paramTypes) != null);
-// }
-//
-// /**
-// * Determine whether the given class has a public constructor with the given signature,
-// * and return it if available (else return {@code null}).
-// * <p>Essentially translates {@code NoSuchMethodException} to {@code null}.
-// * @param clazz the clazz to analyze
-// * @param paramTypes the parameter types current the method
-// * @return the constructor, or {@code null} if not found
-// * @see Class#getConstructor
-// */
-// public static <T> Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// try {
-// return clazz.getConstructor(paramTypes);
-// }
-// catch (NoSuchMethodException ex) {
-// return null;
-// }
-// }
-//
-// /**
-// * Determine whether the given class has a public method with the given signature.
-// * <p>Essentially translates {@code NoSuchMethodException} to "false".
-// * @param clazz the clazz to analyze
-// * @param methodName the name current the method
-// * @param paramTypes the parameter types current the method
-// * @return whether the class has a corresponding method
-// * @see Class#getMethod
-// */
-// public static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
-// return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);
-// }
-//
-// /**
-// * Determine whether the given class has a public method with the given signature,
-// * and return it if available (else throws an {@code IllegalStateException}).
-// * <p>In case current any signature specified, only returns the method if there is a
-// * unique candidate, i.e. a single public method with the specified name.
-// * <p>Essentially translates {@code NoSuchMethodException} to {@code IllegalStateException}.
-// * @param clazz the clazz to analyze
-// * @param methodName the name current the method
-// * @param paramTypes the parameter types current the method
-// * (may be {@code null} to indicate any signature)
-// * @return the method (never {@code null})
-// * @throws IllegalStateException if the method has not been found
-// * @see Class#getMethod
-// */
-// public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// Objects.requireNonNull(methodName, "Method name must not be null");
-// if (paramTypes != null) {
-// try {
-// return clazz.getMethod(methodName, paramTypes);
-// }
-// catch (NoSuchMethodException ex) {
-// throw new IllegalStateException("Expected method not found: " + ex);
-// }
-// }
-// else {
-// Set<Method> candidates = new HashSet<Method>(1);
-// Method[] methods = clazz.getMethods();
-// for (Method method : methods) {
-// if (methodName.equals(method.getName())) {
-// candidates.add(method);
-// }
-// }
-// if (candidates.size() == 1) {
-// return candidates.iterator().next();
-// }
-// else if (candidates.isEmpty()) {
-// throw new IllegalStateException("Expected method not found: " + clazz + "." + methodName);
-// }
-// else {
-// throw new IllegalStateException("No unique method found: " + clazz + "." + methodName);
-// }
-// }
-// }
-//
-// /**
-// * Determine whether the given class has a public method with the given signature,
-// * and return it if available (else return {@code null}).
-// * <p>In case current any signature specified, only returns the method if there is a
-// * unique candidate, i.e. a single public method with the specified name.
-// * <p>Essentially translates {@code NoSuchMethodException} to {@code null}.
-// * @param clazz the clazz to analyze
-// * @param methodName the name current the method
-// * @param paramTypes the parameter types current the method
-// * (may be {@code null} to indicate any signature)
-// * @return the method, or {@code null} if not found
-// * @see Class#getMethod
-// */
-// public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// Objects.requireNonNull(methodName, "Method name must not be null");
-// if (paramTypes != null) {
-// try {
-// return clazz.getMethod(methodName, paramTypes);
-// }
-// catch (NoSuchMethodException ex) {
-// return null;
-// }
-// }
-// else {
-// Set<Method> candidates = new HashSet<Method>(1);
-// Method[] methods = clazz.getMethods();
-// for (Method method : methods) {
-// if (methodName.equals(method.getName())) {
-// candidates.add(method);
-// }
-// }
-// if (candidates.size() == 1) {
-// return candidates.iterator().next();
-// }
-// return null;
-// }
-// }
-//
-// /**
-// * Return the number current methods with a given name (with any argument types),
-// * for the given class and/or its superclasses. Includes non-public methods.
-// * @param clazz the clazz to check
-// * @param methodName the name current the method
-// * @return the number current methods with the given name
-// */
-// public static int getMethodCountForName(Class<?> clazz, String methodName) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// Objects.requireNonNull(methodName, "Method name must not be null");
-// int count = 0;
-// Method[] declaredMethods = clazz.getDeclaredMethods();
-// for (Method method : declaredMethods) {
-// if (methodName.equals(method.getName())) {
-// count++;
-// }
-// }
-// Class<?>[] ifcs = clazz.getInterfaces();
-// for (Class<?> ifc : ifcs) {
-// count += getMethodCountForName(ifc, methodName);
-// }
-// if (clazz.getSuperclass() != null) {
-// count += getMethodCountForName(clazz.getSuperclass(), methodName);
-// }
-// return count;
-// }
-//
-// /**
-// * Does the given class or one current its superclasses at least have one or more
-// * methods with the supplied name (with any argument types)?
-// * Includes non-public methods.
-// * @param clazz the clazz to check
-// * @param methodName the name current the method
-// * @return whether there is at least one method with the given name
-// */
-// public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodName) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// Objects.requireNonNull(methodName, "Method name must not be null");
-// Method[] declaredMethods = clazz.getDeclaredMethods();
-// for (Method method : declaredMethods) {
-// if (method.getName().equals(methodName)) {
-// return true;
-// }
-// }
-// Class<?>[] ifcs = clazz.getInterfaces();
-// for (Class<?> ifc : ifcs) {
-// if (hasAtLeastOneMethodWithName(ifc, methodName)) {
-// return true;
-// }
-// }
-// return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName));
-// }
-//
-// /**
-// * Given a method, which may come from an interface, and a target class used
-// * in the current reflective invocation, find the corresponding target method
-// * if there is one. E.g. the method may be {@code IFoo.bar()} and the
-// * target class may be {@code DefaultFoo}. In this case, the method may be
-// * {@code DefaultFoo.bar()}. This enables attributes on that method to be found.
-// * <p><b>NOTE:</b> In contrast to {@code org.springframework.aop.support.AopUtils#getMostSpecificMethod},
-// * this method does <i>not</i> resolve Java 5 bridge methods automatically.
-// * Call {@code org.springframework.core.BridgeMethodResolver#findBridgedMethod}
-// * if bridge method resolution is desirable (e.g. for obtaining metadata from
-// * the original method definition).
-// * <p><b>NOTE:</b> Since Spring 3.1.1, if Java security settings disallow reflective
-// * access (e.g. calls to {@code Class#getDeclaredMethods} etc, this implementation
-// * will fall back to returning the originally provided method.
-// * @param method the method to be invoked, which may come from an interface
-// * @param targetClass the target class for the current invocation.
-// * May be {@code null} or may not even implement the method.
-// * @return the specific target method, or the original method if the
-// * {@code targetClass} doesn't implement it or is {@code null}
-// */
-// public static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
-// if (method != null && isOverridable(method, targetClass) &&
-// targetClass != null && !targetClass.equals(method.getDeclaringClass())) {
-// try {
-// if (Modifier.isPublic(method.getModifiers())) {
-// try {
-// return targetClass.getMethod(method.getName(), method.getParameterTypes());
-// }
-// catch (NoSuchMethodException ex) {
-// return method;
-// }
-// }
-// else {
-// Method specificMethod =
-// ReflectionUtils.findMethod(targetClass, method.getName(), method.getParameterTypes());
-// return (specificMethod != null ? specificMethod : method);
-// }
-// }
-// catch (SecurityException ex) {
-// // Security settings are disallowing reflective access; fall back to 'method' below.
-// }
-// }
-// return method;
-// }
-//
-// /**
-// * Determine whether the given method is declared by the user or at least pointing to
-// * a user-declared method.
-// * <p>Checks {@link Method#isSynthetic()} (for implementation methods) as well as the
-// * {@code GroovyObject} interface (for interface methods; on an implementation class,
-// * implementations current the {@code GroovyObject} methods will be marked as synthetic anyway).
-// * Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
-// * as user-level methods since they are eventually pointing to a user-declared generic method.
-// * @param method the method to check
-// * @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
-// */
-// public static boolean isUserLevelMethod(Method method) {
-// Objects.requireNonNull(method, "Method must not be null");
-// return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method)));
-// }
-//
-// private static boolean isGroovyObjectMethod(Method method) {
-// return method.getDeclaringClass().getName().equals("groovy.lang.GroovyObject");
-// }
-//
-// /**
-// * Determine whether the given method is overridable in the given target class.
-// * @param method the method to check
-// * @param targetClass the target class to check against
-// */
-// private static boolean isOverridable(Method method, Class<?> targetClass) {
-// if (Modifier.isPrivate(method.getModifiers())) {
-// return false;
-// }
-// if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) {
-// return true;
-// }
-// return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass));
-// }
-//
-// /**
-// * Return a public static method current a class.
-// * @param methodName the static method name
-// * @param clazz the class which defines the method
-// * @param args the parameter types to the method
-// * @return the static method, or {@code null} if no static method was found
-// * @throws IllegalArgumentException if the method name is blank or the clazz is null
-// */
-// public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>... args) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// Objects.requireNonNull(methodName, "Method name must not be null");
-// try {
-// Method method = clazz.getMethod(methodName, args);
-// return Modifier.isStatic(method.getModifiers()) ? method : null;
-// }
-// catch (NoSuchMethodException ex) {
-// return null;
-// }
-// }
-//
-//
-// /**
-// * Check if the given class represents a primitive wrapper,
-// * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
-// * @param clazz the class to check
-// * @return whether the given class is a primitive wrapper class
-// */
-// public static boolean isPrimitiveWrapper(Class<?> clazz) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// return primitiveWrapperTypeMap.containsKey(clazz);
-// }
-//
-// /**
-// * Check if the given class represents a primitive (i.e. boolean, byte,
-// * char, short, int, long, float, or double) or a primitive wrapper
-// * (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double).
-// * @param clazz the class to check
-// * @return whether the given class is a primitive or primitive wrapper class
-// */
-// public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// return (clazz.isPrimitive() || isPrimitiveWrapper(clazz));
-// }
-//
-// /**
-// * Check if the given class represents an array current primitives,
-// * i.e. boolean, byte, char, short, int, long, float, or double.
-// * @param clazz the class to check
-// * @return whether the given class is a primitive array class
-// */
-// public static boolean isPrimitiveArray(Class<?> clazz) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// return (clazz.isArray() && clazz.getComponentType().isPrimitive());
-// }
-//
-// /**
-// * Check if the given class represents an array current primitive wrappers,
-// * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
-// * @param clazz the class to check
-// * @return whether the given class is a primitive wrapper array class
-// */
-// public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType()));
-// }
-//
-// /**
-// * Resolve the given class if it is a primitive class,
-// * returning the corresponding primitive wrapper type instead.
-// * @param clazz the class to check
-// * @return the original class, or a primitive wrapper for the original primitive type
-// */
-// public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// return (clazz.isPrimitive() && clazz != void.class? primitiveTypeToWrapperMap.get(clazz) : clazz);
-// }
-//
-// /**
-// * Check if the right-hand side type may be assigned to the left-hand side
-// * type, assuming setting by reflection. Considers primitive wrapper
-// * classes as assignable to the corresponding primitive types.
-// * @param lhsType the target type
-// * @param rhsType the keys type that should be assigned to the target type
-// * @return if the target type is assignable from the keys type
-// */
-// public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
-// Objects.requireNonNull(lhsType, "Left-hand side type must not be null");
-// Objects.requireNonNull(rhsType, "Right-hand side type must not be null");
-// if (lhsType.isAssignableFrom(rhsType)) {
-// return true;
-// }
-// if (lhsType.isPrimitive()) {
-// Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType);
-// if (resolvedPrimitive != null && lhsType.equals(resolvedPrimitive)) {
-// return true;
-// }
-// }
-// else {
-// Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType);
-// if (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)) {
-// return true;
-// }
-// }
-// return false;
-// }
-//
-// /**
-// * Determine if the given type is assignable from the given keys,
-// * assuming setting by reflection. Considers primitive wrapper classes
-// * as assignable to the corresponding primitive types.
-// * @param type the target type
-// * @param keys the keys that should be assigned to the type
-// * @return if the type is assignable from the keys
-// */
-// public static boolean isAssignableValue(Class<?> type, Object keys) {
-// Objects.requireNonNull(type, "Type must not be null");
-// return (keys != null ? isAssignable(type, keys.getClass()) : !type.isPrimitive());
-// }
-//
-//
-// /**
-// * Convert a "/"-based resource path to a "."-based fully qualified class name.
-// * @param resourcePath the resource path pointing to a class
-// * @return the corresponding fully qualified class name
-// */
-// public static String convertResourcePathToClassName(String resourcePath) {
-// Objects.requireNonNull(resourcePath, "Resource path must not be null");
-// return resourcePath.replace(PATH_SEPARATOR, PACKAGE_SEPARATOR);
-// }
-//
-// /**
-// * Convert a "."-based fully qualified class name to a "/"-based resource path.
-// * @param className the fully qualified class name
-// * @return the corresponding resource path, pointing to the class
-// */
-// public static String convertClassNameToResourcePath(String className) {
-// Objects.requireNonNull(className, "Class name must not be null");
-// return className.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
-// }
-//
-// /**
-// * Return a path suitable for use with {@code ClassLoader.getResource}
-// * (also suitable for use with {@code Class.getResource} by prepending a
-// * slash ('/') to the return keys). Built by taking the package current the specified
-// * class file, converting all dots ('.') to slashes ('/'), adding a trailing slash
-// * if necessary, and concatenating the specified resource name to this.
-// * <br/>As such, this function may be used to build a path suitable for
-// * loading a resource file that is in the same package as a class file,
-// * although {@code org.springframework.core.io.ClassPathResource} is usually
-// * even more convenient.
-// * @param clazz the Class whose package will be used as the base
-// * @param resourceName the resource name to append. A leading slash is optional.
-// * @return the built-up resource path
-// * @see ClassLoader#getResource
-// * @see Class#getResource
-// */
-// public static String addResourcePathToPackagePath(Class<?> clazz, String resourceName) {
-// Objects.requireNonNull(resourceName, "Resource name must not be null");
-// if (!resourceName.startsWith("/")) {
-// return classPackageAsResourcePath(clazz) + "/" + resourceName;
-// }
-// return classPackageAsResourcePath(clazz) + resourceName;
-// }
-
- /**
- * Given an input class object, return a string which consists current the
- * class's package name as a pathname, i.e., all dots ('.') are replaced by
- * slashes ('/'). Neither a leading nor trailing slash is added. The result
- * could be concatenated with a slash and the name current a resource and fed
- * directly to {@code ClassLoader.getResource()}. For it to be fed to
- * {@code Class.getResource} instead, a leading slash would also have
- * to be prepended to the returned keys.
- * @param clazz the input class. A {@code null} keys or the default
- * (empty) package will result in an empty string ("") being returned.
- * @return a path which represents the package name
- * @see ClassLoader#getResource
- * @see Class#getResource
- */
- public static String classPackageAsResourcePath(Class<?> clazz) {
- if (clazz == null) {
- return "";
- }
- String className = clazz.getName();
- int packageEndIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
- if (packageEndIndex == -1) {
- return "";
- }
- String packageName = className.substring(0, packageEndIndex);
- return packageName.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
- }
-
-// /**
-// * Build a String that consists current the names current the classes/interfaces
-// * in the given array.
-// * <p>Basically like {@code AbstractCollection.toString()}, but stripping
-// * the "class "/"interface " prefix before every class name.
-// * @param classes a Collection current Class objects (may be {@code null})
-// * @return a String current form "[com.foo.Bar, com.foo.Baz]"
-// * @see java.util.AbstractCollection#toString()
-// */
-// public static String classNamesToString(Class<?>... classes) {
-// return classNamesToString(Arrays.asList(classes));
-// }
-//
-// /**
-// * Build a String that consists current the names current the classes/interfaces
-// * in the given collection.
-// * <p>Basically like {@code AbstractCollection.toString()}, but stripping
-// * the "class "/"interface " prefix before every class name.
-// * @param classes a Collection current Class objects (may be {@code null})
-// * @return a String current form "[com.foo.Bar, com.foo.Baz]"
-// * @see java.util.AbstractCollection#toString()
-// */
-// public static String classNamesToString(Collection<Class<?>> classes) {
-// if (classes.isEmpty()) {
-// return "[]";
-// }
-// StringBuilder sb = new StringBuilder("[");
-// for (Iterator<Class<?>> it = classes.iterator(); it.hasNext(); ) {
-// Class<?> clazz = it.next();
-// sb.append(clazz.getName());
-// if (it.hasNext()) {
-// sb.append(", ");
-// }
-// }
-// sb.append("]");
-// return sb.toString();
-// }
-//
-// /**
-// * Copy the given Collection into a Class array.
-// * The Collection must contain Class elements only.
-// * @param collection the Collection to copy
-// * @return the Class array ({@code null} if the passed-in
-// * Collection was {@code null})
-// */
-// public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
-// if (collection == null) {
-// return null;
-// }
-// return collection.toArray(new Class<?>[collection.size()]);
-// }
-//
-// /**
-// * Return all interfaces that the given instance implements as array,
-// * including ones implemented by superclasses.
-// * @param instance the instance to analyze for interfaces
-// * @return all interfaces that the given instance implements as array
-// */
-// public static Class<?>[] getAllInterfaces(Object instance) {
-// Objects.requireNonNull(instance, "Instance must not be null");
-// return getAllInterfacesForClass(instance.getClass());
-// }
-//
-// /**
-// * Return all interfaces that the given class implements as array,
-// * including ones implemented by superclasses.
-// * <p>If the class itself is an interface, it gets returned as sole interface.
-// * @param clazz the class to analyze for interfaces
-// * @return all interfaces that the given object implements as array
-// */
-// public static Class<?>[] getAllInterfacesForClass(Class<?> clazz) {
-// return getAllInterfacesForClass(clazz, null);
-// }
-//
-// /**
-// * Return all interfaces that the given class implements as array,
-// * including ones implemented by superclasses.
-// * <p>If the class itself is an interface, it gets returned as sole interface.
-// * @param clazz the class to analyze for interfaces
-// * @param classLoader the ClassLoader that the interfaces need to be visible in
-// * (may be {@code null} when accepting all declared interfaces)
-// * @return all interfaces that the given object implements as array
-// */
-// public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) {
-// Set<Class<?>> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
-// return ifcs.toArray(new Class<?>[ifcs.size()]);
-// }
-//
-// /**
-// * Return all interfaces that the given instance implements as Set,
-// * including ones implemented by superclasses.
-// * @param instance the instance to analyze for interfaces
-// * @return all interfaces that the given instance implements as Set
-// */
-// public static Set<Class<?>> getAllInterfacesAsSet(Object instance) {
-// Objects.requireNonNull(instance, "Instance must not be null");
-// return getAllInterfacesForClassAsSet(instance.getClass());
-// }
-//
-// /**
-// * Return all interfaces that the given class implements as Set,
-// * including ones implemented by superclasses.
-// * <p>If the class itself is an interface, it gets returned as sole interface.
-// * @param clazz the class to analyze for interfaces
-// * @return all interfaces that the given object implements as Set
-// */
-// public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz) {
-// return getAllInterfacesForClassAsSet(clazz, null);
-// }
-//
-// /**
-// * Return all interfaces that the given class implements as Set,
-// * including ones implemented by superclasses.
-// * <p>If the class itself is an interface, it gets returned as sole interface.
-// * @param clazz the class to analyze for interfaces
-// * @param classLoader the ClassLoader that the interfaces need to be visible in
-// * (may be {@code null} when accepting all declared interfaces)
-// * @return all interfaces that the given object implements as Set
-// */
-// public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
-// Objects.requireNonNull(clazz, "Class must not be null");
-// if (clazz.isInterface() && isVisible(clazz, classLoader)) {
-// return Collections.<Class<?>>singleton(clazz);
-// }
-// Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>();
-// while (clazz != null) {
-// Class<?>[] ifcs = clazz.getInterfaces();
-// for (Class<?> ifc : ifcs) {
-// interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));
-// }
-// clazz = clazz.getSuperclass();
-// }
-// return interfaces;
-// }
-//
-// /**
-// * Create a composite interface Class for the given interfaces,
-// * implementing the given interfaces in one single Class.
-// * <p>This implementation builds a JDK proxy class for the given interfaces.
-// * @param interfaces the interfaces to merge
-// * @param classLoader the ClassLoader to of the composite Class in
-// * @return the merged interface as Class
-// * @see java.lang.reflect.Proxy#getProxyClass
-// */
-// public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) {
-// if(interfaces.length==0) throw new IllegalArgumentException("Interfaces must not be empty");
-// Objects.requireNonNull(classLoader, "ClassLoader must not be null");
-// return Proxy.getProxyClass(classLoader, interfaces);
-// }
-//
-// /**
-// * Determine the common ancestor current the given classes, if any.
-// * @param clazz1 the class to introspect
-// * @param clazz2 the other class to introspect
-// * @return the common ancestor (i.e. common superclass, one interface
-// * extending the other), or {@code null} if none found. If any current the
-// * given classes is {@code null}, the other class will be returned.
-// * @since 3.2.6
-// */
-// public static Class<?> determineCommonAncestor(Class<?> clazz1, Class<?> clazz2) {
-// if (clazz1 == null) {
-// return clazz2;
-// }
-// if (clazz2 == null) {
-// return clazz1;
-// }
-// if (clazz1.isAssignableFrom(clazz2)) {
-// return clazz1;
-// }
-// if (clazz2.isAssignableFrom(clazz1)) {
-// return clazz2;
-// }
-// Class<?> ancestor = clazz1;
-// do {
-// ancestor = ancestor.getSuperclass();
-// if (ancestor == null || Object.class.equals(ancestor)) {
-// return null;
-// }
-// }
-// while (!ancestor.isAssignableFrom(clazz2));
-// return ancestor;
-// }
-//
-// /**
-// * Check whether the given class is visible in the given ClassLoader.
-// * @param clazz the class to check (typically an interface)
-// * @param classLoader the ClassLoader to check against (may be {@code null},
-// * in which case this method will always return {@code true})
-// */
-// public static boolean isVisible(Class<?> clazz, ClassLoader classLoader) {
-// if (classLoader == null) {
-// return true;
-// }
-// try {
-// Class<?> actualClass = classLoader.loadClass(clazz.getName());
-// return (clazz == actualClass);
-// // Else: different interface class found...
-// }
-// catch (ClassNotFoundException ex) {
-// // No interface class found...
-// return false;
-// }
-// }
-//
-// /**
-// * Check whether the given object is a CGLIB proxy.
-// * @param object the object to check
-// */
-// public static boolean isCglibProxy(Object object) {
-// return ClassUtils.isCglibProxyClass(object.getClass());
-// }
-//
-// /**
-// * Check whether the specified class is a CGLIB-generated class.
-// * @param clazz the class to check
-// */
-// public static boolean isCglibProxyClass(Class<?> clazz) {
-// return (clazz != null && isCglibProxyClassName(clazz.getName()));
-// }
-//
-// /**
-// * Check whether the specified class name is a CGLIB-generated class.
-// * @param className the class name to check
-// */
-// public static boolean isCglibProxyClassName(String className) {
-// return (className != null && className.contains(CGLIB_CLASS_SEPARATOR));
-// }
-
-}
[21/27] incubator-tamaya git commit: TAMAYA-45,
46: Added initial module for cdi integration module.
Posted by an...@apache.org.
TAMAYA-45,46: Added initial module for cdi integration module.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/6feab0df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/6feab0df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/6feab0df
Branch: refs/heads/master
Commit: 6feab0df95b352765752760dca856e28cf746f37
Parents: fa70437
Author: anatole <an...@apache.org>
Authored: Sat Jan 3 09:48:43 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 3 09:48:43 2015 +0100
----------------------------------------------------------------------
modules/integration/cdi/pom.xml | 178 +++++++++++++++++++++++++++++++++++
1 file changed, 178 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6feab0df/modules/integration/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/pom.xml b/modules/integration/cdi/pom.xml
new file mode 100644
index 0000000..1909bcc
--- /dev/null
+++ b/modules/integration/cdi/pom.xml
@@ -0,0 +1,178 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.integration</groupId>
+ <artifactId>tamaya-integration-all</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-cdi</artifactId>
+ <name>Apache Tamaya Modules Integration - CDI</name>
+ <packaging>jar</packaging>
+
+ <properties>
+ <owb.version>1.5.0-SNAPSHOT</owb.version>
+ <weld.version>2.2.7.Final</weld.version>
+ <geronimo-jcdi-1.1-spec.version>1.0-SNAPSHOT</geronimo-jcdi-1.1-spec.version>
+ <geronimo-interceptor-1.2-spec.version>1.0-SNAPSHOT</geronimo-interceptor-1.2-spec.version>
+ <geronimo-atinject-1.0-spec.version>1.0</geronimo-atinject-1.0-spec.version>
+ <bval.version>0.5</bval.version>
+ <ds.version>1.1.0</ds.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+ <version>${geronimo-jcdi-1.1-spec.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.modules</groupId>
+ <artifactId>deltaspike-test-control-module-api</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.modules</groupId>
+ <artifactId>deltaspike-test-control-module-impl</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>OWB</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <!-- OWB specific dependencies-->
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>${geronimo-atinject-1.0-spec.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.2_spec</artifactId>
+ <version>${geronimo-interceptor-1.2-spec.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.2_spec</artifactId>
+ <version>1.0.MR2-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-el_2.2_spec</artifactId>
+ <version>1.0.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-impl</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-spi</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-resource</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.bval</groupId>
+ <artifactId>bval-jsr303</artifactId>
+ <version>${bval.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.cdictrl</groupId>
+ <artifactId>deltaspike-cdictrl-owb</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>Weld</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.weld.se</groupId>
+ <artifactId>weld-se</artifactId>
+ <version>${weld.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.cdictrl</groupId>
+ <artifactId>deltaspike-cdictrl-weld</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+</project>
[02/27] incubator-tamaya git commit: TAMAYA-42: Fixed Javadoc.
Posted by an...@apache.org.
TAMAYA-42: Fixed Javadoc.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/5f58e718
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/5f58e718
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/5f58e718
Branch: refs/heads/master
Commit: 5f58e7184190693047bac7ee475e61aee9470f88
Parents: cdb4d13
Author: anatole <an...@apache.org>
Authored: Sat Jan 3 09:42:31 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 3 09:42:31 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/tamaya/spi/ConfigurationContext.java | 6 +++---
api/src/test/java/org/apache/tamaya/TestConfiguration.java | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5f58e718/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index 3dc0daa..21d08da 100644
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -40,11 +40,11 @@ public interface ConfigurationContext {
/**
* This method returns the current list of registered PropertySources ordered via their ordinal.
- * PropertySources with a lower ordinal come first. The PropertySource with the
- * highest ordinal comes last.
+ * PropertySources with a lower ordinal come last. The PropertySource with the
+ * highest ordinal comes first.
* If two PropertySources have the same ordinal number they will get sorted
* using their class name just to ensure the user at least gets the same ordering
- * after a JVM restart.
+ * after a JVM restart, hereby names before are added last.
* PropertySources are loaded when this method is called the first time, which basically is
* when the first time configuration is accessed.
*
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5f58e718/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/api/src/test/java/org/apache/tamaya/TestConfiguration.java
index 5a33c53..122d671 100644
--- a/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -21,7 +21,7 @@ package org.apache.tamaya;
import java.util.Optional;
/**
- * Test Configuration class, that is used to test the default methods provided by the API.
+ * Test Configuration class, that is used to testdata the default methods provided by the API.
*/
public class TestConfiguration implements Configuration{
[14/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/DynamicValue.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/DynamicValue.java b/dormant/api/src/main/java/org/apache/tamaya/DynamicValue.java
deleted file mode 100644
index b8e0cf5..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/DynamicValue.java
+++ /dev/null
@@ -1,500 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-import java.beans.PropertyChangeEvent;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.lang.ref.WeakReference;
-import java.util.*;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
-import java.util.logging.Logger;
-
-/**
- * A accessor for a single configured value. This can be used to support values that may change during runtime, reconfigured or
- * final. Hereby external code (could be Tamaya configuration listners or client code), can set a new value. Depending on the
- * {@link org.apache.tamaya.DynamicValue.UpdatePolicy} the new value is immedeately active or it requires an active commit
- * by client code. Similarly an instance also can ignore all later changes to the value.
- * <h3>Implementation Details</h3>
- * This class is
- * <ul>
- * <li>Serializable, when also the item stored is serializable</li>
- * <li>Thread safe</li>
- * </ul>
- */
-public final class DynamicValue<T> implements Serializable{
-
- /**
- * Policy to control how new values are applied to this instance.
- */
- enum UpdatePolicy{
- /** New values are applied immedately and registered listeners are informed about the change. */
- IMMEDIATE,
- /** New values or not applied, but stored in the newValue property. Explcit call to #commit
- of #commitAndGet are required to accept the change and inform the listeners about the change.
- */
- EXPLCIT,
- /**
- * New values are always immedately discarded.
- */
- NEVER,
- /**
- * Changes are logged before the are discarded.
- */
- LOG_AND_DISCARD
- }
-
-
- /** The property name of the entry. */
- private String propertyName;
- /**
- * Policy that defines how new values are applied, be default it is applied initially once, but never updated anymore.
- */
- private UpdatePolicy updatePolicy = UpdatePolicy.NEVER;
- /** The current value, never null. */
- private transient Optional<T> value;
- /** The new value, or null. */
- private transient Optional<T> newValue;
- /** List of listeners that listen for changes. */
- private transient WeakList<Consumer<PropertyChangeEvent>> listeners;
-
- /**
- * Returns an empty {@code Optional} instance. No value is present for this
- * Optional.
- *
- * @apiNote Though it may be tempting to do so, avoid testing if an object
- * is empty by comparing with {@code ==} against instances returned by
- * {@code Option.empty()}. There is no guarantee that it is a singleton.
- * Instead, use {@link #isPresent()}.
- *
- * @param <T> Type of the non-existent value
- * @return an empty {@code Optional}
- */
- public static <T> DynamicValue<T> empty(String propertyName) {
- DynamicValue v = new DynamicValue<T>(propertyName, null);
- return v;
- }
-
- /**
- * Constructor.
- * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
- * @param item the initial value.
- */
- private DynamicValue(String propertyName, Optional<T> item){
- this.propertyName = Objects.requireNonNull(propertyName);
- this.value = item;
- }
-
- /**
- * Creates a new instance.
- * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
- * @param value the initial value, not null.
- * @param <T> the type
- * @return a new instance, never null
- */
- public static <T> DynamicValue<T> of(String propertyName, T value){
- return new DynamicValue(propertyName, Optional.of(value));
- }
-
- /**
- * Creates a new instance.
- * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
- * @param value the initial value
- * @param <T> the target type.
- * @return a new instance, never null
- */
- public static <T> DynamicValue<T> ofNullable(String propertyName, T value){
- return value == null ? empty(propertyName) : of(propertyName, value);
- }
-
- /**
- * Performs a commit, if necessary and returns the current value.
- * otherwise throws {@code ConfigException}.
- *
- * @return the non-null value held by this {@code Optional}
- * @throws org.apache.tamaya.ConfigException if there is no value present
- *
- * @see DynamicValue#isPresent()
- */
- public T commitAndGet(){
- commit();
- return get();
- }
-
- /**
- * Commits a new value that has not been committed yet, make it the new value of the instance. On change any registered listeners will be triggered.
- */
- public void commit(){
- synchronized (value){
- if(newValue!=null){
- PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, value.orElse(null), newValue.orElse(null));
- value = newValue;
- newValue = null;
- for(Consumer<PropertyChangeEvent> consumer: listeners.get()){
- consumer.accept(evt);
- }
- }
- }
- }
-
- /**
- * Discards a new value that was published. No listeners will be informed.
- */
- public void discard(){
- newValue = null;
- }
-
-
-
- /**
- * Access the {@link UpdatePolicy} used for updating this value.
- * @return the update policy, never null.
- */
- public UpdatePolicy getUpdatePolicy() {
- return updatePolicy;
- }
-
- /**
- * Add a listener to be called as weak reference, when this value has been changed.
- * @param l the listner, not null
- */
- public void addListener(Consumer<PropertyChangeEvent> l) {
- if(listeners==null){
- listeners = new WeakList<>();
- }
- listeners.add(l);
- }
-
- /**
- * Removes a listener to be called, when this value has been changed.
- * @param l the listner to be removed, not null
- */
- public void removeListener(Consumer<PropertyChangeEvent> l) {
- if(listeners!=null){
- listeners.remove(l);
- }
- }
-
- /**
- * If a value is present in this {@code ConfiguredValue}, returns the value,
- * otherwise throws {@code ConfigException}.
- *
- * @return the non-null value held by this {@code Optional}
- * @throws org.apache.tamaya.ConfigException if there is no value present
- *
- * @see DynamicValue#isPresent()
- */
- public T get() {
- return value.get();
- }
-
- /**
- * Method to apply a new value. Depending on the {@link org.apache.tamaya.DynamicValue.UpdatePolicy}
- * the value is immediately or deferred visible (or it may even be ignored completely).
- * @param newValue the new value, may also be null.
- */
- public void setNewValue(T newValue){
- switch(this.updatePolicy){
- case IMMEDIATE:
- this.newValue = Optional.ofNullable(newValue);
- commit();
- break;
- case EXPLCIT:
- this.newValue = Optional.ofNullable(newValue);
- break;
- case LOG_AND_DISCARD:
- Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", newValue="+newValue);
- this.newValue = null;
- break;
- case NEVER:
- this.newValue = null;
- break;
- }
-
- }
-
- /**
- * Sets a new {@link org.apache.tamaya.DynamicValue.UpdatePolicy}.
- * @param updatePolicy the new policy, not null.
- */
- public void setUpdatePolicy(UpdatePolicy updatePolicy){
- this.updatePolicy = Objects.requireNonNull(updatePolicy);
- }
-
- /**
- * Access a new value that has not yet been committed.
- * @return the uncommitted new value, or null.
- */
- public T getNewValue(){
- Optional<T> nv = newValue;
- if(nv!=null){
- return nv.orElse(null);
- }
- return null;
- }
-
- /**
- * Return {@code true} if there is a value present, otherwise {@code false}.
- *
- * @return {@code true} if there is a value present, otherwise {@code false}
- */
- public boolean isPresent() {
- return value.isPresent();
- }
-
- /**
- * If a value is present, invoke the specified consumer with the value,
- * otherwise do nothing.
- *
- * @param consumer block to be executed if a value is present
- * @throws NullPointerException if value is present and {@code consumer} is
- * null
- */
- public void ifPresent(Consumer<? super T> consumer) {
- value.ifPresent(consumer);
- }
-
- /**
- * If a value is present, and the value matches the given predicate,
- * return an {@code Optional} describing the value, otherwise return an
- * empty {@code Optional}.
- *
- * @param predicate a predicate to apply to the value, if present
- * @return an {@code Optional} describing the value of this {@code Optional}
- * if a value is present and the value matches the given predicate,
- * otherwise an empty {@code Optional}
- * @throws NullPointerException if the predicate is null
- */
- public DynamicValue<T> filter(Predicate<? super T> predicate) {
- Objects.requireNonNull(predicate);
- if (!isPresent())
- return this;
- else
- return predicate.test(value.get()) ? this : empty(propertyName);
- }
-
- /**
- * If a value is present, apply the provided mapping function to it,
- * and if the result is non-null, return an {@code Optional} describing the
- * result. Otherwise return an empty {@code Optional}.
- *
- * @apiNote This method supports post-processing on optional values, without
- * the need to explicitly check for a return status. For example, the
- * following code traverses a stream of file names, selects one that has
- * not yet been processed, and then opens that file, returning an
- * {@code Optional<FileInputStream>}:
- *
- * <pre>{@code
- * Optional<FileInputStream> fis =
- * names.stream().filter(name -> !isProcessedYet(name))
- * .findFirst()
- * .map(name -> new FileInputStream(name));
- * }</pre>
- *
- * Here, {@code findFirst} returns an {@code Optional<String>}, and then
- * {@code map} returns an {@code Optional<FileInputStream>} for the desired
- * file if one exists.
- *
- * @param <U> The type of the result of the mapping function
- * @param mapper a mapping function to apply to the value, if present
- * @return an {@code Optional} describing the result of applying a mapping
- * function to the value of this {@code Optional}, if a value is present,
- * otherwise an empty {@code Optional}
- * @throws NullPointerException if the mapping function is null
- */
- public <U> DynamicValue<U> map(Function<? super T, ? extends U> mapper) {
- Objects.requireNonNull(mapper);
- if (!isPresent())
- return empty(propertyName);
- else {
- return DynamicValue.ofNullable(propertyName, mapper.apply(value.get()));
- }
- }
-
- /**
- * If a value is present, apply the provided {@code Optional}-bearing
- * mapping function to it, return that result, otherwise return an empty
- * {@code Optional}. This method is similar to {@link #map(Function)},
- * but the provided mapper is one whose result is already an {@code Optional},
- * and if invoked, {@code flatMap} does not wrap it with an additional
- * {@code Optional}.
- *
- * @param <U> The type parameter to the {@code Optional} returned by
- * @param mapper a mapping function to apply to the value, if present
- * the mapping function
- * @return the result of applying an {@code Optional}-bearing mapping
- * function to the value of this {@code Optional}, if a value is present,
- * otherwise an empty {@code Optional}
- * @throws NullPointerException if the mapping function is null or returns
- * a null result
- */
- public <U> DynamicValue<U> flatMap(Function<? super T, DynamicValue<U>> mapper) {
- Objects.requireNonNull(mapper);
- if (!isPresent())
- return empty(propertyName);
- else {
- return Objects.requireNonNull(mapper.apply(value.get()));
- }
- }
-
- /**
- * Return the value if present, otherwise return {@code other}.
- *
- * @param other the value to be returned if there is no value present, may
- * be null
- * @return the value, if present, otherwise {@code other}
- */
- public T orElse(T other) {
- return value.orElse(other);
- }
-
- /**
- * Return the value if present, otherwise invoke {@code other} and return
- * the result of that invocation.
- *
- * @param other a {@code Supplier} whose result is returned if no value
- * is present
- * @return the value if present otherwise the result of {@code other.get()}
- * @throws NullPointerException if value is not present and {@code other} is
- * null
- */
- public T orElseGet(Supplier<? extends T> other) {
- return value.orElseGet(other);
- }
-
- /**
- * Return the contained value, if present, otherwise throw an exception
- * to be created by the provided supplier.
- *
- * @apiNote A method reference to the exception constructor with an empty
- * argument list can be used as the supplier. For example,
- * {@code IllegalStateException::new}
- *
- * @param <X> Type of the exception to be thrown
- * @param exceptionSupplier The supplier which will return the exception to
- * be thrown
- * @return the present value
- * @throws X if there is no value present
- * @throws NullPointerException if no value is present and
- * {@code exceptionSupplier} is null
- */
- public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
- return value.orElseThrow(exceptionSupplier);
- }
-
- /**
- * Converts the instance to an {@link java.util.Optional} instance.
- * @return the corresponding Optional value.
- */
- public Optional<T> toOptional(){
- return value;
- }
-
- /**
- * Serialization implementation that strips away the non serializable Optional part.
- * @param oos the output stream
- * @throws IOException if serialization fails.
- */
- private void writeObject(ObjectOutputStream oos)throws IOException {
- oos.writeObject(updatePolicy);
- if(isPresent()) {
- oos.writeObject(this.value.get());
- }
- else{
- oos.writeObject(null);
- }
- }
-
- /**
- * Reads an instance from the input stream.
- * @param ois the object input stream
- * @throws IOException if deserialization fails.
- * @throws ClassNotFoundException
- */
- private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
- this.updatePolicy = (UpdatePolicy)ois.readObject();
- if(isPresent()) {
- this.value = Optional.of((T) ois.readObject());
- }
- newValue = null;
- }
-
-
- /**
- * Simple helper that allows keeping the listeners registered as weak references, hereby avoiding any
- * memory leaks.
- * @param <T> the type
- */
- private class WeakList<T>{
- List<WeakReference<T>> refs = new LinkedList<>();
-
- /**
- * Adds a new instance.
- * @param t the new instance, not null.
- */
- void add(T t){
- refs.add(new WeakReference(t));
- }
-
- /**
- * Removes a instance.
- * @param t the instance to be removed.
- */
- void remove(T t){
- synchronized (refs){
- for(Iterator<WeakReference<T>> iterator = refs.iterator();iterator.hasNext();){
- WeakReference<T> ref = iterator.next();
- T instance = ref.get();
- if(instance==null || instance == t){
- iterator.remove();
- break;
- }
- }
- }
- }
-
-
- /**
- * Access a list (copy) of the current instances that were not discarded by the GC.
- * @return the list of accessible items.
- */
- public List<T> get() {
- synchronized (refs) {
- List<T> res = new ArrayList<>();
- for (Iterator<WeakReference<T>> iterator = refs.iterator(); iterator.hasNext(); ) {
- WeakReference<T> ref = iterator.next();
- T instance = ref.get();
- if(instance==null){
- iterator.remove();
- }
- else{
- res.add(instance);
- }
- }
- return res;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/PropertyMapSupplier.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/PropertyMapSupplier.java b/dormant/api/src/main/java/org/apache/tamaya/PropertyMapSupplier.java
deleted file mode 100644
index 69dd308..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/PropertyMapSupplier.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.tamaya;
-
-import java.util.Map;
-
-/**
- * Supplier for a property map.
- */
-@FunctionalInterface
-public interface PropertyMapSupplier {
-
- /**
- * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
- * when the underlying storage does not support iteration of its entries.
- *
- * @return the a corresponding map, never null.
- */
- Map<String,String> getProperties();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java
deleted file mode 100644
index e1d773d..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation container to enable injection current multiple {@link org.apache.tamaya.annotation.ConfiguredProperty}
- * annotations. Hereby the ordering current annotations imply the defaulting. The first keys that
- * could be resolved successfully in the chain current annotations will be used.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface ConfiguredProperties {
-
- /**
- * Get the different configuration keys to be looked up, in order current precedence. The first non null keys
- * found will be used.
- */
- ConfiguredProperty[] value() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java
deleted file mode 100644
index 21d4e3a..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import java.lang.annotation.*;
-
-/**
- * Annotation to enable injection current a configured property or define the returned data for
- * a configuration template method. Hereby this annotation can be used in multiple ways and combined
- * with other annotations such as {@link org.apache.tamaya.annotation.DefaultValue},
- * {@link org.apache.tamaya.annotation.WithLoadPolicy}, {@link org.apache.tamaya.annotation.WithConfig},
- * {@link org.apache.tamaya.annotation.WithConfigOperator}, {@link WithPropertyAdapter}.
- *
- * Below the most simple variant current a configured class is given:
- * {@code
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty
- * private String aValue;
- * }
- * When this class is configured, e.g. by passing it to {@link org.apache.tamaya.Configuration#configure(Object)},
- * the following is happening:
- * <ul>
- * <li>The current valid Configuration is evaluated by calling {@code Configuration cfg = Configuration.current();}</li>
- * <li>The current property String keys is evaluated by calling {@code cfg.get("aValue");}</li>
- * <li>if not successful, an error is thrown ({@link org.apache.tamaya.ConfigException}.</li>
- * <li>On success, since no type conversion is involved, the keys is injected.</li>
- * <li>The configured bean is registered as a weak change listener in the config system's underlying
- * configuration, so future config changes can be propagated (controlled by {@link org.apache.tamaya.annotation.WithLoadPolicy}
- * annotations).</li>
- * </ul>
- *
- * In the next example we explicitly define the property keys:
- * {@code
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty
- * @ConfiguredProperty({"a.b.value", "a.b.deprecated.keys", "${env:java.version}"})
- * @ConfiguredProperty(configuration={"a", "b"}
- * @ConfiguredProperty(configuration={"a", "b", keys={"a.b.keys", "a.b.deprecated.keys", "${env:java.version}"}}
- * private String aValue;
- * }
- *
- * Within this example we evaluate multiple possible keys. Evaluation is aborted if a key could be successfully
- * resolved. Hereby the ordering current the annotations define the ordering current resolution, so in the example above
- * resolution equals to {@code "aValue", "a.b.keys", "a.b.deprecated.keys"}. If no keys could be read
- * fromMap the configuration, it uses the keys fromMap the {@code DefaultValue} annotation. Interesting here
- * is that this keys is not static, it is evaluated by calling
- * {@link org.apache.tamaya.Configuration#evaluateValue(String, org.apache.tamaya.Configuration...)}.
- */
-@Repeatable(ConfiguredProperties.class)
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface ConfiguredProperty {
-
- /**
- * Annotation to reference an explicit {@link org.apache.tamaya.Configuration} to be used to
- * resolve the required properties. the configured keys is passed to {@code Configuration.current(String)}
- * to evaluate the required configuration required.
- * @return the configurations to be looked up for the given keys.
- */
- String config() default "";
-
- /**
- * Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys.
- *
- * @return the property names, not null. If missing the field or method name being injected is used by default.
- */
- String[] keys() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/DefaultAreas.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/DefaultAreas.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/DefaultAreas.java
deleted file mode 100644
index 63ea137..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/DefaultAreas.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to control injection and resolution current a configured bean. The configuration keys
- * to be resolved are basically determined by the {@link org.apache.tamaya.annotation.ConfiguredProperty}
- * annotation(s). Nevertheless these annotations can also have relative key names. This annotation allows
- * to define a configuration area that is prefixed to all relative configuration keys within the
- * corresponding class/template interface.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.TYPE })
-public @interface DefaultAreas {
-
- /**
- * Allows to declare an operator that should be applied before injecting values into the bean.
- * @return the operator class to be used.
- */
- String[] value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java
deleted file mode 100644
index c4b2e3a..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define a default keys to be returned, when no configured keys could be
- * determined for a property/template accessor. The keys hereby can also contain a
- * dynamic expression that is evaluated by the configuration system.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface DefaultValue {
-
- /**
- * The default keys to be injected, if no such configuration entry was found. If keys was found and no default
- * is defined, it is handled as a deployment error.
- */
- String value() default "";
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java
deleted file mode 100644
index 116a2c1..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-/**
- * Available policies that describe how changes affecting configured values are published/reinjected.
- * The policy also affects the cases were any configured listeners/listener methods are called for
- * propagation current configuration changes.
- */
-public enum LoadPolicy {
- /**
- * The configuration keys is evaluated once, when the owning component is loaded/configured, but never updated later.
- */
- INITIAL,
- /**
- * The configuration keys is evaluated exactly once on its first use lazily, but never updated later.
- * This feature is not applicable on field injection, but only on configuration template methods.
- */
- LAZY,
- /**
- * The configuration keys is evaluated once, when the owning component is loaded/configured.
- * Later changes on this configuration entry will be reinjected/updated and additionally triggered
- * as {@link java.beans.PropertyChangeEvent}.
- */
- MANAGED,
- /**
- * The configuration keys is evaluated once, when the owning component is loaded/configured.
- * Later changes on this configuration entry will be reinjected/updated, but no {@link java.beans.PropertyChangeEvent}
- * will be triggered.
- */
- SILENT
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java
deleted file mode 100644
index 845ec4c..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import java.lang.annotation.*;
-
-/**
- * This is a small marker annotations to inform Tamaya that the annotated element should never be injected with
- * configured data. This is useful because by default Tamaya tries to lookup and inject configuration also by
- * using property or method names without annotations. With that annotation none of these will be happen.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface NoConfig {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/ObservesConfigChange.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/ObservesConfigChange.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/ObservesConfigChange.java
deleted file mode 100644
index ef92b25..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/ObservesConfigChange.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to annotate a method on a class to be informed on config changes.
- * The exact behaviour, when configuration change events are sent can be configured
- * on each configured property/method by adding the {@link org.apache.tamaya.annotation.WithLoadPolicy}
- * annotation. By default listeners are informed on all changes of configurations that were used as
- * input configurations for configuring a class/instance. Additionally {@link org.apache.tamaya.annotation.ConfiguredProperty}
- * annotations can be added that allows to constrain changes to some limited properties.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.METHOD })
-public @interface ObservesConfigChange {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java
deleted file mode 100644
index 9f6c4f5..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import org.apache.tamaya.Configuration;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.util.function.UnaryOperator;
-
-/**
- * Annotation to define an configuration operator to be used before accessing a configured keys.
- * This allows filtering current configuration, e.g. for realizing views or ensuring security
- * constraints.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
-public @interface WithConfigOperator {
-
- /**
- * Define a custom adapter that should be used to adapt the configuration entry injected. This overrides any
- * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is
- * registered, it is handled as a deployment error.
- */
- Class<? extends UnaryOperator<Configuration>> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java
deleted file mode 100644
index e469f5a..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define how config changes are handled for a type or per property/template method.
- * @see org.apache.tamaya.annotation.LoadPolicy
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
-public @interface WithLoadPolicy {
-
- /**
- * The load policy to be used. If this annotation is present a load policy must be defined.
- * @return The load policy to be used, not null.
- */
- LoadPolicy value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/annotation/WithPropertyAdapter.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/annotation/WithPropertyAdapter.java b/dormant/api/src/main/java/org/apache/tamaya/annotation/WithPropertyAdapter.java
deleted file mode 100644
index fa9cfdf..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/annotation/WithPropertyAdapter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.annotation;
-
-import org.apache.tamaya.PropertyAdapter;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define a type adapter to be used before injecting a configured keys, or for applying changes.
- * This will override any other adapter for performing the type conversion before
- * injecting the field keys.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface WithPropertyAdapter {
-
- /**
- * Define a custom adapter or codec that should be used to adapt the configuration entry injected. This overrides any
- * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is
- * registered, it is handled as a deployment error.
- */
- @SuppressWarnings("rawtypes")
- Class<? extends PropertyAdapter> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/spi/ConfigurationFactorySpi.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/spi/ConfigurationFactorySpi.java b/dormant/api/src/main/java/org/apache/tamaya/spi/ConfigurationFactorySpi.java
deleted file mode 100644
index 3b167cc..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/spi/ConfigurationFactorySpi.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * Factory to create configurations from property sources. If not defines a default is used.
- */
-public interface ConfigurationFactorySpi {
- /**
- * Creates a configuration from a {@link org.apache.tamaya.PropertySource}.
- *
- * @param propertySource the property source
- * @return the corresponding Configuration instance, never null.
- */
- default Configuration from(PropertySource propertySource){
- return new Configuration() {
- @Override
- public String getName() {
- return propertySource.getName();
- }
-
- @Override
- public Optional<String> get(String key) {
- return propertySource.get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return propertySource.getProperties();
- }
-
- @Override
- public String toString(){
- return "Configuration, based on " + propertySource;
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java b/dormant/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
deleted file mode 100644
index 5891dc2..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertyAdapter;
-import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-
-import java.util.Map;
-import java.util.Optional;
-
-
-/**
- * Manager for {@link org.apache.tamaya.Configuration} instances. Implementations must register an instance
- * using the {@link ServiceContextManager} mechanism in place (by default this is based on the {@link java.util.ServiceLoader}.
- * The {@link org.apache.tamaya.Configuration} Singleton in the API delegates its corresponding calls to the
- * instance returned by the current bootstrap service in place.
- *
- * @see org.apache.tamaya.Configuration
- * @see ServiceContextManager
- */
-public interface ConfigurationSpi {
-
- /**
- * Allows to check if a configuration with a given name is defined.
- * @param name the configuration's name, not null, not empty.
- * @return true, if such a configuration is defined.
- */
- boolean isConfigurationAvailable(String name);
-
- /**
- * Access a configuration by name.
- * @param name the configuration's name, not null, not empty.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- Configuration getConfiguration(String name);
-
- /**
- * Access the default configuration.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- default Configuration getConfiguration(){
- return getConfiguration("default");
- }
-
- /**
- * Configures an instance, by resolving and injecting the configuration
- * entries.
- *
- * @param instance the instance with configuration annotations, not null.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @throws org.apache.tamaya.ConfigException if any required configuration could not be resolved/injected.
- */
- void configure(Object instance, Configuration... configurations);
-
- /**
- * Access a configuration by name.
- *
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- <T> T createTemplate(Class<T> template, Configuration... configurations);
-
- /**
- * Evaluate the current expression based on the current configuration valid.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @param expression the expression, not null.
- * @return the evaluated config expression.
- */
- String evaluateValue(String expression, Configuration... configurations);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/main/java/org/apache/tamaya/spi/PropertyAdapterSpi.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/main/java/org/apache/tamaya/spi/PropertyAdapterSpi.java b/dormant/api/src/main/java/org/apache/tamaya/spi/PropertyAdapterSpi.java
deleted file mode 100644
index a1222a4..0000000
--- a/dormant/api/src/main/java/org/apache/tamaya/spi/PropertyAdapterSpi.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertyAdapter;
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-
-
-/**
- * Manager for {@link org.apache.tamaya.Configuration} instances. Implementations must register an instance
- * using the {@link org.apache.tamaya.spi.ServiceContextManager} mechanism in place (by default this is based on the {@link java.util.ServiceLoader}.
- * The {@link org.apache.tamaya.Configuration} Singleton in the API delegates its corresponding calls to the
- * instance returned by the current bootstrap service in place.
- *
- * @see org.apache.tamaya.Configuration
- * @see org.apache.tamaya.spi.ServiceContextManager
- */
-public interface PropertyAdapterSpi {
-
-
- /**
- * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
- * this type.
- * @param targetType The target class, not null.
- * @param adapter The adapter, not null.
- * @param <T> The target type
- * @return any adapter replaced with the new adapter, or null.
- */
- <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter);
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- default <T> PropertyAdapter<T> getAdapter(Class<T> targetType){
- return getPropertyAdapter(targetType, null);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @param <T> the target type
- * @return the corresponding adapter, never null.
- * @throws org.apache.tamaya.ConfigException if the target type is not supported.
- */
- <T> PropertyAdapter<T> getPropertyAdapter(Class<T> targetType, WithPropertyAdapter annotation);
-
- /**
- * Checks if the given target type is supported, i.e. a adapter is registered and accessible.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- boolean isTargetTypeSupported(Class<?> targetType);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/test/java/annottext/AnnotatedConfig.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/test/java/annottext/AnnotatedConfig.java b/dormant/api/src/test/java/annottext/AnnotatedConfig.java
deleted file mode 100644
index 20b135f..0000000
--- a/dormant/api/src/test/java/annottext/AnnotatedConfig.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package annottext;
-
-import org.apache.tamaya.annotation.ConfiguredProperty;
-import org.apache.tamaya.annotation.WithLoadPolicy;
-import org.apache.tamaya.annotation.DefaultValue;
-import org.apache.tamaya.annotation.LoadPolicy;
-
-/**
- * An example showing some basic annotations, using an interface to be proxied by the
- * configuration system.
- * Created by Anatole on 15.02.14.
- */
-@WithLoadPolicy(LoadPolicy.INITIAL)
-public interface AnnotatedConfig {
-
- @ConfiguredProperty(keys = "foo.bar.myprop")
- @ConfiguredProperty(keys = "mp")
- @ConfiguredProperty(keys = "common.test.myProperty")
- @DefaultValue("myValue_$[env.stage]")
- // @ConfigLoadPolicy(listener = MyListener.class)
- String myParameter();
-
- @ConfiguredProperty(keys = "simple_value")
- @WithLoadPolicy(LoadPolicy.LAZY)
- String simpleValue();
-
- @ConfiguredProperty
- String simplestValue();
-
- @ConfiguredProperty(keys = "env.host.name")
- String hostName();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/test/java/annottext/AnnotatedFullConfig.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/test/java/annottext/AnnotatedFullConfig.java b/dormant/api/src/test/java/annottext/AnnotatedFullConfig.java
deleted file mode 100644
index df39d12..0000000
--- a/dormant/api/src/test/java/annottext/AnnotatedFullConfig.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package annottext;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.annotation.ConfiguredProperty;
-import org.apache.tamaya.annotation.WithLoadPolicy;
-import org.apache.tamaya.annotation.DefaultValue;
-import org.apache.tamaya.annotation.LoadPolicy;
-
-/**
- * An example showing some basic annotations, using an interface to be proxied by the
- * configuration system, nevertheless extending the overall Configuration interface.
- * Created by Anatole on 15.02.14.
- */
-@WithLoadPolicy(LoadPolicy.INITIAL)
-public interface AnnotatedFullConfig extends Configuration{
-
- @ConfiguredProperty(keys = "foo.bar.myprop")
- @ConfiguredProperty(keys = "mp")
- @ConfiguredProperty(keys = "common.test.myProperty")
- @DefaultValue("myValue_$[env.stage]")
- // @ConfigLoadPolicy(listener = MyListener.class)
- String myParameter();
-
- @ConfiguredProperty(keys = "simple_value")
- @WithLoadPolicy(LoadPolicy.LAZY)
- String simpleValue();
-
- @ConfiguredProperty
- String simplestValue();
-
- @ConfiguredProperty(keys = "env.host.name")
- String hostName();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java b/dormant/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
deleted file mode 100644
index 858786d..0000000
--- a/dormant/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Consumer;
-
-import org.apache.tamaya.spi.ConfigurationSpi;
-
-/**
- * Created by Anatole on 09.09.2014.
- */
-public class TestConfigServiceSingletonSpi implements ConfigurationSpi {
-
-
- private Map<String, Configuration> configs = new ConcurrentHashMap<>();
-
- public TestConfigServiceSingletonSpi(){
- Map<String,String> config = new HashMap<>();
- config.put("a.b.c.key1", "keys current a.b.c.key1");
- config.put("a.b.c.key2", "keys current a.b.c.key2");
- config.put("a.b.key3", "keys current a.b.key3");
- config.put("a.b.key4", "keys current a.b.key4");
- config.put("a.key5", "keys current a.key5");
- config.put("a.key6", "keys current a.key6");
- config.put("int1", "123456");
- config.put("int2", "111222");
- config.put("booleanT", "true");
- config.put("double1", "1234.5678");
- config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
- config.put("testProperty", "keys current testProperty");
- config.put("runtimeVersion", "${java.version}");
- // configs.put("test", new MapConfiguration(MetaInfoBuilder.current().setName("test").build(), config));
- }
-
-
-
- @Override
- public boolean isConfigurationAvailable(String name){
- return configs.containsKey(name);
- }
-
- @Override
- public Configuration getConfiguration(String name) {
- // TODO
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
- public <T> T createTemplate(Class<T> type, Configuration... configurations) {
- // TODO
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
- public void configure(Object instance, Configuration... configurations) {
- // TODO
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
- public String evaluateValue(String expression, Configuration... configurations) {
- // TODO improve this ugly implementation...
- for (Configuration config : configurations) {
- for (Map.Entry<String, String> en : config.getProperties().entrySet()) {
- expression = expression.replaceAll("\\$\\{" + en.getKey() + "\\}", en.getValue());
- }
- }
- return expression;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/dormant/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java b/dormant/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
deleted file mode 100644
index 65e6c1d..0000000
--- a/dormant/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZoneId;
-import java.util.Currency;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-import org.apache.tamaya.spi.PropertyAdapterSpi;
-
-/**
- * Test implementation current {@link org.apache.tamaya.spi.PropertyAdapterSpi}, which provides propertyAdapters
- * for some basic types.
- */
-@SuppressWarnings({"unchecked", "rawtypes"})
-public final class TestPropertyAdaptersSingletonSpi implements PropertyAdapterSpi {
-
- private Map<Class, PropertyAdapter<?>> propertyAdapters = new ConcurrentHashMap<>();
-
- private TestPropertyAdaptersSingletonSpi(){
- register(char.class, (s) -> s.charAt(0));
- register(int.class, Integer::parseInt);
- register(byte.class, Byte::parseByte);
- register(short.class, Short::parseShort);
- register(boolean.class, Boolean::parseBoolean);
- register(float.class, Float::parseFloat);
- register(double.class, Double::parseDouble);
-
- register(Character.class, (s) -> s.charAt(0));
- register(Integer.class, Integer::valueOf);
- register(Byte.class, Byte::valueOf);
- register(Short.class, Short::valueOf);
- register(Boolean.class, Boolean::valueOf);
- register(Float.class, Float::valueOf);
- register(Double.class, Double::valueOf);
- register(BigDecimal.class, BigDecimal::new);
- register(BigInteger.class, BigInteger::new);
-
- register(Currency.class, Currency::getInstance);
-
- register(LocalDate.class, LocalDate::parse);
- register(LocalTime.class, LocalTime::parse);
- register(LocalDateTime.class, LocalDateTime::parse);
- register(ZoneId.class, ZoneId::of);
- }
-
-
- @Override
- public <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> codec){
- Objects.requireNonNull(targetType);
- Objects.requireNonNull(codec);
- return (PropertyAdapter<T>) propertyAdapters.put(targetType, codec);
- }
-
- @Override
- public <T> PropertyAdapter<T> getPropertyAdapter(Class<T> targetType, WithPropertyAdapter annotation){
- if(annotation!=null){
- Class<?> adapterType = annotation.value();
- if(!adapterType.equals(PropertyAdapter.class)){
- try{
- return (PropertyAdapter<T>)adapterType.newInstance();
- }
- catch(Exception e){
- throw new ConfigException("Failed to load PropertyAdapter: " + adapterType, e);
- }
- }
- }
- return (PropertyAdapter<T>) propertyAdapters.get(targetType);
- }
-
- @Override
- public boolean isTargetTypeSupported(Class<?> targetType){
- return propertyAdapters.containsKey(targetType);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/test/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/dormant/api/src/test/resources/META-INF/beans.xml b/dormant/api/src/test/resources/META-INF/beans.xml
deleted file mode 100644
index 5207c9a..0000000
--- a/dormant/api/src/test/resources/META-INF/beans.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<beans xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
-</beans>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
----------------------------------------------------------------------
diff --git a/dormant/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi b/dormant/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
deleted file mode 100644
index 1b0cdd4..0000000
--- a/dormant/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestConfigServiceSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
----------------------------------------------------------------------
diff --git a/dormant/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi b/dormant/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
deleted file mode 100644
index e9b04b4..0000000
--- a/dormant/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdapterSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/AbstractClasspathAwarePropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/AbstractClasspathAwarePropertySource.java b/dormant/core/src/main/java/old/AbstractClasspathAwarePropertySource.java
new file mode 100644
index 0000000..47eb150
--- /dev/null
+++ b/dormant/core/src/main/java/old/AbstractClasspathAwarePropertySource.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.core.resource.ResourceLoader;
+
+import java.util.*;
+
+public abstract class AbstractClasspathAwarePropertySource extends AbstractPropertySource {
+
+ private static final long serialVersionUID = 5484306410557548246L;
+ private ClassLoader classLoader;
+ private AbstractClasspathAwarePropertySource parentConfig;
+ private Set<String> sources;
+
+
+ public AbstractClasspathAwarePropertySource(ClassLoader classLoader, AbstractClasspathAwarePropertySource parentConfig,
+ Set<String> sourceExpressions, long configReadDT, Map<String, String> entries,
+ String name, Set<String> sources, List<Throwable> errors){
+ super(name);
+ Objects.requireNonNull(sources, "sources required.");
+ Objects.requireNonNull(classLoader, "classLoader required.");
+ this.sources = sources;
+ this.classLoader = classLoader;
+ this.parentConfig = parentConfig;
+ }
+
+ public AbstractClasspathAwarePropertySource(ClassLoader classLoader, AbstractClasspathAwarePropertySource parentConfig,
+ String sourceExpression){
+ super(parentConfig.getName());
+ Objects.requireNonNull(sources, "sources required.");
+ Objects.requireNonNull(sourceExpression, "sourceExpression required.");
+ List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(classLoader, sourceExpression);
+ for(Resource res : resources){
+ addSource(res.toString());
+ }
+ this.classLoader = classLoader;
+ this.parentConfig = parentConfig;
+ }
+
+ protected abstract void readSource(Map<String,String> targetMap, String source);
+
+ @Override
+ public Map<String,String> getProperties(){
+ Map<String,String> result = new HashMap<>();
+ for(String source : sources){
+ // if(!isSourceRead(source)){
+ readSource(result, source);
+ // }
+ }
+ return result;
+ }
+
+
+ public ClassLoader getClassLoader(){
+ return classLoader;
+ }
+
+ public AbstractClasspathAwarePropertySource getParentConfig(){
+ return this.parentConfig;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/AbstractPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/AbstractPropertySource.java b/dormant/core/src/main/java/old/AbstractPropertySource.java
new file mode 100644
index 0000000..7d188b5
--- /dev/null
+++ b/dormant/core/src/main/java/old/AbstractPropertySource.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import java.io.Serializable;
+import java.util.*;
+
+import org.apache.tamaya.PropertySource;
+
+/**
+ * Abstract base class for implementing a {@link org.apache.tamaya.PropertySource}.
+ */
+public abstract class AbstractPropertySource implements PropertySource, Serializable{
+ /**
+ * serialVersionUID.
+ */
+ private static final long serialVersionUID = -6553955893879292837L;
+
+ protected String name;
+
+ /**
+ * Constructor.
+ */
+ protected AbstractPropertySource(String name){
+ this.name = Objects.requireNonNull(name);
+ }
+
+ @Override
+ public String getName(){
+ return name;
+ }
+
+
+ @Override
+ public Optional<String> get(String key){
+ return Optional.ofNullable(getProperties().get(key));
+ }
+
+ @Override
+ public String toString(){
+ return getClass().getSimpleName()) + "(name=" + getName()+")");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/AggregatedPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/AggregatedPropertySource.java b/dormant/core/src/main/java/old/AggregatedPropertySource.java
new file mode 100644
index 0000000..14ea651
--- /dev/null
+++ b/dormant/core/src/main/java/old/AggregatedPropertySource.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.*;
+
+import java.util.*;
+
+/**
+ * Implementation for a {@link org.apache.tamaya.PropertySource} that is an aggregate current
+ * multiple child instances. Controlled by an {@link org.apache.tamaya.AggregationPolicy} the
+ * following aggregations are supported:
+ * <ul>
+ * <li><b>IGNORE_DUPLICATES: </b>Ignore all overrides.</li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * </ul>
+ */
+class AggregatedPropertySource extends AbstractPropertySource {
+
+ private static final long serialVersionUID = -1419376385695224799L;
+ private AggregationPolicy policy = AggregationPolicy.COMBINE;
+ private List<PropertySource> units = new ArrayList<>();
+ private PropertySource mutableProvider;
+
+ /**
+ * Creates a new instance.
+ * @param mutableProvider the provider instance that would be used for delegating
+ * change requests.
+ * @param policy
+ * The aggregation policy to be used.
+ * @param propertyMaps
+ * The property sets to be included.
+ */
+ public AggregatedPropertySource(String name, PropertySource mutableProvider, AggregationPolicy policy, List<PropertySource> propertyMaps) {
+ super(name);
+ this.policy = Objects.requireNonNull(policy);
+ units.addAll(propertyMaps);
+ this.mutableProvider = mutableProvider;
+ }
+
+ /**
+ * Get the {@link AggregationPolicy} for this instance.
+ *
+ * @return the {@link AggregationPolicy}, never {@code null}.
+ */
+ public AggregationPolicy getAggregationPolicy() {
+ return policy;
+ }
+
+ /**
+ * Return the names current the {@link org.apache.tamaya.PropertySource} instances to be
+ * aggregated in this instance, in the order current precedence (the first are
+ * the weakest).
+ *
+ * @return the ordered list current aggregated scope identifiers, never
+ * {@code null}.
+ */
+ public List<PropertySource> getConfigurationUnits() {
+ return Collections.unmodifiableList(units);
+ }
+
+ @Override
+ public Map<String,String> getProperties() {
+ Map<String, String> value = new HashMap<>();
+ for (PropertySource unit : units) {
+ for (Map.Entry<String, String> entry : unit.getProperties()
+ .entrySet()) {
+ String valueToAdd = this.policy.aggregate(entry.getKey(), value.get(entry.getKey()), entry.getValue());
+ if(valueToAdd==null){
+ value.remove(entry.getKey());
+ }
+ else{
+ value.put(entry.getKey(), valueToAdd);
+ }
+ }
+ }
+ return value;
+ }
+
+}
[11/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
deleted file mode 100644
index 879d54a..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.inject;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.*;
-
-import org.apache.tamaya.core.properties.PropertyChangeSet;
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.annotation.*;
-import org.apache.tamaya.core.internal.Utils;
-
-/**
- * Structure that contains and manages configuration related things for a configured type registered.
- * Created by Anatole on 03.10.2014.
- */
-@SuppressWarnings({"rawtypes", "unchecked"})
-public class ConfiguredType {
- /**
- * A list with all annotated instance variables.
- */
- private List<ConfiguredField> configuredFields = new ArrayList<>();
- /**
- * A list with all annotated methods (templates).
- */
- private List<ConfiguredSetterMethod> configuredSetterMethods = new ArrayList<>();
- /**
- * A list with all callback methods listening to config changes.
- */
- private List<ConfigChangeCallbackMethod> callbackMethods = new ArrayList<>();
- /**
- * The basic type.
- */
- private Class type;
-
- /**
- * Creates an instance of this class hereby evaluating the config annotations given for later effective
- * injection (configuration) of instances.
- *
- * @param type the instance type.
- */
-
- public ConfiguredType(Class type) {
- this.type = Objects.requireNonNull(type);
- initFields(type);
- initMethods(type);
- }
-
- private void initFields(Class type) {
- for (Field f : type.getDeclaredFields()) {
- if (f.isAnnotationPresent(NoConfig.class)) {
- continue;
- }
- try {
- ConfiguredField configuredField = new ConfiguredField(f);
- configuredFields.add(configuredField);
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured field: " +
- f.getDeclaringClass().getName() + '.' + f.getName(), e);
- }
- }
- }
-
- private void initMethods(Class type) {
- // TODO revisit this logic here...
- for (Method m : type.getDeclaredMethods()) {
- if (m.isAnnotationPresent(NoConfig.class)) {
- continue;
- }
- ObservesConfigChange mAnnot = m.getAnnotation(ObservesConfigChange.class);
- Collection<ConfiguredProperty> propertiesAnnots = Utils.getAnnotations(m, ConfiguredProperty.class, ConfiguredProperties.class);
- if (type.isInterface()) {
- // it is a template
- if (mAnnot != null) {
- if (m.isDefault()) {
- addObserverMethod(m);
- }
- } else {
- if (m.isDefault()) {
- addPropertySetter(m, propertiesAnnots);
- }
- }
- } else {
- if (mAnnot != null) {
- addObserverMethod(m);
- } else {
- addPropertySetter(m, propertiesAnnots);
- }
- }
- }
- }
-
- private boolean addPropertySetter(Method m, Collection<ConfiguredProperty> propertiesAnnots) {
- if (!propertiesAnnots.isEmpty()) {
- if (m.getParameterTypes().length == 0) {
- // getter method
- Class<?> returnType = m.getReturnType();
- if (!void.class.equals(returnType)) {
- try {
- configuredSetterMethods.add(new ConfiguredSetterMethod(m));
- return true;
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured setter method: " +
- m.getDeclaringClass().getName() + '.' + m.getName(), e);
- }
- }
- }
- }
- return false;
- }
-
-
-
- private void addObserverMethod(Method m) {
- if (m.getParameterTypes().length != 1) {
- return;
- }
- if (!m.getParameterTypes()[0].equals(PropertyChangeSet.class)) {
- return;
- }
- if (!void.class.equals(m.getReturnType())) {
- return;
- }
- try {
- this.callbackMethods.add(new ConfigChangeCallbackMethod(m));
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured callback method: " +
- m.getDeclaringClass().getName() + '.' + m.getName(), e);
- }
- }
-
-
- /**
- * Method called to configure an instance.
- *
- * @param instance The instance to be configured.
- * @param configurations Configuration instances that replace configuration served by services. This allows
- * more easily testing and adaption.
- */
- public void configure(Object instance, Configuration... configurations) {
- for (ConfiguredField field : configuredFields) {
- field.applyInitialValue(instance, configurations);
- }
- for (ConfiguredSetterMethod method : configuredSetterMethods) {
- method.applyInitialValue(instance, configurations);
- // TODO, if method should be recalled on changes, corresponding callbacks could be registered here
- WeakConfigListenerManager.of().registerConsumer(instance, method.createConsumer(instance, configurations));
- }
- // Register callbacks for this intance (weakly)
- for (ConfigChangeCallbackMethod callback : callbackMethods) {
- WeakConfigListenerManager.of().registerConsumer(instance, callback.createConsumer(instance, configurations));
- }
- }
-
-
- private String getName(Object source) {
- if (source instanceof PropertySource) {
- PropertySource ps = (PropertySource) source;
- return ps.getName();
- }
- return "N/A";
- }
-
-
- public boolean isConfiguredBy(Configuration configuration) {
- // TODO implement this
- return true;
- }
-
- public static boolean isConfigured(Class type) {
- if (type.getAnnotation(DefaultAreas.class) != null) {
- return true;
- }
- // if no class level annotation is there we might have field level annotations only
- for (Field field : type.getDeclaredFields()) {
- if (field.isAnnotationPresent(ConfiguredProperties.class)) {
- return true;
- }
- }
- // if no class level annotation is there we might have method level annotations only
- for (Method method : type.getDeclaredMethods()) {
- if (method.isAnnotationPresent(ConfiguredProperties.class)) {
- return true;
- }
- }
- for (Field field : type.getDeclaredFields()) {
- if (field.isAnnotationPresent(ConfiguredProperty.class)) {
- return true;
- }
- }
- // if no class level annotation is there we might have method level annotations only
- for (Method method : type.getDeclaredMethods()) {
- if (method.isAnnotationPresent(ConfiguredProperty.class)) {
- return true;
- }
- }
- return false;
- }
-
- public Class getType() {
- return this.type;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
deleted file mode 100644
index d80ee80..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
+++ /dev/null
@@ -1,221 +0,0 @@
-package org.apache.tamaya.core.internal.inject;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertyAdapter;
-import org.apache.tamaya.annotation.*;
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-import org.apache.tamaya.core.internal.Utils;
-import org.apache.tamaya.spi.PropertyAdapterSpi;
-
-/**
- * Created by Anatole on 19.12.2014.
- */
-@SuppressWarnings("unchecked")
-final class InjectionUtils {
-
- private InjectionUtils(){}
-
- /**
- * This method evaluates the {@link org.apache.tamaya.Configuration} that currently is valid for the given target field/method.
- *
- * @return the {@link org.apache.tamaya.Configuration} instance to be used, never null.
- */
- public static Configuration getConfiguration(ConfiguredProperty prop, Configuration... configuration) {
- String name = prop.config();
- if (name != null && !name.trim().isEmpty()) {
- return Configuration.current(name.trim());
- }
- return Configuration.current();
- }
-
- /**
- * Evaluates all absolute configuration key based on the annotations found on a class.
- *
- * @param areasAnnot the (optional) annotation definining areas to be looked up.
- * @param propertyAnnotation the annotation on field/method level that may defined one or
- * several keys to be looked up (in absolute or relative form).
- * @return the list current keys in order how they should be processed/looked up.
- */
- public static List<String> evaluateKeys(Member member, DefaultAreas areasAnnot, ConfiguredProperty propertyAnnotation) {
- List<String> keys = new ArrayList<>(Arrays.asList(propertyAnnotation.keys()));
- if (keys.isEmpty()) //noinspection UnusedAssignment
- keys.add(member.getName());
- ListIterator<String> iterator = keys.listIterator();
- while (iterator.hasNext()) {
- String next = iterator.next();
- if (next.startsWith("[") && next.endsWith("]")) {
- // absolute key, strip away brackets, take key as is
- iterator.set(next.substring(1, next.length() - 1));
- } else {
- if (areasAnnot != null) {
- // Remove original entry, since it will be replaced with prefixed entries
- iterator.remove();
- // Add prefixed entries, including absolute (root) entry for "" area keys.
- for (String area : areasAnnot.value()) {
- iterator.add(area.isEmpty() ? next : area + '.' + next);
- }
- }
- }
- }
- return keys;
- }
-
- /**
- * Evaluates all absolute configuration key based on the member name found.
- *
- * @param areasAnnot the (optional) annotation definining areas to be looked up.
- * @return the list current keys in order how they should be processed/looked up.
- */
- public static List<String> evaluateKeys(Member member, DefaultAreas areasAnnot) {
- List<String> keys = new ArrayList<>();
- String name = member.getName();
- String mainKey;
- if(name.startsWith("get") || name.startsWith("set")){
- mainKey = Character.toLowerCase(name.charAt(3)) + name.substring(4);
- }
- else{
- mainKey = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- }
- keys.add(mainKey);
- if (areasAnnot != null) {
- // Add prefixed entries, including absolute (root) entry for "" area keys.
- for (String area : areasAnnot.value()) {
- if(!area.isEmpty()) {
- keys.add(area + '.' + mainKey);
- }
- }
- }
- else{ // add package name
- keys.add(member.getDeclaringClass().getName()+'.'+mainKey);
- }
- return keys;
- }
-
- /**
- * Internally evaluated the current valid configuration keys based on the given annotations present.
- *
- * @return the keys to be returned, or null.
- */
- public static String getConfigValue(Method method, Configuration... configurations) {
- DefaultAreas areasAnnot = method.getDeclaringClass().getAnnotation(DefaultAreas.class);
- WithLoadPolicy loadPolicy = Utils.getAnnotation(WithLoadPolicy.class, method, method.getDeclaringClass());
- return getConfigValueInternal(method, areasAnnot, loadPolicy, configurations);
- }
-
-
- /**
- * Internally evaluated the current valid configuration keys based on the given annotations present.
- *
- * @return the keys to be returned, or null.
- */
- public static String getConfigValue(Field field, Configuration... configurations) {
- DefaultAreas areasAnnot = field.getDeclaringClass().getAnnotation(DefaultAreas.class);
- WithLoadPolicy loadPolicy = Utils.getAnnotation(WithLoadPolicy.class, field, field.getDeclaringClass());
- return getConfigValueInternal(field, areasAnnot, loadPolicy, configurations);
- }
-
- /**
- * Internally evaluated the current valid configuration keys based on the given annotations present.
- *
- * @return the keys to be returned, or null.
- */
- private static String getConfigValueInternal(AnnotatedElement element, DefaultAreas areasAnnot, WithLoadPolicy loadPolicy, Configuration... configurations) {
- Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(
- element, ConfiguredProperty.class, ConfiguredProperties.class);
- DefaultValue defaultAnnot = element.getAnnotation(DefaultValue.class);
- String configValue = null;
- if(configuredProperties.isEmpty()){
- List<String> keys = InjectionUtils.evaluateKeys((Member)element, areasAnnot);
- Configuration config = InjectionUtils.getConfiguration("default", configurations);
- configValue = evaluteConfigValue(configValue, keys, config);
- }
- else {
- for (ConfiguredProperty prop : configuredProperties) {
- List<String> keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot, prop);
- Configuration config = InjectionUtils.getConfiguration(prop, configurations);
- configValue = evaluteConfigValue(configValue, keys, config);
- }
- }
- if (configValue == null && defaultAnnot != null) {
- return defaultAnnot.value();
- }
- return configValue;
- }
-
- private static String evaluteConfigValue(String configValue, List<String> keys, Configuration config) {
- for (String key : keys) {
- configValue = config.get(key).orElse(null);
- if (configValue != null) {
- break;
- }
- }
- if (configValue != null) {
- // net step perform expression resolution, if any
- configValue = Configuration.evaluateValue(configValue, config);
- }
- return configValue;
- }
-
-
- @SuppressWarnings("rawtypes")
- public static <T> T adaptValue(AnnotatedElement element, Class<T> targetType, String configValue){
- try {
- // Check for adapter/filter
-// T adaptedValue = null;
- WithPropertyAdapter codecAnnot = element.getAnnotation(WithPropertyAdapter.class);
- Class<? extends PropertyAdapter> codecType;
- if (codecAnnot != null) {
- codecType = codecAnnot.value();
- if (!codecType.equals(PropertyAdapter.class)) {
- // TODO cache here...
-// Codec<String> codec = codecType.newInstance();
-// adaptedValue = (T) codec.adapt(configValue);
- }
- }
- if (String.class.equals(targetType)) {
- return (T)configValue;
- } else {
- PropertyAdapter<?> adapter = PropertyAdapter.getInstance(targetType);
- return (T)adapter.adapt(configValue);
- }
- } catch (Exception e) {
- throw new ConfigException("Failed to annotate configured member: " + element, e);
- }
- }
-
- /**
- * This method evaluates the {@link Configuration} that currently is valid for the given target field/method.
- * @param configurations Configuration instances that replace configuration served by services. This allows
- * more easily testing and adaption.
- * @return the {@link Configuration} instance to be used, never null.
- */
- public static Configuration getConfiguration(String name, Configuration... configurations) {
- if(name!=null) {
- for(Configuration conf: configurations){
- if(name.equals(conf.getName())){
- return conf;
- }
- }
- return Configuration.current(name);
- }
- else{
- for(Configuration conf: configurations){
- if("default".equals(conf.getName())){
- return conf;
- }
- }
- }
- return Configuration.current();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
deleted file mode 100644
index e9b9ec3..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.inject;
-
-import org.apache.tamaya.core.properties.PropertyChangeSet;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.StampedLock;
-import java.util.function.Consumer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Simple listener container that only holds weak references on the listeners.
- */
-public final class WeakConfigListenerManager{
-
- private static final WeakConfigListenerManager INSTANCE = new WeakConfigListenerManager();
-
- private static final Logger LOG = Logger.getLogger(WeakConfigListenerManager.class.getName());
- private StampedLock lock = new StampedLock();
- private Map<Object,Consumer<PropertyChangeSet>> listenerReferences = new WeakHashMap<>();
-
- /** Private singleton constructor. */
- private WeakConfigListenerManager(){}
-
- public static WeakConfigListenerManager of(){
- return INSTANCE;
- }
-
- /**
- * Registers the given consumer for the instance. If a consumer already exists for this instance the given
- * consumer is appended.
- * @param instance the instance, not null.
- * @param listener the consumer.
- */
- public void registerConsumer(Object instance, Consumer<PropertyChangeSet> listener){
- Lock writeLock = lock.asWriteLock();
- try {
- writeLock.lock();
- Consumer<PropertyChangeSet> l = listenerReferences.get(instance);
- if (l == null) {
- listenerReferences.put(instance, listener);
- } else {
- listenerReferences.put(instance, l.andThen(listener));
- }
- }
- finally{
- writeLock.unlock();
- }
- }
-
- /**
- * Unregisters all consumers for the given instance.
- * @param instance the instance, not null.
- */
- public void unregisterConsumer(Object instance) {
- Lock writeLock = lock.asWriteLock();
- try {
- writeLock.lock();
- listenerReferences.remove(instance);
- }
- finally{
- writeLock.unlock();
- }
- }
-
- /**
- * Publishes a change event to all consumers registered.
- * @param change the change event, not null.
- */
- public void publishChangeEvent(PropertyChangeSet change){
- Lock readLock = lock.asReadLock();
- try{
- readLock.lock();
- listenerReferences.values().parallelStream().forEach(l -> {
- try{
- l.accept(change);
- }
- catch(Exception e){
- LOG.log(Level.SEVERE, "ConfigChangeListener failed: " + l.getClass().getName(), e);
- }
- });
- }
- finally{
- readLock.unlock();
- }
- }
-
-
- @Override
- public String toString(){
- return "WeakConfigListenerManager{" +
- "listenerReferences=" + listenerReferences +
- '}';
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
deleted file mode 100644
index cc0ac45..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.logging;
-
-import java.text.MessageFormat;
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.logging.*;
-
-/**
- * java.util.logging.Logger implementation delegating to another framework.
- * All methods can be used except:
- * setLevel
- * addHandler / getHandlers
- * setParent / getParent
- * setUseParentHandlers / getUseParentHandlers
- *
- * @author gnodet
- */
-public abstract class AbstractDelegatingLogger extends Logger {
-
- protected AbstractDelegatingLogger(final String name, final String resourceBundleName) {
- super(name, resourceBundleName);
- }
-
- public void log(final LogRecord record) {
- if (isLoggable(record.getLevel())) {
- doLog(record);
- }
- }
-
- public void log(final Level level, final String msg) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- doLog(lr);
- }
- }
-
- public void log(final Level level, final String msg, final Object param1) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- final Object[] params = {param1};
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- public void log(final Level level, final String msg, final Object[] params) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- public void log(final Level level, final String msg, final Throwable thrown) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
- public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- doLog(lr);
- }
- }
-
- public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Object param1) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- final Object[] params = {param1};
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Object[] params) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Throwable thrown) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
- public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName, final String msg) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- doLog(lr, bundleName);
- }
- }
-
- public void logrb(final Level level, final String sourceClass, final String sourceMethod,
- final String bundleName, final String msg, final Object param1) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- final Object[] params = {param1};
- lr.setParameters(params);
- doLog(lr, bundleName);
- }
- }
-
- public void logrb(final Level level, final String sourceClass, final String sourceMethod,
- final String bundleName, final String msg, final Object[] params) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setParameters(params);
- doLog(lr, bundleName);
- }
- }
-
- public void logrb(final Level level, final String sourceClass, final String sourceMethod,
- final String bundleName, final String msg, final Throwable thrown) {
- if (isLoggable(level)) {
- final LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr, bundleName);
- }
- }
-
- public void entering(final String sourceClass, final String sourceMethod) {
- if (isLoggable(Level.FINER)) {
- logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
- }
- }
-
- public void entering(final String sourceClass, final String sourceMethod, final Object param1) {
- if (isLoggable(Level.FINER)) {
- final Object[] params = {param1};
- logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
- }
- }
-
- public void entering(final String sourceClass, final String sourceMethod, final Object[] params) {
- if (isLoggable(Level.FINER)) {
- final String msg = "ENTRY";
- if (params == null) {
- logp(Level.FINER, sourceClass, sourceMethod, msg);
- return;
- }
- final StringBuilder builder = new StringBuilder(msg);
- for (int i = 0; i < params.length; i++) {
- builder.append(" {");
- builder.append(Integer.toString(i));
- builder.append("}");
- }
- logp(Level.FINER, sourceClass, sourceMethod, builder.toString(), params);
- }
- }
-
- public void exiting(final String sourceClass, final String sourceMethod) {
- if (isLoggable(Level.FINER)) {
- logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
- }
- }
-
- public void exiting(final String sourceClass, final String sourceMethod, final Object result) {
- if (isLoggable(Level.FINER)) {
- final Object[] params = {result};
- logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", params);
- }
- }
-
- public void throwing(final String sourceClass, final String sourceMethod, final Throwable thrown) {
- if (isLoggable(Level.FINER)) {
- final LogRecord lr = new LogRecord(Level.FINER, "THROW");
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
- public void severe(final String msg) {
- if (isLoggable(Level.SEVERE)) {
- final LogRecord lr = new LogRecord(Level.SEVERE, msg);
- doLog(lr);
- }
- }
-
- public void warning(final String msg) {
- if (isLoggable(Level.WARNING)) {
- final LogRecord lr = new LogRecord(Level.WARNING, msg);
- doLog(lr);
- }
- }
-
- public void info(final String msg) {
- if (isLoggable(Level.INFO)) {
- final LogRecord lr = new LogRecord(Level.INFO, msg);
- doLog(lr);
- }
- }
-
- public void config(final String msg) {
- if (isLoggable(Level.CONFIG)) {
- final LogRecord lr = new LogRecord(Level.CONFIG, msg);
- doLog(lr);
- }
- }
-
- public void fine(final String msg) {
- if (isLoggable(Level.FINE)) {
- final LogRecord lr = new LogRecord(Level.FINE, msg);
- doLog(lr);
- }
- }
-
- public void finer(final String msg) {
- if (isLoggable(Level.FINER)) {
- final LogRecord lr = new LogRecord(Level.FINER, msg);
- doLog(lr);
- }
- }
-
- public void finest(final String msg) {
- if (isLoggable(Level.FINEST)) {
- final LogRecord lr = new LogRecord(Level.FINEST, msg);
- doLog(lr);
- }
- }
-
- public void setLevel(final Level newLevel) throws SecurityException {
- throw new UnsupportedOperationException();
- }
-
- public abstract Level getLevel();
-
- public boolean isLoggable(final Level level) {
- final Level l = getLevel();
- return level.intValue() >= l.intValue() && l != Level.OFF;
- }
-
- protected boolean supportsHandlers() {
- return false;
- }
-
- public synchronized void addHandler(final Handler handler) throws SecurityException {
- if (supportsHandlers()) {
- super.addHandler(handler);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- public synchronized void removeHandler(final Handler handler) throws SecurityException {
- if (supportsHandlers()) {
- super.removeHandler(handler);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- public synchronized Handler[] getHandlers() {
- if (supportsHandlers()) {
- return super.getHandlers();
- }
- throw new UnsupportedOperationException();
- }
-
- public synchronized void setUseParentHandlers(final boolean useParentHandlers) {
- if (supportsHandlers()) {
- super.setUseParentHandlers(useParentHandlers);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- public synchronized boolean getUseParentHandlers() {
- if (supportsHandlers()) {
- return super.getUseParentHandlers();
- }
- throw new UnsupportedOperationException();
- }
-
- public Logger getParent() {
- return null;
- }
-
- public void setParent(final Logger parent) {
- throw new UnsupportedOperationException();
- }
-
- protected void doLog(final LogRecord lr) {
- lr.setLoggerName(getName());
- final String rbname = getResourceBundleName();
- if (rbname != null) {
- lr.setResourceBundleName(rbname);
- lr.setResourceBundle(getResourceBundle());
- }
- internalLog(lr);
- }
-
- protected void doLog(final LogRecord lr, final String rbname) {
- lr.setLoggerName(getName());
- if (rbname != null) {
- lr.setResourceBundleName(rbname);
- lr.setResourceBundle(loadResourceBundle(rbname));
- }
- internalLog(lr);
- }
-
- protected void internalLog(final LogRecord record) {
- final Filter filter = getFilter();
- if (filter != null && !filter.isLoggable(record)) {
- return;
- }
- final String msg = formatMessage(record);
- internalLogFormatted(msg, record);
- }
-
- protected abstract void internalLogFormatted(String msg, LogRecord record);
-
- protected String formatMessage(final LogRecord record) {
- String format = record.getMessage();
- final ResourceBundle catalog = record.getResourceBundle();
- if (catalog != null) {
- try {
- format = catalog.getString(record.getMessage());
- } catch (final MissingResourceException ex) {
- format = record.getMessage();
- }
- }
- try {
- final Object[] parameters = record.getParameters();
- if (parameters == null || parameters.length == 0) {
- return format;
- }
- if (format.contains("{0") || format.contains("{1")
- || format.contains("{2") || format.contains("{3")) {
- return MessageFormat.format(format, parameters);
- }
- return format;
- } catch (final Exception ex) {
- return format;
- }
- }
-
- /**
- * Load the specified resource bundle
- *
- * @param resourceBundleName the name current the resource bundle to load, cannot be null
- * @return the loaded resource bundle.
- * @throws MissingResourceException If the specified resource bundle can not be loaded.
- */
- static ResourceBundle loadResourceBundle(final String resourceBundleName) {
- // try context class loader to load the resource
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (null != cl) {
- try {
- return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
- } catch (final MissingResourceException e) {
- // Failed to load using context classloader, ignore
- }
- }
- // try system class loader to load the resource
- cl = ClassLoader.getSystemClassLoader();
- if (null != cl) {
- try {
- return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
- } catch (final MissingResourceException e) {
- // Failed to load using system classloader, ignore
- }
- }
- return null;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
deleted file mode 100644
index 35ae4ab..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4j2Logger.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.logging;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-public class Log4j2Logger extends AbstractDelegatingLogger {
- private static final Map<Level, org.apache.logging.log4j.Level> TO_LOG4J = new HashMap<>();
-
- private final Logger log;
-
- static {
- //older versions current log4j don't have TRACE, use debug
-// org.apache.logging.log4j.Level t = org.apache.logging.log4j.Level.DEBUG;
-
- TO_LOG4J.put(Level.ALL, org.apache.logging.log4j.Level.ALL);
- TO_LOG4J.put(Level.SEVERE, org.apache.logging.log4j.Level.ERROR);
- TO_LOG4J.put(Level.WARNING, org.apache.logging.log4j.Level.WARN);
- TO_LOG4J.put(Level.INFO, org.apache.logging.log4j.Level.INFO);
- TO_LOG4J.put(Level.CONFIG, org.apache.logging.log4j.Level.DEBUG);
- TO_LOG4J.put(Level.FINE, org.apache.logging.log4j.Level.DEBUG);
- TO_LOG4J.put(Level.FINER, org.apache.logging.log4j.Level.TRACE);
- TO_LOG4J.put(Level.FINEST, org.apache.logging.log4j.Level.TRACE);
- TO_LOG4J.put(Level.OFF, org.apache.logging.log4j.Level.OFF);
- }
-
- public Log4j2Logger(final String name, final String resourceBundleName) {
- super(name, resourceBundleName);
- log = LogManager.getLogger(name);
- }
-
- public Level getLevel() {
- final org.apache.logging.log4j.Level l = log.getLevel();
- if (l != null) {
- return fromL4J(l);
- }
- return null;
- }
-
- protected void internalLogFormatted(final String msg, final LogRecord record) {
- log.log(TO_LOG4J.get(record.getLevel()), msg, record.getThrown());
- }
-
-
- private Level fromL4J(final org.apache.logging.log4j.Level l) {
- Level l2 = null;
- switch (l.getStandardLevel()) {
- case ALL:
- l2 = Level.ALL;
- break;
- case FATAL:
- l2 = Level.SEVERE;
- break;
- case ERROR:
- l2 = Level.SEVERE;
- break;
- case WARN:
- l2 = Level.WARNING;
- break;
- case INFO:
- l2 = Level.INFO;
- break;
- case DEBUG:
- l2 = Level.FINE;
- break;
- case OFF:
- l2 = Level.OFF;
- break;
- case TRACE:
- l2 = Level.FINEST;
- break;
- default:
- l2 = Level.FINE;
- }
- return l2;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
deleted file mode 100644
index 224378c..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Log4jLogger.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.logging;
-
-import org.apache.log4j.Appender;
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
-import org.apache.log4j.spi.LoggingEvent;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-/**
- * java.util.logging.Logger implementation delegating to Log4j.
- * All methods can be used except:
- * setLevel
- * addHandler / getHandlers
- * setParent / getParent
- * setUseParentHandlers / getUseParentHandlers
- *
- * @author gnodet
- */
-public class Log4jLogger extends AbstractDelegatingLogger {
- private static final Map<Level, org.apache.log4j.Level> TO_LOG4J = new HashMap<>();
- private static final org.apache.log4j.Level TRACE;
-
- private final Logger log;
-
- static {
- //older versions current log4j don't have TRACE, use debug
- org.apache.log4j.Level t = org.apache.log4j.Level.DEBUG;
- try {
- final Field f = org.apache.log4j.Level.class.getField("TRACE");
- t = (org.apache.log4j.Level) f.get(null);
- } catch (final Throwable ex) {
- //ignore, assume old version current log4j
- }
- TRACE = t;
-
- TO_LOG4J.put(Level.ALL, org.apache.log4j.Level.ALL);
- TO_LOG4J.put(Level.SEVERE, org.apache.log4j.Level.ERROR);
- TO_LOG4J.put(Level.WARNING, org.apache.log4j.Level.WARN);
- TO_LOG4J.put(Level.INFO, org.apache.log4j.Level.INFO);
- TO_LOG4J.put(Level.CONFIG, org.apache.log4j.Level.DEBUG);
- TO_LOG4J.put(Level.FINE, org.apache.log4j.Level.DEBUG);
- TO_LOG4J.put(Level.FINER, TRACE);
- TO_LOG4J.put(Level.FINEST, TRACE);
- TO_LOG4J.put(Level.OFF, org.apache.log4j.Level.OFF);
- }
-
- public Log4jLogger(final String name, final String resourceBundleName) {
- super(name, resourceBundleName);
- log = LogManager.getLogger(name);
- }
-
- public Level getLevel() {
- final org.apache.log4j.Level l = log.getEffectiveLevel();
- if (l != null) {
- return fromL4J(l);
- }
- return null;
- }
-
- public void setLevel(final Level newLevel) throws SecurityException {
- log.setLevel(TO_LOG4J.get(newLevel));
- }
-
- public synchronized void addHandler(final Handler handler) throws SecurityException {
- log.addAppender(new HandlerWrapper(handler));
- }
-
- public synchronized void removeHandler(final Handler handler) throws SecurityException {
- log.removeAppender("HandlerWrapper-" + handler.hashCode());
- }
-
- public synchronized Handler[] getHandlers() {
- final List<Handler> ret = new ArrayList<>();
- final Enumeration<?> en = log.getAllAppenders();
- while (en.hasMoreElements()) {
- final Appender ap = (Appender) en.nextElement();
- if (ap instanceof HandlerWrapper) {
- ret.add(((HandlerWrapper) ap).getHandler());
- }
- }
- return ret.toArray(new Handler[ret.size()]);
- }
-
- protected void internalLogFormatted(final String msg, final LogRecord record) {
- log.log(AbstractDelegatingLogger.class.getName(),
- TO_LOG4J.get(record.getLevel()),
- msg,
- record.getThrown());
- }
-
-
- private Level fromL4J(final org.apache.log4j.Level l) {
- Level l2 = null;
- switch (l.toInt()) {
- case org.apache.log4j.Level.ALL_INT:
- l2 = Level.ALL;
- break;
- case org.apache.log4j.Level.FATAL_INT:
- l2 = Level.SEVERE;
- break;
- case org.apache.log4j.Level.ERROR_INT:
- l2 = Level.SEVERE;
- break;
- case org.apache.log4j.Level.WARN_INT:
- l2 = Level.WARNING;
- break;
- case org.apache.log4j.Level.INFO_INT:
- l2 = Level.INFO;
- break;
- case org.apache.log4j.Level.DEBUG_INT:
- l2 = Level.FINE;
- break;
- case org.apache.log4j.Level.OFF_INT:
- l2 = Level.OFF;
- break;
- default:
- if (l.toInt() == TRACE.toInt()) {
- l2 = Level.FINEST;
- }
- }
- return l2;
- }
-
-
- private class HandlerWrapper extends AppenderSkeleton {
- Handler handler;
-
- public HandlerWrapper(final Handler h) {
- handler = h;
- name = "HandlerWrapper-" + h.hashCode();
- }
-
- public Handler getHandler() {
- return handler;
- }
-
- @Override
- protected void append(final LoggingEvent event) {
- final LogRecord lr = new LogRecord(fromL4J(event.getLevel()),
- event.getMessage().toString());
- lr.setLoggerName(event.getLoggerName());
- if (event.getThrowableInformation() != null) {
- lr.setThrown(event.getThrowableInformation().getThrowable());
- }
- final String rbname = getResourceBundleName();
- if (rbname != null) {
- lr.setResourceBundleName(rbname);
- lr.setResourceBundle(getResourceBundle());
- }
- handler.publish(lr);
- }
-
- public void close() {
- handler.close();
- closed = true;
- }
-
- public boolean requiresLayout() {
- return false;
- }
-
- @Override
- public Priority getThreshold() {
- return TO_LOG4J.get(handler.getLevel());
- }
-
- @Override
- public boolean isAsSevereAsThreshold(final Priority priority) {
- final Priority p = getThreshold();
- return p == null || priority.isGreaterOrEqual(p);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
deleted file mode 100644
index a580128..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.logging;
-
-import org.slf4j.spi.LocationAwareLogger;
-
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-/**
- * <p>
- * java.util.logging.Logger implementation delegating to SLF4J.
- * </p>
- * <p>
- * Methods {@link java.util.logging.Logger#setParent(Logger)}, {@link java.util.logging.Logger#getParent()},
- * {@link java.util.logging.Logger#setUseParentHandlers(boolean)} and
- * {@link java.util.logging.Logger#getUseParentHandlers()} are not overrriden.
- * </p>
- * <p>
- * Level annotation inspired by {@link org.slf4j.bridge.SLF4JBridgeHandler}:
- * </p>
- * <p/>
- * <pre>
- * FINEST -> TRACE
- * FINER -> DEBUG
- * FINE -> DEBUG
- * CONFIG -> DEBUG
- * INFO -> INFO
- * WARN ING -> WARN
- * SEVER -> ERROR
- * </pre>
- */
-public class Slf4jLogger extends AbstractDelegatingLogger {
-
- private static final String FQCN = AbstractDelegatingLogger.class.getName();
-
- private final org.slf4j.Logger logger;
- private LocationAwareLogger locationAwareLogger;
-
-
- public Slf4jLogger(final String name, final String resourceBundleName) {
- super(name, resourceBundleName);
- logger = org.slf4j.LoggerFactory.getLogger(name);
- if (logger instanceof LocationAwareLogger) {
- locationAwareLogger = (LocationAwareLogger) logger;
- }
- }
-
- @Override
- protected boolean supportsHandlers() {
- return true;
- }
-
- @Override
- public Level getLevel() {
- final Level level;
- // Verify fromMap the wider (trace) to the narrower (error)
- if (logger.isTraceEnabled()) {
- level = Level.FINEST;
- } else if (logger.isDebugEnabled()) {
- // map to the lowest between FINER, FINE and CONFIG
- level = Level.FINER;
- } else if (logger.isInfoEnabled()) {
- level = Level.INFO;
- } else if (logger.isWarnEnabled()) {
- level = Level.WARNING;
- } else if (logger.isErrorEnabled()) {
- level = Level.SEVERE;
- } else {
- level = Level.OFF;
- }
- return level;
- }
-
- @Override
- public boolean isLoggable(final Level level) {
- final int i = level.intValue();
- if (i == Level.OFF.intValue()) {
- return false;
- } else if (i >= Level.SEVERE.intValue()) {
- return logger.isErrorEnabled();
- } else if (i >= Level.WARNING.intValue()) {
- return logger.isWarnEnabled();
- } else if (i >= Level.INFO.intValue()) {
- return logger.isInfoEnabled();
- } else if (i >= Level.FINER.intValue()) {
- return logger.isDebugEnabled();
- }
- return logger.isTraceEnabled();
- }
-
-
- @Override
- protected void internalLogFormatted(final String msg, final LogRecord record) {
-
- final Level level = record.getLevel();
- final Throwable t = record.getThrown();
-
- final Handler[] targets = getHandlers();
- if (targets != null) {
- for (final Handler h : targets) {
- h.publish(record);
- }
- }
- if (!getUseParentHandlers()) {
- return;
- }
-
- /*
- * As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order current the
- * comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc
- */
- if (Level.FINE.equals(level)) {
- if (locationAwareLogger == null) {
- logger.debug(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
- }
- } else if (Level.INFO.equals(level)) {
- if (locationAwareLogger == null) {
- logger.info(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, t);
- }
- } else if (Level.WARNING.equals(level)) {
- if (locationAwareLogger == null) {
- logger.warn(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, t);
- }
- } else if (Level.FINER.equals(level)) {
- if (locationAwareLogger == null) {
- logger.trace(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
- }
- } else if (Level.FINEST.equals(level)) {
- if (locationAwareLogger == null) {
- logger.trace(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, t);
- }
- } else if (Level.ALL.equals(level)) {
- // should never occur, all is used to configure java.util.logging
- // but not accessible by the API Logger.xxx() API
- if (locationAwareLogger == null) {
- logger.error(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
- }
- } else if (Level.SEVERE.equals(level)) {
- if (locationAwareLogger == null) {
- logger.error(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
- }
- } else if (Level.CONFIG.equals(level)) {
- if (locationAwareLogger == null) {
- logger.debug(msg, t);
- } else {
- locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
- }
- }
- // don't log if Level.OFF
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AbstractFileResolvingResource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AbstractFileResolvingResource.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AbstractFileResolvingResource.java
deleted file mode 100644
index ff35687..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AbstractFileResolvingResource.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
-
-/**
- * Abstract base class for resources which resolve URLs into File references,
- * such as {@code UrlResource} or {@link ClassPathResource}.
- *
- * <p>Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs,
- * resolving file system references accordingly.
- *
- * @author Juergen Hoeller
- * @since 3.0
- */
-abstract class AbstractFileResolvingResource extends AbstractResource {
-
- /**
- * This implementation returns a File reference for the underlying class path
- * resource, provided that it refers to a file in the file system.
- */
- @Override
- public File getFile() throws IOException {
- URL url = getURL();
- if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
- return VfsResourceDelegate.getResource(url).getFile();
- }
- return ResourceUtils.getFile(url, getDescription());
- }
-
- /**
- * This implementation determines the underlying File
- * (or jar file, in case current a resource in a jar/zip).
- */
- @Override
- protected File getFileForLastModifiedCheck() throws IOException {
- URL url = getURL();
- if (ResourceUtils.isJarURL(url)) {
- URL actualUrl = ResourceUtils.extractJarFileURL(url);
- if (actualUrl.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
- return VfsResourceDelegate.getResource(actualUrl).getFile();
- }
- return ResourceUtils.getFile(actualUrl, "Jar URL");
- }
- else {
- return getFile();
- }
- }
-
- /**
- * This implementation returns a File reference for the underlying class path
- * resource, provided that it refers to a file in the file system.
- * @see ResourceUtils#getFile(java.net.URI, String)
- */
- protected File getFile(URI uri) throws IOException {
- if (uri.getScheme().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
- return VfsResourceDelegate.getResource(uri).getFile();
- }
- return ResourceUtils.getFile(uri, getDescription());
- }
-
-
- @Override
- public boolean exists() {
- try {
- URL url = getURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- return getFile().exists();
- }
- else {
- // Try a URL connection content-length header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- HttpURLConnection httpCon =
- (con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
- if (httpCon != null) {
- int code = httpCon.getResponseCode();
- if (code == HttpURLConnection.HTTP_OK) {
- return true;
- }
- else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
- return false;
- }
- }
- if (con.getContentLength() >= 0) {
- return true;
- }
- if (httpCon != null) {
- // no HTTP OK status, and no content-length header: give up
- httpCon.disconnect();
- return false;
- }
- else {
- // Fall back to stream existence: can we open the stream?
- InputStream is = getInputStream();
- is.close();
- return true;
- }
- }
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- @Override
- public boolean isReadable() {
- try {
- URL url = getURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- File file = getFile();
- return (file.canRead() && !file.isDirectory());
- }
- else {
- return true;
- }
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- @Override
- public long contentLength() throws IOException {
- URL url = getURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- return getFile().length();
- }
- else {
- // Try a URL connection content-length header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- return con.getContentLength();
- }
- }
-
- @Override
- public long lastModified() throws IOException {
- URL url = getURL();
- if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
- // Proceed with file system resolution...
- return super.lastModified();
- }
- else {
- // Try a URL connection last-modified header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- return con.getLastModified();
- }
- }
-
-
- /**
- * Customize the given {@link URLConnection}, obtained in the course current an
- * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
- * <p>Calls {@link ResourceUtils#useCachesIfNecessary(URLConnection)} and
- * delegates to {@link #customizeConnection(HttpURLConnection)} if possible.
- * Can be overridden in subclasses.
- * @param con the URLConnection to customize
- * @throws IOException if thrown from URLConnection methods
- */
- protected void customizeConnection(URLConnection con) throws IOException {
- ResourceUtils.useCachesIfNecessary(con);
- if (con instanceof HttpURLConnection) {
- customizeConnection((HttpURLConnection) con);
- }
- }
-
- /**
- * Customize the given {@link HttpURLConnection}, obtained in the course current an
- * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
- * <p>Sets request method "HEAD" by default. Can be overridden in subclasses.
- * @param con the HttpURLConnection to customize
- * @throws IOException if thrown from HttpURLConnection methods
- */
- protected void customizeConnection(HttpURLConnection con) throws IOException {
- con.setRequestMethod("HEAD");
- }
-
-
- /**
- * Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
- */
- private static class VfsResourceDelegate {
-
- public static Resource getResource(URL url) throws IOException {
- return new VfsResource(VfsUtils.getRoot(url));
- }
-
- public static Resource getResource(URI uri) throws IOException {
- return new VfsResource(VfsUtils.getRoot(uri));
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AbstractResource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AbstractResource.java b/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AbstractResource.java
deleted file mode 100644
index a1c91a5..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AbstractResource.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tamaya.core.internal.resources.io;
-
-import org.apache.tamaya.core.resource.Resource;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Objects;
-
-
-/**
- * Convenience base class for {@link org.apache.tamaya.core.resource.Resource} implementations,
- * pre-implementing typical behavior.
- *
- * <p>The "exists" method will check whether a File or InputStream can
- * be opened; "isOpen" will always return false; "getURL" and "getFile"
- * throw an exception; and "toString" will return the description.
- *
- * @author Juergen Hoeller
- * @since 28.12.2003
- */
-public abstract class AbstractResource implements Resource {
-
- /**
- * This implementation checks whether a File can be opened,
- * falling back to whether an InputStream can be opened.
- * This will cover both directories and content resources.
- */
- @Override
- public boolean exists() {
- // Try file existence: can we find the file in the file system?
- try {
- return getFile().exists();
- }
- catch (IOException ex) {
- // Fall back to stream existence: can we open the stream?
- try {
- InputStream is = getInputStream();
- is.close();
- return true;
- }
- catch (Throwable isEx) {
- return false;
- }
- }
- }
-
- /**
- * This implementation always returns {@code true}.
- */
- @Override
- public boolean isReadable() {
- return true;
- }
-
- /**
- * This implementation always returns {@code false}.
- */
- @Override
- public boolean isOpen() {
- return false;
- }
-
- /**
- * This implementation throws a FileNotFoundException, assuming
- * that the resource cannot be resolved to a URL.
- */
- @Override
- public URL getURL() throws IOException {
- throw new FileNotFoundException(getDescription() + " cannot be resolved to URL");
- }
-
- /**
- * This implementation builds a URI based on the URL returned
- * by {@link #getURL()}.
- */
- @Override
- public URI getURI() throws IOException {
- URL url = getURL();
- try {
- return ResourceUtils.toURI(url);
- }
- catch (URISyntaxException ex) {
- throw new IllegalStateException("Invalid URI [" + url + "]", ex);
- }
- }
-
- /**
- * This implementation throws a FileNotFoundException, assuming
- * that the resource cannot be resolved to an absolute file path.
- */
- @Override
- public File getFile() throws IOException {
- throw new FileNotFoundException(getDescription() + " cannot be resolved to absolute file path");
- }
-
- /**
- * This implementation reads the entire InputStream to calculate the
- * content length. Subclasses will almost always be able to provide
- * a more optimal version current this, e.g. checking a File length.
- * @throws IllegalStateException if {@code #getInputStreamSupplier()} returns null.
- */
- @Override
- public long contentLength() throws IOException {
- InputStream is = this.getInputStream();
- Objects.requireNonNull(is, "resource input stream must not be null");
- try {
- long size = 0;
- byte[] buf = new byte[255];
- int read;
- while ((read = is.read(buf)) != -1) {
- size += read;
- }
- return size;
- }
- finally {
- try {
- is.close();
- }
- catch (IOException ex) {
- }
- }
- }
-
- /**
- * This implementation checks the timestamp current the underlying File,
- * if available.
- * @see #getFileForLastModifiedCheck()
- */
- @Override
- public long lastModified() throws IOException {
- long lastModified = getFileForLastModifiedCheck().lastModified();
- if (lastModified == 0L) {
- throw new FileNotFoundException(getDescription() +
- " cannot be resolved in the file system for resolving its last-modified timestamp");
- }
- return lastModified;
- }
-
- /**
- * Determine the File to use for timestamp checking.
- * <p>The default implementation delegates to {@link #getFile()}.
- * @return the File to use for timestamp checking (never {@code null})
- * @throws IOException if the resource cannot be resolved as absolute
- * file path, i.e. if the resource is not available in a file system
- */
- protected File getFileForLastModifiedCheck() throws IOException {
- return getFile();
- }
-
- /**
- * This implementation throws a FileNotFoundException, assuming
- * that relative resources cannot be created for this resource.
- */
- @Override
- public Resource createRelative(String relativePath) throws IOException {
- throw new FileNotFoundException("Cannot of a relative resource for " + getDescription());
- }
-
- /**
- * This implementation always returns {@code null},
- * assuming that this resource type does not have a filename.
- */
- @Override
- public String getFilename() {
- return null;
- }
-
-
- /**
- * This implementation returns the description current this resource.
- * @see #getDescription()
- */
- @Override
- public String toString() {
- return getDescription();
- }
-
- /**
- * This implementation compares description strings.
- * @see #getDescription()
- */
- @Override
- public boolean equals(Object obj) {
- return (obj == this ||
- (obj instanceof Resource && ((Resource) obj).getDescription().equals(getDescription())));
- }
-
- /**
- * This implementation returns the description's hash code.
- * @see #getDescription()
- */
- @Override
- public int hashCode() {
- return getDescription().hashCode();
- }
-
-}
[13/27] incubator-tamaya git commit: TAMAYA-19: Reorganized dormant
part for better focus of future discussions.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/AggregationPolicy.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/AggregationPolicy.java b/dormant/core/src/main/java/old/AggregationPolicy.java
new file mode 100644
index 0000000..99be931
--- /dev/null
+++ b/dormant/core/src/main/java/old/AggregationPolicy.java
@@ -0,0 +1,133 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.ConfigException;
+
+import java.util.logging.Logger;
+
+/**
+* Policy that defines how the different configurations/property sources should be aggregated.
+* This is done by a mapping function defined as follows:
+* <pre>
+* function f(key, value1, value2) -> result
+*
+* whereas
+*
+* key = the fully qualified property key,
+* value1 = the value from the first configuration/property source (can be null)
+* value2 = the value from the second configuration/property source (can be null)
+*
+* result = the value to be used in the aggregation, or null, which removed the
+* key from the result.
+* </pre>
+*
+* Of course, during this evaluation step additional actions can be taken, e.g. refer to #LOG_ERROR, which
+* ignores duplicate entries, but also logs the conflict on severe/error level.
+*/
+public interface AggregationPolicy {
+
+ /**
+ * Method which decides how keys/values are aggregated.
+ * @param key the key current the entry, must not be {@code null}.
+ * @param currentValue the current keys, or {@code null}.
+ * @param newValue the new keys, never {@code null}.
+ * @return the target keys to be used in the resulting property set, or null, to remove the property.
+ */
+ public String aggregate(String key, String currentValue, String newValue);
+
+ /** Ignore overrides, only extend (additive). */
+ public static final AggregationPolicy IGNORE_DUPLICATES = (k, v1, v2) -> v1 == null? v2 : v1;
+
+ /** Combine multiple values into a comma separated list. */
+ public static final AggregationPolicy COMBINE = (k, v1, v2) -> v1 != null && v2 != null ? v1 + ',' + v2: v2;
+
+ /**
+ * Interpret later keys as override (additive and override), replacing
+ * the key loaded earlier/fromMap previous contained
+ * {@link org.apache.tamaya.PropertySource}.
+ */
+ public static final AggregationPolicy OVERRIDE = (k, v1, v2) -> v2;
+
+ /**
+ * Throw an exception, when keys are not disjunctive (strictly
+ * additive).
+ */
+ public static final AggregationPolicy EXCEPTION =
+ (String key, String value, String newValue) -> {
+ if(value!=null && newValue!=null && !value.equals(newValue)){
+ throw new ConfigException("Conflicting values encountered key="+key+", keys="+value+", newValue="+newValue);
+ }
+ return newValue;
+ };
+
+ /**
+ * Ignores any duplicates, but logs the conflict encountered to error/severe level.
+ */
+ public static final AggregationPolicy LOG_ERROR =
+ (String key, String value, String newValue) -> {
+ if(value!=null && newValue!=null && !value.equals(newValue)){
+ Logger.getLogger(AggregationPolicy.class.getName())
+ .severe(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
+ return value;
+ }
+ return newValue;
+ };
+
+ /**
+ * Ignores any duplicates, but logs the conflict encountered to info level.
+ */
+ public static final AggregationPolicy LOG_WARNING =
+ (String key, String value, String newValue) -> {
+ if(value!=null && newValue!=null && !value.equals(newValue)){
+ Logger.getLogger(AggregationPolicy.class.getName())
+ .warning(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
+ return value;
+ }
+ return newValue;
+ };
+
+ /**
+ * Ignores any duplicates, but logs the conflict encountered to info level.
+ */
+ public static final AggregationPolicy LOG_INFO =
+ (String key, String value, String newValue) -> {
+ if(value!=null && newValue!=null && !value.equals(newValue)){
+ Logger.getLogger(AggregationPolicy.class.getName())
+ .info(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
+ return value;
+ }
+ return newValue;
+ };
+
+ /**
+ * Ignores any duplicates, but logs the conflict encountered to debug/finest level.
+ */
+ public static final AggregationPolicy LOG_DEBUG =
+ (String key, String value, String newValue) -> {
+ if(value!=null && newValue!=null && !value.equals(newValue)){
+ Logger.getLogger(AggregationPolicy.class.getName())
+ .finest(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
+ return value;
+ }
+ return newValue;
+ };
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/BuildablePropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/BuildablePropertySource.java b/dormant/core/src/main/java/old/BuildablePropertySource.java
new file mode 100644
index 0000000..847fbe9
--- /dev/null
+++ b/dormant/core/src/main/java/old/BuildablePropertySource.java
@@ -0,0 +1,60 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy current the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.PropertySource;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * Created by Anatole on 07.12.2014.
+ */
+class BuildablePropertySource implements PropertySource
+{
+
+ private String name;
+ private PropertySource baseProvider;
+
+ public BuildablePropertySource(String name, PropertySource baseProvider) {
+ this.name = Objects.requireNonNull(name);
+ this.baseProvider = Objects.requireNonNull(baseProvider);
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return this.baseProvider.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return this.baseProvider.getProperties();
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ public String toString(){
+ return "BuildablePropertyProvider -> " + getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/ConfigurationBuilder.java b/dormant/core/src/main/java/old/ConfigurationBuilder.java
new file mode 100644
index 0000000..6d50d0e
--- /dev/null
+++ b/dormant/core/src/main/java/old/ConfigurationBuilder.java
@@ -0,0 +1,375 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package old;
+
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.BiFunction;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertySource;
+import org.apache.tamaya.core.config.FreezedConfiguration;
+import org.apache.tamaya.core.properties.AggregationPolicy;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
+
+/**
+* Builder for assembling non trivial {@link org.apache.tamaya.Configuration} instances.
+*/
+public final class ConfigurationBuilder {
+
+ /**
+ * The final meta info to be used, or null, if a default should be generated.
+ */
+ private PropertySourceBuilder builderDelegate;
+
+ /**
+ * Private singleton constructor.
+ */
+ private ConfigurationBuilder(String name) {
+ this.builderDelegate = PropertySourceBuilder.of(name);
+ }
+
+ /**
+ * Private singleton constructor.
+ */
+ private ConfigurationBuilder(String name, PropertySource source) {
+ this.builderDelegate = PropertySourceBuilder.of(name, source);
+ }
+
+ /**
+ * Private singleton constructor.
+ */
+ private ConfigurationBuilder(PropertySource source) {
+ this.builderDelegate = PropertySourceBuilder.of(source);
+ }
+
+
+ /**
+ * Creates a new builder instance.
+ *
+ * @param provider the base provider to be used, not null.
+ * @return a new builder instance, never null.
+ */
+ public static ConfigurationBuilder of(PropertySource provider) {
+ return new ConfigurationBuilder(provider);
+ }
+
+ /**
+ * Creates a new builder instance.
+ *
+ * @param name the provider name, not null.
+ * @return a new builder instance, never null.
+ */
+ public static ConfigurationBuilder of(String name) {
+ return new ConfigurationBuilder(Objects.requireNonNull(name));
+ }
+
+ /**
+ * Creates a new builder instance.
+ *
+ * @return a new builder instance, never null.
+ */
+ public static ConfigurationBuilder of() {
+ return new ConfigurationBuilder("<noname>");
+ }
+
+
+
+
+ /**
+ * Sets the aggregation policy to be used, when adding additional property sets. The policy will
+ * be active a slong as the builder is used or it is reset to another keys.
+ *
+ * @param aggregationPolicy the aggregation policy, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder withAggregationPolicy(AggregationPolicy aggregationPolicy) {
+ this.builderDelegate.withAggregationPolicy(aggregationPolicy);
+ return this;
+ }
+
+ /**
+ * Sets the meta info to be used for the next operation.
+ *
+ * @param name the name, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder withName(String name) {
+ this.builderDelegate.withName(name);
+ return this;
+ }
+
+ /**
+ * Adds the given providers with the current active {@link AggregationPolicy}. By
+ * default {@link AggregationPolicy#OVERRIDE} is used.
+ * @see #withAggregationPolicy(AggregationPolicy)
+ * @param providers providers to be added, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addProviders(PropertySource... providers) {
+ this.builderDelegate.addProviders(providers);
+ return this;
+ }
+
+ /**
+ * Adds the given providers with the current active {@link AggregationPolicy}. By
+ * default {@link AggregationPolicy#OVERRIDE} is used.
+ * @see #withAggregationPolicy(AggregationPolicy)
+ * @param providers providers to be added, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addProviders(List<PropertySource> providers) {
+ this.builderDelegate.addProviders(providers);
+ return this;
+ }
+
+
+ /**
+ * Creates a new {@link org.apache.tamaya.PropertySource} using the given command line arguments and adds it
+ * using the current aggregation policy in place.
+ *
+ * @param args the command line arguments, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addArgs(String... args) {
+ this.builderDelegate.addArgs(args);
+ return this;
+ }
+
+ /**
+ * Creates a new read-only {@link org.apache.tamaya.PropertySource} by reading the according path resources. The effective resources read
+ * hereby are determined by the {@code PathResolverService} configured into the {@code Bootstrap} SPI.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param paths the paths to be resolved by the {@code PathResolverService} , not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addPaths(String... paths) {
+ this.builderDelegate.addPaths(paths);
+ return this;
+ }
+
+
+ /**
+ * Creates a new read-only {@link org.apache.tamaya.PropertySource} by reading the according path resources. The effective resources read
+ * hereby are determined by the {@code PathResolverService} configured into the {@code Bootstrap} SPI.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param paths the paths to be resolved by the {@code PathResolverService} , not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addPaths(List<String> paths) {
+ this.builderDelegate.addPaths(paths);
+ return this;
+ }
+
+ /**
+ * Creates a new read-only {@link org.apache.tamaya.PropertySource} by reading the according URL resources.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param urls the urls to be read, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addURLs(URL... urls) {
+ this.builderDelegate.addURLs(urls);
+ return this;
+ }
+
+ /**
+ * Creates a new read-only {@link org.apache.tamaya.PropertySource} by reading the according URL resources.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param urls the urls to be read, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addURLs(List<URL> urls) {
+ this.builderDelegate.addURLs(urls);
+ return this;
+ }
+
+
+ /**
+ * Creates a new read-only {@link org.apache.tamaya.PropertySource} based on the given map.
+ * Properties read are aggregated using the current aggregation policy active.
+ *
+ * @param map the map to be added, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addMap(Map<String, String> map) {
+ this.builderDelegate.addMap(map);
+ return this;
+ }
+
+
+ /**
+ * Add the current environment properties. Aggregation is based on the current {@link AggregationPolicy} acvtive.
+ *
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addEnvironmentProperties() {
+ this.builderDelegate.addEnvironmentProperties();
+ return this;
+ }
+
+ /**
+ * Add the current system properties. Aggregation is based on the current {@link AggregationPolicy} acvtive.
+ *
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder addSystemProperties() {
+ this.builderDelegate.addSystemProperties();
+ return this;
+ }
+
+ /**
+ * Adds the given {@link org.apache.tamaya.PropertySource} instances using the current {@link AggregationPolicy}
+ * active.
+ *
+ * @param providers the maps to be included, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder aggregate(PropertySource... providers) {
+ this.builderDelegate.aggregate(providers);
+ return this;
+ }
+
+
+ /**
+ * Adds the given {@link org.apache.tamaya.PropertySource} instances using the current {@link AggregationPolicy}
+ * active.
+ *
+ * @param providers the maps to be included, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder aggregate(List<PropertySource> providers) {
+ this.builderDelegate.aggregate(providers);
+ return this;
+ }
+
+
+ /**
+ * Intersetcs the current properties with the given {@link org.apache.tamaya.PropertySource} instance.
+ *
+ * @param providers the maps to be intersected, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder intersect(PropertySource... providers) {
+ this.builderDelegate.intersect(providers);
+ return this;
+ }
+
+
+ /**
+ * Subtracts with the given {@link org.apache.tamaya.PropertySource} instance from the current properties.
+ *
+ * @param providers the maps to be subtracted, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationBuilder subtract(PropertySource... providers) {
+ this.builderDelegate.subtract(providers);
+ return this;
+ }
+
+
+ /**
+ * Filters the current properties based on the given predicate..
+ *
+ * @param filter the filter to be applied, not null.
+ * @return the new filtering instance.
+ */
+ public ConfigurationBuilder filter(Predicate<String> filter) {
+ this.builderDelegate.filter(filter);
+ return this;
+ }
+
+ /**
+ * Filters the current {@link org.apache.tamaya.Configuration} with the given valueFilter.
+ * @param valueFilter the value filter, not null.
+ * @return the (dynamically) filtered source instance, never null.
+ */
+ public ConfigurationBuilder filterValues(BiFunction<String, String, String> valueFilter){
+ this.builderDelegate.filterValues(valueFilter);
+ return this;
+ }
+
+ /**
+ * Creates a new contextual {@link org.apache.tamaya.PropertySource}. Contextual maps delegate to different instances current PropertyMap depending
+ * on the keys returned fromMap the isolationP
+ *
+ * @param mapSupplier the supplier creating new provider instances
+ * @param isolationKeySupplier the supplier providing contextual keys based on the current environment.
+ */
+ public ConfigurationBuilder addContextual(Supplier<PropertySource> mapSupplier,
+ Supplier<String> isolationKeySupplier) {
+ this.builderDelegate.addContextual(mapSupplier, isolationKeySupplier);
+ return this;
+ }
+
+ /**
+ * Replaces all keys in the current provider by the given map.
+ *
+ * @param replacementMap the map instance, that will replace all corresponding entries in {@code mainMap}, not null.
+ * @return the new delegating instance.
+ */
+ public ConfigurationBuilder replace(Map<String, String> replacementMap) {
+ this.builderDelegate.replace(replacementMap);
+ return this;
+ }
+
+ /**
+ * Build a new property provider based on the input.
+ * @return a new property provider, or null.
+ */
+ public PropertySource buildPropertySource(){
+ return this.builderDelegate.build();
+ }
+
+ /**
+ * Build a new property provider based on the input.
+ * @return a new property provider, or null.
+ */
+ public Configuration build(){
+ return this.buildPropertySource().toConfiguration();
+ }
+
+ /**
+ * Creates a {@link org.apache.tamaya.PropertySource} instance that is serializable and immutable,
+ * so it can be sent over a network connection.
+ *
+ * @return the freezed instance, never null.
+ */
+ public PropertySource buildFreezedPropertySource() {
+ return this.builderDelegate.buildFrozen();
+ }
+
+ /**
+ * Creates a {@link org.apache.tamaya.PropertySource} instance that is serializable and immutable,
+ * so it can be sent over a network connection.
+ *
+ * @return the freezed instance, never null.
+ */
+ public Configuration buildFreezed() {
+ return FreezedConfiguration.of(this.buildFreezedPropertySource().toConfiguration());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/ConfigurationProviderSpi.java b/dormant/core/src/main/java/old/ConfigurationProviderSpi.java
new file mode 100644
index 0000000..26697ea
--- /dev/null
+++ b/dormant/core/src/main/java/old/ConfigurationProviderSpi.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import org.apache.tamaya.Configuration;
+
+/**
+* This configuration provider SPI allows to register the effective factory logic to of and manage a configuration
+* instance. Hereby the qualifiers determine the type current configuration. By default
+*/
+public interface ConfigurationProviderSpi{
+
+ /**
+ * Returns the name current the configuration provided.
+ * @return the name current the configuration provided, not empty.
+ */
+ String getConfigName();
+
+ /**
+ * Get the {@link Configuration}, if available.
+ * @return according configuration, or null, if none is available for the given environment.
+ */
+ Configuration getConfiguration();
+
+ /**
+ * Reloads the provider for the current context.
+ */
+ void reload();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/ContextualPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/ContextualPropertySource.java b/dormant/core/src/main/java/old/ContextualPropertySource.java
new file mode 100644
index 0000000..6290706
--- /dev/null
+++ b/dormant/core/src/main/java/old/ContextualPropertySource.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.*;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+
+/**
+ * Created by Anatole on 12.04.2014.
+ */
+class ContextualPropertySource implements PropertySource {
+
+ private volatile Map<String,PropertySource> cachedMaps = new ConcurrentHashMap<>();
+
+ private Supplier<PropertySource> mapSupplier;
+ private Supplier<String> isolationKeySupplier;
+ private String name;
+
+
+ /**
+ * Creates a new contextual PropertyMap. Contextual maps delegate to different instances current PropertyMap depending
+ * on the keys returned fromMap the isolationP
+ *
+ * @param mapSupplier
+ * @param isolationKeySupplier
+ */
+ public ContextualPropertySource(String name, Supplier<PropertySource> mapSupplier, Supplier<String> isolationKeySupplier){
+ this.name = Optional.ofNullable(name).orElse("<noname>");
+ Objects.requireNonNull(mapSupplier);
+ Objects.requireNonNull(isolationKeySupplier);
+ this.mapSupplier = mapSupplier;
+ this.isolationKeySupplier = isolationKeySupplier;
+ }
+
+ /**
+ * This method provides the contextual Map for the current environment. Hereby, ba default, for each different
+ * key returned by the #isolationKeySupplier a separate PropertyMap instance is acquired fromMap the #mapSupplier.
+ * If the map supplier returns an instance it is cached in the local #cachedMaps.
+ *
+ * @return the current contextual PropertyMap.
+ */
+ protected PropertySource getContextualMap(){
+ String environmentKey = this.isolationKeySupplier.get();
+ if(environmentKey == null){
+ return PropertySource.EMPTY_PROPERTYSOURCE;
+ }
+ PropertySource map = this.cachedMaps.get(environmentKey);
+ if(map == null){
+ synchronized(cachedMaps){
+ map = this.cachedMaps.get(environmentKey);
+ if(map == null){
+ map = this.mapSupplier.get();
+ if(map == null){
+ return PropertySource.EMPTY_PROPERTYSOURCE;
+ }
+ this.cachedMaps.put(environmentKey, map);
+ }
+ }
+ }
+ return map;
+ }
+
+ @Override
+ public Map<String,String> getProperties(){
+ return getContextualMap().getProperties();
+ }
+
+ @Override
+ public String getName(){
+ return this.name;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ return getContextualMap().get(key);
+ }
+
+ /**
+ * Access a cached PropertyMap.
+ *
+ * @param key the target environment key as returned by the environment key supplier, not null.
+ * @return the corresponding PropertyMap, or null.
+ */
+ public PropertySource getCachedMap(String key){
+ return this.cachedMaps.get(key);
+ }
+
+ /**
+ * Access the set current currently loaded/cached maps.
+ *
+ * @return the set current cached map keys, never null.
+ */
+ public Set<String> getCachedMapKeys(){
+ return this.cachedMaps.keySet();
+ }
+
+ /**
+ * Access the supplier for environment key, determining map isolation.
+ *
+ * @return the environment key supplier instance, not null.
+ */
+ public Supplier<String> getIsolationKeySupplier(){
+ return this.isolationKeySupplier;
+ }
+
+ /**
+ * Access the supplier for new PropertyMap instances.
+ *
+ * @return the PropertyMap supplier instance, not null.
+ */
+ public Supplier<PropertySource> getMapSupplier(){
+ return this.mapSupplier;
+ }
+
+ @Override
+ public String toString(){
+ return "ContextualMap{" +
+ "cachedMaps(key)=" + cachedMaps.keySet() +
+ ", mapSupplier=" + mapSupplier +
+ ", isolationKeySupplier=" + isolationKeySupplier +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/DefaultConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/DefaultConfigurationSpi.java b/dormant/core/src/main/java/old/DefaultConfigurationSpi.java
new file mode 100644
index 0000000..fe9f788
--- /dev/null
+++ b/dormant/core/src/main/java/old/DefaultConfigurationSpi.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import java.lang.reflect.Proxy;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.internal.config.FallbackSimpleConfigProvider;
+import org.apache.tamaya.core.internal.el.DefaultExpressionEvaluator;
+import org.apache.tamaya.core.internal.inject.ConfigTemplateInvocationHandler;
+import org.apache.tamaya.core.internal.inject.ConfigurationInjector;
+import org.apache.tamaya.core.spi.ExpressionEvaluator;
+import org.apache.tamaya.spi.ConfigurationSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
+
+/**
+ * Default SPI that implements the behaviour of {@link org.apache.tamaya.spi.ConfigurationSpi}.
+ */
+@SuppressWarnings("unchecked")
+public class DefaultConfigurationSpi implements ConfigurationSpi {
+
+ private static final String DEFAULT_CONFIG_NAME = "default";
+
+ private Map<String, ConfigurationProviderSpi> configProviders = new ConcurrentHashMap<>();
+
+ private ExpressionEvaluator expressionEvaluator = loadEvaluator();
+
+ private ExpressionEvaluator loadEvaluator() {
+ ExpressionEvaluator eval = ServiceContext.getInstance().getService(ExpressionEvaluator.class).orElse(null);
+ if (eval == null) {
+ eval = new DefaultExpressionEvaluator();
+ }
+ return eval;
+ }
+
+ public DefaultConfigurationSpi() {
+ if(configProviders.isEmpty()) {
+ for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
+ configProviders.put(spi.getConfigName(), spi);
+ }
+ }
+ }
+
+ @Override
+ public <T> T createTemplate(Class<T> type, Configuration... configurations) {
+ ClassLoader cl = Optional.ofNullable(Thread.currentThread()
+ .getContextClassLoader()).orElse(getClass().getClassLoader());
+ return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, configurations));
+ }
+
+ /**
+ *
+ * @param instance the instance with configuration annotations, not null.
+ * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no items are passed, the default configuration is used.
+ */
+ @Override
+ public void configure(Object instance, Configuration... configurations) {
+ ConfigurationInjector.configure(instance, configurations);
+ }
+
+
+ @Override
+ public String evaluateValue(String expression, Configuration... configurations) {
+ return expressionEvaluator.evaluate(expression, configurations);
+ }
+
+ @Override
+ public boolean isConfigurationAvailable(String name) {
+ ConfigurationProviderSpi spi = this.configProviders.get(name);
+ return spi != null;
+ }
+
+ @Override
+ public Configuration getConfiguration(String name) {
+ ConfigurationProviderSpi provider = configProviders.get(name);
+ if (provider == null) {
+ if (DEFAULT_CONFIG_NAME.equals(name)) {
+ provider = new FallbackSimpleConfigProvider();
+ configProviders.put(DEFAULT_CONFIG_NAME, provider);
+ } else {
+ throw new ConfigException("No such config: " + name);
+ }
+ }
+ Configuration config = provider.getConfiguration();
+ if (config == null) {
+ throw new ConfigException("No such config: " + name);
+ }
+ return config;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/DefaultServiceComparator.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/DefaultServiceComparator.java b/dormant/core/src/main/java/old/DefaultServiceComparator.java
new file mode 100644
index 0000000..f284426
--- /dev/null
+++ b/dormant/core/src/main/java/old/DefaultServiceComparator.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import java.util.*;
+
+/**
+ * Simple comparator based on a Collection of {@link OrdinalProvider} instances.
+ */
+final class DefaultServiceComparator implements Comparator<Object>{
+
+ /**
+ * List of ordinal providers loaded.
+ */
+ private List<OrdinalProvider> ordinalProviders = new ArrayList<>();
+
+ DefaultServiceComparator(Collection<? extends OrdinalProvider> providers){
+ ordinalProviders.addAll(Objects.requireNonNull(providers));
+ ordinalProviders.sort(this::compare);
+ }
+
+ private int compare(OrdinalProvider provider1, OrdinalProvider provider2){
+ int o1 = getOrdinal(provider1);
+ int o2 = getOrdinal(provider2);
+ int order = o1-o2;
+ if(order < 0){
+ return -1;
+ }
+ else if(order > 0){
+ return 1;
+ }
+ return 0;
+ }
+
+ private int getOrdinal(OrdinalProvider provider){
+ if(provider instanceof Orderable){
+ return ((Orderable)provider).order();
+ }
+ return 0;
+ }
+
+ public int getOrdinal(Object service){
+ for(OrdinalProvider provider: ordinalProviders){
+ OptionalInt ord = provider.getOrdinal(service.getClass());
+ if(ord.isPresent()){
+ return ord.getAsInt();
+ }
+ }
+ if(service instanceof Orderable){
+ return ((Orderable)service).order();
+ }
+ return 0;
+ }
+
+
+ @Override
+ public int compare(Object o1, Object o2) {
+ int ord1 = getOrdinal(o1);
+ int ord2 = getOrdinal(o2);
+ int order = ord1-ord2;
+ if(order < 0){
+ return -1;
+ }
+ else if(order > 0){
+ return 1;
+ }
+ return 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/DefaultServiceContextProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/DefaultServiceContextProvider.java b/dormant/core/src/main/java/old/DefaultServiceContextProvider.java
new file mode 100644
index 0000000..ae02afd
--- /dev/null
+++ b/dormant/core/src/main/java/old/DefaultServiceContextProvider.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
+ * {@link java.util.ServiceLoader} to load the services required.
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+class DefaultServiceContextProvider implements ServiceContext {
+ /** List current services loaded, per class. */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+ /** Singletons. */
+ private final ConcurrentHashMap<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
+ /** Comparator for ordering of multiple services found. */
+ private DefaultServiceComparator serviceComparator;
+
+ public DefaultServiceContextProvider(){
+ serviceComparator = new DefaultServiceComparator(getServices(OrdinalProvider.class, Collections.emptyList()));
+ }
+
+ @Override
+ public <T> Optional<T> getService(Class<T> serviceType) {
+ Optional<T> cached = (Optional<T>)singletons.get(serviceType);
+ if(cached==null) {
+ List<? extends T> services = getServices(serviceType, Collections.emptyList());
+ if (services.isEmpty()) {
+ cached = Optional.empty();
+ }
+ else{
+ cached = Optional.of(services.get(0));
+ }
+ singletons.put(serviceType, cached);
+ }
+ return cached;
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param serviceType
+ * The service type.
+ * @param <T>
+ * the concrete type.
+ * @param defaultList
+ * the list current items returned, if no services were found.
+ * @return the items found, never {@code null}.
+ */
+ @Override
+ public <T> List<? extends T> getServices(final Class<T> serviceType, final List<? extends T> defaultList) {
+ List<T> found = (List<T>) servicesLoaded.get(serviceType);
+ if (found != null) {
+ return found;
+ }
+ return loadServices(serviceType, defaultList);
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param serviceType The service type.
+ * @param <T> the concrete type.
+ * @param defaultList the list current items returned, if no services were found.
+ *
+ * @return the items found, never {@code null}.
+ */
+ private <T> List<? extends T> loadServices(final Class<T> serviceType, final List<? extends T> defaultList) {
+ try {
+ List<T> services = new ArrayList<>();
+ for (T t : ServiceLoader.load(serviceType)) {
+ services.add(t);
+ }
+ if(services.isEmpty()){
+ services.addAll(defaultList);
+ }
+ if(!serviceType.equals(OrdinalProvider.class)) {
+ services.sort(serviceComparator);
+ }
+ services = Collections.unmodifiableList(services);
+ final List<T> previousServices = (List<T>) servicesLoaded.putIfAbsent(serviceType, (List<Object>)services);
+ return previousServices != null ? previousServices : services;
+ } catch (Exception e) {
+ Logger.getLogger(DefaultServiceContextProvider.class.getName()).log(Level.WARNING,
+ "Error loading services current type " + serviceType, e);
+ return defaultList;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/DelegatingPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/DelegatingPropertySource.java b/dormant/core/src/main/java/old/DelegatingPropertySource.java
new file mode 100644
index 0000000..9cb9f57
--- /dev/null
+++ b/dormant/core/src/main/java/old/DelegatingPropertySource.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import org.apache.tamaya.PropertySource;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.*;
+
+/**
+ * Implementation for a {@link org.apache.tamaya.PropertySource} that is an aggregate current
+ * multiple child instances. Controlled by an {@link org.apache.tamaya.AggregationPolicy} the
+ * following aggregations are supported:
+ * <ul>
+ * <li><b>IGNORE_DUPLICATES: </b>Ignore all overrides.</li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * </ul>
+ */
+class DelegatingPropertySource implements PropertySource {
+
+ private PropertySource mainMap;
+ private Map<String,String> parentMap;
+ private String name;
+
+
+ /**
+ * Creates a mew instance, with aggregation polilcy
+ * {@code AggregationPolicy.OVERRIDE}.
+ *
+ * @param mainMap The main ConfigMap.
+ * @param parentMap The delegated parent ConfigMap.
+ */
+ public DelegatingPropertySource(String name, PropertySource mainMap, Map<String, String> parentMap){
+ this.name = Optional.of(name).orElse("<noname>");
+ this.parentMap = Objects.requireNonNull(parentMap);
+ this.parentMap = Objects.requireNonNull(parentMap);
+ }
+
+ @Override
+ public Map<String,String> getProperties(){
+ return null;
+ }
+
+ @Override
+ public String getName(){
+ return this.name;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ Optional<String> val = mainMap.get(key);
+ if(!val.isPresent()){
+ return Optional.ofNullable(parentMap.get(key));
+ }
+ return val;
+ }
+
+ @Override
+ public String toString(){
+ return super.toString() + "(mainMap=" + mainMap + ", delegate=" + parentMap + ")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/EnvPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/EnvPropertiesConfigProvider.java b/dormant/core/src/main/java/old/EnvPropertiesConfigProvider.java
new file mode 100644
index 0000000..82306bb
--- /dev/null
+++ b/dormant/core/src/main/java/old/EnvPropertiesConfigProvider.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
+import old.ConfigurationProviderSpi;
+
+import org.apache.tamaya.Configuration;
+
+/**
+ * Provides a {@link org.apache.tamaya.Configuration} named 'environment.properties'
+ * containing the current environment properties.
+ *
+ * Created by Anatole on 29.09.2014.
+ */
+public class EnvPropertiesConfigProvider implements ConfigurationProviderSpi{
+
+ private Configuration envConfig;
+
+ public EnvPropertiesConfigProvider(){
+ envConfig = Configuration.from(PropertySourceBuilder.of("environment.properties").addEnvironmentProperties().build());
+ }
+
+ @Override
+ public String getConfigName(){
+ return "environment.properties";
+ }
+
+ @Override
+ public Configuration getConfiguration(){
+ return envConfig;
+ }
+
+ @Override
+ public void reload() {
+ // nothing todo here
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/MappedConfiguration.java b/dormant/core/src/main/java/old/MappedConfiguration.java
new file mode 100644
index 0000000..43c63dc
--- /dev/null
+++ b/dormant/core/src/main/java/old/MappedConfiguration.java
@@ -0,0 +1,57 @@
+package old;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.UnaryOperator;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.config.AbstractConfiguration;
+
+/**
+ * Configuration implementation that maps certain parts (defined by an {@code UnaryOperator<String>}) to alternate areas.
+ */
+class MappedConfiguration extends AbstractConfiguration implements Configuration {
+
+ private static final long serialVersionUID = 8690637705511432083L;
+
+ /** The mapping operator. */
+ private UnaryOperator<String> keyMapper;
+ /** The base configuration. */
+ private Configuration config;
+
+ /**
+ * Creates a new instance.
+ * @param config the base configuration, not null
+ * @param keyMapper The mapping operator, not null
+ */
+ public MappedConfiguration(Configuration config, UnaryOperator<String> keyMapper) {
+ super(config.getName());
+ this.config = Objects.requireNonNull(config);
+ this.keyMapper = Objects.requireNonNull(keyMapper);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> result = new HashMap<>();
+ Map<String, String> map = this.config.getProperties();
+ map.forEach((k,v) -> {
+ String targetKey = keyMapper.apply(k);
+ if(targetKey!=null){
+ result.put(targetKey, v);
+ }
+ });
+ return result;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.config.isEmpty();
+ }
+
+ @Override
+ public Configuration toConfiguration() {
+ return this;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/Orderable.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/Orderable.java b/dormant/core/src/main/java/old/Orderable.java
new file mode 100644
index 0000000..13380a1
--- /dev/null
+++ b/dormant/core/src/main/java/old/Orderable.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+/**
+ * Interface that can be optionally implemented by SPI components to be loaded into
+ * the Tamaya's ServiceContext. The ordinal provided will be used to determine
+ * priority and precedence, when multiple components implement the same
+ * service interface.
+ */
+@FunctionalInterface
+public interface Orderable {
+ /**
+ * Get the ordinal keys for the component, by default 0.
+ * @return the ordinal keys
+ */
+ int order();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/OrdinalProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/OrdinalProvider.java b/dormant/core/src/main/java/old/OrdinalProvider.java
new file mode 100644
index 0000000..0152b84
--- /dev/null
+++ b/dormant/core/src/main/java/old/OrdinalProvider.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import java.util.OptionalInt;
+
+/**
+ * The ordinal provider is an optional component that provides an abstraction for ordering/prioritizing
+ * services loaded. This can be used to determine, which SPI should be used, if multiple instances are
+ * available, or for ordering chain of services.
+ * @see org.apache.tamaya.spi.ServiceContext
+ */
+public interface OrdinalProvider {
+ /**
+ * Evaluate the ordinal number for the given type.
+ * @param type the target type, not null.
+ * @return the ordinal, if not defined, 0 should be returned.
+ */
+ OptionalInt getOrdinal(Class<?> type);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/PropertyAdapterProviderSpi.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/PropertyAdapterProviderSpi.java b/dormant/core/src/main/java/old/PropertyAdapterProviderSpi.java
new file mode 100644
index 0000000..65c31a7
--- /dev/null
+++ b/dormant/core/src/main/java/old/PropertyAdapterProviderSpi.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import org.apache.tamaya.PropertyAdapter;
+
+/**
+ * This service provides different {@link org.apache.tamaya.PropertyAdapter} instances for types.
+ */
+public interface PropertyAdapterProviderSpi {
+
+ /**
+ * Called, when a given {@link org.apache.tamaya.Configuration} has to be evaluated.
+ *
+ * @return the corresponding {@link java.util.function.Function<String, T>}, or {@code null}, if
+ * not available for the given target type.
+ */
+ <T> PropertyAdapter<T> getPropertyAdapter(Class<T> type);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/PropertyChangeSet.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/PropertyChangeSet.java b/dormant/core/src/main/java/old/PropertyChangeSet.java
new file mode 100644
index 0000000..3cf6b31
--- /dev/null
+++ b/dormant/core/src/main/java/old/PropertyChangeSet.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.PropertySource;
+
+import java.beans.PropertyChangeEvent;
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * Event that contains a set current changes that were applied or could be applied.
+ * This class is immutable and thread-safe. To create instances use
+ * {@link PropertyChangeSetBuilder}.
+ *
+ * Created by Anatole on 22.10.2014.
+ */
+public final class PropertyChangeSet implements Serializable{
+
+ private static final long serialVersionUID = 1l;
+ /** The base property provider/configuration. */
+ private PropertySource propertySource;
+ /** The base version, usable for optimistic locking. */
+ private String baseVersion;
+ /** The recorded changes. */
+ private Map<String,PropertyChangeEvent> changes = new HashMap<>();
+
+ /**
+ * Get an empty change set for the given provider.
+ * @param propertyProvider The base property provider/configuration, not null.
+ * @return an empty ConfigChangeSet instance.
+ */
+ public static PropertyChangeSet emptyChangeSet(PropertySource propertyProvider){
+ return new PropertyChangeSet(propertyProvider, Collections.emptySet());
+ }
+
+ /**
+ * Constructor used by {@link PropertyChangeSetBuilder}.
+ * @param propertySource The base property provider/configuration, not null.
+ * @param changes The recorded changes, not null.
+ */
+ PropertyChangeSet(PropertySource propertySource, Collection<PropertyChangeEvent> changes) {
+ this.propertySource = Objects.requireNonNull(propertySource);
+ changes.forEach((c) -> this.changes.put(c.getPropertyName(), c));
+ }
+
+ /**
+ * Get the underlying property provider/configuration.
+ * @return the underlying property provider/configuration, never null.
+ */
+ public PropertySource getPropertySource(){
+ return this.propertySource;
+ }
+
+ /**
+ * Get the base version, usable for optimistic locking.
+ * @return the base version.
+ */
+ public String getBaseVersion(){
+ return baseVersion;
+ }
+
+ /**
+ * Get the changes recorded.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertyChangeEvent> getEvents(){
+ return Collections.unmodifiableCollection(this.changes.values());
+ }
+
+ /**
+ * Access the number current removed entries.
+ * @return the number current removed entries.
+ */
+ public int getRemovedSize() {
+ return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
+ }
+
+ /**
+ * Access the number current added entries.
+ * @return the number current added entries.
+ */
+ public int getAddedSize() {
+ return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null).count();
+ }
+
+ /**
+ * Access the number current updated entries.
+ * @return the number current updated entries.
+ */
+ public int getUpdatedSize() {
+ return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
+ }
+
+
+ /**
+ * Checks if the given key was removed.
+ * @param key the target key, not null.
+ * @return true, if the given key was removed.
+ */
+ public boolean isRemoved(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getNewValue() == null;
+ }
+
+ /**
+ * Checks if the given key was added.
+ * @param key the target key, not null.
+ * @return true, if the given key was added.
+ */
+ public boolean isAdded(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getOldValue() == null;
+ }
+
+ /**
+ * Checks if the given key was updated.
+ * @param key the target key, not null.
+ * @return true, if the given key was updated.
+ */
+ public boolean isUpdated(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getOldValue() != null && change.getNewValue() != null;
+ }
+
+ /**
+ * Checks if the given key is added, or updated AND NOT removed.
+ * @param key the target key, not null.
+ * @return true, if the given key was added, or updated BUT NOT removed.
+ */
+ public boolean containsKey(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getNewValue() != null;
+ }
+
+ /**
+ * CHecks if the current change set does not contain any changes.
+ * @return tru, if the change set is empty.
+ */
+ public boolean isEmpty(){
+ return this.changes.isEmpty();
+ }
+
+
+ @Override
+ public String toString() {
+ return "ConfigChangeSet{" +
+ "properties=" + propertySource +
+ ", baseVersion=" + baseVersion +
+ ", changes=" + changes +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/PropertyChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/PropertyChangeSetBuilder.java b/dormant/core/src/main/java/old/PropertyChangeSetBuilder.java
new file mode 100644
index 0000000..b6e22f8
--- /dev/null
+++ b/dormant/core/src/main/java/old/PropertyChangeSetBuilder.java
@@ -0,0 +1,347 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.PropertySource;
+
+import java.beans.PropertyChangeEvent;
+import java.util.*;
+import java.util.function.Function;
+
+/**
+ * Models a set current changes to be applied to a configuration/property provider. Such a set can be applied
+ * to any {@link org.apache.tamaya.PropertySource} instance. If the provider is mutable it may check the
+ * version given and applyChanges the changes to the provider/configuration, including triggering current regarding
+ * change events.
+ * <p>
+ * For appropriate conversion a {@code Function<String, Codec>} can be applied, which performs correct conversion,
+ * when changed values are set. This function enables connecting e.g. setters on a configuration template with
+ * the corresponding conversion logic, so the template calls are correctly converted back.
+ */
+public final class PropertyChangeSetBuilder {
+ /**
+ * The recorded changes.
+ */
+ final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>();
+ /**
+ * The underlying configuration/provider.
+ */
+ PropertySource source;
+
+ /**
+ * Constructor.
+ *
+ * @param source the underlying configuration/provider, not null.
+ */
+ private PropertyChangeSetBuilder(PropertySource source) {
+ this.source = Objects.requireNonNull(source);
+ }
+
+ /**
+ * Creates a new instance current this builder.
+ *
+ * @param source the underlying property provider/configuration, not null.
+ * @return the builder for chaining.
+ */
+ public static PropertyChangeSetBuilder of(PropertySource source) {
+ return new PropertyChangeSetBuilder(source);
+ }
+
+ /**
+ * This method records all changes to be applied to the base property provider/configuration to
+ * achieve the given target state.
+ *
+ * @param newState the new target state, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder addChanges(PropertySource newState) {
+ compare(newState, this.source).forEach((c) -> this.delta.put(c.getPropertyName(), c));
+ return this;
+ }
+
+ /**
+ * Get the current values, also considering any changes recorded within this change set.
+ *
+ * @param key the key current the entry, not null.
+ * @return the keys, or null.
+ */
+ public String get(String key) {
+ PropertyChangeEvent change = this.delta.get(key);
+ if (change != null && !(change.getNewValue() == null)) {
+ return (String) change.getNewValue();
+ }
+ return null;
+ }
+
+ /**
+ * Marks the given key(s) fromMap the configuration/properties to be removed.
+ *
+ * @param key the key current the entry, not null.
+ * @param otherKeys additional keys to be removed (convenience), not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder remove(String key, String... otherKeys) {
+ String oldValue = this.source.get(key).orElse(null);
+ if (oldValue == null) {
+ this.delta.remove(key);
+ }
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, oldValue, null));
+ for (String addKey : otherKeys) {
+ oldValue = this.source.get(addKey).orElse(null);
+ if (oldValue == null) {
+ this.delta.remove(addKey);
+ }
+ this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue, null));
+ }
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, boolean value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ s* Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, byte value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, char value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, short value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, int value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, long value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, float value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, double value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, String value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ * @throws org.apache.tamaya.ConfigException if no matching Codec could be found.
+ */
+ public <T> PropertyChangeSetBuilder put(String key, Class<T> type, T value) {
+ put(key, type, value, null);
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @param adapter the codec to be used, if set overrides any other codecs that may apply. If null an appropriate
+ * codec is tried to be evaluated as needed.
+ * @return the builder for chaining.
+ * @throws org.apache.tamaya.ConfigException if no matching Codec could be found.
+ */
+ public <T> PropertyChangeSetBuilder put(String key, Class<T> type, T value, Function<T,String> adapter) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), adapter.apply(Objects.requireNonNull(value))));
+ return this;
+ }
+
+
+ /**
+ * Apply all the given values to the base configuration/properties.
+ * Note that all values passed must be convertible to String, either
+ * <ul>
+ * <li>the registered codecs provider provides codecs for the corresponding keys, or </li>
+ * <li>default codecs are present for the given type, or</li>
+ * <li>the value is an instanceof String</li>
+ * </ul>
+ *
+ * @param changes the changes to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder putAll(Map<String, String> changes) {
+ changes.putAll(changes);
+ return this;
+ }
+
+ /**
+ * This method will create a change set that clears all entries fromMap the given base configuration/properties.
+ *
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder deleteAll() {
+ this.delta.clear();
+ this.source.getProperties().forEach((k, v) ->
+ this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
+ return this;
+ }
+
+ /**
+ * Checks if the change set is empty, i.e. does not contain any changes.
+ *
+ * @return true, if the set is empty.
+ */
+ public boolean isEmpty() {
+ return this.delta.isEmpty();
+ }
+
+ /**
+ * Resets this change set instance. This will clear all changes done to this builder, so the
+ * set will be empty.
+ */
+ public void reset() {
+ this.delta.clear();
+ }
+
+ /**
+ * Builds the corresponding change set.
+ *
+ * @return the new change set, never null.
+ */
+ public PropertyChangeSet build() {
+ return new PropertyChangeSet(this.source, Collections.unmodifiableCollection(this.delta.values()));
+ }
+
+ /**
+ * Compares the two property config/configurations and creates a collection current all changes
+ * that must be appied to render {@code map1} into {@code map2}.
+ *
+ * @param map1 the source map, not null.
+ * @param map2 the target map, not null.
+ * @return a collection current change events, never null.
+ */
+ public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
+ List<PropertyChangeEvent> changes = new ArrayList<>();
+ for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
+ Optional<String> val = map2.get(en.getKey());
+ if (!val.isPresent()) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ } else if (!val.get().equals(en.getValue())) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
+ }
+ }
+ for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
+ Optional<String> val = map1.get(en.getKey());
+ if (!val.isPresent()) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ } else if (!val.equals(Optional.ofNullable(en.getValue()))) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
+ }
+ }
+ return changes;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "PropertyChangeEventBuilder [source=" + source + ", " +
+ ", delta=" + delta + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/SubtractingPropertySource.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/SubtractingPropertySource.java b/dormant/core/src/main/java/old/SubtractingPropertySource.java
new file mode 100644
index 0000000..f78ceb9
--- /dev/null
+++ b/dormant/core/src/main/java/old/SubtractingPropertySource.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.PropertySource;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+class SubtractingPropertySource extends AbstractPropertySource {
+
+ private static final long serialVersionUID = 4301042530074932562L;
+ private PropertySource unit;
+ private List<PropertySource> subtrahends;
+
+ public SubtractingPropertySource(String name, PropertySource configuration, List<PropertySource> subtrahends){
+ super(name);
+ Objects.requireNonNull(configuration);
+ this.unit = configuration;
+ this.subtrahends = new ArrayList<>(subtrahends);
+ }
+
+ private boolean filter(Map.Entry<String,String> entry){
+ for(PropertySource prov: subtrahends){
+ if(prov.get(entry.getKey()).isPresent()){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public Map<String,String> getProperties(){
+ return this.unit.getProperties().entrySet().stream().filter(this::filter).collect(Collectors.toMap(
+ Map.Entry::getKey,
+ Map.Entry::getValue
+ ));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/old/SystemPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/old/SystemPropertiesConfigProvider.java b/dormant/core/src/main/java/old/SystemPropertiesConfigProvider.java
new file mode 100644
index 0000000..30a0cf0
--- /dev/null
+++ b/dormant/core/src/main/java/old/SystemPropertiesConfigProvider.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package old;
+
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
+import old.ConfigurationProviderSpi;
+
+import org.apache.tamaya.Configuration;
+
+/**
+ * Provides a {@link org.apache.tamaya.Configuration} named 'system.properties'
+ * containing the current system properties.
+ *
+ * Created by Anatole on 29.09.2014.
+ */
+public class SystemPropertiesConfigProvider implements ConfigurationProviderSpi{
+
+ private Configuration systemConfig;
+
+ public SystemPropertiesConfigProvider(){
+ systemConfig = Configuration.from(PropertySourceBuilder.of("system.properties").addSystemProperties().build());
+ }
+
+ @Override
+ public String getConfigName(){
+ return "system.properties";
+ }
+
+ @Override
+ public Configuration getConfiguration(){
+ return systemConfig;
+ }
+
+ @Override
+ public void reload() {
+ // nothing todo here
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java b/dormant/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
index 31179cd..8289d64 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
@@ -22,7 +22,7 @@ import java.util.Optional;
import org.apache.tamaya.*;
import org.apache.tamaya.core.properties.AbstractPropertySource;
-import org.apache.tamaya.core.spi.PropertyAdapterProviderSpi;
+import old.PropertyAdapterProviderSpi;
import org.apache.tamaya.spi.ServiceContext;
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b56817f7/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java b/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
index c1a2518..7306fff 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.core.config;
+import old.MappedConfiguration;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.core.properties.PropertySourceBuilder;