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 2018/01/03 00:09:07 UTC
[11/18] incubator-tamaya-extensions git commit: Rewrite/adaptation
based on JSR API.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java
index 6b0e35e..580e283 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java
@@ -18,8 +18,9 @@
*/
package org.apache.tamaya.mutableconfig;
-import org.apache.tamaya.Configuration;
+import org.apache.tamaya.mutableconfig.spi.MutableConfigSource;
+import javax.config.Config;
import java.util.Collection;
import java.util.Map;
@@ -34,26 +35,26 @@ import java.util.Map;
* As a consequence clients should first check, using the corresponding methods, if entries can be added/updated or
* removed.
*
- * This class should only used in a single threaded context, though all methods inherited from {@link Configuration}
+ * This class should only used in a single threaded context, though all methods inherited from {@link Config}
* must be thread-safe. Methods handling configuration changes are expected to be used in a single threaded environment
* only. For multi-threaded us create a new instance of {@link MutableConfiguration} for each thread.
*/
-public interface MutableConfiguration extends Configuration {
+public interface MutableConfiguration extends Config {
/**
* Storesd the changes. After a commit the change is not editable anymore. All changes applied will be written to
* the corresponding configuration backend.
*
- * NOTE that changes applied must not necessarily be visible in the current {@link Configuration} instance,
- * since visibility of changes also depends on the ordinals set on the {@link org.apache.tamaya.spi.PropertySource}s
+ * NOTE that changes applied must not necessarily be visible in the current {@link Config} instance,
+ * since visibility of changes also depends on the ordinals set on the {@link javax.config.spi.ConfigSource}s
* configured.
- * @throws org.apache.tamaya.ConfigException if the request already has been committed or cancelled, or the commit fails.
+ * @throws IllegalStateException if the request already has been committed or cancelled, or the commit fails.
*/
void store();
/**
* Access the current configuration change context, built up on all the change context of the participating
- * {@link org.apache.tamaya.mutableconfig.spi.MutablePropertySource} instances.
+ * {@link MutableConfigSource} instances.
* @return the colleted changes as one single config change for the current transaction, or null, if no transaction
* is active.
*/
@@ -61,7 +62,7 @@ public interface MutableConfiguration extends Configuration {
/**
* Access the active {@link ChangePropagationPolicy}.This policy controls how configuration changes are written/published
- * to the known {@link org.apache.tamaya.mutableconfig.spi.MutablePropertySource} instances of a {@link Configuration}.
+ * to the known {@link MutableConfigSource} instances of a {@link Config}.
* @return he active {@link ChangePropagationPolicy}, never null.
*/
ChangePropagationPolicy getChangePropagationPolicy();
@@ -72,7 +73,7 @@ public interface MutableConfiguration extends Configuration {
* @param key the property's key, not null.
* @param value the property's value, not null.
* @return the former property value, or null.
- * @throws org.apache.tamaya.ConfigException if the key/value cannot be added, or the request is read-only.
+ * @throws IllegalStateException if the key/value cannot be added, or the request is read-only.
*/
MutableConfiguration put(String key, String value);
@@ -80,14 +81,14 @@ public interface MutableConfiguration extends Configuration {
* Puts all given configuration entries. This method should check that all given properties are
* basically removable, as defined by #isWritable. If any of the passed keys is not writable during this initial
* check, the operation should not perform any configuration changes and throw a
- * {@link org.apache.tamaya.ConfigException}. If errors occur afterwards, when the properties are effectively
+ * {@link IllegalArgumentException}. If errors occur afterwards, when the properties are effectively
* written back to the backends, the errors should be collected and returned as part of the ConfigException
* payload. Nevertheless the operation should in that case remove all entries as far as possible and abort the
* writing operation.
*
* @param properties the properties tobe written, not null.
* @return the config change request
- * @throws org.apache.tamaya.ConfigException if any of the given properties could not be written, or the request
+ * @throws IllegalStateException if any of the given properties could not be written, or the request
* is read-only.
*/
MutableConfiguration putAll(Map<String, String> properties);
@@ -96,14 +97,14 @@ public interface MutableConfiguration extends Configuration {
* Removes all given configuration entries. This method should check that all given properties are
* basically removable, as defined by #isRemovable. If any of the passed keys is not removable during this initial
* check, the operation should not perform any configuration changes and throw a
- * {@link org.apache.tamaya.ConfigException}. If errors
+ * {@link IllegalArgumentException}. If errors
* occur afterwards, when the properties are effectively written back to the backends, the errors should be
* collected and returned as part of the ConfigException payload. Nevertheless the operation should in that case
* remove all entries as far as possible and abort the writing operation.
*
* @param keys the property's keys to be removedProperties, not null.
* @return the config change request
- * @throws org.apache.tamaya.ConfigException if any of the given keys could not be removedProperties, or the
+ * @throws IllegalStateException if any of the given keys could not be removedProperties, or the
* request is read-only.
*/
MutableConfiguration remove(Collection<String> keys);
@@ -111,14 +112,14 @@ public interface MutableConfiguration extends Configuration {
/**
* Removes all given configuration entries. This method should check that all given properties are
* basically removable, as defined by #isRemovable. If any of the passed keys is not removable during this initial
- * check, the operation should not perform any configuration changes and throw a {@link org.apache.tamaya.ConfigException}. If errors
+ * check, the operation should not perform any configuration changes and throw a {@link IllegalArgumentException}. If errors
* occur afterwards, when the properties are effectively written back to the backends, the errors should be
* collected and returned as part of the ConfigException payload. Nevertheless the operation should in that case
* remove all entries as far as possible and abort the writing operation.
*
* @param keys the property's keys to be removedProperties, not null.
* @return the config change request
- * @throws org.apache.tamaya.ConfigException if any of the given keys could not be removedProperties, or the request is read-only.
+ * @throws IllegalStateException if any of the given keys could not be removedProperties, or the request is read-only.
*/
MutableConfiguration remove(String... keys);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java
index 1198c09..179ceda 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java
@@ -18,16 +18,14 @@
*/
package org.apache.tamaya.mutableconfig;
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.mutableconfig.spi.MutableConfigSource;
import org.apache.tamaya.spi.ServiceContextManager;
+import javax.config.Config;
+import javax.config.ConfigProvider;
+import javax.config.spi.ConfigSource;
import java.util.Arrays;
-import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
@@ -46,7 +44,7 @@ public final class MutableConfigurationProvider {
MutableConfigurationProviderSpi spi = ServiceContextManager.getServiceContext().getService(
MutableConfigurationProviderSpi.class) ;
if(spi==null){
- throw new ConfigException("Failed to initialize MutableConfigurationProviderSpi - " +
+ throw new IllegalArgumentException("Failed to initialize MutableConfigurationProviderSpi - " +
"mutable configuration support.");
}
return spi;
@@ -58,50 +56,50 @@ public final class MutableConfigurationProvider {
/**
* Creates a new {@link MutableConfiguration} for the given default configuration, using all
- * {@link MutablePropertySource} instances found in its context and {@code autoCommit = false}.
+ * {@link MutableConfigSource} instances found in its context and {@code autoCommit = false}.
*
* @return a new MutableConfiguration instance
*/
public static MutableConfiguration createMutableConfiguration(){
return spi().createMutableConfiguration(
- ConfigurationProvider.getConfiguration(), getApplyMostSignificantOnlyChangePolicy());
+ ConfigProvider.getConfig(), getApplyMostSignificantOnlyChangePolicy());
}
/**
* Creates a new {@link MutableConfiguration} for the given default configuration, using all
- * {@link MutablePropertySource} instances found in its context and {@code autoCommit = false}.
+ * {@link MutableConfigSource} instances found in its context and {@code autoCommit = false}.
* @param changePropgationPolicy policy that defines how a change is written back and which property
* sources are finally eligible for a write operation.
* @return a new MutableConfiguration instance, with the given change policy active.
*/
public static MutableConfiguration createMutableConfiguration(ChangePropagationPolicy changePropgationPolicy){
return spi().createMutableConfiguration(
- ConfigurationProvider.getConfiguration(), changePropgationPolicy);
+ ConfigProvider.getConfig(), changePropgationPolicy);
}
/**
* Creates a new {@link MutableConfiguration} for the given configuration, using all
- * {@link MutablePropertySource} instances found in its context and {@code MOST_SIGNIFICANT_ONLY_POLICY}
+ * {@link MutableConfigSource} instances found in its context and {@code MOST_SIGNIFICANT_ONLY_POLICY}
* configuration writing policy.
*
* @param configuration the configuration to use to write the changes/config.
* @return a new MutableConfiguration instance
*/
- public static MutableConfiguration createMutableConfiguration(Configuration configuration){
+ public static MutableConfiguration createMutableConfiguration(Config configuration){
return createMutableConfiguration(configuration, MOST_SIGNIFICANT_ONLY_POLICY);
}
/**
* Creates a new {@link MutableConfiguration} for the given configuration, using all
- * {@link MutablePropertySource} instances found in its context and {@code ALL_POLICY}
+ * {@link MutableConfigSource} instances found in its context and {@code ALL_POLICY}
* configuration writing policy.
*
* @param configuration the configuration to use to write the changes/config.
* @param changePropagationPolicy the configuration writing policy.
* @return a new MutableConfiguration instance
*/
- public static MutableConfiguration createMutableConfiguration(Configuration configuration, ChangePropagationPolicy changePropagationPolicy){
+ public static MutableConfiguration createMutableConfiguration(Config configuration, ChangePropagationPolicy changePropagationPolicy){
return spi().createMutableConfiguration(configuration, changePropagationPolicy);
}
@@ -147,13 +145,13 @@ public final class MutableConfigurationProvider {
*/
private static final ChangePropagationPolicy ALL_POLICY = new ChangePropagationPolicy() {
@Override
- public void applyChange(ConfigChangeRequest change, Collection<PropertySource> propertySources) {
- for(PropertySource propertySource: propertySources){
- if(propertySource instanceof MutablePropertySource){
- MutablePropertySource target = (MutablePropertySource)propertySource;
+ public void applyChange(ConfigChangeRequest change, Iterable<ConfigSource> propertySources) {
+ for(ConfigSource propertySource: propertySources){
+ if(propertySource instanceof MutableConfigSource){
+ MutableConfigSource target = (MutableConfigSource)propertySource;
try{
target.applyChange(change);
- }catch(ConfigException e){
+ }catch(Exception e){
LOG.warning("Failed to store changes '"+change+"' not applicable to "+target.getName()
+"("+target.getClass().getName()+").");
}
@@ -169,13 +167,13 @@ public final class MutableConfigurationProvider {
*/
private static final ChangePropagationPolicy MOST_SIGNIFICANT_ONLY_POLICY = new ChangePropagationPolicy() {
@Override
- public void applyChange(ConfigChangeRequest change, Collection<PropertySource> propertySources) {
- for(PropertySource propertySource: propertySources){
- if(propertySource instanceof MutablePropertySource){
- MutablePropertySource target = (MutablePropertySource)propertySource;
+ public void applyChange(ConfigChangeRequest change, Iterable<ConfigSource> propertySources) {
+ for(ConfigSource propertySource: propertySources){
+ if(propertySource instanceof MutableConfigSource){
+ MutableConfigSource target = (MutableConfigSource)propertySource;
try{
target.applyChange(change);
- }catch(ConfigException e){
+ }catch(Exception e){
LOG.warning("Failed to store changes '"+change+"' not applicable to "+target.getName()
+"("+target.getClass().getName()+").");
}
@@ -192,7 +190,7 @@ public final class MutableConfigurationProvider {
*/
private static final ChangePropagationPolicy NONE_POLICY = new ChangePropagationPolicy() {
@Override
- public void applyChange(ConfigChangeRequest change, Collection<PropertySource> propertySources) {
+ public void applyChange(ConfigChangeRequest change, Iterable<ConfigSource> propertySources) {
LOG.warning("Cannot store changes '"+change+"': prohibited by change policy (read-only).");
}
};
@@ -209,14 +207,14 @@ public final class MutableConfigurationProvider {
}
@Override
- public void applyChange(ConfigChangeRequest change, Collection<PropertySource> propertySources) {
- for(PropertySource propertySource: propertySources){
- if(propertySource instanceof MutablePropertySource){
+ public void applyChange(ConfigChangeRequest change, Iterable<ConfigSource> propertySources) {
+ for(ConfigSource propertySource: propertySources){
+ if(propertySource instanceof MutableConfigSource){
if(this.propertySourceNames.contains(propertySource.getName())) {
- MutablePropertySource target = (MutablePropertySource) propertySource;
+ MutableConfigSource target = (MutableConfigSource) propertySource;
try{
target.applyChange(change);
- }catch(ConfigException e){
+ }catch(Exception e){
LOG.warning("Failed to store changes '"+change+"' not applicable to "+target.getName()
+"("+target.getClass().getName()+").");
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
index 0fe3e23..7d331aa 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
@@ -18,25 +18,15 @@
*/
package org.apache.tamaya.mutableconfig.internal;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.ConfigQuery;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.mutableconfig.ChangePropagationPolicy;
import org.apache.tamaya.mutableconfig.MutableConfiguration;
import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.mutableconfig.spi.MutableConfigSource;
import org.osgi.service.component.annotations.Component;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.UUID;
+import javax.config.Config;
+import javax.config.spi.ConfigSource;
+import java.util.*;
import java.util.logging.Logger;
@@ -47,10 +37,10 @@ import java.util.logging.Logger;
public class DefaultMutableConfiguration implements MutableConfiguration {
private static final Logger LOG = Logger.getLogger(DefaultMutableConfiguration.class.getName());
private ConfigChangeRequest changeRequest = new ConfigChangeRequest(UUID.randomUUID().toString());
- private final Configuration config;
+ private final Config config;
private ChangePropagationPolicy changePropagationPolicy;
- public DefaultMutableConfiguration(Configuration config, ChangePropagationPolicy changePropagationPolicy){
+ public DefaultMutableConfiguration(Config config, ChangePropagationPolicy changePropagationPolicy){
this.config = Objects.requireNonNull(config);
this.changePropagationPolicy = Objects.requireNonNull(changePropagationPolicy);
}
@@ -65,11 +55,11 @@ public class DefaultMutableConfiguration implements MutableConfiguration {
return changeRequest;
}
- protected List<MutablePropertySource> getMutablePropertySources() {
- List<MutablePropertySource> result = new ArrayList<>();
- for(PropertySource propertySource:this.config.getContext().getPropertySources()) {
- if(propertySource instanceof MutablePropertySource){
- result.add((MutablePropertySource)propertySource);
+ protected List<MutableConfigSource> getMutablePropertySources() {
+ List<MutableConfigSource> result = new ArrayList<>();
+ for(ConfigSource propertySource:this.config.getConfigSources()) {
+ if(propertySource instanceof MutableConfigSource){
+ result.add((MutableConfigSource)propertySource);
}
}
return result;
@@ -97,69 +87,35 @@ public class DefaultMutableConfiguration implements MutableConfiguration {
@Override
public void store() {
- this.changePropagationPolicy.applyChange(changeRequest, config.getContext().getPropertySources());
+ this.changePropagationPolicy.applyChange(changeRequest, config.getConfigSources());
}
@Override
public MutableConfiguration remove(Collection<String> keys) {
- for(MutablePropertySource target:getMutablePropertySources()) {
+ for(MutableConfigSource target:getMutablePropertySources()) {
changeRequest.removeAll(keys);
}
return this;
}
@Override
- public String get(String key) {
- return this.config.get(key);
+ public <T> T getValue(String key, Class<T> type) {
+ return this.config.getValue(key, type);
}
@Override
- public String getOrDefault(String key, String defaultValue) {
- return this.config.getOrDefault(key, defaultValue);
+ public <T> Optional<T> getOptionalValue(String key, Class<T> type) {
+ return this.config.getOptionalValue(key,type);
}
@Override
- public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
- return this.config.getOrDefault(key, type, defaultValue);
+ public Iterable<String> getPropertyNames() {
+ return this.config.getPropertyNames();
}
@Override
- public <T> T get(String key, Class<T> type) {
- return this.config.get(key, type);
- }
-
- @Override
- public <T> T get(String key, TypeLiteral<T> type) {
- return this.config.get(key, type);
- }
-
- @Override
- public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
- return this.config.getOrDefault(key, type, defaultValue);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return this.config.getProperties();
- }
-
- @Override
- public Configuration with(ConfigOperator operator) {
- return operator.operate(this);
- }
-
- @Override
- public <T> T query(ConfigQuery<T> query) {
- return query.query(this);
- }
-
- @Override
- public ConfigurationContext getContext() {
- return config.getContext();
- }
-
- private Collection<PropertySource> getPropertySources() {
- return this.config.getContext().getPropertySources();
+ public Iterable<ConfigSource> getConfigSources() {
+ return this.config.getConfigSources();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.java
index 1ab38a8..6d7f57b 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.java
@@ -18,22 +18,23 @@
*/
package org.apache.tamaya.mutableconfig.internal;
-import org.apache.tamaya.Configuration;
import org.apache.tamaya.mutableconfig.ChangePropagationPolicy;
import org.apache.tamaya.mutableconfig.MutableConfiguration;
import org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi;
import org.osgi.service.component.annotations.Component;
+import javax.config.Config;
+
/**
* SPI implementation that creates instances of {@link DefaultMutableConfiguration}, hereby for
- * each instance of {@link Configuration} a new instance has to be returned.
+ * each instance of {@link Config} a new instance has to be returned.
*/
@Component
public class DefaultMutableConfigurationSpi implements MutableConfigurationProviderSpi {
@Override
- public MutableConfiguration createMutableConfiguration(Configuration configuration,
+ public MutableConfiguration createMutableConfiguration(Config configuration,
ChangePropagationPolicy propagationPolicy){
return new DefaultMutableConfiguration(configuration, propagationPolicy);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesConfigSource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesConfigSource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesConfigSource.java
new file mode 100644
index 0000000..490c568
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesConfigSource.java
@@ -0,0 +1,159 @@
+/*
+ * 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.mutableconfig.propertysources;
+
+import org.apache.tamaya.base.configsource.BaseConfigSource;
+import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
+import org.apache.tamaya.mutableconfig.spi.MutableConfigSource;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Simple implementation of a mutable {@link javax.config.spi.ConfigSource} for .properties files.
+ */
+public class MutablePropertiesConfigSource extends BaseConfigSource
+implements MutableConfigSource {
+
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(MutablePropertiesConfigSource.class.getName());
+
+ /**
+ * The configuration resource's URL.
+ */
+ private File file;
+
+ /**
+ * The current properties.
+ */
+ private Map<String, String> properties = new HashMap<>();
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param propertiesLocation the URL encoded location, not null.
+ */
+ public MutablePropertiesConfigSource(File propertiesLocation) {
+ this(propertiesLocation, 0);
+ }
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param propertiesLocation the URL encoded location, not null.
+ * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property
+ * source's properties.
+ */
+ public MutablePropertiesConfigSource(File propertiesLocation, int defaultOrdinal) {
+ super(propertiesLocation.toString(), defaultOrdinal);
+ try {
+ this.file = propertiesLocation;
+ refresh();
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Cannot convert file to URL: " + propertiesLocation, e);
+ }
+ }
+
+
+ @Override
+ public String getValue(String key) {
+ Map<String,String> properties = getProperties();
+ return properties.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(this.properties);
+ }
+
+ /**
+ * loads the Properties from the given URL
+ *
+ * @throws IllegalStateException in case of an error while reading properties-file
+ */
+ public void refresh() {
+ try (InputStream stream = new FileInputStream(file)) {
+ Map<String, String> properties = new HashMap<>();
+ Properties props = new Properties();
+ props.load(stream);
+ for (String key : props.stringPropertyNames()) {
+ properties.put(key, props.getProperty(key));
+ }
+ LOG.log(Level.FINEST, "Loaded properties from " + file);
+ this.properties = properties;
+ } catch (IOException e) {
+ LOG.log(Level.FINEST, "Cannot load properties from " + file, e);
+ }
+ }
+
+ @Override
+ public void applyChange(ConfigChangeRequest change) {
+ if(change.isEmpty()){
+ LOG.info("Nothing to commit for transaction: " + change.getTransactionID());
+ return;
+ }
+ if(!file.exists()){
+ try {
+ if(!file.createNewFile()){
+ throw new IllegalArgumentException("Failed to create config file " + file);
+ }
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Failed to create config file " + file, e);
+ }
+ }
+ for(Map.Entry<String,String> en:change.getAddedProperties().entrySet()){
+ int index = en.getKey().indexOf('?');
+ if(index>0){
+ this.properties.put(en.getKey().substring(0, index), en.getValue());
+ }else{
+ this.properties.put(en.getKey(), en.getValue());
+ }
+ }
+ for(String rmKey:change.getRemovedProperties()){
+ this.properties.remove(rmKey);
+ }
+ try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){
+ Properties props = new Properties();
+ for (Map.Entry<String,String> en : this.properties.entrySet()) {
+ props.setProperty(en.getKey(), en.getValue());
+ }
+ props.store(bos, "Properties written from Tamaya on " + new Date());
+ bos.flush();
+ }
+ catch(Exception e){
+ throw new IllegalArgumentException("Failed to write config to " + file, e);
+ }
+ }
+
+ @Override
+ protected String toStringValues() {
+ return super.toStringValues() +
+ " file=" + file + '\n';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
deleted file mode 100644
index 659dab2..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
+++ /dev/null
@@ -1,164 +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.mutableconfig.propertysources;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Simple implementation of a mutable {@link org.apache.tamaya.spi.PropertySource} for .properties files.
- */
-public class MutablePropertiesPropertySource extends BasePropertySource
-implements MutablePropertySource{
-
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(MutablePropertiesPropertySource.class.getName());
-
- /**
- * The configuration resource's URL.
- */
- private File file;
-
- /**
- * The current properties.
- */
- private Map<String, String> properties = new HashMap<>();
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- */
- public MutablePropertiesPropertySource(File propertiesLocation) {
- this(propertiesLocation, 0);
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property
- * source's properties.
- */
- public MutablePropertiesPropertySource(File propertiesLocation, int defaultOrdinal) {
- super(propertiesLocation.toString(), defaultOrdinal);
- try {
- this.file = propertiesLocation;
- refresh();
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Cannot convert file to URL: " + propertiesLocation, e);
- }
- }
-
-
- @Override
- public PropertyValue get(String key) {
- Map<String,PropertyValue> properties = getProperties();
- return properties.get(key);
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return PropertyValue.map(this.properties, getName());
- }
-
- /**
- * loads the Properties from the given URL
- *
- * @throws IllegalStateException in case of an error while reading properties-file
- */
- public void refresh() {
- try (InputStream stream = new FileInputStream(file)) {
- Map<String, String> properties = new HashMap<>();
- Properties props = new Properties();
- props.load(stream);
- for (String key : props.stringPropertyNames()) {
- properties.put(key, props.getProperty(key));
- }
- LOG.log(Level.FINEST, "Loaded properties from " + file);
- this.properties = properties;
- } catch (IOException e) {
- LOG.log(Level.FINEST, "Cannot load properties from " + file, e);
- }
- }
-
- @Override
- public void applyChange(ConfigChangeRequest change) {
- if(change.isEmpty()){
- LOG.info("Nothing to commit for transaction: " + change.getTransactionID());
- return;
- }
- if(!file.exists()){
- try {
- if(!file.createNewFile()){
- throw new ConfigException("Failed to create config file " + file);
- }
- } catch (IOException e) {
- throw new ConfigException("Failed to create config file " + file, e);
- }
- }
- for(Map.Entry<String,String> en:change.getAddedProperties().entrySet()){
- int index = en.getKey().indexOf('?');
- if(index>0){
- this.properties.put(en.getKey().substring(0, index), en.getValue());
- }else{
- this.properties.put(en.getKey(), en.getValue());
- }
- }
- for(String rmKey:change.getRemovedProperties()){
- this.properties.remove(rmKey);
- }
- try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){
- Properties props = new Properties();
- for (Map.Entry<String,String> en : this.properties.entrySet()) {
- props.setProperty(en.getKey(), en.getValue());
- }
- props.store(bos, "Properties written from Tamaya on " + new Date());
- bos.flush();
- }
- catch(Exception e){
- throw new ConfigException("Failed to write config to " + file, e);
- }
- }
-
- @Override
- protected String toStringValues() {
- return super.toStringValues() +
- " file=" + file + '\n';
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesConfigSource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesConfigSource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesConfigSource.java
new file mode 100644
index 0000000..6c654c6
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesConfigSource.java
@@ -0,0 +1,162 @@
+/*
+ * 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.mutableconfig.propertysources;
+
+import org.apache.tamaya.base.configsource.BaseConfigSource;
+import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
+import org.apache.tamaya.mutableconfig.spi.MutableConfigSource;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Simple implementation of a mutable {@link javax.config.spi.ConfigSource} for .xml properties files.
+ */
+public class MutableXmlPropertiesConfigSource extends BaseConfigSource
+implements MutableConfigSource {
+
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(MutableXmlPropertiesConfigSource.class.getName());
+
+ /**
+ * The configuration resource's URL.
+ */
+ private File file;
+
+ /**
+ * The current properties.
+ */
+ private Map<String, String> properties = new HashMap<>();
+
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param propertiesLocation the URL encoded location, not null.
+ */
+ public MutableXmlPropertiesConfigSource(File propertiesLocation) {
+ this(propertiesLocation, 0);
+ }
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param propertiesLocation the URL encoded location, not null.
+ * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property
+ * source's properties.
+ */
+ public MutableXmlPropertiesConfigSource(File propertiesLocation, int defaultOrdinal) {
+ super(propertiesLocation.toString(), defaultOrdinal);
+ try {
+ this.file = propertiesLocation;
+ load();
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Cannot convert file to URL: " + propertiesLocation, e);
+ }
+ }
+
+
+
+ @Override
+ public String getValue(String key) {
+ return this.properties.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(this.properties);
+ }
+
+ /**
+ * loads the Properties from the given URL
+ *
+ * @throws IllegalStateException in case of an error while reading properties-file
+ */
+ private void load() {
+ try (InputStream stream = new FileInputStream(file)) {
+ Map<String, String> properties = new HashMap<>();
+ Properties props = new Properties();
+ props.loadFromXML(stream);
+ for (String key : props.stringPropertyNames()) {
+ properties.put(key, props.getProperty(key));
+ }
+ this.properties = properties;
+ LOG.log(Level.FINEST, "Loaded properties from " + file);
+ this.properties = properties;
+ } catch (IOException e) {
+ LOG.log(Level.FINEST, "Cannot refresh properties from " + file, e);
+ }
+ }
+
+ @Override
+ public void applyChange(ConfigChangeRequest configChange) {
+ if(configChange.isEmpty()){
+ LOG.info("Nothing to commit for transaction: " + configChange.getTransactionID());
+ return;
+ }
+ if(!file.exists()){
+ try {
+ if(!file.createNewFile()){
+ throw new IllegalStateException("Failed to create config file " + file);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to create config file " + file, e);
+ }
+ }
+ for(Map.Entry<String,String> en:configChange.getAddedProperties().entrySet()){
+ int index = en.getKey().indexOf('?');
+ if(index>0){
+ this.properties.put(en.getKey().substring(0, index), en.getValue());
+ }else{
+ this.properties.put(en.getKey(), en.getValue());
+ }
+ }
+ for(String rmKey:configChange.getRemovedProperties()){
+ this.properties.remove(rmKey);
+ }
+ try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){
+ Properties props = new Properties();
+ for (Map.Entry<String,String> en : this.properties.entrySet()) {
+ props.setProperty(en.getKey(), en.getValue());
+ }
+ props.storeToXML(bos, "Properties written from Tamaya on " + new Date());
+ bos.flush();
+ }
+ catch(Exception e){
+ throw new IllegalStateException("Failed to write config to " + file, e);
+ }
+ }
+
+ @Override
+ protected String toStringValues() {
+ return super.toStringValues() +
+ " file=" + file + '\n';
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
deleted file mode 100644
index bcba53a..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
+++ /dev/null
@@ -1,171 +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.mutableconfig.propertysources;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Simple implementation of a mutable {@link org.apache.tamaya.spi.PropertySource} for .xml properties files.
- */
-public class MutableXmlPropertiesPropertySource extends BasePropertySource
-implements MutablePropertySource{
-
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(MutableXmlPropertiesPropertySource.class.getName());
-
- /**
- * The configuration resource's URL.
- */
- private File file;
-
- /**
- * The current properties.
- */
- private Map<String, String> properties = new HashMap<>();
-
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- */
- public MutableXmlPropertiesPropertySource(File propertiesLocation) {
- this(propertiesLocation, 0);
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property
- * source's properties.
- */
- public MutableXmlPropertiesPropertySource(File propertiesLocation, int defaultOrdinal) {
- super(propertiesLocation.toString(), defaultOrdinal);
- try {
- this.file = propertiesLocation;
- load();
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Cannot convert file to URL: " + propertiesLocation, e);
- }
- }
-
-
-
- @Override
- public PropertyValue get(String key) {
- String val = this.properties.get(key);
- if(val!=null) {
- return PropertyValue.of(key, val, getName());
- }
- return null;
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return PropertyValue.map(this.properties,getName());
- }
-
- /**
- * loads the Properties from the given URL
- *
- * @throws IllegalStateException in case of an error while reading properties-file
- */
- private void load() {
- try (InputStream stream = new FileInputStream(file)) {
- Map<String, String> properties = new HashMap<>();
- Properties props = new Properties();
- props.loadFromXML(stream);
- for (String key : props.stringPropertyNames()) {
- properties.put(key, props.getProperty(key));
- }
- this.properties = properties;
- LOG.log(Level.FINEST, "Loaded properties from " + file);
- this.properties = properties;
- } catch (IOException e) {
- LOG.log(Level.FINEST, "Cannot refresh properties from " + file, e);
- }
- }
-
- @Override
- public void applyChange(ConfigChangeRequest configChange) {
- if(configChange.isEmpty()){
- LOG.info("Nothing to commit for transaction: " + configChange.getTransactionID());
- return;
- }
- if(!file.exists()){
- try {
- if(!file.createNewFile()){
- throw new ConfigException("Failed to create config file " + file);
- }
- } catch (IOException e) {
- throw new ConfigException("Failed to create config file " + file, e);
- }
- }
- for(Map.Entry<String,String> en:configChange.getAddedProperties().entrySet()){
- int index = en.getKey().indexOf('?');
- if(index>0){
- this.properties.put(en.getKey().substring(0, index), en.getValue());
- }else{
- this.properties.put(en.getKey(), en.getValue());
- }
- }
- for(String rmKey:configChange.getRemovedProperties()){
- this.properties.remove(rmKey);
- }
- try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){
- Properties props = new Properties();
- for (Map.Entry<String,String> en : this.properties.entrySet()) {
- props.setProperty(en.getKey(), en.getValue());
- }
- props.storeToXML(bos, "Properties written from Tamaya on " + new Date());
- bos.flush();
- }
- catch(Exception e){
- throw new ConfigException("Failed to write config to " + file, e);
- }
- }
-
- @Override
- protected String toStringValues() {
- return super.toStringValues() +
- " file=" + file + '\n';
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigSource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigSource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigSource.java
new file mode 100644
index 0000000..c965bee
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigSource.java
@@ -0,0 +1,49 @@
+/*
+ * 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.mutableconfig.spi;
+
+import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
+
+import javax.config.spi.ConfigSource;
+
+
+/**
+ * This interface models a writable backend for configuration data.
+ *
+ * As a consequence clients should first check, using the corresponding methods, if entries are to edited or removedProperties
+ * actually are eligible for change/creation or removal.
+ */
+public interface MutableConfigSource extends ConfigSource {
+
+ /**
+ * Puts all given configuration entries. This method should check that all given properties are
+ * basically removable, as defined by #isWritable. If any of the passed keys is not writable during this initial
+ * check, the operation should not perform any configuration changes and throw a {@link org.apache.tamaya.ConfigException}. If errors
+ * occur afterwards, when the properties are effectively written back to the backends, the errors should be
+ * collected and returned as part of the ConfigException payload. Nevertheless the operation should in that case
+ * remove all entries as far as possible and abort the writing operation.
+ *
+ * @param configChange the {@link ConfigChangeRequest}, containing the transactionId used to isolate
+ * the change, the properties to be added/overridden and the property keys
+ * being removed.
+ * @throws org.apache.tamaya.ConfigException if any of the given properties could not be written, or the request is read-only.
+ */
+ void applyChange(ConfigChangeRequest configChange);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java
index 4412085..bd1eca0 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java
@@ -18,10 +18,11 @@
*/
package org.apache.tamaya.mutableconfig.spi;
-import org.apache.tamaya.Configuration;
import org.apache.tamaya.mutableconfig.ChangePropagationPolicy;
import org.apache.tamaya.mutableconfig.MutableConfiguration;
+import javax.config.Config;
+
/**
* Provider SPI used by {@link org.apache.tamaya.mutableconfig.MutableConfigurationProvider}. Providers may override
@@ -37,6 +38,6 @@ public interface MutableConfigurationProviderSpi {
* sources.
* @return a new mutable configuration instance.
*/
- MutableConfiguration createMutableConfiguration(Configuration configuration,
+ MutableConfiguration createMutableConfiguration(Config configuration,
ChangePropagationPolicy propagationPolicy);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java
deleted file mode 100644
index 211869c..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.mutableconfig.spi;
-
-import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
-import org.apache.tamaya.spi.PropertySource;
-
-
-/**
- * This interface models a writable backend for configuration data.
- *
- * As a consequence clients should first check, using the corresponding methods, if entries are to edited or removedProperties
- * actually are eligible for change/creation or removal.
- */
-public interface MutablePropertySource extends PropertySource {
-
- /**
- * Puts all given configuration entries. This method should check that all given properties are
- * basically removable, as defined by #isWritable. If any of the passed keys is not writable during this initial
- * check, the operation should not perform any configuration changes and throw a {@link org.apache.tamaya.ConfigException}. If errors
- * occur afterwards, when the properties are effectively written back to the backends, the errors should be
- * collected and returned as part of the ConfigException payload. Nevertheless the operation should in that case
- * remove all entries as far as possible and abort the writing operation.
- *
- * @param configChange the {@link ConfigChangeRequest}, containing the transactionId used to isolate
- * the change, the properties to be added/overridden and the property keys
- * being removed.
- * @throws org.apache.tamaya.ConfigException if any of the given properties could not be written, or the request is read-only.
- */
- void applyChange(ConfigChangeRequest configChange);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationProviderTest.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationProviderTest.java
index b316b7d..a7adbff 100644
--- a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationProviderTest.java
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationProviderTest.java
@@ -19,9 +19,10 @@
package org.apache.tamaya.mutableconfig;
-import org.apache.tamaya.ConfigurationProvider;
import org.junit.Test;
+import javax.config.ConfigProvider;
+
import static org.junit.Assert.*;
/**
@@ -36,7 +37,7 @@ public class MutableConfigurationProviderTest {
@Test
public void createMutableConfiguration1() throws Exception {
MutableConfiguration cfg = MutableConfigurationProvider
- .createMutableConfiguration(ConfigurationProvider.getConfiguration());
+ .createMutableConfiguration(ConfigProvider.getConfig());
assertNotNull(cfg);
assertEquals(cfg.getChangePropagationPolicy(),
MutableConfigurationProvider.getApplyMostSignificantOnlyChangePolicy());
@@ -46,7 +47,7 @@ public class MutableConfigurationProviderTest {
public void createMutableConfiguration2() throws Exception {
ChangePropagationPolicy policy = MutableConfigurationProvider.getApplySelectiveChangePolicy("blabla");
MutableConfiguration cfg = MutableConfigurationProvider
- .createMutableConfiguration(ConfigurationProvider.getConfiguration(),
+ .createMutableConfiguration(ConfigProvider.getConfig(),
policy);
assertNotNull(cfg);
assertEquals(cfg.getChangePropagationPolicy(), policy);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java
index 814f3ce..dae8478 100644
--- a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java
@@ -18,12 +18,11 @@
*/
package org.apache.tamaya.mutableconfig;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.mutableconfig.internal.WritablePropertiesSource;
import org.apache.tamaya.mutableconfig.internal.WritableXmlPropertiesSource;
import org.junit.Test;
+import javax.config.ConfigProvider;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
@@ -46,12 +45,12 @@ public class MutableConfigurationTest {
public void testCreateMutableConfiguration() throws Exception {
File f = File.createTempFile("ConfigChangeRequest",".properties");
MutableConfiguration cfg1 = MutableConfigurationProvider.createMutableConfiguration(
- ConfigurationProvider.getConfiguration(),
+ ConfigProvider.getConfig(),
MutableConfigurationProvider.getApplyAllChangePolicy());
assertNotNull(cfg1);
assertNotNull(cfg1.getConfigChangeRequest());
MutableConfiguration cfg2 = MutableConfigurationProvider.createMutableConfiguration(
- ConfigurationProvider.getConfiguration());
+ ConfigProvider.getConfig());
assertNotNull(cfg2);
assertNotNull(cfg2.getConfigChangeRequest());
assertTrue(cfg1!=cfg2);
@@ -66,7 +65,7 @@ public class MutableConfigurationTest {
@Test(expected=NullPointerException.class)
public void testNullCreateMutableConfiguration1() throws Exception {
MutableConfigurationProvider.createMutableConfiguration(
- (Configuration) null);
+ (javax.config.Config) null);
}
/**
@@ -89,7 +88,7 @@ public class MutableConfigurationTest {
public void testReadWriteProperties_WithCancel() throws IOException {
WritablePropertiesSource.target.delete();
MutableConfiguration mutConfig = MutableConfigurationProvider.createMutableConfiguration(
- ConfigurationProvider.getConfiguration()
+ ConfigProvider.getConfig()
);
mutConfig.put("key1", "value1");
Map<String,String> cm = new HashMap<>();
@@ -106,7 +105,7 @@ public class MutableConfigurationTest {
public void testReadWriteProperties_WithCommit() throws IOException {
WritablePropertiesSource.target.delete();
MutableConfiguration mutConfig = MutableConfigurationProvider.createMutableConfiguration(
- ConfigurationProvider.getConfiguration()
+ ConfigProvider.getConfig()
);
mutConfig.put("key1", "value1");
Map<String,String> cm = new HashMap<>();
@@ -116,7 +115,7 @@ public class MutableConfigurationTest {
mutConfig.store();
assertTrue(WritablePropertiesSource.target.exists());
MutableConfiguration mmutConfig2 = MutableConfigurationProvider.createMutableConfiguration(
- ConfigurationProvider.getConfiguration()
+ ConfigProvider.getConfig()
);
mmutConfig2.remove("foo");
mmutConfig2.remove("key3");
@@ -140,7 +139,7 @@ public class MutableConfigurationTest {
public void testReadWriteXmlProperties_WithCommit() throws IOException {
WritableXmlPropertiesSource.target.delete();
MutableConfiguration cfg = MutableConfigurationProvider.createMutableConfiguration(
- ConfigurationProvider.getConfiguration(), MutableConfigurationProvider.getApplyAllChangePolicy());
+ ConfigProvider.getConfig(), MutableConfigurationProvider.getApplyAllChangePolicy());
cfg.put("key1", "value1");
Map<String,String> cm = new HashMap<>();
cm.put("key2", "value2");
@@ -149,7 +148,7 @@ public class MutableConfigurationTest {
cfg.store();
assertTrue(WritableXmlPropertiesSource.target.exists());
MutableConfiguration cfg2 = MutableConfigurationProvider.createMutableConfiguration(
- ConfigurationProvider.getConfiguration());
+ ConfigProvider.getConfig());
assertTrue(cfg != cfg2);
cfg2.remove("foo");
cfg2.remove("key3");
@@ -172,7 +171,7 @@ public class MutableConfigurationTest {
public void testWriteWithNoChangePolicy() throws IOException {
WritableXmlPropertiesSource.target.delete();
MutableConfiguration cfg = MutableConfigurationProvider.createMutableConfiguration(
- ConfigurationProvider.getConfiguration(),
+ ConfigProvider.getConfig(),
MutableConfigurationProvider.getApplyNonePolicy());
cfg.put("key1", "value1");
Map<String,String> cm = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
index e6c79f5..825b6cb 100644
--- a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
@@ -18,11 +18,11 @@
*/
package org.apache.tamaya.mutableconfig.internal;
-import org.apache.tamaya.mutableconfig.propertysources.MutablePropertiesPropertySource;
+import org.apache.tamaya.mutableconfig.propertysources.MutablePropertiesConfigSource;
/**
- * Tests for {@link MutablePropertiesPropertySource}.
+ * Tests for {@link MutablePropertiesConfigSource}.
*/
public class PropertiesFileConfigBackendTest {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java
index 5257c8b..1d865f2 100644
--- a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java
@@ -18,15 +18,15 @@
*/
package org.apache.tamaya.mutableconfig.internal;
-import org.apache.tamaya.mutableconfig.propertysources.MutablePropertiesPropertySource;
+import org.apache.tamaya.mutableconfig.propertysources.MutablePropertiesConfigSource;
import java.io.File;
import java.io.IOException;
/**
- * Writable test property source based on the {@link MutablePropertiesPropertySource}.
+ * Writable test property source based on the {@link MutablePropertiesConfigSource}.
*/
-public class WritablePropertiesSource extends MutablePropertiesPropertySource {
+public class WritablePropertiesSource extends MutablePropertiesConfigSource {
public static File target = createFile();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java
index d6aa7ec..6137c8d 100644
--- a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java
@@ -18,15 +18,15 @@
*/
package org.apache.tamaya.mutableconfig.internal;
-import org.apache.tamaya.mutableconfig.propertysources.MutableXmlPropertiesPropertySource;
+import org.apache.tamaya.mutableconfig.propertysources.MutableXmlPropertiesConfigSource;
import java.io.File;
import java.io.IOException;
/**
- * Writable test property source based on the {@link MutableXmlPropertiesPropertySource}.
+ * Writable test property source based on the {@link MutableXmlPropertiesConfigSource}.
*/
-public class WritableXmlPropertiesSource extends MutableXmlPropertiesPropertySource {
+public class WritableXmlPropertiesSource extends MutableXmlPropertiesConfigSource {
public static File target = createFile();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/test/resources/META-INF/services/javax.config.spi.ConfigSource
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/resources/META-INF/services/javax.config.spi.ConfigSource b/modules/mutable-config/src/test/resources/META-INF/services/javax.config.spi.ConfigSource
new file mode 100644
index 0000000..609b9fe
--- /dev/null
+++ b/modules/mutable-config/src/test/resources/META-INF/services/javax.config.spi.ConfigSource
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.mutableconfig.internal.WritablePropertiesSource
+org.apache.tamaya.mutableconfig.internal.WritableXmlPropertiesSource
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/modules/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index 609b9fe..0000000
--- a/modules/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.mutableconfig.internal.WritablePropertiesSource
-org.apache.tamaya.mutableconfig.internal.WritableXmlPropertiesSource
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/optional/pom.xml
----------------------------------------------------------------------
diff --git a/modules/optional/pom.xml b/modules/optional/pom.xml
index 341f547..566056b 100644
--- a/modules/optional/pom.xml
+++ b/modules/optional/pom.xml
@@ -37,13 +37,6 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${tamaya-apicore.version}</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
<version>${tamaya-apicore.version}</version>
<scope>provided</scope>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java b/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
index 1d59cda..10789c4 100644
--- a/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
+++ b/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
@@ -20,8 +20,7 @@ package org.apache.tamaya.optional;
import java.util.Objects;
-
-import org.apache.tamaya.ConfigurationProvider;
+import javax.config.ConfigProvider;
/**
* Simplified configuration API, that can be used by code that only wants Tamaya to optionally enhance its configuration
@@ -32,21 +31,21 @@ public final class OptionalConfiguration {
/**
* Flag only true, if Tamaya is on the classpath.
*/
- private static final boolean TAMAYA_LOADED = initTamayaLoaded();
+ private static final boolean CONFIG_LOADED = initConfigLoaded();
/**
* Configuration API to be loaded.
*/
- private static final String TAMAYA_CONFIGURATION = "org.apache.tamaya.Configuration";
+ private static final String JAVAX_CONFIGURATION = "javax.config.Config";
/**
* Tries to load the Tamaya Configuration interface from the classpath.
*
* @return true, if the interface is available.
*/
- private static boolean initTamayaLoaded() {
+ private static boolean initConfigLoaded() {
try {
- Class.forName(TAMAYA_CONFIGURATION);
+ Class.forName(JAVAX_CONFIGURATION);
return true;
} catch (final Exception e) {
return false;
@@ -57,8 +56,8 @@ public final class OptionalConfiguration {
* Allows to check if Tamaya is on the classpath.
* @return true, if Tamaya is available.
*/
- public static boolean isTamayaLoaded(){
- return TAMAYA_LOADED;
+ public static boolean isConfigLoaded(){
+ return CONFIG_LOADED;
}
/**
@@ -178,7 +177,7 @@ public final class OptionalConfiguration {
case THROWS_EXCEPTION:
if (tamayaValue != value) {
if ((tamayaValue != null && !tamayaValue.equals(value)) ||
- (value != null && TAMAYA_LOADED && !value.equals(tamayaValue))) {
+ (value != null && CONFIG_LOADED && !value.equals(tamayaValue))) {
throw new IllegalStateException("Incompatible configuration values: key=" + key +
"=" + value + "(provider)/" + tamayaValue + "(Tamaya");
}
@@ -214,11 +213,11 @@ public final class OptionalConfiguration {
* @param <T> The type param
* @return the corresponding value from Tamaya, or null.
* @throws IllegalStateException if Tamaya is not loaded.
- * @see #isTamayaLoaded()
+ * @see #isConfigLoaded()
*/
private <T> T getTamaya(String key, Class<T> type) {
- if (TAMAYA_LOADED) {
- return ConfigurationProvider.getConfiguration().get(key, type);
+ if (CONFIG_LOADED) {
+ return ConfigProvider.getConfig().getValue(key, type);
}
throw new IllegalStateException("Tamaya is not loaded.");
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/osgi/common/bnd.bnd b/modules/osgi/common/bnd.bnd
index e937379..fc550e2 100644
--- a/modules/osgi/common/bnd.bnd
+++ b/modules/osgi/common/bnd.bnd
@@ -29,5 +29,5 @@ Import-Package: \
org.apache.tamaya,\
org.apache.tamaya.spi,\
org.apache.tamaya.functions,\
- org.apache.tamaya.spisupport
+ org.apache.tamaya.base
Export-Service: org.apache.tamaya.osgi.commands.TamayaConfigService
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/pom.xml
----------------------------------------------------------------------
diff --git a/modules/osgi/common/pom.xml b/modules/osgi/common/pom.xml
index 57c56c3..847e2b3 100644
--- a/modules/osgi/common/pom.xml
+++ b/modules/osgi/common/pom.xml
@@ -53,12 +53,7 @@
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
+ <artifactId>tamaya-base</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
@@ -68,8 +63,9 @@
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-spisupport</artifactId>
+ <artifactId>tamaya-core</artifactId>
<version>${project.parent.version}</version>
+ <scope>test</scope>
</dependency>
<!-- Testing -->
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
----------------------------------------------------------------------
diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
index 0969a59..170cebf 100644
--- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
+++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.osgi;
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.functions.ConfigurationFunctions;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -26,6 +25,8 @@ import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
+import javax.config.Config;
+import javax.config.ConfigProvider;
import java.io.IOException;
import java.util.Date;
import java.util.Dictionary;
@@ -102,7 +103,7 @@ final class ConfigChanger {
LOG.finest("Stored OSGI configuration backup for PID: " + pid);
}
LOG.finest("Evaluating Tamaya Config for PID: " + pid);
- org.apache.tamaya.Configuration tamayaConfig = getTamayaConfiguration(root);
+ Config tamayaConfig = getJavaConfiguration(root);
if (tamayaConfig == null) {
LOG.finest("No Tamaya configuration for root: " + root);
}else {
@@ -136,7 +137,7 @@ final class ConfigChanger {
}
}
- public void modifyConfiguration(String pid, org.apache.tamaya.Configuration config, Dictionary<String, Object> dictionary, Policy opMode) {
+ public void modifyConfiguration(String pid, Config config, Dictionary<String, Object> dictionary, Policy opMode) {
LOG.info(() -> "Updating configuration for PID: " + pid + "...");
dictionary.put("tamaya.modified.at", new Date().toString());
@@ -148,7 +149,7 @@ final class ConfigChanger {
dictionaryMap.put(key, value);
}
for (Map.Entry<String, Object> dictEntry : dictionaryMap.entrySet()) {
- Object configuredValue = config.getOrDefault(dictEntry.getKey(), dictEntry.getValue().getClass(), null);
+ Object configuredValue = config.getOptionalValue(dictEntry.getKey(), dictEntry.getValue().getClass()).orElse(null);
if (configuredValue != null) {
if(configuredValue.equals(dictEntry.getValue())){
continue;
@@ -168,39 +169,40 @@ final class ConfigChanger {
}
}
}
- for (Map.Entry<String, String> configEntry : config.getProperties().entrySet()) {
- Object dictValue = dictionary.get(configEntry.getKey());
- if(dictValue!=null && dictValue.equals(configEntry.getValue())){
+ for (String configKey : config.getPropertyNames()) {
+ Object dictValue = dictionary.get(configKey);
+ String configValue = config.getValue(configKey, String.class);
+ if(dictValue!=null && dictValue.equals(configValue)){
continue;
}
switch (opMode) {
case EXTEND:
if(dictValue==null){
- LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue());
- ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), null);
- dictionary.put(configEntry.getKey(), configEntry.getValue());
+ LOG.info(() -> "Setting key " + configKey + " to " + configValue);
+ ConfigHistory.propertySet(pid,configKey, configValue, null);
+ dictionary.put(configKey, configValue);
}
break;
case OVERRIDE:
- LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue());
- ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), null);
- dictionary.put(configEntry.getKey(), configEntry.getValue());
+ LOG.info(() -> "Setting key " + configKey + " to " + configValue);
+ ConfigHistory.propertySet(pid,configKey, configValue, null);
+ dictionary.put(configKey, configValue);
break;
case UPDATE_ONLY:
if(dictValue!=null){
- LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue());
- ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), dictValue);
- dictionary.put(configEntry.getKey(), configEntry.getValue());
+ LOG.info(() -> "Setting key " + configKey + " to " + configValue);
+ ConfigHistory.propertySet(pid,configKey, configValue, dictValue);
+ dictionary.put(configKey, configValue);
}
break;
}
}
}
- public org.apache.tamaya.Configuration getTamayaConfiguration(String root) {
+ public Config getJavaConfiguration(String root) {
if (root != null) {
- return ConfigurationProvider.getConfiguration()
- .with(ConfigurationFunctions.section(root, true));
+ return ConfigurationFunctions.section(root, true)
+ .apply(ConfigProvider.getConfig());
}
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
----------------------------------------------------------------------
diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
index 6c9c685..5d16ba7 100644
--- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
+++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
@@ -23,6 +23,7 @@ import org.osgi.framework.*;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
+import javax.config.Config;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
@@ -323,8 +324,8 @@ public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, S
}
- public org.apache.tamaya.Configuration getTamayaConfiguration(String root) {
- return configChanger.getTamayaConfiguration(root);
+ public Config getJavaConfiguration(String root) {
+ return configChanger.getJavaConfiguration(root);
}
@Override