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/24 02:12:15 UTC
[5/6] incubator-tamaya git commit: TAMAYA-19: - Moved out much of
unused/experimental code. - Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly). - Moved Environment model
to separate metamodel module.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java b/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java
deleted file mode 100644
index 30423a6..0000000
--- a/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-import org.apache.tamaya.spi.EnvironmentManagerSingletonSpi;
-
-/**
- * Created by Anatole on 12.09.2014.
- */
-public class TestEnvironmentManagerSingleton implements EnvironmentManagerSingletonSpi{
- @Override
- public Environment getCurrentEnvironment(){
- return null;
- }
-
- @Override
- public Environment getRootEnvironment(){
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java b/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
index 8aa6375..b27164c 100644
--- a/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
+++ b/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
@@ -30,14 +30,14 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.tamaya.annotation.WithCodec;
-import org.apache.tamaya.spi.CodecsSingletonSpi;
+import org.apache.tamaya.spi.CodecSpi;
/**
- * Test implementation current {@link org.apache.tamaya.spi.CodecsSingletonSpi}, which provides codecs
+ * Test implementation current {@link org.apache.tamaya.spi.CodecSpi}, which provides codecs
* for some basic types.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
-public final class TestPropertyAdaptersSingletonSpi implements CodecsSingletonSpi {
+public final class TestPropertyAdaptersSingletonSpi implements CodecSpi {
private Map<Class, Codec<?>> codecs = new ConcurrentHashMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
new file mode 100644
index 0000000..e9b04b4
--- /dev/null
+++ b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.TestPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
deleted file mode 100644
index e9b04b4..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
deleted file mode 100644
index 1b0cdd4..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationManagerSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestConfigServiceSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
new file mode 100644
index 0000000..1b0cdd4
--- /dev/null
+++ b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.TestConfigServiceSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
deleted file mode 100644
index d39ba55..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.EnvironmentManagerSingletonSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestEnvironmentManagerSingleton
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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
index c89e269..b6f54fc 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
@@ -23,7 +23,7 @@ import java.util.UUID;
import org.apache.tamaya.*;
import org.apache.tamaya.core.properties.AbstractPropertySource;
-import org.apache.tamaya.core.spi.AdapterProviderSpi;
+import org.apache.tamaya.core.spi.CodecProviderSpi;
import org.apache.tamaya.spi.ServiceContext;
/**
@@ -36,17 +36,15 @@ public abstract class AbstractConfiguration extends AbstractPropertySource imple
private final Object LOCK = new Object();
- private String version = UUID.randomUUID().toString();
-
- protected AbstractConfiguration(MetaInfo metaInfo){
- super(metaInfo);
+ protected AbstractConfiguration(String name){
+ super(name);
}
@Override
public <T> Optional<T> get(String key, Class<T> type){
- AdapterProviderSpi as = ServiceContext.getInstance().getSingleton(AdapterProviderSpi.class);
- Codec<T> adapter = as.getAdapter(type);
+ CodecProviderSpi as = ServiceContext.getInstance().getSingleton(CodecProviderSpi.class);
+ Codec<T> adapter = as.getCodec(type);
if(adapter == null){
throw new ConfigException(
"Can not deserialize config property '" + key + "' to " + type.getName() + ": no such " +
@@ -55,11 +53,6 @@ public abstract class AbstractConfiguration extends AbstractPropertySource imple
return getAdapted(key, adapter);
}
- @Override
- public String getVersion(){
- return version;
- }
-
/**
* This method reloads the content current this PropertyMap by reloading the contents delegate.
*/
@@ -82,7 +75,6 @@ public abstract class AbstractConfiguration extends AbstractPropertySource imple
if(changeSet.isEmpty()){
return ConfigChangeSet.emptyChangeSet(this);
}
- this.version = UUID.randomUUID().toString();
Configuration.publishChange(changeSet);
return changeSet;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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
index ddd83e2..c1a2518 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
@@ -18,10 +18,12 @@
*/
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;
@@ -59,7 +61,7 @@ public final class ConfigFunctions {
return config -> {
Map<String, String> area = new HashMap<>();
area.putAll(
- config.toMap().entrySet().stream()
+ config.getProperties().entrySet().stream()
.filter(e -> isKeyInArea(e.getKey(), areaKey))
.collect(Collectors.toMap(
e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
@@ -82,6 +84,98 @@ public final class ConfigFunctions {
}
/**
+ * 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.
@@ -106,7 +200,7 @@ public final class ConfigFunctions {
Map<String, String> area = new HashMap<>();
String lookupKey = areaKey + '.';
area.putAll(
- config.toMap().entrySet().stream()
+ config.getProperties().entrySet().stream()
.filter(e -> e.getKey().startsWith(lookupKey))
.collect(Collectors.toMap(
e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
@@ -120,13 +214,13 @@ public final class ConfigFunctions {
* 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 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);
+ return mapKeys(key -> key.startsWith(areaKey + '.') ?
+ mappedAreaKey + key.substring(areaKey.length()) : key);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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
index b190b14..9104a1f 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
@@ -44,22 +44,22 @@ public final class ConfigurationBuilder {
/**
* Private singleton constructor.
*/
- private ConfigurationBuilder(MetaInfo metaInfo) {
- this.builderDelegate = PropertySourceBuilder.of(metaInfo);
+ private ConfigurationBuilder(String name) {
+ this.builderDelegate = PropertySourceBuilder.of(name);
}
/**
* Private singleton constructor.
*/
- private ConfigurationBuilder(String name) {
- this.builderDelegate = PropertySourceBuilder.of(name);
+ private ConfigurationBuilder(String name, PropertySource source) {
+ this.builderDelegate = PropertySourceBuilder.of(name, source);
}
/**
* Private singleton constructor.
*/
- private ConfigurationBuilder(PropertySource provider) {
- this.builderDelegate = PropertySourceBuilder.of(provider);
+ private ConfigurationBuilder(PropertySource source) {
+ this.builderDelegate = PropertySourceBuilder.of(source);
}
@@ -76,16 +76,6 @@ public final class ConfigurationBuilder {
/**
* Creates a new builder instance.
*
- * @param metaInfo the meta information, not null.
- * @return a new builder instance, never null.
- */
- public static ConfigurationBuilder of(MetaInfo metaInfo) {
- return new ConfigurationBuilder(metaInfo);
- }
-
- /**
- * Creates a new builder instance.
- *
* @param name the provider name, not null.
* @return a new builder instance, never null.
*/
@@ -120,11 +110,11 @@ public final class ConfigurationBuilder {
/**
* Sets the meta info to be used for the next operation.
*
- * @param metaInfo the meta info, not null.
+ * @param name the name, not null.
* @return the builder for chaining.
*/
- public ConfigurationBuilder withMetaInfo(MetaInfo metaInfo) {
- this.builderDelegate.withMetaInfo(metaInfo);
+ public ConfigurationBuilder withName(String name) {
+ this.builderDelegate.withName(name);
return this;
}
@@ -336,19 +326,6 @@ public final class ConfigurationBuilder {
}
/**
- * Sets an additional key on the final {@link org.apache.tamaya.MetaInfo} of the provider
- * created.
- *
- * @param key the key to be added, not null.
- * @param value the keys to be added, not null.
- * @return this builder for chaining
- */
- public ConfigurationBuilder setMeta(String key, String value){
- this.builderDelegate.setMeta(key, value);
- return this;
- }
-
- /**
* Build a new property provider based on the input.
* @return a new property provider, or null.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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
new file mode 100644
index 0000000..8feaf6a
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/config/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.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/a3c10d6e/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormats.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormats.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormats.java
deleted file mode 100644
index e2469ee..0000000
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationFormats.java
+++ /dev/null
@@ -1,91 +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.ConfigurationFormat;
-import org.apache.tamaya.core.spi.ConfigurationFormatsSingletonSpi;
-
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.Collection;
-
-/**
- * Singleton accessor for accessing {@link org.apache.tamaya.core.spi.ConfigurationFormat} instances.
- */
-public final class ConfigurationFormats{
-
- /**
- * Private singleton constructor.
- */
- private ConfigurationFormats(){
- }
-
- /**
- * Access a {@link org.apache.tamaya.core.spi.ConfigurationFormat}.
- *
- * @param formatName the format name
- * @return the corresponding {@link org.apache.tamaya.core.spi.ConfigurationFormat}, or {@code null}, if
- * not available for the given environment.
- */
- public static ConfigurationFormat getFormat(String formatName){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatsSingletonSpi.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(ConfigurationFormatsSingletonSpi.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 getFormat(Resource resource){
- return ServiceContext.getInstance().getSingleton(ConfigurationFormatsSingletonSpi.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(ConfigurationFormatsSingletonSpi.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(ConfigurationFormatsSingletonSpi.class).getXmlPropertiesFormat();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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
index 7ecaf5d..240ccbe 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/FreezedConfiguration.java
@@ -34,16 +34,14 @@ final class FreezedConfiguration extends AbstractConfiguration implements Serial
private static final long serialVersionUID = -6373137316556444171L;
private PropertySource properties;
- private String version;
/**
* Constructor.
* @param config The base configuration.
*/
private FreezedConfiguration(Configuration config){
- super(MetaInfoBuilder.of(config.getMetaInfo()).set("freezedAt", Instant.now().toString()).build());
+ super(config.getName());
this.properties = PropertySourceBuilder.of(config).buildFreezed();
- this.version = Objects.requireNonNull(config.getVersion());
}
public static final Configuration of(Configuration config){
@@ -54,13 +52,8 @@ final class FreezedConfiguration extends AbstractConfiguration implements Serial
}
@Override
- public Map<String,String> toMap(){
- return properties.toMap();
- }
-
- @Override
- public String getVersion() {
- return version;
+ public Map<String,String> getProperties(){
+ return properties.getProperties();
}
@Override
@@ -71,14 +64,12 @@ final class FreezedConfiguration extends AbstractConfiguration implements Serial
FreezedConfiguration that = (FreezedConfiguration) o;
if (!properties.equals(that.properties)) return false;
- if (version != null ? !version.equals(that.version) : that.version != null) return false;
return true;
}
@Override
public int hashCode() {
int result = properties.hashCode();
- result = 31 * result + (version != null ? version.hashCode() : 0);
return result;
}
@@ -86,7 +77,7 @@ final class FreezedConfiguration extends AbstractConfiguration implements Serial
public String toString() {
return "FreezedConfiguration{" +
"properties=" + properties +
- ", version=" + version +
+ ", name=" + name +
'}';
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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
index e668b91..b5a4a6a 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
@@ -27,15 +27,15 @@ class MappedConfiguration extends AbstractConfiguration implements Configuration
* @param keyMapper The mapping operator, not null
*/
public MappedConfiguration(Configuration config, UnaryOperator<String> keyMapper) {
- super(MetaInfoBuilder.of(config.getMetaInfo()).setInfo("Mapped configuration, mapper=" + keyMapper).build());
+ super(config.getName());
this.config = Objects.requireNonNull(config);
this.keyMapper = Objects.requireNonNull(keyMapper);
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
Map<String, String> result = new HashMap<>();
- Map<String, String> map = this.config.toMap();
+ Map<String, String> map = this.config.getProperties();
map.forEach((k,v) -> {
String targetKey = keyMapper.apply(k);
if(targetKey!=null){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/env/BuildableEnvironment.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/env/BuildableEnvironment.java b/core/src/main/java/org/apache/tamaya/core/env/BuildableEnvironment.java
deleted file mode 100644
index f44592c..0000000
--- a/core/src/main/java/org/apache/tamaya/core/env/BuildableEnvironment.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.env;
-
-import org.apache.tamaya.Environment;
-
-import java.util.*;
-
-/**
- * Environment class that is used by the {@link org.apache.tamaya.core.env.EnvironmentBuilder}.
- */
-class BuildableEnvironment implements Environment {
-
- /** The environment data. */
- private Map<String,String> context = new TreeMap<>();
-
- /**
- * Constructor.
- * @param builder the builder, not null.
- */
- BuildableEnvironment(EnvironmentBuilder builder){
- Objects.requireNonNull(builder);
- context.putAll(builder.contextData);
- }
-
- @Override
- public Map<String, String> toMap() {
- return context;
- }
-
- @Override
- public Optional<String> get(String key){
- return Optional.ofNullable(context.get(key));
- }
-
- @Override
- public boolean containsKey(String key){
- return context.containsKey(key);
- }
-
- @Override
- public Set<String> keySet() {
- return context.keySet();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- BuildableEnvironment that = (BuildableEnvironment) o;
- return context.equals(that.context);
- }
-
- @Override
- public int hashCode() {
- return context.hashCode();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString(){
- return "Environment: " + getData();
- }
-
- /**
- * Get the delta.
- * @return
- */
- private String getData() {
- StringBuilder b = new StringBuilder();
- for(Map.Entry<String,String> en: this.context.entrySet()){
- b.append(" ").append(en.getKey()).append('=').append(escape(en.getValue())).append('\n');
- }
- if(b.length()>0)
- b.setLength(b.length()-1);
- return b.toString();
- }
-
- /**
- * Escapes several characters.
- * @param value
- * @return
- */
- private String escape(String value){
- if(value==null)
- return null;
- return value.replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r").replaceAll("\t", "\\\\t")
- .replaceAll("=", "\\\\=");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/env/ConfiguredSystemProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/env/ConfiguredSystemProperties.java b/core/src/main/java/org/apache/tamaya/core/env/ConfiguredSystemProperties.java
deleted file mode 100644
index 51367e8..0000000
--- a/core/src/main/java/org/apache/tamaya/core/env/ConfiguredSystemProperties.java
+++ /dev/null
@@ -1,353 +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.env;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.Environment;
-
-/**
- * Properties implementation class that can be applied as current System properties by calling
- * {@link org.apache.tamaya.core.env.ConfiguredSystemProperties#install()}. The system properties will
- * then behave contextually depending on the current runtime configuration active.
- */
-public class ConfiguredSystemProperties extends Properties {
-
- private static final long serialVersionUID = 2152870929299226804L;
-
- private static final Logger LOG = Logger.getLogger(ConfiguredSystemProperties.class.getName());
- private Properties initialProperties;
- private static volatile Map<String, Properties> contextualProperties = new ConcurrentHashMap<>();
- private static volatile Supplier<String> contextProvider = () ->
- Environment.current().get("context.id").orElse("<system>");
-
-
- private final Object LOCK = new Object();
-
-
- private ConfiguredSystemProperties(Properties initialProperties) {
- super(initialProperties);
- this.initialProperties = initialProperties;
- }
-
- public static void install() {
- Properties props = System.getProperties();
- if (props instanceof ConfiguredSystemProperties) {
- return;
- }
- ConfiguredSystemProperties systemProps = new ConfiguredSystemProperties(props);
- LOG.finest("Installing enhanced system properties...");
- System.setProperties(systemProps);
- LOG.info("Installed enhanced system properties successfully.");
- }
-
- public static void uninstall() {
- Properties props = System.getProperties();
- if (props instanceof ConfiguredSystemProperties) {
- Properties initialProperties = ((ConfiguredSystemProperties) props).initialProperties;
- LOG.finest("Uninstalling enhanced system properties...");
- System.setProperties(initialProperties);
- LOG.info("Uninstalled enhanced system properties successfully.");
- }
- }
-
- @Override
- public String getProperty(String key) {
- return getContextualProperties().getProperty(key);
- }
-
- @Override
- public String getProperty(String key, String defaultValue) {
- return getContextualProperties().getProperty(key, defaultValue);
- }
-
- @Override
- public Enumeration<?> propertyNames() {
- return getContextualProperties().propertyNames();
- }
-
- @Override
- public Set<String> stringPropertyNames() {
- return getContextualProperties().stringPropertyNames();
- }
-
- @Override
- public synchronized int size() {
- return getContextualProperties().size();
- }
-
- @Override
- public synchronized Enumeration<Object> keys() {
- return getContextualProperties().keys();
- }
-
- @Override
- public synchronized Enumeration<Object> elements() {
- return getContextualProperties().elements();
- }
-
- @Override
- public synchronized boolean contains(Object value) {
- return getContextualProperties().contains(value);
- }
-
- @Override
- public boolean containsValue(Object value) {
- return getContextualProperties().containsValue(value);
- }
-
- @Override
- public synchronized boolean containsKey(Object key) {
- return getContextualProperties().containsKey(key);
- }
-
- @Override
- public synchronized Object get(Object key) {
- return getContextualProperties().get(key);
- }
-
- @Override
- public synchronized Object clone() {
- return getContextualProperties().clone();
- }
-
- @Override
- public Set<Object> keySet() {
- return getContextualProperties().keySet();
- }
-
- @Override
- public Set<Map.Entry<Object, Object>> entrySet() {
- return getContextualProperties().entrySet();
- }
-
- @Override
- public Collection<Object> values() {
- return getContextualProperties().values();
- }
-
-
- @Override
- public Object getOrDefault(Object key, Object defaultValue) {
- return getContextualProperties().getOrDefault(key, defaultValue);
- }
-
- @Override
- public void forEach(BiConsumer<? super Object, ? super Object> action) {
- getContextualProperties().forEach(action);
- }
-
-
- @Override
- public Object computeIfAbsent(Object key, Function<? super Object, ?> mappingFunction) {
- return getContextualProperties().computeIfAbsent(key, mappingFunction);
- }
-
- @Override
- public synchronized Object computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
- return getContextualProperties().computeIfPresent(key, remappingFunction);
- }
-
- @Override
- public synchronized Object compute(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
- return getContextualProperties().compute(key, remappingFunction);
- }
-
- @Override
- public String toString() {
- return getContextualProperties().toString();
- }
-
- @Override
- public synchronized Object setProperty(String key, String value) {
- return getContextualProperties().setProperty(key, value);
- }
-
- @Override
- public synchronized void load(Reader reader) throws IOException {
- getContextualProperties().load(reader);
- }
-
- @Override
- public synchronized void load(InputStream inStream) throws IOException {
- getContextualProperties().load(inStream);
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void save(OutputStream out, String comments) {
- super.save(out, comments);
- }
-
- @Override
- public void store(Writer writer, String comments) throws IOException {
- getContextualProperties().store(writer, comments);
- }
-
- @Override
- public void store(OutputStream out, String comments) throws IOException {
- getContextualProperties().store(out, comments);
- }
-
- @Override
- public void loadFromXML(InputStream in) throws IOException {
- getContextualProperties().loadFromXML(in);
- }
-
- @Override
- public void storeToXML(OutputStream os, String comment) throws IOException {
- getContextualProperties().storeToXML(os, comment);
- }
-
- @Override
- public void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
- getContextualProperties().storeToXML(os, comment, encoding);
- }
-
- @Override
- public void list(PrintStream out) {
- getContextualProperties().list(out);
- }
-
- @Override
- public void list(PrintWriter out) {
- getContextualProperties().list(out);
- }
-
- @Override
- public boolean isEmpty() {
- return getContextualProperties().isEmpty();
- }
-
- @Override
- public Object put(Object key, Object value) {
- return getContextualProperties().put(key, value);
- }
-
- @Override
- public Object remove(Object key) {
- return getContextualProperties().remove(key);
- }
-
- @Override
- public void putAll(Map<?, ?> t) {
- getContextualProperties().putAll(t);
- }
-
- @Override
- public void clear() {
- getContextualProperties().clear();
- }
-
- @Override
- public boolean equals(Object o) {
- return getContextualProperties().equals(o);
- }
-
- @Override
- public int hashCode() {
- return getContextualProperties().hashCode();
- }
-
- @Override
- public void replaceAll(BiFunction<? super Object, ? super Object, ?> function) {
- getContextualProperties().replaceAll(function);
- }
-
- @Override
- public Object putIfAbsent(Object key, Object value) {
- return getContextualProperties().putIfAbsent(key, value);
- }
-
- @Override
- public boolean remove(Object key, Object value) {
- return getContextualProperties().remove(key, value);
- }
-
- @Override
- public boolean replace(Object key, Object oldValue, Object newValue) {
- return getContextualProperties().replace(key, oldValue, newValue);
- }
-
- @Override
- public Object replace(Object key, Object value) {
- return getContextualProperties().replace(key, value);
- }
-
- @Override
- public Object merge(Object key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
- return getContextualProperties().merge(key, value, remappingFunction);
- }
-
- public Properties getInitialProperties() {
- return initialProperties;
- }
-
- /**
- * Uninstalls the contextual system properties for the current context, as determined by the current
- * context provider active.
- */
- public static void resetProperties() {
- String contextId = contextProvider == null ? "" : contextProvider.get();
- contextualProperties.remove(contextId);
- }
-
- protected Properties getContextualProperties() {
- String contextId = contextProvider == null ? "" : contextProvider.get();
- Properties props = ConfiguredSystemProperties.contextualProperties.get(contextId);
- if (props == null) {
- synchronized (LOCK) {
- props = ConfiguredSystemProperties.contextualProperties.get(contextId);
- if (props == null) {
- props = createNewProperties();
- contextualProperties.put(contextId, props);
- }
- }
- }
- return props;
- }
-
- protected Properties createNewProperties() {
- Properties props = new Properties(initialProperties);
- Configuration config = Configuration.current();
- Map<String, String> configMap = config.toMap();
- for (Map.Entry<String, String> en : configMap.entrySet()) {
- props.put(en.getKey(), en.getValue());
- }
- return props;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java b/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
deleted file mode 100644
index 895ac76..0000000
--- a/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.env;
-
-import org.apache.tamaya.Environment;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
-* Builder to create new {@link org.apache.tamaya.Environment instances.}
-*/
-public final class EnvironmentBuilder{
-
- /** The property name for the stage property. */
- public static final String STAGE_PROP = "stage";
-
- /** THe environment data. */
- Map<String,String> contextData = new HashMap<>();
-
- /**
- * Constructor.
- */
- private EnvironmentBuilder() {
- }
-
- /**
- * Creates a new buildr instance.
- * @return the new builder instance.
- */
- public static final EnvironmentBuilder of() {
- return new EnvironmentBuilder();
- }
-
- /**
- * Sets a new environment property.
- * @param key the key, not null.
- * @param value the keys, not null.
- * @return the builder for chaining
- */
- public EnvironmentBuilder set(String key, String value){
- this.contextData.put(key, value);
- return this;
- }
-
- /**
- * Sets new environment properties.
- * @param values the key/values, not null.
- * @return the builder for chaining
- */
- public EnvironmentBuilder setAll(Map<String,String> values){
- this.contextData.putAll(values);
- return this;
- }
-
- /**
- * Sets the stage using the default stage key.
- * @param stage The stage, not null.
- * @return the builder for chaining.
- */
- public EnvironmentBuilder setStage(String stage){
- this.contextData.put(STAGE_PROP, Objects.requireNonNull(stage));
- return this;
- }
-
- /**
- * Access a property
- * @param key the key, not null.
- * @return the builder for chaining.
- */
- public String getProperty(String key) {
- return this.contextData.get(key);
- }
-
- /**
- * Builds a new Environment.
- * @return a new Environment, never null.
- */
- public Environment build() {
- return new BuildableEnvironment(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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 6a98fb8..4b3511f 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
@@ -18,10 +18,9 @@
*/
package org.apache.tamaya.core.internal;
-import org.apache.tamaya.core.config.ConfigurationFormats;
import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
+import org.apache.tamaya.core.config.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
@@ -49,7 +48,7 @@ public final class MetaConfig {
"classpath:META-INF/config.properties");
for(Resource res:resources){
try{
- ConfigurationFormat format = ConfigurationFormats.getFormat(res);
+ ConfigurationFormat format = ConfigurationFormat.from(res);
Map<String,String> read = format.readConfiguration(res);
properties.putAll(read);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultCodecSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultCodecSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultCodecSpi.java
new file mode 100644
index 0000000..fbbf130
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultCodecSpi.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.internal.config;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.util.Currency;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+
+import org.apache.tamaya.Codec;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.annotation.WithCodec;
+import org.apache.tamaya.spi.CodecSpi;
+
+/**
+ * Default codecs singleton, which provides default codesc for all kind of classes out of the box, which will be
+ * instantiatable from configuration, if one of the following is given:
+ * <ul>
+ * <li>static factory methods using a String as simgle argument, called {@code of, valueOf, getInstance, instance, parse}</li>
+ * <li>have constructors taking a single String</li>
+ * </ul>
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class DefaultCodecSpi implements CodecSpi {
+
+
+ private Map<Class,Codec> adapters = new ConcurrentHashMap<>();
+
+ public DefaultCodecSpi(){
+ // Add default adapters
+ register(char.class, (s) -> s.charAt(0), (ch) -> String.valueOf(ch));
+ register(byte.class, Byte::parseByte, Object::toString);
+ register(short.class, Short::parseShort, Object::toString);
+ register(int.class, Integer::parseInt, Object::toString);
+ register(long.class, Long::parseLong, Object::toString);
+ register(boolean.class, Boolean::parseBoolean, b -> String.valueOf(b));
+ register(float.class, Float::parseFloat, f -> String.valueOf(f));
+ register(double.class, Double::parseDouble, d -> String.valueOf(d));
+
+ register(Character.class, (s) -> s.charAt(0), Object::toString);
+ register(Byte.class, Byte::valueOf, Object::toString);
+ register(Short.class, Short::valueOf, String::valueOf);
+ register(Integer.class, Integer::valueOf, Object::toString);
+ register(Long.class, Long::valueOf, Object::toString);
+ register(Boolean.class, Boolean::valueOf, b -> String.valueOf(b));
+ register(Float.class, Float::valueOf, f -> String.valueOf(f));
+ register(Double.class, Double::valueOf, d -> String.valueOf(d));
+ register(BigDecimal.class, BigDecimal::new, String::valueOf);
+ register(BigInteger.class, BigInteger::new, String::valueOf);
+
+ register(Currency.class, Currency::getInstance, Object::toString);
+
+ register(LocalDate.class, LocalDate::parse, Object::toString);
+ register(LocalTime.class, LocalTime::parse, Object::toString);
+ register(LocalDateTime.class, LocalDateTime::parse, Object::toString);
+ register(ZoneId.class, ZoneId::of, ZoneId::getId);
+ }
+
+ @Override
+ public <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
+ return adapters.put(targetType, adapter);
+ }
+
+ @Override
+ public <T> Codec<T> getCodec(Class<T> targetType, WithCodec adapterAnnot){
+ Codec codec = null;
+ Class<? extends Codec> configuredCodec = null;
+ if(adapterAnnot != null){
+ configuredCodec = adapterAnnot.value();
+ if(!configuredCodec.equals(Codec.class)){
+ try{
+ codec = configuredCodec.newInstance();
+ }
+ catch(Exception e){
+ throw new ConfigException("Invalid codec configured.", e);
+ }
+ }
+ }
+ if(codec == null){
+ codec = adapters.get(targetType);
+ }
+ if(codec == null){
+ codec = getDefaultCodec(targetType);
+ }
+ if(codec == null){
+ throw new ConfigException("No Codec found for " + targetType.getName());
+ }
+ return codec;
+ }
+
+ private <T> Codec getDefaultCodec(Class<T> targetType) {
+ Function<String, T> decoder = null;
+ Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "parse");
+ if(factoryMethod!=null){
+ decoder = (s) -> {
+ try{
+ factoryMethod.setAccessible(true);
+ return targetType.cast(factoryMethod.invoke(s));
+ }
+ catch (Exception e){
+ throw new ConfigException("Failed to decode '"+s+"'", e);
+ }
+ };
+ }
+ if(decoder==null) {
+ try {
+ Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
+ decoder = (s) -> {
+ try{
+ constr.setAccessible(true);
+ return constr.newInstance(s);
+ }
+ catch (Exception e){
+ throw new ConfigException("Failed to decode '"+s+"'", e);
+ }
+ };
+ } catch (Exception e) {
+ // ignore, TODO log finest
+ }
+ }
+ if(decoder!=null) {
+ return register(targetType, decoder, String::valueOf);
+ }
+ return null;
+ }
+
+ private Method getFactoryMethod(Class<?> type, String... methodNames) {
+ Method m;
+ for(String name:methodNames){
+ try{
+ m = type.getDeclaredMethod(name, String.class);
+ return m;
+ }
+ catch(Exception e){
+ // ignore, TODO log finest
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isTargetTypeSupported(Class<?> targetType){
+ return adapters.containsKey(targetType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
deleted file mode 100644
index 2b0a471..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.config;
-
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-
-import org.apache.tamaya.ConfigChangeSet;
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-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.ConfigurationManagerSingletonSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-
-/**
- * Default SPI that implements the behaviour of {@link org.apache.tamaya.spi.ConfigurationManagerSingletonSpi}.
- */
-@SuppressWarnings("unchecked")
-public class DefaultConfigurationManagerSingletonSpi implements ConfigurationManagerSingletonSpi {
-
- private static final String DEFAULT_CONFIG_NAME = "default";
-
- private Map<String, ConfigurationProviderSpi> configProviders = new ConcurrentHashMap<>();
-
- private ExpressionEvaluator expressionEvaluator = loadEvaluator();
-
- private ExpressionEvaluator loadEvaluator() {
- ExpressionEvaluator eval = ServiceContext.getInstance().getService(ExpressionEvaluator.class).orElse(null);
- if (eval == null) {
- eval = new DefaultExpressionEvaluator();
- }
- return eval;
- }
-
- public DefaultConfigurationManagerSingletonSpi() {
- for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
- configProviders.put(spi.getConfigName(), spi);
- }
- }
-
- @Override
- public <T> T createTemplate(Class<T> type, Configuration... configurations) {
- ClassLoader cl = Optional.ofNullable(Thread.currentThread()
- .getContextClassLoader()).orElse(getClass().getClassLoader());
- return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, configurations));
- }
-
- /**
- *
- * @param instance the instance with configuration annotations, not null.
- * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
- * If no items are passed, the default configuration is used.
- */
- @Override
- public void configure(Object instance, Configuration... configurations) {
- ConfigurationInjector.configure(instance, configurations);
- }
-
-
- @Override
- public String evaluateValue(String expression, Configuration... configurations) {
- return expressionEvaluator.evaluate(expression, configurations);
- }
-
- @Override
- public void addChangeListener(Consumer<ConfigChangeSet> l) {
- WeakConfigListenerManager.of().registerConsumer(l,l);
- }
-
- @Override
- public void removeChangeListener(Consumer<ConfigChangeSet> l) {
- WeakConfigListenerManager.of().unregisterConsumer(l);
- }
-
- @Override
- public void publishChange(ConfigChangeSet configChangeSet) {
- WeakConfigListenerManager.of().publishChangeEvent(configChangeSet);
- }
-
- @Override
- public boolean isConfigurationDefined(String name) {
- ConfigurationProviderSpi spi = this.configProviders.get(name);
- return spi != null;
- }
-
- @Override
- public Configuration getConfiguration(String name) {
- ConfigurationProviderSpi provider = configProviders.get(name);
- if (provider == null) {
- if (DEFAULT_CONFIG_NAME.equals(name)) {
- provider = new FallbackSimpleConfigProvider();
- configProviders.put(DEFAULT_CONFIG_NAME, provider);
- } else {
- throw new ConfigException("No such config: " + name);
- }
- }
- Configuration config = provider.getConfiguration();
- if (config == null) {
- throw new ConfigException("No such config: " + name);
- }
- return config;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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
new file mode 100644
index 0000000..f755058
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.config;
+
+import java.lang.reflect.Proxy;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Consumer;
+
+import org.apache.tamaya.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;
+import org.apache.tamaya.spi.ServiceContext;
+
+
+/**
+ * Default SPI that implements the behaviour of {@link org.apache.tamaya.spi.ConfigurationSpi}.
+ */
+@SuppressWarnings("unchecked")
+public class DefaultConfigurationSpi implements ConfigurationSpi {
+
+ private static final String DEFAULT_CONFIG_NAME = "default";
+
+ private Map<String, ConfigurationProviderSpi> configProviders = new ConcurrentHashMap<>();
+
+ private ExpressionEvaluator expressionEvaluator = loadEvaluator();
+
+ private ExpressionEvaluator loadEvaluator() {
+ ExpressionEvaluator eval = ServiceContext.getInstance().getService(ExpressionEvaluator.class).orElse(null);
+ if (eval == null) {
+ eval = new DefaultExpressionEvaluator();
+ }
+ return eval;
+ }
+
+ public DefaultConfigurationSpi() {
+ for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
+ configProviders.put(spi.getConfigName(), spi);
+ }
+ }
+
+ @Override
+ public <T> T createTemplate(Class<T> type, Configuration... configurations) {
+ ClassLoader cl = Optional.ofNullable(Thread.currentThread()
+ .getContextClassLoader()).orElse(getClass().getClassLoader());
+ return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, configurations));
+ }
+
+ /**
+ *
+ * @param instance the instance with configuration annotations, not null.
+ * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no items are passed, the default configuration is used.
+ */
+ @Override
+ public void configure(Object instance, Configuration... configurations) {
+ ConfigurationInjector.configure(instance, configurations);
+ }
+
+
+ @Override
+ public String evaluateValue(String expression, Configuration... configurations) {
+ return expressionEvaluator.evaluate(expression, configurations);
+ }
+
+ @Override
+ public void addChangeListener(Consumer<ConfigChangeSet> l) {
+ WeakConfigListenerManager.of().registerConsumer(l,l);
+ }
+
+ @Override
+ public void removeChangeListener(Consumer<ConfigChangeSet> l) {
+ WeakConfigListenerManager.of().unregisterConsumer(l);
+ }
+
+ @Override
+ public void publishChange(ConfigChangeSet configChangeSet) {
+ WeakConfigListenerManager.of().publishChangeEvent(configChangeSet);
+ }
+
+ @Override
+ public boolean isConfigurationAvailable(String name) {
+ ConfigurationProviderSpi spi = this.configProviders.get(name);
+ return spi != null;
+ }
+
+ @Override
+ public Configuration getConfiguration(String name) {
+ ConfigurationProviderSpi provider = configProviders.get(name);
+ if (provider == null) {
+ if (DEFAULT_CONFIG_NAME.equals(name)) {
+ provider = new FallbackSimpleConfigProvider();
+ configProviders.put(DEFAULT_CONFIG_NAME, provider);
+ } else {
+ throw new ConfigException("No such config: " + name);
+ }
+ }
+ Configuration config = provider.getConfiguration();
+ if (config == null) {
+ throw new ConfigException("No such config: " + name);
+ }
+ return config;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/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 0b5c2c7..661bf64 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
@@ -3,6 +3,7 @@ package org.apache.tamaya.core.internal.config;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import java.util.UUID;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.MetaInfo;
@@ -27,18 +28,13 @@ class FileConfiguration implements Configuration, FileChangeObserver {
return Optional.ofNullable(configurationMap.get(key));
}
- @Override
- public MetaInfo getMetaInfo() {
- return MetaInfo.of("files.config");
- }
-
- @Override
- public boolean containsKey(String key) {
- return configurationMap.containsKey(key);
+ @Override
+ public String getName() {
+ return "files.config";
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
return configurationMap;
}
@@ -66,7 +62,7 @@ class FileConfiguration implements Configuration, FileChangeObserver {
}
if(Configuration.class.isInstance(obj)) {
Configuration other = Configuration.class.cast(obj);
- return Objects.equals(configurationMap, other.toMap());
+ return Objects.equals(configurationMap, other.getProperties());
}
return false;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentApplicationEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentApplicationEnvironmentProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentApplicationEnvironmentProvider.java
deleted file mode 100644
index 1632fcd..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentApplicationEnvironmentProvider.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.env;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-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.spi.ConfigurationFormat;
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-import org.apache.tamaya.spi.ServiceContext;
-
-/**
- * Application environment provider that is dependent on the current context classloader and tries to
- * evaluate {@code META-INF/env/application.properties, META-INF/env/application.xml and META-INF/env/application.ini}.
- * Only if a property named {@code org.apache.tamaya.env.applicationId} is found, it will
- * be used as the {@code environmentId} and a corresponding {@link org.apache.tamaya.Environment} instance
- * is created and attached.
- */
-public class ClassLoaderDependentApplicationEnvironmentProvider implements EnvironmentProvider {
-
- private static final Logger LOG = Logger.getLogger(ClassLoaderDependentApplicationEnvironmentProvider.class.getName());
-
- private Map<ClassLoader, Map<String,String>> environments = new ConcurrentHashMap<>();
- private Map<ClassLoader, Boolean> environmentAvailable = new ConcurrentHashMap<>();
-
- @Override
- public boolean isActive() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- return false;
- }
- Boolean available = this.environmentAvailable.get(cl);
- if(available!=null && !available){
- return false;
- }
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
- "classpath:META-INF/env/application.properties", "classpath:META-INF/env/application.xml", "classpath:META-INF/env/application.ini");
- available = !propertyUris.isEmpty();
- this.environmentAvailable.put(cl, available);
- return available;
- }
-
- @Override
- public Map<String,String> getEnvironmentData() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- return null;
- }
- Map<String,String> data = this.environments.get(cl);
- if(data!=null){
- return data;
- }
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
- "classpath:META-INF/env/application.properties", "classpath:META-INF/env/application.xml", "classpath:META-INF/env/application.ini");
- data = new HashMap<>();
-
- for(Resource resource:propertyUris){
- try{
- ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
- data.putAll(format.readConfiguration(resource));
- }
- catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error reading application environment data fromMap " + resource);
- }
- }
- data.put("classloader.type", cl.getClass().getName());
- data.put("classloader.info", cl.toString());
- Set<Resource> uris = new HashSet<>();
- uris.addAll(propertyUris);
- data.put("environment.sources", uris.toString());
- data = Collections.unmodifiableMap(data);
- this.environments.put(cl, data);
- return data;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentEarEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentEarEnvironmentProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentEarEnvironmentProvider.java
deleted file mode 100644
index 990d13d..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/env/ClassLoaderDependentEarEnvironmentProvider.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.env;
-
-import org.apache.tamaya.core.config.ConfigurationFormats;
-import org.apache.tamaya.core.env.EnvironmentBuilder;
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.spi.ConfigurationFormat;
-import org.apache.tamaya.core.spi.EnvironmentProvider;
-import org.apache.tamaya.core.resource.ResourceLoader;
-
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class implements a {@link org.apache.tamaya.core.spi.EnvironmentProvider} that tries
- * to read configuration for an ear deployment located under {@code META-INF/env/ear.properties,
- * META-INF/env/ear.xml or META-INF/env/ear.ini}. The environment id hereby is defined by a
- * configuration entry named {@code org.apache.tamaya.core.env.earId}.
- *
- * Only if such a configuration with such an {@code earId} is found an {@link org.apache.tamaya.Environment}
- * is created and attached to the corresponding ear classloader.
- */
-public class ClassLoaderDependentEarEnvironmentProvider implements EnvironmentProvider {
-
- private static final Logger LOG = Logger.getLogger(ClassLoaderDependentEarEnvironmentProvider.class.getName());
-
-// private static final String EARID_PROP = "environment.earId";
-
- private Map<ClassLoader, Map<String,String>> environments = new ConcurrentHashMap<>();
- private Map<ClassLoader, Boolean> environmentAvailable = new ConcurrentHashMap<>();
-
- @Override
- public boolean isActive() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- return false;
- }
- Boolean available = this.environmentAvailable.get(cl);
- if(available!=null && !available){
- return false;
- }
- List<Resource> propertyUris = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
- "classpath:META-INF/env/ear.properties", "classpath:META-INF/env/ear.xml", "classpath:META-INF/env/ear.ini");
- available = !propertyUris.isEmpty();
- this.environmentAvailable.put(cl, available);
- return available;
- }
-
- @Override
- public Map<String,String> getEnvironmentData() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl==null){
- return null;
- }
- Map<String,String> data = this.environments.get(cl);
- if(data!=null){
- return data;
- }
- List<Resource> resources = ServiceContext.getInstance().getSingleton(ResourceLoader.class).getResources(cl,
- "classpath:META-INF/env/ear.properties", "classpath:META-INF/env/ear.xml", "classpath:META-INF/env/ear.ini");
- data = new HashMap<>();
- for(Resource resource:resources){
- try{
- ConfigurationFormat format = ConfigurationFormats.getFormat(resource);
- Map<String,String> read = format.readConfiguration(resource);
- data.putAll(read);
- }
- catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error reading ear environment data fromMap " + resource);
- }
- }
-// String earId = data.getOrDefault(EARID_PROP, cl.toString());
- String stageValue = data.get(EnvironmentBuilder.STAGE_PROP);
- if (stageValue != null) {
- data.put(EnvironmentBuilder.STAGE_PROP,stageValue);
- }
- data.put("classloader.type", cl.getClass().getName());
- data.put("classloader.info", cl.toString());
- Set<Resource> resourceSet = new HashSet<>();
- resourceSet.addAll(resources);
- data.put("environment.sources", resourceSet.toString());
- data = Collections.unmodifiableMap(data);
- this.environments.put(cl, data);
- return data;
- }
-
-}