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/01 10:43:50 UTC
[7/8] incubator-tamaya git commit: TAMAYA-14: added resource support.
TAMAYA-15: Moved PropertyProviders to API,
added SPI. TAMAYA-8: Added/improved Javadoc.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/ContextualPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/ContextualPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/ContextualPropertyProvider.java
new file mode 100644
index 0000000..9bea099
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/ContextualPropertyProvider.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.*;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+
+/**
+ * Created by Anatole on 12.04.2014.
+ */
+class ContextualPropertyProvider implements PropertyProvider{
+
+ private volatile Map<String,PropertyProvider> cachedMaps = new ConcurrentHashMap<>();
+
+ private Supplier<PropertyProvider> mapSupplier;
+ private Supplier<String> isolationKeySupplier;
+ private MetaInfo metaInfo;
+
+ /**
+ * Creates a new contextual PropertyMap. Contextual maps delegate to different instances of PropertyMap depending
+ * on the keys returned fromMap the isolationP
+ *
+ * @param mapSupplier
+ * @param isolationKeySupplier
+ */
+ public ContextualPropertyProvider(Supplier<PropertyProvider> mapSupplier, Supplier<String> isolationKeySupplier){
+ this.metaInfo = MetaInfoBuilder.of().setType("contextual").set("mapSupplier", mapSupplier.toString())
+ .set("isolationKeySupplier", isolationKeySupplier.toString()).build();
+ Objects.requireNonNull(mapSupplier);
+ Objects.requireNonNull(isolationKeySupplier);
+ this.mapSupplier = mapSupplier;
+ this.isolationKeySupplier = isolationKeySupplier;
+ }
+
+ /**
+ * This method provides the contextual Map for the current environment. Hereby, ba default, for each different
+ * key returned by the #isolationKeySupplier a separate PropertyMap instance is acquired fromMap the #mapSupplier.
+ * If the map supplier returns an instance it is cached in the local #cachedMaps.
+ *
+ * @return the current contextual PropertyMap.
+ */
+ protected PropertyProvider getContextualMap(){
+ String environmentKey = this.isolationKeySupplier.get();
+ if(environmentKey == null){
+ return PropertyProviders.empty();
+ }
+ PropertyProvider map = this.cachedMaps.get(environmentKey);
+ if(map == null){
+ synchronized(cachedMaps){
+ map = this.cachedMaps.get(environmentKey);
+ if(map == null){
+ map = this.mapSupplier.get();
+ if(map == null){
+ return PropertyProviders
+ .empty(MetaInfoBuilder.of().setInfo(
+ "No map provided by supplier " + mapSupplier + " for key " + environmentKey)
+ .build());
+ }
+ this.cachedMaps.put(environmentKey, map);
+ }
+ }
+ }
+ return map;
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ return getContextualMap().load();
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return getContextualMap().containsKey(key);
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ return getContextualMap().toMap();
+ }
+
+ @Override
+ public MetaInfo getMetaInfo(){
+ return this.metaInfo;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ return getContextualMap().get(key);
+ }
+
+ @Override
+ public Set<String> keySet(){
+ return getContextualMap().keySet();
+ }
+
+ /**
+ * Apply a config change to this item. Hereby the change must be related to the same instance.
+ * @param change the config change
+ * @throws org.apache.tamaya.ConfigException if an unrelated change was passed.
+ * @throws UnsupportedOperationException when the configuration is not writable.
+ */
+ @Override
+ public void apply(ConfigChangeSet change){
+ getContextualMap().apply(change);
+ }
+
+ /**
+ * Access a cached PropertyMap.
+ *
+ * @param key the target environment key as returned by the environment key supplier, not null.
+ * @return the corresponding PropertyMap, or null.
+ */
+ public PropertyProvider getCachedMap(String key){
+ return this.cachedMaps.get(key);
+ }
+
+ /**
+ * Access the set of currently loaded/cached maps.
+ *
+ * @return the set of cached map keys, never null.
+ */
+ public Set<String> getCachedMapKeys(){
+ return this.cachedMaps.keySet();
+ }
+
+ /**
+ * Access the supplier for environment key, determining map isolation.
+ *
+ * @return the environment key supplier instance, not null.
+ */
+ public Supplier<String> getIsolationKeySupplier(){
+ return this.isolationKeySupplier;
+ }
+
+ /**
+ * Access the supplier for new PropertyMap instances.
+ *
+ * @return the PropertyMap supplier instance, not null.
+ */
+ public Supplier<PropertyProvider> getMapSupplier(){
+ return this.mapSupplier;
+ }
+
+ @Override
+ public String toString(){
+ return "ContextualMap{" +
+ "cachedMaps(key)=" + cachedMaps.keySet() +
+ ", mapSupplier=" + mapSupplier +
+ ", isolationKeySupplier=" + isolationKeySupplier +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigProvider.java
index 3519c3e..a3b1d47 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigProvider.java
@@ -18,9 +18,9 @@
*/
package org.apache.tamaya.core.internal;
+import org.apache.tamaya.PropertyProviders;
import org.apache.tamaya.core.config.ConfigurationBuilder;
-import org.apache.tamaya.core.properties.AggregationPolicy;
-import org.apache.tamaya.core.properties.PropertyProviders;
+import org.apache.tamaya.AggregationPolicy;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
import org.apache.tamaya.Configuration;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/DefaultPropertyProvidersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultPropertyProvidersSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultPropertyProvidersSingletonSpi.java
new file mode 100644
index 0000000..0bb7e07
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultPropertyProvidersSingletonSpi.java
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.AggregationPolicy;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertyProvider;
+import org.apache.tamaya.spi.PropertyProvidersSingletonSpi;
+
+import java.net.URI;
+import java.time.Instant;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import java.util.logging.Logger;
+
+/**
+ * Default implementation of the singleton backing bean for the {@link org.apache.tamaya.PropertyProviders}.
+ */
+public class DefaultPropertyProvidersSingletonSpi implements PropertyProvidersSingletonSpi {
+
+ private final PropertyProvider EMPTY_PROPERTYPROVIDER = fromMap(MetaInfo.of("<empty>"), Collections.emptyMap());
+ private static final PropertyProvider ENV_PROPERTYPROVIDER = new EnvironmentPropertyProvider();
+
+ private static final Logger LOG = Logger.getLogger(DefaultPropertyProvidersSingletonSpi.class.getName());
+
+ @Override
+ public PropertyProvider fromArgs(MetaInfo metaInfo, String... args) {
+ Objects.requireNonNull(metaInfo);
+ // TODO read the CLI with some better library, e.g. move parsing service to ext. service SPI
+ Map<String, String> properties = new HashMap<>();
+ for (int base = 0; base < args.length; base++) {
+ if (args[base].startsWith("--")) {
+ String argKey = args[base].substring(2);
+ String value = "true"; // flag only
+ if (base != args.length - 1) {
+ if (args[base + 1].startsWith("-")) {
+ base++;
+ int eqIndex = argKey.indexOf('=');
+ if (eqIndex > 0) {
+ value = argKey.substring(eqIndex + 1);
+ argKey = argKey.substring(0, eqIndex);
+ }
+ } else {
+ value = args[base + 1];
+ base += 2;
+ }
+ }
+ properties.put(argKey, value);
+ } else if (args[base].startsWith("-")) {
+ String argKey = args[base].substring(1);
+ String value = "true"; // flag only
+ if (base != args.length - 1) {
+ if (args[base + 1].startsWith("-")) {
+ base++;
+ int eqIndex = argKey.indexOf('=');
+ if (eqIndex > 0) {
+ value = argKey.substring(eqIndex + 1);
+ argKey = argKey.substring(0, eqIndex);
+ }
+ } else {
+ value = args[base + 1];
+ base += 2;
+ }
+ }
+ properties.put(argKey, value);
+ }
+ }
+ return fromMap(metaInfo, properties);
+ }
+
+ @Override
+ public PropertyProvider fromPaths(AggregationPolicy aggregationPolicy, MetaInfo metaInfo, List<String> paths) {
+ if(metaInfo == null){
+ metaInfo = MetaInfoBuilder.of().setInfo("From Paths").set("paths", paths.toString()).build();
+ }
+ return new PathBasedPropertyProvider(metaInfo, paths, aggregationPolicy);
+ }
+
+ @Override
+ public PropertyProvider fromUris(AggregationPolicy aggregationPolicy, MetaInfo metaInfo, List<URI> uris) {
+ if(metaInfo == null){
+ metaInfo = MetaInfoBuilder.of().setInfo("From URIs").set("uris", uris.toString()).build();
+ }
+ return new URIBasedPropertyProvider(metaInfo, uris, aggregationPolicy);
+ }
+
+ @Override
+ public PropertyProvider fromMap(MetaInfo metaInfo, Map<String, String> map) {
+ if(metaInfo == null){
+ metaInfo = MetaInfoBuilder.of().setInfo("From Map").set("map", map.toString()).build();
+ }
+ return new MapBasedPropertyProvider(metaInfo, map);
+ }
+
+ @Override
+ public PropertyProvider empty(MetaInfo metaInfo) {
+ if(metaInfo==null) {
+ return EMPTY_PROPERTYPROVIDER;
+ }
+ return fromMap(metaInfo, Collections.emptyMap());
+ }
+
+ @Override
+ public PropertyProvider emptyMutable(MetaInfo metaInfo) {
+ return fromMap(metaInfo, new ConcurrentHashMap<>());
+ }
+
+ /**
+ * Returns a read-only {@link PropertyProvider} reflecting the current runtime environment properties.
+ *
+ * @return a new read-only {@link PropertyProvider} instance based on the current runtime environment properties.
+ */
+ @Override
+ public PropertyProvider fromEnvironmentProperties() {
+ return ENV_PROPERTYPROVIDER;
+ }
+
+ /**
+ * Creates a new read-only {@link PropertyProvider} reflecting the current system properties.
+ *
+ * @return a new read-only {@link PropertyProvider} instance based on the current system properties.
+ */
+ @Override
+ public PropertyProvider fromSystemProperties() {
+ return new SystemPropertiesPropertyProvider();
+ }
+
+ @Override
+ public PropertyProvider freezed(MetaInfo metaInfo, PropertyProvider provider) {
+ if(metaInfo==null){
+ metaInfo = MetaInfoBuilder.of().setType("freezed")
+ .set("provider", provider.toString())
+ .set("freezedAt", Date.from(Instant.now()).toString())
+ .build();
+ }
+ else{
+ metaInfo = MetaInfoBuilder.of(metaInfo).setType("freezed")
+ .set("freezedAt", Date.from(Instant.now()).toString())
+ .set("provider", provider.toString())
+ .build();
+ }
+ return FreezedPropertyProvider.of(metaInfo, provider);
+ }
+
+ /**
+ * Creates a new {@link PropertyProvider} containing all property maps given, hereby using the given AggregationPolicy.
+ *
+ * @param policy the AggregationPolicy to be used, not null.
+ * @param providers the maps to be included, not null.
+ * @return the aggregated instance containing all given maps.
+ */
+ @Override
+ public PropertyProvider aggregate(AggregationPolicy policy, MetaInfo metaInfo, List<PropertyProvider> providers) {
+ if(metaInfo==null){
+ metaInfo = MetaInfoBuilder.of().setInfo("Aggregated")
+ .set("AggregationPolicy", policy.toString())
+ .set("providers", providers.toString())
+ .build();
+ }
+ return new AggregatedPropertyProvider(metaInfo, null, policy, providers);
+ }
+
+ /**
+ * Creates a new {@link PropertyProvider} that is mutable by adding a map based instance that overrides
+ * values fromMap the original map.
+ * @param provider the provider to be made mutable, not null.
+ * @return the mutable instance.
+ */
+ @Override
+ public PropertyProvider mutable(MetaInfo metaInfo, PropertyProvider provider) {
+ if(metaInfo==null){
+ metaInfo = MetaInfoBuilder.of(provider.getMetaInfo())
+ .set("mutableSince", Date.from(Instant.now()).toString())
+ .build();
+ }
+ PropertyProvider mutableProvider = emptyMutable(metaInfo);
+ List<PropertyProvider> providers = new ArrayList<>(2);
+ providers.add(provider);
+ providers.add(mutableProvider);
+ return new AggregatedPropertyProvider(metaInfo, mutableProvider, AggregationPolicy.OVERRIDE, providers);
+ }
+
+ /**
+ * Creates a new {@link PropertyProvider} containing only properties that are shared by all given maps,
+ * hereby later maps in the array override properties fromMap previous instances.
+ * @param aggregationPolicy the policy to resolve aggregation conflicts.
+ * @param providers the maps to be included, not null.
+ * @return the intersecting instance containing all given maps.
+ */
+ @Override
+ public PropertyProvider intersected(AggregationPolicy aggregationPolicy, List<PropertyProvider> providers) {
+ return new IntersectingPropertyProvider(aggregationPolicy, providers);
+ }
+
+ /**
+ * Creates a new {@link PropertyProvider} containing only properties fromMap the target instance, that are not contained
+ * in one of the other maps passed.
+ *
+ * @param target the base map, not null.
+ * @param subtrahendSets the maps to be subtracted, not null.
+ * @return the intersecting instance containing all given maps.
+ */
+ @Override
+ public PropertyProvider subtracted(PropertyProvider target, List<PropertyProvider> subtrahendSets) {
+ return new SubtractingPropertyProvider(target, subtrahendSets);
+ }
+
+
+ /**
+ * Creates a filtered {@link PropertyProvider} (a view) of a given base {@link }PropertyMap}. The filter hereby is
+ * applied dynamically on access, so also runtime changes of the base map are reflected appropriately.
+ *
+ * @param propertyMap the base map instance, not null.
+ * @param filter the filtger to be applied, not null.
+ * @return the new filtering instance.
+ */
+ @Override
+ public PropertyProvider filtered(Predicate<String> filter, PropertyProvider propertyMap) {
+ return new FilteredPropertyProvider(propertyMap, filter);
+ }
+
+ /**
+ * Creates a new contextual {@link PropertyProvider}. Contextual maps delegate to different instances of 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.
+ */
+ @Override
+ public PropertyProvider contextual(Supplier<PropertyProvider> mapSupplier,
+ Supplier<String> isolationKeySupplier) {
+ return new ContextualPropertyProvider(mapSupplier, isolationKeySupplier);
+ }
+
+
+ /**
+ * Creates a filtered {@link PropertyProvider} (a view) of a given base {@link }PropertyMap}. The filter hereby is
+ * applied dynamically on access, so also runtime changes of the base map are reflected appropriately.
+ *
+ * @param mainMap the main map instance, not null.
+ * @param parentMap the delegated parent map instance, not null.
+ * @return the new delegating instance.
+ */
+ @Override
+ public PropertyProvider delegating(PropertyProvider mainMap, Map<String, String> parentMap) {
+ return new DelegatingPropertyProvider(mainMap, parentMap);
+ }
+
+ /**
+ * Creates a {@link org.apache.tamaya.PropertyProvider} where all keys of a current map,
+ * existing in another map are replaced
+ * with the ones fromMap the other {@link org.apache.tamaya.PropertyProvider}. The filter hereby is
+ * applied dynamically on access, so also runtime changes of the base map are reflected appropriately.
+ * Keys not existing in the {@code mainMap}, but present in {@code replacementMao} will be hidden.
+ *
+ * @param mainMap the main map instance, which keys, present in {@code replacementMap} will be replaced
+ * with the ones
+ * in {@code replacementMap}, not null.
+ * @param replacementMap the map instance, that will replace all corresponding entries in {@code mainMap}, not null.
+ * @return the new delegating instance.
+ */
+ @Override
+ public PropertyProvider replacing(PropertyProvider mainMap, Map<String, String> replacementMap) {
+ return new ReplacingPropertyProvider(mainMap, replacementMap);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/DelegatingPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DelegatingPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/DelegatingPropertyProvider.java
new file mode 100644
index 0000000..0057bf2
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DelegatingPropertyProvider.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertyProvider;
+
+import java.util.*;
+
+/**
+ * Implementation for a {@link org.apache.tamaya.PropertyProvider} that is an aggregate of
+ * multiple child instances. Controlled by an {@link org.apache.tamaya.AggregationPolicy} the
+ * following aggregations are supported:
+ * <ul>
+ * <li><b>IGNORE: </b>Ignore all overrides.</li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * </ul>
+ */
+class DelegatingPropertyProvider implements PropertyProvider{
+
+ private static final long serialVersionUID = -1419376385695224799L;
+ private PropertyProvider mainMap;
+ private Map<String,String> parentMap;
+ private MetaInfo metaInfo;
+
+ /**
+ * Creates a mew instance, with aggregation polilcy
+ * {@code AggregationPolicy.OVERRIDE}.
+ *
+ * @param mainMap The main ConfigMap.
+ * @param parentMap The delegated parent ConfigMap.
+ */
+ public DelegatingPropertyProvider(PropertyProvider mainMap, Map<String,String> parentMap){
+ this.metaInfo =
+ MetaInfoBuilder.of().setType("delegate").set("provider", mainMap.toString()).set("delegate", parentMap.toString())
+ .build();
+ Objects.requireNonNull(parentMap);
+ this.parentMap = parentMap;
+ Objects.requireNonNull(parentMap);
+ this.parentMap = parentMap;
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ return mainMap.load();
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return keySet().contains(key);
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ return null;
+ }
+
+ @Override
+ public MetaInfo getMetaInfo(){
+ return this.metaInfo;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ Optional<String> val = mainMap.get(key);
+ if(!val.isPresent()){
+ return Optional.ofNullable(parentMap.get(key));
+ }
+ return val;
+ }
+
+ @Override
+ public Set<String> keySet(){
+ Set<String> keys = new HashSet<>(mainMap.keySet());
+ keys.addAll(parentMap.keySet());
+ return keys;
+ }
+
+ @Override
+ public String toString(){
+ return super.toString() + "(mainMap=" + mainMap + ", delegate=" + parentMap + ")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/EnvironmentPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/EnvironmentPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/EnvironmentPropertyProvider.java
new file mode 100644
index 0000000..2a4064b
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/EnvironmentPropertyProvider.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.core.properties.AbstractPropertyProvider;
+
+import java.util.Map;
+
+class EnvironmentPropertyProvider extends AbstractPropertyProvider {
+
+ private static final long serialVersionUID = 4753258482658331010L;
+
+ public Map<String,String> toMap(){
+ return System.getenv();
+ }
+
+ public EnvironmentPropertyProvider(){
+ super(MetaInfoBuilder.of().setType("env-properties").build());
+ }
+
+ @Override
+ public String toString(){
+ return "EnvironmentPropertyMap{" +
+ "props=" + super.toString() +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/FilteredPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/FilteredPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/FilteredPropertyProvider.java
new file mode 100644
index 0000000..cd83c1d
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/FilteredPropertyProvider.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertyProvider;
+import org.apache.tamaya.core.properties.AbstractPropertyProvider;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+class FilteredPropertyProvider extends AbstractPropertyProvider {
+
+ private static final long serialVersionUID = 4301042530074932562L;
+ private PropertyProvider unit;
+ private Predicate<String> filter;
+
+ public FilteredPropertyProvider(PropertyProvider configuration, Predicate<String> filter){
+ super(MetaInfoBuilder.of(configuration.getMetaInfo()).setType("filtered").set("filter", filter.toString()).build());
+ Objects.requireNonNull(configuration);
+ this.unit = configuration;
+ this.filter = filter;
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ final Map<String,String> result = new HashMap<>();
+ this.unit.toMap().entrySet().forEach(e -> {
+ if(filter.test(e.getKey())){
+ result.put(e.getKey(), e.getValue());
+ }
+ });
+ return result;
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ unit.load();
+ return super.load();
+ }
+
+ /**
+ * Apply a config change to this item. Hereby the change must be related to the same instance.
+ * @param change the config change
+ * @throws org.apache.tamaya.ConfigException if an unrelated change was passed.
+ * @throws UnsupportedOperationException when the configuration is not writable.
+ */
+ @Override
+ public void apply(ConfigChangeSet change){
+ this.unit.apply(change);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/FreezedPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/FreezedPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/FreezedPropertyProvider.java
new file mode 100644
index 0000000..fb43385
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/FreezedPropertyProvider.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertyProvider;
+
+import java.io.Serializable;
+import java.time.Instant;
+import java.util.*;
+
+/**
+ * This class models a freezed instance of an {@link org.apache.tamaya.PropertyProvider}.
+ * Created by Anatole on 28.03.14.
+ */
+final class FreezedPropertyProvider implements PropertyProvider, Serializable{
+
+ private static final long serialVersionUID = 3365413090311267088L;
+ private Map<String,Map<String,String>> fieldMMetaInfo = new HashMap<>();
+ private MetaInfo metaInfo;
+ private Map<String,String> properties = new HashMap<>();
+
+ private FreezedPropertyProvider(MetaInfo metaInfo, PropertyProvider propertyMap) {
+ Map<String, String> map = propertyMap.toMap();
+ this.properties.putAll(map);
+ this.properties = Collections.unmodifiableMap(this.properties);
+ if (metaInfo == null) {
+ this.metaInfo =
+ MetaInfoBuilder.of(propertyMap.getMetaInfo()).set("freezedAt", Instant.now().toString()).build();
+ } else {
+ this.metaInfo = metaInfo;
+ }
+ }
+
+ public static PropertyProvider of(MetaInfo metaInfo, PropertyProvider propertyProvider){
+ if(propertyProvider instanceof FreezedPropertyProvider){
+ return propertyProvider;
+ }
+ return new FreezedPropertyProvider(metaInfo, propertyProvider);
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ return ConfigChangeSet.emptyChangeSet(this);
+ }
+
+ public int size(){
+ return properties.size();
+ }
+
+ public boolean isEmpty(){
+ return properties.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return properties.containsKey(key);
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ return Collections.unmodifiableMap(this.properties);
+ }
+
+ @Override
+ public MetaInfo getMetaInfo(){
+ return this.metaInfo;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ return Optional.ofNullable(properties.get(key));
+ }
+
+ @Override
+ public Set<String> keySet(){
+ return properties.keySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/IntersectingPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/IntersectingPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/IntersectingPropertyProvider.java
new file mode 100644
index 0000000..2e82d3c
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/IntersectingPropertyProvider.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.*;
+import org.apache.tamaya.core.properties.AbstractPropertyProvider;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * Provider implementation that combines multiple other providers by intersecting
+ * the key/values common to all providers, conflicting keys are resolved using an
+ * {@link org.apache.tamaya.AggregationPolicy}.
+ */
+class IntersectingPropertyProvider extends AbstractPropertyProvider {
+
+ private List<PropertyProvider> providers;
+ private PropertyProvider aggregatedDelegate;
+
+ public IntersectingPropertyProvider(AggregationPolicy policy, List<PropertyProvider> providers) {
+ super(MetaInfoBuilder.of().setType("intersection").build());
+ this.providers = new ArrayList<>(providers);
+ aggregatedDelegate = PropertyProviders.aggregate(policy, this.providers);
+ }
+
+ public IntersectingPropertyProvider(MetaInfo metaInfo, AggregationPolicy policy, PropertyProvider... providers) {
+ super(metaInfo);
+ this.providers = Arrays.asList(Objects.requireNonNull(providers));
+ aggregatedDelegate = PropertyProviders.aggregate(policy, providers);
+ }
+
+
+ @Override
+ public Optional<String> get(String key) {
+ if (containsKey(key))
+ return aggregatedDelegate.get(key);
+ return Optional.empty();
+ }
+
+ private boolean filter(Map.Entry<String, String> entry) {
+ return containsKey(entry.getKey());
+ }
+
+ @Override
+ public boolean containsKey(String key) {
+ for (PropertyProvider prov : this.providers) {
+ if (!prov.containsKey(key)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return aggregatedDelegate.toMap().entrySet().stream().filter(en -> containsKey(en.getKey())).collect(
+ Collectors.toConcurrentMap(en -> en.getKey(), en -> en.getValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/MapBasedPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/MapBasedPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/MapBasedPropertyProvider.java
new file mode 100644
index 0000000..d782353
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/MapBasedPropertyProvider.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.core.properties.AbstractPropertyProvider;
+
+import java.beans.PropertyChangeEvent;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+
+/**
+ * Models a {@link org.apache.tamaya.PropertyProvider} that can be build using a builder pattern.
+ */
+class MapBasedPropertyProvider extends AbstractPropertyProvider {
+
+ private static final long serialVersionUID = 7601389831472839249L;
+
+ private static final Logger LOG = Logger.getLogger(MapBasedPropertyProvider.class.getName());
+ /**
+ * The unit's entries.
+ */
+ private Map<String,String> entries = new ConcurrentHashMap<>();
+
+ /**
+ * Constructor used by {@link org.apache.tamaya.core.properties.MapBasedPropertyProviderBuilder}, or subclasses.
+ *
+ * @param entries the config entries, not null.
+ */
+ MapBasedPropertyProvider(MetaInfo metaInfo, Map<String,String> entries){
+ super(metaInfo);
+ Objects.requireNonNull(entries, "entries required.");
+ this.entries.putAll(entries);
+ }
+
+
+ /**
+ * Constructor used by {@link org.apache.tamaya.core.properties.MapBasedPropertyProviderBuilder}, or subclasses.
+ *
+ * @param entries the entries
+ * @param sources the sources
+ * @param errors the errors
+ */
+ MapBasedPropertyProvider(MetaInfo metaInfo, Map<String,String> entries, Set<String> sources,
+ Collection<Throwable> errors){
+ super(metaInfo);
+ Objects.requireNonNull(entries, "entries required.");
+ this.entries.putAll(entries);
+ addSources(sources);
+ }
+
+ MapBasedPropertyProvider(MetaInfo metaInfo, Set<String> sources){
+ super(metaInfo);
+ addSources(sources);
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return new HashMap<>(this.entries);
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ // Can not reload...
+ return ConfigChangeSet.emptyChangeSet(this);
+ }
+
+ /**
+ * Apply a config change to this item. Hereby the change must be related to the same instance.
+ * @param change the config change
+ * @throws org.apache.tamaya.ConfigException if an unrelated change was passed.
+ * @throws UnsupportedOperationException when the configuration is not writable.
+ */
+ @Override
+ public void apply(ConfigChangeSet change){
+ change.getEvents().forEach(this::applyChange);
+ }
+
+ private void applyChange(PropertyChangeEvent propertyChangeEvent) {
+ LOG.finest(() -> "Applying change to map provider: " + propertyChangeEvent);
+ if(propertyChangeEvent.getNewValue()==null){
+ this.entries.remove(propertyChangeEvent.getPropertyName());
+ }
+ else{
+ this.entries.put(propertyChangeEvent.getPropertyName(), propertyChangeEvent.getNewValue().toString());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/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 d02e7ec..1c8b07d 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
@@ -33,7 +33,7 @@ import java.util.logging.Logger;
/**
* Singleton to read the configuration for the configuration system
- * from {@code META-INF/config.properties}.
+ * fromMap {@code META-INF/config.properties}.
* Created by Anatole on 17.10.2014.
*/
public final class MetaConfig {
@@ -54,7 +54,7 @@ public final class MetaConfig {
properties.putAll(read);
}
catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error reading meta configuration from " + uri);
+ LOG.log(Level.SEVERE, e, () -> "Error reading meta configuration fromMap " + uri);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/PathBasedPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PathBasedPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/PathBasedPropertyProvider.java
new file mode 100644
index 0000000..8ec3874
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/PathBasedPropertyProvider.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.*;
+import org.apache.tamaya.core.config.ConfigurationFormats;
+import org.apache.tamaya.core.properties.AbstractPropertyProvider;
+import org.apache.tamaya.spi.Bootstrap;
+import org.apache.tamaya.core.spi.ConfigurationFormat;
+import org.apache.tamaya.core.spi.ResourceLoader;
+
+import java.net.URI;
+import java.util.*;
+
+/**
+ * Created by Anatole on 16.10.2014.
+ */
+final class PathBasedPropertyProvider extends AbstractPropertyProvider {
+
+ private List<String> paths = new ArrayList<>();
+ private Map<String, String> properties = new HashMap<>();
+ private AggregationPolicy aggregationPolicy;
+
+ public PathBasedPropertyProvider(MetaInfo metaInfo, Collection<String> paths, AggregationPolicy aggregationPolicy) {
+ super(metaInfo);
+ this.paths.addAll(Objects.requireNonNull(paths));
+ this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
+ init();
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return this.properties;
+ }
+
+ private void init() {
+ List<String> sources = new ArrayList<>();
+ List<String> effectivePaths = new ArrayList<>();
+ paths.forEach((path) -> {
+ effectivePaths.add(path);
+ for (URI uri : Bootstrap.getService(ResourceLoader.class).getResources(path)) {
+ ConfigurationFormat format = ConfigurationFormats.getFormat(uri);
+ if (format != null) {
+ try {
+ Map<String, String> read = format.readConfiguration(uri);
+ sources.add(uri.toString());
+ read.forEach((k, v) -> {
+ switch (aggregationPolicy) {
+ case OVERRIDE:
+ properties.put(k, v);
+ break;
+ case IGNORE:
+ properties.putIfAbsent(k, v);
+ break;
+ case EXCEPTION:
+ default:
+ String prev = properties.putIfAbsent(k, v);
+ if (prev != null && !prev.equals(v)) {
+ throw new ConfigException("Conflicting value encountered in " + uri
+ + ": key=" + k + ", value=" + v + ", existing=" + prev);
+ }
+ }
+ });
+ }
+ catch(ConfigException e){
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ });
+ metaInfo = MetaInfoBuilder.of(getMetaInfo())
+ .setSourceExpressions(new String[effectivePaths.size()])
+ .set("sources", sources.toString()).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/ReplacingPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/ReplacingPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/ReplacingPropertyProvider.java
new file mode 100644
index 0000000..877f544
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/ReplacingPropertyProvider.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.internal;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertyProvider;
+
+import java.util.*;
+
+/**
+ * Implementation for a {@link org.apache.tamaya.PropertyProvider} that is an aggregate of
+ * multiple child instances, where all existing key/values in a replacementMap will
+ * replace values in a main map, if present there.
+ */
+class ReplacingPropertyProvider implements PropertyProvider{
+
+ private static final long serialVersionUID = -1419376385695224799L;
+ private PropertyProvider mainMap;
+ private Map<String,String> replacingMap;
+ private MetaInfo metaInfo;
+
+ /**
+ * Creates a mew instance, with aggregation polilcy
+ * {@code AggregationPolicy.OVERRIDE}.
+ *
+ * @param mainMap The main ConfigMap.
+ * @param replacingMap The replacing ConfigMap.
+ */
+ public ReplacingPropertyProvider(PropertyProvider mainMap, Map<String,String> replacingMap){
+ Objects.requireNonNull(replacingMap);
+ this.replacingMap = replacingMap;
+ Objects.requireNonNull(mainMap);
+ this.mainMap = mainMap;
+ this.metaInfo = MetaInfoBuilder.of().setType("replacing").set("mainProvider", mainMap.toString())
+ .set("replacing", replacingMap.toString()).build();
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ return mainMap.load();
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return mainMap.containsKey(key);
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ Map<String,String> result = new HashMap<>(replacingMap);
+ for(Map.Entry<String,String> en : mainMap.toMap().entrySet()){
+ if(!replacingMap.containsKey(en.getKey())){
+ result.put(en.getKey(), en.getValue());
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public MetaInfo getMetaInfo(){
+ return this.metaInfo;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ String val = replacingMap.get(key);
+ if(val == null){
+ return mainMap.get(key);
+ }
+ return Optional.ofNullable(val);
+ }
+
+ @Override
+ public Set<String> keySet(){
+ return mainMap.keySet();
+ }
+
+ /**
+ * Apply a config change to this item. Hereby the change must be related to the same instance.
+ * @param change the config change
+ * @throws org.apache.tamaya.ConfigException if an unrelated change was passed.
+ * @throws UnsupportedOperationException when the configuration is not writable.
+ */
+ @Override
+ public void apply(ConfigChangeSet change){
+ this.mainMap.apply(change);
+ }
+
+ @Override
+ public String toString(){
+ return super.toString() + "(mainMap=" + mainMap + ", replacingMap=" + replacingMap + ")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/SubtractingPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/SubtractingPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/SubtractingPropertyProvider.java
new file mode 100644
index 0000000..9a76cdc
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/SubtractingPropertyProvider.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertyProvider;
+import org.apache.tamaya.core.properties.AbstractPropertyProvider;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+class SubtractingPropertyProvider extends AbstractPropertyProvider {
+
+ private static final long serialVersionUID = 4301042530074932562L;
+ private PropertyProvider unit;
+ private List<PropertyProvider> subtrahends;
+
+ public SubtractingPropertyProvider(PropertyProvider configuration, List<PropertyProvider> subtrahends){
+ super(MetaInfoBuilder.of(configuration.getMetaInfo()).setType("sutracted").build());
+ Objects.requireNonNull(configuration);
+ this.unit = configuration;
+ this.subtrahends = new ArrayList<>(subtrahends);
+ }
+
+ private boolean filter(Map.Entry<String,String> entry){
+ for(PropertyProvider prov: subtrahends){
+ if(prov.containsKey(entry.getKey())){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ return this.unit.toMap().entrySet().stream().filter(this::filter).collect(Collectors.toMap(
+ (en) -> en.getKey(),
+ (en) -> en.getValue()
+ ));
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ unit.load();
+ return super.load();
+ }
+
+ /**
+ * Apply a config change to this item. Hereby the change must be related to the same instance.
+ * @param change the config change
+ * @throws org.apache.tamaya.ConfigException if an unrelated change was passed.
+ * @throws UnsupportedOperationException when the configuration is not writable.
+ */
+ @Override
+ public void apply(ConfigChangeSet change){
+ this.unit.apply(change);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/SystemPropertiesPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/SystemPropertiesPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/SystemPropertiesPropertyProvider.java
new file mode 100644
index 0000000..3f3760a
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/SystemPropertiesPropertyProvider.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.core.env.ConfiguredSystemProperties;
+import org.apache.tamaya.core.properties.AbstractPropertyProvider;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+class SystemPropertiesPropertyProvider extends AbstractPropertyProvider {
+
+
+ private static final long serialVersionUID = -5935940312707001199L;
+
+ public SystemPropertiesPropertyProvider(){
+ super(MetaInfoBuilder.of().setType("sys-properties").build());
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ Properties sysProps = System.getProperties();
+ if(sysProps instanceof ConfiguredSystemProperties){
+ sysProps = ((ConfiguredSystemProperties)sysProps).getInitialProperties();
+ }
+ Map<String,String> props = new HashMap<>();
+ for (Map.Entry<Object,Object> en : sysProps.entrySet()) {
+ props.put(en.getKey().toString(), en.getValue().toString());
+ }
+ return Collections.unmodifiableMap(props);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/UriBasedPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/UriBasedPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/UriBasedPropertyProvider.java
new file mode 100644
index 0000000..0604e0b
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/UriBasedPropertyProvider.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.AggregationPolicy;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.core.config.ConfigurationFormats;
+import org.apache.tamaya.core.properties.AbstractPropertyProvider;
+import org.apache.tamaya.spi.Bootstrap;
+import org.apache.tamaya.core.spi.ConfigurationFormat;
+
+import java.net.URI;
+import java.util.*;
+
+/**
+ * Created by Anatole on 16.10.2014.
+ */
+final class URIBasedPropertyProvider extends AbstractPropertyProvider {
+
+ private List<URI> uris = new ArrayList<>();
+ private Map<String,String> properties = new HashMap<>();
+ private AggregationPolicy aggregationPolicy;
+
+ public URIBasedPropertyProvider(MetaInfo metaInfo, List<URI> uris, AggregationPolicy aggregationPolicy) {
+ super(metaInfo);
+ this.uris.addAll(Objects.requireNonNull(uris));
+ this.aggregationPolicy = Objects.requireNonNull(aggregationPolicy);
+ init();
+ }
+
+ private void init(){
+ List<String> sources = new ArrayList<>();
+ for(URI uri : uris){
+ ConfigurationFormat format = ConfigurationFormats.getFormat(uri);
+ if(format != null){
+ try{
+ Map<String, String> read = format.readConfiguration(uri);
+ sources.add(uri.toString());
+ read.forEach((k, v) -> {
+ switch (aggregationPolicy) {
+ case OVERRIDE:
+ properties.put(k, v);
+ break;
+ case IGNORE:
+ properties.putIfAbsent(k, v);
+ break;
+ case EXCEPTION:
+ default:
+ String prev = properties.putIfAbsent(k, v);
+ if (prev != null) {
+ throw new ConfigException("Duplicate value encountered in " + uri
+ + ": key=" + k + ", value=" + v + ", existing=" + prev);
+ }
+ }
+ });
+ }
+ catch(ConfigException e){
+ throw e;
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ }
+ MetaInfoBuilder metaInfoBuilder = MetaInfoBuilder.of(getMetaInfo());
+ metaInfo = metaInfoBuilder
+ .setSources(sources.toString()).build();
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/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
index 478ff8c..14ea12f 100644
--- 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
@@ -86,7 +86,7 @@ public class ClassLoaderDependentApplicationEnvironmentProvider implements Envir
data.putAll(read);
}
catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error reading application environment data from " + uri);
+ LOG.log(Level.SEVERE, e, () -> "Error reading application environment data fromMap " + uri);
}
}
String applicationId = data.getOrDefault(WARID_PROP, cl.toString());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/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
index f407b93..7251896 100644
--- 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
@@ -89,7 +89,7 @@ public class ClassLoaderDependentEarEnvironmentProvider implements EnvironmentPr
data.putAll(read);
}
catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error reading ear environment data from " + uri);
+ LOG.log(Level.SEVERE, e, () -> "Error reading ear environment data fromMap " + uri);
}
}
String earId = data.getOrDefault(EARID_PROP, cl.toString());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java
index 575dc3d..9c6ecbe 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/env/SystemClassLoaderEnvironmentProvider.java
@@ -34,7 +34,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * System environment provider (loaded only once using the system class loader) that loads additional environment properties from the classpath evaluating
+ * System environment provider (loaded only once using the system class loader) that loads additional environment properties fromMap the classpath evaluating
* {@code META-INF/env/system.properties, META-INF/env/system.xml and META-INF/env/system.ini}.
*/
public class SystemClassLoaderEnvironmentProvider implements EnvironmentProvider {
@@ -69,7 +69,7 @@ public class SystemClassLoaderEnvironmentProvider implements EnvironmentProvider
builder.setAll(data);
}
catch(Exception e){
- LOG.log(Level.SEVERE, e, () -> "Error readong environment data from " + uri);
+ LOG.log(Level.SEVERE, e, () -> "Error readong environment data fromMap " + uri);
}
}
builder.setParent(parentEnvironment);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/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 1b0bada..cb76d95 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
@@ -60,6 +60,7 @@ public class IniFormat implements ConfigurationFormat{
lineNum++;
line = line.trim();
if(line.isEmpty()){
+ line = reader.readLine();
continue;
}
if(line.startsWith("[")){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
index 63f712e..fe79615 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
@@ -56,7 +56,7 @@ public class ConfiguredField {
}
/**
- * Evaluate the initial value from the configuration and apply it to the field.
+ * Evaluate the initial value fromMap the configuration and apply it to the field.
*
* @param target the target instance.
* @throws ConfigException if evaluation or conversion failed.
@@ -185,7 +185,7 @@ public class ConfiguredField {
}
/**
- * This method checks if the given (qualified) configuration key is referenced from this field.
+ * This method checks if the given (qualified) configuration key is referenced fromMap this field.
* This is useful to determine, if a key changed in a configuration should trigger any change events
* on the related instances.
*
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
index c037c41..00f0958 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
@@ -40,7 +40,7 @@ public final class ConfiguredInstancesManager implements PropertyChangeListener{
private final Object LOCK = new Object();
private ConfiguredInstancesManager(){
-// Configuration.addGlobalPropertyChangeListener(this);
+// Configuration.addConfigChangeListener(this);
}
public static <T> void register(ConfiguredType configuredType, Object instance) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
index 6e39a25..970a748 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
@@ -123,7 +123,7 @@ public class ConfiguredMethod {
}
/**
- * This method checks if the given (qualified) configuration key is referenced from this field.
+ * This method checks if the given (qualified) configuration key is referenced fromMap this field.
* This is useful to determine, if a key changed in a configuration should trigger any change events
* on the related instances.
*
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
index 0bdf367..d7f359a 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/logging/Slf4jLogger.java
@@ -69,7 +69,7 @@ public class Slf4jLogger extends AbstractDelegatingLogger {
@Override
public Level getLevel() {
final Level level;
- // Verify from the wider (trace) to the narrower (error)
+ // Verify fromMap the wider (trace) to the narrower (error)
if (logger.isTraceEnabled()) {
level = Level.FINEST;
} else if (logger.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathResolver.java
index a7f09ef..9d4e96b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathResolver.java
@@ -18,10 +18,15 @@
*/
package org.apache.tamaya.core.internal.resources;
+import org.apache.tamaya.core.internal.resources.io.PathMatchingResourcePatternResolver;
+import org.apache.tamaya.core.internal.resources.io.Resource;
+
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
public class AntPathClasspathResolver implements PathResolver{
@@ -33,22 +38,38 @@ public class AntPathClasspathResolver implements PathResolver{
@Override
public Collection<URI> resolve(ClassLoader classLoader, Stream<String> expressions){
+ PathMatchingResourcePatternResolver resolver = PathMatchingResourcePatternResolver.of(classLoader);
List<URI> result = new ArrayList<>();
expressions.forEach((expression) -> {
- if(expression.startsWith("classpath:")){
- String exp = expression.substring("classpath:".length());
- URL url = classLoader.getResource(exp);
- if(url != null){
- try{
- result.add(url.toURI());
- }
- catch(URISyntaxException e){
+ try {
+ Resource[] resources = resolver.getResources(expression);
+ for (Resource res : resources) {
+ try {
+ result.add(res.getURI());
+ } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
+ catch(IOException e){
+ // TODO log
+ }
});
+// if(expression.startsWith("classpath:")){
+// String exp = expression.substring("classpath:".length());
+// URL url = classLoader.getResource(exp);
+// if(url != null){
+// try{
+// result.add(url.toURI());
+// }
+// catch(URISyntaxException e){
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// }
+// }
+// });
return result;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java
index 4f3a898..fe4ca28 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java
@@ -18,6 +18,9 @@
*/
package org.apache.tamaya.core.internal.resources;
+import org.apache.tamaya.core.internal.resources.io.PathMatchingResourcePatternResolver;
+import org.apache.tamaya.core.internal.resources.io.Resource;
+
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -34,31 +37,49 @@ public class AntPathClasspathsResolver implements PathResolver{
@Override
public Collection<URI> resolve(ClassLoader classLoader, Stream<String> expressions){
+ PathMatchingResourcePatternResolver resolver = PathMatchingResourcePatternResolver.of(classLoader);
List<URI> result = new ArrayList<>();
- Objects.requireNonNull(classLoader);
expressions.forEach((expression) -> {
- if(expression.startsWith("classpath*:")){
- String exp = expression.substring("classpath*:".length());
- Enumeration<URL> urls;
- try{
- urls = classLoader.getResources(exp);
- while(urls.hasMoreElements()){
- URL url = (URL) urls.nextElement();
- try{
- result.add(url.toURI());
- }
- catch(URISyntaxException e){
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ try {
+ Resource[] resources = resolver.getResources(expression);
+ for (Resource res : resources) {
+ try {
+ result.add(res.getURI());
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
}
- catch(IOException e1){
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
+ }
+ catch(IOException e){
+ // TODO log
}
});
+// List<URI> result = new ArrayList<>();
+// Objects.requireNonNull(classLoader);
+// expressions.forEach((expression) -> {
+// if(expression.startsWith("classpath*:")){
+// String exp = expression.substring("classpath*:".length());
+// Enumeration<URL> urls;
+// try{
+// urls = classLoader.getResources(exp);
+// while(urls.hasMoreElements()){
+// URL url = (URL) urls.nextElement();
+// try{
+// result.add(url.toURI());
+// }
+// catch(URISyntaxException e){
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// }
+// }
+// catch(IOException e1){
+// // TODO Auto-generated catch block
+// e1.printStackTrace();
+// }
+// }
+// });
return result;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFileResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFileResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFileResolver.java
index 7b0a2fe..09758aa 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFileResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFileResolver.java
@@ -18,7 +18,11 @@
*/
package org.apache.tamaya.core.internal.resources;
+import org.apache.tamaya.core.internal.resources.io.PathMatchingResourcePatternResolver;
+import org.apache.tamaya.core.internal.resources.io.Resource;
+
import java.io.File;
+import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.util.stream.Stream;
@@ -33,15 +37,23 @@ public class AntPathFileResolver implements PathResolver{
@Override
public Collection<URI> resolve(ClassLoader classLoader, Stream<String> expressions){
+ PathMatchingResourcePatternResolver resolver = PathMatchingResourcePatternResolver.of(classLoader);
List<URI> result = new ArrayList<>();
expressions.forEach((expression) -> {
- if(expression.startsWith("file:")){
- String exp = expression.substring("file:".length());
- File f = new File(exp);
- if(f.exists() && f.isFile()){
- result.add(f.toURI());
+ try {
+ Resource[] resources = resolver.getResources(expression);
+ for (Resource res : resources) {
+ try {
+ result.add(res.getURI());
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
+ catch(IOException e){
+ // TODO log
+ }
});
return result;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a55d1c97/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java
index 852bdfc..7290f45 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java
@@ -18,7 +18,11 @@
*/
package org.apache.tamaya.core.internal.resources;
+import org.apache.tamaya.core.internal.resources.io.PathMatchingResourcePatternResolver;
+import org.apache.tamaya.core.internal.resources.io.Resource;
+
import java.io.File;
+import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.util.stream.Stream;
@@ -32,15 +36,23 @@ public class AntPathFilesResolver implements PathResolver{
@Override
public Collection<URI> resolve(ClassLoader classLoader, Stream<String> expressions){
+ PathMatchingResourcePatternResolver resolver = PathMatchingResourcePatternResolver.of(classLoader);
List<URI> result = new ArrayList<>();
expressions.forEach((expression) -> {
- if(expression.startsWith("file*:")){
- String exp = expression.substring("file:".length());
- File f = new File(exp);
- if(f.exists() && f.isFile()){
- result.add(f.toURI());
+ try {
+ Resource[] resources = resolver.getResources(expression);
+ for (Resource res : resources) {
+ try {
+ result.add(res.getURI());
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
+ catch(IOException e){
+ // TODO log
+ }
});
return result;
}