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 2014/12/27 02:13:55 UTC
[1/5] incubator-tamaya git commit: Made DynamicValue a class.similar
to Optional, but serializable.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 702156cd9 -> 784884c79
Made DynamicValue a class.similar to Optional, but serializable.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/9bd9e0dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/9bd9e0dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/9bd9e0dd
Branch: refs/heads/master
Commit: 9bd9e0dd3e5d93d75987a8c15bb56e2e02b92d7e
Parents: 33be3a1
Author: anatole <an...@apache.org>
Authored: Fri Dec 26 14:10:17 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Fri Dec 26 14:10:17 2014 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/ConfiguredValue.java | 256 -----------
.../java/org/apache/tamaya/DynamicValue.java | 425 +++++++++++++++++++
2 files changed, 425 insertions(+), 256 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bd9e0dd/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfiguredValue.java b/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
deleted file mode 100644
index e75cd51..0000000
--- a/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();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bd9e0dd/api/src/main/java/org/apache/tamaya/DynamicValue.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/DynamicValue.java b/api/src/main/java/org/apache/tamaya/DynamicValue.java
new file mode 100644
index 0000000..150586f
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/DynamicValue.java
@@ -0,0 +1,425 @@
+/*
+ * 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 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 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 #update
+ of #updateAndGet 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
+ }
+
+
+ /**
+ * Converts this value to an {@link java.util.Optional} instance.
+ * @return an {@link java.util.Optional} instance, never null.
+ */
+ private UpdatePolicy updatePolicy = UpdatePolicy.NEVER;
+ private transient Optional<T> value;
+ private transient PropertyChangeEvent newValue;
+ private transient WeakList<Consumer<PropertyChangeEvent>> listeners;
+
+ public static final DynamicValue EMPTY = new DynamicValue(null);
+
+ /**
+ * 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() {
+ DynamicValue v = (DynamicValue<T>) EMPTY;
+ return v;
+ }
+
+ private DynamicValue(Optional<T> item){
+ this.value = item;
+ }
+
+ public static <T> DynamicValue<T> of(T instance){
+ return new DynamicValue(Optional.of(instance));
+ }
+
+ public static <T> DynamicValue<T> ofNullable(T value){
+ return value == null ? empty() : of(value);
+ }
+
+ /**
+ * Performs an update, 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 updateAndGet(){
+ update();
+ return get();
+ }
+
+ /**
+ * Accepts a new value based on the instance's settings. On change any registered listeners will be triggered.
+ */
+ public void update(){
+ synchronized (value){
+ if(newValue!=null){
+ value = Optional.ofNullable((T)newValue.getNewValue());
+ PropertyChangeEvent evt = 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 discardChange(){
+ newValue = null;
+ }
+
+
+
+ /**
+ * Access the {@link UpdatePolicy} used for updating this value.
+ * @return the load policy, never null.
+ */
+ public UpdatePolicy getUpdatePolicy() {
+ return updatePolicy;
+ }
+
+ /**
+ * Add a listener to be called, when this value is 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 is 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(String propertyName, T newValue){
+ switch(this.updatePolicy){
+ case IMMEDIATE:
+ this.newValue = new PropertyChangeEvent(this, propertyName, value.orElse(null), newValue);
+ update();
+ break;
+ case EXPLCIT:
+ this.newValue = new PropertyChangeEvent(this, propertyName, value.orElse(null), 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;
+ }
+
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * 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();
+ else {
+ return DynamicValue.ofNullable(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();
+ 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);
+ }
+
+ public Optional<T> toOptional(){
+ return value;
+ }
+
+ private void writeObject(ObjectOutputStream oos)throws IOException {
+ oos.writeObject(updatePolicy);
+ if(isPresent()) {
+ oos.writeObject(this.value.get());
+ }
+ else{
+ oos.writeObject(null);
+ }
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ this.updatePolicy = (UpdatePolicy)ois.readObject();
+ if(isPresent()) {
+ this.value = Optional.of((T) ois.readObject());
+ }
+ newValue = null;
+ }
+
+
+ private class WeakList<T>{
+ List<WeakReference<T>> refs = new LinkedList<>();
+
+ void add(T t){
+ refs.add(new WeakReference(t));
+ }
+
+ 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;
+ }
+ }
+ }
+ }
+
+
+ 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;
+ }
+ }
+ }
+
+}
[5/5] 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/784884c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/784884c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/784884c7
Branch: refs/heads/master
Commit: 784884c79d4aa18f427e2278a85682b69301ad43
Parents: b7a49a4 702156c
Author: anatole <an...@apache.org>
Authored: Sat Dec 27 02:13:09 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Dec 27 02:13:09 2014 +0100
----------------------------------------------------------------------
modules/integration/pom.xml | 24 +++++++++-
modules/integration/se/pom.xml | 71 ++++++++++++++++++++++++++++
modules/metamodels/environment/pom.xml | 73 +++++++++++++++++++++++++++++
modules/pom.xml | 2 +-
pom.xml | 6 ++-
5 files changed, 171 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
[2/5] incubator-tamaya git commit: TAMAYA-19: Separated config from
property source.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
index e2d1759..db4a7c7 100644
--- a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentApplicationEnvironmentProvider.java
@@ -31,7 +31,7 @@ import java.util.logging.Logger;
import org.apache.tamaya.core.config.ConfigurationFormats;
import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.core.resource.ResourceLoader;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
import org.apache.tamaya.spi.ServiceContext;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
index 6f05466..2ef88ec 100644
--- a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/ClassLoaderDependentEarEnvironmentProvider.java
@@ -23,7 +23,7 @@ import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.metamodel.environment.EnvironmentBuilder;
import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
index d0def60..e943971 100644
--- a/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
+++ b/modules/metamodels/environment/src/main/java/org/apache/tamaya/metamodel/environment/internal/SystemClassLoaderEnvironmentProvider.java
@@ -22,7 +22,7 @@ import org.apache.tamaya.core.config.ConfigurationFormats;
import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.metamodel.environment.spi.EnvironmentProvider;
import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
[4/5] incubator-tamaya git commit: TAMAYA-19: Separated config from
property source.
Posted by an...@apache.org.
TAMAYA-19: Separated config from property source.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b7a49a41
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b7a49a41
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b7a49a41
Branch: refs/heads/master
Commit: b7a49a41d032f3665e3b61d809aa4a6e51094491
Parents: 9bd9e0d
Author: anatole <an...@apache.org>
Authored: Sat Dec 27 02:10:31 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Dec 27 02:10:31 2014 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/ConfigQuery.java | 37 --
.../java/org/apache/tamaya/Configuration.java | 134 ++++++-
.../java/org/apache/tamaya/DynamicValue.java | 153 ++++++--
.../org/apache/tamaya/PropertyMapSupplier.java | 37 ++
.../java/org/apache/tamaya/PropertySource.java | 61 +--
.../tamaya/spi/ConfigurationFactorySpi.java | 60 +++
.../org/apache/tamaya/spi/ConfigurationSpi.java | 4 +
.../org/apache/tamaya/spi/ServiceContext.java | 14 +
.../tamaya/core/ConfigurationFunctions.java | 213 +++++++++++
.../core/config/AbstractConfiguration.java | 55 ---
.../tamaya/core/config/ConfigFunctions.java | 238 ------------
.../core/config/ConfigurationBuilder.java | 374 -------------------
.../tamaya/core/config/ConfigurationFormat.java | 111 ------
.../core/config/FreezedConfiguration.java | 81 ----
.../tamaya/core/config/MappedConfiguration.java | 56 ---
.../apache/tamaya/core/internal/MetaConfig.java | 2 +-
.../config/DefaultConfigurationSpi.java | 9 +-
.../config/EnvPropertiesConfigProvider.java | 2 +-
.../config/FallbackSimpleConfigProvider.java | 4 +-
.../internal/config/FileChangeListener.java | 6 +-
.../internal/config/FileChangeObserver.java | 2 +-
.../core/internal/config/FileConfiguration.java | 2 +-
.../config/FilesPropertiesConfigProvider.java | 2 +-
.../config/SystemPropertiesConfigProvider.java | 2 +-
.../format/DefaultConfigurationFormatSpi.java | 2 +-
.../tamaya/core/internal/format/IniFormat.java | 2 +-
.../core/internal/format/PropertiesFormat.java | 2 +-
.../internal/format/PropertiesXmlFormat.java | 2 +-
.../inject/ConfigChangeCallbackMethod.java | 8 +-
.../internal/inject/ConfiguredSetterMethod.java | 4 +-
.../core/internal/inject/ConfiguredType.java | 4 +-
.../inject/WeakConfigListenerManager.java | 11 +-
.../properties/AggregatedPropertySource.java | 1 -
.../core/properties/ConfigurationFormat.java | 111 ++++++
.../properties/ContextualPropertySource.java | 1 -
.../properties/DelegatingPropertySource.java | 1 -
.../core/properties/FilteredPropertySource.java | 1 -
.../core/properties/FrozenPropertySource.java | 80 ++++
.../core/properties/MappedPropertySource.java | 53 +++
.../properties/PathBasedPropertySource.java | 1 -
.../core/properties/PropertyChangeSet.java | 169 +++++++++
.../properties/PropertyChangeSetBuilder.java | 347 +++++++++++++++++
.../properties/PropertySourceFunctions.java | 65 ++++
.../properties/ReplacingPropertySource.java | 1 -
.../core/properties/URLBasedPropertySource.java | 1 -
.../tamaya/core/resource/ResourceLoader.java | 8 +-
.../tamaya/core/spi/ConfigurationFormatSpi.java | 8 +-
...pache.tamaya.core.config.ConfigurationFormat | 21 --
...e.tamaya.core.properties.ConfigurationFormat | 21 ++
.../java/org/apache/tamaya/JavaOneDemo.java | 18 +-
.../internal/MutableTestConfigProvider.java | 183 +++++----
.../tamaya/internal/TestConfigProvider.java | 5 +-
.../samples/annotations/AutoConfiguredTest.java | 4 +-
.../simple/SimplePropertiesAndCLISample.java | 18 +-
.../apache/tamaya/ucs/UC1ReadProperties.java | 12 +-
.../tamaya/ucs/deltaspike/ConfigFiltering.java | 5 +-
...che.tamaya.core.spi.ConfigurationProviderSpi | 3 +-
...DependentApplicationEnvironmentProvider.java | 2 +-
...ssLoaderDependentEarEnvironmentProvider.java | 2 +-
.../SystemClassLoaderEnvironmentProvider.java | 2 +-
60 files changed, 1599 insertions(+), 1239 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/api/src/main/java/org/apache/tamaya/ConfigQuery.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigQuery.java b/api/src/main/java/org/apache/tamaya/ConfigQuery.java
deleted file mode 100644
index 58d8742..0000000
--- a/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/b7a49a41/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Configuration.java b/api/src/main/java/org/apache/tamaya/Configuration.java
index 8254e3a..fa61447 100644
--- a/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -18,10 +18,12 @@
*/
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationFactorySpi;
import org.apache.tamaya.spi.ConfigurationSpi;
import org.apache.tamaya.spi.ServiceContext;
import java.util.*;
+import java.util.function.Function;
import java.util.function.UnaryOperator;
/**
@@ -41,7 +43,69 @@ import java.util.function.UnaryOperator;
* simplifying the development current this interface, e.g. for being backed up by systems and stores that are not part current
* this library at all.
*/
-public interface Configuration extends PropertySource {
+public interface Configuration extends PropertyMapSupplier {
+
+ /**
+ * An empty and immutable Configuration instance.
+ */
+ public static final Configuration EMPTY_CONFIGURATION = new Configuration() {
+
+ @Override
+ public String getName() {
+ return "<empty>";
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return Optional.empty();
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public String toString(){
+ return "PropertySource [name=<empty>]";
+ }
+ };
+
+ /**
+ * Get the name of the property source. The name should be unique for the type of source, whereas the id is used
+ * to ensure unique identity, either locally or remotely.
+ * @return the configuration's name, never null.
+ */
+ String getName();
+
+ /**
+ * Access a property.
+ *
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ Optional<String> get(String key);
+
+ /**
+ * Determines if this config source should be scanned for its list of properties.
+ *
+ * Generally, slow ConfigSources should return false here.
+ *
+ * @return true if this ConfigSource should be scanned for its list of properties,
+ * false if it should not be scanned.
+ */
+ default boolean isScannable(){
+ return true;
+ }
+
+ /**
+ * Allows to quickly check, if a provider is empty.
+ *
+ * @return true, if the provier is empty.
+ */
+ default boolean isEmpty() {
+ return getProperties().isEmpty();
+ }
/**
* Get the property keys as {@link Boolean}.
@@ -49,6 +113,7 @@ public interface Configuration extends PropertySource {
* @param key the property's absolute, or relative path, e.g. {@code
* a/b/c/d.myProperty}.
* @return the property's keys.
+ * @throws ConfigException if the configured value could not be converted to the target type.
*/
default Boolean getBoolean(String key) {
Optional<Boolean> val = get(key, Boolean.class);
@@ -64,6 +129,7 @@ public interface Configuration extends PropertySource {
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
* @return the property's keys.
+ * @throws ConfigException if the configured value could not be converted to the target type.
*/
default OptionalInt getInteger(String key){
Optional<Integer> val = get(key, Integer.class);
@@ -80,6 +146,7 @@ public interface Configuration extends PropertySource {
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
* @return the property's keys.
+ * @throws ConfigException if the configured value could not be converted to the target type.
*/
default OptionalLong getLong(String key){
Optional<Long> val = get(key, Long.class);
@@ -96,7 +163,7 @@ public interface Configuration extends PropertySource {
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
* @return the property's keys.
- * @throws IllegalArgumentException if no such property exists.
+ * @throws ConfigException if the configured value could not be converted to the target type.
*/
default OptionalDouble getDouble(String key){
@@ -122,7 +189,7 @@ public interface Configuration extends PropertySource {
* @param adapter the PropertyAdapter to perform the conversion fromMap
* {@link String} to {@code Class<T>}, not {@code null}.
* @return the property's keys.
- * @throws IllegalArgumentException if the keys could not be converted to the required target
+ * @throws ConfigException if the keys could not be converted to the required target
* type, or no such property exists.
*/
default <T> Optional<T> getAdapted(String key, PropertyAdapter<T> adapter){
@@ -133,6 +200,31 @@ public interface Configuration extends PropertySource {
return Optional.empty();
}
+// /**
+// * Get the property with the given key as type {@code Class<T>}.
+// * <p>
+// * If {@code Class<T>} is not one current
+// * {@code Boolean, Short, Integer, Long, Float, Double, BigInteger,
+// * BigDecimal, String} , an according adapter must be
+// * available to perform the conversion from {@link String} to
+// * {@code Class<T>}.
+// *
+// * @param key the property's absolute, or relative path, e.g. {@code
+// * a/b/c/d.myProperty}.
+// * @param adapter the PropertyAdapter to perform the conversion from
+// * {@link String} to {@code Class<T>}, not {@code null}.
+// * @return the property value, never null.
+// * @throws ConfigException if the keys could not be converted to the required target
+// * type, or no such property exists.
+// */
+// default <T> DynamicValue<T> getAdaptedDynamicValue(String key, PropertyAdapter<T> adapter){
+// Optional<String> value = get(key);
+// if(value.isPresent()) {
+// return DynamicValue.ofNullable(getName()+':' + key, adapter.adapt(value.get()));
+// }
+// return DynamicValue.empty(getName()+':' + key);
+// }
+
/**
* Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -142,14 +234,29 @@ public interface Configuration extends PropertySource {
* @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.
- * @return the property's keys.
- * @throws IllegalArgumentException if the keys could not be converted to the required target
+ * @return the property value, never null..
+ * @throws ConfigException if the keys could not be converted to the required target
* type.
*/
default <T> Optional<T> get(String key, Class<T> type){
return getAdapted(key, PropertyAdapter.getInstance(type));
}
+// /**
+// * Get the property value as {@link org.apache.tamaya.DynamicValue}. This will implicitly require a corresponding {@link
+// * PropertyAdapter} that is capable of converting the String value to the current required type T.
+// *
+// * @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.
+// * @return the dynamic value instance, never null.
+// * @throws ConfigException if the keys could not be converted to the required target
+// * type.
+// */
+// default <T> DynamicValue<T> getDynamicValue(String key, Class<T> type){
+// return getAdaptedDynamicValue(key, PropertyAdapter.getInstance(type));
+// }
+
/**
* Extension point for adjusting configuration.
*
@@ -161,14 +268,15 @@ public interface Configuration extends PropertySource {
return operator.apply(this);
}
+
/**
- * Query some keys fromMap a configuration.
+ * Query a configuration.
*
* @param query the query, never {@code null}.
* @return the result
*/
- default <T> T query(ConfigQuery<T> query){
- return query.query(this);
+ default <T> T query(Function<Configuration,T> query){
+ return query.apply(this);
}
@@ -183,6 +291,16 @@ public interface Configuration extends PropertySource {
}
/**
+ * Creates a configuration from a {@link org.apache.tamaya.PropertySource}.
+ *
+ * @param propertySource the property source
+ * @return the corresponding Configuration instance, never null.
+ */
+ public static Configuration from(PropertySource propertySource){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFactorySpi.class, () -> new ConfigurationFactorySpi(){}).from(propertySource);
+ }
+
+ /**
* Access a configuration by name.
*
* @param name the configuration's name, not null, not empty.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/api/src/main/java/org/apache/tamaya/DynamicValue.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/DynamicValue.java b/api/src/main/java/org/apache/tamaya/DynamicValue.java
index 150586f..b8e0cf5 100644
--- a/api/src/main/java/org/apache/tamaya/DynamicValue.java
+++ b/api/src/main/java/org/apache/tamaya/DynamicValue.java
@@ -32,13 +32,14 @@ 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 be reinjected, reconfigured or
- * final.
- * <h3>Implementation Requirements</h3>
- * Instances of this class must be
+ * 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</li>
- * <li>Immutable</li>
+ * <li>Serializable, when also the item stored is serializable</li>
* <li>Thread safe</li>
* </ul>
*/
@@ -50,8 +51,8 @@ public final class DynamicValue<T> implements Serializable{
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 #update
- of #updateAndGet are required to accept the change and inform the listeners about the change.
+ /** 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,
/**
@@ -65,17 +66,19 @@ public final class DynamicValue<T> implements Serializable{
}
+ /** The property name of the entry. */
+ private String propertyName;
/**
- * Converts this value to an {@link java.util.Optional} instance.
- * @return an {@link java.util.Optional} instance, never null.
+ * 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;
- private transient PropertyChangeEvent newValue;
+ /** The new value, or null. */
+ private transient Optional<T> newValue;
+ /** List of listeners that listen for changes. */
private transient WeakList<Consumer<PropertyChangeEvent>> listeners;
- public static final DynamicValue EMPTY = new DynamicValue(null);
-
/**
* Returns an empty {@code Optional} instance. No value is present for this
* Optional.
@@ -88,25 +91,45 @@ public final class DynamicValue<T> implements Serializable{
* @param <T> Type of the non-existent value
* @return an empty {@code Optional}
*/
- public static <T> DynamicValue<T> empty() {
- DynamicValue v = (DynamicValue<T>) EMPTY;
+ public static <T> DynamicValue<T> empty(String propertyName) {
+ DynamicValue v = new DynamicValue<T>(propertyName, null);
return v;
}
- private DynamicValue(Optional<T> item){
+ /**
+ * 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;
}
- public static <T> DynamicValue<T> of(T instance){
- return new DynamicValue(Optional.of(instance));
+ /**
+ * 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));
}
- public static <T> DynamicValue<T> ofNullable(T value){
- return value == null ? empty() : 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 an update, if necessary and returns the current 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}
@@ -114,19 +137,19 @@ public final class DynamicValue<T> implements Serializable{
*
* @see DynamicValue#isPresent()
*/
- public T updateAndGet(){
- update();
+ public T commitAndGet(){
+ commit();
return get();
}
/**
- * Accepts a new value based on the instance's settings. On change any registered listeners will be triggered.
+ * 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 update(){
+ public void commit(){
synchronized (value){
if(newValue!=null){
- value = Optional.ofNullable((T)newValue.getNewValue());
- PropertyChangeEvent evt = newValue;
+ 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);
@@ -138,7 +161,7 @@ public final class DynamicValue<T> implements Serializable{
/**
* Discards a new value that was published. No listeners will be informed.
*/
- public void discardChange(){
+ public void discard(){
newValue = null;
}
@@ -146,14 +169,14 @@ public final class DynamicValue<T> implements Serializable{
/**
* Access the {@link UpdatePolicy} used for updating this value.
- * @return the load policy, never null.
+ * @return the update policy, never null.
*/
public UpdatePolicy getUpdatePolicy() {
return updatePolicy;
}
/**
- * Add a listener to be called, when this value is changed.
+ * 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) {
@@ -164,7 +187,7 @@ public final class DynamicValue<T> implements Serializable{
}
/**
- * Removes a listener to be called, when this value is changed.
+ * 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) {
@@ -191,14 +214,14 @@ public final class DynamicValue<T> implements Serializable{
* 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(String propertyName, T newValue){
+ public void setNewValue(T newValue){
switch(this.updatePolicy){
case IMMEDIATE:
- this.newValue = new PropertyChangeEvent(this, propertyName, value.orElse(null), newValue);
- update();
+ this.newValue = Optional.ofNullable(newValue);
+ commit();
break;
case EXPLCIT:
- this.newValue = new PropertyChangeEvent(this, propertyName, value.orElse(null), newValue);
+ this.newValue = Optional.ofNullable(newValue);
break;
case LOG_AND_DISCARD:
Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", newValue="+newValue);
@@ -212,6 +235,26 @@ public final class DynamicValue<T> implements Serializable{
}
/**
+ * 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}
@@ -248,7 +291,7 @@ public final class DynamicValue<T> implements Serializable{
if (!isPresent())
return this;
else
- return predicate.test(value.get()) ? this : empty();
+ return predicate.test(value.get()) ? this : empty(propertyName);
}
/**
@@ -283,9 +326,9 @@ public final class DynamicValue<T> implements Serializable{
public <U> DynamicValue<U> map(Function<? super T, ? extends U> mapper) {
Objects.requireNonNull(mapper);
if (!isPresent())
- return empty();
+ return empty(propertyName);
else {
- return DynamicValue.ofNullable(mapper.apply(value.get()));
+ return DynamicValue.ofNullable(propertyName, mapper.apply(value.get()));
}
}
@@ -309,7 +352,7 @@ public final class DynamicValue<T> implements Serializable{
public <U> DynamicValue<U> flatMap(Function<? super T, DynamicValue<U>> mapper) {
Objects.requireNonNull(mapper);
if (!isPresent())
- return empty();
+ return empty(propertyName);
else {
return Objects.requireNonNull(mapper.apply(value.get()));
}
@@ -360,10 +403,19 @@ public final class DynamicValue<T> implements Serializable{
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()) {
@@ -374,6 +426,12 @@ public final class DynamicValue<T> implements Serializable{
}
}
+ /**
+ * 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()) {
@@ -383,13 +441,26 @@ public final class DynamicValue<T> implements Serializable{
}
+ /**
+ * 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();){
@@ -404,6 +475,10 @@ public final class DynamicValue<T> implements Serializable{
}
+ /**
+ * 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<>();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/api/src/main/java/org/apache/tamaya/PropertyMapSupplier.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/PropertyMapSupplier.java b/api/src/main/java/org/apache/tamaya/PropertyMapSupplier.java
new file mode 100644
index 0000000..69dd308
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/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/b7a49a41/api/src/main/java/org/apache/tamaya/PropertySource.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/PropertySource.java b/api/src/main/java/org/apache/tamaya/PropertySource.java
index d0c5bc1..f4b01ae 100644
--- a/api/src/main/java/org/apache/tamaya/PropertySource.java
+++ b/api/src/main/java/org/apache/tamaya/PropertySource.java
@@ -19,6 +19,8 @@
package org.apache.tamaya;
import java.util.*;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
/**
* This interface models a provider that serves configuration properties. The contained
@@ -38,7 +40,7 @@ import java.util.*;
* </ul>
* </p>
*/
-public interface PropertySource {
+public interface PropertySource extends PropertyMapSupplier {
/**
* An empty and immutable PropertyProvider instance.
@@ -82,14 +84,6 @@ public interface PropertySource {
Optional<String> get(String key);
/**
- * 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();
-
- /**
* Determines if this config source should be scanned for its list of properties.
*
* Generally, slow ConfigSources should return false here.
@@ -111,42 +105,25 @@ public interface PropertySource {
}
/**
- * Convert the this PropertyProvider instance to a {@link org.apache.tamaya.Configuration}.
+ * Extension point for adjusting property sources.
*
- * @return the configuration, never null.
+ * @param operator A property source operator, e.g. a filter, or an adjuster
+ * combining property sources.
+ * @return the new adjusted property source, never {@code null}.
*/
- default Configuration toConfiguration() {
- return new Configuration() {
- @Override
- public String getName() {
- return PropertySource.this.getName();
- }
-
- @Override
- public boolean isScannable() {
- return PropertySource.this.isScannable();
- }
-
- @Override
- public boolean isEmpty() {
- return PropertySource.this.isEmpty();
- }
-
- @Override
- public Optional<String> get(String key) {
- return PropertySource.this.get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return PropertySource.this.getProperties();
- }
+ default PropertySource with(UnaryOperator<PropertySource> operator){
+ return operator.apply(this);
+ }
- @Override
- public String toString() {
- return "Configuration [name: " + getName() + "]";
- }
- };
+ /**
+ * Query something from a property source.
+ *
+ * @param query the query, never {@code null}.
+ * @return the result
+ */
+ default <T> T query(Function<PropertySource, T> query){
+ return query.apply(this);
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/api/src/main/java/org/apache/tamaya/spi/ConfigurationFactorySpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationFactorySpi.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationFactorySpi.java
new file mode 100644
index 0000000..3b167cc
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/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/b7a49a41/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
index b3f1094..5891dc2 100644
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
+++ b/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
@@ -20,8 +20,12 @@ 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
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java b/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
index aeacade..a2e127e 100644
--- a/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
+++ b/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
+import java.util.function.Supplier;
/**
* This class models the component that is managing the lifecycle current the
@@ -40,6 +41,19 @@ public interface ServiceContext {
return getService(serviceType)
.orElseThrow(() -> new IllegalStateException("Singleton missing: " + serviceType.getName()));
}
+
+ /**
+ * Delegate method for {@link ServiceContext#getService(Class)}.
+ *
+ * @param serviceType the service type.
+ * @return the service found, never {@code null}.
+ * @see ServiceContext#getService(Class)
+ */
+ default <T> T getSingleton(Class<T> serviceType, Supplier<T> defaultSupplier) {
+ return getService(serviceType)
+ .orElse((defaultSupplier.get()));
+ }
+
/**
* Access a singleton, given its type.
*
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/ConfigurationFunctions.java b/core/src/main/java/org/apache/tamaya/core/ConfigurationFunctions.java
new file mode 100644
index 0000000..b1c2522
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/ConfigurationFunctions.java
@@ -0,0 +1,213 @@
+/*
+ * 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.apache.tamaya.core.properties.PropertySourceBuilder;
+
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+import java.util.stream.Collectors;
+
+/**
+ * Accessor that provides useful functions along with configuration.
+ */
+public final class ConfigurationFunctions {
+ /**
+ * Private singleton constructor.
+ */
+ private ConfigurationFunctions() {
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (non recursive). Hereby
+ * the area key is stripped away fromMap the resulting key.
+ *
+ * @param areaKey the area key, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static UnaryOperator<Configuration> selectArea(String areaKey) {
+ return selectArea(areaKey, true);
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (non recursive).
+ *
+ * @param areaKey the area key, not null
+ * @param stripKeys if set to true, the area key is stripped away fromMap the resulting key.
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static UnaryOperator<Configuration> selectArea(String areaKey, boolean stripKeys) {
+ return config -> {
+ Map<String, String> area = new HashMap<>();
+ area.putAll(
+ config.getProperties().entrySet().stream()
+ .filter(e -> isKeyInArea(e.getKey(), areaKey))
+ .collect(Collectors.toMap(
+ e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
+ Map.Entry::getValue)));
+ return Configuration.from(PropertySourceBuilder.of("area: " + areaKey).addMap(area).build());
+ };
+ }
+
+ /**
+ * Calculates the current area key and compares it with the given key.
+ *
+ * @param key the fully qualified entry key, not null
+ * @param areaKey the area key, not null
+ * @return true, if the entry is exact in this area
+ */
+ public static boolean isKeyInArea(String key, String areaKey) {
+ int lastIndex = key.lastIndexOf('.');
+ String curAreaKey = lastIndex > 0 ? key.substring(0, lastIndex) : "";
+ return curAreaKey.equals(areaKey);
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualifies area names. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @return s set with all areas, never {@code null}.
+ */
+ public static Function<Configuration,Set<String>> getAreas() {
+ return config -> {
+ final Set<String> areas = new HashSet<>();
+ config.getProperties().keySet().forEach(s -> {
+ int index = s.lastIndexOf('.');
+ if (index > 0) {
+ areas.add(s.substring(0, index));
+ } else {
+ areas.add("<root>");
+ }
+ });
+ return areas;
+ };
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing the transitive closure also including all
+ * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate
+ * as possible, but may not provide a complete set of areas that are finally accessible, especially when the
+ * underlying storage does not support key iteration.
+ *
+ * @return s set with all transitive areas, never {@code null}.
+ */
+ public static Function<Configuration,Set<String>> getTransitiveAreas() {
+ return config -> {
+ final Set<String> transitiveAreas = new HashSet<>();
+ config.query(getAreas()).forEach(s -> {
+ int index = s.lastIndexOf('.');
+ if (index < 0) {
+ transitiveAreas.add("<root>");
+ } else {
+ while (index > 0) {
+ s = s.substring(0, index);
+ transitiveAreas.add(s);
+ index = s.lastIndexOf('.');
+ }
+ }
+ });
+ return transitiveAreas;
+ };
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing only the
+ * areas that match the predicate and have properties attached. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
+ * @return s set with all areas, never {@code null}.
+ */
+ public static Function<Configuration,Set<String>> getAreas(final Predicate<String> predicate) {
+ return config -> {
+ return config.query(getAreas()).stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
+ };
+ }
+
+ /**
+ * Return a query to evaluate the set with all fully qualified area names, containing the transitive closure also including all
+ * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate as possible,
+ * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
+ * does not support key iteration.
+ *
+ * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
+ * @return s set with all transitive areas, never {@code null}.
+ */
+ public static Function<Configuration,Set<String>> getTransitiveAreas(Predicate<String> predicate) {
+ return config -> {
+ return config.query(getTransitiveAreas()).stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
+ };
+ }
+
+ /**
+ * Return a query to evaluate to evaluate if an area exists. In case where the underlying storage implementation does not allow
+ * querying the keys available, {@code false} should be returned.
+ *
+ * @param areaKey the configuration area (sub)path.
+ * @return {@code true}, if such a node exists.
+ */
+ public static Function<Configuration,Boolean> containsArea(String areaKey) {
+ return config -> {
+ return config.query(getAreas()).contains(areaKey);
+ };
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (recursive). Hereby
+ * the area key is stripped away fromMap the resulting key.
+ *
+ * @param areaKey the area key, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static UnaryOperator<Configuration> selectAreaRecursive(String areaKey) {
+ return selectAreaRecursive(areaKey, true);
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (recursive).
+ *
+ * @param areaKey the area key, not null
+ * @param stripKeys if set to true, the area key is stripped away fromMap the resulting key.
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static UnaryOperator<Configuration> selectAreaRecursive(String areaKey, boolean stripKeys) {
+ return config -> {
+ Map<String, String> area = new HashMap<>();
+ String lookupKey = areaKey + '.';
+ area.putAll(
+ config.getProperties().entrySet().stream()
+ .filter(e -> e.getKey().startsWith(lookupKey))
+ .collect(Collectors.toMap(
+ e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
+ Map.Entry::getValue)));
+ return Configuration.from(PropertySourceBuilder.of("area (recursive): " + areaKey).addMap(area).build());
+ };
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
deleted file mode 100644
index 31179cd..0000000
--- a/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.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.config;
-
-import java.util.Optional;
-
-import org.apache.tamaya.*;
-import org.apache.tamaya.core.properties.AbstractPropertySource;
-import org.apache.tamaya.core.spi.PropertyAdapterProviderSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-/**
- * Abstract implementation class for {@link org.apache.tamaya.Configuration}, which supports optimistic
- * locking and mutability.
- */
-public abstract class AbstractConfiguration extends AbstractPropertySource implements Configuration{
-
- private static final long serialVersionUID = 503764580971917964L;
-
- private final Object LOCK = new Object();
-
- protected AbstractConfiguration(String name){
- super(name);
- }
-
-
- @Override
- public <T> Optional<T> get(String key, Class<T> type){
- PropertyAdapterProviderSpi as = ServiceContext.getInstance().getSingleton(PropertyAdapterProviderSpi.class);
- PropertyAdapter<T> adapter = as.getPropertyAdapter(type);
- if(adapter == null){
- throw new ConfigException(
- "Can not adapt config property '" + key + "' to " + type.getName() + ": no such " +
- "adapter.");
- }
- return getAdapted(key, adapter);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
deleted file mode 100644
index c1a2518..0000000
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
+++ /dev/null
@@ -1,238 +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.ConfigQuery;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.properties.PropertySourceBuilder;
-
-import java.util.*;
-import java.util.function.Predicate;
-import java.util.function.UnaryOperator;
-import java.util.stream.Collectors;
-
-/**
- * Accessor that provides useful functions along with configuration.
- */
-public final class ConfigFunctions {
- /**
- * Private singleton constructor.
- */
- private ConfigFunctions() {
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (non recursive). Hereby
- * the area key is stripped away fromMap the resulting key.
- *
- * @param areaKey the area key, not null
- * @return the area configuration, with the areaKey stripped away.
- */
- public static UnaryOperator<Configuration> selectArea(String areaKey) {
- return selectArea(areaKey, true);
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (non recursive).
- *
- * @param areaKey the area key, not null
- * @param stripKeys if set to true, the area key is stripped away fromMap the resulting key.
- * @return the area configuration, with the areaKey stripped away.
- */
- public static UnaryOperator<Configuration> selectArea(String areaKey, boolean stripKeys) {
- return config -> {
- Map<String, String> area = new HashMap<>();
- area.putAll(
- config.getProperties().entrySet().stream()
- .filter(e -> isKeyInArea(e.getKey(), areaKey))
- .collect(Collectors.toMap(
- e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
- Map.Entry::getValue)));
- return PropertySourceBuilder.of("area: " + areaKey).addMap(area).build().toConfiguration();
- };
- }
-
- /**
- * Calculates the current area key and compares it with the given key.
- *
- * @param key the fully qualified entry key, not null
- * @param areaKey the area key, not null
- * @return true, if the entry is exact in this area
- */
- public static boolean isKeyInArea(String key, String areaKey) {
- int lastIndex = key.lastIndexOf('.');
- String curAreaKey = lastIndex > 0 ? key.substring(0, lastIndex) : "";
- return curAreaKey.equals(areaKey);
- }
-
- /**
- * Return a query to evaluate the set with all fully qualifies area names. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @return s set with all areas, never {@code null}.
- */
- public static ConfigQuery<Set<String>> getAreas() {
- return config -> {
- final Set<String> areas = new HashSet<>();
- config.getProperties().keySet().forEach(s -> {
- int index = s.lastIndexOf('.');
- if (index > 0) {
- areas.add(s.substring(0, index));
- } else {
- areas.add("<root>");
- }
- });
- return areas;
- };
- }
-
- /**
- * Return a query to evaluate the set with all fully qualified area names, containing the transitive closure also including all
- * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate
- * as possible, but may not provide a complete set of areas that are finally accessible, especially when the
- * underlying storage does not support key iteration.
- *
- * @return s set with all transitive areas, never {@code null}.
- */
- public static ConfigQuery<Set<String>> getTransitiveAreas() {
- return config -> {
- final Set<String> transitiveAreas = new HashSet<>();
- config.query(getAreas()).forEach(s -> {
- int index = s.lastIndexOf('.');
- if (index < 0) {
- transitiveAreas.add("<root>");
- } else {
- while (index > 0) {
- s = s.substring(0, index);
- transitiveAreas.add(s);
- index = s.lastIndexOf('.');
- }
- }
- });
- return transitiveAreas;
- };
- }
-
- /**
- * Return a query to evaluate the set with all fully qualified area names, containing only the
- * areas that match the predicate and have properties attached. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
- * @return s set with all areas, never {@code null}.
- */
- public static ConfigQuery<Set<String>> getAreas(final Predicate<String> predicate) {
- return config -> {
- return config.query(getAreas()).stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
- };
- }
-
- /**
- * Return a query to evaluate the set with all fully qualified area names, containing the transitive closure also including all
- * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
- * @return s set with all transitive areas, never {@code null}.
- */
- public static ConfigQuery<Set<String>> getTransitiveAreas(Predicate<String> predicate) {
- return config -> {
- return config.query(getTransitiveAreas()).stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
- };
- }
-
- /**
- * Return a query to evaluate to evaluate if an area exists. In case where the underlying storage implementation does not allow
- * querying the keys available, {@code false} should be returned.
- *
- * @param areaKey the configuration area (sub)path.
- * @return {@code true}, if such a node exists.
- */
- public static ConfigQuery<Boolean> containsArea(String areaKey) {
- return config -> {
- return config.query(getAreas()).contains(areaKey);
- };
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (recursive). Hereby
- * the area key is stripped away fromMap the resulting key.
- *
- * @param areaKey the area key, not null
- * @return the area configuration, with the areaKey stripped away.
- */
- public static UnaryOperator<Configuration> selectAreaRecursive(String areaKey) {
- return selectAreaRecursive(areaKey, true);
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (recursive).
- *
- * @param areaKey the area key, not null
- * @param stripKeys if set to true, the area key is stripped away fromMap the resulting key.
- * @return the area configuration, with the areaKey stripped away.
- */
- public static UnaryOperator<Configuration> selectAreaRecursive(String areaKey, boolean stripKeys) {
- return config -> {
- Map<String, String> area = new HashMap<>();
- String lookupKey = areaKey + '.';
- area.putAll(
- config.getProperties().entrySet().stream()
- .filter(e -> e.getKey().startsWith(lookupKey))
- .collect(Collectors.toMap(
- e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
- Map.Entry::getValue)));
- return PropertySourceBuilder.of("area (recursive): " + areaKey).addMap(area).build().toConfiguration();
- };
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (non recursive). Hereby
- * the area key is stripped away fromMap the resulting key.
- *
- * @param areaKey the area key, not null
- * @param mappedAreaKey the target key, not null
- * @return the area configuration, with the areaKey stripped away.
- */
- public static UnaryOperator<Configuration> mapArea(String areaKey, String mappedAreaKey) {
- return mapKeys(key -> key.startsWith(areaKey + '.') ?
- mappedAreaKey + key.substring(areaKey.length()) : key);
- }
-
- /**
- * Creates a {@link UnaryOperator} that creates a {@link org.apache.tamaya.Configuration} that maps any keys as
- * defined by the {@code keyMapper} given. If the {@code keyMapper} returns
- * {@code null} for a keys, it is removed from the resulting map.
- *
- * @param keyMapper the key mapper, not null
- * @return the area configuration, with the areaKey stripped away.
- */
- public static UnaryOperator<Configuration> mapKeys(UnaryOperator<String> keyMapper) {
- return (c) -> new MappedConfiguration(c, keyMapper);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
deleted file mode 100644
index f8b1c95..0000000
--- a/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/b7a49a41/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormat.java
deleted file mode 100644
index 8feaf6a..0000000
--- a/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/b7a49a41/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
deleted file mode 100644
index 43d6957..0000000
--- a/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/b7a49a41/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
deleted file mode 100644
index 736b33e..0000000
--- a/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/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java b/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
index 4b3511f..8d3ad15 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/MetaConfig.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.core.internal;
import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
[3/5] incubator-tamaya git commit: TAMAYA-19: Separated config from
property source.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
index 0417f35..8b7180c 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
@@ -23,15 +23,12 @@ import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Consumer;
-import org.apache.tamaya.core.config.ConfigChangeSet;
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.internal.inject.WeakConfigListenerManager;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
import org.apache.tamaya.core.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.ConfigurationSpi;
@@ -59,8 +56,10 @@ public class DefaultConfigurationSpi implements ConfigurationSpi {
}
public DefaultConfigurationSpi() {
- for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
- configProviders.put(spi.getConfigName(), spi);
+ if(configProviders.isEmpty()) {
+ for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
+ configProviders.put(spi.getConfigName(), spi);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
index 1494e7a..6fd4672 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
@@ -34,7 +34,7 @@ public class EnvPropertiesConfigProvider implements ConfigurationProviderSpi{
private Configuration envConfig;
public EnvPropertiesConfigProvider(){
- envConfig = PropertySourceBuilder.of("environment.properties").addEnvironmentProperties().build().toConfiguration();
+ envConfig = Configuration.from(PropertySourceBuilder.of("environment.properties").addEnvironmentProperties().build());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
index 7f997e5..7bcfb77 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
@@ -43,7 +43,7 @@ public class FallbackSimpleConfigProvider implements ConfigurationProviderSpi {
@Override
public void reload() {
- this.configuration =
+ this.configuration = Configuration.from(
PropertySourceBuilder.of(DEFAULT_CONFIG_NAME)
.addProviders(PropertySourceBuilder.of("CL default")
.withAggregationPolicy(AggregationPolicy.LOG_ERROR)
@@ -55,6 +55,6 @@ public class FallbackSimpleConfigProvider implements ConfigurationProviderSpi {
.build())
.addSystemProperties()
.addEnvironmentProperties()
- .build().toConfiguration();
+ .build());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
index 94e6694..afd1199 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
@@ -20,11 +20,11 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
/**
- * Class that has the responsibility to watch the folder and then update the {@link ConfigurationProviderSpi}
- * to update the Configuration from the properties or xml files, another ones will be ignored.
+ * Class that has the responsibility to watch the folder and then commit the {@link ConfigurationProviderSpi}
+ * to commit the Configuration from the properties or xml files, another ones will be ignored.
* @see FilesPropertiesConfigProvider
* This listener will wait to events and wait to one second to watch again.
- * <p>If new file was created or modified will update from this file.</p>
+ * <p>If new file was created or modified will commit from this file.</p>
* <p>If a file was removed then the listener will load using all files left.</p>
* @author otaviojava
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java
index e4fc95d..a7d4ba9 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java
@@ -3,7 +3,7 @@ package org.apache.tamaya.core.internal.config;
import java.util.Map;
/**
- * Observer to be used in {@link FileChangeListener} to update all configurations and provider.
+ * Observer to be used in {@link FileChangeListener} to commit all configurations and provider.
* @author otaviojava
*/
interface FileChangeObserver {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
index 8286768..4f76180 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
@@ -8,7 +8,7 @@ import org.apache.tamaya.Configuration;
/**
* Implementation of Configuration which the information is from xml or properties files.
- * Once the File modified, it will update automatically by provider.
+ * Once the File modified, it will commit automatically by provider.
* @see FilesPropertiesConfigProvider
* @see FileChangeObserver
* @author otaviojava
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
index 5cd1a93..c2cf7fa 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
@@ -19,7 +19,7 @@ import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
/**
* This implementation run in a folder and once found xml and properties files
- * will create the Configuration, when one file is created, deleted or modified the configuration will update
+ * will create the Configuration, when one file is created, deleted or modified the configuration will commit
* automatically.
* The default folder is META-INF/configuration, but you can change using the absolute path in
* "-Dtamaya.configbase" parameter.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
index 4f42b95..cdd90b2 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
@@ -34,7 +34,7 @@ public class SystemPropertiesConfigProvider implements ConfigurationProviderSpi{
private Configuration systemConfig;
public SystemPropertiesConfigProvider(){
- systemConfig = PropertySourceBuilder.of("system.properties").addSystemProperties().build().toConfiguration();
+ systemConfig = Configuration.from(PropertySourceBuilder.of("system.properties").addSystemProperties().build());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
index eb776bc..eac0a3b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.format;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.spi.ConfigurationFormatSpi;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
index ac17d91..85ce778 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.format;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.ConfigException;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
index d360dae..10355ef 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
@@ -26,7 +26,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
public class PropertiesFormat implements ConfigurationFormat{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
index 7b9b459..660c092 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.format;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import java.io.InputStream;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
index 554981b..f929f8e 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.inject;
-import org.apache.tamaya.core.config.ConfigChangeSet;
+import org.apache.tamaya.core.properties.PropertyChangeSet;
import org.apache.tamaya.Configuration;
import java.lang.reflect.Method;
@@ -41,10 +41,10 @@ public final class ConfigChangeCallbackMethod {
this.callbackMethod = Optional.of(callbackMethod).filter(
(m) -> void.class.equals(m.getReturnType()) &&
m.getParameterCount() == 1 &&
- m.getParameterTypes()[0].equals(ConfigChangeSet.class)).get();
+ m.getParameterTypes()[0].equals(PropertyChangeSet.class)).get();
}
- public Consumer<ConfigChangeSet> createConsumer(Object instance, Configuration... configurations){
+ public Consumer<PropertyChangeSet> createConsumer(Object instance, Configuration... configurations){
// TODO consider also environment !
return event -> {
for(Configuration cfg:configurations){
@@ -56,7 +56,7 @@ public final class ConfigChangeCallbackMethod {
};
}
- public void call(Object instance, ConfigChangeSet configChangeEvent) {
+ public void call(Object instance, PropertyChangeSet configChangeEvent) {
try {
callbackMethod.setAccessible(true);
callbackMethod.invoke(instance, configChangeEvent);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
index 57b83a9..90497ae 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
@@ -24,7 +24,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
-import org.apache.tamaya.core.config.ConfigChangeSet;
+import org.apache.tamaya.core.properties.PropertyChangeSet;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.annotation.*;
@@ -53,7 +53,7 @@ public class ConfiguredSetterMethod {
m.getParameterCount() == 1).get();
}
- public Consumer<ConfigChangeSet> createConsumer(Object instance, Configuration... configurations){
+ public Consumer<PropertyChangeSet> createConsumer(Object instance, Configuration... configurations){
// TODO consider environment as well
return event -> {
for(Configuration cfg:configurations){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
index 20b97c8..879d54a 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
@@ -22,7 +22,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
-import org.apache.tamaya.core.config.ConfigChangeSet;
+import org.apache.tamaya.core.properties.PropertyChangeSet;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.PropertySource;
@@ -134,7 +134,7 @@ public class ConfiguredType {
if (m.getParameterTypes().length != 1) {
return;
}
- if (!m.getParameterTypes()[0].equals(ConfigChangeSet.class)) {
+ if (!m.getParameterTypes()[0].equals(PropertyChangeSet.class)) {
return;
}
if (!void.class.equals(m.getReturnType())) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
index 7bf85bd..e9b9ec3 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
@@ -18,7 +18,8 @@
*/
package org.apache.tamaya.core.internal.inject;
-import org.apache.tamaya.core.config.ConfigChangeSet;
+import org.apache.tamaya.core.properties.PropertyChangeSet;
+
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.locks.Lock;
@@ -36,7 +37,7 @@ public final class WeakConfigListenerManager{
private static final Logger LOG = Logger.getLogger(WeakConfigListenerManager.class.getName());
private StampedLock lock = new StampedLock();
- private Map<Object,Consumer<ConfigChangeSet>> listenerReferences = new WeakHashMap<>();
+ private Map<Object,Consumer<PropertyChangeSet>> listenerReferences = new WeakHashMap<>();
/** Private singleton constructor. */
private WeakConfigListenerManager(){}
@@ -51,11 +52,11 @@ public final class WeakConfigListenerManager{
* @param instance the instance, not null.
* @param listener the consumer.
*/
- public void registerConsumer(Object instance, Consumer<ConfigChangeSet> listener){
+ public void registerConsumer(Object instance, Consumer<PropertyChangeSet> listener){
Lock writeLock = lock.asWriteLock();
try {
writeLock.lock();
- Consumer<ConfigChangeSet> l = listenerReferences.get(instance);
+ Consumer<PropertyChangeSet> l = listenerReferences.get(instance);
if (l == null) {
listenerReferences.put(instance, listener);
} else {
@@ -86,7 +87,7 @@ public final class WeakConfigListenerManager{
* Publishes a change event to all consumers registered.
* @param change the change event, not null.
*/
- public void publishChangeEvent(ConfigChangeSet change){
+ public void publishChangeEvent(PropertyChangeSet change){
Lock readLock = lock.asReadLock();
try{
readLock.lock();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
index 420246b..14ea651 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java b/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java
new file mode 100644
index 0000000..cf94d99
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.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.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/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
index e64cf07..6290706 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
index e06f08d..c4bfc92 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.core.properties;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import org.apache.tamaya.PropertySource;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
index a780bcd..a0c1a53 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.core.properties;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import org.apache.tamaya.PropertySource;
import java.util.HashMap;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
new file mode 100644
index 0000000..743655e
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.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 org.apache.tamaya.core.properties;
+
+import org.apache.tamaya.*;
+
+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 FrozenPropertySource extends AbstractPropertySource implements Serializable{
+ private static final long serialVersionUID = -6373137316556444171L;
+
+ private PropertySource properties;
+
+ /**
+ * Constructor.
+ * @param config The base configuration.
+ */
+ private FrozenPropertySource(PropertySource config){
+ super(config.getName());
+ this.properties = PropertySourceBuilder.of(config).buildFrozen();
+ }
+
+ public static final PropertySource of(PropertySource config){
+ if(config instanceof FrozenPropertySource){
+ return config;
+ }
+ return new FrozenPropertySource(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;
+
+ FrozenPropertySource that = (FrozenPropertySource) 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/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
new file mode 100644
index 0000000..160d6c4
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
@@ -0,0 +1,53 @@
+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/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
index 56426ca..80184d1 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
@@ -21,7 +21,6 @@ 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.config.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java
new file mode 100644
index 0000000..3cf6b31
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/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/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java
new file mode 100644
index 0000000..b6e22f8
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/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/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
new file mode 100644
index 0000000..5fcf895
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
@@ -0,0 +1,65 @@
+/*
+ * 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.function.Function;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+import java.util.stream.Collectors;
+
+/**
+ * Accessor that provides useful functions along with configuration.
+ */
+public final class PropertySourceFunctions {
+ /**
+ * Private singleton constructor.
+ */
+ private PropertySourceFunctions() {
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (non recursive). Hereby
+ * the area key is stripped away fromMap the resulting key.
+ *
+ * @param areaKey the area key, not null
+ * @param mappedAreaKey the target key, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static UnaryOperator<PropertySource> mapArea(String areaKey, String mappedAreaKey) {
+ return mapKeys(key -> key.startsWith(areaKey + '.') ?
+ mappedAreaKey + key.substring(areaKey.length()) : key);
+ }
+
+ /**
+ * Creates a {@link java.util.function.UnaryOperator} that creates a {@link org.apache.tamaya.Configuration} that maps any keys as
+ * defined by the {@code keyMapper} given. If the {@code keyMapper} returns
+ * {@code null} for a keys, it is removed from the resulting map.
+ *
+ * @param keyMapper the key mapper, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static UnaryOperator<PropertySource> mapKeys(UnaryOperator<String> keyMapper) {
+ return (c) -> new MappedPropertySource(c, keyMapper);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
index 69bbb79..85100e3 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.core.properties;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import org.apache.tamaya.PropertySource;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
index 1d79537..f690ef9 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
@@ -21,7 +21,6 @@ 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 org.apache.tamaya.core.config.ConfigurationFormat;
import java.net.URL;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
index 52e6f47..1c55e55 100644
--- a/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
+++ b/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
@@ -46,7 +46,7 @@ public interface ResourceLoader{
*
* @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.config.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
* .
*/
List<Resource> getResources(String... expressions);
@@ -56,7 +56,7 @@ public interface ResourceLoader{
*
* @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.config.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
* .
*/
List<Resource> getResources(Collection<String> expressions);
@@ -66,7 +66,7 @@ public interface ResourceLoader{
*
* @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.config.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
* .
*/
List<Resource> getResources(ClassLoader classLoader, String... expressions);
@@ -76,7 +76,7 @@ public interface ResourceLoader{
*
* @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.config.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
* .
*/
List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java b/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
index 7df988b..1c41820 100644
--- a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.spi;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.Resource;
import java.util.Collection;
@@ -28,16 +28,16 @@ import java.util.Collection;
*/
public interface ConfigurationFormatSpi {
/**
- * Access a {@link org.apache.tamaya.core.config.ConfigurationFormat}.
+ * Access a {@link org.apache.tamaya.core.properties.ConfigurationFormat}.
*
* @param formatName the format name
- * @return the corresponding {@link org.apache.tamaya.core.config.ConfigurationFormat}, or {@code null}, if
+ * @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.config.ConfigurationFormat} instances.
+ * 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.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat
deleted file mode 100644
index 7aa2407..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.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/b7a49a41/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat
new file mode 100644
index 0000000..7aa2407
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.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/b7a49a41/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/JavaOneDemo.java b/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
index e4c93ef..77cbf94 100644
--- a/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
+++ b/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.Map;
-import org.apache.tamaya.core.config.ConfigFunctions;
+import org.apache.tamaya.core.ConfigurationFunctions;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
@@ -53,22 +53,22 @@ public class JavaOneDemo {
Map<String, String> cfgMap = new HashMap<>();
cfgMap.put("param1", "value1");
cfgMap.put("a", "Adrian"); // overrides Anatole
- Configuration config = PropertySourceBuilder.of("myTestConfig").addPaths(
+ Configuration config = Configuration.from(PropertySourceBuilder.of("myTestConfig").addPaths(
"classpath:test.properties").addPaths("classpath:cfg/test.xml")
.addArgs(new String[]{"-arg1", "--fullarg", "fullValue", "-myflag"})
- .addMap(cfgMap).build().toConfiguration();
- System.out.println(config.query(ConfigFunctions.getAreas()));
+ .addMap(cfgMap).build());
+ System.out.println(config.query(ConfigurationFunctions.getAreas()));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getAreas(s -> s.startsWith("another"))));
+ System.out.println(config.query(ConfigurationFunctions.getAreas(s -> s.startsWith("another"))));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getTransitiveAreas()));
+ System.out.println(config.query(ConfigurationFunctions.getTransitiveAreas()));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
+ System.out.println(config.query(ConfigurationFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
System.out.println("---");
System.out.println(config);
System.out.print("--- b=");
System.out.println(config.get("b"));
- System.out.println("--- only a,b,c)");
- System.out.println(PropertySourceBuilder.of(config).filter((f) -> f.equals("a") || f.equals("b") || f.equals("c")).build());
+// System.out.println("--- only a,b,c)");
+// System.out.println(PropertySourceBuilder.of(config).filter((f) -> f.equals("a") || f.equals("b") || f.equals("c")).build());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
index 4a5bfe7..bf8d709 100644
--- a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
+++ b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
@@ -1,93 +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.internal;
-
-import java.beans.PropertyChangeEvent;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.tamaya.core.config.ConfigChangeSet;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.config.AbstractConfiguration;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
-
-/**
- * Simple test provider that creates a mutable instance of a configuration, just using a simple map instance.
- */
-public class MutableTestConfigProvider implements ConfigurationProviderSpi{
- /** The config name. */
- private static final String CONFIG_NAME = "mutableTestConfig";
- /** The config provided. */
- private MutableConfiguration testConfig;
-
- /**
- * COnsatructor.
- */
- public MutableTestConfigProvider(){
- Map<String, String> dataMap = new HashMap<>();
- dataMap.put("dad", "Anatole");
- dataMap.put("mom", "Sabine");
- dataMap.put("sons.1", "Robin");
- dataMap.put("sons.2", "Luke");
- dataMap.put("sons.3", "Benjamin");
-// PropertySource provider = PropertySourceBuilder.of(CONFIG_NAME).addMap(dataMap).build();
- testConfig = new MutableConfiguration(dataMap, CONFIG_NAME);
- }
-
- @Override
- public String getConfigName(){
- return CONFIG_NAME;
- }
-
- @Override
- public Configuration getConfiguration(){
- return testConfig;
- }
-
- @Override
- public void reload() {
-
- }
-
- /**
- * Implements a simple mutable config based on a Mao instance.
- */
- private final class MutableConfiguration extends AbstractConfiguration{
-
- private static final long serialVersionUID = 8811989470609598218L;
- private final Map<String,String> data = new ConcurrentHashMap<>();
-
- MutableConfiguration(Map<String,String> data, String name){
- super(name);
- this.data.putAll(data);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.unmodifiableMap(data);
- }
-
- @Override
- public Configuration toConfiguration(){
- return this;
- }
- }
-}
+///*
+// * 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.internal;
+//
+//import java.util.Collections;
+//import java.util.HashMap;
+//import java.util.Map;
+//import java.util.concurrent.ConcurrentHashMap;
+//
+//import org.apache.tamaya.Configuration;
+//import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+//
+///**
+// * Simple test provider that creates a mutable instance of a configuration, just using a simple map instance.
+// */
+//public class MutableTestConfigProvider implements ConfigurationProviderSpi{
+// /** The config name. */
+// private static final String CONFIG_NAME = "mutableTestConfig";
+// /** The config provided. */
+// private MutableConfiguration testConfig;
+//
+// /**
+// * COnsatructor.
+// */
+// public MutableTestConfigProvider(){
+// Map<String, String> dataMap = new HashMap<>();
+// dataMap.put("dad", "Anatole");
+// dataMap.put("mom", "Sabine");
+// dataMap.put("sons.1", "Robin");
+// dataMap.put("sons.2", "Luke");
+// dataMap.put("sons.3", "Benjamin");
+//// PropertySource provider = PropertySourceBuilder.of(CONFIG_NAME).addMap(dataMap).build();
+// testConfig = new MutableConfiguration(dataMap, CONFIG_NAME);
+// }
+//
+// @Override
+// public String getConfigName(){
+// return CONFIG_NAME;
+// }
+//
+// @Override
+// public Configuration getConfiguration(){
+// return testConfig;
+// }
+//
+// @Override
+// public void reload() {
+//
+// }
+//
+// /**
+// * Implements a simple mutable config based on a Mao instance.
+// */
+// private final class MutableConfiguration extends AbstractConfiguration{
+//
+// private static final long serialVersionUID = 8811989470609598218L;
+// private final Map<String,String> data = new ConcurrentHashMap<>();
+//
+// MutableConfiguration(Map<String,String> data, String name){
+// super(name);
+// this.data.putAll(data);
+// }
+//
+// @Override
+// public Map<String, String> getProperties() {
+// return Collections.unmodifiableMap(data);
+// }
+//
+// @Override
+// public Configuration toConfiguration(){
+// return this;
+// }
+// }
+//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java b/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
index d185de1..ddbe4af 100644
--- a/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
+++ b/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
@@ -18,6 +18,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;
@@ -47,8 +48,8 @@ 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 = Configuration.from(PropertySourceBuilder.of("test").addMap(
+ config).build());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java b/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
index 2e29cff..8b1c7dd 100644
--- a/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
+++ b/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.samples.annotations;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.config.ConfigurationBuilder;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -36,7 +36,7 @@ public class AutoConfiguredTest {
@Test
public void testTemplateWithEnvironmentVariableOnUnixoidSystem(){
AutoConfiguredClass config = new AutoConfiguredClass();
- Configuration.configure(config, ConfigurationBuilder.of("default").addPaths("classpath:cfg/autoloaded.xml").build());
+ Configuration.configure(config, Configuration.from(PropertySourceBuilder.of("default").addPaths("classpath:cfg/autoloaded.xml").build()));
System.out.println(config);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java b/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
index 499017a..e0351b2 100644
--- a/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
+++ b/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
@@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.config.ConfigFunctions;
+import org.apache.tamaya.core.ConfigurationFunctions;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
@@ -47,23 +47,23 @@ public class SimplePropertiesAndCLISample {
Map<String, String> cfgMap = new HashMap<>();
cfgMap.put("param1", "value1");
cfgMap.put("a", "Adrian"); // overrides Anatole
- Configuration config = PropertySourceBuilder.of("myTestConfig").addPaths(
+ Configuration config = Configuration.from(PropertySourceBuilder.of("myTestConfig").addPaths(
"classpath:test.properties").addPaths("classpath:cfg/test.xml")
.addArgs(new String[]{"-arg1", "--fullarg", "fullValue", "-myflag"}).addMap(cfgMap)
- .build().toConfiguration();
- System.out.println(config.query(ConfigFunctions.getAreas()));
+ .build());
+ System.out.println(config.query(ConfigurationFunctions.getAreas()));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getAreas(s -> s.startsWith("another"))));
+ System.out.println(config.query(ConfigurationFunctions.getAreas(s -> s.startsWith("another"))));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getTransitiveAreas()));
+ System.out.println(config.query(ConfigurationFunctions.getTransitiveAreas()));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
+ System.out.println(config.query(ConfigurationFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
System.out.println("---");
System.out.println(config);
System.out.print("--- b=");
System.out.println(config.get("b"));
- System.out.println("--- only a,b,c)");
- System.out.println(PropertySourceBuilder.of(config).filter((f) -> f.equals("a") || f.equals("b") || f.equals("c")).build());
+// System.out.println("--- only a,b,c)");
+// System.out.println(PropertySourceBuilder.of(config).filter((f) -> f.equals("a") || f.equals("b") || f.equals("c")).build());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
index 50e1753..e7f2049 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.core.config.ConfigFunctions;
+import org.apache.tamaya.core.ConfigurationFunctions;
import org.apache.tamaya.core.properties.AggregationPolicy;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
@@ -61,29 +61,29 @@ public class UC1ReadProperties {
@Test
public void example() {
- Configuration config = PropertySourceBuilder.of("test")
- .addPaths("classpath:ucs/UC1ReadProperties/UC1ReadPropertiesTest.properties").build().toConfiguration();
+ Configuration config = Configuration.from(PropertySourceBuilder.of("test")
+ .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"));
// double anotherNum = config.getDouble("num.Double").getAsDouble();
// long longNum = config.getLong("num.Long").orElse(288900L);
// or more simpler use area function
- Configuration areaConfig2 = config.with(ConfigFunctions.selectArea("num"));
+ Configuration areaConfig2 = config.with(ConfigurationFunctions.selectArea("num"));
System.out.println(areaConfig2);
// iterator over an area, using streams only
Map<String, String> areaMap = config.getProperties().entrySet().stream()
.filter((e) -> e.getKey().startsWith("num."))
.collect(Collectors.toMap((e) -> e.getKey().substring("num.".length()), Map.Entry::getValue));
- Configuration areaConfig = PropertySourceBuilder.of("Test").addMap(areaMap).build().toConfiguration();
+ Configuration areaConfig = Configuration.from(PropertySourceBuilder.of("Test").addMap(areaMap).build());
System.out.println(areaConfig);
}
@Test
public void getConfigurationTest() {
PropertySource provider = PropertySourceBuilder.of("Test").addPaths("classpath:barFoo.properties").build();
- Configuration config = provider.toConfiguration();
+ Configuration config = Configuration.from(provider);
assertNotNull(config);
assertTrue(config.isEmpty());
assertTrue(config.getProperties().isEmpty());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java b/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java
index 910610f..3269b3c 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java
@@ -19,8 +19,7 @@
package org.apache.tamaya.ucs.deltaspike;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.config.ConfigFunctions;
-import org.apache.tamaya.core.config.ConfigurationBuilder;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
import java.net.URL;
@@ -52,7 +51,7 @@ public class ConfigFiltering {
String pwd = Configuration.current().get("endPointURL.password").get();
// In the SPI
- ConfigurationBuilder.of().addPaths("...").filterValues((k,v) -> k.equals("endPointURL.password")?MyPKI.decrypt(v):v).build();
+ PropertySourceBuilder.of().addPaths("...").filterValues((k,v) -> k.equals("endPointURL.password")?MyPKI.decrypt(v):v).build();
}
private static class MyPKI{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi b/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
index 981a477..c4ba801 100644
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
+++ b/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
@@ -16,5 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.internal.TestConfigProvider
-org.apache.tamaya.internal.MutableTestConfigProvider
\ No newline at end of file
+org.apache.tamaya.internal.TestConfigProvider
\ No newline at end of file