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 2016/02/02 17:16:17 UTC
[8/8] incubator-tamaya git commit: TAMAYA-136: Adding PropertyValue
for PropertySource SPI. All changes and test fixes in all modules/examples
relevant for release.
TAMAYA-136: Adding PropertyValue for PropertySource SPI. All changes and test fixes in all modules/examples relevant for release.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/d778cb81
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d778cb81
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d778cb81
Branch: refs/heads/master
Commit: d778cb81476f4f12f5d9b55a65edc686af38311b
Parents: 0be037b
Author: anatole <an...@apache.org>
Authored: Tue Feb 2 17:15:53 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Feb 2 17:15:53 2016 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/spi/FilterContext.java | 19 +-
.../org/apache/tamaya/spi/PropertySource.java | 2 +-
.../org/apache/tamaya/spi/PropertyValue.java | 5 +-
.../spi/PropertyValueCombinationPolicy.java | 4 +-
.../tamaya/core/internal/PropertyFiltering.java | 4 +-
examples/8-remote-example/client/pom.xml | 7 +-
.../tamaya/examples/remote/client/Client.java | 6 +-
.../remote/client/RemotePropertySource.java | 62 ---
.../org.apache.tamaya.spi.PropertySource | 2 +-
examples/8-remote-example/server/pom.xml | 91 +++-
.../server/src/main/java/ExampleServer.java | 33 ++
.../remote/server/ClientScopeProvider.java | 55 --
.../tamaya/examples/remote/server/Start.java | 63 ---
.../org.apache.tamaya.server.spi.ScopeProvider | 19 -
.../server/src/main/resources/config-server.yml | 29 ++
.../tamaya/builder/SimplePropertySource.java | 7 +-
.../builder/ConfigurationBuilderTest.java | 46 +-
.../builder/TestANonSPIPropertyFilter.java | 3 +-
.../builder/TestBNonSPIPropertyFilter.java | 3 +-
.../tamaya/builder/TestPropertyFilter.java | 3 +-
.../tamaya/builder/TestPropertySource.java | 5 +-
.../builder/TestPropertySourceProvider.java | 9 +-
.../builder/TestPropertySourceProviderB.java | 9 +-
.../tamaya/events/FrozenPropertySource.java | 5 +-
.../events/PropertySourceChangeBuilder.java | 11 +-
.../tamaya/events/FrozenPropertySourceTest.java | 2 +-
modules/filter/pom.xml | 77 +++
.../tamaya/filter/ConfigurationFilter.java | 112 ++++
.../tamaya/filter/DefaultMetadataFilter.java | 42 ++
.../tamaya/filter/ProgrammableFilter.java | 111 ++++
.../tamaya/filter/RegexPropertyFilter.java | 56 ++
.../org.apache.tamaya.spi.PropertyFilter | 20 +
.../format/FlattenedDefaultPropertySource.java | 5 +-
.../FlattenedDefaultPropertySourceTest.java | 11 +-
.../functions/ConfigWrappingPropertySource.java | 5 +-
.../functions/ConfigurationFunctions.java | 20 +-
.../functions/EnrichedPropertySource.java | 9 +-
.../functions/FilteredPropertySource.java | 5 +-
.../tamaya/functions/MappedPropertySource.java | 5 +-
.../functions/MetaEnrichedPropertySource.java | 91 ----
.../functions/PropertySourceFunctions.java | 37 +-
.../functions/ValueMappedPropertySource.java | 7 +-
.../tamaya/inject/TestPropertySource.java | 5 +-
.../internal/DefaultDynamicValueTest.java | 5 +-
.../cdi/cfg/ProvidedPropertySource.java | 5 +-
.../integration/cdi/cfg/TestPropertySource.java | 5 +-
.../org/apache/tamaya/etcd/EtcdAccessor.java | 33 +-
.../apache/tamaya/etcd/EtcdPropertySource.java | 20 +-
.../etcd/internal/EtcdConfigChangeRequest.java | 43 +-
.../apache/tamaya/json/JSONPropertySource.java | 9 +-
.../json/CommonJSONTestCaseCollection.java | 45 +-
.../tamaya/json/JSONPropertySourceTest.java | 2 +-
.../mutableconfig/ConfigChangeManager.java | 23 +
.../PropertiesFileConfigChangeRequest.java | 13 +-
.../XmlPropertiesFileConfigChangeRequest.java | 7 +-
.../spi/AbstractConfigChangeRequest.java | 8 +
.../mutableconfig/ConfigChangeManagerTest.java | 14 +-
modules/pom.xml | 1 +
.../tamaya/remote/BaseRemotePropertySource.java | 9 +-
.../internal/ExpressionResolutionFilter.java | 9 +-
.../tamaya/resolver/MyTestPropertySource.java | 5 +-
.../AbstractPathPropertySourceProvider.java | 9 +-
.../AbstractPathPropertySourceProviderTest.java | 8 +-
.../PathBasedPropertySourceProvider.java | 6 +-
modules/server/pom.xml | 91 +++-
.../org/apache/tamaya/server/ConfigServer.java | 50 --
.../apache/tamaya/server/ConfigServiceApp.java | 57 ++
.../server/ConfigServiceConfiguration.java | 41 ++
.../tamaya/server/ConfigurationResource.java | 321 ++++++++++++
.../tamaya/server/FilteredConfigServlet.java | 86 ---
.../apache/tamaya/server/FullConfigServlet.java | 86 ---
.../java/org/apache/tamaya/server/Server.java | 46 --
.../internal/DefaultConfigAdminService.java | 136 -----
.../server/internal/DefaultConfigService.java | 137 -----
.../tamaya/server/internal/MediaTypeUtil.java | 58 ---
.../server/internal/RestConfigAdminService.java | 133 -----
.../server/internal/RestConfigService.java | 103 ----
.../tamaya/server/internal/SimpleServer.java | 81 ---
.../tamaya/server/spi/ConfigAdminService.java | 48 --
.../apache/tamaya/server/spi/ConfigService.java | 64 ---
.../services/org.apache.tamaya.server.Server | 19 -
....apache.tamaya.server.spi.ConfigAdminService | 19 -
.../org.apache.tamaya.server.spi.ConfigService | 19 -
modules/server/src/main/resources/banner.txt | 14 +
.../server/src/main/resources/config-server.yml | 29 ++
.../tamaya/server/ConfigServiceAppTest.java | 32 ++
.../org/apache/tamaya/server/EtcdAccessor.java | 519 +++++++++++++++++++
.../tamaya/spisupport/BasePropertySource.java | 9 +-
.../tamaya/spisupport/DefaultConfiguration.java | 16 +-
.../tamaya/spisupport/PropertyFiltering.java | 8 +-
src/site/asciidoc/extensions/index.adoc | 15 +-
src/site/asciidoc/extensions/mod_filter.adoc | 154 ++++++
92 files changed, 2163 insertions(+), 1629 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java b/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
index 7e81bd9..0cc4f5f 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
@@ -29,17 +29,22 @@ import java.util.Objects;
* @see PropertyFilter
*/
public class FilterContext {
-
+ /** The key. */
private final String key;
@Experimental
private Map<String, String> configEntries = new HashMap();
+ @Experimental
+ private boolean singlePropertyScoped;
+
/**
* Creates a new FilterContext.
* @param key the key under evaluation, not null.
+ * @param singlePropertyScope true, if the filtering is done only for one single property accessed explcitily.
* @param configEntries the raw configuration data available in the current evaluation context, not null.
*/
- public FilterContext(String key, Map<String,String> configEntries) {
+ public FilterContext(String key, Map<String,String> configEntries, boolean singlePropertyScope) {
+ this.singlePropertyScoped = singlePropertyScope;
this.key = Objects.requireNonNull(key);
this.configEntries.putAll(configEntries);
this.configEntries = Collections.unmodifiableMap(this.configEntries);
@@ -57,6 +62,16 @@ public class FilterContext {
}
/**
+ * Method that determines if filtering is done for a single property accessed, or as part of call to
+ * {@code getProperties()}.
+ * @return true, if its scoped to a single property accessed.
+ */
+ @Experimental
+ public boolean isSinglePropertyScoped(){
+ return singlePropertyScoped;
+ }
+
+ /**
* This map contains the following keys:
* <ul>
* <li>the original value <b>before</b> any filters were applied on it.</li>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
index 804adf5..ec2ef48 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -95,7 +95,7 @@ public interface PropertySource {
* @return the property value map, where {@code map.get(key) == value}, including also any metadata. In case a
* value is null, simply return {@code null}.
*/
- Map<String,String> get(String key);
+ PropertyValue get(String key);
/**
* Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
index 8d3559c..f56fa5d 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
@@ -97,9 +97,12 @@ public final class PropertyValue {
* @param key the key, not null.
* @param value the value.
* @param source the source, typically the name of the {@link PropertySource} providing the value, not null.
- * @return a new builder instance.
+ * @return a new property value instance, or null, if the value passed is null..
*/
public static PropertyValue of(String key, String value, String source){
+ if(value==null){
+ return null;
+ }
return new PropertyValue(key, value, source);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
index ad842d2..096b2a1 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
@@ -37,8 +37,8 @@ public interface PropertyValueCombinationPolicy {
@Override
public Map<String,String> collect(Map<String,String> currentValue, String key, PropertySource propertySource) {
- Map<String,String> value = propertySource.get(key);
- return value!=null && value.get(key)!=null?value:currentValue;
+ PropertyValue value = propertySource.get(key);
+ return value!=null?value.getConfigEntries():currentValue;
}
};
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
index f0d15bc..e16b056 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
@@ -57,7 +57,7 @@ public final class PropertyFiltering{
for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
boolean changed = false;
// Apply filters to values, prevent values filtered to null!
- FilterContext filterContext = new FilterContext(key, configData);
+ FilterContext filterContext = new FilterContext(key, configData, false);
for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
String newValue = filter.filterProperty(result, filterContext);
if (newValue != null && !newValue.equals(result)) {
@@ -96,7 +96,7 @@ public final class PropertyFiltering{
for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
AtomicInteger changes = new AtomicInteger();
for (Map.Entry<String, String> entry : inputMap.entrySet()) {
- FilterContext filterContext = new FilterContext(entry.getKey(), inputMap);
+ FilterContext filterContext = new FilterContext(entry.getKey(), inputMap, true);
for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
final String k = entry.getKey();
final String v = entry.getValue();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/client/pom.xml
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/pom.xml b/examples/8-remote-example/client/pom.xml
index f90c126..6bab59b 100644
--- a/examples/8-remote-example/client/pom.xml
+++ b/examples/8-remote-example/client/pom.xml
@@ -46,7 +46,12 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-remote</artifactId>
+ <artifactId>tamaya-etcd</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-filter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java
index 5eaba64..76bf407 100644
--- a/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java
+++ b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java
@@ -54,7 +54,7 @@ public class Client {
if(portValue==null){
portValue = ConfigurationProvider.getConfiguration().get("client.port");
}
- int port = portValue!=null?Integer.parseInt(portValue):8080;
+ int port = portValue!=null?Integer.parseInt(portValue):8055;
tomcat.setPort(port);
File base = new File(System.getProperty("java.io.tmpdir")+"/"+getClientId());
if(!base.exists()){
@@ -84,9 +84,9 @@ public class Client {
* @return the client identifier to be used.
*/
public static String getClientId() {
- String clientId = System.getenv("CLIENT_ID");
+ String clientId = System.getenv("ENV_CLIENT_ID");
if(clientId == null){
- clientId = System.getProperty("clientId");
+ clientId = System.getProperty("ENV_CLIENT_ID");
}
if(clientId == null){
clientId = "default";
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/RemotePropertySource.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/RemotePropertySource.java b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/RemotePropertySource.java
deleted file mode 100644
index 9990874..0000000
--- a/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/RemotePropertySource.java
+++ /dev/null
@@ -1,62 +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.examples.remote.client;
-
-import org.apache.tamaya.remote.BaseRemotePropertySource;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Property Resource, which reads configuration dat from the (local) configuration server. Normally also the config
- * server should be configured, e.g. using system or environment properties.
- */
-public class RemotePropertySource extends BaseRemotePropertySource{
- /** Current remote property source default ordinal. */
- private static final int REMOTE_ORDINAL = 15000;
-
- @Override
- public int getDefaultOrdinal(){
- return REMOTE_ORDINAL;
- }
-
- @Override
- protected Collection<URL> getAccessURLs() {
- try {
- String configServerUrl = System.getenv("CONFIG_SERVER");
- if(configServerUrl==null){
- configServerUrl = System.getProperty("configServer");
- }
- if(configServerUrl==null){
- configServerUrl = "http://localhost:8888/config?scope=CLIENT&scopeId={clientId}&format=application/json";
- }
- System.out.println("Reading config from " + configServerUrl.replace("{clientId}", Client.getClientId()));
- return Arrays.asList(new URL(configServerUrl.replace("{clientId}", Client.getClientId())));
- } catch (MalformedURLException e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to configure remote config location,", e);
- return Collections.emptySet();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
index 63d9a5b..a2a4042 100644
--- a/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ b/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.examples.remote.client.RemotePropertySource
\ No newline at end of file
+#org.apache.tamaya.examples.remote.client.RemotePropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/server/pom.xml
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/pom.xml b/examples/8-remote-example/server/pom.xml
index 1965bd3..5c5f97c 100644
--- a/examples/8-remote-example/server/pom.xml
+++ b/examples/8-remote-example/server/pom.xml
@@ -33,22 +33,103 @@ under the License.
<dependencies>
<dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-api</artifactId>
<version>${project.version}</version>
+ <scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-server</artifactId>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
<version>${project.version}</version>
+ <scope>compile</scope>
</dependency>
-
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.spotify</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>0.3.258</version>
+ <configuration>
+ <imageName>apache/tamaya/examples-server</imageName>
+ <imageTags>
+ <imageTag>${project.version}</imageTag>
+ </imageTags>
+ <baseImage>java:8-jre</baseImage>
+ <entryPoint>["java", "-jar", "/${project.build.finalName}.jar", "server", "/config-server.yml"]</entryPoint>
+ <exposes>
+ <expose>8080</expose>
+ </exposes>
+ <resources>
+ <resource>
+ <targetPath>/</targetPath>
+ <directory>${project.build.directory}</directory>
+ <include>${project.build.finalName}.jar</include>
+ </resource>
+ <resource>
+ <targetPath>/</targetPath>
+ <directory>${project.build.directory}/classes</directory>
+ <include>config-server.yml</include>
+ </resource>
+ </resources>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <createDependencyReducedPom>true</createDependencyReducedPom>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <mainClass>org.apache.tamaya.server.ConfigServiceApp</mainClass>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/server/src/main/java/ExampleServer.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/java/ExampleServer.java b/examples/8-remote-example/server/src/main/java/ExampleServer.java
new file mode 100644
index 0000000..ad55480
--- /dev/null
+++ b/examples/8-remote-example/server/src/main/java/ExampleServer.java
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+import org.apache.tamaya.server.ConfigServiceApp;
+
+/**
+ * Created by atsticks on 22.01.16.
+ */
+public class ExampleServer {
+
+ private ExampleServer(){}
+
+ public static void main(String... args) throws Exception{
+ ConfigServiceApp.main("server", "./src/main/resources/config-server.yml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/ClientScopeProvider.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/ClientScopeProvider.java b/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/ClientScopeProvider.java
deleted file mode 100644
index 12dc82d..0000000
--- a/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/ClientScopeProvider.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.examples.remote.server;
-
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.functions.ConfigurationFunctions;
-import org.apache.tamaya.server.spi.ScopeProvider;
-
-
-/**
- * Implementation of a {@link ScopeProvider} that registers a {@link ConfigOperator} that
- * filters out and combines a configuration subsection identified by
- * {@code client.default, client.<CLIENTID>}.
- */
-public class ClientScopeProvider implements ScopeProvider{
-
- /**
- * Access the unique scope name.
- * @return the unique scope name.
- */
- public String getScopeType(){
- return "CLIENT";
- }
-
- @Override
- public ConfigOperator getScope(final String scopeId) {
- return new ConfigOperator() {
- @Override
- public Configuration operate(Configuration c) {
- return ConfigurationFunctions.combine("Scoped Config CLIENT="+scopeId,
- c.with(ConfigurationFunctions.sectionRecursive(true, "client.default")),
- c.with(ConfigurationFunctions.sectionRecursive(true, "client." + scopeId))
- );
- }
- };
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/Start.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/Start.java b/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/Start.java
deleted file mode 100644
index f4372cf..0000000
--- a/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/Start.java
+++ /dev/null
@@ -1,63 +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.examples.remote.server;
-
-
-import org.apache.tamaya.server.Server;
-
-
-/**
- * Main class to start the server part of this example. Usage:
- * <pre>
- * java org.apache.tamaya.examples.remote.server.Start [-Dport=1234]
- * </pre>
- * The optional port value hereby overrides any port value received from the remote configuration.
- * By default port 8888 is used.
- */
-public class Start {
-
- /**
- * Utility class only.
- */
- private Start(){}
-
- /**
- * Mein methods. Usage:
- * <pre>
- * java org.apache.tamaya.examples.remote.server.Start [-Dport=1234]
- * </pre>
- * The optional port value hereby overrides any port value received from the remote configuration.
- * By default port 8888 is used.
- * @param args the args passed.
- */
- public static void main(String... args){
- // init configuration
- String portValue = System.getProperty("port");
- int port = portValue!=null?Integer.parseInt(portValue):8888;
- try {
- System.out.println("Starting server with port " + port);
- Server server = org.apache.tamaya.server.ConfigServer.createServer();
- server.start(port);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(-1);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/server/src/main/resources/META-INF/services/org.apache.tamaya.server.spi.ScopeProvider
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/resources/META-INF/services/org.apache.tamaya.server.spi.ScopeProvider b/examples/8-remote-example/server/src/main/resources/META-INF/services/org.apache.tamaya.server.spi.ScopeProvider
deleted file mode 100644
index 52e219c..0000000
--- a/examples/8-remote-example/server/src/main/resources/META-INF/services/org.apache.tamaya.server.spi.ScopeProvider
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.examples.remote.server.ClientScopeProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/examples/8-remote-example/server/src/main/resources/config-server.yml
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/resources/config-server.yml b/examples/8-remote-example/server/src/main/resources/config-server.yml
new file mode 100644
index 0000000..446351f
--- /dev/null
+++ b/examples/8-remote-example/server/src/main/resources/config-server.yml
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+scope: java
+server:
+ applicationConnectors:
+ - type: http
+ port: 4001
+ adminConnectors:
+ - type: http
+ port: 4099
+
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
index 0d5561e..085bd9a 100644
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
+++ b/modules/builder/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.builder;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
import java.util.Map;
@@ -42,10 +43,10 @@ public class SimplePropertySource implements PropertySource {
@Override
public int getOrdinal(){
- String configuredOrdinal = get(TAMAYA_ORDINAL);
+ PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
if(configuredOrdinal!=null){
try{
- return Integer.parseInt(configuredOrdinal);
+ return Integer.parseInt(configuredOrdinal.getValue());
} catch(Exception e){
Logger.getLogger(getClass().getName()).log(Level.WARNING,
"Configured Ordinal is not an int number: " + configuredOrdinal, e);
@@ -64,7 +65,7 @@ public class SimplePropertySource implements PropertySource {
}
@Override
- public String get(String key) {
+ public PropertyValue get(String key) {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
index d48fe08..43196f7 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java
@@ -103,7 +103,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("one").when(source).getName();
- doReturn("a").when(source).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(source).get("keyOfA");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source);
@@ -121,12 +121,12 @@ public class ConfigurationBuilderTest {
PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
doReturn(10).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
doReturn(10).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
@@ -167,12 +167,12 @@ public class ConfigurationBuilderTest {
PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
doReturn(10).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
doReturn(20).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
@@ -191,12 +191,12 @@ public class ConfigurationBuilderTest {
PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("one").when(sourceOne).getName();
- doReturn("b").when(sourceOne).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","b", "test")).when(sourceOne).get("keyOfA");
doReturn(30).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
- doReturn("a").when(sourceTwo).get("keyOfA");
+ doReturn(PropertyValue.of("keyOfA","a", "test")).when(sourceTwo).get("keyOfA");
doReturn(20).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, sourceTwo);
@@ -215,13 +215,13 @@ public class ConfigurationBuilderTest {
doReturn("one").when(sourceOne).getName();
doReturn(null).when(sourceOne).get(anyString());
- doReturn("b").when(sourceOne).get("b");
+ doReturn(PropertyValue.of("b","b", "test")).when(sourceOne).get("b");
doReturn(30).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
doReturn(null).when(sourceTwo).get(anyString());
- doReturn("a").when(sourceTwo).get("a");
+ doReturn(PropertyValue.of("a","a", "test")).when(sourceTwo).get("a");
doReturn(30).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne)
@@ -239,13 +239,13 @@ public class ConfigurationBuilderTest {
doReturn("one").when(sourceOne).getName();
doReturn(null).when(sourceOne).get(anyString());
- doReturn("b").when(sourceOne).get("b");
+ doReturn(PropertyValue.of("b","b", "test")).when(sourceOne).get("b");
doReturn(30).when(sourceOne).getOrdinal();
PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("two").when(sourceTwo).getName();
doReturn(null).when(sourceTwo).get(anyString());
- doReturn("a").when(sourceTwo).get("a");
+ doReturn(PropertyValue.of("a","a", "test")).when(sourceTwo).get("a");
doReturn(30).when(sourceTwo).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, null, sourceTwo);
@@ -285,7 +285,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -315,7 +315,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -345,7 +345,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -378,7 +378,7 @@ public class ConfigurationBuilderTest {
public void canAddNonSPIPropertyFilter() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -397,7 +397,7 @@ public class ConfigurationBuilderTest {
public void canAddNonSPIPropertyFiltersViaConsecutiveCalls() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -418,7 +418,7 @@ public class ConfigurationBuilderTest {
public void canAddMultipleNonSPIPropertyFiltersWhileOneIsNull() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -440,7 +440,7 @@ public class ConfigurationBuilderTest {
public void overhandedNullPropertyFilterIsSafelyHandled() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -460,7 +460,7 @@ public class ConfigurationBuilderTest {
public void canAddMultipleNonSPIPropertyFilter() {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
- doReturn("M").when(source).get("key");
+ doReturn(PropertyValue.of("key","M", "test")).when(source).get("key");
doReturn("source").when(source).getName();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -574,7 +574,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
@@ -591,7 +591,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(source)
@@ -667,7 +667,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
@@ -708,7 +708,7 @@ public class ConfigurationBuilderTest {
PropertySource source = mock(PropertySource.class, NOT_MOCKED_ANSWER);
doReturn("source").when(source).getName();
- doReturn("A").when(source).get("key");
+ doReturn(PropertyValue.of("key","A", "test")).when(source).get("key");
doReturn(100).when(source).getOrdinal();
ConfigurationBuilder builder = new ConfigurationBuilder();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java b/modules/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
index e113010..896e0bc 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestANonSPIPropertyFilter.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
public class TestANonSPIPropertyFilter implements PropertyFilter {
@Override
- public String filterProperty(String key, String value) {
+ public String filterProperty(String value, FilterContext context) {
String result = value;
if (!result.contains(("ABC"))) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java b/modules/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
index 2ce81fc..a9c0ac2 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestBNonSPIPropertyFilter.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
public class TestBNonSPIPropertyFilter implements PropertyFilter {
@Override
- public String filterProperty(String key, String value) {
+ public String filterProperty(String value, FilterContext context) {
String result = value;
if (!result.contains(("XYZ"))) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
index 80c4cb3..e22fca8 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertyFilter.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya.builder;
+import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
public class TestPropertyFilter implements PropertyFilter {
@Override
- public String filterProperty(String key, String value) {
+ public String filterProperty(String value, FilterContext context) {
String result = value;
if (!result.contains(("inBerlin"))) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
index e30c244..f1ebfea 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.builder;
import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.Collections;
import java.util.Hashtable;
@@ -47,8 +48,8 @@ public class TestPropertySource extends BasePropertySource
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
index 0dcd68c..5a2f400 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.builder;
import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.ArrayList;
import java.util.Collection;
@@ -54,8 +55,8 @@ public class TestPropertySourceProvider
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override
@@ -73,8 +74,8 @@ public class TestPropertySourceProvider
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
index e06c75c..9cfe725 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.builder;
import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.ArrayList;
import java.util.Collection;
@@ -54,8 +55,8 @@ public class TestPropertySourceProviderB
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key,getProperties().get(key), getName());
}
@Override
@@ -73,8 +74,8 @@ public class TestPropertySourceProviderB
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
index a8167f2..81e6dca 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.events;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.io.Serializable;
import java.util.Collections;
@@ -81,8 +82,8 @@ public final class FrozenPropertySource implements PropertySource, Serializable
}
@Override
- public String get(String key) {
- return this.properties.get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, this.properties.get(key), getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
index cefa4f4..0858fdb 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.events;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
@@ -95,19 +96,19 @@ public final class PropertySourceChangeBuilder {
public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
List<PropertyChangeEvent> changes = new ArrayList<>();
for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
- String val = map2.get(en.getKey());
+ PropertyValue val = map2.get(en.getKey());
if (val == null) {
changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
} else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue()));
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val.getValue(), en.getValue()));
}
}
for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
- String val = map1.get(en.getKey());
+ PropertyValue val = map1.get(en.getKey());
if (val == null) {
changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), null));
} else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), val));
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), val.getValue()));
}
}
return changes;
@@ -170,7 +171,7 @@ public final class PropertySourceChangeBuilder {
* @return the builder for chaining.
*/
public PropertySourceChangeBuilder remove(String key, String... otherKeys) {
- String oldValue = this.source.get(key);
+ PropertyValue oldValue = this.source.get(key);
if (oldValue == null) {
this.delta.remove(key);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
index 0c61e0b..1431228 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
@@ -58,7 +58,7 @@ public class FrozenPropertySourceTest {
PropertySource ps = FrozenPropertySource.of(myPS);
assertNotNull(ps);
for (Map.Entry<String, String> e : myPS.getProperties().entrySet()) {
- assertEquals(ps.get(e.getKey()), e.getValue());
+ assertEquals(ps.get(e.getKey()).getValue(), e.getValue());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/filter/pom.xml
----------------------------------------------------------------------
diff --git a/modules/filter/pom.xml b/modules/filter/pom.xml
new file mode 100644
index 0000000..2480950
--- /dev/null
+++ b/modules/filter/pom.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-extensions</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>tamaya-filter</artifactId>
+ <name>Apache Tamaya Modules - Adaptive Configuration Filtering</name>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.filter,
+ </Export-Package>
+ <!--<Private-Package>-->
+ <!--org.apache.tamaya.events.internal-->
+ <!--</Private-Package>-->
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
new file mode 100644
index 0000000..99ab27f
--- /dev/null
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
@@ -0,0 +1,112 @@
+/*
+ * 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.filter;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+
+
+/**
+ * Hereby
+ * <ul>
+ * <li><b>Single</b> filters are applied only when values are explicitly accessed. This is useful, e.g. for
+ * filtering passwords into clear text variants. Nevertheless metadata keys hidden on map level must be
+ * accessible (=not filtered) when accessed as single values.</li>
+ * <li><b>Map</b> filters are applied when values are filtered as part of a full properties access.
+ * Often filtering in these cases is more commonly applied, e.g. you dont want to show up all kind of metadata.
+ * </li>
+ * For both variants individual filter rules can be applied here. All filters configured are managed on a
+ * thread-local level, so this class is typically used to temporarely filter out some values. Do not forget to
+ * restore its state, when not using a thread anymore (especially important in multi-threaded environments), not
+ * doing so will create nasty side effects of configuration not being visisble depending on the thread
+ * active.
+ * </ul>
+ */
+public final class ConfigurationFilter implements PropertyFilter{
+
+ static final ThreadLocal<Boolean> THREADED_METADATA_FILTERED = new ThreadLocal<Boolean>(){
+ @Override
+ protected Boolean initialValue() {
+ return Boolean.TRUE;
+ }
+ };
+
+ private static final ThreadLocal<ProgrammableFilter> THREADED_MAP_FILTERS = new ThreadLocal<ProgrammableFilter>(){
+ @Override
+ protected ProgrammableFilter initialValue() {
+ return new ProgrammableFilter();
+ }
+ };
+
+ private static final ThreadLocal<ProgrammableFilter> THREADED_SINGLE_FILTERS = new ThreadLocal<ProgrammableFilter>(){
+ @Override
+ protected ProgrammableFilter initialValue() {
+ return new ProgrammableFilter();
+ }
+ };
+
+ /**
+ * Seactivates metadata filtering also on global map access for this thread.
+ * @see #clearFilters()
+ * @param active true,to enable metadata filtering (default).
+ */
+ public static void setMetadataFilter(boolean active){
+ THREADED_METADATA_FILTERED.set(active);
+ }
+
+ /**
+ * Access the filtering configuration that is used for filtering single property values accessed.
+ * @return the filtering config, never null.
+ */
+ public static ProgrammableFilter getSingleFilters(){
+ return THREADED_SINGLE_FILTERS.get();
+ }
+
+ /**
+ * Access the filtering configuration that is used for filtering configuration properties accessed as full
+ * map.
+ * @return the filtering config, never null.
+ */
+ public static ProgrammableFilter getMapFilters(){
+ return THREADED_MAP_FILTERS.get();
+ }
+
+ /**
+ * Removes all programmable filters active on the current thread.
+ */
+ public static void clearFilters(){
+ THREADED_MAP_FILTERS.get().clearFilters();
+ THREADED_SINGLE_FILTERS.get().clearFilters();
+ THREADED_METADATA_FILTERED.set(true);
+ }
+
+ @Override
+ public String filterProperty(String valueToBeFiltered, FilterContext context) {
+ if(!context.isSinglePropertyScoped()){
+ for(PropertyFilter pred: THREADED_MAP_FILTERS.get().getFilters()){
+ valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context);
+ }
+ }else{
+ for(PropertyFilter pred: THREADED_SINGLE_FILTERS.get().getFilters()){
+ valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context);
+ }
+ }
+ return valueToBeFiltered;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/filter/src/main/java/org/apache/tamaya/filter/DefaultMetadataFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/DefaultMetadataFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/DefaultMetadataFilter.java
new file mode 100644
index 0000000..389d9fa
--- /dev/null
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/DefaultMetadataFilter.java
@@ -0,0 +1,42 @@
+/*
+ * 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.filter;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+
+/**
+ * Default property filter that hides metadta entries starting with an '_', similar ti {@code etcd}.
+ */
+public final class DefaultMetadataFilter implements PropertyFilter{
+ @Override
+ public String filterProperty(String valueToBeFiltered, FilterContext context) {
+ if(context.isSinglePropertyScoped()){
+ // When accessing keys explicitly, do not hide anything.
+ return valueToBeFiltered;
+ }
+ if(ConfigurationFilter.THREADED_METADATA_FILTERED.get()) {
+ if (context.getKey().startsWith("_")) {
+ // Hide metadata entries.
+ return null;
+ }
+ }
+ return valueToBeFiltered;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/filter/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.java
new file mode 100644
index 0000000..8589faa
--- /dev/null
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.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.filter;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A set of property filter and accessor methods.
+ */
+public final class ProgrammableFilter implements PropertyFilter{
+ /** The filters. */
+ private List<PropertyFilter> filters = new ArrayList<>();
+
+ /**
+ * Add a filter.
+ * @param filter the filter.
+ */
+ public void addFilter(PropertyFilter filter){
+ filters.add(filter);
+ }
+
+ /**
+ * Adds a filter at given position.
+ * @param pos the position.
+ * @param filter the filter.
+ */
+ public void addFilter(int pos, PropertyFilter filter){
+ filters.add(pos, filter);
+ }
+
+ /**
+ * Removes a filter at a given position.
+ * @param pos the position.
+ * @return the filter removed, or null.
+ */
+ public PropertyFilter removeFilter(int pos){
+ return filters.remove(pos);
+ }
+
+ /**
+ * Clears all filters.
+ */
+ public void clearFilters(){
+ filters.clear();
+ }
+
+ /**
+ * Set the filters.
+ * @param filters the filters to be applied.
+ */
+ public void setFilters(PropertyFilter... filters){
+ setFilters(Arrays.asList(filters));
+ }
+
+ /**
+ * Set the filters.
+ * @param filters the filters to be applied.
+ */
+ public void setFilters(Collection<PropertyFilter> filters) {
+ filters.clear();
+ filters.addAll(filters);
+ }
+
+ /**
+ * Get all filters.
+ * @return all filters.
+ */
+ public List<PropertyFilter> getFilters(){
+ return Collections.unmodifiableList(filters);
+ }
+
+ @Override
+ public String filterProperty(String valueToBeFiltered, FilterContext context) {
+ for(PropertyFilter filter:filters){
+ valueToBeFiltered = filter.filterProperty(valueToBeFiltered, context);
+ }
+ return valueToBeFiltered;
+ }
+
+ @Override
+ public String toString() {
+ return "FilterConfig{" +
+ "filters=" + filters +
+ '}';
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/filter/src/main/java/org/apache/tamaya/filter/RegexPropertyFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/RegexPropertyFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/RegexPropertyFilter.java
new file mode 100644
index 0000000..616f2cf
--- /dev/null
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/RegexPropertyFilter.java
@@ -0,0 +1,56 @@
+/*
+ * 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.filter;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+
+import java.util.Objects;
+
+/**
+ * Predicate filtering using a regex expression operating on the key.
+ */
+public final class RegexPropertyFilter implements PropertyFilter{
+ /** The expression used to filter. */
+ private String expression;
+
+ /**
+ * Creates a new regex filter expression.
+ * @param expression the reged expression, not null.
+ */
+ public RegexPropertyFilter(String expression){
+ this.expression = Objects.requireNonNull(expression);
+ }
+
+ @Override
+ public String filterProperty(String valueToBeFiltered, FilterContext context) {
+ if(context.getKey().matches(expression)){
+ return null;
+ }
+ return valueToBeFiltered;
+ }
+
+ @Override
+ public String toString() {
+ return "RegexPredicate{" +
+ "expression='" + expression + '\'' +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
new file mode 100644
index 0000000..630c222
--- /dev/null
+++ b/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
@@ -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.filter.ConfigurationFilter
+org.apache.tamaya.filter.DefaultMetadataFilter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
index 4680981..9d2097f 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.format;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.Collections;
import java.util.HashMap;
@@ -101,8 +102,8 @@ public class FlattenedDefaultPropertySource implements PropertySource {
}
@Override
- public String get(String key) {
- return properties.get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, properties.get(key), getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java b/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java
index b53d367..adc94f6 100644
--- a/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java
+++ b/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java
@@ -67,14 +67,13 @@ public class FlattenedDefaultPropertySourceTest {
@Test
public void testGet() throws Exception {
FlattenedDefaultPropertySource ps = new FlattenedDefaultPropertySource(createConfigurationData("test2"));
- assertEquals("aValue", ps.get("a"));
- assertNotNull(ps.get("section1.sectionKey1"));
- assertNotNull(ps.get("section2.sectionKey1"));
- assertNull(ps.get("sectionKey1"));
+ assertEquals("aValue", ps.get("a").get("a"));
+ assertNotNull(ps.get("section1.sectionKey1").get("section1.sectionKey1"));
+ assertNotNull(ps.get("section2.sectionKey1").get("section2.sectionKey1"));
assertNull(ps.get("sectionKey1"));
ps = new FlattenedDefaultPropertySource(createConfigurationDataNoDefault("test2"));
- assertEquals("sectionValue11", ps.get("section1.sectionKey1"));
- assertEquals("sectionValue21", ps.get("section2.sectionKey1"));
+ assertEquals("sectionValue11", ps.get("section1.sectionKey1").get("section1.sectionKey1"));
+ assertEquals("sectionValue21", ps.get("section2.sectionKey1").get("section2.sectionKey1"));
assertNull(ps.get("a"));
assertNull(ps.get("section1"));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
index 0c8f7a6..83a628a 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.functions;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.Map;
import java.util.Objects;
@@ -58,8 +59,8 @@ final class ConfigWrappingPropertySource implements PropertySource {
}
@Override
- public String get(String key) {
- return config.get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, config.get(key), getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
index 57815fe..5effaa7 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -193,7 +193,7 @@ public final class ConfigurationFunctions {
* @return true, if the entry is exact in this section
*/
public static boolean isKeyInSection(String key, String sectionKey) {
- return key.startsWith(sectionKey);
+ return sectionKey.isEmpty() || key.startsWith(sectionKey);
}
/**
@@ -399,12 +399,10 @@ public final class ConfigurationFunctions {
@Override
public String query(Configuration config) {
Map<String, String> props = new TreeMap<>(config.getProperties());
- props.put("{meta}type", "Configuration");
- props.put("{meta}class", config.getClass().getName());
- props.put("{meta}timestamp", String.valueOf(System.currentTimeMillis()));
+ props.put("__timestamp", String.valueOf(System.currentTimeMillis()));
if(info!=null) {
for (Map.Entry<String, String> en : info.entrySet()) {
- props.put("{meta}info." + escape(en.getKey()), escape(en.getValue()));
+ props.put("__" + escape(en.getKey()), escape(en.getValue()));
}
}
StringBuilder builder = new StringBuilder(400).append("{\n");
@@ -443,12 +441,10 @@ public final class ConfigurationFunctions {
@Override
public String query(Configuration config) {
Map<String, String> props = new TreeMap<>(config.getProperties());
- props.put("{meta}type", "Configuration");
- props.put("{meta}class", config.getClass().getName());
- props.put("{meta}timestamp", String.valueOf(System.currentTimeMillis()));
+ props.put("__timestamp", String.valueOf(System.currentTimeMillis()));
if(info!=null) {
for (Map.Entry<String, String> en : info.entrySet()) {
- props.put("{meta}info." + escape(en.getKey()), escape(en.getValue()));
+ props.put("__" + escape(en.getKey()), escape(en.getValue()));
}
}
StringBuilder builder = new StringBuilder(400);
@@ -481,12 +477,10 @@ public final class ConfigurationFunctions {
@Override
public String query(Configuration config) {
Map<String, String> props = new TreeMap<>(config.getProperties());
- props.put("{meta}type", "Configuration");
- props.put("{meta}class", config.getClass().getName());
- props.put("{meta}timestamp", String.valueOf(System.currentTimeMillis()));
+ props.put("__timestamp", String.valueOf(System.currentTimeMillis()));
if(info!=null) {
for (Map.Entry<String, String> en : info.entrySet()) {
- props.put("{meta}info." + escape(en.getKey()), escape(en.getValue()));
+ props.put("__" + escape(en.getKey()), escape(en.getValue()));
}
}
StringBuilder builder = new StringBuilder(400).append("Configuration:\n");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java
index 309424d..de48fa8 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.functions;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
import java.util.Map;
@@ -60,19 +61,19 @@ class EnrichedPropertySource implements PropertySource {
}
@Override
- public String get(String key) {
+ public PropertyValue get(String key) {
if (overriding) {
String val = addedProperties.get(key);
if (val != null) {
- return val;
+ return PropertyValue.of(key, val, getName());
}
return basePropertySource.get(key);
}
- String val = basePropertySource.get(key);
+ PropertyValue val = basePropertySource.get(key);
if (val != null) {
return val;
}
- return addedProperties.get(key);
+ return PropertyValue.of(key, addedProperties.get(key), getName());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d778cb81/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java
index 657656b..7eccdee 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.functions;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
import java.util.Map;
@@ -53,8 +54,8 @@ class FilteredPropertySource implements PropertySource {
}
@Override
- public String get(String key) {
- return getProperties().get(key);
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, getProperties().get(key), getName());
}
@Override