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/03/18 00:49:13 UTC
[1/6] incubator-tamaya git commit: - Added format name. - Simplified
base property provider class.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master ff3faca16 -> d4141c1ff
- Added format name.
- Simplified base property provider class.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b8aa9e8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b8aa9e8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b8aa9e8e
Branch: refs/heads/master
Commit: b8aa9e8e64b0718e664b17785cb94605b7d7070d
Parents: a5420d6
Author: anatole <an...@apache.org>
Authored: Tue Mar 3 22:01:20 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Mar 3 22:01:20 2015 +0100
----------------------------------------------------------------------
.../BaseFormatPropertySourceProvider.java | 148 +++++++++++++++++++
...hBasedMultiFormatPropertySourceProvider.java | 125 ----------------
.../BaseSimpleFormatPropertySourceProvider.java | 68 ---------
.../tamaya/format/ConfigurationFormat.java | 6 +
.../tamaya/format/ConfigurationFormats.java | 27 +++-
.../format/formats/IniConfigurationFormat.java | 5 +
.../tamaya/format/formats/PropertiesFormat.java | 5 +
.../format/formats/PropertiesXmlFormat.java | 5 +
8 files changed, 195 insertions(+), 194 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b8aa9e8e/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java b/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
new file mode 100644
index 0000000..d70515d
--- /dev/null
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
@@ -0,0 +1,148 @@
+/*
+ * 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.format;
+
+import org.apache.tamaya.resource.ResourceResolver;
+import org.apache.tamaya.resource.Resources;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.io.IOException;
+import java.io.InputStream;
+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.Objects;
+import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Implementation of a {@link PropertySourceProvider} that reads configuration from some given resource paths
+ * and using the given formats. The resource path are resolved using the current
+ * {@link org.apache.tamaya.resource.ResourceResolver} active. For each resource found the configuration formats
+ * passed get a chance to read the resource, if they succeed the result is taken as the providers PropertySources
+ * to be exposed.
+ */
+public abstract class BaseFormatPropertySourceProvider implements PropertySourceProvider {
+ /**
+ * The logger used.
+ */
+ private static final Logger LOG = Logger.getLogger(BaseFormatPropertySourceProvider.class.getName());
+ /**
+ * The config formats supported for the given location/resource paths.
+ */
+ private List<ConfigurationFormat> configFormats = new ArrayList<>();
+ /**
+ * The paths to be evaluated.
+ */
+ private Collection<URL> paths = new ArrayList<>();
+ /**
+ * The ClassLoader to use.
+ */
+ private Optional<ClassLoader> classLoader;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param formats the formats to be used, not null, not empty.
+ * @param paths the paths to be resolved, not null, not empty.
+ */
+ public BaseFormatPropertySourceProvider(
+ List<ConfigurationFormat> formats,
+ URL... paths) {
+ this.configFormats.addAll(Objects.requireNonNull(formats));
+ this.paths.addAll(Arrays.asList(Objects.requireNonNull(paths)));
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param classLoader the ClassLoader to be used, not null, not empty.
+ * @param formats the formats to be used, not null, not empty.
+ * @param paths the paths to be resolved, not null, not empty.
+ */
+ public BaseFormatPropertySourceProvider(
+ List<ConfigurationFormat> formats,
+ ClassLoader classLoader, String... paths) {
+ this.configFormats.addAll(Objects.requireNonNull(formats));
+ for(String path:paths) {
+ Enumeration<URL> urls = null;
+ try {
+ urls = classLoader.getResources(path);
+ } catch (IOException e) {
+ LOG.log(Level.WARNING, e, () -> "Failed to read resource: " + path);
+ continue;
+ }
+ while(urls.hasMoreElements()) {
+ this.paths.add(urls.nextElement());
+ }
+ }
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param formats the formats to be used, not null, not empty.
+ * @param paths the paths to be resolved, not null, not empty.
+ */
+ public BaseFormatPropertySourceProvider(
+ ClassLoader classLoader,
+ List<ConfigurationFormat> formats, URL... paths) {
+ this.classLoader = Optional.ofNullable(classLoader);
+ this.configFormats.addAll(Objects.requireNonNull(formats));
+ this.paths.addAll(Arrays.asList(Objects.requireNonNull(paths)));
+ }
+
+ /**
+ * Method to create a {@link org.apache.tamaya.spi.PropertySource} based on the given entries read.
+ *
+ * @param data the configuration data, not null.
+ * @return the {@link org.apache.tamaya.spi.PropertySource} instance ready to be registered.
+ */
+ protected abstract Collection<PropertySource> getPropertySources(ConfigurationData data);
+
+ /**
+ * This method does dynamically resolve the paths using the current ClassLoader set. If no ClassLoader was
+ * explcitly set during creation the current Thread context ClassLoader is used. If none of the supported
+ * formats is able to parse a resource a WARNING log is written.
+ *
+ * @return the PropertySources successfully read
+ */
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ ResourceResolver resourceResolver = Resources.getResourceResolver();
+ List<PropertySource> propertySources = new ArrayList<>();
+ this.paths.forEach(res -> {
+ try(InputStream is = res.openStream()) {
+ for (ConfigurationFormat format : configFormats) {
+ ConfigurationData data = format.readConfiguration(res.toString(), is);
+ propertySources.addAll(getPropertySources(data));
+ }
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Failed to add resource based config: " + res, e);
+ }
+ });
+ return propertySources;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b8aa9e8e/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java b/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java
deleted file mode 100644
index 32b25fb..0000000
--- a/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java
+++ /dev/null
@@ -1,125 +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.format;
-
-import org.apache.tamaya.resource.ResourceResolver;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Implementation of a {@link PropertySourceProvider} that reads configuration from some given resource paths
- * and using the given formats. The resource path are resolved using the current
- * {@link org.apache.tamaya.resource.ResourceResolver} active. For each resource found the configuration formats
- * passed get a chance to read the resource, if they succeed the result is taken as the providers PropertySources
- * to be exposed.
- */
-public abstract class BasePathBasedMultiFormatPropertySourceProvider implements PropertySourceProvider {
- /**
- * The logger used.
- */
- private static final Logger LOG = Logger.getLogger(BasePathBasedMultiFormatPropertySourceProvider.class.getName());
- /**
- * The config formats supported for the given location/resource paths.
- */
- private List<ConfigurationFormat> configFormats = new ArrayList<>();
- /**
- * The paths to be evaluated.
- */
- private List<String> paths = new ArrayList<>();
- /**
- * The ClassLoader to use.
- */
- private Optional<ClassLoader> classLoader;
-
- /**
- * Creates a new instance.
- *
- * @param formats the formats to be used, not null, not empty.
- * @param paths the paths to be resolved, not null, not empty.
- */
- public BasePathBasedMultiFormatPropertySourceProvider(
- List<ConfigurationFormat> formats,
- String... paths) {
- this.configFormats.addAll(Objects.requireNonNull(formats));
- this.paths.addAll(Arrays.asList(Objects.requireNonNull(paths)));
- }
-
- /**
- * Creates a new instance.
- *
- * @param formats the formats to be used, not null, not empty.
- * @param paths the paths to be resolved, not null, not empty.
- */
- public BasePathBasedMultiFormatPropertySourceProvider(
- ClassLoader classLoader,
- List<ConfigurationFormat> formats, String... paths) {
- this.classLoader = Optional.ofNullable(classLoader);
- this.configFormats.addAll(Objects.requireNonNull(formats));
- this.paths.addAll(Arrays.asList(Objects.requireNonNull(paths)));
- }
-
- /**
- * Method to create a {@link org.apache.tamaya.spi.PropertySource} based on the given entries read.
- *
- * @param data the configuration data, not null.
- * @return the {@link org.apache.tamaya.spi.PropertySource} instance ready to be registered.
- */
- protected abstract Collection<PropertySource> getPropertySources(ConfigurationData data);
-
- /**
- * This method does dynamically resolve the paths using the current ClassLoader set. If no ClassLoader was
- * explcitly set during creation the current Thread context ClassLoader is used. If none of the supported
- * formats is able to parse a resource a WARNING log is written.
- *
- * @return the PropertySources successfully read
- */
- @Override
- public Collection<PropertySource> getPropertySources() {
- ResourceResolver resourceResolver = ServiceContext.getInstance().getService(ResourceResolver.class).get();
- List<PropertySource> propertySources = new ArrayList<>();
- paths.forEach((path) -> {
- for (URL res : resourceResolver.getResources(
- this.classLoader.orElse(Thread.currentThread().getContextClassLoader()),
- path)) {
- try(InputStream is = res.openStream()) {
- for (ConfigurationFormat format : configFormats) {
- ConfigurationData entries = format.readConfiguration(res.toString(), is);
- propertySources.addAll(getPropertySources(entries));
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Failed to add resource based config: " + res, e);
- }
- }
- });
- return propertySources;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b8aa9e8e/modules/formats/src/main/java/org/apache/tamaya/format/BaseSimpleFormatPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/BaseSimpleFormatPropertySourceProvider.java b/modules/formats/src/main/java/org/apache/tamaya/format/BaseSimpleFormatPropertySourceProvider.java
deleted file mode 100644
index 7401c8a..0000000
--- a/modules/formats/src/main/java/org/apache/tamaya/format/BaseSimpleFormatPropertySourceProvider.java
+++ /dev/null
@@ -1,68 +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.format;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.net.URL;
-import java.util.Collection;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Implementation of a {@link org.apache.tamaya.spi.PropertySourceProvider} that reads configuration from
- * a given resource and in a given format.
- */
-public abstract class BaseSimpleFormatPropertySourceProvider implements PropertySourceProvider {
- /**
- * The logger used.
- */
- private static final Logger LOG = Logger.getLogger(BaseSimpleFormatPropertySourceProvider.class.getName());
- /**
- * The config formats supported, not null.
- */
- private ConfigurationFormat configFormat;
- /**
- * The resource to be read, not null.
- */
- private URL resource;
-
- /**
- * Creates a new instance.
- *
- * @param format the formas to be used, not null.
- * @param resource the resource to be read, not null.
- */
- public BaseSimpleFormatPropertySourceProvider(
- ConfigurationFormat format,
- URL resource) {
- this.configFormat = Objects.requireNonNull(format);
- this.resource = Objects.requireNonNull(resource);
- }
-
- /**
- * Method to create a {@link org.apache.tamaya.spi.PropertySource} based on the given entries read.
- *
- * @param configData the config data read.
- * @return the {@link org.apache.tamaya.spi.PropertySource} instance ready to be registered.
- */
- protected abstract Collection<PropertySource> createPropertySourcea(ConfigurationData configData);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b8aa9e8e/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java
index b3c1717..dc3f588 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java
@@ -38,6 +38,12 @@ import java.net.URL;
public interface ConfigurationFormat {
/**
+ * Get a unique name of the format. This name can be used to access the format.
+ * @return
+ */
+ public String getName();
+
+ /**
* Allows the format to examine the given resource, e.g. for a matching file ending. Only, if a format accepts an
* URL, it will be tried for reading the configuration.
* @param url the url to read the configuration data from (could be a file, a remote location, a classpath
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b8aa9e8e/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
index 4c6f67f..84f9456 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
@@ -25,17 +25,22 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Objects;
+import java.util.Set;
+import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.stream.Collector;
import java.util.stream.Collectors;
/**
* Small accessor and management class dealing with {@link org.apache.tamaya.format.ConfigurationFormat}
* instances.
*/
-public class ConfigurationFormats {
+public final class ConfigurationFormats {
/**
* The logger used.
*/
@@ -61,6 +66,26 @@ public class ConfigurationFormats {
*
* @return the currently available formats, never null.
*/
+ public static List<ConfigurationFormat> getFormats(String... formatNames) {
+ Set<String> names = new HashSet<>(Arrays.asList(formatNames));
+ return getFormats(f -> names.contains(f));
+ }
+
+ /**
+ * Get all currently available formats, ordered by priority.
+ *
+ * @return the currently available formats, never null.
+ */
+ public static List<ConfigurationFormat> getFormats(Predicate<String> namePredicate) {
+ return getFormats().stream().filter(f -> namePredicate.test(f.getName()))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Get all currently available formats, ordered by priority.
+ *
+ * @return the currently available formats, never null.
+ */
public static List<ConfigurationFormat> getFormats(URL url) {
List<ConfigurationFormat> formats = getFormats();
return formats.stream().filter(f -> f.accepts(url)).collect(Collectors.toList());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b8aa9e8e/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
index 58ec3d7..f49f27a 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
@@ -41,6 +41,11 @@ public class IniConfigurationFormat implements ConfigurationFormat {
private final static Logger LOG = Logger.getLogger(IniConfigurationFormat.class.getName());
@Override
+ public String getName() {
+ return "ini";
+ }
+
+ @Override
public boolean accepts(URL url) {
String fileName = url.getFile();
return fileName.endsWith(".ini") || fileName.endsWith(".INI");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b8aa9e8e/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
index 99ec1cc..9d804d6 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
@@ -44,6 +44,11 @@ public class PropertiesFormat implements ConfigurationFormat {
@Override
+ public String getName() {
+ return "properties";
+ }
+
+ @Override
public boolean accepts(URL url) {
String fileName = url.getFile();
return fileName.endsWith(".properties") || fileName.endsWith(".PROPERTIES") ||
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b8aa9e8e/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
index 5130e3b..50cb966 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
@@ -42,6 +42,11 @@ public class PropertiesXmlFormat implements ConfigurationFormat {
private final static Logger LOG = Logger.getLogger(PropertiesXmlFormat.class.getName());
@Override
+ public String getName() {
+ return "xml-properties";
+ }
+
+ @Override
public boolean accepts(URL url) {
String fileName = url.getFile();
return fileName.endsWith(".xml") || fileName.endsWith(".XML");
[2/6] incubator-tamaya git commit: Fixed test bugs. Added default
method for ordinal evaluation.
Posted by an...@apache.org.
Fixed test bugs.
Added default method for ordinal evaluation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/3bd3fe71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/3bd3fe71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/3bd3fe71
Branch: refs/heads/master
Commit: 3bd3fe71dff5bdd015ebe81edd25c6d23fa8a662
Parents: b8aa9e8
Author: anatole <an...@apache.org>
Authored: Wed Mar 4 01:08:29 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Mar 4 01:08:29 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/Configuration.java | 21 ++++++++++++++++----
.../org/apache/tamaya/spi/PropertySource.java | 16 +++++++++++++--
.../org/apache/tamaya/ConfigurationTest.java | 8 +++++---
.../org/apache/tamaya/TestConfiguration.java | 4 ++--
4 files changed, 38 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3bd3fe71/java8/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/Configuration.java b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
index afaced9..468e9e1 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -67,6 +67,7 @@ public interface Configuration {
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
* @param type The target type required, not null.
+ * @param <T> the target type.
* @return the property value, never null..
* @throws ConfigException if the keys could not be converted to the required target type.
*/
@@ -82,6 +83,7 @@ public interface Configuration {
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
* @param type The target type required, not null.
+ * @param <T> the target type.
* @return the property value, or null, if the underlying value is null as well.
* @throws ConfigException if the value could not be converted to the required target type by any of the
* registered converters.
@@ -125,6 +127,7 @@ public interface Configuration {
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
* @param type The target type required, not null.
+ * @param <T> the target type.
* @return the property value, never null..
* @throws ConfigException if the keys could not be converted to the required target type.
*/
@@ -140,6 +143,7 @@ public interface Configuration {
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
* @param type The target type required, not null.
+ * @param <T> the target type.
* @return the property value, never null..
* @throws ConfigException if the keys could not be converted to the required target type.
*/
@@ -160,6 +164,7 @@ public interface Configuration {
* a/b/c/d.myProperty}.
* @param converter the PropertyConverter to perform the conversion fromMap
* {@link String} to {@code Class<T>}, not {@code null}.
+ * @param <T> the target type.
* @return the property's keys.
* @throws ConfigException if the keys could not be converted to the required target
* type, or no such property exists.
@@ -177,6 +182,9 @@ public interface Configuration {
* Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
* instances may not be contained in the result, but nevertheless be accessible calling one of the
* {@code get(...)} methods.
+ *
+ * @return the current properties. These may not include all properties from non-scannable
+ * {@link org.apache.tamaya.spi.PropertySource}s.
*/
@SuppressWarnings("JavaDoc")
Map<String, String> getProperties();
@@ -194,9 +202,11 @@ public interface Configuration {
* a/b/c/d.myProperty}.
* @param converter the PropertyConverter to perform the conversion fromMap
* {@link String} to {@code Class<T>}, not {@code null}.
+ * @param <T> the target type.
* @return the property's keys.
* @throws ConfigException if the keys could not be converted to the required target
* type, or no such property exists.
+ * @since Java8
*/
default <T> Optional<T> getOptional(String key, PropertyConverter<T> converter) {
Optional<String> value = getOptional(key);
@@ -214,11 +224,10 @@ public interface Configuration {
* a/b/c/d.myProperty}.
* @return the property's keys.
* @throws ConfigException if the configured value could not be converted to the target type.
+ * @since Java8
*/
- default Boolean getBoolean(String key) {
- Optional<Boolean> val = getOptional(key, Boolean.class);
-
- return val.orElse(null);
+ default Optional<Boolean> getBoolean(String key) {
+ return getOptional(key, Boolean.class);
}
/**
@@ -228,6 +237,7 @@ public interface Configuration {
* a/b/c/d.myProperty}.
* @return the property's keys.
* @throws ConfigException if the configured value could not be converted to the target type.
+ * @since Java8
*/
default OptionalInt getInteger(String key) {
Optional<Integer> val = getOptional(key, Integer.class);
@@ -245,6 +255,7 @@ public interface Configuration {
* a/b/c/d.myProperty}.
* @return the property's keys.
* @throws ConfigException if the configured value could not be converted to the target type.
+ * @since Java8
*/
default OptionalLong getLong(String key) {
Optional<Long> val = getOptional(key, Long.class);
@@ -261,6 +272,7 @@ public interface Configuration {
* a/b/c/d.myProperty}.
* @return the property's keys.
* @throws ConfigException if the configured value could not be converted to the target type.
+ * @since Java8
*/
default OptionalDouble getDouble(String key) {
@@ -286,6 +298,7 @@ public interface Configuration {
* Query a configuration.
*
* @param query the query, never {@code null}.
+ * @param <T> the target query result type.
* @return the result
*/
default <T> T query(ConfigQuery<T> query) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3bd3fe71/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
index 20e8b88..7212bd3 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -20,6 +20,8 @@ package org.apache.tamaya.spi;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
@@ -78,9 +80,19 @@ public interface PropertySource {
* config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
*
* @return the 'importance' aka ordinal of the configured values. The higher, the more important.
- * //X TODO think about making this a default method which returns default priority
*/
- int getOrdinal();
+ default int getOrdinal(){
+ String configuredOrdinal = get(TAMAYA_ORDINAL);
+ if(configuredOrdinal!=null){
+ try{
+ return Integer.parseInt(configuredOrdinal);
+ } catch(Exception e){
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, e,
+ () -> "Configured Ordinal is not an int number: " + configuredOrdinal);
+ }
+ }
+ return 0;
+ }
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3bd3fe71/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
index 28d25ba..240caf0 100644
--- a/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
+++ b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
@@ -39,9 +39,11 @@ public class ConfigurationTest {
@org.junit.Test
public void testGetBoolean() throws Exception {
- assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue"));
- assertFalse(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse"));
- assertFalse(ConfigurationProvider.getConfiguration().getBoolean("foorBar"));
+ assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue").isPresent());
+ assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse").isPresent());
+ assertFalse(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse").get());
+ assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue").get());
+ assertFalse(ConfigurationProvider.getConfiguration().getBoolean("fooBar").isPresent());
}
@org.junit.Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3bd3fe71/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
index 31500ae..ef7cccf 100644
--- a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -63,13 +63,13 @@ public class TestConfiguration implements Configuration {
} else if (type.getType().equals(Boolean.class)) {
if ("booleanTrue".equals(key)) {
return (T) (Object) Boolean.TRUE;
- } else {
+ } else if ("booleanFalse".equals(key)) {
return (T) (Object) Boolean.FALSE;
}
} else if (type.getType().equals(String.class)) {
return (T) (Object) "aStringValue";
}
- throw new ConfigException("No such property: " + key);
+ return null;
}
@Override
[6/6] incubator-tamaya git commit: Added further docs for resolver
module.
Posted by an...@apache.org.
Added further docs for resolver 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/d4141c1f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d4141c1f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d4141c1f
Branch: refs/heads/master
Commit: d4141c1ffc9fc1f8222feed10dc838bd32b4be38
Parents: a3c702e
Author: anatole <an...@apache.org>
Authored: Wed Mar 18 00:49:00 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Mar 18 00:49:00 2015 +0100
----------------------------------------------------------------------
docs/mod_resolver.adoc | 83 ++++++++++++++++++++++++++++++++++++++-------
1 file changed, 71 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d4141c1f/docs/mod_resolver.adoc
----------------------------------------------------------------------
diff --git a/docs/mod_resolver.adoc b/docs/mod_resolver.adoc
index 2b111b2..cf2ba08 100644
--- a/docs/mod_resolver.adoc
+++ b/docs/mod_resolver.adoc
@@ -14,10 +14,10 @@ Apache Tamaya -- Extension: Resolver
:website: http://tamaya.incubator.apache.org/
:iconsdir: {imagesdir}/icons
:toc:
-:toc-placement: manual
:icons:
:encoding: UTF-8
:numbered:
+
// 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
@@ -34,24 +34,83 @@ Apache Tamaya -- Extension: Resolver
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-'''
-
-<<<
-
-toc::[]
-<<<
-:numbered!:
-<<<
[[Core]]
-== Tamaya Events (Extension Module)
+== Tamaya Resolver (Extension Module)
+
=== Overview
Tamaya Resolver is an extension module. Refer to the link::modules.html[extensions documentation] for further details
about modules.
-Tamaya Events provides an abstraction for events like change events, when configuration has bee changed.
+Tamaya Resolver provides a dynamic resolution mechanism, which allows to use UNIX-styled (+${...}+ placeholder
+expressions in your configuration values. The resolver hereby supports transitive resolution and also prevents
+cycles to loop endlessly.
+
+=== Installation
+
+To benefit from dynamic value resolution you only must add the corresponding dependency to your module:
+
+[source, xml]
+===============================================
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-resolver</artifactId>
+ <version>...</version>
+</dependency>
+===============================================
+
+The module automatically registers an according +PropertyFilter+ that is automatically called, whenever a value
+is accessed.
+
+=== Available Resolvers
+
+Currently the module defined the following resolvers:
+
+.Available Resolvers
+|=======
+|_Expression_ |_Description_ |_Example_
+|+conf:<configKey>+ |Reads another configKey and replaces the expression with the value found. | conf-ref=${conf:anotherConf.entryKey}
+|+resource:<resourceRef>+ |Reads a resource from the current classpath and replaces the expression with the given text content. | cp-ref=${resource:Testresource.txt}
+|+file:<fileRef>+ |Reads a resource from the current classpath and replaces the expression with the given text content. | file-ref=${file:c:\myFile.txt}
+|+url:<url>+ |Reads an URL and replaces the expression with the given text content. | url-ref=${url:http://www.google.com}
+|=======
+
+=== SPI: Implementing your own Resolvers
+
+The module also provides an easy but powerful SPI for adding your own resolver implementations. Basically the
+first and most important thing to do is implementing the +ExpressionResolver+ interface:
+
+.Implementing a Custom Resolver
+[source, java]
+================================================================
+public class PwdDecrypter implements ExpressionResolver {
+
+ @Override
+ public String getResolverPrefix(){
+ return "decrypt:";
+ }
+
+ @Override
+ public String evaluate(String expression){
+ return decrypt(expression);
+ }
+
+ private String decrypt(String s){
+ ...
+ }
+}
+================================================================
+Basically that is all you must do, after having registered the class with the +ServiceLoader+ it will be found
+and loaded by the implementation. With that all expressions that start with the given prefix are passed to the
+resolver, so all the following expressions will be sent to the implementation:
+[source,listing]
+=============================================================================
+blabla ${decrypt:myname}
+blabla ${decrypt:myname} foo blabla ${decrypt:myname}
+=============================================================================
-tbc...
\ No newline at end of file
+Hereby evaluation is repeasted until no further change of values could be detetced. In case of a endless loop
+the evaluation is broken after a (configurable) number of cycles.
[4/6] incubator-tamaya git commit: Added Resource singleton. Added
test ps.
Posted by an...@apache.org.
Added Resource singleton.
Added test ps.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ded8115d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ded8115d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ded8115d
Branch: refs/heads/master
Commit: ded8115d83e7b51647c235ec17ce80f355443646
Parents: bc03d8c
Author: anatole <an...@apache.org>
Authored: Mon Mar 16 01:40:42 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 16 01:40:42 2015 +0100
----------------------------------------------------------------------
.../tamaya/resource/ResourceResolver.java | 11 ----
.../org/apache/tamaya/resource/Resources.java | 44 ++++++++++++++
.../PathBasedPropertySourceProvider.java | 64 ++++++++++++++++++++
3 files changed, 108 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ded8115d/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java b/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
index a5c491c..c150c4d 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
@@ -107,15 +107,4 @@ public interface ResourceResolver {
*/
Collection<URL> getResources(ClassLoader classLoader, Collection<String> expressions);
- /**
- * Access the current ResourceResolver.
- * @return the current ResourceResolver instance, never null.
- * @throws ConfigException, if no ResourceResolver is available (should not happen).
- */
- public static ResourceResolver getInstance(){
- return ServiceContext.getInstance().getService(ResourceResolver.class).orElseThrow(
- () -> new ConfigException("ResourceResolver not available.")
- );
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ded8115d/modules/resources/src/main/java/org/apache/tamaya/resource/Resources.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/Resources.java b/modules/resources/src/main/java/org/apache/tamaya/resource/Resources.java
new file mode 100644
index 0000000..b62a832
--- /dev/null
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/Resources.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.resource;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ServiceContext;
+
+/**
+ * Singleton Accessor for accessing the current {@link org.apache.tamaya.resource.ResourceResolver} instance.
+ */
+public final class Resources {
+
+ /**
+ * Singleton constructor.
+ */
+ private Resources(){}
+
+ /**
+ * Access the current ResourceResolver.
+ * @return the current ResourceResolver instance, never null.
+ * @throws org.apache.tamaya.ConfigException, if no ResourceResolver is available (should not happen).
+ */
+ public static ResourceResolver getResourceResolver(){
+ return ServiceContext.getInstance().getService(ResourceResolver.class).orElseThrow(
+ () -> new ConfigException("ResourceResolver not available.")
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ded8115d/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java b/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
new file mode 100644
index 0000000..423a115
--- /dev/null
+++ b/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
@@ -0,0 +1,64 @@
+package org.apache.tamaya.resource.internal;
+
+import org.apache.tamaya.resource.Resources;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Created by Anatole on 03.03.2015.
+ */
+public class PathBasedPropertySourceProvider implements PropertySourceProvider{
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ List<PropertySource> propertySources = new ArrayList<>();
+ Collection<URL> resources = Resources.getResourceResolver().getResources("META-INF/cfg/**/*.properties");
+ for(URL url:resources){
+ Properties props = new Properties();
+ try(InputStream is = url.openStream()){
+ props.load(is);
+ propertySources.add(new PropertiesBasedPropertySource(url.toString(), props));
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ return propertySources;
+ }
+
+
+ private final static class PropertiesBasedPropertySource implements PropertySource{
+
+ private String name;
+ private Map<String,String> properties = new HashMap<>();
+
+ public PropertiesBasedPropertySource(String name, Properties props) {
+ this.name = name;
+ props.forEach((k,v) -> this.properties.put(k.toString(), v.toString()));
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String get(String key) {
+ return properties.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+ }
+}
[5/6] incubator-tamaya git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-tamaya
Posted by an...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-tamaya
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a3c702e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a3c702e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a3c702e2
Branch: refs/heads/master
Commit: a3c702e2b94e56aa9094f97695eb3d6574ec8fe0
Parents: ded8115 ff3faca
Author: anatole <an...@apache.org>
Authored: Mon Mar 16 01:43:29 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 16 01:43:29 2015 +0100
----------------------------------------------------------------------
docs/misc/examples.adoc | 76 ++
docs/misc/examples.adocoff | 76 --
docs/mod_builder.adoc | 50 ++
docs/modules.adoc | 1 +
.../converters/LocalDateConverterTest.java | 41 +
modules/builder/pom.xml | 14 +
.../tamaya/builder/ConfigurationBuilder.java | 580 ++++++++++++
.../ProgrammaticConfigurationContext.java | 406 +++++++++
.../org/apache/tamaya/builder/package-info.java | 28 +
.../modules/builder/ConfigurationBuilder.java | 251 ------
.../ProgrammaticConfigurationContext.java | 406 ---------
.../builder/ConfigurationBuilderTest.java | 896 +++++++++++++++++++
.../builder/TestNonSPIPropertyFilterA.java | 34 +
.../builder/TestNonSPIPropertyFilterB.java | 34 +
.../tamaya/builder/TestPropertyFilter.java | 34 +
.../tamaya/builder/TestPropertySource.java | 58 ++
.../builder/TestPropertySourceProvider.java | 89 ++
.../builder/TestPropertySourceProviderB.java | 89 ++
.../builder/util/mockito/NotMockedAnswer.java | 55 ++
.../tamaya/builder/util/types/CustomTypeA.java | 34 +
.../tamaya/builder/util/types/CustomTypeB.java | 39 +
.../tamaya/builder/util/types/CustomTypeC.java | 36 +
.../types/CustomTypeCPropertyConverter.java | 28 +
.../builder/ConfigurationBuilderTest.java | 762 ----------------
.../builder/TestNonSPIPropertyFilterA.java | 34 -
.../builder/TestNonSPIPropertyFilterB.java | 34 -
.../modules/builder/TestPropertyFilter.java | 34 -
.../modules/builder/TestPropertySource.java | 58 --
.../builder/TestPropertySourceProvider.java | 89 --
.../builder/TestPropertySourceProviderB.java | 89 --
.../builder/util/mockito/NotMockedAnswer.java | 55 --
.../modules/builder/util/types/CustomTypeA.java | 34 -
.../modules/builder/util/types/CustomTypeB.java | 39 -
.../modules/builder/util/types/CustomTypeC.java | 36 -
.../types/CustomTypeCPropertyConverter.java | 28 -
.../org.apache.tamaya.PropertyConverter | 2 +-
.../org.apache.tamaya.spi.PropertyFilter | 2 +-
.../org.apache.tamaya.spi.PropertySource | 2 +-
...org.apache.tamaya.spi.PropertySourceProvider | 2 +-
.../test/resources/configfiles/json/first.json | 4 +
.../test/resources/configfiles/json/second.json | 4 +
.../test/resources/configfiles/json/simple.json | 4 +
.../test/resources/configfiles/json/third.json | 4 +
.../test/resources/configfiles/other/simple.oml | 19 +
.../tamaya/json/JSONConfigurationFormat.java | 42 +
.../java/org/apache/tamaya/json/JSONFormat.java | 71 ++
.../apache/tamaya/json/JSONPropertySource.java | 199 ++++
.../tamaya/json/JSONPropertySourceProvider.java | 64 ++
.../org/apache/tamaya/json/JSONVisitor.java | 107 +++
.../modules/json/JSONConfigurationFormat.java | 42 -
.../apache/tamaya/modules/json/JSONFormat.java | 71 --
.../tamaya/modules/json/JSONPropertySource.java | 199 ----
.../json/JSONPropertySourceProvider.java | 64 --
.../apache/tamaya/modules/json/JSONVisitor.java | 107 ---
...org.apache.tamaya.format.ConfigurationFormat | 2 +-
.../json/CommonJSONTestCaseCollection.java | 173 ++++
.../tamaya/json/ConfigurationDataUCD.java | 44 +
.../org/apache/tamaya/json/JSONFormatIT.java | 47 +
.../org/apache/tamaya/json/JSONFormatTest.java | 75 ++
...pertySourceProviderExistingConfigFileIT.java | 87 ++
...opertySourceProviderMissingConfigFileIT.java | 69 ++
.../tamaya/json/JSONPropertySourceTest.java | 49 +
.../tamaya/json/JSONPropertySourceUCD.java | 39 +
.../apache/tamaya/json/UnifiedConfigData.java | 32 +
.../json/CommonJSONTestCaseCollection.java | 173 ----
.../modules/json/ConfigurationDataUCD.java | 44 -
.../tamaya/modules/json/JSONFormatIT.java | 47 -
.../tamaya/modules/json/JSONFormatTest.java | 75 --
...pertySourceProviderExistingConfigFileIT.java | 87 --
...opertySourceProviderMissingConfigFileIT.java | 69 --
.../modules/json/JSONPropertySourceTest.java | 49 -
.../modules/json/JSONPropertySourceUCD.java | 39 -
.../tamaya/modules/json/UnifiedConfigData.java | 32 -
pom.xml | 12 +-
74 files changed, 3768 insertions(+), 3132 deletions(-)
----------------------------------------------------------------------
[3/6] incubator-tamaya git commit: Added Resolver singleton.
Posted by an...@apache.org.
Added Resolver singleton.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/bc03d8c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/bc03d8c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/bc03d8c4
Branch: refs/heads/master
Commit: bc03d8c42c2e5a2b55c0f8cbf2308f04dffcdf22
Parents: 3bd3fe7
Author: anatole <an...@apache.org>
Authored: Mon Mar 16 01:39:13 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 16 01:39:13 2015 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/resolver/Resolver.java | 54 ++++++++++++++++++++
1 file changed, 54 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc03d8c4/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
new file mode 100644
index 0000000..39844f9
--- /dev/null
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.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 org.apache.tamaya.resolver;
+
+import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * Resolver singleton.
+ */
+public final class Resolver {
+
+ /**
+ * Singleton constructor.
+ */
+ private Resolver(){}
+
+ /**
+ * Evaluates the current expression.
+ * @param key the key, not null.
+ * @param value the value to be filtered/evaluated.
+ * @return the filtered/evaluated value, including null.
+ */
+ public static String evaluateExpression(String key, String value){
+ return ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class).get()
+ .evaluateExpression(key, value);
+ }
+
+ /**
+ * Evaluates the current expression.
+ * @param value the value to be filtered/evaluated.
+ * @return the filtered/evaluated value, including null.
+ */
+ public static String evaluateExpression(String value){
+ return ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class).get()
+ .evaluateExpression(null, value);
+ }
+}